Skip to content

Commit 6c00dc4

Browse files
edumazetdavem330
authored andcommitted
net_sched: sch_pie: implement lockless pie_dump()
Instead of relying on RTNL, pie_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in pie_change(). Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 293c7e2 commit 6c00dc4

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

net/sched/sch_pie.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -156,36 +156,38 @@ static int pie_change(struct Qdisc *sch, struct nlattr *opt,
156156
u32 target = nla_get_u32(tb[TCA_PIE_TARGET]);
157157

158158
/* convert to pschedtime */
159-
q->params.target = PSCHED_NS2TICKS((u64)target * NSEC_PER_USEC);
159+
WRITE_ONCE(q->params.target,
160+
PSCHED_NS2TICKS((u64)target * NSEC_PER_USEC));
160161
}
161162

162163
/* tupdate is in jiffies */
163164
if (tb[TCA_PIE_TUPDATE])
164-
q->params.tupdate =
165-
usecs_to_jiffies(nla_get_u32(tb[TCA_PIE_TUPDATE]));
165+
WRITE_ONCE(q->params.tupdate,
166+
usecs_to_jiffies(nla_get_u32(tb[TCA_PIE_TUPDATE])));
166167

167168
if (tb[TCA_PIE_LIMIT]) {
168169
u32 limit = nla_get_u32(tb[TCA_PIE_LIMIT]);
169170

170-
q->params.limit = limit;
171-
sch->limit = limit;
171+
WRITE_ONCE(q->params.limit, limit);
172+
WRITE_ONCE(sch->limit, limit);
172173
}
173174

174175
if (tb[TCA_PIE_ALPHA])
175-
q->params.alpha = nla_get_u32(tb[TCA_PIE_ALPHA]);
176+
WRITE_ONCE(q->params.alpha, nla_get_u32(tb[TCA_PIE_ALPHA]));
176177

177178
if (tb[TCA_PIE_BETA])
178-
q->params.beta = nla_get_u32(tb[TCA_PIE_BETA]);
179+
WRITE_ONCE(q->params.beta, nla_get_u32(tb[TCA_PIE_BETA]));
179180

180181
if (tb[TCA_PIE_ECN])
181-
q->params.ecn = nla_get_u32(tb[TCA_PIE_ECN]);
182+
WRITE_ONCE(q->params.ecn, nla_get_u32(tb[TCA_PIE_ECN]));
182183

183184
if (tb[TCA_PIE_BYTEMODE])
184-
q->params.bytemode = nla_get_u32(tb[TCA_PIE_BYTEMODE]);
185+
WRITE_ONCE(q->params.bytemode,
186+
nla_get_u32(tb[TCA_PIE_BYTEMODE]));
185187

186188
if (tb[TCA_PIE_DQ_RATE_ESTIMATOR])
187-
q->params.dq_rate_estimator =
188-
nla_get_u32(tb[TCA_PIE_DQ_RATE_ESTIMATOR]);
189+
WRITE_ONCE(q->params.dq_rate_estimator,
190+
nla_get_u32(tb[TCA_PIE_DQ_RATE_ESTIMATOR]));
189191

190192
/* Drop excess packets if new limit is lower */
191193
qlen = sch->q.qlen;
@@ -469,17 +471,18 @@ static int pie_dump(struct Qdisc *sch, struct sk_buff *skb)
469471

470472
/* convert target from pschedtime to us */
471473
if (nla_put_u32(skb, TCA_PIE_TARGET,
472-
((u32)PSCHED_TICKS2NS(q->params.target)) /
474+
((u32)PSCHED_TICKS2NS(READ_ONCE(q->params.target))) /
473475
NSEC_PER_USEC) ||
474-
nla_put_u32(skb, TCA_PIE_LIMIT, sch->limit) ||
476+
nla_put_u32(skb, TCA_PIE_LIMIT, READ_ONCE(sch->limit)) ||
475477
nla_put_u32(skb, TCA_PIE_TUPDATE,
476-
jiffies_to_usecs(q->params.tupdate)) ||
477-
nla_put_u32(skb, TCA_PIE_ALPHA, q->params.alpha) ||
478-
nla_put_u32(skb, TCA_PIE_BETA, q->params.beta) ||
478+
jiffies_to_usecs(READ_ONCE(q->params.tupdate))) ||
479+
nla_put_u32(skb, TCA_PIE_ALPHA, READ_ONCE(q->params.alpha)) ||
480+
nla_put_u32(skb, TCA_PIE_BETA, READ_ONCE(q->params.beta)) ||
479481
nla_put_u32(skb, TCA_PIE_ECN, q->params.ecn) ||
480-
nla_put_u32(skb, TCA_PIE_BYTEMODE, q->params.bytemode) ||
482+
nla_put_u32(skb, TCA_PIE_BYTEMODE,
483+
READ_ONCE(q->params.bytemode)) ||
481484
nla_put_u32(skb, TCA_PIE_DQ_RATE_ESTIMATOR,
482-
q->params.dq_rate_estimator))
485+
READ_ONCE(q->params.dq_rate_estimator)))
483486
goto nla_put_failure;
484487

485488
return nla_nest_end(skb, opts);

0 commit comments

Comments
 (0)