From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: "Simon Horman" <horms@kernel.org>,
"Jamal Hadi Salim" <jhs@mojatatu.com>,
"Victor Nogueira" <victor@mojatatu.com>,
"Jiri Pirko" <jiri@resnulli.us>,
"Toke Høiland-Jørgensen" <toke@toke.dk>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
"Eric Dumazet" <edumazet@google.com>
Subject: [PATCH net-next 3/4] net/sched: sch_htb: annotate data-races (II)
Date: Thu, 14 May 2026 09:59:34 +0000 [thread overview]
Message-ID: <20260514095935.3926276-4-edumazet@google.com> (raw)
In-Reply-To: <20260514095935.3926276-1-edumazet@google.com>
htb_dump_class_stats() will soon run locklessly.
(no RTNL, not qdisc spinlock).
Remove cl->xstats and replace it with two fields:
- xstats_lends
- xstats_borrows
Then use READ_ONCE()/WRITE_ONCE() annotations on them, and change
htb_dump_class_stats to use a private struct tc_htb_xstats.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/sched/sch_htb.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index 5bf1889bc0300e8e3a61d56ddcf1bb1402955107..353467eb7611be45c6a9c92a0dcd4357d136a232 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -114,7 +114,8 @@ struct htb_class {
*/
struct gnet_stats_basic_sync bstats;
struct gnet_stats_basic_sync bstats_bias;
- struct tc_htb_xstats xstats; /* our special stats */
+ u32 xstats_lends;
+ u32 xstats_borrows;
/* token bucket parameters */
s64 tokens, ctokens;/* current number of tokens */
@@ -707,10 +708,10 @@ static void htb_charge_class(struct htb_sched *q, struct htb_class *cl,
diff = min_t(s64, q->now - cl->t_c, cl->mbuffer);
if (cl->level >= level) {
if (cl->level == level)
- cl->xstats.lends++;
+ WRITE_ONCE(cl->xstats_lends, cl->xstats_lends + 1);
htb_accnt_tokens(cl, bytes, diff);
} else {
- cl->xstats.borrows++;
+ WRITE_ONCE(cl->xstats_borrows, cl->xstats_borrows + 1);
cl->tokens += diff; /* we moved t_c; update tokens */
}
htb_accnt_ctokens(cl, bytes, diff);
@@ -1319,6 +1320,10 @@ htb_dump_class_stats(struct Qdisc *sch, unsigned long arg, struct gnet_dump *d)
{
struct htb_class *cl = (struct htb_class *)arg;
struct htb_sched *q = qdisc_priv(sch);
+ struct tc_htb_xstats xstats = {
+ .lends = READ_ONCE(cl->xstats_lends),
+ .borrows = READ_ONCE(cl->xstats_borrows),
+ };
struct gnet_stats_queue qs = {
.drops = cl->drops,
.overlimits = cl->overlimits,
@@ -1328,10 +1333,10 @@ htb_dump_class_stats(struct Qdisc *sch, unsigned long arg, struct gnet_dump *d)
if (!cl->level && cl->leaf.q)
qdisc_qstats_qlen_backlog(cl->leaf.q, &qlen, &qs.backlog);
- cl->xstats.tokens = clamp_t(s64, PSCHED_NS2TICKS(cl->tokens),
- INT_MIN, INT_MAX);
- cl->xstats.ctokens = clamp_t(s64, PSCHED_NS2TICKS(cl->ctokens),
- INT_MIN, INT_MAX);
+ xstats.tokens = clamp_t(s64, PSCHED_NS2TICKS(cl->tokens),
+ INT_MIN, INT_MAX);
+ xstats.ctokens = clamp_t(s64, PSCHED_NS2TICKS(cl->ctokens),
+ INT_MIN, INT_MAX);
if (q->offload) {
if (!cl->level) {
@@ -1352,7 +1357,7 @@ htb_dump_class_stats(struct Qdisc *sch, unsigned long arg, struct gnet_dump *d)
gnet_stats_copy_queue(d, NULL, &qs, qlen) < 0)
return -1;
- return gnet_stats_copy_app(d, &cl->xstats, sizeof(cl->xstats));
+ return gnet_stats_copy_app(d, &xstats, sizeof(xstats));
}
static struct netdev_queue *
--
2.54.0.563.g4f69b47b94-goog
next prev parent reply other threads:[~2026-05-14 9:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-14 9:59 [PATCH net-next 0/4] net/sched: sch_htb: first round of fixes Eric Dumazet
2026-05-14 9:59 ` [PATCH net-next 1/4] net/sched: sch_htb: do not change sch->flags in htb_dump() Eric Dumazet
2026-05-14 9:59 ` [PATCH net-next 2/4] net/sched: sch_htb: annotate data-races (I) Eric Dumazet
2026-05-14 9:59 ` Eric Dumazet [this message]
2026-05-14 9:59 ` [PATCH net-next 4/4] net/sched: sch_htb: annotate data-races (III) Eric Dumazet
2026-05-16 1:30 ` [PATCH net-next 0/4] net/sched: sch_htb: first round of fixes patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260514095935.3926276-4-edumazet@google.com \
--to=edumazet@google.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=horms@kernel.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=toke@toke.dk \
--cc=victor@mojatatu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.