Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v3] bonding: check XDP support before enslaving changes state
@ 2026-11-30  4:47 Hangbin Liu
  2026-12-06  4:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Hangbin Liu @ 2026-11-30  4:47 UTC (permalink / raw)
  To: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Nikolay Aleksandrov
  Cc: Hangbin Liu, netdev, linux-kernel, bpf, Hangbin Liu

From: Hangbin Liu <liuhangbin@kylinos.cn>

The XDP capability checks in bond_enslave() - ndo_bpf/ndo_xdp_xmit
presence and whether the slave already runs an XDP program - run only
after the slave has been opened, linked and published to the
datapath. On failure the slave may already be bond->curr_active_slave
or reachable through bond->slave_cnt and the upper device list, so a
lot of state has to be undone, and bond_xdp_xmit() can observe the
slave before its capability was ever verified.

Move both checks into the validation section at the top of
bond_enslave(), before the first state change, so a rejected slave
returns directly with nothing mutated. bond_xdp_set() repeats the
same two checks for every slave, so factor them into a common
bond_slave_xdp_check() helper used by both paths.

Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
For Sashiko:

Please ignore the bond's promiscuity/allmulti/ns maddrs leak issue
when xdp setup failed. It will be addressed in another patch.

Please ignore the no unwind for bond_3ad_bind_slave if
dev_xdp_propagate failed. It will be addressed in another patch.
---
Changes in v3:
- rebase to latest net-next, no code change
- Link to v2: https://patch.msgid.link/20261127-bond_xdp_fix-v2-1-1e05818a41ef@kylinos.cn

Changes in v2:
- move the duplicate checking in bond_xdp_set to the new check function.
- Move the bond_xdp_xmit() fix in another patch and target to net (sashiko)
- Link to v1: https://patch.msgid.link/20261124-bond_xdp_fix-v1-1-e67983924324@kylinos.cn
---
 drivers/net/bonding/bond_main.c | 58 ++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 754048ef4835..23f78f0f80fc 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1866,6 +1866,26 @@ static void bond_ether_setup(struct net_device *bond_dev)
 	bond_dev->priv_flags &= ~IFF_TX_SKB_SHARING;
 }
 
+static int bond_slave_xdp_check(struct net_device *bond_dev,
+				struct net_device *slave_dev,
+				struct netlink_ext_ack *extack)
+{
+	if (!slave_dev->netdev_ops->ndo_bpf ||
+	    !slave_dev->netdev_ops->ndo_xdp_xmit) {
+		SLAVE_NL_ERR(bond_dev, slave_dev, extack,
+			     "Slave does not support XDP");
+		return -EOPNOTSUPP;
+	}
+
+	if (dev_xdp_has_own_prog(slave_dev)) {
+		SLAVE_NL_ERR(bond_dev, slave_dev, extack,
+			     "Slave has XDP program loaded, please unload before enslaving");
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
 void bond_xdp_set_features(struct net_device *bond_dev)
 {
 	struct bonding *bond = netdev_priv(bond_dev);
@@ -1962,6 +1982,12 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 		return -EINVAL;
 	}
 
+	if (bond->xdp_prog) {
+		res = bond_slave_xdp_check(bond_dev, slave_dev, extack);
+		if (res)
+			return res;
+	}
+
 	/* set bonding device ether type by slave - bonding netdevices are
 	 * created with ether_setup, so when the slave type is not ARPHRD_ETHER
 	 * there is a need to override some of the type dependent attribs/funcs.
@@ -2319,15 +2345,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 		unblock_netpoll_tx();
 	}
 
-	if (!slave_dev->netdev_ops->ndo_bpf ||
-	    !slave_dev->netdev_ops->ndo_xdp_xmit) {
-		if (bond->xdp_prog) {
-			SLAVE_NL_ERR(bond_dev, slave_dev, extack,
-				     "Slave does not support XDP");
-			res = -EOPNOTSUPP;
-			goto err_dec_slave_cnt;
-		}
-	} else if (bond->xdp_prog) {
+	if (bond->xdp_prog) {
 		struct netdev_bpf xdp = {
 			.command = XDP_SETUP_PROG,
 			.flags   = 0,
@@ -2335,13 +2353,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 			.extack  = extack,
 		};
 
-		if (dev_xdp_has_own_prog(slave_dev)) {
-			SLAVE_NL_ERR(bond_dev, slave_dev, extack,
-				     "Slave has XDP program loaded, please unload before enslaving");
-			res = -EOPNOTSUPP;
-			goto err_dec_slave_cnt;
-		}
-
 		res = dev_xdp_propagate(slave_dev, &xdp);
 		if (res < 0) {
 			/* ndo_bpf() sets extack error message */
@@ -5740,20 +5751,9 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog,
 	bond_for_each_slave(bond, slave, iter) {
 		struct net_device *slave_dev = slave->dev;
 
-		if (!slave_dev->netdev_ops->ndo_bpf ||
-		    !slave_dev->netdev_ops->ndo_xdp_xmit) {
-			SLAVE_NL_ERR(dev, slave_dev, extack,
-				     "Slave device does not support XDP");
-			err = -EOPNOTSUPP;
+		err = bond_slave_xdp_check(dev, slave_dev, extack);
+		if (err)
 			goto err;
-		}
-
-		if (dev_xdp_has_own_prog(slave_dev)) {
-			SLAVE_NL_ERR(dev, slave_dev, extack,
-				     "Slave has XDP program loaded, please unload before enslaving");
-			err = -EOPNOTSUPP;
-			goto err;
-		}
 
 		err = dev_xdp_propagate(slave_dev, &xdp);
 		if (err < 0) {

---
base-commit: 81159a672c331993566a12ad8e07532b38355cba
change-id: 20261124-bond_xdp_fix-3f5eb6533f50

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


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

* Re: [PATCH net-next v3] bonding: check XDP support before enslaving changes state
  2026-11-30  4:47 [PATCH net-next v3] bonding: check XDP support before enslaving changes state Hangbin Liu
@ 2026-12-06  4:20 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-12-06  4:20 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: jv, andrew+netdev, davem, edumazet, kuba, pabeni, ast, daniel,
	hawk, john.fastabend, sdf, razor, netdev, linux-kernel, bpf

Hello:

This patch was applied to netdev/net-next.git (main)
by Willem de Bruijn <willemb@google.com>:

On Mon, 30 Nov 2026 12:47:09 +0800 you wrote:
> From: Hangbin Liu <liuhangbin@kylinos.cn>
> 
> The XDP capability checks in bond_enslave() - ndo_bpf/ndo_xdp_xmit
> presence and whether the slave already runs an XDP program - run only
> after the slave has been opened, linked and published to the
> datapath. On failure the slave may already be bond->curr_active_slave
> or reachable through bond->slave_cnt and the upper device list, so a
> lot of state has to be undone, and bond_xdp_xmit() can observe the
> slave before its capability was ever verified.
> 
> [...]

Here is the summary with links:
  - [net-next,v3] bonding: check XDP support before enslaving changes state
    https://git.kernel.org/netdev/net-next/c/88aad5958aed

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-12-06  4:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  4:47 [PATCH net-next v3] bonding: check XDP support before enslaving changes state Hangbin Liu
2026-12-06  4:20 ` patchwork-bot+netdevbpf

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