Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: bonding: fix possible peer notify event loss or dup issue

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>
Acked-by: Jay Vosburgh <jv@jvosburgh.net>
Link: https://patch.msgid.link/20251021050933.46412-1-tonghao@bamaicloud.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Tonghao Zhang and committed by
Paolo Abeni
10843e14 c0178eec

+18 -22
+18 -22
drivers/net/bonding/bond_main.c
··· 2874 2874 { 2875 2875 struct bonding *bond = container_of(work, struct bonding, 2876 2876 mii_work.work); 2877 - bool should_notify_peers = false; 2877 + bool should_notify_peers; 2878 2878 bool commit; 2879 2879 unsigned long delay; 2880 2880 struct slave *slave; ··· 2886 2886 goto re_arm; 2887 2887 2888 2888 rcu_read_lock(); 2889 + 2889 2890 should_notify_peers = bond_should_notify_peers(bond); 2890 2891 commit = !!bond_miimon_inspect(bond); 2891 - if (bond->send_peer_notif) { 2892 - rcu_read_unlock(); 2893 - if (rtnl_trylock()) { 2894 - bond->send_peer_notif--; 2895 - rtnl_unlock(); 2896 - } 2897 - } else { 2898 - rcu_read_unlock(); 2899 - } 2900 2892 2901 - if (commit) { 2893 + rcu_read_unlock(); 2894 + 2895 + if (commit || bond->send_peer_notif) { 2902 2896 /* Race avoidance with bond_close cancel of workqueue */ 2903 2897 if (!rtnl_trylock()) { 2904 2898 delay = 1; 2905 - should_notify_peers = false; 2906 2899 goto re_arm; 2907 2900 } 2908 2901 2909 - bond_for_each_slave(bond, slave, iter) { 2910 - bond_commit_link_state(slave, BOND_SLAVE_NOTIFY_LATER); 2902 + if (commit) { 2903 + bond_for_each_slave(bond, slave, iter) { 2904 + bond_commit_link_state(slave, 2905 + BOND_SLAVE_NOTIFY_LATER); 2906 + } 2907 + bond_miimon_commit(bond); 2911 2908 } 2912 - bond_miimon_commit(bond); 2909 + 2910 + if (bond->send_peer_notif) { 2911 + bond->send_peer_notif--; 2912 + if (should_notify_peers) 2913 + call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, 2914 + bond->dev); 2915 + } 2913 2916 2914 2917 rtnl_unlock(); /* might sleep, hold no other locks */ 2915 2918 } ··· 2920 2917 re_arm: 2921 2918 if (bond->params.miimon) 2922 2919 queue_delayed_work(bond->wq, &bond->mii_work, delay); 2923 - 2924 - if (should_notify_peers) { 2925 - if (!rtnl_trylock()) 2926 - return; 2927 - call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, bond->dev); 2928 - rtnl_unlock(); 2929 - } 2930 2920 } 2931 2921 2932 2922 static int bond_upper_dev_walk(struct net_device *upper,