* [PATCH v7 bpf 1/5] bpf: test_run: Use a private rxq info for XDP test runs
2026-11-19 13:30 [PATCH v7 bpf 0/5] xdp: fix page_pool leaks Slawomir Stepien
@ 2026-11-19 13:30 ` Slawomir Stepien
2026-11-19 13:49 ` sashiko-bot
2026-11-19 13:30 ` [PATCH v7 bpf 2/5] xdp: introduce xdp_convert_skb_to_buff() Slawomir Stepien
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Slawomir Stepien @ 2026-11-19 13:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, David S . Miller,
Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev
Cc: bpf, netdev, Maciej Fijalkowski, Tianyi Gao, Octavian Purdila,
Toke Høiland-Jørgensen, Alexander Lobakin,
Ilias Apalodimas, Lorenzo Bianconi, Magnus Karlsson,
Ihor Solodrai, Eric Dumazet, Paolo Abeni, Andrew Lunn,
Simon Horman, Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman,
Song Liu, Yonghong Song, Jiri Olsa, Kumar Kartikeya Dwivedi,
Shuah Khan, linux-kselftest, Slawomir Stepien, stable
bpf_prog_test_run_xdp() runs the program with xdp->rxq pointing to the
xdp_rxq_info of a real device queue: queue 0 of the loopback device, or
the queue given by ingress_ifindex and rx_queue_index in the context.
The frags of a multi-buffer test packet come from alloc_page(), and when
the program releases one with bpf_xdp_adjust_tail() or
bpf_xdp_pull_data(), __xdp_return() frees it according to
xdp->rxq->mem.type. This only works as long as nobody else changes the
mem type of that shared queue.
The next patch makes generic XDP set the mem type of the queue it runs
on to MEM_TYPE_PAGE_POOL, since frags it hands to the program come from
skb_pp_cow_data(). After any packet went through generic XDP on lo, a
later test run would free its alloc_page() frags as page_pool pages:
WARNING: include/net/page_pool/helpers.h:305 at __xdp_return+0x828/0x9c0
Call Trace:
bpf_xdp_adjust_tail+0x8a0/0xd10
bpf_prog_..._xdp_adjust_tail_shrink+0xe1/0x101
bpf_test_run+0x31a/0xc30
bpf_prog_test_run_xdp+0x948/0x1740
and leak the page. Restoring the mem type after generic XDP would not
be enough, as generic XDP may run on the same queue on another CPU at
the same time.
Run the program on a private copy of the rxq info instead, with
MEM_TYPE_PAGE_SHARED, which describes the memory test_run allocates.
devmap and cpumap already do the same for the programs they run. The
device and queue index stay the same, so the program sees the same
ingress_ifindex and rx_queue_index, and xdp_convert_buff_to_md() still
drops the device reference. Live frames mode does not allow frags and
uses its own rxq info for the page_pool frames, so it is unaffected.
The problem was found by Sashiko AI review and BPF CI in the review of
v6 of this series.
Link: https://lore.kernel.org/all/sashiko-outbox-197255@kernel.org/
Cc: <stable@vger.kernel.org> # 6.4.x
Signed-off-by: Slawomir Stepien <sst@poczta.fm>
---
net/bpf/test_run.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index d6c9dc62182e..676107758678 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -1348,6 +1348,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
u32 repeat = kattr->test.repeat;
struct netdev_rx_queue *rxqueue;
struct skb_shared_info *sinfo;
+ struct xdp_rxq_info rxq;
struct xdp_buff xdp = {};
int i, ret = -EINVAL;
struct xdp_md *ctx;
@@ -1426,6 +1427,14 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
if (ret)
goto free_data;
+ /* xdp.rxq points to the rxq info of a real device queue, which
+ * generic XDP updates for every packet it runs on. Use a private
+ * copy with the mem type of the frags allocated below.
+ */
+ rxq = *xdp.rxq;
+ rxq.mem = (struct xdp_mem_info){ .type = MEM_TYPE_PAGE_SHARED };
+ xdp.rxq = &rxq;
+
size = linear_sz;
if (unlikely(kattr->test.data_size_in > size)) {
void __user *data_in = u64_to_user_ptr(kattr->test.data_in);
--
2.56.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH v7 bpf 1/5] bpf: test_run: Use a private rxq info for XDP test runs
2026-11-19 13:30 ` [PATCH v7 bpf 1/5] bpf: test_run: Use a private rxq info for XDP test runs Slawomir Stepien
@ 2026-11-19 13:49 ` sashiko-bot
0 siblings, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-11-19 13:49 UTC (permalink / raw)
To: Slawomir Stepien; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] bpf: shared lo xdp_rxq.frag_size mutation in
bpf_prog_test_run_xdp()
- [Low] bpf: non-standard multi-line comment style in
bpf_prog_test_run_xdp()
- [Low] bpf: missing Fixes: trailer on commit marked for stable backport
--
commit 56f6fcd36def90ece50bcb79a3714bded7c3b347
Author: Slawomir Stepien <sst@poczta.fm>
> bpf: test_run: Use a private rxq info for XDP test runs
>
> bpf_prog_test_run_xdp() runs the program with xdp->rxq pointing to the
> xdp_rxq_info of a real device queue: queue 0 of the loopback device, or
> the queue given by ingress_ifindex and rx_queue_index in the context.
> The frags of a multi-buffer test packet come from alloc_page(), and when
> the program releases one with bpf_xdp_adjust_tail() or
> bpf_xdp_pull_data(), __xdp_return() frees it according to
> xdp->rxq->mem.type. This only works as long as nobody else changes the
> mem type of that shared queue.
>
> The next patch makes generic XDP set the mem type of the queue it runs
> on to MEM_TYPE_PAGE_POOL, since frags it hands to the program come from
> skb_pp_cow_data(). After any packet went through generic XDP on lo, a
> later test run would free its alloc_page() frags as page_pool pages:
>
> WARNING: include/net/page_pool/helpers.h:305 at __xdp_return+0x828/0x9c0
> Call Trace:
> bpf_xdp_adjust_tail+0x8a0/0xd10
> bpf_prog_..._xdp_adjust_tail_shrink+0xe1/0x101
> bpf_test_run+0x31a/0xc30
> bpf_prog_test_run_xdp+0x948/0x1740
>
> and leak the page. Restoring the mem type after generic XDP would not
> be enough, as generic XDP may run on the same queue on another CPU at
> the same time.
>
> Run the program on a private copy of the rxq info instead, with
> MEM_TYPE_PAGE_SHARED, which describes the memory test_run allocates.
> devmap and cpumap already do the same for the programs they run. The
> device and queue index stay the same, so the program sees the same
> ingress_ifindex and rx_queue_index, and xdp_convert_buff_to_md() still
> drops the device reference. Live frames mode does not allow frags and
> uses its own rxq info for the page_pool frames, so it is unaffected.
>
> The problem was found by Sashiko AI review and BPF CI in the review of
> v6 of this series.
>
> Link: https://lore.kernel.org/all/sashiko-outbox-197255@kernel.org/
> Cc: <stable@vger.kernel.org> # 6.4.x
> Signed-off-by: Slawomir Stepien <sst@poczta.fm>
[Severity: Low]
Since this commit is tagged for stable backporting and fixes freeing of
alloc_page() fragments in bpf_prog_test_run_xdp(), should it include a
Fixes: tag?
Fixes: 1c1949982524 ("bpf: introduce frags support to bpf_prog_test_run_xdp()")
> diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
> index d6c9dc62182ee..6761077586780 100644
> --- a/net/bpf/test_run.c
> +++ b/net/bpf/test_run.c
> @@ -1348,6 +1348,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
> u32 repeat = kattr->test.repeat;
> struct netdev_rx_queue *rxqueue;
> struct skb_shared_info *sinfo;
> + struct xdp_rxq_info rxq;
> struct xdp_buff xdp = {};
> int i, ret = -EINVAL;
> struct xdp_md *ctx;
> @@ -1426,6 +1427,14 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
> if (ret)
> goto free_data;
>
> + /* xdp.rxq points to the rxq info of a real device queue, which
> + * generic XDP updates for every packet it runs on. Use a private
> + * copy with the mem type of the frags allocated below.
> + */
[Severity: Low]
This isn't a bug, but BPF coding style places the opening /* of a
multi-line comment on its own line, with the comment text starting on the
next line.
> + rxq = *xdp.rxq;
> + rxq.mem = (struct xdp_mem_info){ .type = MEM_TYPE_PAGE_SHARED };
> + xdp.rxq = &rxq;
[Severity: High]
Should frag_size = PAGE_SIZE also be set on the private rxq copy here
instead of mutating the shared loopback queue's rxqueue->xdp_rxq.frag_size
earlier in bpf_prog_test_run_xdp()?
net/bpf/test_run.c:bpf_prog_test_run_xdp() {
...
rxqueue = __netif_get_rx_queue(current->nsproxy->net_ns->loopback_dev, 0);
rxqueue->xdp_rxq.frag_size = PAGE_SIZE;
xdp_init_buff(&xdp, rxqueue->xdp_rxq.frag_size, &rxqueue->xdp_rxq);
xdp_prepare_buff(&xdp, data, headroom, linear_sz, true);
sinfo = xdp_get_shared_info_from_buff(&xdp);
ret = xdp_convert_md_to_buff(ctx, &xdp);
...
}
When ctx->ingress_ifindex points to a device queue other than loopback
queue 0, xdp_convert_md_to_buff() switches xdp.rxq to that queue's
xdp_rxq_info, so rxq = *xdp.rxq inherits the target queue's frag_size
rather than PAGE_SIZE even though test_run allocates PAGE_SIZE pages via
alloc_page() below. In bpf_xdp_frags_increase_tail(), a target queue with
frag_size == 0 (such as veth or tun) or frag_size > PAGE_SIZE causes
tail expansion to fail with -EOPNOTSUPP, while 0 < frag_size < PAGE_SIZE
can compute a negative tailroom and trigger WARN_ON_ONCE(tailroom < 0).
In addition, writing PAGE_SIZE into the shared loopback queue 0
rxqueue->xdp_rxq.frag_size leaves lo with rxq->frag_size == PAGE_SIZE for
later generic XDP runs; if a non-linear skb passes through generic XDP on
lo, skb_pp_cow_data() can allocate sub-page fragments from a shared
page_pool page while bpf_xdp_frags_increase_tail() lets
bpf_xdp_adjust_tail() grow a sub-page fragment up to PAGE_SIZE and write
out of bounds into adjacent fragments.
Passing PAGE_SIZE directly to xdp_init_buff(&xdp, PAGE_SIZE,
&rxqueue->xdp_rxq) and setting rxq.frag_size = PAGE_SIZE on the private
rxq copy avoids mutating the shared loopback queue and keeps rxq.frag_size
consistent with the allocated fragment pages.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119133032.2015656-1-sst@poczta.fm?part=1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v7 bpf 2/5] xdp: introduce xdp_convert_skb_to_buff()
2026-11-19 13:30 [PATCH v7 bpf 0/5] xdp: fix page_pool leaks Slawomir Stepien
2026-11-19 13:30 ` [PATCH v7 bpf 1/5] bpf: test_run: Use a private rxq info for XDP test runs Slawomir Stepien
@ 2026-11-19 13:30 ` Slawomir Stepien
2026-11-19 13:41 ` sashiko-bot
2026-11-19 14:11 ` bot+bpf-ci
2026-11-19 13:30 ` [PATCH v7 bpf 3/5] veth: use the frame mem type when running XDP on an xdp_frame Slawomir Stepien
` (2 subsequent siblings)
4 siblings, 2 replies; 12+ messages in thread
From: Slawomir Stepien @ 2026-11-19 13:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, David S . Miller,
Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev
Cc: bpf, netdev, Maciej Fijalkowski, Tianyi Gao, Octavian Purdila,
Toke Høiland-Jørgensen, Alexander Lobakin,
Ilias Apalodimas, Lorenzo Bianconi, Magnus Karlsson,
Ihor Solodrai, Eric Dumazet, Paolo Abeni, Andrew Lunn,
Simon Horman, Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman,
Song Liu, Yonghong Song, Jiri Olsa, Kumar Kartikeya Dwivedi,
Shuah Khan, linux-kselftest, syzbot+ff145014d6b0ce64a173, stable,
Slawomir Stepien
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Currently, generic XDP hook uses xdp_rxq_info from netstack Rx queues
which do not have its XDP memory model registered. There is a case when
XDP program calls bpf_xdp_adjust_tail() BPF helper, which in turn
releases underlying memory. This happens when it consumes enough amount
of bytes and when XDP buffer has fragments. For this action the memory
model knowledge passed to XDP program is crucial so that core can call
suitable function for freeing/recycling the page.
For netstack queues it defaults to MEM_TYPE_PAGE_SHARED (0) due to lack
of mem model registration. The problem we're fixing here is when kernel
copied the skb to new buffer backed by system's page_pool and XDP buffer
is built around it. Then when bpf_xdp_adjust_tail() calls
__xdp_return(), it acts incorrectly due to mem type not being set to
MEM_TYPE_PAGE_POOL and causes a page leak.
Pull out the existing code from bpf_prog_run_generic_xdp() that
init/prepares xdp_buff onto new helper xdp_convert_skb_to_buff() and
set there the mem type of the rxq info that the xdp_buff points to.
Make it agnostic to current skb->data position.
The mem type is only consulted when the program releases fragments; the
head can not be freed from under the skb. All current users pass skbs
with fragments through skb_pp_cow_data() first, and when the CoW fails
the skb is linearized, so fragments seen here are always page_pool
backed. Hence set MEM_TYPE_PAGE_POOL unconditionally and warn under
CONFIG_DEBUG_NET if a non-linear skb shows up without pp_recycle.
This problem was triggered by syzbot as well as by the AF_XDP test
suite.
Reported-by: syzbot+ff145014d6b0ce64a173@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/6756c37b.050a0220.a30f1.019a.GAE@google.com/
Fixes: e6d5dbdd20aa ("xdp: add multi-buff support for xdp running in generic mode")
Cc: <stable@vger.kernel.org> # 6.4.x
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Co-developed-by: Octavian Purdila <tavip@google.com>
Signed-off-by: Octavian Purdila <tavip@google.com> # whole analysis, testing, initiating a fix
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> # commit msg and proposed more robust fix
[sst: rebased onto bpf/master; set MEM_TYPE_PAGE_POOL unconditionally, add
DEBUG_NET_WARN_ON_ONCE() and kdoc as agreed in v4/v5 review; dropped
Tested-by/Reviewed-by as the code changed; reworded the description
of the mem type and dropped the stale BPF CI remark (BPF CI)]
Signed-off-by: Slawomir Stepien <sst@poczta.fm>
---
include/net/xdp.h | 36 ++++++++++++++++++++++++++++++++++++
net/core/dev.c | 25 ++++---------------------
2 files changed, 40 insertions(+), 21 deletions(-)
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 07231adfb5f8..28bd78dbef20 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -389,6 +389,42 @@ struct sk_buff *xdp_build_skb_from_frame(struct xdp_frame *xdpf,
struct net_device *dev);
struct xdp_frame *xdpf_clone(struct xdp_frame *xdpf);
+/**
+ * xdp_convert_skb_to_buff - build an xdp_buff on top of an skb
+ * @skb: skb to describe, packet data is taken from its MAC header onwards
+ * @xdp: xdp_buff to initialize
+ * @xdp_rxq: Rx queue info to attach to @xdp
+ *
+ * The memory type set on @xdp_rxq is only used to release fragments that
+ * the XDP program consumes; the head can not be freed from under the skb.
+ * A non-linear @skb is expected to have gone through skb_pp_cow_data(), so
+ * all of its fragments are page_pool backed.
+ */
+static inline
+void xdp_convert_skb_to_buff(struct sk_buff *skb, struct xdp_buff *xdp,
+ struct xdp_rxq_info *xdp_rxq)
+{
+ u32 frame_sz, pkt_len;
+
+ /* 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));
+ pkt_len = skb_tail_pointer(skb) - skb_mac_header(skb);
+
+ xdp_init_buff(xdp, frame_sz, xdp_rxq);
+ xdp_prepare_buff(xdp, skb->head, skb->mac_header, pkt_len, true);
+
+ if (skb_is_nonlinear(skb)) {
+ skb_shinfo(skb)->xdp_frags_size = skb->data_len;
+ xdp_buff_set_frags_flag(xdp);
+ } else {
+ xdp_buff_clear_frags_flag(xdp);
+ }
+
+ DEBUG_NET_WARN_ON_ONCE(skb_is_nonlinear(skb) && !skb->pp_recycle);
+ xdp->rxq->mem.type = MEM_TYPE_PAGE_POOL;
+}
+
static inline
void xdp_convert_frame_to_buff(const struct xdp_frame *frame,
struct xdp_buff *xdp)
diff --git a/net/core/dev.c b/net/core/dev.c
index 3ac700d37e59..4eeeb0182a6a 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5667,35 +5667,18 @@ static struct netdev_rx_queue *netif_get_rxqueue(struct sk_buff *skb)
u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp,
const struct bpf_prog *xdp_prog)
{
- void *orig_data, *orig_data_end, *hard_start;
+ void *orig_data, *orig_data_end;
struct netdev_rx_queue *rxqueue;
bool orig_bcast, orig_host;
- u32 mac_len, frame_sz;
+ u32 metalen, act, mac_len;
__be16 orig_eth_type;
struct ethhdr *eth;
- u32 metalen, act;
int off;
- /* The XDP program wants to see the packet starting at the MAC
- * header.
- */
+ rxqueue = netif_get_rxqueue(skb);
mac_len = skb->data - skb_mac_header(skb);
- hard_start = skb->data - skb_headroom(skb);
-
- /* SKB "head" area always have tailroom for skb_shared_info */
- frame_sz = (void *)skb_end_pointer(skb) - hard_start;
- frame_sz += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
- rxqueue = netif_get_rxqueue(skb);
- xdp_init_buff(xdp, frame_sz, &rxqueue->xdp_rxq);
- xdp_prepare_buff(xdp, hard_start, skb_headroom(skb) - mac_len,
- skb_headlen(skb) + mac_len, true);
- if (skb_is_nonlinear(skb)) {
- skb_shinfo(skb)->xdp_frags_size = skb->data_len;
- xdp_buff_set_frags_flag(xdp);
- } else {
- xdp_buff_clear_frags_flag(xdp);
- }
+ xdp_convert_skb_to_buff(skb, xdp, &rxqueue->xdp_rxq);
orig_data_end = xdp->data_end;
orig_data = xdp->data;
--
2.56.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH v7 bpf 2/5] xdp: introduce xdp_convert_skb_to_buff()
2026-11-19 13:30 ` [PATCH v7 bpf 2/5] xdp: introduce xdp_convert_skb_to_buff() Slawomir Stepien
@ 2026-11-19 13:41 ` sashiko-bot
2026-11-19 14:11 ` bot+bpf-ci
1 sibling, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-11-19 13:41 UTC (permalink / raw)
To: Slawomir Stepien; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] xdp: malformed Signed-off-by trailers with trailing comments
--
commit b52c8a4a1dfa14f2b9eeae449bd2e813e860af3a
Author: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
xdp: introduce xdp_convert_skb_to_buff()
This commit factors out xdp_buff initialization from
bpf_prog_run_generic_xdp() into xdp_convert_skb_to_buff() and sets
MEM_TYPE_PAGE_POOL on the attached xdp_rxq_info so fragments released by
bpf_xdp_adjust_tail() are recycled properly.
[Severity: High]
In the commit message trailer block, the Signed-off-by trailers for
Octavian Purdila and Maciej Fijalkowski have trailing hash comments
appended after the closing angle bracket of the email address. Per
Documentation/process/submitting-patches.rst, Signed-off-by lines must end
at the closing > of the email address; any contributor attribution notes
should be moved into a separate bracketed [name: description] block.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119133032.2015656-1-sst@poczta.fm?part=2
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v7 bpf 2/5] xdp: introduce xdp_convert_skb_to_buff()
2026-11-19 13:30 ` [PATCH v7 bpf 2/5] xdp: introduce xdp_convert_skb_to_buff() Slawomir Stepien
2026-11-19 13:41 ` sashiko-bot
@ 2026-11-19 14:11 ` bot+bpf-ci
1 sibling, 0 replies; 12+ messages in thread
From: bot+bpf-ci @ 2026-11-19 14:11 UTC (permalink / raw)
To: sst, ast, daniel, davem, kuba, hawk, john.fastabend, sdf
Cc: bpf, netdev, maciej.fijalkowski, tianyi, tavip, toke,
aleksander.lobakin, ilias.apalodimas, lorenzo, magnus.karlsson,
ihor.solodrai, edumazet, pabeni, andrew+netdev, horms, andrii,
martin.lau, eddyz87, song, yonghong.song, jolsa, memxor, shuah,
linux-kselftest, syzbot+ff145014d6b0ce64a173, stable, sst, ast,
andrii, daniel, martin.lau, eddyz87, yonghong.song, mason,
ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 3057 bytes --]
> xdp: introduce xdp_convert_skb_to_buff()
TL;DR:
- Commit message calls the bug a page leak; it may be a use-after-free of
page_pool pages
- Stable Cc 6.4.x predates the Fixes: tag (v6.9)
- kdoc may overstate mem type usage (nit)
> Then when bpf_xdp_adjust_tail() calls
> __xdp_return(), it acts incorrectly due to mem type not being set to
> MEM_TYPE_PAGE_POOL and causes a page leak.
Is "causes a page leak" the full impact?
The mechanism is bpf_xdp_adjust_tail() -> bpf_xdp_frags_shrink_tail() ->
bpf_xdp_shrink_data() -> __xdp_return(netmem, MEM_TYPE_PAGE_SHARED) ->
page_frag_free(). That ends in put_page_testzero() on a page_pool page.
With page checks enabled this is reported as "page_pool leak" and the page
is not freed. Without them, page_pool keeps _refcount at 1 and counts
fragment users in pp_ref_count, and skb_pp_cow_data() allocates
fragment-sized chunks. A single page_frag_free() can therefore hand back
to the buddy allocator a page that other skbs or pool->frag_page still
use, which looks like a use-after-free rather than only a leak.
Could the commit message describe that?
> Cc: <stable@vger.kernel.org> # 6.4.x
The Fixes: tag points at e6d5dbdd20aa, which first landed in v6.9. Before
that, generic XDP linearized every skb and never set the frags flag, so
this bug cannot occur on 6.4 through 6.8.
The later veth patch in this series (1d3541dbf827) appears to be why 6.4.x
is listed, since it uses this helper and needs it as a backport
prerequisite. Could the commit message either say that, or align the
stable range with the Fixes: tag?
> diff --git a/include/net/xdp.h b/include/net/xdp.h
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h
[ ... ]
> +/**
> + * xdp_convert_skb_to_buff - build an xdp_buff on top of an skb
> + * @skb: skb to describe, packet data is taken from its MAC header onwards
> + * @xdp: xdp_buff to initialize
> + * @xdp_rxq: Rx queue info to attach to @xdp
> + *
> + * The memory type set on @xdp_rxq is only used to release fragments that
> + * the XDP program consumes; the head can not be freed from under the skb.
> + * A non-linear @skb is expected to have gone through skb_pp_cow_data(), so
> + * all of its fragments are page_pool backed.
> + */
This isn't a bug, but is the "only used to release fragments" statement a
property of this helper, or of its current caller?
It holds for generic XDP. However, the veth patch later in this series
(1d3541dbf827) converts the xdp_buff to an xdp_frame on XDP_TX and
XDP_REDIRECT, where the head is released through the same mem type, and it
has to overwrite rq->xdp_rxq.mem after calling this helper.
The kdoc also does not mention that the mem type stays set on the caller's
possibly shared @xdp_rxq after the call. Should the kdoc say that these
properties depend on the caller?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44535627869
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v7 bpf 3/5] veth: use the frame mem type when running XDP on an xdp_frame
2026-11-19 13:30 [PATCH v7 bpf 0/5] xdp: fix page_pool leaks Slawomir Stepien
2026-11-19 13:30 ` [PATCH v7 bpf 1/5] bpf: test_run: Use a private rxq info for XDP test runs Slawomir Stepien
2026-11-19 13:30 ` [PATCH v7 bpf 2/5] xdp: introduce xdp_convert_skb_to_buff() Slawomir Stepien
@ 2026-11-19 13:30 ` Slawomir Stepien
2026-11-19 13:54 ` bot+bpf-ci
2026-11-19 13:30 ` [PATCH v7 bpf 4/5] veth: update mem type in xdp_buff Slawomir Stepien
2026-11-19 13:30 ` [PATCH v7 bpf 5/5] selftests/bpf: Shrink test_run frags after generic XDP ran on lo Slawomir Stepien
4 siblings, 1 reply; 12+ messages in thread
From: Slawomir Stepien @ 2026-11-19 13:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, David S . Miller,
Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev
Cc: bpf, netdev, Maciej Fijalkowski, Tianyi Gao, Octavian Purdila,
Toke Høiland-Jørgensen, Alexander Lobakin,
Ilias Apalodimas, Lorenzo Bianconi, Magnus Karlsson,
Ihor Solodrai, Eric Dumazet, Paolo Abeni, Andrew Lunn,
Simon Horman, Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman,
Song Liu, Yonghong Song, Jiri Olsa, Kumar Kartikeya Dwivedi,
Shuah Khan, linux-kselftest, Slawomir Stepien, stable
veth_xdp_rcv_one() runs the XDP program on frames queued by
ndo_xdp_xmit(), i.e. redirected to veth or sent back by the peer with
XDP_TX. The xdp_buff points at rq->xdp_rxq, whose mem type is whatever
the previous packet left there: the queue's MEM_TYPE_PAGE_SHARED, or
the type of an earlier frame or skb. frame->mem_type is copied in only
for XDP_TX and XDP_REDIRECT, after the program has run.
bpf_xdp_adjust_tail() and bpf_xdp_pull_data() release whole frags with
the rxq mem type. For a MEM_TYPE_PAGE_POOL frame and a stale
MEM_TYPE_PAGE_SHARED rxq, page_frag_free() drops the reference owned by
the page_pool:
BUG: Bad page state in process ping pfn:2244a
page dumped because: page_pool leak
bad_page.cold+0x58/0x6b
__free_frozen_pages+0x837/0x1280
page_frag_free+0x1a4/0x200
__xdp_return+0x3a8/0x9c0
bpf_xdp_adjust_tail+0x8a0/0xd10
bpf_prog_007aa02d10594afa_xdp_trim_drop+0x8f/0xd8
veth_xdp_rcv_one+0x389/0x10e0
veth_xdp_rcv+0x1c5/0xb20
veth_poll+0x33d/0xe00
...
kernel BUG at ./include/linux/mm.h:1820!
The reverse, a MEM_TYPE_PAGE_SHARED frame after a page_pool one, hands
pages that are not page_pool backed to page_pool_put_full_netmem().
Set the rxq mem type from the frame before running the program, as
cpumap and devmap do, and drop the now redundant updates in the XDP_TX
and XDP_REDIRECT paths.
The splat above is from two veth peers with the next patch applied:
one bounces multi-buffer packets with XDP_TX, the other trims all frags
of the resulting frames. Page pool backed frames from other drivers
can hit the same path today.
Fixes: 718a18a0c8a6 ("veth: Rework veth_xdp_rcv_skb in order to accept non-linear skb")
Cc: <stable@vger.kernel.org>
Reviewed-by: Tianyi Gao <tianyi@cloudflare.com>
Signed-off-by: Slawomir Stepien <sst@poczta.fm>
---
drivers/net/veth.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 3eca92d3dc60..afae2c6533b9 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -658,6 +658,8 @@ static struct xdp_frame *veth_xdp_rcv_one(struct veth_rq *rq,
xdp_convert_frame_to_buff(frame, xdp);
xdp->rxq = &rq->xdp_rxq;
+ /* The program may release frags, do it the frame's way */
+ xdp->rxq->mem.type = frame->mem_type;
vxbuf.skb = NULL;
act = bpf_prog_run_xdp(xdp_prog, xdp);
@@ -669,7 +671,6 @@ static struct xdp_frame *veth_xdp_rcv_one(struct veth_rq *rq,
break;
case XDP_TX:
orig_frame = *frame;
- xdp->rxq->mem.type = frame->mem_type;
if (unlikely(veth_xdp_tx(rq, xdp, bq) < 0)) {
trace_xdp_exception(rq->dev, xdp_prog, act);
frame = &orig_frame;
@@ -681,7 +682,6 @@ static struct xdp_frame *veth_xdp_rcv_one(struct veth_rq *rq,
goto xdp_xmit;
case XDP_REDIRECT:
orig_frame = *frame;
- xdp->rxq->mem.type = frame->mem_type;
if (xdp_do_redirect(rq->dev, xdp, xdp_prog)) {
frame = &orig_frame;
stats->rx_drops++;
--
2.56.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH v7 bpf 3/5] veth: use the frame mem type when running XDP on an xdp_frame
2026-11-19 13:30 ` [PATCH v7 bpf 3/5] veth: use the frame mem type when running XDP on an xdp_frame Slawomir Stepien
@ 2026-11-19 13:54 ` bot+bpf-ci
2026-11-19 14:24 ` Tianyi Gao
0 siblings, 1 reply; 12+ messages in thread
From: bot+bpf-ci @ 2026-11-19 13:54 UTC (permalink / raw)
To: sst, ast, daniel, davem, kuba, hawk, john.fastabend, sdf
Cc: bpf, netdev, maciej.fijalkowski, tianyi, tavip, toke,
aleksander.lobakin, ilias.apalodimas, lorenzo, magnus.karlsson,
ihor.solodrai, edumazet, pabeni, andrew+netdev, horms, andrii,
martin.lau, eddyz87, song, yonghong.song, jolsa, memxor, shuah,
linux-kselftest, sst, stable, ast, andrii, daniel, martin.lau,
eddyz87, yonghong.song, mason, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 2189 bytes --]
> veth: use the frame mem type when running XDP on an xdp_frame
TL;DR: Commit message only: the Fixes: tag (718a18a0c8a6) looks wrong, since
it only touches the skb path; the review suggests naming the commit that
introduced the stale rxq mem type problem.
> veth: use the frame mem type when running XDP on an xdp_frame
>
> veth_xdp_rcv_one() runs the XDP program on frames queued by
> ndo_xdp_xmit(), i.e. redirected to veth or sent back by the peer with
> XDP_TX. The xdp_buff points at rq->xdp_rxq, whose mem type is whatever
> the previous packet left there: the queue's MEM_TYPE_PAGE_SHARED, or
> the type of an earlier frame or skb. frame->mem_type is copied in only
> for XDP_TX and XDP_REDIRECT, after the program has run.
> bpf_xdp_adjust_tail() and bpf_xdp_pull_data() release whole frags with
> the rxq mem type.
[ ... ]
> Set the rxq mem type from the frame before running the program, as
> cpumap and devmap do, and drop the now redundant updates in the XDP_TX
> and XDP_REDIRECT paths.
[ ... ]
> Fixes: 718a18a0c8a6 ("veth: Rework veth_xdp_rcv_skb in order to accept non-linear skb")
> Cc: <stable@vger.kernel.org>
> Reviewed-by: Tianyi Gao <tianyi@cloudflare.com>
> Signed-off-by: Slawomir Stepien <sst@poczta.fm>
Is this Fixes: tag pointing at the right commit?
718a18a0c8a6 only reworks the skb path (veth_xdp_rcv_skb() and
veth_convert_skb_to_xdp_buff()), and does not touch veth_xdp_rcv_one(),
which is the only function this patch changes.
The stale rxq mem type on the xdp_frame path comes from the
XDP_TX/XDP_REDIRECT-only "xdp->rxq->mem = frame->mem" assignments, which
predate that commit and were added by d1396004dd86 ("veth: Add XDP TX and
REDIRECT").
The stale type only becomes harmful once frag release uses the rxq mem type,
which happened in bf25146a5595 for bpf_xdp_adjust_tail() and in 4dce1a0d7cf3
for bpf_xdp_pull_data().
Could the tag be changed to name the commit that actually introduced the
problem?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44535627869
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v7 bpf 3/5] veth: use the frame mem type when running XDP on an xdp_frame
2026-11-19 13:54 ` bot+bpf-ci
@ 2026-11-19 14:24 ` Tianyi Gao
0 siblings, 0 replies; 12+ messages in thread
From: Tianyi Gao @ 2026-11-19 14:24 UTC (permalink / raw)
To: bot+bpf-ci
Cc: sst, ast, daniel, davem, kuba, hawk, john.fastabend, sdf, bpf,
netdev, maciej.fijalkowski, tavip, toke, aleksander.lobakin,
ilias.apalodimas, lorenzo, magnus.karlsson, ihor.solodrai,
edumazet, pabeni, andrew+netdev, horms, andrii, martin.lau,
eddyz87, song, yonghong.song, jolsa, memxor, shuah,
linux-kselftest, stable, martin.lau, mason
On Thu, 19 Nov 2026 13:54:58 +0000, bot+bpf-ci@kernel.org wrote:
> Is this Fixes: tag pointing at the right commit?
>
> 718a18a0c8a6 only reworks the skb path (veth_xdp_rcv_skb() and
> veth_convert_skb_to_xdp_buff()), and does not touch veth_xdp_rcv_one(),
> which is the only function this patch changes.
I think the AI is wrong here. Before 718a18a0c8a6, veth copied a
non-linear skb into one linear page, so no frame with frags could reach
veth_xdp_rcv_one(). Either way, 718a18a0c8a6 and bf25146a5595 are both
in v5.18-rc1, so the choice makes no difference for stable.
Cheers,
Tianyi
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v7 bpf 4/5] veth: update mem type in xdp_buff
2026-11-19 13:30 [PATCH v7 bpf 0/5] xdp: fix page_pool leaks Slawomir Stepien
` (2 preceding siblings ...)
2026-11-19 13:30 ` [PATCH v7 bpf 3/5] veth: use the frame mem type when running XDP on an xdp_frame Slawomir Stepien
@ 2026-11-19 13:30 ` Slawomir Stepien
2026-11-19 13:30 ` [PATCH v7 bpf 5/5] selftests/bpf: Shrink test_run frags after generic XDP ran on lo Slawomir Stepien
4 siblings, 0 replies; 12+ messages in thread
From: Slawomir Stepien @ 2026-11-19 13:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, David S . Miller,
Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev
Cc: bpf, netdev, Maciej Fijalkowski, Tianyi Gao, Octavian Purdila,
Toke Høiland-Jørgensen, Alexander Lobakin,
Ilias Apalodimas, Lorenzo Bianconi, Magnus Karlsson,
Ihor Solodrai, Eric Dumazet, Paolo Abeni, Andrew Lunn,
Simon Horman, Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman,
Song Liu, Yonghong Song, Jiri Olsa, Kumar Kartikeya Dwivedi,
Shuah Khan, linux-kselftest, stable, Slawomir Stepien
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
When skb's headroom is not sufficient for XDP purposes,
skb_pp_cow_data() returns new skb with requested headroom space. This
skb was provided by page_pool.
For CONFIG_DEBUG_VM=y and XDP program that uses bpf_xdp_adjust_tail()
against a skb with frags, and mentioned helper consumed enough amount of
bytes that in turn released the page, following splat was observed:
[ 32.204881] BUG: Bad page state in process test_progs pfn:11c98b
[ 32.207167] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x11c98b
[ 32.210084] flags: 0x1fffe0000000000(node=0|zone=1|lastcpupid=0x7fff)
[ 32.212493] raw: 01fffe0000000000 dead000000000040 ff11000123c9b000 0000000000000000
[ 32.218056] raw: 0000000000000000 0000000000000001 00000000ffffffff 0000000000000000
[ 32.220900] page dumped because: page_pool leak
[ 32.222636] Modules linked in: bpf_testmod(O) bpf_preload
[ 32.224632] CPU: 6 UID: 0 PID: 3612 Comm: test_progs Tainted: G O 6.17.0-rc5-gfec474d29325 #6969 PREEMPT
[ 32.224638] Tainted: [O]=OOT_MODULE
[ 32.224639] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
[ 32.224641] Call Trace:
[ 32.224644] <IRQ>
[ 32.224646] dump_stack_lvl+0x4b/0x70
[ 32.224653] bad_page.cold+0xbd/0xe0
[ 32.224657] __free_frozen_pages+0x838/0x10b0
[ 32.224660] ? skb_pp_cow_data+0x782/0xc30
[ 32.224665] bpf_xdp_shrink_data+0x221/0x530
[ 32.224668] ? skb_pp_cow_data+0x6d1/0xc30
[ 32.224671] bpf_xdp_adjust_tail+0x598/0x810
[ 32.224673] ? xsk_destruct_skb+0x321/0x800
[ 32.224678] bpf_prog_004ac6bb21de57a7_xsk_xdp_adjust_tail+0x52/0xd6
[ 32.224681] veth_xdp_rcv_skb+0x45d/0x15a0
[ 32.224684] ? get_stack_info_noinstr+0x16/0xe0
[ 32.224688] ? veth_set_channels+0x920/0x920
[ 32.224691] ? get_stack_info+0x2f/0x80
[ 32.224693] ? unwind_next_frame+0x3af/0x1df0
[ 32.224697] veth_xdp_rcv.constprop.0+0x38a/0xbe0
[ 32.224700] ? common_startup_64+0x13e/0x148
[ 32.224703] ? veth_xdp_rcv_one+0xcd0/0xcd0
[ 32.224706] ? stack_trace_save+0x84/0xa0
[ 32.224709] ? stack_depot_save_flags+0x28/0x820
[ 32.224713] ? __resched_curr.constprop.0+0x332/0x3b0
[ 32.224716] ? timerqueue_add+0x217/0x320
[ 32.224719] veth_poll+0x115/0x5e0
[ 32.224722] ? veth_xdp_rcv.constprop.0+0xbe0/0xbe0
[ 32.224726] ? update_load_avg+0x1cb/0x12d0
[ 32.224730] ? update_cfs_group+0x121/0x2c0
[ 32.224733] __napi_poll+0xa0/0x420
[ 32.224736] net_rx_action+0x901/0xe90
[ 32.224740] ? run_backlog_napi+0x50/0x50
[ 32.224743] ? clockevents_program_event+0x1cc/0x280
[ 32.224746] ? hrtimer_interrupt+0x31e/0x7c0
[ 32.224749] handle_softirqs+0x151/0x430
[ 32.224752] do_softirq+0x3f/0x60
[ 32.224755] </IRQ>
It's because xdp_rxq with mem model set to MEM_TYPE_PAGE_SHARED was used
when initializing xdp_buff.
Fix this by using new helper xdp_convert_skb_to_buff(). Unlike generic
XDP, veth turns the xdp_buff into an xdp_frame on XDP_{TX,REDIRECT}, so
the head is later released through the mem type as well and the
helper's frags-only reasoning is not enough here. Advertise
MEM_TYPE_PAGE_POOL only when the whole buffer was just copied into
rq->page_pool by skb_pp_cow_data(); otherwise keep the queue's original
MEM_TYPE_PAGE_SHARED model. An skb that skips the CoW has no frags, so
nothing can be released through the mem type while the program runs.
XDP_{TX,REDIRECT} no longer reset the mem type to the queue's original
model before the buff is converted to a frame, as the frame has to
carry the type chosen above. Nothing needs to be restored afterwards
either: the previous patch makes the frame path set its own mem type
and every skb sets it here. Add a page_pool variant of veth_xdp_get()
so that we avoid refcount underflow when draining page frag.
Frames redirected out of veth can now be MEM_TYPE_PAGE_POOL. A devmap
egress program only releases their frags correctly since commit
b3ca872947ef ("bpf: Use the frame mem type in devmap egress XDP"), so
that commit has to come first when backporting, as do the previous
three patches of this series: xdp_convert_skb_to_buff() is used here,
dropping the restores relies on the frame path setting its own mem
type, and test_run needs its own rxq info once the helper sets it.
Before v6.9, generic XDP has no frags and xdp_convert_skb_to_buff()
has to be adapted to the older bpf_prog_run_generic_xdp().
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/
Cc: <stable@vger.kernel.org> # 6.4.x: b3ca872947ef: bpf: Use the frame mem type in devmap egress XDP
Cc: <stable@vger.kernel.org> # 6.4.x
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
[sst: rebased onto bpf/master; claim MEM_TYPE_PAGE_POOL only after CoW into
rq->page_pool; take page_pool refs on compound heads via netmem helpers;
drop the rq mem model restores as every path sets its own mem type now;
dropped Reviewed-by as the code changed; list the backport
prerequisites (BPF CI)]
Signed-off-by: Slawomir Stepien <sst@poczta.fm>
---
drivers/net/veth.c | 52 +++++++++++++++++++++++++++++++---------------
1 file changed, 35 insertions(+), 17 deletions(-)
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index afae2c6533b9..e159f0e00ddb 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -741,7 +741,7 @@ static void veth_xdp_rcv_bulk_skb(struct veth_rq *rq, void **frames,
}
}
-static void veth_xdp_get(struct xdp_buff *xdp)
+static void veth_xdp_get_shared(struct xdp_buff *xdp)
{
struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
int i;
@@ -754,12 +754,36 @@ static void veth_xdp_get(struct xdp_buff *xdp)
netmem_inc_ref(skb_frag_netmem(&sinfo->frags[i]));
}
+static void veth_xdp_get_pp(struct xdp_buff *xdp)
+{
+ struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
+ int i;
+
+ page_pool_ref_netmem(netmem_compound_head(virt_to_netmem(xdp->data)));
+ if (likely(!xdp_buff_has_frags(xdp)))
+ return;
+
+ for (i = 0; i < sinfo->nr_frags; i++) {
+ netmem_ref netmem = skb_frag_netmem(&sinfo->frags[i]);
+
+ page_pool_ref_netmem(netmem_compound_head(netmem));
+ }
+}
+
+static void veth_xdp_get(struct xdp_buff *xdp)
+{
+ if (xdp->rxq->mem.type == MEM_TYPE_PAGE_POOL)
+ veth_xdp_get_pp(xdp);
+ else
+ veth_xdp_get_shared(xdp);
+}
+
static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq,
struct xdp_buff *xdp,
struct sk_buff **pskb)
{
struct sk_buff *skb = *pskb;
- u32 frame_sz;
+ bool pp_cow = false;
if (skb_shared(skb) || skb_head_is_locked(skb) ||
skb_is_nonlinear(skb) ||
@@ -768,21 +792,17 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq,
goto drop;
skb = *pskb;
+ pp_cow = true;
}
- /* 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);
- xdp_prepare_buff(xdp, skb->head, skb_headroom(skb),
- skb_headlen(skb), true);
-
- if (skb_shinfo(skb)->nr_frags) {
- skb_shinfo(skb)->xdp_frags_size = skb->data_len;
- xdp_buff_set_frags_flag(xdp);
- } else {
- xdp_buff_clear_frags_flag(xdp);
- }
+ xdp_convert_skb_to_buff(skb, xdp, &rq->xdp_rxq);
+ /* Unlike generic XDP, XDP_{TX,REDIRECT} turn the buff into an
+ * xdp_frame, which later releases the head via mem.type as well.
+ * Only claim page_pool memory when the whole buffer was copied into
+ * rq->page_pool above; an skb that skipped the CoW is linear.
+ */
+ if (!pp_cow)
+ rq->xdp_rxq.mem = rq->xdp_mem;
*pskb = skb;
return 0;
@@ -830,7 +850,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 +861,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;
--
2.56.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v7 bpf 5/5] selftests/bpf: Shrink test_run frags after generic XDP ran on lo
2026-11-19 13:30 [PATCH v7 bpf 0/5] xdp: fix page_pool leaks Slawomir Stepien
` (3 preceding siblings ...)
2026-11-19 13:30 ` [PATCH v7 bpf 4/5] veth: update mem type in xdp_buff Slawomir Stepien
@ 2026-11-19 13:30 ` Slawomir Stepien
2026-11-19 13:37 ` sashiko-bot
4 siblings, 1 reply; 12+ messages in thread
From: Slawomir Stepien @ 2026-11-19 13:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, David S . Miller,
Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev
Cc: bpf, netdev, Maciej Fijalkowski, Tianyi Gao, Octavian Purdila,
Toke Høiland-Jørgensen, Alexander Lobakin,
Ilias Apalodimas, Lorenzo Bianconi, Magnus Karlsson,
Ihor Solodrai, Eric Dumazet, Paolo Abeni, Andrew Lunn,
Simon Horman, Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman,
Song Liu, Yonghong Song, Jiri Olsa, Kumar Kartikeya Dwivedi,
Shuah Khan, linux-kselftest, Slawomir Stepien
bpf_prog_test_run_xdp() used the rxq info of the loopback device's
queue 0, and generic XDP sets the mem type of that rxq info for the
packets it handles. Run a packet through generic XDP on lo in a new
netns, then repeat xdp_adjust_frags_tail_shrink there, which frees
test_run frags from the program.
Without the test_run fix this hits WARN_ON() in page_pool_unref_netmem()
and leaks the frag pages; the test itself still passes, so the failure
shows up in the kernel log (and as a panic with panic_on_warn).
Signed-off-by: Slawomir Stepien <sst@poczta.fm>
---
.../bpf/prog_tests/xdp_adjust_tail.c | 51 +++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
index 43264347e7d7..c0d54cf421d8 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include <network_helpers.h>
+#include <linux/if_link.h>
+#include <net/if.h>
+#include "xdp_dummy.skel.h"
static void test_xdp_adjust_tail_shrink(void)
{
@@ -355,6 +358,52 @@ static void test_xdp_adjust_frags_tail_grow_64k(void)
bpf_object__close(obj);
}
+/* bpf_prog_test_run_xdp() runs on the rxq of lo's queue 0, where generic
+ * XDP sets the mem type of the frags it hands to its program. Let generic
+ * XDP see a packet on lo first, then free test_run frags from the program.
+ */
+static void test_xdp_adjust_frags_tail_shrink_after_generic(void)
+{
+ struct sockaddr_in addr = {
+ .sin_family = AF_INET,
+ .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
+ .sin_port = htons(9),
+ };
+ struct netns_obj *ns = NULL;
+ struct xdp_dummy *skel;
+ int fd = -1, lo;
+
+ skel = xdp_dummy__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "xdp_dummy__open_and_load"))
+ return;
+
+ ns = netns_new("xdp_adjust_tail_ns", true);
+ if (!ASSERT_OK_PTR(ns, "netns_new"))
+ goto out;
+
+ SYS(out, "ip link set dev lo up");
+ lo = if_nametoindex("lo");
+ if (!ASSERT_GT(lo, 0, "lo ifindex"))
+ goto out;
+
+ if (!ASSERT_OK(bpf_xdp_attach(lo, bpf_program__fd(skel->progs.xdp_dummy_prog),
+ XDP_FLAGS_SKB_MODE, NULL), "attach generic XDP"))
+ goto out;
+
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (ASSERT_GE(fd, 0, "socket"))
+ ASSERT_EQ(sendto(fd, "x", 1, 0, (struct sockaddr *)&addr, sizeof(addr)),
+ 1, "sendto");
+ bpf_xdp_detach(lo, XDP_FLAGS_SKB_MODE, NULL);
+
+ test_xdp_adjust_frags_tail_shrink();
+out:
+ if (fd >= 0)
+ close(fd);
+ netns_free(ns);
+ xdp_dummy__destroy(skel);
+}
+
void test_xdp_adjust_tail(void)
{
int page_size = getpagesize();
@@ -367,6 +416,8 @@ void test_xdp_adjust_tail(void)
test_xdp_adjust_tail_grow2();
if (test__start_subtest("xdp_adjust_frags_tail_shrink"))
test_xdp_adjust_frags_tail_shrink();
+ if (test__start_subtest("xdp_adjust_frags_tail_shrink_after_generic"))
+ test_xdp_adjust_frags_tail_shrink_after_generic();
if (test__start_subtest("xdp_adjust_frags_tail_grow")) {
if (page_size == 65536)
test_xdp_adjust_frags_tail_grow_64k();
--
2.56.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH v7 bpf 5/5] selftests/bpf: Shrink test_run frags after generic XDP ran on lo
2026-11-19 13:30 ` [PATCH v7 bpf 5/5] selftests/bpf: Shrink test_run frags after generic XDP ran on lo Slawomir Stepien
@ 2026-11-19 13:37 ` sashiko-bot
0 siblings, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-11-19 13:37 UTC (permalink / raw)
To: Slawomir Stepien; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] selftests/bpf: multi-line comment style violation in
xdp_adjust_tail.c
--
commit 9a3d1edafa68cea574abb6c7a0a6330bded5c6c7
Author: Slawomir Stepien <sst@poczta.fm>
selftests/bpf: Shrink test_run frags after generic XDP ran on lo
This commit adds a BPF selftest that sends a packet through generic XDP
on the loopback interface in a new network namespace before running
test_xdp_adjust_frags_tail_shrink().
> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
> index 43264347e7d77..c0d54cf421d8c 100644
> --- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
[ ... ]
> @@ -355,6 +358,52 @@ static void test_xdp_adjust_frags_tail_grow_64k(void)
> bpf_object__close(obj);
> }
>
> +/* bpf_prog_test_run_xdp() runs on the rxq of lo's queue 0, where generic
> + * XDP sets the mem type of the frags it hands to its program. Let generic
> + * XDP see a packet on lo first, then free test_run frags from the program.
> + */
[Severity: Low]
This isn't a bug, but BPF coding style places the opening /* of a
multi-line comment on its own line with the comment text starting on the
next line.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119133032.2015656-1-sst@poczta.fm?part=5
^ permalink raw reply [flat|nested] 12+ messages in thread