Re: [PATCH net v5 2/2] bonding: fix u32 overflow in compute_gap()

From: Nikolay Aleksandrov

Date: Wed Aug 26 2026 - 03:37:40 EST


On 25/08/2026 04:01, Hangbin Liu wrote:
From: Hangbin Liu <liuhangbin@xxxxxxxxxx>

The TLB load-tracking fields tx_bytes, load_history, load, and
unbalanced_load are all u32. At sustained throughput above ~3.2 Gbit/s
over the 10-second rebalance interval the byte counters wrap, causing
compute_gap() to produce incorrect gap values and mis-select slaves.
Such speeds are common on modern NICs under heavy traffic.

Widen these fields to u64. Use u64_stats_sync to protect the per-cpu
unbalanced_load_stats against tearing on 32-bit architectures, and
div_u64() for the 64-bit divisions. The tx_bytes and load_history
are protected in spin_lock. Also protect the slave load writing in
bond_alb_monitor() with spin_lock in case of tear on 32-bit.

Rework compute_gap() to use s64 arithmetic throughout. Return LLONG_MIN
when the speed is unknown.

Detected by AI code review.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Hangbin Liu <liuhangbin@xxxxxxxxxx>
---
drivers/net/bonding/bond_alb.c | 52 ++++++++++++++++++++++++++++++------------
include/net/bond_alb.h | 11 +++++----
2 files changed, 44 insertions(+), 19 deletions(-)


Reviewed-by: Nikolay Aleksandrov <razor@xxxxxxxxxxxxx>