Skip to content

Commit

Permalink
net_sched: use tcf_queue_work() in u32 filter
Browse files Browse the repository at this point in the history
Defer the tcf_exts_destroy() in RCU callback to
tc filter workqueue and get RTNL lock.

Reported-by: Chris Mi <[email protected]>
Cc: Daniel Borkmann <[email protected]>
Cc: Jiri Pirko <[email protected]>
Cc: John Fastabend <[email protected]>
Cc: Jamal Hadi Salim <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Signed-off-by: Cong Wang <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
congwang authored and davem330 committed Oct 29, 2017
1 parent df2735e commit c0d378e
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions net/sched/cls_u32.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ struct tc_u_knode {
u32 __percpu *pcpu_success;
#endif
struct tcf_proto *tp;
struct rcu_head rcu;
union {
struct work_struct work;
struct rcu_head rcu;
};
/* The 'sel' field MUST be the last field in structure to allow for
* tc_u32_keys allocated at end of structure.
*/
Expand Down Expand Up @@ -418,11 +421,21 @@ static int u32_destroy_key(struct tcf_proto *tp, struct tc_u_knode *n,
* this the u32_delete_key_rcu variant does not free the percpu
* statistics.
*/
static void u32_delete_key_work(struct work_struct *work)
{
struct tc_u_knode *key = container_of(work, struct tc_u_knode, work);

rtnl_lock();
u32_destroy_key(key->tp, key, false);
rtnl_unlock();
}

static void u32_delete_key_rcu(struct rcu_head *rcu)
{
struct tc_u_knode *key = container_of(rcu, struct tc_u_knode, rcu);

u32_destroy_key(key->tp, key, false);
INIT_WORK(&key->work, u32_delete_key_work);
tcf_queue_work(&key->work);
}

/* u32_delete_key_freepf_rcu is the rcu callback variant
Expand All @@ -432,11 +445,21 @@ static void u32_delete_key_rcu(struct rcu_head *rcu)
* for the variant that should be used with keys return from
* u32_init_knode()
*/
static void u32_delete_key_freepf_work(struct work_struct *work)
{
struct tc_u_knode *key = container_of(work, struct tc_u_knode, work);

rtnl_lock();
u32_destroy_key(key->tp, key, true);
rtnl_unlock();
}

static void u32_delete_key_freepf_rcu(struct rcu_head *rcu)
{
struct tc_u_knode *key = container_of(rcu, struct tc_u_knode, rcu);

u32_destroy_key(key->tp, key, true);
INIT_WORK(&key->work, u32_delete_key_freepf_work);
tcf_queue_work(&key->work);
}

static int u32_delete_key(struct tcf_proto *tp, struct tc_u_knode *key)
Expand Down

0 comments on commit c0d378e

Please sign in to comment.