From: Slawomir Stepien <sst@poczta.fm>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
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,
"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>,
"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
"Lorenzo Bianconi" <lorenzo@kernel.org>,
"Lorenzo Bianconi" <lorenzo.bianconi@oss.qualcomm.com>,
"Magnus Karlsson" <magnus.karlsson@intel.com>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>,
"Eric Dumazet" <edumazet@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"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 v8 bpf 2/7] bpf: test_run: Keep frag_size on the private rxq info
Date: Tue, 24 Nov 2026 11:40:11 +0100 [thread overview]
Message-ID: <20261124104016.532341-3-sst@poczta.fm> (raw)
In-Reply-To: <20261124104016.532341-1-sst@poczta.fm>
bpf_prog_test_run_xdp() sets frag_size of the rxq info of lo's queue 0
to PAGE_SIZE, for the PAGE_SIZE frags it allocates, before
ingress_ifindex may switch the program to another queue. This has two
effects:
The value stays on lo after the test run. Generic XDP on lo runs with
this rxq info, and bpf_xdp_frags_increase_tail() then lets a program
grow the last frag up to the end of its page. The frags generic XDP
gets from skb_pp_cow_data() can be parts of a page_pool page, so the
program overwrites what follows the frag in that page, possibly the
data of another packet. Without a test run, frag_size of lo is 0 and
the grow fails with -EOPNOTSUPP, as for generic XDP on any other
device. Generic XDP runs programs on frags since commit e6d5dbdd20aa
("xdp: add multi-buff support for xdp running in generic mode").
With ingress_ifindex, the program runs with the rxq info of that device
queue, whose frag_size is 0, so growing a frag of the test packet fails
although the frags are full pages.
The previous patch made test_run run the program on a private copy of
the rxq info. Set frag_size there and leave the device's rxq info
alone.
The problem was found by Sashiko AI review in the review of v7 of this
series.
Link: https://lore.kernel.org/all/sashiko-outbox-223211@kernel.org/
Fixes: 1c1949982524 ("bpf: introduce frags support to bpf_prog_test_run_xdp()")
Cc: <stable@vger.kernel.org> # 6.4.x
Signed-off-by: Slawomir Stepien <sst@poczta.fm>
---
net/bpf/test_run.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 9bbd83ece67b..8e9543f98211 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -1418,8 +1418,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
}
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_init_buff(&xdp, PAGE_SIZE, &rxqueue->xdp_rxq);
xdp_prepare_buff(&xdp, data, headroom, linear_sz, true);
sinfo = xdp_get_shared_info_from_buff(&xdp);
@@ -1430,10 +1429,12 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
/*
* 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.
+ * copy with the mem type and the frag size of the frags allocated
+ * below.
*/
rxq = *xdp.rxq;
rxq.mem = (struct xdp_mem_info){ .type = MEM_TYPE_PAGE_SHARED };
+ rxq.frag_size = PAGE_SIZE;
xdp.rxq = &rxq;
size = linear_sz;
--
2.56.0
next prev parent reply other threads:[~2026-11-24 10:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 10:40 [PATCH v8 bpf 0/7] xdp: fix page_pool leaks Slawomir Stepien
2026-11-24 10:40 ` [PATCH v8 bpf 1/7] bpf: test_run: Use a private rxq info for XDP test runs Slawomir Stepien
2026-11-24 10:40 ` Slawomir Stepien [this message]
2026-11-24 10:40 ` [PATCH v8 bpf 3/7] xdp: introduce xdp_convert_skb_to_buff() Slawomir Stepien
2026-11-24 11:32 ` bot+bpf-ci
2026-11-24 10:40 ` [PATCH v8 bpf 4/7] veth: use the frame mem type when running XDP on an xdp_frame Slawomir Stepien
2026-11-24 10:40 ` [PATCH v8 bpf 5/7] veth: update mem type in xdp_buff Slawomir Stepien
2026-11-24 10:40 ` [PATCH v8 bpf 6/7] selftests/bpf: Shrink test_run frags after generic XDP ran on lo Slawomir Stepien
2026-11-24 10:40 ` [PATCH v8 bpf 7/7] selftests/bpf: Grow test_run and generic XDP frags after a test run Slawomir Stepien
2026-11-24 21:04 ` [PATCH v8 bpf 0/7] xdp: fix page_pool leaks Alexei Starovoitov
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=20261124104016.532341-3-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=ilias.apalodimas@linaro.org \
--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=magnus.karlsson@intel.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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=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