From: Slawomir Stepien <sst@poczta.fm>
To: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
"Jiayuan Chen" <jiayuan.chen@linux.dev>,
"Dudu Lu" <phx0fer@gmail.com>,
"Maciej Fijalkowski" <maciej.fijalkowski@intel.com>,
"Tianyi Gao" <tianyi@cloudflare.com>,
"Octavian Purdila" <tavip@google.com>,
"Toke Høiland-Jørgensen" <toke@redhat.com>,
"Alexander Lobakin" <aleksander.lobakin@intel.com>,
"Lorenzo Bianconi" <lorenzo@kernel.org>,
"Lorenzo Bianconi" <lorenzo.bianconi@oss.qualcomm.com>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"Willem de Bruijn" <willemb@google.com>,
"Simon Horman" <horms@kernel.org>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Emil Tsalapatis" <emil@etsalapatis.com>,
"Shuah Khan" <shuah@kernel.org>,
linux-kselftest@vger.kernel.org,
"Slawomir Stepien" <sst@poczta.fm>,
stable@vger.kernel.org
Subject: [PATCH net v9 4/6] veth: use the page_pool mem type when running XDP on an skb
Date: Fri, 27 Nov 2026 11:01:30 +0100 [thread overview]
Message-ID: <20261127100132.1977890-5-sst@poczta.fm> (raw)
In-Reply-To: <20261127100132.1977890-1-sst@poczta.fm>
Since commit 0ebab78cbcbf ("net: veth: add page_pool for page
recycling") veth_convert_skb_to_xdp_buff() copies the skb into pages
from rq->page_pool when the program cannot run on the skb as it is, for
example when the skb is non-linear or has too little headroom. The
program still runs with rq->xdp_rxq, whose mem type is
MEM_TYPE_PAGE_SHARED, so when it shrinks a frag away,
bpf_xdp_shrink_data() frees the page_pool page with page_frag_free():
BUG: Bad page state in process ping pfn:6aa02
page dumped because: page_pool leak
Run the program with the rxq info on the stack of veth_xdp_rcv() and
set its mem type to MEM_TYPE_PAGE_POOL. The program can free only frags
and they always come from skb_pp_cow_data(). On XDP_TX and
XDP_REDIRECT, veth_xdp_get() takes plain page references and the skb is
consumed, so the buff holds plain page references from then on: set the
mem type to MEM_TYPE_PAGE_SHARED there, which the frame keeps, as it
does today. rq->xdp_rxq is not changed any more, so rq->xdp_mem, which
restored it, can go.
Fixes: 0ebab78cbcbf ("net: veth: add page_pool for page recycling")
Reported-by: Alexei Starovoitov <ast@kernel.org>
Closes: https://lore.kernel.org/bpf/CAADnVQ+bBofJDfieyOYzSmSujSfJwDTQhiz3aJw7hE+4E2_iPA@mail.gmail.com/
Suggested-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/all/DN3QVHST3PUQ.3NINFUW0FL9IW@gmail.com/
Cc: <stable@vger.kernel.org>
Signed-off-by: Slawomir Stepien <sst@poczta.fm>
---
drivers/net/veth.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index cce253b58c2b..8bb015c13376 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -63,7 +63,6 @@ struct veth_rq {
struct napi_struct __rcu *napi; /* points to xdp_napi when the latter is initialized */
struct net_device *dev;
struct bpf_prog __rcu *xdp_prog;
- struct xdp_mem_info xdp_mem;
struct veth_rq_stats stats;
bool rx_notify_masked;
struct ptr_ring xdp_ring;
@@ -746,6 +745,9 @@ static void veth_xdp_get(struct xdp_buff *xdp)
struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
int i;
+ /* the buff holds plain page references from here on */
+ xdp->rxq->mem.type = MEM_TYPE_PAGE_SHARED;
+
get_page(virt_to_page(xdp->data));
if (likely(!xdp_buff_has_frags(xdp)))
return;
@@ -755,6 +757,7 @@ static void veth_xdp_get(struct xdp_buff *xdp)
}
static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq,
+ struct xdp_rxq_info *rxq,
struct xdp_buff *xdp,
struct sk_buff **pskb)
{
@@ -773,7 +776,9 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq,
/* SKB "head" area always have tailroom for skb_shared_info */
frame_sz = skb_end_pointer(skb) - skb->head;
frame_sz += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
- xdp_init_buff(xdp, frame_sz, &rq->xdp_rxq);
+ /* the prog can free only frags and they came from skb_pp_cow_data() */
+ rxq->mem.type = MEM_TYPE_PAGE_POOL;
+ xdp_init_buff(xdp, frame_sz, rxq);
xdp_prepare_buff(xdp, skb->head, skb_headroom(skb),
skb_headlen(skb), true);
@@ -794,6 +799,7 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq,
}
static struct sk_buff *veth_xdp_rcv_skb(struct veth_rq *rq,
+ struct xdp_rxq_info *rxq,
struct sk_buff *skb,
struct veth_xdp_tx_bq *bq,
struct veth_stats *stats)
@@ -815,7 +821,7 @@ static struct sk_buff *veth_xdp_rcv_skb(struct veth_rq *rq,
}
__skb_push(skb, skb->data - skb_mac_header(skb));
- if (veth_convert_skb_to_xdp_buff(rq, xdp, &skb))
+ if (veth_convert_skb_to_xdp_buff(rq, rxq, xdp, &skb))
goto drop;
vxbuf.skb = skb;
@@ -830,7 +836,6 @@ static struct sk_buff *veth_xdp_rcv_skb(struct veth_rq *rq,
case XDP_TX:
veth_xdp_get(xdp);
consume_skb(skb);
- xdp->rxq->mem = rq->xdp_mem;
if (unlikely(veth_xdp_tx(rq, xdp, bq) < 0)) {
trace_xdp_exception(rq->dev, xdp_prog, act);
stats->rx_drops++;
@@ -842,7 +847,6 @@ static struct sk_buff *veth_xdp_rcv_skb(struct veth_rq *rq,
case XDP_REDIRECT:
veth_xdp_get(xdp);
consume_skb(skb);
- xdp->rxq->mem = rq->xdp_mem;
if (xdp_do_redirect(rq->dev, xdp, xdp_prog)) {
stats->rx_drops++;
goto err_xdp;
@@ -948,7 +952,7 @@ static int veth_xdp_rcv(struct veth_rq *rq, int budget,
struct sk_buff *skb = ptr;
stats->xdp_bytes += skb->len;
- skb = veth_xdp_rcv_skb(rq, skb, bq, stats);
+ skb = veth_xdp_rcv_skb(rq, &rxq, skb, bq, stats);
if (skb) {
if (skb_shared(skb) || skb_unclone(skb, GFP_ATOMIC))
netif_receive_skb(skb);
@@ -1154,9 +1158,6 @@ static int veth_enable_xdp_range(struct net_device *dev, int start, int end,
NULL);
if (err < 0)
goto err_reg_mem;
-
- /* Save original mem info as it can be overwritten */
- rq->xdp_mem = rq->xdp_rxq.mem;
}
return 0;
@@ -1185,7 +1186,6 @@ static void veth_disable_xdp_range(struct net_device *dev, int start, int end,
for (i = start; i < end; i++) {
struct veth_rq *rq = &priv->rq[i];
- rq->xdp_rxq.mem = rq->xdp_mem;
xdp_rxq_info_unreg(&rq->xdp_rxq);
if (delete_napi)
--
2.56.0
next prev parent reply other threads:[~2026-11-27 10:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 10:01 [PATCH net v9 0/6] xdp: fix page_pool leaks Slawomir Stepien
2026-11-27 10:01 ` [PATCH net v9 1/6] xdp: run generic XDP on frags with a copy of the rxq info Slawomir Stepien
2026-11-27 10:01 ` [PATCH net v9 2/6] bpf: test_run: Set frag_size on " Slawomir Stepien
2026-11-27 10:01 ` [PATCH net v9 3/6] veth: use the frame mem type when running XDP on an xdp_frame Slawomir Stepien
2026-11-27 10:01 ` Slawomir Stepien [this message]
2026-11-28 10:03 ` [PATCH net v9 4/6] veth: use the page_pool mem type when running XDP on an skb netdev-bot+sashiko
2026-11-27 10:01 ` [PATCH net v9 5/6] selftests/bpf: add xdp_shrink_frags Slawomir Stepien
2026-11-28 10:04 ` netdev-bot+sashiko
2026-11-27 10:01 ` [PATCH net v9 6/6] selftests/bpf: Grow test_run and generic XDP frags after a test run Slawomir Stepien
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=20261127100132.1977890-5-sst@poczta.fm \
--to=sst@poczta.fm \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=jiayuan.chen@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lorenzo.bianconi@oss.qualcomm.com \
--cc=lorenzo@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=phx0fer@gmail.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tavip@google.com \
--cc=tianyi@cloudflare.com \
--cc=toke@redhat.com \
--cc=willemb@google.com \
--cc=yonghong.song@linux.dev \
/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