Re: [PATCH net v5 2/2] bonding: fix u32 overflow in compute_gap()
From: Hangbin Liu
Date: Thu Aug 27 2026 - 21:28:56 EST
On Thu, Aug 27, 2026 at 03:42:23PM +0200, Paolo Abeni wrote:
> > @@ -170,8 +171,14 @@ static void tlb_deinitialize(struct bonding *bond)
> >
> > static long long compute_gap(struct slave *slave)
> > {
> > - return (s64) (slave->speed << 20) - /* Convert to Megabit per sec */
> > - (s64) (SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */
> > + u32 raw_speed = READ_ONCE(slave->speed);
> > +
> > + /* It's meaningless to compare gap on unknown speed NIC */
> > + if (raw_speed == (u32)SPEED_UNKNOWN)
> > + return LLONG_MIN;
>
> Sashiko noted the above could entirely disable:
>
> https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260825-bond_overflow-v5-0-7a800de133f1%40kylinos.cn
>
> I think the v2 code for the above should be fine.
Thanks, it looks like I was over‑thinking this.
I was considering a case with two slaves: one at 1 Gbit/s and another at
10 Gbit/s. Once traffic exceeds 1 Gbit/s, `compute_gap` may still select the
1 Gbit/s slave, which leads to overload.
In any case, this behavior is still better than no balancing at all. I will fix this.
Thanks
Hangbin