Netdev List
 help / color / mirror / Atom feed
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 2/6] bpf: test_run: Set frag_size on a copy of the rxq info
Date: Fri, 27 Nov 2026 11:01:28 +0100	[thread overview]
Message-ID: <20261127100132.1977890-3-sst@poczta.fm> (raw)
In-Reply-To: <20261127100132.1977890-1-sst@poczta.fm>

bpf_prog_test_run_xdp() runs the program with the rxq info of lo's
queue 0 and stores frag_size = PAGE_SIZE into it, because the frags it
allocates are full pages. That rxq info is shared with generic XDP on
lo, whose frags come from skb_pp_cow_data() and can be a part of a
page_pool page. After a test run, a generic XDP program on lo can grow
such a frag with bpf_xdp_adjust_tail() up to the end of the page, over
the data of the next frag in that page.

The store also comes too early when the test run picks the rxq info of
another device with ingress_ifindex: xdp_convert_md_to_buff() replaces
xdp->rxq after it, the frag_size of that rxq info is 0, and growing a
frag of the test run fails with -EOPNOTSUPP.

Keep lo's rxq info as it is. Once xdp_convert_md_to_buff() has chosen
the rxq info, run the program with a copy of it on the stack that has
frag_size = PAGE_SIZE.

Fixes: 1c1949982524 ("bpf: introduce frags support to bpf_prog_test_run_xdp()")
Suggested-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/all/sashiko-outbox-223211@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>
---
 net/bpf/test_run.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index d6c9dc62182e..1d89b6f71a48 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -1349,6 +1349,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
 	struct netdev_rx_queue *rxqueue;
 	struct skb_shared_info *sinfo;
 	struct xdp_buff xdp = {};
+	struct xdp_rxq_info rxq;
 	int i, ret = -EINVAL;
 	struct xdp_md *ctx;
 	void *data;
@@ -1417,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);
 
@@ -1426,6 +1426,11 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
 	if (ret)
 		goto free_data;
 
+	/* generic XDP uses the same rxq and its frags can be smaller */
+	rxq = *xdp.rxq;
+	rxq.frag_size = PAGE_SIZE;
+	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


  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 ` Slawomir Stepien [this message]
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 ` [PATCH net v9 4/6] veth: use the page_pool mem type when running XDP on an skb Slawomir Stepien
2026-11-28 10:03   ` 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-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=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