Skip to contentSkip to conversation

net/sched: sch_htb: fix htb_dump_class_stats() vs offload mode

PATCH Applied Eric Dumazet 2 participants 2 messages May 18 – May 20

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

Fixes 83271586249c ("sch_htb: Stats for offloaded HTB")
Cc Maxim Mikityanskiy <[email protected]>
Cc Tariq Toukan <[email protected]>
---
 net/sched/sch_htb.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
net/sched/sch_htb.c +12 -10
index d8ef3efbe0d5eab42c535e48d95d9005ac9682be..908b9ba9ba2efa8df396b51d437a714afc802a73 100644
@@ -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
#1 lore raw
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() 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.

[...]

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