Skip to contentSkip to conversation

net: bonding: use workqueue to make sure peer notify updated in lacp mode

PATCH In review Tonghao Zhang 2 participants 4 messages Nov 18, 2025 – Nov 23, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: bonding: use workqueue to make sure peer notify updated in lacp mode

The rtnl lock might be locked, preventing ad_cond_set_peer_notif() from acquiring the lock and updating send_peer_notif. This patch addresses the issue by using a workqueue. Since updating send_peer_notif does not require high real-time performance, such delayed updates are entirely acceptable.

In fact, checking send_peer_notif value and using it in multiple places, all operations are protected at the same time by rtnl lock, such as
- read send_peer_notif
- send_peer_notif--
- bond_should_notify_peers

By the way, rtnl lock is still required, when accessing bond.params.* for updating send_peer_notif. In lacp mode, resetting send_peer_notif in workqueue is safe, simple and effective way.

Cc Jay Vosburgh <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Simon Horman <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Nikolay Aleksandrov <[email protected]>
Cc Hangbin Liu <[email protected]>

---
v1:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
v2:
- add more commit message
- the origin patch, which using atomic
- https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

---
 drivers/net/bonding/bond_3ad.c  |  7 ++---
 drivers/net/bonding/bond_main.c | 52 +++++++++++++++++++++++++--------
 include/net/bonding.h           |  2 ++
 3 files changed, 44 insertions(+), 17 deletions(-)
drivers/net/bonding/bond_3ad.c +2 -5
index 49717b7b82a2..d2b324200604 100644
@@ -999,11 +999,8 @@ static void ad_cond_set_peer_notif(struct port *port)
 {
 	struct bonding *bond = port->slave->bond;
 
-	if (bond->params.broadcast_neighbor && rtnl_trylock()) {
-		bond->send_peer_notif = bond->params.num_peer_notif *
-			max(1, bond->params.peer_notif_delay);
-		rtnl_unlock();
-	}
+	if (bond->params.broadcast_neighbor)
+		bond_peer_notify_work_rearm(bond, 0);
 }
 
 /**
drivers/net/bonding/bond_main.c +40 -12

85 lines not on this page · raw message

include/net/bonding.h +2 -0
index 49edc7da0586..63d08056a4a4 100644
@@ -254,6 +254,7 @@ struct bonding {
 	struct   delayed_work ad_work;
 	struct   delayed_work mcast_work;
 	struct   delayed_work slave_arr_work;
+	struct   delayed_work peer_notify_work;
 #ifdef CONFIG_DEBUG_FS
 	/* debugging support via debugfs */
 	struct	 dentry *debug_dir;
@@ -709,6 +710,7 @@ struct bond_vlan_tag *bond_verify_device_path(struct net_device *start_dev,
 					      int level);
 int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave);
 void bond_slave_arr_work_rearm(struct bonding *bond, unsigned long delay);
+void bond_peer_notify_work_rearm(struct bonding *bond, unsigned long delay);
 void bond_work_init_all(struct bonding *bond);
 void bond_work_cancel_all(struct bonding *bond);
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw

drivers/net/bonding/bond_main.c static bool bond_should_notify_peers(struct bonding *bond) · line 1217

Quoted 7 lines · Tonghao Zhang
drivers/net/bonding/bond_main.c +7 -0
+static void bond_peer_notify_handler(struct work_struct *work)
+{
+	struct bonding *bond = container_of(work, struct bonding,
+					    peer_notify_work.work);
+
+	if (!rtnl_trylock())
+		goto rearm;

Why trylock() here? This is process context, you could just call

	rtnl_lock();

and no re-schedule.

/P

maintainer
#2 lore raw
Quoted 11 lines · Paolo Abeni

drivers/net/bonding/bond_main.c static bool bond_should_notify_peers(struct bonding *bond) · line 1217

Quoted 7 lines · Tonghao Zhang
drivers/net/bonding/bond_main.c +7 -0
+static void bond_peer_notify_handler(struct work_struct *work)
+{
+	struct bonding *bond = container_of(work, struct bonding,
+					    peer_notify_work.work);
+
+	if (!rtnl_trylock())
+		goto rearm;

Why trylock() here? This is process context, you could just call

Quoted 3 lines
	rtnl_lock();

and no re-schedule.

Whoops, sorry, I lacked the context. ndo_close() will try to flush the work under the rtnl lock; the workqueue must not block on such lock to avoid deadlock.

Still a comment above would be nice/useful for future memory.

/P

#3 lore raw
Quoted 19 lines · Paolo Abeni
Quoted 13 lines · Paolo Abeni

drivers/net/bonding/bond_main.c static bool bond_should_notify_peers(struct bonding *bond) · line 1217

Quoted 7 lines · Tonghao Zhang
drivers/net/bonding/bond_main.c +7 -0
+static void bond_peer_notify_handler(struct work_struct *work)
+{
+ struct bonding *bond = container_of(work, struct bonding,
+     peer_notify_work.work);
+
+ if (!rtnl_trylock())
+ goto rearm;

Why trylock() here? This is process context, you could just call

rtnl_lock();

Quoted 7 lines
Quoted 1 line

and no re-schedule.

Whoops, sorry, I lacked the context. ndo_close() will try to flush the work under the rtnl lock; the workqueue must not block on such lock to avoid deadlock.

Still a comment above would be nice/useful for future memory.

Yes, I will add a comment in bond_work_init_all(), so if others add new workqueue, they should see the reminder.

Quoted 2 lines

/P