net/sched: sch_htb: fix htb_dump_class_stats() vs offload mode
Subsystems (3)
PATCH 1/1 net/sched: sch_htb: fix htb_dump_class_stats() vs offload mode
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.
--- net/sched/sch_htb.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
net/sched/sch_htb.c +12 -10
@@ -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 ||
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Mon, 18 May 2026 09:05:18 +0000 you wrote:
htb_dump_class_stats()andhtb_offload_aggregate_stats()callgnet_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.[...]
Here is the summary with links:
- [net-next] net/sched: sch_htb: fix htb_dump_class_stats() vs offload mode
https://git.kernel.org/netdev/net-next/c/231c53e1a529
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html