* [PATCH net-next v2] bonding: check XDP support before enslaving changes state
@ 2026-11-27 6:37 Hangbin Liu
2026-11-30 4:34 ` Hangbin Liu
0 siblings, 1 reply; 2+ messages in thread
From: Hangbin Liu @ 2026-11-27 6:37 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 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 de933245b12b..757ab7fa63ee 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);
@@ -1955,6 +1975,12 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
return -EPERM;
}
+ 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.
@@ -2318,15 +2344,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,
@@ -2334,13 +2352,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 */
@@ -5735,20 +5746,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: ccb81d5e317b0ae2cc66ca1c628c0ca907928f94
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 v2] bonding: check XDP support before enslaving changes state
2026-11-27 6:37 [PATCH net-next v2] bonding: check XDP support before enslaving changes state Hangbin Liu
@ 2026-11-30 4:34 ` Hangbin Liu
0 siblings, 0 replies; 2+ messages in thread
From: Hangbin Liu @ 2026-11-30 4:34 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: netdev, linux-kernel, bpf
On Fri, Nov 27, 2026 at 02:37:28PM +0800, Hangbin Liu 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.
>
> 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 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
> ---
Patch doesn't apply to latest net-next due to recent 802.3ad update.
I will rebase the code and repost a new version.
---
pw-bot: cr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 4:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 6:37 [PATCH net-next v2] bonding: check XDP support before enslaving changes state Hangbin Liu
2026-11-30 4:34 ` Hangbin Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox