net: make xdp config checks effective vs netif_xdp_propagate()
Subsystems (9)
Jakub Kicinski
maintainercover net: make xdp config checks effective vs netif_xdp_propagate()
Bonding (and netvsc) try to auto-propagate XDP programs down to their lower devices. These programs were installed directly with .ndo_bpf and not recorded in struct net_device of the lowers. This makes all the config checks for features incompatible with XDP ineffective - HDS, memory providers etc. use dev_xdp_prog_count() and do not call down to the driver to ask it whether it has XDP installed.
Record the state appropriately. dev_xdp_prog_count() will now "see" the propagated programs.
The issue was discovered when reworking HW-GRO and XDP interactions. I was trying to make sure HW-GRO is reliably disabled with XDP, and discovered we have a way to bypass all checks with bonding. Not treating this as a fix since it's admin-only self-inflicted damage that nobody is reporting being bothered by in real life.
Jakub Kicinski (5):
net: don't safety-check device features for XDP uninstall
net: move dev_xdp_set_link() and dev_xdp_set_prog() up
net: record XDP programs propagated to lower devices selftests/bpf: check XDP attach on a nested bond slave selftests/bpf: check replacing and detaching XDP on a bond through a
link
.../networking/net_cachelines/net_device.rst | 1 + include/linux/netdevice.h | 7 + drivers/net/bonding/bond_main.c | 4 +- drivers/net/hyperv/netvsc_bpf.c | 2 +- drivers/net/hyperv/netvsc_drv.c | 5 +- net/core/dev.c | 133 ++++++++++++------ .../selftests/bpf/prog_tests/xdp_bonding.c | 120 +++++++++++++++- 7 files changed, 224 insertions(+), 48 deletions(-)
Signature · 1 line
2.56.0
Jakub Kicinski
maintainerPATCH 1/5 net: don't safety-check device features for XDP uninstall
Commit ad27ed7d2309 ("bpf, xdp: move offload check into dev_xdp_install()") lifted the safety checks from dev_xdp_attach() to dev_xdp_install() to cover more paths. Since all these checks are prog
related they are under one big "if (prog)".
Lift the pre-existing checks under "if (prog)" as well, and do the same thing in netif_xdp_propagate(). This way we don't have to worry about triggering WARN()s on cleanup paths mistakenly trying to un-install a program when there is none, and failing because device has a memory provider.
This is a refactoring / consistency cleanup, later patches don't depend on this change.
--- net/core/dev.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-)
net/core/dev.c +27 -21
@@ -10580,17 +10580,23 @@ int netif_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf)if (!dev->netdev_ops->ndo_bpf)return -EOPNOTSUPP ; -if (dev->cfg->hds_config ==ETHTOOL_TCP_DATA_SPLIT_ENABLED && - bpf->command ==XDP_SETUP_PROG && - bpf->prog && !bpf->prog->aux->xdp_has_frags) { -NL_SET_ERR_MSG (bpf->extack, -"unable to propagate XDP to device using tcp-data-split" ); -return -EBUSY ; - } +/* setup requires extra handling, bypass those for other commands */ +if (bpf->command !=XDP_SETUP_PROG ) +return dev->netdev_ops->ndo_bpf (dev, bpf); -if (dev_get_min_mp_channel_count (dev)) { -NL_SET_ERR_MSG (bpf->extack,"unable to propagate XDP to device using memory provider" ); -return -EBUSY ; +if (bpf->prog) { +if (dev->cfg->hds_config ==ETHTOOL_TCP_DATA_SPLIT_ENABLED && + !bpf->prog->aux->xdp_has_frags) { +NL_SET_ERR_MSG (bpf->extack, +"unable to propagate XDP to device using tcp-data-split" ); +return -EBUSY ; + } + +if (dev_get_min_mp_channel_count (dev)) { +NL_SET_ERR_MSG (bpf->extack, +"unable to propagate XDP to device using memory provider" ); +return -EBUSY ; + } }return dev->netdev_ops->ndo_bpf (dev, bpf);
@@ -10656,17 +10662,17 @@ static int dev_xdp_install(struct net_device *dev, enum bpf_xdp_mode mode,NL_SET_ERR_MSG (extack,"BPF_XDP_CPUMAP programs can not be attached to a device" );return -EINVAL ; } - } - -if (dev->cfg->hds_config ==ETHTOOL_TCP_DATA_SPLIT_ENABLED && - prog && !prog->aux->xdp_has_frags) { -NL_SET_ERR_MSG (extack,"unable to install XDP to device using tcp-data-split" ); -return -EBUSY ; - } - -if (dev_get_min_mp_channel_count (dev)) { -NL_SET_ERR_MSG (extack,"unable to install XDP to device using memory provider" ); -return -EBUSY ; +if (dev->cfg->hds_config ==ETHTOOL_TCP_DATA_SPLIT_ENABLED && + !prog->aux->xdp_has_frags) { +NL_SET_ERR_MSG (extack, +"unable to install XDP to device using tcp-data-split" ); +return -EBUSY ; + } +if (dev_get_min_mp_channel_count (dev)) { +NL_SET_ERR_MSG (extack, +"unable to install XDP to device using memory provider" ); +return -EBUSY ; + } }memset (&xdp,0 ,sizeof (xdp));
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH net-next 1/5] net: don't safety-check device features for XDP uninstall
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message of "net: don't safety-check device features for XDP uninstall" calls the change a "refactoring / consistency…
--
net: don't safety-check device features for XDP uninstall
This moves the tcp-data-split and memory provider checks in dev_xdp_install() and netif_xdp_propagate() under "if (prog)", so they only run when a program is being installed. netif_xdp_propagate() also now hands commands other than XDP_SETUP_PROG straight to ndo_bpf.
Quoted 7 lines
This way we don't have to worry about triggering WARN()s on cleanup paths mistakenly trying to un-install a program when there is none, and failing because device has a memory provider.
This is a refactoring / consistency cleanup, later patches don't depend on this change.
[Severity: Low]
Is this really only a cleanup? It looks like it also fixes an XDP uninstall failure that can be hit in the current tree.
Before this patch, netif_xdp_propagate() ran the memory provider check unconditionally, so it also refused to propagate prog == NULL:
net/core/dev.c:netif_xdp_propagate() {
...
if (dev_get_min_mp_channel_count(dev)) {
NL_SET_ERR_MSG(bpf->extack, "unable to propagate XDP to device using memory provider");
return -EBUSY;
}
...
}A lower device can run a program propagated from an upper device and also have a memory provider bound. At this point in the tree, netif_xdp_propagate() does not record the propagated program in the lower device's xdp_state, so the reverse checks pass. __netif_mp_open_rxq() only checks dev_xdp_prog_count(dev), and ethnl_set_rings() only checks dev_xdp_sb_prog_count().
When a bond slave is in that state, removing XDP from the bond fails:
bond_xdp_set(bond_dev, NULL)
dev_xdp_propagate(slave_dev, &xdp) /* xdp.prog == NULL */
netif_xdp_propagate()
dev_get_min_mp_channel_count(dev) != 0 -> -EBUSYbond_xdp_set() then rolls back, so XDP cannot be removed from the bond.
In __bond_release_one() the same failure only prints a warning:
if (dev_xdp_propagate(slave_dev, &xdp)) slave_warn(bond_dev, slave_dev, "failed to unload XDP program\n");
The released slave keeps running the bond's program, and nothing about it is in the slave's xdp_state. The program then cannot be seen or removed through that device. netvsc_vf_setxdp(vf, NULL) fails the same way.
The check being relaxed here came from commit 170aafe35cb9 ("netdev:
support binding dma-buf to netdevice"), which is in current LTS trees.
Should this patch have a Fixes: tag for that commit? Could the commit message also describe the uninstall failure, rather than calling the change a refactoring?
A later patch in this series, "net: record XDP programs propagated to lower devices", fixes the root cause (a memory provider coexisting with a propagated program). That patch has no Fixes: tag either.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112235027.4072149-1-kuba%40kernel.org
Jakub Kicinski
maintainerRe: [PATCH net-next 1/5] net: don't safety-check device features for XDP uninstall
Quoted 2 lines · On Fri, 13 Nov 2026 23:53:14 +0000 [email protected] wrote:
Is this really only a cleanup? It looks like it also fixes an XDP uninstall failure that can be hit in the current tree.
TBH it's been a while since I wrote this commit so I could be misremembering, but IIRC what I mean to say in the commit msg is that I wrote the patch because the shape of the code was annoying me. There _may_ be some cases where we already got into bad state which this fixes. But fixing any specific case wasn't what made me write the patch. (And the whole XDP prog state got desynced area has too many bugs to claim this moves the needle).
Jakub Kicinski
maintainerPATCH 2/5 net: move dev_xdp_set_link() and dev_xdp_set_prog() up
In reply to Jakub Kicinskinetif_xdp_propagate() will need dev_xdp_set_prog() in the next patch. Move both helpers above it, no functional change.
--- net/core/dev.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
net/core/dev.c +14 -14
@@ -10575,6 +10575,20 @@ u8 dev_xdp_sb_prog_count(struct net_device *dev)return count; } +static void dev_xdp_set_link (struct net_device *dev,enum bpf_xdp_mode mode, +struct bpf_xdp_link *link) +{ + dev->xdp_state[mode].link = link; + dev->xdp_state[mode].prog =NULL ; +} + +static void dev_xdp_set_prog (struct net_device *dev,enum bpf_xdp_mode mode, +struct bpf_prog *prog) +{ + dev->xdp_state[mode].link =NULL ; + dev->xdp_state[mode].prog = prog; +} +int netif_xdp_propagate (struct net_device *dev,struct netdev_bpf *bpf) {if (!dev->netdev_ops->ndo_bpf)
@@ -10610,20 +10624,6 @@ u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode)return prog ? prog->aux->id :0 ; } -static void dev_xdp_set_link (struct net_device *dev,enum bpf_xdp_mode mode, -struct bpf_xdp_link *link) -{ - dev->xdp_state[mode].link = link; - dev->xdp_state[mode].prog =NULL ; -} - -static void dev_xdp_set_prog (struct net_device *dev,enum bpf_xdp_mode mode, -struct bpf_prog *prog) -{ - dev->xdp_state[mode].link =NULL ; - dev->xdp_state[mode].prog = prog; -} -static int dev_xdp_install (struct net_device *dev,enum bpf_xdp_mode mode,bpf_op_t bpf_op,struct netlink_ext_ack *extack,u32 flags,struct bpf_prog *prog)
Signature · 1 line
2.56.0
Jakub Kicinski
maintainerPATCH 3/5 net: record XDP programs propagated to lower devices
In reply to Jakub KicinskiAn upper device installs its XDP program on each lower with dev_xdp_propagate(), which calls ndo_bpf() directly and records nothing in the lower's xdp_state[]. netif_xdp_propagate() open-codes two of the checks dev_xdp_install() makes, but the lower still looks program-free to everything else, so the checks made in the opposite direction miss it entirely:
ethtool -G $slave tcp-data-split on
is refused by dev_xdp_sb_prog_count() for a device running a single-buffer XDP program, but not for a bond slave running the bond's, even though netif_xdp_propagate() would have refused to install that same program had header-data split been on already. Binding a memory provider has the same asymmetry. The lower does not report the program over rtnetlink either, so it is invisible to userspace as well.
Install it into xdp_state[] like any other program and mark it with xdp_from_upper, rather than tracking it separately. Every other user of dev_xdp_prog_count() and dev_xdp_sb_prog_count() then gets the right answer with no changes. The flag is only needed where the owner matters:
bonding and netvsc read it to tell a lower's own program apart from the one they pushed down, to refuse taking over such a device, and to let their own program be replaced and taken back, and dev_xdp_attach() reads it to keep the program from being replaced or removed behind the upper's back.
The lower now holds its own reference and its own registration with the XDP dispatcher, as it does for a program of its own, so that tearing it down through dev_xdp_uninstall() when the lower goes away first stays balanced. The upper's per-lower reference for the driver is unchanged.
An upper is expected to propagate NULL before it unlinks, but the lower may refuse it - bonding and netvsc then only warn, and the program keeps running. So when the master unlinks, let the device own whatever is left rather than leave it with nobody allowed to remove it.
While here, refuse to propagate onto a device which has a program of its own, the counterpart of the new check in dev_xdp_attach(). Bonding and netvsc already check for this before taking a device over and before installing.
---
v2:
- register the lower's program with the XDP dispatcher as well, so that dev_xdp_uninstall() of the lower stays balanced
- let the device own a program left behind when its master unlinks
- refuse removing the device's own program too, not only replacing it
- assert the lower's ops lock in netif_xdp_propagate()
- convert netvsc's checks of its VF to dev_xdp_has_own_prog()
- split out moving dev_xdp_set_link() and dev_xdp_set_prog() up
v1: https://lore.kernel.org/[email protected]
--- .../networking/net_cachelines/net_device.rst | 1 + include/linux/netdevice.h | 7 +++ drivers/net/bonding/bond_main.c | 4 +- drivers/net/hyperv/netvsc_bpf.c | 2 +- drivers/net/hyperv/netvsc_drv.c | 5 +- net/core/dev.c | 49 ++++++++++++++++++- 6 files changed, 62 insertions(+), 6 deletions(-)
Documentation/networking/net_cachelines/net_device.rst +1 -0
@@ -169,6 +169,7 @@ unsigned_long:1 see_all_hwtstamp_requests unsigned_long:1 change_proto_down unsigned_long:1 netns_immutable unsigned_long:1 fcoe_mtu +unsigned_long:1 xdp_from_upper struct list_head net_notifier_list struct macsec_ops* macsec_ops struct udp_tunnel_nic_info* udp_tunnel_nic_info
include/linux/netdevice.h +7 -0
@@ -2531,6 +2531,12 @@ struct net_device { unsigned long change_proto_down:1; unsigned long netns_immutable:1; unsigned long fcoe_mtu:1; +/** +* @xdp_from_upper: the program in @xdp_state was installed by an +* upper device with netif_xdp_propagate(); it belongs to the +* upper and can't be replaced or removed through this device. +*/ + unsigned long xdp_from_upper:1;struct list_head net_notifier_list;
@@ -4445,6 +4451,7 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,int bpf_xdp_link_attach (const union bpf_attr *attr,struct bpf_prog *prog);u8 dev_xdp_prog_count (struct net_device *dev); +bool dev_xdp_has_own_prog (struct net_device *dev);int netif_xdp_propagate (struct net_device *dev,struct netdev_bpf *bpf);int dev_xdp_propagate (struct net_device *dev,struct netdev_bpf *bpf);u8 dev_xdp_sb_prog_count (struct net_device *dev);
drivers/net/bonding/bond_main.c +2 -2
@@ -2327,7 +2327,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, .extack = extack, }; -if (dev_xdp_prog_count (slave_dev) >0 ) { +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 ;
@@ -5736,7 +5736,7 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog, goto err; } -if (dev_xdp_prog_count (slave_dev) >0 ) { +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 ;
drivers/net/hyperv/netvsc_bpf.c +1 -1
@@ -228,7 +228,7 @@ int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf)/* The VF's own program is not ours: refuse to install over * it, as bonding does, and leave it be on removal. */ -if (vf_netdev &&dev_xdp_prog_count (vf_netdev)) { +if (vf_netdev &&dev_xdp_has_own_prog (vf_netdev)) {if (bpf->prog) {NL_SET_ERR_MSG_MOD (extack,"VF has an XDP program of its own" );
drivers/net/hyperv/netvsc_drv.c +3 -2
@@ -2332,7 +2332,7 @@ static int netvsc_register_vf(struct net_device *vf_netdev, int context)return NOTIFY_DONE ; prog =netvsc_xdp_get (netvsc_dev); -if (prog &&dev_xdp_prog_count (vf_netdev)) { +if (prog &&dev_xdp_has_own_prog (vf_netdev)) {netdev_warn (ndev,"not using VF %s, it has an XDP program attached\n" , vf_netdev->name);return NOTIFY_DONE ;
@@ -2485,7 +2485,8 @@ static int netvsc_unregister_vf(struct net_device *vf_netdev)* reach netvsc, but leave a program of the VF's own be. */ nvdev =rtnl_dereference (net_device_ctx->nvdev); -if (nvdev &&netvsc_xdp_get (nvdev) && !dev_xdp_prog_count (vf_netdev)) { +if (nvdev &&netvsc_xdp_get (nvdev) && + !dev_xdp_has_own_prog (vf_netdev)) {netdev_lock_ops (vf_netdev); ret =netvsc_vf_setxdp (vf_netdev,NULL );netdev_unlock_ops (vf_netdev);
net/core/dev.c +48 -1
91 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH net-next 3/5] net: record XDP programs propagated to lower devices
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] netvsc_register_vf() (drivers/net/hyperv/netvsc_drv.c) calls netvsc_vf_setxdp(vf_netdev, prog) before netvsc_vf_join() has created…
- [Low] The commit fixes a user-visible bug but has no Fixes: tag.
- [Low] dev_xdp_attach() in net/core/dev.c now checks dev->xdp_from_upper before the existing 'don't allow if an upper device already has a…
- [Low] The comment on dev_xdp_has_own_prog() in net/core/dev.c says it answers 'was it installed directly on the device rather than…
--
net: record XDP programs propagated to lower devices
This commit records XDP programs that an upper device propagates to its lowers in the lower's xdp_state[], and marks them with a new xdp_from_upper flag. It adds dev_xdp_has_own_prog() so bonding and netvsc can tell a lower's own program apart from theirs, and refuses attach on a lower while the flag is set. The flag is cleared when the master unlinks.
Quoted 7 lines
ethtool -G $slave tcp-data-split on
is refused by
dev_xdp_sb_prog_count()for a device running a single-buffer XDP program, but not for a bond slave running the bond's, even thoughnetif_xdp_propagate()would have refused to install that same program had header-data split been on already. Binding a memory provider has the same asymmetry.
[Severity: Low]
This describes a user-visible bug, but there is no Fixes: tag. The install-direction checks in netif_xdp_propagate() came from these commits, and neither of them covered the reverse direction:
2d46e481a9af ("net: disallow setup single buffer XDP when tcp-data-split is enabled.") 170aafe35cb9 ("netdev: support binding dma-buf to netdevice")
Should the commit carry Fixes: tags for them?
Quoted 5 lines
net/core/dev.c +0
-0
net/core/dev.c static void __netdev_upper_dev_unlink(struct net_device *dev, · line 9334
Quoted 9 lines
net/core/dev.c +3
-0@@ -9326,6 +9326,9 @@ static void __netdev_upper_dev_unlink(struct net_device *dev,__netdev_adjacent_dev_unlink_neighbour (dev, upper_dev); +if (changeupper_info.master) + dev->xdp_from_upper =0 ; +call_netdevice_notifiers_info (NETDEV_CHANGEUPPER , &changeupper_info.info);
[Severity: Medium]
The commit message says that clearing the flag here lets the device own a leftover program "rather than leave it with nobody allowed to remove it". Can a lower end up with xdp_from_upper set when no master link was ever created, so that this code never runs?
netvsc_register_vf() propagates netvsc's program before it joins:
ret = netvsc_vf_setxdp(vf_netdev, prog);
...
if (netvsc_vf_join(vf_netdev, ndev, context) != 0) {
ret = prog ? netvsc_vf_setxdp(vf_netdev, NULL) : 0;
if (ret)
netdev_warn(ndev,
"failed to remove XDP program from VF %s: %d\n",
vf_netdev->name, ret);
return NOTIFY_DONE;
}The first call stores the program in vf_netdev->xdp_state[XDP_MODE_DRV] and sets xdp_from_upper. netvsc_vf_join() can fail in netdev_rx_handler_register() or in netdev_master_upper_dev_link(). Both failure paths return without a master link.
If the driver's ndo_bpf() then refuses the NULL program, netif_xdp_propagate() returns before it touches xdp_state[] or the flag:
err = dev->netdev_ops->ndo_bpf(dev, bpf);
if (err)
return err;netvsc returns NOTIFY_DONE without storing the VF in net_device_ctx->vf_netdev, so it never comes back to this VF. No master was linked, so __netdev_upper_dev_unlink() never clears the flag. Only dev_xdp_uninstall() at unregister does.
Quoted 1 line
From then on, every
IFLA_XDPset or remove and every BPF link attach on
the VF hits the new -EBUSY check in dev_xdp_attach(). netvsc's program keeps running on the VF. Before this patch xdp_state[] was empty in this case, so the user could attach a program and then detach it to clear things up.
The only way out seems to be linking the VF to some master and then unlinking it. Should the failed-join path, or netif_xdp_propagate(), handle this case?
bond_xdp_set() has a smaller version of the same problem. If the unwind call fails:
err_unwind = dev_xdp_propagate(slave_dev, &xdp);
the slave keeps the new program with xdp_from_upper set, while bond->xdp_prog has been reset to old_prog. That slave can't be fixed directly until it is released from the bond.
net/core/dev.c u8 dev_xdp_prog_count(struct net_device *dev) · line 10574
Quoted 12 lines
net/core/dev.c +8
-0@@ -10561,6 +10564,15 @@ u8 dev_xdp_prog_count(struct net_device *dev) }EXPORT_SYMBOL_GPL (dev_xdp_prog_count); +/* Does the device have an XDP program, and was it installed directly on the +* device rather than propagated down by an upper with netif_xdp_propagate()? +*/ +bool dev_xdp_has_own_prog (struct net_device *dev) +{ +return dev_xdp_prog_count (dev) && !dev->xdp_from_upper; +} +EXPORT_SYMBOL_GPL (dev_xdp_has_own_prog);
[Severity: Low]
This isn't a bug, but does this comment still match what the function returns? It describes where the program came from. The new kernel-doc in include/linux/netdevice.h does too:
@xdp_from_upper: the program in @xdp_state was installed by an
upper device with netif_xdp_propagate(); it belongs to the upper and can't be replaced or removed through this device.
__netdev_upper_dev_unlink() clears xdp_from_upper on any master unlink. That includes the case where the upper's NULL propagate failed and bonding or netvsc only warned. After that, dev_xdp_has_own_prog() returns true for a program that an upper propagated.
Could both comments describe the flag as current ownership, including the hand-over on master unlink?
[ ... ]
net/core/dev.c static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack · line 10822
Quoted 8 lines
net/core/dev.c +4
-0@@ -10773,6 +10816,10 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack } mode =dev_xdp_mode (dev, flags); +if (dev->xdp_from_upper) { +NL_SET_ERR_MSG (extack,"Can't replace an XDP program installed by an upper device" ); +return -EBUSY ; + }
[Severity: Low]
This check now runs before the existing loop that refuses an attach when an upper has a program:
netdev_for_each_upper_dev_rcu(dev, upper, iter) {
if (dev_xdp_prog_count(upper) > 0) {
NL_SET_ERR_MSG(extack, "Cannot attach when an upper device already has a program");
return -EEXIST;
}
}For a direct bond slave or a joined netvsc VF, the upper keeps its program in its own xdp_state[]. Attach, replace and detach on the lower were therefore already refused, with -EEXIST. They now fail with -EBUSY and a different extack message.
The commit message says dev_xdp_attach() reads the flag "to keep the program from being replaced or removed behind the upper's back". However, that protection is only new for nested lowers and for the netvsc window before the join.
Is the errno and message change for the common direct-lower case intended? If so, could the commit message mention it?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112235027.4072149-1-kuba%40kernel.org
Jakub Kicinski
maintainerRe: [PATCH net-next 3/5] net: record XDP programs propagated to lower devices
Quoted 61 lines · On Fri, 13 Nov 2026 23:53:16 +0000 [email protected] wrote:
Quoted 5 lines
net/core/dev.c +0
-0net/core/dev.c static void __netdev_upper_dev_unlink(struct net_device *dev, · line 9334
Quoted 9 lines
net/core/dev.c +3
-0@@ -9326,6 +9326,9 @@ static void __netdev_upper_dev_unlink(struct net_device *dev,__netdev_adjacent_dev_unlink_neighbour (dev, upper_dev); +if (changeupper_info.master) + dev->xdp_from_upper =0 ; +call_netdevice_notifiers_info (NETDEV_CHANGEUPPER , &changeupper_info.info);[Severity: Medium]
The commit message says that clearing the flag here lets the device own a leftover program "rather than leave it with nobody allowed to remove it". Can a lower end up withxdp_from_upperset when no master link was ever created, so that this code never runs?
netvsc_register_vf()propagates netvsc's program before it joins:ret = netvsc_vf_setxdp(vf_netdev, prog); ... if (netvsc_vf_join(vf_netdev, ndev, context) != 0) { ret = prog ? netvsc_vf_setxdp(vf_netdev, NULL) : 0; if (ret) netdev_warn(ndev, "failed to remove XDP program from VF %s: %d\n", vf_netdev->name, ret); return NOTIFY_DONE; }The first call stores the program in vf_netdev->xdp_state[XDP_MODE_DRV] and sets
xdp_from_upper.netvsc_vf_join()can fail innetdev_rx_handler_register()or innetdev_master_upper_dev_link(). Both failure paths return without a master link.If the driver's
ndo_bpf()then refuses the NULL program,netif_xdp_propagate()returns before it touches xdp_state[] or the flag:err = dev->netdev_ops->ndo_bpf(dev, bpf); if (err) return err;netvsc returns
NOTIFY_DONEwithout storing the VF innet_device_ctx->vf_netdev, so it never comes back to this VF. No master was linked, so__netdev_upper_dev_unlink()never clears the flag. Onlydev_xdp_uninstall()at unregister does.From then on, every
IFLA_XDPset or remove and every BPF link attach on the VF hits the new-EBUSYcheck indev_xdp_attach(). netvsc's program keeps running on the VF. Before this patch xdp_state[] was empty in this case, so the user could attach a program and then detach it to clear things up.The only way out seems to be linking the VF to some master and then unlinking it. Should the failed-join path, or
netif_xdp_propagate(), handle this case?
Quoted 8 lines
bond_xdp_set()has a smaller version of the same problem. If the unwind call fails:err_unwind = dev_xdp_propagate(slave_dev, &xdp);the slave keeps the new program with
xdp_from_upperset, whilebond->xdp_proghas been reset toold_prog. That slave can't be fixed directly until it is released from the bond.
I guess AI semi-randomly anchored this comment here, it's basically saying that since netvsc is buggy the state may get out of sync. Yes, as mentioned in the netvsc series I didn't manage to cover all the error paths there. And also that's the reason why I added the clearing of "from upper" on unlink, to make the bad state recoverable.
IOW patch is working as intended. We're going from "no safety checks" to "some already buggy driver error path may fail to clean up".
Quoted 22 lines
net/core/dev.c u8 dev_xdp_prog_count(struct net_device *dev) · line 10574
Quoted 12 lines
net/core/dev.c +8
-0@@ -10561,6 +10564,15 @@ u8 dev_xdp_prog_count(struct net_device *dev) }EXPORT_SYMBOL_GPL (dev_xdp_prog_count); +/* Does the device have an XDP program, and was it installed directly on the +* device rather than propagated down by an upper with netif_xdp_propagate()? +*/ +bool dev_xdp_has_own_prog (struct net_device *dev) +{ +return dev_xdp_prog_count (dev) && !dev->xdp_from_upper; +} +EXPORT_SYMBOL_GPL (dev_xdp_has_own_prog);[Severity: Low]
This isn't a bug, but does this comment still match what the function returns? It describes where the program came from. The new kernel-doc ininclude/linux/netdevice.hdoes too:@xdp_from_upper: the program in @xdp_state was installed by an
upper device withnetif_xdp_propagate(); it belongs to the upper and can't be replaced or removed through this device.
Quoted 7 lines
__netdev_upper_dev_unlink()clearsxdp_from_upperon any master unlink. That includes the case where the upper's NULL propagate failed and bonding or netvsc only warned. After that,dev_xdp_has_own_prog()returns true for a program that an upper propagated.Could both comments describe the flag as current ownership, including the hand-over on master unlink?
No, it's a failure mode / de-sync case. We shouldn't document it.
Quoted 25 lines
net/core/dev.c static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack · line 10822
Quoted 8 lines
net/core/dev.c +4
-0@@ -10773,6 +10816,10 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack } mode =dev_xdp_mode (dev, flags); +if (dev->xdp_from_upper) { +NL_SET_ERR_MSG (extack,"Can't replace an XDP program installed by an upper device" ); +return -EBUSY ; + }[Severity: Low]
This check now runs before the existing loop that refuses an attach when an upper has a program:netdev_for_each_upper_dev_rcu(dev, upper, iter) { if (dev_xdp_prog_count(upper) > 0) { NL_SET_ERR_MSG(extack, "Cannot attach when an upper device already has a program"); return -EEXIST; } }For a direct bond slave or a joined netvsc VF, the upper keeps its program in its own xdp_state[]. Attach, replace and detach on the lower were therefore already refused, with
-EEXIST. They now fail with-EBUSYand a different extack message.
Quoted 7 lines
The commit message says
dev_xdp_attach()reads the flag "to keep the program from being replaced or removed behind the upper's back". However, that protection is only new for nested lowers and for the netvsc window before the join.Is the errno and message change for the common direct-lower case intended? If so, could the commit message mention it?
Intended / doesn't matter.
Jakub Kicinski
maintainerPATCH 4/5 selftests/bpf: check XDP attach on a nested bond slave
In reply to Jakub Kicinskitest_xdp_bonding_attach() already covers a flat bond both ways round:
the master is refused while a slave has a program, and a slave is refused while the master has one. The nested test only ever checked that attaching to the outermost master succeeds.
That left the more interesting half of the nesting untested. With bond -> bond_nest1 -> bond_nest2, bond_nest2 refuses a program of its own only if the program the outer bond pushed down is recorded on it. Before "net: record XDP programs propagated to lower devices" it was recorded nowhere, and a second program could be attached to bond_nest2 while the outer bond's was already running on it. Check that the attach is refused, and with -EBUSY, which is what the recorded program gives.
--- .../selftests/bpf/prog_tests/xdp_bonding.c | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/xdp_bonding.c +21 -3
@@ -461,11 +461,15 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons)system ("ip link del vxlan" ); } -/* Test with nested bonding devices to catch issue with negative jump label count */ +/* +* Test with nested bonding devices to catch issue with negative jump label +* count, and check that a nested slave refuses a program of its own. +*/ static void test_xdp_bonding_nested (struct skeletons *skeletons) { +struct bpf_link *link2 =NULL ;struct bpf_link *link =NULL ; -int bond, err; +int bond, nest2, err;if (!ASSERT_OK (system ("ip link add bond type bond" ),"add bond" )) goto out;
@@ -488,10 +492,24 @@ static void test_xdp_bonding_nested(struct skeletons *skeletons)if (!ASSERT_OK (err,"set bond_nest2 master" )) goto out; + nest2 =if_nametoindex ("bond_nest2" ); +if (!ASSERT_GT (nest2,0 ,"if_nametoindex bond_nest2" )) + goto out; + link =bpf_program__attach_xdp (skeletons->xdp_dummy->progs.xdp_dummy_prog, bond); -ASSERT_OK_PTR (link,"attach program to master" ); +if (!ASSERT_OK_PTR (link,"attach program to master" )) + goto out; + +/* +* Attaching to a nested slave is not allowed either. The program the +* outer bond pushed down is recorded there too. +*/ + link2 =bpf_program__attach_xdp (skeletons->xdp_dummy->progs.xdp_dummy_prog, nest2); +ASSERT_EQ (libbpf_get_error (link2), -EBUSY , +"attach program to nested slave when master has program" ); out: +bpf_link__destroy (link2);bpf_link__destroy (link);system ("ip link del bond" );system ("ip link del bond_nest1" );
Signature · 1 line
2.56.0
Jakub Kicinski
maintainerPATCH 5/5 selftests/bpf: check replacing and detaching XDP on a bond through a link
In reply to Jakub KicinskiThe bond tests attach and destroy links, but never replace the program behind one, or detach it without closing the link. Both only ever operate on the device the link was created on, and rely on the bond to pass the change down to its slaves.
Check that the slave follows the replacement and the detach, and that the program which got replaced is released - the bond used to leak it.
--- .../selftests/bpf/prog_tests/xdp_bonding.c | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+)
tools/testing/selftests/bpf/prog_tests/xdp_bonding.c +96 -0
@@ -516,6 +516,99 @@ static void test_xdp_bonding_nested(struct skeletons *skeletons)system ("ip link del bond_nest2" ); } +/* +* Replace, then detach the program on a bond through its link. The link only +* knows about the bond, the slave has to follow it, and the replaced program +* has to be released. +*/ +static void test_xdp_bonding_link_update (struct skeletons *skeletons) +{ + LIBBPF_OPTS(bpf_prog_load_opts, opts, .expected_attach_type = BPF_XDP); +struct bpf_program *new_prog = skeletons->xdp_dummy->progs.xdp_dummy_prog; +struct bpf_insn insns[] = { +BPF_MOV64_IMM (BPF_REG_0 ,XDP_PASS ), +BPF_EXIT_INSN (), + }; +int veth, bond, err, fd, old_fd =-1 , link_fd =-1 ; +struct bpf_prog_info info = {}; +__u32 old_id, new_id, id, len; + +if (!ASSERT_OK (system ("ip link add veth type veth" ),"add veth" )) + goto out; +if (!ASSERT_OK (system ("ip link add bond type bond" ),"add bond" )) + goto out; + + veth =if_nametoindex ("veth" ); +if (!ASSERT_GT (veth,0 ,"if_nametoindex veth" )) + goto out; + bond =if_nametoindex ("bond" ); +if (!ASSERT_GT (bond,0 ,"if_nametoindex bond" )) + goto out; + + err =system ("ip link set veth master bond" ); +if (!ASSERT_OK (err,"set veth master" )) + goto out; + +/* same attach type as the skeleton's, or the link won't take it */ + old_fd =bpf_prog_load (BPF_PROG_TYPE_XDP ,"xdp_old" ,"GPL" , insns, +ARRAY_SIZE (insns), &opts); +if (!ASSERT_GE (old_fd,0 ,"load old program" )) + goto out; + len =sizeof (info); +if (!ASSERT_OK (bpf_prog_get_info_by_fd (old_fd, &info, &len),"old program info" )) + goto out; + old_id = info.id; + +memset (&info,0 ,sizeof (info)); + len =sizeof (info); + err =bpf_prog_get_info_by_fd (bpf_program__fd (new_prog), &info, &len); +if (!ASSERT_OK (err,"new program info" )) + goto out; + new_id = info.id; + + link_fd =bpf_link_create (old_fd, bond,BPF_XDP ,NULL ); +if (!ASSERT_GE (link_fd,0 ,"attach old program to bond" )) + goto out; + + err =bpf_xdp_query_id (veth,XDP_FLAGS_DRV_MODE , &id); +if (!ASSERT_OK (err,"query veth" ) || + !ASSERT_EQ (id, old_id,"veth runs the old program" )) + goto out; + + err =bpf_link_update (link_fd,bpf_program__fd (new_prog),NULL ); +if (!ASSERT_OK (err,"replace the program through the link" )) + goto out; + + err =bpf_xdp_query_id (veth,XDP_FLAGS_DRV_MODE , &id); +if (!ASSERT_OK (err,"query veth" ) || + !ASSERT_EQ (id, new_id,"veth follows to the new program" )) + goto out; + +/* nothing but our fd should be holding on to the old program now */ +close (old_fd); + old_fd =-1 ; + fd =bpf_prog_get_fd_by_id (old_id); +if (!ASSERT_EQ (fd, -ENOENT ,"old program released" ) && fd >=0 ) +close (fd); + + err =bpf_link_detach (link_fd); +if (!ASSERT_OK (err,"detach the link" )) + goto out; + + err =bpf_xdp_query_id (veth,XDP_FLAGS_DRV_MODE , &id); +if (!ASSERT_OK (err,"query veth" )) + goto out; +ASSERT_EQ (id,0 ,"veth has no program left" ); + +out: +if (link_fd >=0 ) +close (link_fd); +if (old_fd >=0 ) +close (old_fd); +system ("ip link del veth" ); +system ("ip link del bond" ); +} +/* * Test that XDP redirect via xdp_master_redirect() does not crash when * the bond master device is not up. When bond is in round-robin mode but
@@ -826,6 +919,9 @@ void serial_test_xdp_bonding(void)if (test__start_subtest ("xdp_bonding_nested" ))test_xdp_bonding_nested (&skeletons); +if (test__start_subtest ("xdp_bonding_link_update" )) +test_xdp_bonding_link_update (&skeletons); +if (test__start_subtest ("xdp_bonding_features" ))test_xdp_bonding_features (&skeletons);
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH net-next 5/5] selftests/bpf: check replacing and detaching XDP on a bond through a link
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message of "selftests/bpf: check replacing and detaching XDP on a bond through a link" leaves out two things a reader…
--
selftests/bpf: check replacing and detaching XDP on a bond through a link
This adds an xdp_bonding_link_update subtest. The subtest attaches a program to a bond through a link, replaces it with bpf_link_update(), and detaches it with bpf_link_detach(). It checks that the veth slave follows each change and that the replaced program is released.
Quoted 2 lines
Check that the slave follows the replacement and the detach, and that the program which got replaced is released - the bond used to leak it.
[Severity: Low]
This isn't a bug, but could the message name the fix this test guards? The leak appears to have been fixed by commit 184b5ddf82d4 ("bonding: fix the program leak when XDP is replaced"). That commit's message says the selftest would come in the net-next series.
The message also leaves out that the slave-side assertions depend on "net: record XDP programs propagated to lower devices", which is earlier in this series. The previous patch, "selftests/bpf: check XDP attach on a nested bond slave", does name that dependency.
bpf_xdp_query_id(veth, XDP_FLAGS_DRV_MODE, &id) reads dev->xdp_state[XDP_MODE_DRV] through rtnl_xdp_prog_drv()->dev_xdp_prog_id().
Before that patch, netif_xdp_propagate() only called ndo_bpf() and never recorded the program on the lower device. A bond slave therefore always reported id 0.
In test_xdp_bonding_link_update() in tools/testing/selftests/bpf/prog_tests/xdp_bonding.c, the first slave check jumps to out before the leak check runs:
err = bpf_xdp_query_id(veth, XDP_FLAGS_DRV_MODE, &id); if (!ASSERT_OK(err, "query veth") || !ASSERT_EQ(id, old_id, "veth runs the old program")) goto out; ... fd = bpf_prog_get_fd_by_id(old_id); if (!ASSERT_EQ(fd, -ENOENT, "old program released") && fd >= 0) close(fd);
On a kernel that has 184b5ddf82d4 but not the propagation change, the test fails at the first veth query and the leak assertion never runs.
Could the commit message reference both of these changes?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112235027.4072149-1-kuba%40kernel.org
Quoted 17 lines · Jakub Kicinski
Bonding (and netvsc) try to auto-propagate XDP programs down to their lower devices. These programs were installed directly with .ndo_bpf and not recorded in struct
net_deviceof the lowers. This makes all the config checks for features incompatible with XDP ineffective - HDS, memory providers etc. usedev_xdp_prog_count()and do not call down to the driver to ask it whether it has XDP installed.Record the state appropriately.
dev_xdp_prog_count()will now "see" the propagated programs.The issue was discovered when reworking HW-GRO and XDP interactions. I was trying to make sure HW-GRO is reliably disabled with XDP, and discovered we have a way to bypass all checks with bonding. Not treating this as a fix since it's admin-only self-inflicted damage that nobody is reporting being bothered by in real life.
Quoted 7 lines
Jakub Kicinski (5):
net: don't safety-check device features for XDP uninstall
net: movedev_xdp_set_link()anddev_xdp_set_prog()up
net: record XDP programs propagated to lower devices selftests/bpf: check XDP attach on a nested bond slave selftests/bpf: check replacing and detaching XDP on a bond through a
link
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Thu, 12 Nov 2026 15:50:22 -0800 you wrote:
Bonding (and netvsc) try to auto-propagate XDP programs down to their lower devices. These programs were installed directly with .ndo_bpf and not recorded in struct
net_deviceof the lowers. This makes all the config checks for features incompatible with XDP ineffective - HDS, memory providers etc. usedev_xdp_prog_count()and do not call down to the driver to ask it whether it has XDP installed.[...]
Here is the summary with links:
- [net-next,1/5] net: don't safety-check device features for XDP uninstall
https://git.kernel.org/netdev/net-next/c/390095fe5405 - [net-next,2/5] net: move dev_xdp_set_link() and dev_xdp_set_prog() up https://git.kernel.org/netdev/net-next/c/63e4bfec2cd7 - [net-next,3/5] net: record XDP programs propagated to lower devices https://git.kernel.org/netdev/net-next/c/f564749b3b26 - [net-next,4/5] selftests/bpf: check XDP attach on a nested bond slave https://git.kernel.org/netdev/net-next/c/29260040ae3b - [net-next,5/5] selftests/bpf: check replacing and detaching XDP on a bond through a link https://git.kernel.org/netdev/net-next/c/221ceda44838
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html