Skip to content

Commit

Permalink
net: sched: act_bpf: remove dependency on rtnl lock
Browse files Browse the repository at this point in the history
Use tcf spinlock to protect bpf action private data from concurrent
modification during dump and init. Remove rtnl lock assertion that is no
longer necessary.

Signed-off-by: Vlad Buslov <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
w1ldptr authored and davem330 committed Aug 11, 2018
1 parent 2b14e1e commit 2142236
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions net/sched/act_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ static int tcf_bpf_dump(struct sk_buff *skb, struct tc_action *act,
.index = prog->tcf_index,
.refcnt = refcount_read(&prog->tcf_refcnt) - ref,
.bindcnt = atomic_read(&prog->tcf_bindcnt) - bind,
.action = prog->tcf_action,
};
struct tcf_t tm;
int ret;

spin_lock(&prog->tcf_lock);
opt.action = prog->tcf_action;
if (nla_put(skb, TCA_ACT_BPF_PARMS, sizeof(opt), &opt))
goto nla_put_failure;

Expand All @@ -163,9 +164,11 @@ static int tcf_bpf_dump(struct sk_buff *skb, struct tc_action *act,
TCA_ACT_BPF_PAD))
goto nla_put_failure;

spin_unlock(&prog->tcf_lock);
return skb->len;

nla_put_failure:
spin_unlock(&prog->tcf_lock);
nlmsg_trim(skb, tp);
return -1;
}
Expand Down Expand Up @@ -264,7 +267,7 @@ static void tcf_bpf_prog_fill_cfg(const struct tcf_bpf *prog,
{
cfg->is_ebpf = tcf_bpf_is_ebpf(prog);
/* updates to prog->filter are prevented, since it's called either
* with rtnl lock or during final cleanup in rcu callback
* with tcf lock or during final cleanup in rcu callback
*/
cfg->filter = rcu_dereference_protected(prog->filter, 1);

Expand Down Expand Up @@ -336,8 +339,8 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla,
goto out;

prog = to_bpf(*act);
ASSERT_RTNL();

spin_lock(&prog->tcf_lock);
if (res != ACT_P_CREATED)
tcf_bpf_prog_fill_cfg(prog, &old);

Expand All @@ -349,6 +352,7 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla,

prog->tcf_action = parm->action;
rcu_assign_pointer(prog->filter, cfg.filter);
spin_unlock(&prog->tcf_lock);

if (res == ACT_P_CREATED) {
tcf_idr_insert(tn, *act);
Expand Down

0 comments on commit 2142236

Please sign in to comment.