Skip to content

Commit c881455

Browse files
w1ldptrdavem330
authored andcommitted
net: sched: act_skbmod: remove dependency on rtnl lock
Move read of skbmod_p rcu pointer to be protected by tcf spinlock. Use tcf spinlock to protect private skbmod data from concurrent modification during dump. Signed-off-by: Vlad Buslov <vladbu@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5e48180 commit c881455

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

net/sched/act_skbmod.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ static int tcf_skbmod_init(struct net *net, struct nlattr *nla,
156156

157157
d = to_skbmod(*a);
158158

159-
ASSERT_RTNL();
160159
p = kzalloc(sizeof(struct tcf_skbmod_params), GFP_KERNEL);
161160
if (unlikely(!p)) {
162161
tcf_idr_release(*a, bind);
@@ -166,10 +165,10 @@ static int tcf_skbmod_init(struct net *net, struct nlattr *nla,
166165
p->flags = lflags;
167166
d->tcf_action = parm->action;
168167

169-
p_old = rtnl_dereference(d->skbmod_p);
170-
171168
if (ovr)
172169
spin_lock_bh(&d->tcf_lock);
170+
/* Protected by tcf_lock if overwriting existing action. */
171+
p_old = rcu_dereference_protected(d->skbmod_p, 1);
173172

174173
if (lflags & SKBMOD_F_DMAC)
175174
ether_addr_copy(p->eth_dst, daddr);
@@ -205,15 +204,18 @@ static int tcf_skbmod_dump(struct sk_buff *skb, struct tc_action *a,
205204
{
206205
struct tcf_skbmod *d = to_skbmod(a);
207206
unsigned char *b = skb_tail_pointer(skb);
208-
struct tcf_skbmod_params *p = rtnl_dereference(d->skbmod_p);
207+
struct tcf_skbmod_params *p;
209208
struct tc_skbmod opt = {
210209
.index = d->tcf_index,
211210
.refcnt = refcount_read(&d->tcf_refcnt) - ref,
212211
.bindcnt = atomic_read(&d->tcf_bindcnt) - bind,
213-
.action = d->tcf_action,
214212
};
215213
struct tcf_t t;
216214

215+
spin_lock_bh(&d->tcf_lock);
216+
opt.action = d->tcf_action;
217+
p = rcu_dereference_protected(d->skbmod_p,
218+
lockdep_is_held(&d->tcf_lock));
217219
opt.flags = p->flags;
218220
if (nla_put(skb, TCA_SKBMOD_PARMS, sizeof(opt), &opt))
219221
goto nla_put_failure;
@@ -231,8 +233,10 @@ static int tcf_skbmod_dump(struct sk_buff *skb, struct tc_action *a,
231233
if (nla_put_64bit(skb, TCA_SKBMOD_TM, sizeof(t), &t, TCA_SKBMOD_PAD))
232234
goto nla_put_failure;
233235

236+
spin_unlock_bh(&d->tcf_lock);
234237
return skb->len;
235238
nla_put_failure:
239+
spin_unlock_bh(&d->tcf_lock);
236240
nlmsg_trim(skb, b);
237241
return -1;
238242
}

0 commit comments

Comments
 (0)