net_sched: sch_pie: implement lockless pie_dump()
authorEric Dumazet <edumazet@google.com>
Thu, 18 Apr 2024 07:32:47 +0000 (07:32 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 19 Apr 2024 10:34:08 +0000 (11:34 +0100)
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>
net/sched/sch_pie.c

index 1764059..b3dcb84 100644 (file)
@@ -156,36 +156,38 @@ static int pie_change(struct Qdisc *sch, struct nlattr *opt,
                u32 target = nla_get_u32(tb[TCA_PIE_TARGET]);
 
                /* convert to pschedtime */
-               q->params.target = PSCHED_NS2TICKS((u64)target * NSEC_PER_USEC);
+               WRITE_ONCE(q->params.target,
+                          PSCHED_NS2TICKS((u64)target * NSEC_PER_USEC));
        }
 
        /* tupdate is in jiffies */
        if (tb[TCA_PIE_TUPDATE])
-               q->params.tupdate =
-                       usecs_to_jiffies(nla_get_u32(tb[TCA_PIE_TUPDATE]));
+               WRITE_ONCE(q->params.tupdate,
+                          usecs_to_jiffies(nla_get_u32(tb[TCA_PIE_TUPDATE])));
 
        if (tb[TCA_PIE_LIMIT]) {
                u32 limit = nla_get_u32(tb[TCA_PIE_LIMIT]);
 
-               q->params.limit = limit;
-               sch->limit = limit;
+               WRITE_ONCE(q->params.limit, limit);
+               WRITE_ONCE(sch->limit, limit);
        }
 
        if (tb[TCA_PIE_ALPHA])
-               q->params.alpha = nla_get_u32(tb[TCA_PIE_ALPHA]);
+               WRITE_ONCE(q->params.alpha, nla_get_u32(tb[TCA_PIE_ALPHA]));
 
        if (tb[TCA_PIE_BETA])
-               q->params.beta = nla_get_u32(tb[TCA_PIE_BETA]);
+               WRITE_ONCE(q->params.beta, nla_get_u32(tb[TCA_PIE_BETA]));
 
        if (tb[TCA_PIE_ECN])
-               q->params.ecn = nla_get_u32(tb[TCA_PIE_ECN]);
+               WRITE_ONCE(q->params.ecn, nla_get_u32(tb[TCA_PIE_ECN]));
 
        if (tb[TCA_PIE_BYTEMODE])
-               q->params.bytemode = nla_get_u32(tb[TCA_PIE_BYTEMODE]);
+               WRITE_ONCE(q->params.bytemode,
+                          nla_get_u32(tb[TCA_PIE_BYTEMODE]));
 
        if (tb[TCA_PIE_DQ_RATE_ESTIMATOR])
-               q->params.dq_rate_estimator =
-                               nla_get_u32(tb[TCA_PIE_DQ_RATE_ESTIMATOR]);
+               WRITE_ONCE(q->params.dq_rate_estimator,
+                          nla_get_u32(tb[TCA_PIE_DQ_RATE_ESTIMATOR]));
 
        /* Drop excess packets if new limit is lower */
        qlen = sch->q.qlen;
@@ -469,17 +471,18 @@ static int pie_dump(struct Qdisc *sch, struct sk_buff *skb)
 
        /* convert target from pschedtime to us */
        if (nla_put_u32(skb, TCA_PIE_TARGET,
-                       ((u32)PSCHED_TICKS2NS(q->params.target)) /
+                       ((u32)PSCHED_TICKS2NS(READ_ONCE(q->params.target))) /
                        NSEC_PER_USEC) ||
-           nla_put_u32(skb, TCA_PIE_LIMIT, sch->limit) ||
+           nla_put_u32(skb, TCA_PIE_LIMIT, READ_ONCE(sch->limit)) ||
            nla_put_u32(skb, TCA_PIE_TUPDATE,
-                       jiffies_to_usecs(q->params.tupdate)) ||
-           nla_put_u32(skb, TCA_PIE_ALPHA, q->params.alpha) ||
-           nla_put_u32(skb, TCA_PIE_BETA, q->params.beta) ||
+                       jiffies_to_usecs(READ_ONCE(q->params.tupdate))) ||
+           nla_put_u32(skb, TCA_PIE_ALPHA, READ_ONCE(q->params.alpha)) ||
+           nla_put_u32(skb, TCA_PIE_BETA, READ_ONCE(q->params.beta)) ||
            nla_put_u32(skb, TCA_PIE_ECN, q->params.ecn) ||
-           nla_put_u32(skb, TCA_PIE_BYTEMODE, q->params.bytemode) ||
+           nla_put_u32(skb, TCA_PIE_BYTEMODE,
+                       READ_ONCE(q->params.bytemode)) ||
            nla_put_u32(skb, TCA_PIE_DQ_RATE_ESTIMATOR,
-                       q->params.dq_rate_estimator))
+                       READ_ONCE(q->params.dq_rate_estimator)))
                goto nla_put_failure;
 
        return nla_nest_end(skb, opts);