Skip to content

Commit 729e012

Browse files
w1ldptrdavem330
authored andcommitted
net: sched: act_tunnel_key: remove dependency on rtnl lock
Use tcf lock to protect tunnel key action struct private data from concurrent modification in init and dump. Use rcu swap operation to reassign params pointer under protection of tcf lock. (old params value is not used by init, so there is no need of standalone rcu dereference step) Remove rtnl lock assertion that is no longer required. Signed-off-by: Vlad Buslov <vladbu@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c881455 commit 729e012

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

net/sched/act_tunnel_key.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
204204
{
205205
struct tc_action_net *tn = net_generic(net, tunnel_key_net_id);
206206
struct nlattr *tb[TCA_TUNNEL_KEY_MAX + 1];
207-
struct tcf_tunnel_key_params *params_old;
208207
struct tcf_tunnel_key_params *params_new;
209208
struct metadata_dst *metadata = NULL;
210209
struct tc_tunnel_key *parm;
@@ -346,24 +345,22 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
346345

347346
t = to_tunnel_key(*a);
348347

349-
ASSERT_RTNL();
350348
params_new = kzalloc(sizeof(*params_new), GFP_KERNEL);
351349
if (unlikely(!params_new)) {
352350
tcf_idr_release(*a, bind);
353351
NL_SET_ERR_MSG(extack, "Cannot allocate tunnel key parameters");
354352
return -ENOMEM;
355353
}
356-
357-
params_old = rtnl_dereference(t->params);
358-
359-
t->tcf_action = parm->action;
360354
params_new->tcft_action = parm->t_action;
361355
params_new->tcft_enc_metadata = metadata;
362356

363-
rcu_assign_pointer(t->params, params_new);
364-
365-
if (params_old)
366-
kfree_rcu(params_old, rcu);
357+
spin_lock(&t->tcf_lock);
358+
t->tcf_action = parm->action;
359+
rcu_swap_protected(t->params, params_new,
360+
lockdep_is_held(&t->tcf_lock));
361+
spin_unlock(&t->tcf_lock);
362+
if (params_new)
363+
kfree_rcu(params_new, rcu);
367364

368365
if (ret == ACT_P_CREATED)
369366
tcf_idr_insert(tn, *a);
@@ -485,12 +482,13 @@ static int tunnel_key_dump(struct sk_buff *skb, struct tc_action *a,
485482
.index = t->tcf_index,
486483
.refcnt = refcount_read(&t->tcf_refcnt) - ref,
487484
.bindcnt = atomic_read(&t->tcf_bindcnt) - bind,
488-
.action = t->tcf_action,
489485
};
490486
struct tcf_t tm;
491487

492-
params = rtnl_dereference(t->params);
493-
488+
spin_lock(&t->tcf_lock);
489+
params = rcu_dereference_protected(t->params,
490+
lockdep_is_held(&t->tcf_lock));
491+
opt.action = t->tcf_action;
494492
opt.t_action = params->tcft_action;
495493

496494
if (nla_put(skb, TCA_TUNNEL_KEY_PARMS, sizeof(opt), &opt))
@@ -522,10 +520,12 @@ static int tunnel_key_dump(struct sk_buff *skb, struct tc_action *a,
522520
if (nla_put_64bit(skb, TCA_TUNNEL_KEY_TM, sizeof(tm),
523521
&tm, TCA_TUNNEL_KEY_PAD))
524522
goto nla_put_failure;
523+
spin_unlock(&t->tcf_lock);
525524

526525
return skb->len;
527526

528527
nla_put_failure:
528+
spin_unlock(&t->tcf_lock);
529529
nlmsg_trim(skb, b);
530530
return -1;
531531
}

0 commit comments

Comments
 (0)