Skip to content

Commit 91052fa

Browse files
w1ldptrdavem330
authored andcommitted
net: sched: protect chain->explicitly_created with block->lock
In order to remove dependency on rtnl lock, protect tcf_chain->explicitly_created flag with block->lock. Consolidate code that checks and resets 'explicitly_created' flag into __tcf_chain_put() to execute it atomically with rest of code that puts chain reference. Signed-off-by: Vlad Buslov <[email protected]> Acked-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c266f64 commit 91052fa

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

net/sched/cls_api.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,22 @@ EXPORT_SYMBOL(tcf_chain_get_by_act);
370370

371371
static void tc_chain_tmplt_del(struct tcf_chain *chain);
372372

373-
static void __tcf_chain_put(struct tcf_chain *chain, bool by_act)
373+
static void __tcf_chain_put(struct tcf_chain *chain, bool by_act,
374+
bool explicitly_created)
374375
{
375376
struct tcf_block *block = chain->block;
376377
bool is_last, free_block = false;
377378
unsigned int refcnt;
378379

379380
mutex_lock(&block->lock);
381+
if (explicitly_created) {
382+
if (!chain->explicitly_created) {
383+
mutex_unlock(&block->lock);
384+
return;
385+
}
386+
chain->explicitly_created = false;
387+
}
388+
380389
if (by_act)
381390
chain->action_refcnt--;
382391

@@ -402,19 +411,18 @@ static void __tcf_chain_put(struct tcf_chain *chain, bool by_act)
402411

403412
static void tcf_chain_put(struct tcf_chain *chain)
404413
{
405-
__tcf_chain_put(chain, false);
414+
__tcf_chain_put(chain, false, false);
406415
}
407416

408417
void tcf_chain_put_by_act(struct tcf_chain *chain)
409418
{
410-
__tcf_chain_put(chain, true);
419+
__tcf_chain_put(chain, true, false);
411420
}
412421
EXPORT_SYMBOL(tcf_chain_put_by_act);
413422

414423
static void tcf_chain_put_explicitly_created(struct tcf_chain *chain)
415424
{
416-
if (chain->explicitly_created)
417-
tcf_chain_put(chain);
425+
__tcf_chain_put(chain, false, true);
418426
}
419427

420428
static void tcf_chain_flush(struct tcf_chain *chain)
@@ -2305,7 +2313,6 @@ static int tc_ctl_chain(struct sk_buff *skb, struct nlmsghdr *n,
23052313
* to the chain previously taken during addition.
23062314
*/
23072315
tcf_chain_put_explicitly_created(chain);
2308-
chain->explicitly_created = false;
23092316
break;
23102317
case RTM_GETCHAIN:
23112318
err = tc_chain_notify(chain, skb, n->nlmsg_seq,

0 commit comments

Comments
 (0)