Skip to content

Commit d772849

Browse files
w1ldptrdavem330
authored andcommitted
net: sched: act_sample: remove dependency on rtnl lock
Use tcf spinlock to protect private sample action data from concurrent modification during dump and init. Signed-off-by: Vlad Buslov <vladbu@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 67b0c1a commit d772849

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

net/sched/act_sample.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ static int tcf_sample_init(struct net *net, struct nlattr *nla,
8080
}
8181
s = to_sample(*a);
8282

83+
spin_lock(&s->tcf_lock);
8384
s->tcf_action = parm->action;
8485
s->rate = nla_get_u32(tb[TCA_SAMPLE_RATE]);
8586
s->psample_group_num = nla_get_u32(tb[TCA_SAMPLE_PSAMPLE_GROUP]);
8687
psample_group = psample_group_get(net, s->psample_group_num);
8788
if (!psample_group) {
89+
spin_unlock(&s->tcf_lock);
8890
tcf_idr_release(*a, bind);
8991
return -ENOMEM;
9092
}
@@ -94,6 +96,7 @@ static int tcf_sample_init(struct net *net, struct nlattr *nla,
9496
s->truncate = true;
9597
s->trunc_size = nla_get_u32(tb[TCA_SAMPLE_TRUNC_SIZE]);
9698
}
99+
spin_unlock(&s->tcf_lock);
97100

98101
if (ret == ACT_P_CREATED)
99102
tcf_idr_insert(tn, *a);
@@ -105,7 +108,8 @@ static void tcf_sample_cleanup(struct tc_action *a)
105108
struct tcf_sample *s = to_sample(a);
106109
struct psample_group *psample_group;
107110

108-
psample_group = rtnl_dereference(s->psample_group);
111+
/* last reference to action, no need to lock */
112+
psample_group = rcu_dereference_protected(s->psample_group, 1);
109113
RCU_INIT_POINTER(s->psample_group, NULL);
110114
if (psample_group)
111115
psample_group_put(psample_group);
@@ -174,12 +178,13 @@ static int tcf_sample_dump(struct sk_buff *skb, struct tc_action *a,
174178
struct tcf_sample *s = to_sample(a);
175179
struct tc_sample opt = {
176180
.index = s->tcf_index,
177-
.action = s->tcf_action,
178181
.refcnt = refcount_read(&s->tcf_refcnt) - ref,
179182
.bindcnt = atomic_read(&s->tcf_bindcnt) - bind,
180183
};
181184
struct tcf_t t;
182185

186+
spin_lock(&s->tcf_lock);
187+
opt.action = s->tcf_action;
183188
if (nla_put(skb, TCA_SAMPLE_PARMS, sizeof(opt), &opt))
184189
goto nla_put_failure;
185190

@@ -196,9 +201,12 @@ static int tcf_sample_dump(struct sk_buff *skb, struct tc_action *a,
196201

197202
if (nla_put_u32(skb, TCA_SAMPLE_PSAMPLE_GROUP, s->psample_group_num))
198203
goto nla_put_failure;
204+
spin_unlock(&s->tcf_lock);
205+
199206
return skb->len;
200207

201208
nla_put_failure:
209+
spin_unlock(&s->tcf_lock);
202210
nlmsg_trim(skb, b);
203211
return -1;
204212
}

0 commit comments

Comments
 (0)