]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: bonding: move bond_should_notify_peers, e.g. into rtnl lock block
authorTonghao Zhang <tonghao@bamaicloud.com>
Sun, 18 Jan 2026 04:21:12 +0000 (12:21 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 22 Jan 2026 10:20:33 +0000 (11:20 +0100)
This patch tries to avoid the possible peer notify event loss.

In bond_mii_monitor()/bond_activebackup_arp_mon(), when we hold the rtnl lock:
- check send_peer_notif again to avoid unconditionally reducing this value.
- send_peer_notif may have been reset. Therefore, it is necessary to check
  whether to send peer notify via bond_should_notify_peers() to avoid the
  loss of notification events.

Cc: Jay Vosburgh <jv@jvosburgh.net>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>
Cc: Nikolay Aleksandrov <razor@blackwall.org>
Cc: Hangbin Liu <liuhangbin@gmail.com>
Cc: Jason Xing <kerneljasonxing@gmail.com>
Signed-off-by: Tonghao Zhang <tonghao@bamaicloud.com>
Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>
Link: https://patch.msgid.link/78cef328822b94638c97638b89011c507b8bf19e.1768709239.git.tonghao@bamaicloud.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/bonding/bond_main.c

index 353b0c8a0ca720905b9c4bccc4883765cdbe4544..16418e1dc10ab900163b0da03f4f3efbed0fea6b 100644 (file)
@@ -2816,11 +2816,10 @@ static void bond_mii_monitor(struct work_struct *work)
 {
        struct bonding *bond = container_of(work, struct bonding,
                                            mii_work.work);
-       bool should_notify_peers;
-       bool commit;
-       unsigned long delay;
-       struct slave *slave;
        struct list_head *iter;
+       struct slave *slave;
+       unsigned long delay;
+       bool commit;
 
        delay = msecs_to_jiffies(bond->params.miimon);
 
@@ -2829,7 +2828,6 @@ static void bond_mii_monitor(struct work_struct *work)
 
        rcu_read_lock();
 
-       should_notify_peers = bond_should_notify_peers(bond);
        commit = !!bond_miimon_inspect(bond);
 
        rcu_read_unlock();
@@ -2849,12 +2847,8 @@ static void bond_mii_monitor(struct work_struct *work)
                        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);
-               }
+               if (bond->send_peer_notif)
+                       bond_peer_notify_may_events(bond, true);
 
                rtnl_unlock();  /* might sleep, hold no other locks */
        }
@@ -3765,7 +3759,6 @@ check_state:
 
 static void bond_activebackup_arp_mon(struct bonding *bond)
 {
-       bool should_notify_peers = false;
        bool should_notify_rtnl = false;
        int delta_in_ticks;
 
@@ -3776,15 +3769,12 @@ static void bond_activebackup_arp_mon(struct bonding *bond)
 
        rcu_read_lock();
 
-       should_notify_peers = bond_should_notify_peers(bond);
-
        if (bond_ab_arp_inspect(bond)) {
                rcu_read_unlock();
 
                /* Race avoidance with bond_close flush of workqueue */
                if (!rtnl_trylock()) {
                        delta_in_ticks = 1;
-                       should_notify_peers = false;
                        goto re_arm;
                }
 
@@ -3801,15 +3791,13 @@ re_arm:
        if (bond->params.arp_interval)
                queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks);
 
-       if (should_notify_peers || should_notify_rtnl) {
+       if (bond->send_peer_notif || should_notify_rtnl) {
                if (!rtnl_trylock())
                        return;
 
-               if (should_notify_peers) {
-                       bond->send_peer_notif--;
-                       call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
-                                                bond->dev);
-               }
+               if (bond->send_peer_notif)
+                       bond_peer_notify_may_events(bond, true);
+
                if (should_notify_rtnl) {
                        bond_slave_state_notify(bond);
                        bond_slave_link_notify(bond);