Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Hangbin Liu
Fri, 13 Nov 2026 14:04
[PATCH net-next 1/6] bonding: check XDP support before enslaving changes state
Author: Hangbin Liu
Date: Fri, 13 Nov 2026 14:04
Date: Fri, 13 Nov 2026 14:04
87 lines
11505 bytes
11505 bytes
From: Hangbin Liu <liuhangbin@kylinos.cn>
The XDP capability checks (ndo_bpf/ndo_xdp_xmit) and the slave XDP
program count check in bond_enslave() run after the slave has already
been opened, attached and made visible to the datapath. In particular
the slave can become bond->curr_active_slave, or be published via
bond->slave_cnt, before we verify that slave_dev->netdev_ops->ndo_xdp_xmit
exists, so bond_xdp_xmit() may call a NULL ndo_xdp_xmit.
Move both checks to the validation section at the top of bond_enslave(),
before the first state change. On failure nothing has been mutated yet,
so the function can return directly. The dev_xdp_propagate() setup is
left in place for now and still uses the same error path.
Error messages and errno values are unchanged (-EOPNOTSUPP with the
same netlink extack strings), and the success path is unaffected
beyond running the read-only checks earlier.
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
drivers/net/bonding/bond_main.c | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 9249a79a168e..340af4c3fa20 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1948,6 +1948,23 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
return -EPERM;
}
+ /* Check XDP support before any state change, so a slave without
+ * XDP can never become visible to bond_xdp_xmit().
+ */
+ if (bond->xdp_prog) {
+ if (!slave_ops->ndo_bpf || !slave_ops->ndo_xdp_xmit) {
+ SLAVE_NL_ERR(bond_dev, slave_dev, extack,
+ "Slave does not support XDP");
+ return -EOPNOTSUPP;
+ }
+
+ if (dev_xdp_prog_count(slave_dev) > 0) {
+ SLAVE_NL_ERR(bond_dev, slave_dev, extack,
+ "Slave has XDP program loaded, please unload before enslaving");
+ return -EOPNOTSUPP;
+ }
+ }
+
/* 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.
@@ -2311,15 +2328,8 @@ 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) {
+ /* XDP capability and prog-count were already validated above */
+ if (bond->xdp_prog) {
struct netdev_bpf xdp = {
.command = XDP_SETUP_PROG,
.flags = 0,
@@ -2327,13 +2337,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
.extack = extack,
};
- if (dev_xdp_prog_count(slave_dev) > 0) {
- 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 */
--
2.56.0
Re: [PATCH net-next 1/6] bonding: check XDP support before enslaving changes state
Author: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 14:40
Date: Tue, 17 Nov 2026 14:40
153 lines
13717 bytes
13717 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 2
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).
- [High] The fix is incomplete: a slave without ndo_xdp_xmit can still be
reached by bond_xdp_xmit() whenever the bond has no XDP program.
- [Low] The commit message presents this as a crash fix ("bond_xdp_xmit()
may call a NULL ndo_xdp_xmit"), but the commit has no Fixes: tag (and…
- [Low] The commit author (From:) is "Hangbin Liu
<hangbin.liu@linux.dev>", but the only Signed-off-by line is "Hangbin…
--
bonding: check XDP support before enslaving changes state
This commit moves two XDP checks in bond_enslave() to the validation
section at the top of the function: the ndo_bpf/ndo_xdp_xmit capability
check and the slave XDP program count check. They now run before the slave
is opened, attached and made visible to the datapath. The
dev_xdp_propagate() setup stays where it was.
> In particular
> the slave can become bond->curr_active_slave, or be published via
> bond->slave_cnt, before we verify that slave_dev->netdev_ops->ndo_xdp_xmit
> exists, so bond_xdp_xmit() may call a NULL ndo_xdp_xmit.
[Severity: Low]
The commit message describes this as a fix for a NULL ndo_xdp_xmit call,
but there is no Fixes: tag and no Cc: stable. Should there be a Fixes:
tag?
git blame shows the late capability and prog-count checks came from commit
9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver"), and
commit 6d5f1ef83868 later restructured them.
> Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
[Severity: Low]
The author is Hangbin Liu <hangbin.liu@linux.dev>, but the only
Signed-off-by line uses <liuhangbin@kylinos.cn>. checkpatch reports this
as a From:/Signed-off-by: email address mismatch. Could the two addresses
be made to match?
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index 9249a79a168e4..340af4c3fa201 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -1948,6 +1948,23 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
> return -EPERM;
> }
>
> + /* Check XDP support before any state change, so a slave without
> + * XDP can never become visible to bond_xdp_xmit().
> + */
> + if (bond->xdp_prog) {
> + if (!slave_ops->ndo_bpf || !slave_ops->ndo_xdp_xmit) {
> + SLAVE_NL_ERR(bond_dev, slave_dev, extack,
> + "Slave does not support XDP");
> + return -EOPNOTSUPP;
> + }
[Severity: High]
Does the "can never become visible" claim still hold when bond->xdp_prog
is NULL?
bond_xdp_xmit() is the bond's ndo_xdp_xmit. Devmap and bpf_redirect reach
it after only this check:
kernel/bpf/devmap.c:__xdp_enqueue() {
...
if (!(dev->xdp_features & NETDEV_XDP_ACT_NDO_XMIT))
return -EOPNOTSUPP;
...
}
bond_xdp_set_features() builds that flag from bond_xdp_check() and the
slaves' xdp_features. It never looks at bond->xdp_prog:
if (!bond_xdp_check(bond, BOND_MODE(bond)) || !bond_has_slaves(bond)) {
xdp_clear_features_flag(bond_dev);
return;
}
bond_for_each_slave(bond, slave, iter)
val &= slave->dev->xdp_features;
Take a round-robin, active-backup, XOR or 802.3ad bond with no XDP
program, where all current slaves advertise NDO_XMIT and another device
redirects XDP frames into the bond. Enslaving a device with a NULL
ndo_xdp_xmit skips this check.
The new slave then becomes visible before bond_xdp_set_features() clears
NDO_XMIT on the bond:
- the default case of the mode switch in bond_enslave() does
rcu_assign_pointer(bond->curr_active_slave, new_slave)
- bond_master_upper_dev_link() puts the slave on the lower list that
bond_get_slave_by_id() walks
- slave_cnt++ and bond_update_slave_arr() also run before
bond_xdp_set_features()
A redirect on another CPU runs under RCU only, without RTNL. It could pick
the new slave, for example through the IGMP path of
bond_xdp_xmit_roundrobin_slave_get():
if (iph->protocol == IPPROTO_IGMP) {
slave = rcu_dereference(bond->curr_active_slave);
if (slave)
return slave;
bond_xdp_xmit() then makes the call without a NULL check:
err = slave_dev->netdev_ops->ndo_xdp_xmit(slave_dev, 1, frames1, flags);
Can this call a NULL ndo_xdp_xmit in softirq context?
There seems to be a second window as well. __xdp_enqueue() checks
xdp_features when a frame is queued, but the bulk queue is flushed later
without a recheck:
kernel/bpf/devmap.c:bq_xmit_all() {
...
sent = dev->netdev_ops->ndo_xdp_xmit(dev, to_send, bq->q, flags);
...
}
No RCU grace period follows xdp_set_features_flag() either.
The later patches in the series don't close this. At the end of the
series:
- the check is still gated on bond->xdp_prog, now in
bond_enslave_validate()
- bond_xdp_xmit() is unchanged
- bond_xdp_set_features() now runs before bond_publish_slave(), but
still after the curr_active_slave assignment and the lower-list link
One option is to guard the call in bond_xdp_xmit(), or to select only
slaves that advertise NDO_XMIT. Another is to clear the bond's NDO_XMIT
and wait for in-flight readers before any slave without XDP support
becomes visible, whether or not bond->xdp_prog is set. Would one of these
be a better fit?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-bond_enslave_restruct-v1-0-364c549e78db%40kylinos.cn
Re: [PATCH net-next 1/6] bonding: check XDP support before enslaving changes state
Author: Hangbin Liu
Date: Wed, 18 Nov 2026 01:06
Date: Wed, 18 Nov 2026 01:06
170 lines
15077 bytes
15077 bytes
On Tue, Nov 17, 2026 at 02:40:07PM +0000, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · Medium: 0 · Low: 2
>
> 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).
>
> - [High] The fix is incomplete: a slave without ndo_xdp_xmit can still be
> reached by bond_xdp_xmit() whenever the bond has no XDP program.
> - [Low] The commit message presents this as a crash fix ("bond_xdp_xmit()
> may call a NULL ndo_xdp_xmit"), but the commit has no Fixes: tag (and…
> - [Low] The commit author (From:) is "Hangbin Liu
> <hangbin.liu@linux.dev>", but the only Signed-off-by line is "Hangbin…
>
> --
>
> bonding: check XDP support before enslaving changes state
>
> This commit moves two XDP checks in bond_enslave() to the validation
> section at the top of the function: the ndo_bpf/ndo_xdp_xmit capability
> check and the slave XDP program count check. They now run before the slave
> is opened, attached and made visible to the datapath. The
> dev_xdp_propagate() setup stays where it was.
>
> > In particular
> > the slave can become bond->curr_active_slave, or be published via
> > bond->slave_cnt, before we verify that slave_dev->netdev_ops->ndo_xdp_xmit
> > exists, so bond_xdp_xmit() may call a NULL ndo_xdp_xmit.
>
> [Severity: Low]
> The commit message describes this as a fix for a NULL ndo_xdp_xmit call,
> but there is no Fixes: tag and no Cc: stable. Should there be a Fixes:
> tag?
>
> git blame shows the late capability and prog-count checks came from commit
> 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver"), and
> commit 6d5f1ef83868 later restructured them.
>
> > Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
>
> [Severity: Low]
> The author is Hangbin Liu <hangbin.liu@linux.dev>, but the only
> Signed-off-by line uses <liuhangbin@kylinos.cn>. checkpatch reports this
> as a From:/Signed-off-by: email address mismatch. Could the two addresses
> be made to match?
>
> > diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> > index 9249a79a168e4..340af4c3fa201 100644
> > --- a/drivers/net/bonding/bond_main.c
> > +++ b/drivers/net/bonding/bond_main.c
> > @@ -1948,6 +1948,23 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
> > return -EPERM;
> > }
> >
> > + /* Check XDP support before any state change, so a slave without
> > + * XDP can never become visible to bond_xdp_xmit().
> > + */
> > + if (bond->xdp_prog) {
> > + if (!slave_ops->ndo_bpf || !slave_ops->ndo_xdp_xmit) {
> > + SLAVE_NL_ERR(bond_dev, slave_dev, extack,
> > + "Slave does not support XDP");
> > + return -EOPNOTSUPP;
> > + }
>
> [Severity: High]
> Does the "can never become visible" claim still hold when bond->xdp_prog
> is NULL?
>
> bond_xdp_xmit() is the bond's ndo_xdp_xmit. Devmap and bpf_redirect reach
> it after only this check:
>
> kernel/bpf/devmap.c:__xdp_enqueue() {
> ...
> if (!(dev->xdp_features & NETDEV_XDP_ACT_NDO_XMIT))
> return -EOPNOTSUPP;
> ...
> }
>
> bond_xdp_set_features() builds that flag from bond_xdp_check() and the
> slaves' xdp_features. It never looks at bond->xdp_prog:
>
> if (!bond_xdp_check(bond, BOND_MODE(bond)) || !bond_has_slaves(bond)) {
> xdp_clear_features_flag(bond_dev);
> return;
> }
>
> bond_for_each_slave(bond, slave, iter)
> val &= slave->dev->xdp_features;
>
> Take a round-robin, active-backup, XOR or 802.3ad bond with no XDP
> program, where all current slaves advertise NDO_XMIT and another device
> redirects XDP frames into the bond. Enslaving a device with a NULL
> ndo_xdp_xmit skips this check.
>
> The new slave then becomes visible before bond_xdp_set_features() clears
> NDO_XMIT on the bond:
>
> - the default case of the mode switch in bond_enslave() does
> rcu_assign_pointer(bond->curr_active_slave, new_slave)
> - bond_master_upper_dev_link() puts the slave on the lower list that
> bond_get_slave_by_id() walks
> - slave_cnt++ and bond_update_slave_arr() also run before
> bond_xdp_set_features()
>
> A redirect on another CPU runs under RCU only, without RTNL. It could pick
> the new slave, for example through the IGMP path of
> bond_xdp_xmit_roundrobin_slave_get():
>
> if (iph->protocol == IPPROTO_IGMP) {
> slave = rcu_dereference(bond->curr_active_slave);
> if (slave)
> return slave;
>
> bond_xdp_xmit() then makes the call without a NULL check:
>
> err = slave_dev->netdev_ops->ndo_xdp_xmit(slave_dev, 1, frames1, flags);
>
> Can this call a NULL ndo_xdp_xmit in softirq context?
>
> There seems to be a second window as well. __xdp_enqueue() checks
> xdp_features when a frame is queued, but the bulk queue is flushed later
> without a recheck:
>
> kernel/bpf/devmap.c:bq_xmit_all() {
> ...
> sent = dev->netdev_ops->ndo_xdp_xmit(dev, to_send, bq->q, flags);
> ...
> }
>
> No RCU grace period follows xdp_set_features_flag() either.
>
> The later patches in the series don't close this. At the end of the
> series:
>
> - the check is still gated on bond->xdp_prog, now in
> bond_enslave_validate()
> - bond_xdp_xmit() is unchanged
> - bond_xdp_set_features() now runs before bond_publish_slave(), but
> still after the curr_active_slave assignment and the lower-list link
>
> One option is to guard the call in bond_xdp_xmit(), or to select only
> slaves that advertise NDO_XMIT. Another is to clear the bond's NDO_XMIT
> and wait for in-flight readers before any slave without XDP support
> becomes visible, whether or not bond->xdp_prog is set. Would one of these
> be a better fit?
>
As I mentioned in the previous mail[1], we may need a check like
if (likely(slave_dev->netdev_ops->ndo_xdp_xmit))
err = slave_dev->netdev_ops->ndo_xdp_xmit(slave_dev, 1, frames1, flags);
On the other hand, should we call bond_xdp_xmit() without a bond->xdp_prog?
I need to check if we should move the bond_xdp_set_features(bond_dev);
inside the if (bond->xdp_prog) checking. So when we build the bond xdp
features, we can make sure there is a bond->xdp_prog set.
[1] https://lore.kernel.org/netdev/aqokD2avF7B7Towi@fedora/
Thanks
Hangbin
---
pw-bot: cr
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads