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>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
Eric Dumazet <edumazet@google.com>,
Maxim Mikityanskiy <maximmi@mellanox.com>,
Tariq Toukan <tariqt@nvidia.com>
Subject: [PATCH net-next] net/sched: sch_htb: fix htb_dump_class_stats() vs offload mode
Date: Mon, 18 May 2026 09:05:18 +0000 [thread overview]
Message-ID: <20260518090518.629245-1-edumazet@google.com> (raw)
htb_dump_class_stats() and htb_offload_aggregate_stats()
call gnet_stats_basic_sync_init(&cl->bstats) which
is wrong on 32bit arches when syncp is cleared.
Make sure to acquire qdisc spinlock and use
_bstats_set() to ease future lockless dumps.
Fixes: 83271586249c ("sch_htb: Stats for offloaded HTB")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Maxim Mikityanskiy <maximmi@mellanox.com>
Cc: Tariq Toukan <tariqt@nvidia.com>
---
net/sched/sch_htb.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index d8ef3efbe0d5eab42c535e48d95d9005ac9682be..908b9ba9ba2efa8df396b51d437a714afc802a73 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -1293,8 +1293,6 @@ static void htb_offload_aggregate_stats(struct htb_sched *q,
struct htb_class *c;
unsigned int i;
- gnet_stats_basic_sync_init(&cl->bstats);
-
for (i = 0; i < q->clhash.hashsize; i++) {
hlist_for_each_entry(c, &q->clhash.hash[i], common.hnode) {
struct htb_class *p = c;
@@ -1313,7 +1311,7 @@ static void htb_offload_aggregate_stats(struct htb_sched *q,
}
}
}
- _bstats_update(&cl->bstats, bytes, packets);
+ _bstats_set(&cl->bstats, bytes, packets);
}
static int
@@ -1340,17 +1338,21 @@ htb_dump_class_stats(struct Qdisc *sch, unsigned long arg, struct gnet_dump *d)
INT_MIN, INT_MAX);
if (q->offload) {
+ spin_lock_bh(qdisc_lock(sch));
if (!cl->level) {
- if (cl->leaf.q)
- cl->bstats = cl->leaf.q->bstats;
- else
- gnet_stats_basic_sync_init(&cl->bstats);
- _bstats_update(&cl->bstats,
- u64_stats_read(&cl->bstats_bias.bytes),
- u64_stats_read(&cl->bstats_bias.packets));
+ u64 bytes = 0, packets = 0;
+
+ if (cl->leaf.q) {
+ bytes = u64_stats_read(&cl->leaf.q->bstats.bytes);
+ packets = u64_stats_read(&cl->leaf.q->bstats.packets);
+ }
+ bytes += u64_stats_read(&cl->bstats_bias.bytes);
+ packets += u64_stats_read(&cl->bstats_bias.packets);
+ _bstats_set(&cl->bstats, bytes, packets);
} else {
htb_offload_aggregate_stats(q, cl);
}
+ spin_unlock_bh(qdisc_lock(sch));
}
if (gnet_stats_copy_basic(d, NULL, &cl->bstats, true) < 0 ||
--
2.54.0.563.g4f69b47b94-goog
reply other threads:[~2026-05-18 9:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260518090518.629245-1-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=maximmi@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tariqt@nvidia.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox