Skip to content

Commit 53dfd50

Browse files
jrfastabdavem330
authored andcommitted
net: sched: cls_rcvp, complete rcu conversion
This completes the cls_rsvp conversion to RCU safe copy, update semantics. As a result all cases of tcf_exts_change occur on empty lists now. Signed-off-by: John Fastabend <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3d9a0d2 commit 53dfd50

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

net/sched/cls_rsvp.h

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,33 @@ static int rsvp_classify(struct sk_buff *skb, const struct tcf_proto *tp,
222222
return -1;
223223
}
224224

225+
static void rsvp_replace(struct tcf_proto *tp, struct rsvp_filter *n, u32 h)
226+
{
227+
struct rsvp_head *head = rtnl_dereference(tp->root);
228+
struct rsvp_session *s;
229+
struct rsvp_filter __rcu **ins;
230+
struct rsvp_filter *pins;
231+
unsigned int h1 = h & 0xFF;
232+
unsigned int h2 = (h >> 8) & 0xFF;
233+
234+
for (s = rtnl_dereference(head->ht[h1]); s;
235+
s = rtnl_dereference(s->next)) {
236+
for (ins = &s->ht[h2], pins = rtnl_dereference(*ins); ;
237+
ins = &pins->next, pins = rtnl_dereference(*ins)) {
238+
if (pins->handle == h) {
239+
RCU_INIT_POINTER(n->next, pins->next);
240+
rcu_assign_pointer(*ins, n);
241+
return;
242+
}
243+
}
244+
}
245+
246+
/* Something went wrong if we are trying to replace a non-existant
247+
* node. Mind as well halt instead of silently failing.
248+
*/
249+
BUG_ON(1);
250+
}
251+
225252
static unsigned long rsvp_get(struct tcf_proto *tp, u32 handle)
226253
{
227254
struct rsvp_head *head = rtnl_dereference(tp->root);
@@ -454,15 +481,26 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
454481
f = (struct rsvp_filter *)*arg;
455482
if (f) {
456483
/* Node exists: adjust only classid */
484+
struct rsvp_filter *n;
457485

458486
if (f->handle != handle && handle)
459487
goto errout2;
488+
489+
n = kmemdup(f, sizeof(*f), GFP_KERNEL);
490+
if (!n) {
491+
err = -ENOMEM;
492+
goto errout2;
493+
}
494+
495+
tcf_exts_init(&n->exts, TCA_RSVP_ACT, TCA_RSVP_POLICE);
496+
460497
if (tb[TCA_RSVP_CLASSID]) {
461-
f->res.classid = nla_get_u32(tb[TCA_RSVP_CLASSID]);
462-
tcf_bind_filter(tp, &f->res, base);
498+
n->res.classid = nla_get_u32(tb[TCA_RSVP_CLASSID]);
499+
tcf_bind_filter(tp, &n->res, base);
463500
}
464501

465-
tcf_exts_change(tp, &f->exts, &e);
502+
tcf_exts_change(tp, &n->exts, &e);
503+
rsvp_replace(tp, n, handle);
466504
return 0;
467505
}
468506

0 commit comments

Comments
 (0)