From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
andrew+netdev@lunn.ch, horms@kernel.org, haiyangz@microsoft.com,
wei.liu@kernel.org, decui@microsoft.com,
kameroncarr@linux.microsoft.com, ernis@linux.microsoft.com,
Jakub Kicinski <kuba@kernel.org>,
stable+noautosel@kernel.org
Subject: [PATCH net-next v2 1/5] hv_netvsc: fix the program refcount when the VF refuses XDP
Date: Mon, 9 Nov 2026 11:48:39 -0800 [thread overview]
Message-ID: <20261109194843.1353592-2-kuba@kernel.org> (raw)
In-Reply-To: <20261109194843.1353592-1-kuba@kernel.org>
ndo_bpf() takes over the reference it is passed only on success, the
caller puts it back itself on failure. netvsc_xdp_set() takes that one
plus num_chn - 1 more for its channels, and the rollback after the VF
refuses the program clears the channels again, putting all num_chn of
them. dev_xdp_install() then puts the one it passed in a second time,
and the program can be freed while the fd which loaded it still points
at it.
The VF refuses a program netvsc has already committed to when the
program is single-buffer and the VF has header-data split enabled, when
the VF has a memory provider bound, or when the VF's driver has
conditions of its own.
The rollback clears the channels rather than putting back the program
they ran before, too. A refused replace or removal then leaves the
synthetic path running no program at all, while the core and the VF
keep the old one. Put the old program back instead.
Reported by Sashiko during core rework. Unverified and untested.
Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path
Fixes: 184367dce4f7 ("hv_netvsc: Fix XDP refcnt for synthetic and VF NICs")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2:
- put the old program back on the channels rather than clearing them
(Kameron)
- reword the comment on the extra reference, it's the caller's, which
isn't always the core
- Tested-by tags from v1 not carried over, the rollback changed
v1: https://lore.kernel.org/20261001014131.310771-2-kuba@kernel.org
---
drivers/net/hyperv/netvsc_bpf.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/drivers/net/hyperv/netvsc_bpf.c b/drivers/net/hyperv/netvsc_bpf.c
index 1dd3755d9e6d..fcc60729384e 100644
--- a/drivers/net/hyperv/netvsc_bpf.c
+++ b/drivers/net/hyperv/netvsc_bpf.c
@@ -197,6 +197,7 @@ int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf)
struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev);
struct net_device *vf_netdev = rtnl_dereference(ndevctx->vf_netdev);
struct netlink_ext_ack *extack = bpf->extack;
+ struct bpf_prog *old_prog;
int ret;
if (!nvdev || nvdev->destroy) {
@@ -205,10 +206,17 @@ int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf)
switch (bpf->command) {
case XDP_SETUP_PROG:
+ /* Hold on to the old program, to put it back on the channels
+ * if the VF refuses the change.
+ */
+ old_prog = netvsc_xdp_get(nvdev);
+ if (old_prog)
+ bpf_prog_inc(old_prog);
+
ret = netvsc_xdp_set(dev, bpf->prog, extack, nvdev);
if (ret)
- return ret;
+ goto put_old_prog;
ret = netvsc_vf_setxdp(vf_netdev, bpf->prog);
@@ -216,9 +224,22 @@ int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf)
netdev_err(dev, "vf_setxdp failed:%d\n", ret);
NL_SET_ERR_MSG_MOD(extack, "vf_setxdp failed");
- netvsc_xdp_set(dev, NULL, extack, nvdev);
+ /* The caller hands us its reference to bpf->prog only
+ * on success, take one so that putting the num_chn
+ * channel references below doesn't consume it.
+ */
+ if (bpf->prog)
+ bpf_prog_inc(bpf->prog);
+ /* Can't fail, old_prog has passed the same checks
+ * before. The channels take over our reference to it.
+ */
+ netvsc_xdp_set(dev, old_prog, extack, nvdev);
+ return ret;
}
+put_old_prog:
+ if (old_prog)
+ bpf_prog_put(old_prog);
return ret;
default:
--
2.56.0
next prev parent reply other threads:[~2026-11-09 19:48 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 19:48 [PATCH net-next v2 0/5] hv_netvsc: make XDP propagation act more like bonding Jakub Kicinski
2026-11-09 19:48 ` Jakub Kicinski [this message]
2026-11-09 19:48 ` [PATCH net-next v2 2/5] hv_netvsc: hold the VF's instance lock when installing XDP on it Jakub Kicinski
2026-11-11 10:48 ` netdev-bot+sashiko
2026-11-09 19:48 ` [PATCH net-next v2 3/5] hv_netvsc: treat the VF's XDP program the way bonding treats a slave's Jakub Kicinski
2026-11-11 10:48 ` netdev-bot+sashiko
2026-11-11 18:35 ` Jakub Kicinski
2026-11-09 19:48 ` [PATCH net-next v2 4/5] hv_netvsc: move a new VF to netvsc's netns from a work item Jakub Kicinski
2026-11-11 10:48 ` netdev-bot+sashiko
2026-11-11 18:40 ` Jakub Kicinski
2026-11-09 19:48 ` [PATCH net-next v2 5/5] hv_netvsc: let the core take XDP off a netvsc device that is going away Jakub Kicinski
2026-11-11 10:48 ` netdev-bot+sashiko
2026-11-11 18:45 ` Jakub Kicinski
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=20261109194843.1353592-2-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=edumazet@google.com \
--cc=ernis@linux.microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=horms@kernel.org \
--cc=kameroncarr@linux.microsoft.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable+noautosel@kernel.org \
--cc=wei.liu@kernel.org \
/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