Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2] bonding: fix slave_cnt leak on XDP error paths
@ 2026-09-03  8:10 Hangbin Liu
  2026-09-03  8:18 ` Nikolay Aleksandrov
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Hangbin Liu @ 2026-09-03  8:10 UTC (permalink / raw)
  To: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Daniel Borkmann, Jussi Maki,
	Nikolay Aleksandrov
  Cc: Hangbin Liu, netdev, linux-kernel, Hangbin Liu

From: Hangbin Liu <liuhangbin@kylinos.cn>

When bond_enslave() succeeds up to the XDP setup stage, slave_cnt is
already incremented. If XDP setup subsequently fails, the error paths
jump directly to err_sysfs_del, bypassing the slave_cnt decrement.

This causes slave_cnt to drift upward on each failed enslaving attempt,
which would lead to unbalanced traffic distribution with round-robin
mode.

Fix it by moving the slave_cnt increasement after XDP setup.

Fixes: 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver")
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
Changes in v2:
- move the slave_cnt increasement after XDP setup (Nikolay Aleksandrov)
- balance-xor mode is not affected, not mention it (Nikolay Aleksandrov)
- Link to v1: https://lore.kernel.org/r/20260902-bond_slave_cnt-v1-1-36e95bf4a6ff@kylinos.cn
---
 drivers/net/bonding/bond_main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 947d92a669b6..f3290aee50d1 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -2284,7 +2284,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 		}
 	}
 
-	WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
 	netdev_compute_master_upper_features(bond->dev, true);
 	bond_set_carrier(bond);
 
@@ -2339,6 +2338,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 
 	bond_xdp_set_features(bond_dev);
 
+	WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
+
 	slave_info(bond_dev, slave_dev, "Enslaving as %s interface with %s link\n",
 		   bond_is_active_slave(new_slave) ? "an active" : "a backup",
 		   new_slave->link != BOND_LINK_DOWN ? "an up" : "a down");

---
base-commit: 70f3995830d3f1e79faa14eb0605914f778feca9
change-id: 20260807-bond_slave_cnt-88e78c5f0ab9

Best regards,
-- 
Hangbin Liu <liuhangbin@kylinos.cn>


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-09-04 14:11 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-03  8:10 [PATCH net v2] bonding: fix slave_cnt leak on XDP error paths Hangbin Liu
2026-09-03  8:18 ` Nikolay Aleksandrov
2026-09-03  9:27   ` Hangbin Liu
2026-09-03  9:31     ` Nikolay Aleksandrov
2026-09-03 10:38 ` Matthieu Baerts
2026-09-03 11:53   ` Nikolay Aleksandrov
2026-09-04  1:30     ` Hangbin Liu
2026-09-04  1:40     ` Hangbin Liu
2026-09-04  1:58     ` Hangbin Liu
2026-09-03 16:22   ` Jakub Kicinski
2026-09-04  2:01     ` Hangbin Liu
2026-09-04 14:11 ` [syzbot ci] " syzbot ci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox