Re: [PATCH net v3 2/2] bonding: fix u32 overflow in compute_gap()
From: Nikolay Aleksandrov
Date: Wed Aug 19 2026 - 04:35:53 EST
On 19/08/2026 05:09, Hangbin Liu wrote:
On Wed, Aug 19, 2026 at 10:07:22AM +0800, Hangbin Liu wrote:
... this here, as u64_stats_update_begin doesn't provide exclusive access, so writers
must do that themselves, so you can't be sure what value will end up, the zeroing
might not work at all and can get overwritten
I meant - it doesn't improve on the current situation where it can also happen. :)
Ah, yes. I forgot this. The reset_unbalanced_load() could be called on any
CPU, which conflicts with other writers.
I re-checked the code. unbalanced_load is only called in two situations:
1. To rebalance the load in bond_alb_monitor(), which only executes once
every 10 seconds.
2. !tx_slave in bond_do_alb_xmit(), which is only for multicast/broadcast
traffic. This traffic shouldn't be significant.
So looks using spin_lock here is acceptable. What do you think?
I mean, drop the per-CPU design directly and use spin_lock to protect the data.
Hangbin
hmm why don't you change the way the reset is done? *untested* but in theory
you could just record the values at a reset "moment" in reset unbalanced and
just use the delta, so it becomes a reader and there is only 1 writer left (tx).
Keep the counters only increasing (important), only record a snapshot at a reset
moment, count current total bytes (sum all per-cpu data), decrement the previous
total from it and use that as the "interval bytes" to div.
Cheers,
Nik