Skip to content

Commit 2142236

Browse files
w1ldptrdavem330
authored andcommitted
net: sched: act_bpf: remove dependency on rtnl lock
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 <vladbu@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2b14e1e commit 2142236

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

net/sched/act_bpf.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,12 @@ static int tcf_bpf_dump(struct sk_buff *skb, struct tc_action *act,
143143
.index = prog->tcf_index,
144144
.refcnt = refcount_read(&prog->tcf_refcnt) - ref,
145145
.bindcnt = atomic_read(&prog->tcf_bindcnt) - bind,
146-
.action = prog->tcf_action,
147146
};
148147
struct tcf_t tm;
149148
int ret;
150149

150+
spin_lock(&prog->tcf_lock);
151+
opt.action = prog->tcf_action;
151152
if (nla_put(skb, TCA_ACT_BPF_PARMS, sizeof(opt), &opt))
152153
goto nla_put_failure;
153154

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

167+
spin_unlock(&prog->tcf_lock);
166168
return skb->len;
167169

168170
nla_put_failure:
171+
spin_unlock(&prog->tcf_lock);
169172
nlmsg_trim(skb, tp);
170173
return -1;
171174
}
@@ -264,7 +267,7 @@ static void tcf_bpf_prog_fill_cfg(const struct tcf_bpf *prog,
264267
{
265268
cfg->is_ebpf = tcf_bpf_is_ebpf(prog);
266269
/* updates to prog->filter are prevented, since it's called either
267-
* with rtnl lock or during final cleanup in rcu callback
270+
* with tcf lock or during final cleanup in rcu callback
268271
*/
269272
cfg->filter = rcu_dereference_protected(prog->filter, 1);
270273

@@ -336,8 +339,8 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla,
336339
goto out;
337340

338341
prog = to_bpf(*act);
339-
ASSERT_RTNL();
340342

343+
spin_lock(&prog->tcf_lock);
341344
if (res != ACT_P_CREATED)
342345
tcf_bpf_prog_fill_cfg(prog, &old);
343346

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

350353
prog->tcf_action = parm->action;
351354
rcu_assign_pointer(prog->filter, cfg.filter);
355+
spin_unlock(&prog->tcf_lock);
352356

353357
if (res == ACT_P_CREATED) {
354358
tcf_idr_insert(tn, *act);

0 commit comments

Comments
 (0)