All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hangbin Liu <hangbin.liu@linux.dev>
To: Nikolay Aleksandrov <razor@blackwall.org>
Cc: Jay Vosburgh <jv@jvosburgh.net>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Hangbin Liu <liuhangbin@kylinos.cn>
Subject: Re: [PATCH net v3 2/2] bonding: fix u32 overflow in compute_gap()
Date: Wed, 19 Aug 2026 10:07:14 +0800	[thread overview]
Message-ID: <aoUP0sLeEhCPxukB@fedora> (raw)
In-Reply-To: <bf56ea5d-a0d2-40f9-b8d5-73d8c54ca32b@blackwall.org>

Hi Nikolay,
On Tue, Aug 18, 2026 at 02:51:31PM +0300, Nikolay Aleksandrov wrote:
> > > > @@ -1344,8 +1355,14 @@ static netdev_tx_t bond_do_alb_xmit(struct sk_buff *skb, struct bonding *bond,
> > > >       if (!tx_slave) {
> > > >           /* unbalanced or unassigned, send through primary */
> > > >           tx_slave = rcu_dereference(bond->curr_active_slave);
> > > > -        if (bond->params.tlb_dynamic_lb)
> > > > -            this_cpu_add(bond_info->unbalanced_load->tx_bytes, skb->len);
> > > > +        if (bond->params.tlb_dynamic_lb) {
> > > > +            struct unbalanced_load_stats *pcpu_load;
> > > > +
> > > > +            pcpu_load = this_cpu_ptr(bond_info->unbalanced_load);
> > > > +            u64_stats_update_begin(&pcpu_load->syncp);
> > > > +            u64_stats_add(&pcpu_load->tx_bytes, skb->len);
> > > > +            u64_stats_update_end(&pcpu_load->syncp);
> > > 
> > > this still races with...
> > > 
> > > > +        }
> > > >       }
> > > >       if (tx_slave && bond_slave_can_tx(tx_slave)) {
> > > > @@ -1529,19 +1546,28 @@ netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
> > > >       return bond_do_alb_xmit(skb, bond, tx_slave);
> > > >   }
> > > > -static u32 reset_unbalanced_load(struct alb_bond_info *bond_info)
> > > > +static u64 reset_unbalanced_load(struct alb_bond_info *bond_info)
> > > >   {
> > > >       struct unbalanced_load_stats *p;
> > > > -    u32 total_bytes = 0;
> > > > +    u64 tx_bytes, total_bytes = 0;
> > > > +    unsigned int start;
> > > >       int i;
> > > >       for_each_possible_cpu(i) {
> > > >           p = per_cpu_ptr(bond_info->unbalanced_load, i);
> > > > -        total_bytes += READ_ONCE(p->tx_bytes);
> > > > -        WRITE_ONCE(p->tx_bytes, 0);
> > > > +        do {
> > > > +            start = u64_stats_fetch_begin(&p->syncp);
> > > > +            tx_bytes = u64_stats_read(&p->tx_bytes);
> > > > +        } while (u64_stats_fetch_retry(&p->syncp, start));
> > > > +
> > > > +        u64_stats_update_begin(&p->syncp);
> > > > +        u64_stats_set(&p->tx_bytes, 0);
> > > > +        u64_stats_update_end(&p->syncp);
> > > 
> > > ... 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?

> > 
> 
> Sorry for the multiple replies, but thinking about this - having multiple concurrent
> writers could cause write tearing for 32-bit architectures (the monitor is a writer
> and can write concurrently with tx) leading to invalid result.

Never mind. A detailed explanation is always welcome. I really appreciate
your review and comments.

Best Regards
Hangbin

  reply	other threads:[~2026-08-19  2:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18  8:47 [PATCH net v3 0/2] bonding: fix TLB load-tracking overflow on high-speed NICs Hangbin Liu
2026-08-18  8:47 ` [PATCH net v3 1/2] bonding: convert unbalanced_load to per-cpu state Hangbin Liu
2026-08-18  9:42   ` Nikolay Aleksandrov
2026-08-19  1:11     ` Hangbin Liu
2026-08-18  8:47 ` [PATCH net v3 2/2] bonding: fix u32 overflow in compute_gap() Hangbin Liu
2026-08-18  9:44   ` Nikolay Aleksandrov
2026-08-18 11:06     ` Nikolay Aleksandrov
2026-08-18 11:51       ` Nikolay Aleksandrov
2026-08-19  2:07         ` Hangbin Liu [this message]
2026-08-19  2:09           ` Hangbin Liu
2026-08-19  8:35             ` Nikolay Aleksandrov
2026-08-19  9:51               ` Hangbin Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aoUP0sLeEhCPxukB@fedora \
    --to=hangbin.liu@linux.dev \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jv@jvosburgh.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuhangbin@kylinos.cn \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.