From: Philipp Sudakas <filzador@gmail.com>
To: ronak.doshi@broadcom.com, bcm-kernel-feedback-list@broadcom.com
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, ast@kernel.org,
daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
sdf@fomichev.me, u9012063@gmail.com,
Philipp Sudakas <filzador@gmail.com>
Subject: [PATCH net v3 2/5] vmxnet3: fix the error path of XDP program setup
Date: Wed, 25 Nov 2026 10:52:52 +0300 [thread overview]
Message-ID: <20261125075255.1517-3-filzador@gmail.com> (raw)
In-Reply-To: <20261125075255.1517-1-filzador@gmail.com>
vmxnet3_xdp_set() publishes the new program and drops its reference to
the old one before it recreates the rx queues and reactivates the
device. If vmxnet3_rq_create_all() or vmxnet3_activate_dev() then
fails, it returns -EOPNOTSUPP without rolling anything back:
- On a failed attach, dev_xdp_install() drops the reference it took
for the new program, but the driver still points to it.
- On a failed detach, the driver has already dropped the old program.
The core keeps it recorded as attached, except on XDP link release,
where dev_xdp_detach_link() ignores the error.
- The interface stays up with NAPI disabled, IRQs freed and, if queue
creation failed, no rx rings. vmxnet3_suspend(), vmxnet3_resume()
or a pending vmxnet3_reset_work() can then hang or crash.
So far the stale program pointer was mostly hidden because every error
path of vmxnet3_activate_dev() goes through vmxnet3_rq_cleanup_all(),
which also clears xdp_bpf_prog.
On a failed attach (the old program is always NULL there, as replacing
a program does not reconfigure the device), drop the new program, bring
the device back up without XDP and return the error. On a failed
detach, complete the detach and return 0, so that the driver and the
core agree. In both cases, if the device cannot be restarted, close the
interface with dev_close(): the device is already quiesced, with NAPI
disabled and IRQs freed, and vmxnet3_force_close() would quiesce it
again and free the IRQs a second time.
Release the old program, and update the redirect target feature, only
once the change is done. The feature is now also updated when the
program is set while the interface is down, as the program now stays
in effect when the interface comes up. Use rtnl_dereference() to read
the current program: ndo_bpf runs under RTNL, not in an RCU read-side
section.
The problem was found and analysed, and this patch drafted, with the
help of an AI coding assistant. It was also reported by an automated
review of an earlier version of this series.
Fixes: 54f00cce1178 ("vmxnet3: Add XDP support.")
Signed-off-by: Philipp Sudakas <filzador@gmail.com>
---
drivers/net/vmxnet3/vmxnet3_xdp.c | 84 +++++++++++++++++++++----------
1 file changed, 58 insertions(+), 26 deletions(-)
diff --git a/drivers/net/vmxnet3/vmxnet3_xdp.c b/drivers/net/vmxnet3/vmxnet3_xdp.c
index 5f47049..a578667 100644
--- a/drivers/net/vmxnet3/vmxnet3_xdp.c
+++ b/drivers/net/vmxnet3/vmxnet3_xdp.c
@@ -33,6 +33,23 @@ vmxnet3_xdp_get_tq(struct vmxnet3_adapter *adapter)
return tq;
}
+/* Recreate the rx queues in the mode given by adapter->xdp_bpf_prog and
+ * reactivate the quiesced device.
+ */
+static int
+vmxnet3_xdp_restart_dev(struct vmxnet3_adapter *adapter)
+{
+ int err;
+
+ vmxnet3_reset_dev(adapter);
+ vmxnet3_rq_destroy_all(adapter);
+ vmxnet3_adjust_rx_ring_size(adapter);
+ err = vmxnet3_rq_create_all(adapter);
+ if (err)
+ return err;
+ return vmxnet3_activate_dev(adapter);
+}
+
static int
vmxnet3_xdp_set(struct net_device *netdev, struct netdev_bpf *bpf,
struct netlink_ext_ack *extack)
@@ -55,46 +72,61 @@ vmxnet3_xdp_set(struct net_device *netdev, struct netdev_bpf *bpf,
adapter->netdev->features &= ~NETIF_F_LRO;
}
- old_bpf_prog = rcu_dereference(adapter->xdp_bpf_prog);
+ old_bpf_prog = rtnl_dereference(adapter->xdp_bpf_prog);
if (!new_bpf_prog && !old_bpf_prog)
return 0;
running = netif_running(netdev);
need_update = !!old_bpf_prog != !!new_bpf_prog;
- if (running && need_update)
- vmxnet3_quiesce_dev(adapter);
+ if (!running || !need_update) {
+ vmxnet3_xdp_exchange_program(adapter, new_bpf_prog);
+ goto done;
+ }
+ vmxnet3_quiesce_dev(adapter);
vmxnet3_xdp_exchange_program(adapter, new_bpf_prog);
- if (old_bpf_prog)
- bpf_prog_put(old_bpf_prog);
-
- if (!running || !need_update)
- return 0;
-
- if (new_bpf_prog)
- xdp_features_set_redirect_target(netdev, false);
- else
- xdp_features_clear_redirect_target(netdev);
-
- vmxnet3_reset_dev(adapter);
- vmxnet3_rq_destroy_all(adapter);
- vmxnet3_adjust_rx_ring_size(adapter);
- err = vmxnet3_rq_create_all(adapter);
- if (err) {
- NL_SET_ERR_MSG_MOD(extack,
- "failed to re-create rx queues for XDP.");
- return -EOPNOTSUPP;
+ err = vmxnet3_xdp_restart_dev(adapter);
+ if (err && new_bpf_prog) {
+ /* Attach failed (old_bpf_prog is NULL here): the core drops
+ * its reference to the new program and keeps nothing
+ * attached. Bring the device back up without XDP.
+ */
+ NL_SET_ERR_MSG_MOD(extack, "failed to restart device for XDP");
+ vmxnet3_xdp_exchange_program(adapter, NULL);
+ if (vmxnet3_xdp_restart_dev(adapter))
+ goto err_close;
+ return err;
}
- err = vmxnet3_activate_dev(adapter);
if (err) {
- NL_SET_ERR_MSG_MOD(extack,
- "failed to activate device for XDP.");
- return -EOPNOTSUPP;
+ /* Detach failed. The core may ignore an error here (XDP link
+ * release), so complete the detach on a closed device.
+ */
+ netdev_err(netdev, "XDP removal failed to restart, closing\n");
+ goto err_close;
}
clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
+done:
+ if (need_update) {
+ if (new_bpf_prog)
+ xdp_features_set_redirect_target(netdev, false);
+ else
+ xdp_features_clear_redirect_target(netdev);
+ }
+ if (old_bpf_prog)
+ bpf_prog_put(old_bpf_prog);
return 0;
+
+err_close:
+ /* The device is left quiesced, with IRQs freed and NAPI disabled,
+ * as vmxnet3_close() expects after a quiesce: close the interface.
+ * vmxnet3_force_close() would quiesce it and free the IRQs again.
+ */
+ dev_close(netdev);
+ if (new_bpf_prog)
+ return err;
+ goto done;
}
/* This is the main xdp call used by kernel to set/unset eBPF program. */
--
2.47.3
next prev parent reply other threads:[~2026-11-25 7:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 7:52 [PATCH net v3 0/5] vmxnet3: fix native XDP crash on oversized frames and XDP loss on reset Philipp Sudakas
2026-11-25 7:52 ` [PATCH net v3 1/5] vmxnet3: clear rx_ctx.skb after a data ring XDP verdict Philipp Sudakas
2026-11-25 7:52 ` Philipp Sudakas [this message]
2026-11-25 7:52 ` [PATCH net v3 3/5] vmxnet3: limit the XDP MTU to the rx head buffer size Philipp Sudakas
2026-11-25 7:52 ` [PATCH net v3 4/5] vmxnet3: drop XDP frames that do not fit in one rx buffer Philipp Sudakas
2026-11-25 7:52 ` [PATCH net v3 5/5] vmxnet3: keep the XDP program across device resets Philipp Sudakas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125075255.1517-3-filzador@gmail.com \
--to=filzador@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=ast@kernel.org \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ronak.doshi@broadcom.com \
--cc=sdf@fomichev.me \
--cc=u9012063@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox