netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jay Vosburgh <jv@jvosburgh.net>
To: Tonghao Zhang <tonghao@bamaicloud.com>
Cc: netdev@vger.kernel.org, Andrew Lunn <andrew+netdev@lunn.ch>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Hangbin Liu <liuhangbin@gmail.com>,
	Nikolay Aleksandrov <razor@blackwall.org>,
	Vincent Bernat <vincent@bernat.ch>,
	stable@vger.kernel.org
Subject: Re: [PATCH net] net: bonding: fix possible peer notify event loss or dup issue
Date: Tue, 21 Oct 2025 18:08:05 -0700	[thread overview]
Message-ID: <953400.1761095285@famine> (raw)
In-Reply-To: <20251021050933.46412-1-tonghao@bamaicloud.com>

Tonghao Zhang <tonghao@bamaicloud.com> wrote:

>If the send_peer_notif counter and the peer event notify are not synchronized.
>It may cause problems such as the loss or dup of peer notify event.
>
>Before this patch:
>- If should_notify_peers is true and the lock for send_peer_notif-- fails, peer
>  event may be sent again in next mii_monitor loop, because should_notify_peers
>  is still true.
>- If should_notify_peers is true and the lock for send_peer_notif-- succeeded,
>  but the lock for peer event fails, the peer event will be lost.
>
>This patch locks the RTNL for send_peer_notif, events, and commit simultaneously.
>
>Fixes: 07a4ddec3ce9 ("bonding: add an option to specify a delay between peer notifications")
>Cc: Jay Vosburgh <jv@jvosburgh.net>
>Cc: Andrew Lunn <andrew+netdev@lunn.ch>
>Cc: Eric Dumazet <edumazet@google.com>
>Cc: Jakub Kicinski <kuba@kernel.org>
>Cc: Paolo Abeni <pabeni@redhat.com>
>Cc: Hangbin Liu <liuhangbin@gmail.com>
>Cc: Nikolay Aleksandrov <razor@blackwall.org>
>Cc: Vincent Bernat <vincent@bernat.ch>
>Cc: <stable@vger.kernel.org>
>Signed-off-by: Tonghao Zhang <tonghao@bamaicloud.com>

	I'll note that this appears to preserve the ordering of the
various events (commit, link state, notify peers).

	-J

Acked-by: Jay Vosburgh <jv@jvosburgh.net>


>---
> drivers/net/bonding/bond_main.c | 40 +++++++++++++++------------------
> 1 file changed, 18 insertions(+), 22 deletions(-)
>
>diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
>index 5791c3e39baa..52b7ac8ddfbc 100644
>--- a/drivers/net/bonding/bond_main.c
>+++ b/drivers/net/bonding/bond_main.c
>@@ -2971,7 +2971,7 @@ static void bond_mii_monitor(struct work_struct *work)
> {
> 	struct bonding *bond = container_of(work, struct bonding,
> 					    mii_work.work);
>-	bool should_notify_peers = false;
>+	bool should_notify_peers;
> 	bool commit;
> 	unsigned long delay;
> 	struct slave *slave;
>@@ -2983,30 +2983,33 @@ static void bond_mii_monitor(struct work_struct *work)
> 		goto re_arm;
> 
> 	rcu_read_lock();
>+
> 	should_notify_peers = bond_should_notify_peers(bond);
> 	commit = !!bond_miimon_inspect(bond);
>-	if (bond->send_peer_notif) {
>-		rcu_read_unlock();
>-		if (rtnl_trylock()) {
>-			bond->send_peer_notif--;
>-			rtnl_unlock();
>-		}
>-	} else {
>-		rcu_read_unlock();
>-	}
> 
>-	if (commit) {
>+	rcu_read_unlock();
>+
>+	if (commit || bond->send_peer_notif) {
> 		/* Race avoidance with bond_close cancel of workqueue */
> 		if (!rtnl_trylock()) {
> 			delay = 1;
>-			should_notify_peers = false;
> 			goto re_arm;
> 		}
> 
>-		bond_for_each_slave(bond, slave, iter) {
>-			bond_commit_link_state(slave, BOND_SLAVE_NOTIFY_LATER);
>+		if (commit) {
>+			bond_for_each_slave(bond, slave, iter) {
>+				bond_commit_link_state(slave,
>+						       BOND_SLAVE_NOTIFY_LATER);
>+			}
>+			bond_miimon_commit(bond);
>+		}
>+
>+		if (bond->send_peer_notif) {
>+			bond->send_peer_notif--;
>+			if (should_notify_peers)
>+				call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
>+							 bond->dev);
> 		}
>-		bond_miimon_commit(bond);
> 
> 		rtnl_unlock();	/* might sleep, hold no other locks */
> 	}
>@@ -3014,13 +3017,6 @@ static void bond_mii_monitor(struct work_struct *work)
> re_arm:
> 	if (bond->params.miimon)
> 		queue_delayed_work(bond->wq, &bond->mii_work, delay);
>-
>-	if (should_notify_peers) {
>-		if (!rtnl_trylock())
>-			return;
>-		call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, bond->dev);
>-		rtnl_unlock();
>-	}
> }
> 
> static int bond_upper_dev_walk(struct net_device *upper,
>-- 
>2.34.1
>

---
	-Jay Vosburgh, jv@jvosburgh.net

  reply	other threads:[~2025-10-22  1:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-21  5:09 [PATCH net] net: bonding: fix possible peer notify event loss or dup issue Tonghao Zhang
2025-10-22  1:08 ` Jay Vosburgh [this message]
2025-10-23 11:20 ` patchwork-bot+netdevbpf

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=953400.1761095285@famine \
    --to=jv@jvosburgh.net \
    --cc=andrew+netdev@lunn.ch \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=liuhangbin@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.org \
    --cc=stable@vger.kernel.org \
    --cc=tonghao@bamaicloud.com \
    --cc=vincent@bernat.ch \
    /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;
as well as URLs for NNTP newsgroup(s).