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 3/6] veth: use the frame mem type when running XDP on an xdp_frame
Date: Fri, 27 Nov 2026 11:01:29 +0100	[thread overview]
Message-ID: <20261127100132.1977890-4-sst@poczta.fm> (raw)
In-Reply-To: <20261127100132.1977890-1-sst@poczta.fm>

veth_xdp_rcv_one() runs the program on an xdp_frame with rq->xdp_rxq,
whose mem type is MEM_TYPE_PAGE_SHARED, and copies the frame's mem type
into it only for XDP_TX and XDP_REDIRECT, after the program ran. That is
too late: the program itself can free frags, and bpf_xdp_shrink_data()
frees them according to xdp->rxq->mem.type. When the program shrinks a
frag of a page_pool frame away, bpf_xdp_shrink_data() frees the
page_pool page with page_frag_free(). The mem type stored for XDP_TX and
XDP_REDIRECT also stays in rq->xdp_rxq, so later packets on the queue,
skbs and frames, run with the mem type of that frame.

Do not store into rq->xdp_rxq. Run the program with an rxq info on the
stack of veth_xdp_rcv(), and set its mem type to the frame's one before
the program runs. The queue index is the one veth_enable_xdp_range()
registers rq->xdp_rxq with.

Fixes: 718a18a0c8a6 ("veth: Rework veth_xdp_rcv_skb in order to accept non-linear skb")
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 | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index faa837acea7b..cce253b58c2b 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -642,6 +642,7 @@ static int veth_xdp_tx(struct veth_rq *rq, struct xdp_buff *xdp,
 }
 
 static struct xdp_frame *veth_xdp_rcv_one(struct veth_rq *rq,
+					  struct xdp_rxq_info *rxq,
 					  struct xdp_frame *frame,
 					  struct veth_xdp_tx_bq *bq,
 					  struct veth_stats *stats)
@@ -657,7 +658,8 @@ static struct xdp_frame *veth_xdp_rcv_one(struct veth_rq *rq,
 		u32 act;
 
 		xdp_convert_frame_to_buff(frame, xdp);
-		xdp->rxq = &rq->xdp_rxq;
+		rxq->mem.type = frame->mem_type;
+		xdp->rxq = rxq;
 		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++;
@@ -914,6 +914,11 @@ static int veth_xdp_rcv(struct veth_rq *rq, int budget,
 			struct veth_xdp_tx_bq *bq,
 			struct veth_stats *stats)
 {
+	struct veth_priv *priv = netdev_priv(rq->dev);
+	struct xdp_rxq_info rxq = {
+		.dev = rq->dev,
+		.queue_index = rq - priv->rq,
+	};
 	int i, done = 0, n_xdpf = 0;
 	void *xdpf[VETH_XDP_BATCH];
 
@@ -928,7 +933,7 @@ static int veth_xdp_rcv(struct veth_rq *rq, int budget,
 			struct xdp_frame *frame = veth_ptr_to_xdp(ptr);
 
 			stats->xdp_bytes += xdp_get_frame_len(frame);
-			frame = veth_xdp_rcv_one(rq, frame, bq, stats);
+			frame = veth_xdp_rcv_one(rq, &rxq, frame, bq, stats);
 			if (frame) {
 				/* XDP_PASS */
 				xdpf[n_xdpf++] = frame;
-- 
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 ` [PATCH net v9 2/6] bpf: test_run: Set frag_size on " Slawomir Stepien
2026-11-27 10:01 ` Slawomir Stepien [this message]
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-4-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