mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: hangbin.liu@linux.dev
Cc: jv@jvosburgh.net, andrew+netdev@lunn.ch, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	tonghao@bamaicloud.com, razor@blackwall.org, shuah@kernel.org,
	jiangjiehua1@huawei.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net v2 2/3] bonding: update slave array on link change for broadcast mode
Date: Thu, 03 Dec 2026 06:29:52 +0000	[thread overview]
Message-ID: <179627939278.3146.9699110701797983880@kernel.org> (raw)
In-Reply-To: <20261201-bond_broadcast_updelay-v2-2-969e1844f2c4@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 (2) · Low: 0 (2)

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] In balance-rr, updelay is ignored for good after the bond has
  been switched from broadcast mode.
- [Medium] bonding: stale usable_slaves in bond_change_active_slave() on
  LINK_BACK promotion

Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but ALB mode and
  TLB with tlb_dynamic_lb=1 have the same stale usable_slaves problem…
- [Medium] This problem wasn't introduced by this patch, but balance-rr
  never implements the rule in bonding.rst section 13.1 ('when a bonding…
- [Low] This problem wasn't introduced by this patch, but two comments
  are stale.
- [Low] This problem wasn't introduced by this patch, but
  bond_miimon_inspect() reads usable_slaves->count with a plain load…

--

bonding: update slave array on link change for broadcast mode

In broadcast mode, this patch rebuilds the usable and all slave arrays on
MII and ARP monitor link-state changes, in bond_open(), and on slave
NETDEV_UP/CHANGE/DOWN events. The aim is to keep usable_slaves current so
that bond_miimon_inspect() decides correctly whether to bypass updelay. It
relies on the preceding revert that makes broadcast mode publish
usable_slaves again.

> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index d6675e87d06b6..a8c79fa9f5bf2 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -2780,6 +2780,7 @@ static void bond_miimon_link_change(struct bonding *bond,
>  		bond_alb_handle_link_change(bond, slave, link);
>  		break;
>  	case BOND_MODE_XOR:
> +	case BOND_MODE_BROADCAST:
>  		bond_update_slave_arr(bond, NULL);
>  		break;
>  	}

[Severity: Medium]
Does this cover every place where a broadcast slave becomes
BOND_LINK_UP?

bond_change_active_slave() can move a slave that is still in
BOND_LINK_BACK straight to BOND_LINK_UP, which skips the rest of its
updelay. In that path it resets new_active->delay and calls
bond_set_slave_link_state(). After that it only calls
bond_3ad_handle_link_change() for 802.3ad and
bond_alb_handle_link_change() for TLB/ALB. Nothing rebuilds the
arrays for broadcast or xor.

Here is one sequence with updelay > 0. Slave A is curr_active_slave
and is the only slave that can transmit. Slave B is in BOND_LINK_BACK
with delay < updelay. Then A loses carrier:

bond_miimon_commit()
    bond_miimon_link_change(bond, A, BOND_LINK_DOWN)
        bond_update_slave_arr()       <- B is BACK, count == 0
    bond_select_active_slave()
        bond_find_best_slave()        <- returns B
        bond_change_active_slave(bond, B)
            bond_set_slave_link_state(B, BOND_LINK_UP, ...)

Releasing A through __bond_release_one() has the same result. That
path rebuilds the array with A skipped, and only then calls
bond_select_active_slave().

B is now forwarding, but usable_slaves->count is still 0. B's link is
already BOND_LINK_UP, so later bond_miimon_inspect() passes skip it and
bond_miimon_commit() never handles it. The array stays empty until some
other link event happens.

The next slave to recover then sees count == 0 in
bond_miimon_inspect(). It sets ignore_updelay and skips updelay while
B is still forwarding. That is the case the commit message sets out to
fix.

Balance-xor already has this hole. There the empty array also makes
bond_3ad_xor_xmit() drop packets while B is up.

Would it be the right fix to call
bond_miimon_link_change(bond, new_active, BOND_LINK_UP) from
bond_change_active_slave(), in place of the open-coded 802.3ad and
TLB/ALB calls? Or should the callers rebuild the array after
bond_select_active_slave()?

[Severity: Medium]
This is a pre-existing issue, but do ALB mode and TLB with tlb_dynamic_lb=1
have the same stale usable_slaves problem that this patch fixes for
broadcast?

bond_mode_can_use_xmit_hash() includes TLB and ALB. So enslave, release,
bond_open() and NETDEV_UP/CHANGE/DOWN all rebuild the array for those modes.

On MII link transitions, though, the TLB/ALB case goes through
bond_alb_handle_link_change(). That function rebuilds only for
non-dynamic TLB:

drivers/net/bonding/bond_alb.c:bond_alb_handle_link_change() {
    ...
	if (bond_is_nondyn_tlb(bond)) {
		if (bond_update_slave_arr(bond, NULL))
    ...
}

This condition is never true for ALB, because bond_option_mode_set() forces
tlb_dynamic_lb=1. It is not true for dynamic TLB either.

Here is one sequence. Carrier-up raises NETDEV_CHANGE, which is handled
promptly because bond slaves are lag ports. The array is rebuilt while
slave->link is still DOWN or BACK, so bond_slave_can_tx() leaves the slave
out. miimon later commits BOND_LINK_UP, and nothing rebuilds the array.

Wouldn't the array then stay empty while a slave is forwarding? The next
recovering slave would then bypass updelay in bond_miimon_inspect().

[Severity: Low]
This is a pre-existing issue, but bond_miimon_inspect() reads
usable_slaves->count with a plain load while holding only RCU:

	usable_slaves = rcu_dereference(bond->usable_slaves);

	if (usable_slaves && usable_slaves->count == 0)
		ignore_updelay = true;

bond_skip_slave() can change count in place on the already published array,
holding only RTNL. This happens on the ENOMEM path of bond_update_slave_arr()
when it is called from __bond_release_one():

	WRITE_ONCE(slaves->count, slaves->count - 1);

The two sides share no lock and only one access is marked, so KCSAN would
report this pair. Other readers already use READ_ONCE(slaves->count), for
example bond_xmit_broadcast(), bond_xmit_3ad_xor_slave_get(),
bond_xdp_xmit_3ad_xor_slave_get() and __bond_sk_get_lower_dev().

Should bond_miimon_inspect() use READ_ONCE() here too?

[ ... ]

> @@ -4411,7 +4414,8 @@ static int bond_open(struct net_device *bond_dev)
>  			static_branch_inc(&bond_bcast_neigh_enabled);
>  	}
>  
> -	if (bond_mode_can_use_xmit_hash(bond))
> +	if (bond_mode_can_use_xmit_hash(bond) ||
> +	    BOND_MODE(bond) == BOND_MODE_BROADCAST)
>  		bond_update_slave_arr(bond, NULL);
>  
>  	return 0;

[Severity: Medium]
Can a bond that is switched from broadcast to balance-rr end up ignoring
updelay for good?

With the preceding revert, broadcast mode publishes bond->usable_slaves
again. Releasing the last broadcast slave goes through:

__bond_release_one()
    bond_update_slave_arr(bond, slave)
        bond_set_slave_arr()  <- publishes non-NULL usable_slaves, count == 0

The mode option requires BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN. But
neither bond_option_mode_set() nor bond_close() resets usable_slaves or
all_slaves, so the count == 0 array carries over into balance-rr.

In balance-rr, nothing rebuilds that array:

- enslave, release, bond_open() and bond_slave_netdev_event() are gated on
  bond_mode_can_use_xmit_hash() || BROADCAST.
- bond_miimon_link_change() has no rr case.

The check in bond_miimon_inspect() is then true on every pass:

	if (usable_slaves && usable_slaves->count == 0)
		ignore_updelay = true;

As a result, every recovering rr slave gets delay = 0, even while other
slaves are still forwarding. This looks like the case the commit message
says it fixes:

    A stale empty array can
    make a recovering slave bypass updelay while another slave is still
    forwarding.

The xor to rr path already had this problem. The broadcast to rr variant is
new with this series.

It is only mentioned in the "For Sashiko" note below the --- line, which
won't reach the git log or stable reviewers, even though the patch carries
Cc: stable.

Should the arrays be reset on mode change or in bond_close()? Or should the
commit message at least note this limitation?

[Severity: Medium]
This is a pre-existing issue, but does balance-rr ever follow the
bonding.rst section 13.1 rule that the commit message cites?

    Note that when a bonding interface has no active links, the
    driver will immediately reuse the first link that goes up, even if the
    updelay parameter has been specified

bond_miimon_inspect() derives ignore_updelay from bond->usable_slaves for
every mode except active-backup. No bond_update_slave_arr() call site covers
BOND_MODE_ROUNDROBIN:

- enslave, release, open and netdev events are gated on xmit_hash ||
  BROADCAST.
- bond_miimon_link_change() covers 8023AD/TLB/ALB/XOR/BROADCAST.
- bond_loadbalance_arp_mon() covers XOR/BROADCAST.

A bond that has always been in rr mode therefore has usable_slaves == NULL,
and ignore_updelay stays false.

Doesn't the first recovering link then wait the full updelay, even though
no slave can transmit? If the bond was earlier in xor or broadcast mode, the
opposite failure described above happens instead.

[Severity: Low]
This isn't a bug introduced by this patch, but two existing comments no
longer match how broadcast mode uses the arrays.

The header comment of bond_update_slave_arr() leaves out
BOND_MODE_BROADCAST:

/* Build the usable slaves array in control path for modes that use xmit-hash
 * to determine the slave interface -
 * (a) BOND_MODE_8023AD
 * (b) BOND_MODE_XOR
 * (c) (BOND_MODE_TLB || BOND_MODE_ALB) && tlb_dynamic_lb == 0

The comment in bond_enslave() gives all_slaves as the only reason for
broadcast:

	/* broadcast mode uses the all_slaves to loop through slaves. */

The new broadcast call sites, however, exist to keep usable_slaves current
for bond_miimon_inspect().

Could these comments be updated as well?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201-bond_broadcast_updelay-v2-0-969e1844f2c4%40kylinos.cn

  reply	other threads:[~2026-12-03  6:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  6:29 [PATCH net v2 0/3] bonding: ignore updelay when no active links " Hangbin Liu
2026-12-01  6:29 ` [PATCH net v2 1/3] Revert "bonding: do not set usable_slaves for broadcast mode" Hangbin Liu
2026-12-03  6:29   ` netdev-bot+sashiko
2026-12-03  7:51     ` Hangbin Liu
2026-12-01  6:29 ` [PATCH net v2 2/3] bonding: update slave array on link change for broadcast mode Hangbin Liu
2026-12-03  6:29   ` netdev-bot+sashiko [this message]
2026-12-03  8:39     ` Hangbin Liu
2026-12-01  6:29 ` [PATCH net v2 3/3] selftests: bonding: add recovery updelay test " Hangbin Liu
2026-12-03  6:29   ` netdev-bot+sashiko
2026-12-01  6:34 ` [PATCH net v2 0/3] bonding: ignore updelay when no active links " netdev-bot+sinfo
2026-12-01  8:38   ` 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=179627939278.3146.9699110701797983880@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hangbin.liu@linux.dev \
    --cc=jiangjiehua1@huawei.com \
    --cc=jv@jvosburgh.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.org \
    --cc=shuah@kernel.org \
    --cc=tonghao@bamaicloud.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®