BPF List
 help / color / mirror / Atom feed
* [PATCH net 0/3] xsk: Keep the shared info of zero-copy buffers in kernel memory
@ 2026-11-27 14:21 Björn Töpel
  2026-11-27 14:21 ` [PATCH net 1/3] libeth: xsk: Count each XDP_TX buffer on its own Björn Töpel
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Björn Töpel @ 2026-11-27 14:21 UTC (permalink / raw)
  To: Magnus Karlsson, Maciej Fijalkowski, Alexander Lobakin,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Willem de Bruijn, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, Shuah Khan, netdev, bpf
  Cc: Björn Töpel, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	Larysa Zaremba, Tushar Vyavahare, Jason Xing, Bastien Curutchet,
	Colin Ian King, intel-wired-lan, linux-kselftest

A packet that AF_XDP receives in zero-copy mode over several buffers
keeps its shared info, the fragment list and its count, in the UMEM,
which userspace can write while the kernel uses it. A rewritten list
or count makes the kernel read and write out of bounds.

Patch 2 moves the shared info into the buffer pool and lets the device
write up to the end of each chunk. Patch 1 makes libeth count XSk
XDP_TX buffers one by one, as it read the shared info at a later bulk
flush. Patch 3 updates the xsk selftests.

Sashiko found this in its review of the AF_XDP device buffer layout
series [1].

I tested this on mlx5 hardware, and on igb and veth in QEMU. None of
them receives multi-buffer packets in zero copy, so i40e, ice and
idpf, which do, are only build-tested. Intel folks, could you run your
multi-buffer zero-copy tests on them?

Also for Intel, found while auditing the drivers and not touched here:
ice no longer sizes its zero-copy RX buffers from the XSK pool. Commit
3a4f419f7509 ("ice: drop page splitting and recycling") programmed a
fixed 3072 bytes, and 93f53db9f9dc ("ice: switch to Page Pool")
changed ice_setup_rx_ctx() to use ring->rx_buf_len, which only the
page pool path sets. An XSK ring gets the length of its last page pool
setup, 3456 bytes on 4K pages, or 0 if it never had one. With 2K
chunks the device can write past the chunk into the next one. I found
this by reading the code and did not test it.

[1] https://lore.kernel.org/netdev/179561567996.3135.9952128421877275714@kernel.org/

Björn Töpel (3):
  libeth: xsk: Count each XDP_TX buffer on its own
  xsk: Keep the shared info of zero-copy buffers in kernel memory
  selftests/bpf: Drop the zero-copy tailroom from the xsk tests

 include/net/libeth/tx.h                       |  3 +-
 include/net/libeth/xdp.h                      |  9 +++++-
 include/net/libeth/xsk.h                      |  6 ++--
 include/net/xdp.h                             | 32 +++++++++++++++----
 include/net/xdp_sock_drv.h                    | 29 ++++++-----------
 include/net/xsk_buff_pool.h                   |  2 ++
 net/xdp/xdp_umem.c                            |  3 +-
 net/xdp/xsk_buff_pool.c                       | 17 +++++-----
 .../selftests/bpf/prog_tests/test_xsk.c       | 10 +++---
 .../selftests/bpf/prog_tests/test_xsk.h       |  2 --
 tools/testing/selftests/bpf/prog_tests/xsk.c  | 13 +-------
 tools/testing/selftests/bpf/xskxceiver.c      | 15 +--------
 12 files changed, 67 insertions(+), 74 deletions(-)


base-commit: 28a371228d4eb4857cc31eeb1a0d7d01e9c3ea2f
-- 
2.56.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH net 1/3] libeth: xsk: Count each XDP_TX buffer on its own
  2026-11-27 14:21 [PATCH net 0/3] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
@ 2026-11-27 14:21 ` Björn Töpel
  2026-11-28 15:14   ` netdev-bot+sashiko
  2026-11-27 14:21 ` [PATCH net 2/3] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Björn Töpel @ 2026-11-27 14:21 UTC (permalink / raw)
  To: Magnus Karlsson, Maciej Fijalkowski, Alexander Lobakin,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Willem de Bruijn, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, Shuah Khan, netdev, bpf
  Cc: Björn Töpel, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	Larysa Zaremba, Tushar Vyavahare, Jason Xing, Bastien Curutchet,
	Colin Ian King, intel-wired-lan, linux-kselftest

libeth reads the shared info of an XSk XDP_TX frame when it flushes
the bulk, not when it queues the frame. The fragment count it finds
there decides how many completions idpf reports to the XSk pool.

The shared info of a zero-copy buffer lives in the UMEM, which
userspace may write at any time, so a rewritten count makes idpf
report the wrong number of completions. Once the next patch moves the
shared info into the buffer pool, the next multi-buffer frame of the
same poll can overwrite it before the flush.

Count each buffer on its own SQE. Head and fragments each take one off
the in-flight count, and the head counts the packet. Stats do not
change.

Found by code inspection.

Fixes: b3ad8450b4dc ("libeth: xsk: add XSk XDP_TX sending helpers")
Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 include/net/libeth/tx.h  | 3 ++-
 include/net/libeth/xdp.h | 9 ++++++++-
 include/net/libeth/xsk.h | 6 ++++--
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/include/net/libeth/tx.h b/include/net/libeth/tx.h
index c3db5c6f1641..25cad5566436 100644
--- a/include/net/libeth/tx.h
+++ b/include/net/libeth/tx.h
@@ -22,7 +22,8 @@
  * @LIBETH_SQE_XDP_XMIT: &xdp_frame, unmap and xdp_return_frame_bulk(), stats
  * @LIBETH_SQE_XDP_XMIT_FRAG: &xdp_frame frag, only unmap DMA
  * @LIBETH_SQE_XSK_TX: &libeth_xdp_buff on XSk queue, xsk_buff_free(), stats
- * @LIBETH_SQE_XSK_TX_FRAG: &libeth_xdp_buff frag on XSk queue, xsk_buff_free()
+ * @LIBETH_SQE_XSK_TX_FRAG: &libeth_xdp_buff frag on XSk queue, xsk_buff_free(),
+ *			    stats
  */
 enum libeth_sqe_type {
 	LIBETH_SQE_EMPTY		= 0U,
diff --git a/include/net/libeth/xdp.h b/include/net/libeth/xdp.h
index 898723ab62e8..66a3c4ec9967 100644
--- a/include/net/libeth/xdp.h
+++ b/include/net/libeth/xdp.h
@@ -1794,12 +1794,19 @@ __libeth_xdp_complete_tx(struct libeth_sqe *sqe, struct libeth_cq_pp *cp,
 	switch (type) {
 	case LIBETH_SQE_XDP_TX:
 	case LIBETH_SQE_XDP_XMIT:
-	case LIBETH_SQE_XSK_TX:
 		cp->xdp_tx -= sqe->nr_frags;
 
 		cp->xss->packets++;
 		cp->xss->bytes += sqe->bytes;
 		break;
+	case LIBETH_SQE_XSK_TX:
+		cp->xss->packets++;
+		fallthrough;
+	case LIBETH_SQE_XSK_TX_FRAG:
+		/* One buffer per SQE, see libeth_xsk_tx_fill_buf() */
+		cp->xdp_tx--;
+		cp->xss->bytes += sqe->bytes;
+		break;
 	default:
 		break;
 	}
diff --git a/include/net/libeth/xsk.h b/include/net/libeth/xsk.h
index 249b1c740788..2cd4252a3445 100644
--- a/include/net/libeth/xsk.h
+++ b/include/net/libeth/xsk.h
@@ -129,6 +129,10 @@ libeth_xsk_tx_fill_buf(struct libeth_xdp_tx_frame frm, u32 i,
 
 	sqe = &sq->sqes[i];
 	sqe->xsk = xdp;
+	/* Count each buffer on its own SQE. The shared info of the frame
+	 * may change before the bulk is flushed.
+	 */
+	sqe->bytes = desc.len;
 
 	if (!(desc.flags & LIBETH_XDP_TX_FIRST)) {
 		sqe->type = LIBETH_SQE_XSK_TX_FRAG;
@@ -136,8 +140,6 @@ libeth_xsk_tx_fill_buf(struct libeth_xdp_tx_frame frm, u32 i,
 	}
 
 	sqe->type = LIBETH_SQE_XSK_TX;
-	libeth_xdp_tx_fill_stats(sqe, &desc,
-				 xdp_get_shared_info_from_buff(&xdp->base));
 
 	return desc;
 }

base-commit: 28a371228d4eb4857cc31eeb1a0d7d01e9c3ea2f
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net 2/3] xsk: Keep the shared info of zero-copy buffers in kernel memory
  2026-11-27 14:21 [PATCH net 0/3] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
  2026-11-27 14:21 ` [PATCH net 1/3] libeth: xsk: Count each XDP_TX buffer on its own Björn Töpel
@ 2026-11-27 14:21 ` Björn Töpel
  2026-11-27 19:26   ` Maciej Fijalkowski
                     ` (2 more replies)
  2026-11-27 14:21 ` [PATCH net 3/3] selftests/bpf: Drop the zero-copy tailroom from the xsk tests Björn Töpel
  2026-11-27 14:24 ` [PATCH net 0/3] xsk: Keep the shared info of zero-copy buffers in kernel memory netdev-bot+sinfo
  3 siblings, 3 replies; 11+ messages in thread
From: Björn Töpel @ 2026-11-27 14:21 UTC (permalink / raw)
  To: Magnus Karlsson, Maciej Fijalkowski, Alexander Lobakin,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Willem de Bruijn, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, Shuah Khan, netdev, bpf
  Cc: Björn Töpel, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	Larysa Zaremba, Tushar Vyavahare, Jason Xing, Bastien Curutchet,
	Colin Ian King, intel-wired-lan, linux-kselftest

A packet that a driver receives in zero-copy mode over several buffers
keeps its shared info, the fragment list and its count, in the
tailroom of the UMEM chunk of its head. Userspace may write the UMEM
at any time, also while the kernel walks the fragments, and a
rewritten list or count makes the kernel read and write out of bounds.

Keep the shared info in the buffer pool, which outlives its buffers
and the queues that point to it, and let the device write up to the
end of the chunk. One shared info per pool is enough, as a pool builds
one multi-buffer packet at a time. libeth read it later, at an XDP_TX
bulk flush, which the previous patch fixes.

Multi-buffer pools now give the device the whole chunk, as
single-buffer pools already do, and allow a larger UMEM headroom.
bpf_xdp_adjust_tail() can grow a packet up to the end of its chunk.
Copy mode does not change.

Found by an AI code review agent, in its review of another series.

Suggested-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Fixes: 24ea50127ecf ("xsk: support mbuf on ZC RX")
Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 include/net/xdp.h           | 32 ++++++++++++++++++++++++++------
 include/net/xdp_sock_drv.h  | 29 +++++++++--------------------
 include/net/xsk_buff_pool.h |  2 ++
 net/xdp/xdp_umem.c          |  3 +--
 net/xdp/xsk_buff_pool.c     | 17 +++++++++--------
 5 files changed, 47 insertions(+), 36 deletions(-)

diff --git a/include/net/xdp.h b/include/net/xdp.h
index 07231adfb5f8..68dc9caacfa9 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -65,6 +65,10 @@ struct xdp_rxq_info {
 	u32 reg_state;
 	struct xdp_mem_info mem;
 	u32 frag_size;
+	/* Shared info of buffers with %XDP_FLAGS_SINFO_EXT, in the XSk buffer
+	 * pool, set by xsk_pool_set_rxq_info().
+	 */
+	struct skb_shared_info *ext_sinfo;
 } ____cacheline_aligned; /* perf critical, avoid false-sharing */
 
 struct xdp_txq_info {
@@ -81,6 +85,13 @@ enum xdp_buff_flags {
 	 * XDP program is not attached.
 	 */
 	XDP_FLAGS_FRAGS_UNREADABLE	= BIT(2),
+	/* The shared info lives in &xdp_rxq_info.ext_sinfo, not at the end of
+	 * the frame, as userspace may write the frame. The frame reserves no
+	 * tailroom, so the data may reach its end. The pool builds one such
+	 * buffer at a time, so a consumer that uses the shared info later
+	 * must copy what it needs.
+	 */
+	XDP_FLAGS_SINFO_EXT		= BIT(3),
 };
 
 struct xdp_buff {
@@ -178,17 +189,26 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
 
 /* Reserve memory area at end-of data area.
  *
- * This macro reserves tailroom in the XDP buffer by limiting the
- * XDP/BPF data access to data_hard_end.  Notice same area (and size)
- * is used for XDP_PASS, when constructing the SKB via build_skb().
+ * This reserves tailroom in the XDP buffer by limiting the XDP/BPF data
+ * access to data_hard_end.  Notice same area (and size) is used for
+ * XDP_PASS, when constructing the SKB via build_skb(). Buffers with
+ * %XDP_FLAGS_SINFO_EXT keep the shared info elsewhere and reserve none.
  */
-#define xdp_data_hard_end(xdp)				\
-	((xdp)->data_hard_start + (xdp)->frame_sz -	\
-	 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
+static __always_inline void *xdp_data_hard_end(const struct xdp_buff *xdp)
+{
+	u32 tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+
+	if (xdp->flags & XDP_FLAGS_SINFO_EXT)
+		tailroom = 0;
+	return xdp->data_hard_start + xdp->frame_sz - tailroom;
+}
 
 static inline struct skb_shared_info *
 xdp_get_shared_info_from_buff(const struct xdp_buff *xdp)
 {
+	if (xdp->flags & XDP_FLAGS_SINFO_EXT)
+		return xdp->rxq->ext_sinfo;
+
 	return (struct skb_shared_info *)xdp_data_hard_end(xdp);
 }
 
diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h
index a40ad3f90f13..fc22314e72c4 100644
--- a/include/net/xdp_sock_drv.h
+++ b/include/net/xdp_sock_drv.h
@@ -41,11 +41,6 @@ static inline u32 xsk_pool_get_headroom(struct xsk_buff_pool *pool)
 	return XDP_PACKET_HEADROOM + pool->headroom;
 }
 
-static inline u32 xsk_pool_get_tailroom(bool mbuf)
-{
-	return mbuf ? SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) : 0;
-}
-
 static inline u32 xsk_pool_get_chunk_size(struct xsk_buff_pool *pool)
 {
 	return pool->chunk_size;
@@ -56,20 +51,13 @@ static inline u32 __xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool)
 	return xsk_pool_get_chunk_size(pool) - xsk_pool_get_headroom(pool);
 }
 
+/* Device RX buffers typically come in 128-byte units. The shared info
+ * of zero-copy buffers lives in the pool, see xp_set_rxq_info(), so the
+ * device may write up to the end of the chunk.
+ */
 static inline u32 xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool)
 {
-	u32 frame_size =  __xsk_pool_get_rx_frame_size(pool);
-	struct xdp_umem *umem = pool->umem;
-	bool mbuf;
-
-	/* Reserve tailroom only for zero-copy pools that opted into
-	 * multi-buffer. The reserved area is used for skb_shared_info,
-	 * matching the XDP core's xdp_data_hard_end() layout.
-	 */
-	mbuf = pool->dev && (umem->flags & XDP_UMEM_SG_FLAG);
-	frame_size -= xsk_pool_get_tailroom(mbuf);
-
-	return ALIGN_DOWN(frame_size, 128);
+	return ALIGN_DOWN(__xsk_pool_get_rx_frame_size(pool), 128);
 }
 
 static inline u32 xsk_pool_get_rx_frag_step(struct xsk_buff_pool *pool)
@@ -152,7 +140,6 @@ static inline void xsk_buff_free(struct xdp_buff *xdp)
 		xp_free(pos);
 	}
 
-	xdp_get_shared_info_from_buff(xdp)->nr_frags = 0;
 	xdp_buff_clear_frags_flag(xdp);
 out:
 	xp_free(xskb);
@@ -226,8 +213,10 @@ static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size)
 	xdp->data = xdp->data_hard_start + XDP_PACKET_HEADROOM;
 	xdp->data_meta = xdp->data;
 	xdp->data_end = xdp->data + size;
-	/* Frags flag is cleared when the frags of a head are released */
-	xdp->flags &= XDP_FLAGS_HAS_FRAGS;
+	/* Frags flag is cleared when the frags of a head are released. The
+	 * shared info flag stays, see xp_set_rxq_info().
+	 */
+	xdp->flags &= XDP_FLAGS_HAS_FRAGS | XDP_FLAGS_SINFO_EXT;
 }
 
 static inline dma_addr_t xsk_buff_raw_get_dma(struct xsk_buff_pool *pool,
diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h
index 02e89350faf9..f43e618ae707 100644
--- a/include/net/xsk_buff_pool.h
+++ b/include/net/xsk_buff_pool.h
@@ -59,6 +59,8 @@ struct xsk_buff_pool {
 	spinlock_t rx_lock;
 	struct list_head free_list;
 	struct list_head xskb_list;
+	/* Fragment list of the packet being built, out of userspace reach */
+	struct skb_shared_info sinfo;
 	u32 heads_cnt;
 	u16 queue_id;
 
diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
index cd8643360eb3..e78a43c3c3e9 100644
--- a/net/xdp/xdp_umem.c
+++ b/net/xdp/xdp_umem.c
@@ -203,8 +203,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
 	if (!unaligned_chunks && chunks_rem)
 		return -EINVAL;
 
-	if (headroom > chunk_size - XDP_PACKET_HEADROOM -
-		       SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) - 128)
+	if (headroom > chunk_size - XDP_PACKET_HEADROOM - 128)
 		return -EINVAL;
 
 	if (mr->flags & XDP_UMEM_TX_METADATA_LEN) {
diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
index 5ec092f7cb6f..553630170229 100644
--- a/net/xdp/xsk_buff_pool.c
+++ b/net/xdp/xsk_buff_pool.c
@@ -125,8 +125,14 @@ void xp_set_rxq_info(struct xsk_buff_pool *pool, struct xdp_rxq_info *rxq)
 {
 	u32 i;
 
-	for (i = 0; i < pool->heads_cnt; i++)
+	/* Userspace may write the UMEM. Keep the shared info in the pool,
+	 * and let the device write up to the end of each chunk.
+	 */
+	for (i = 0; i < pool->heads_cnt; i++) {
 		pool->heads[i].xdp.rxq = rxq;
+		pool->heads[i].xdp.flags |= XDP_FLAGS_SINFO_EXT;
+	}
+	rxq->ext_sinfo = &pool->sinfo;
 }
 EXPORT_SYMBOL(xp_set_rxq_info);
 
@@ -229,12 +235,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool,
 		segs = 1;
 	}
 
-	/* open-code xsk_pool_get_rx_frame_size() as pool->dev is not
-	 * set yet at this point; we are before getting down to driver
-	 */
-	frame_size = __xsk_pool_get_rx_frame_size(pool) -
-		     xsk_pool_get_tailroom(mbuf);
-	frame_size = ALIGN_DOWN(frame_size, 128);
+	frame_size = xsk_pool_get_rx_frame_size(pool);
 
 	if (needed > frame_size * segs) {
 		err = -EINVAL;
@@ -629,7 +630,7 @@ struct xdp_buff *xp_alloc(struct xsk_buff_pool *pool)
 
 	xskb->xdp.data = xskb->xdp.data_hard_start + XDP_PACKET_HEADROOM;
 	xskb->xdp.data_meta = xskb->xdp.data;
-	xskb->xdp.flags &= XDP_FLAGS_HAS_FRAGS;
+	xskb->xdp.flags &= XDP_FLAGS_HAS_FRAGS | XDP_FLAGS_SINFO_EXT;
 
 	if (pool->dev)
 		xp_dma_sync_for_device(pool, xskb->dma, pool->frame_len);
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net 3/3] selftests/bpf: Drop the zero-copy tailroom from the xsk tests
  2026-11-27 14:21 [PATCH net 0/3] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
  2026-11-27 14:21 ` [PATCH net 1/3] libeth: xsk: Count each XDP_TX buffer on its own Björn Töpel
  2026-11-27 14:21 ` [PATCH net 2/3] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
@ 2026-11-27 14:21 ` Björn Töpel
  2026-11-27 15:49   ` Maciej Fijalkowski
  2026-11-27 14:24 ` [PATCH net 0/3] xsk: Keep the shared info of zero-copy buffers in kernel memory netdev-bot+sinfo
  3 siblings, 1 reply; 11+ messages in thread
From: Björn Töpel @ 2026-11-27 14:21 UTC (permalink / raw)
  To: Magnus Karlsson, Maciej Fijalkowski, Alexander Lobakin,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Willem de Bruijn, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, Shuah Khan, netdev, bpf
  Cc: Björn Töpel, Simon Horman, Stanislav Fomichev,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Tony Nguyen, Przemek Kitszel,
	Larysa Zaremba, Tushar Vyavahare, Jason Xing, Bastien Curutchet,
	Colin Ian King, intel-wired-lan, linux-kselftest

The xsk tests take the size of the shared info off the UMEM headroom
of RX_DROPPED and off the growth of XDP_ADJUST_TAIL_GROW_MULTI_BUFF,
as zero-copy multi-buffer pools kept it at the end of each chunk.

The previous patch moves the shared info into the buffer pool, so the
UMEM headroom limit and the frame size no longer leave room for it.
Drop it from both tests.

Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 tools/testing/selftests/bpf/prog_tests/test_xsk.c | 10 ++++------
 tools/testing/selftests/bpf/prog_tests/test_xsk.h |  2 --
 tools/testing/selftests/bpf/prog_tests/xsk.c      | 13 +------------
 tools/testing/selftests/bpf/xskxceiver.c          | 15 +--------------
 4 files changed, 6 insertions(+), 34 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.c b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
index 4549358cc8c2..7145a36e6ea2 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_xsk.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
@@ -1984,17 +1984,16 @@ int testapp_headroom(struct test_spec *test)
 int testapp_stats_rx_dropped(struct test_spec *test)
 {
 	struct xsk_umem_info *umem = test->ifobj_rx->xsk->umem;
-	u32 umem_tr = test->ifobj_tx->umem_tailroom;
 
 	if (test->mode == TEST_MODE_ZC) {
 		ksft_print_msg("Can not run RX_DROPPED test for ZC mode\n");
 		return TEST_SKIP;
 	}
 
-	if (pkt_stream_replace_half(test, (MIN_PKT_SIZE * 3) + umem_tr, 0))
+	if (pkt_stream_replace_half(test, MIN_PKT_SIZE * 4, 0))
 		return TEST_FAILURE;
 	umem->frame_headroom = umem->frame_size -
-		XDP_PACKET_HEADROOM - (MIN_PKT_SIZE * 2) - umem_tr;
+		XDP_PACKET_HEADROOM - MIN_PKT_SIZE * 3;
 	if (pkt_stream_receive_half(test))
 		return TEST_FAILURE;
 	test->ifobj_rx->validation_func = validate_rx_dropped;
@@ -2592,12 +2591,11 @@ int testapp_adjust_tail_grow_mb(struct test_spec *test)
 	 * pkt_len, expect that it will be broken down to 2 descs each
 	 * with 3k payload;
 	 *
-	 * 4k is truesize, 3k payload, 256 HR, 320 TR;
+	 * 4k is truesize, 3k payload, 256 HR;
 	 */
 	grow_size = XSK_UMEM__MAX_FRAME_SIZE -
 		    XSK_UMEM__LARGE_FRAME_SIZE -
-		    XDP_PACKET_HEADROOM -
-		    test->ifobj_tx->umem_tailroom;
+		    XDP_PACKET_HEADROOM;
 	test->mtu = MAX_ETH_JUMBO_SIZE;
 
 	return testapp_adjust_tail(test, grow_size, XSK_UMEM__LARGE_FRAME_SIZE * 2);
diff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.h b/tools/testing/selftests/bpf/prog_tests/test_xsk.h
index 03753ddc5dcd..1b816226597b 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_xsk.h
+++ b/tools/testing/selftests/bpf/prog_tests/test_xsk.h
@@ -32,7 +32,6 @@
 #define USLEEP_MAX			10000
 
 #define MAX_SKB_FRAGS_PATH "/proc/sys/net/core/max_skb_frags"
-#define SMP_CACHE_BYTES_PATH "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
 
 extern bool opt_verbose;
 #define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0)
@@ -137,7 +136,6 @@ struct ifobject {
 	int mtu;
 	u32 bind_flags;
 	u32 xdp_zc_max_segs;
-	u32 umem_tailroom;
 	u32 max_skb_frags;
 	bool tx_on;
 	bool rx_on;
diff --git a/tools/testing/selftests/bpf/prog_tests/xsk.c b/tools/testing/selftests/bpf/prog_tests/xsk.c
index 772f3dd7ce64..b3758b9bf2ec 100644
--- a/tools/testing/selftests/bpf/prog_tests/xsk.c
+++ b/tools/testing/selftests/bpf/prog_tests/xsk.c
@@ -62,7 +62,7 @@ int configure_ifobj(struct ifobject *tx, struct ifobject *rx)
 
 static void test_xsk(const struct test_spec *test_to_run, enum test_mode mode)
 {
-	u32 max_frags, umem_tailroom, cache_line_size;
+	u32 max_frags;
 	struct ifobject *ifobj_tx, *ifobj_rx;
 	struct test_spec test;
 	int ret;
@@ -85,10 +85,6 @@ static void test_xsk(const struct test_spec *test_to_run, enum test_mode mode)
 		ifobj_tx->set_ring.default_rx = ifobj_tx->ring.rx_pending;
 	}
 
-	cache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);
-	if (!cache_line_size)
-		cache_line_size = 64;
-
 	max_frags = read_procfs_val(MAX_SKB_FRAGS_PATH);
 	if (!max_frags)
 		max_frags = 17;
@@ -96,13 +92,6 @@ static void test_xsk(const struct test_spec *test_to_run, enum test_mode mode)
 	ifobj_tx->max_skb_frags = max_frags;
 	ifobj_rx->max_skb_frags = max_frags;
 
-	/* 48 bytes is a part of skb_shared_info w/o frags array;
-	 * 16 bytes is sizeof(skb_frag_t)
-	 */
-	umem_tailroom = ALIGN(48 + (max_frags * 16), cache_line_size);
-	ifobj_tx->umem_tailroom = umem_tailroom;
-	ifobj_rx->umem_tailroom = umem_tailroom;
-
 	if (!ASSERT_OK(init_iface(ifobj_rx, worker_testapp_validate_rx), "init RX"))
 		goto delete_rx;
 	if (!ASSERT_OK(init_iface(ifobj_tx, worker_testapp_validate_tx), "init TX"))
diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
index 7dad8556a722..a385464cfaf8 100644
--- a/tools/testing/selftests/bpf/xskxceiver.c
+++ b/tools/testing/selftests/bpf/xskxceiver.c
@@ -334,7 +334,7 @@ static void print_tests(void)
 int main(int argc, char **argv)
 {
 	const size_t total_tests = ARRAY_SIZE(tests) + ARRAY_SIZE(ci_skip_tests);
-	u32 cache_line_size, max_frags, umem_tailroom;
+	u32 max_frags;
 	struct pkt_stream *rx_pkt_stream_default;
 	struct pkt_stream *tx_pkt_stream_default;
 	struct ifobject *ifobj_tx, *ifobj_rx;
@@ -356,12 +356,6 @@ int main(int argc, char **argv)
 
 	setlocale(LC_ALL, "");
 
-	cache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);
-	if (!cache_line_size) {
-		ksft_print_msg("Can't get SMP_CACHE_BYTES from system, using default (64)\n");
-		cache_line_size = 64;
-	}
-
 	max_frags = read_procfs_val(MAX_SKB_FRAGS_PATH);
 	if (!max_frags) {
 		ksft_print_msg("Can't get MAX_SKB_FRAGS from system, using default (17)\n");
@@ -370,13 +364,6 @@ int main(int argc, char **argv)
 	ifobj_tx->max_skb_frags = max_frags;
 	ifobj_rx->max_skb_frags = max_frags;
 
-	/* 48 bytes is a part of skb_shared_info w/o frags array;
-	 * 16 bytes is sizeof(skb_frag_t)
-	 */
-	umem_tailroom = ALIGN(48 + (max_frags * 16), cache_line_size);
-	ifobj_tx->umem_tailroom = umem_tailroom;
-	ifobj_rx->umem_tailroom = umem_tailroom;
-
 	parse_command_line(ifobj_tx, ifobj_rx, argc, argv);
 
 	if (opt_print_tests) {
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH net 0/3] xsk: Keep the shared info of zero-copy buffers in kernel memory
  2026-11-27 14:21 [PATCH net 0/3] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
                   ` (2 preceding siblings ...)
  2026-11-27 14:21 ` [PATCH net 3/3] selftests/bpf: Drop the zero-copy tailroom from the xsk tests Björn Töpel
@ 2026-11-27 14:24 ` netdev-bot+sinfo
  3 siblings, 0 replies; 11+ messages in thread
From: netdev-bot+sinfo @ 2026-11-27 14:24 UTC (permalink / raw)
  To: Björn Töpel
  Cc: Magnus Karlsson, Maciej Fijalkowski, Alexander Lobakin,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Willem de Bruijn, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, Shuah Khan, netdev, bpf, Simon Horman,
	Stanislav Fomichev, Martin KaFai Lau, Song Liu, Yonghong Song,
	Jiri Olsa, Emil Tsalapatis, Ihor Solodrai, Tony Nguyen,
	Przemek Kitszel, Larysa Zaremba, Tushar Vyavahare, Jason Xing,
	Bastien Curutchet, Colin Ian King, intel-wired-lan,
	linux-kselftest

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net 3/3] selftests/bpf: Drop the zero-copy tailroom from the xsk tests
  2026-11-27 14:21 ` [PATCH net 3/3] selftests/bpf: Drop the zero-copy tailroom from the xsk tests Björn Töpel
@ 2026-11-27 15:49   ` Maciej Fijalkowski
  2026-11-27 16:56     ` Björn Töpel
  0 siblings, 1 reply; 11+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:49 UTC (permalink / raw)
  To: Björn Töpel
  Cc: Magnus Karlsson, Alexander Lobakin, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, Shuah Khan, netdev, bpf, Simon Horman,
	Stanislav Fomichev, Martin KaFai Lau, Song Liu, Yonghong Song,
	Jiri Olsa, Emil Tsalapatis, Ihor Solodrai, Tony Nguyen,
	Przemek Kitszel, Larysa Zaremba, Tushar Vyavahare, Jason Xing,
	Bastien Curutchet, Colin Ian King, intel-wired-lan,
	linux-kselftest

On Fri, Nov 27, 2026 at 03:21:29PM +0100, Björn Töpel wrote:
> The xsk tests take the size of the shared info off the UMEM headroom
> of RX_DROPPED and off the growth of XDP_ADJUST_TAIL_GROW_MULTI_BUFF,
> as zero-copy multi-buffer pools kept it at the end of each chunk.
> 
> The previous patch moves the shared info into the buffer pool, so the
> UMEM headroom limit and the frame size no longer leave room for it.
> Drop it from both tests.
> 
> Signed-off-by: Björn Töpel <bjorn@kernel.org>
> ---
>  tools/testing/selftests/bpf/prog_tests/test_xsk.c | 10 ++++------
>  tools/testing/selftests/bpf/prog_tests/test_xsk.h |  2 --
>  tools/testing/selftests/bpf/prog_tests/xsk.c      | 13 +------------
>  tools/testing/selftests/bpf/xskxceiver.c          | 15 +--------------

This is based on old xskxceiver location, would it be better to have this
one send to -next out of this set? I assume the move might not have been
back-propagated yet...so seems we would have to double the effort?

>  4 files changed, 6 insertions(+), 34 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.c b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
> index 4549358cc8c2..7145a36e6ea2 100644
> --- a/tools/testing/selftests/bpf/prog_tests/test_xsk.c
> +++ b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
> @@ -1984,17 +1984,16 @@ int testapp_headroom(struct test_spec *test)
>  int testapp_stats_rx_dropped(struct test_spec *test)
>  {
>  	struct xsk_umem_info *umem = test->ifobj_rx->xsk->umem;
> -	u32 umem_tr = test->ifobj_tx->umem_tailroom;
>  
>  	if (test->mode == TEST_MODE_ZC) {
>  		ksft_print_msg("Can not run RX_DROPPED test for ZC mode\n");
>  		return TEST_SKIP;
>  	}
>  
> -	if (pkt_stream_replace_half(test, (MIN_PKT_SIZE * 3) + umem_tr, 0))
> +	if (pkt_stream_replace_half(test, MIN_PKT_SIZE * 4, 0))
>  		return TEST_FAILURE;
>  	umem->frame_headroom = umem->frame_size -
> -		XDP_PACKET_HEADROOM - (MIN_PKT_SIZE * 2) - umem_tr;
> +		XDP_PACKET_HEADROOM - MIN_PKT_SIZE * 3;
>  	if (pkt_stream_receive_half(test))
>  		return TEST_FAILURE;
>  	test->ifobj_rx->validation_func = validate_rx_dropped;
> @@ -2592,12 +2591,11 @@ int testapp_adjust_tail_grow_mb(struct test_spec *test)
>  	 * pkt_len, expect that it will be broken down to 2 descs each
>  	 * with 3k payload;
>  	 *
> -	 * 4k is truesize, 3k payload, 256 HR, 320 TR;
> +	 * 4k is truesize, 3k payload, 256 HR;
>  	 */
>  	grow_size = XSK_UMEM__MAX_FRAME_SIZE -
>  		    XSK_UMEM__LARGE_FRAME_SIZE -
> -		    XDP_PACKET_HEADROOM -
> -		    test->ifobj_tx->umem_tailroom;
> +		    XDP_PACKET_HEADROOM;
>  	test->mtu = MAX_ETH_JUMBO_SIZE;
>  
>  	return testapp_adjust_tail(test, grow_size, XSK_UMEM__LARGE_FRAME_SIZE * 2);
> diff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.h b/tools/testing/selftests/bpf/prog_tests/test_xsk.h
> index 03753ddc5dcd..1b816226597b 100644
> --- a/tools/testing/selftests/bpf/prog_tests/test_xsk.h
> +++ b/tools/testing/selftests/bpf/prog_tests/test_xsk.h
> @@ -32,7 +32,6 @@
>  #define USLEEP_MAX			10000
>  
>  #define MAX_SKB_FRAGS_PATH "/proc/sys/net/core/max_skb_frags"
> -#define SMP_CACHE_BYTES_PATH "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
>  
>  extern bool opt_verbose;
>  #define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0)
> @@ -137,7 +136,6 @@ struct ifobject {
>  	int mtu;
>  	u32 bind_flags;
>  	u32 xdp_zc_max_segs;
> -	u32 umem_tailroom;
>  	u32 max_skb_frags;
>  	bool tx_on;
>  	bool rx_on;
> diff --git a/tools/testing/selftests/bpf/prog_tests/xsk.c b/tools/testing/selftests/bpf/prog_tests/xsk.c
> index 772f3dd7ce64..b3758b9bf2ec 100644
> --- a/tools/testing/selftests/bpf/prog_tests/xsk.c
> +++ b/tools/testing/selftests/bpf/prog_tests/xsk.c
> @@ -62,7 +62,7 @@ int configure_ifobj(struct ifobject *tx, struct ifobject *rx)
>  
>  static void test_xsk(const struct test_spec *test_to_run, enum test_mode mode)
>  {
> -	u32 max_frags, umem_tailroom, cache_line_size;
> +	u32 max_frags;
>  	struct ifobject *ifobj_tx, *ifobj_rx;
>  	struct test_spec test;
>  	int ret;
> @@ -85,10 +85,6 @@ static void test_xsk(const struct test_spec *test_to_run, enum test_mode mode)
>  		ifobj_tx->set_ring.default_rx = ifobj_tx->ring.rx_pending;
>  	}
>  
> -	cache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);
> -	if (!cache_line_size)
> -		cache_line_size = 64;
> -
>  	max_frags = read_procfs_val(MAX_SKB_FRAGS_PATH);
>  	if (!max_frags)
>  		max_frags = 17;
> @@ -96,13 +92,6 @@ static void test_xsk(const struct test_spec *test_to_run, enum test_mode mode)
>  	ifobj_tx->max_skb_frags = max_frags;
>  	ifobj_rx->max_skb_frags = max_frags;
>  
> -	/* 48 bytes is a part of skb_shared_info w/o frags array;
> -	 * 16 bytes is sizeof(skb_frag_t)
> -	 */
> -	umem_tailroom = ALIGN(48 + (max_frags * 16), cache_line_size);
> -	ifobj_tx->umem_tailroom = umem_tailroom;
> -	ifobj_rx->umem_tailroom = umem_tailroom;
> -
>  	if (!ASSERT_OK(init_iface(ifobj_rx, worker_testapp_validate_rx), "init RX"))
>  		goto delete_rx;
>  	if (!ASSERT_OK(init_iface(ifobj_tx, worker_testapp_validate_tx), "init TX"))
> diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
> index 7dad8556a722..a385464cfaf8 100644
> --- a/tools/testing/selftests/bpf/xskxceiver.c
> +++ b/tools/testing/selftests/bpf/xskxceiver.c
> @@ -334,7 +334,7 @@ static void print_tests(void)
>  int main(int argc, char **argv)
>  {
>  	const size_t total_tests = ARRAY_SIZE(tests) + ARRAY_SIZE(ci_skip_tests);
> -	u32 cache_line_size, max_frags, umem_tailroom;
> +	u32 max_frags;
>  	struct pkt_stream *rx_pkt_stream_default;
>  	struct pkt_stream *tx_pkt_stream_default;
>  	struct ifobject *ifobj_tx, *ifobj_rx;
> @@ -356,12 +356,6 @@ int main(int argc, char **argv)
>  
>  	setlocale(LC_ALL, "");
>  
> -	cache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);
> -	if (!cache_line_size) {
> -		ksft_print_msg("Can't get SMP_CACHE_BYTES from system, using default (64)\n");
> -		cache_line_size = 64;
> -	}
> -
>  	max_frags = read_procfs_val(MAX_SKB_FRAGS_PATH);
>  	if (!max_frags) {
>  		ksft_print_msg("Can't get MAX_SKB_FRAGS from system, using default (17)\n");
> @@ -370,13 +364,6 @@ int main(int argc, char **argv)
>  	ifobj_tx->max_skb_frags = max_frags;
>  	ifobj_rx->max_skb_frags = max_frags;
>  
> -	/* 48 bytes is a part of skb_shared_info w/o frags array;
> -	 * 16 bytes is sizeof(skb_frag_t)
> -	 */
> -	umem_tailroom = ALIGN(48 + (max_frags * 16), cache_line_size);
> -	ifobj_tx->umem_tailroom = umem_tailroom;
> -	ifobj_rx->umem_tailroom = umem_tailroom;
> -
>  	parse_command_line(ifobj_tx, ifobj_rx, argc, argv);
>  
>  	if (opt_print_tests) {
> -- 
> 2.56.1
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net 3/3] selftests/bpf: Drop the zero-copy tailroom from the xsk tests
  2026-11-27 15:49   ` Maciej Fijalkowski
@ 2026-11-27 16:56     ` Björn Töpel
  0 siblings, 0 replies; 11+ messages in thread
From: Björn Töpel @ 2026-11-27 16:56 UTC (permalink / raw)
  To: Maciej Fijalkowski
  Cc: Magnus Karlsson, Alexander Lobakin, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, Shuah Khan, netdev, bpf, Simon Horman,
	Stanislav Fomichev, Martin KaFai Lau, Song Liu, Yonghong Song,
	Jiri Olsa, Emil Tsalapatis, Ihor Solodrai, Tony Nguyen,
	Przemek Kitszel, Larysa Zaremba, Tushar Vyavahare, Jason Xing,
	Bastien Curutchet, Colin Ian King, intel-wired-lan,
	linux-kselftest

On Fri, 27 Nov 2026 at 16:49, Maciej Fijalkowski
<maciej.fijalkowski@intel.com> wrote:
>
> On Fri, Nov 27, 2026 at 03:21:29PM +0100, Björn Töpel wrote:
> > The xsk tests take the size of the shared info off the UMEM headroom
> > of RX_DROPPED and off the growth of XDP_ADJUST_TAIL_GROW_MULTI_BUFF,
> > as zero-copy multi-buffer pools kept it at the end of each chunk.
> >
> > The previous patch moves the shared info into the buffer pool, so the
> > UMEM headroom limit and the frame size no longer leave room for it.
> > Drop it from both tests.
> >
> > Signed-off-by: Björn Töpel <bjorn@kernel.org>
> > ---
> >  tools/testing/selftests/bpf/prog_tests/test_xsk.c | 10 ++++------
> >  tools/testing/selftests/bpf/prog_tests/test_xsk.h |  2 --
> >  tools/testing/selftests/bpf/prog_tests/xsk.c      | 13 +------------
> >  tools/testing/selftests/bpf/xskxceiver.c          | 15 +--------------
>
> This is based on old xskxceiver location, would it be better to have this
> one send to -next out of this set? I assume the move might not have been
> back-propagated yet...so seems we would have to double the effort?

Ya, good call. I'll pop this out of the series, and respin a v2 w/o this.

Please have a look at the Intel side of things if 1 and 2 is a good
fit. I'll spin a v2 when Sashiko has spoken!


Björn

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net 2/3] xsk: Keep the shared info of zero-copy buffers in kernel memory
  2026-11-27 14:21 ` [PATCH net 2/3] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
@ 2026-11-27 19:26   ` Maciej Fijalkowski
  2026-11-28 14:22   ` sashiko-bot
  2026-11-28 15:14   ` netdev-bot+sashiko
  2 siblings, 0 replies; 11+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 19:26 UTC (permalink / raw)
  To: Björn Töpel
  Cc: Magnus Karlsson, Alexander Lobakin, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, Shuah Khan, netdev, bpf, Simon Horman,
	Stanislav Fomichev, Martin KaFai Lau, Song Liu, Yonghong Song,
	Jiri Olsa, Emil Tsalapatis, Ihor Solodrai, Tony Nguyen,
	Przemek Kitszel, Larysa Zaremba, Tushar Vyavahare, Jason Xing,
	Bastien Curutchet, Colin Ian King, intel-wired-lan,
	linux-kselftest

On Fri, Nov 27, 2026 at 03:21:28PM +0100, Björn Töpel wrote:
> A packet that a driver receives in zero-copy mode over several buffers
> keeps its shared info, the fragment list and its count, in the
> tailroom of the UMEM chunk of its head. Userspace may write the UMEM
> at any time, also while the kernel walks the fragments, and a
> rewritten list or count makes the kernel read and write out of bounds.
> 
> Keep the shared info in the buffer pool, which outlives its buffers
> and the queues that point to it, and let the device write up to the
> end of the chunk. One shared info per pool is enough, as a pool builds
> one multi-buffer packet at a time. libeth read it later, at an XDP_TX
> bulk flush, which the previous patch fixes.
> 
> Multi-buffer pools now give the device the whole chunk, as
> single-buffer pools already do, and allow a larger UMEM headroom.
> bpf_xdp_adjust_tail() can grow a packet up to the end of its chunk.
> Copy mode does not change.
> 
> Found by an AI code review agent, in its review of another series.
> 
> Suggested-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
> Fixes: 24ea50127ecf ("xsk: support mbuf on ZC RX")
> Signed-off-by: Björn Töpel <bjorn@kernel.org>

I applied this change on top of my changes implementing xsk.py in drv-net
selftests and gave this a run, plus a patch 3/3 was adjusted to fit the
new python runner but intent stayed the same.

Test used Intel's e810 (ice) back-to-back connection, 84 cases passed 0
failed.

Tested-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>

> ---
>  include/net/xdp.h           | 32 ++++++++++++++++++++++++++------
>  include/net/xdp_sock_drv.h  | 29 +++++++++--------------------
>  include/net/xsk_buff_pool.h |  2 ++
>  net/xdp/xdp_umem.c          |  3 +--
>  net/xdp/xsk_buff_pool.c     | 17 +++++++++--------
>  5 files changed, 47 insertions(+), 36 deletions(-)
> 
> diff --git a/include/net/xdp.h b/include/net/xdp.h
> index 07231adfb5f8..68dc9caacfa9 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h
> @@ -65,6 +65,10 @@ struct xdp_rxq_info {
>  	u32 reg_state;
>  	struct xdp_mem_info mem;
>  	u32 frag_size;
> +	/* Shared info of buffers with %XDP_FLAGS_SINFO_EXT, in the XSk buffer
> +	 * pool, set by xsk_pool_set_rxq_info().
> +	 */
> +	struct skb_shared_info *ext_sinfo;
>  } ____cacheline_aligned; /* perf critical, avoid false-sharing */
>  
>  struct xdp_txq_info {
> @@ -81,6 +85,13 @@ enum xdp_buff_flags {
>  	 * XDP program is not attached.
>  	 */
>  	XDP_FLAGS_FRAGS_UNREADABLE	= BIT(2),
> +	/* The shared info lives in &xdp_rxq_info.ext_sinfo, not at the end of
> +	 * the frame, as userspace may write the frame. The frame reserves no
> +	 * tailroom, so the data may reach its end. The pool builds one such
> +	 * buffer at a time, so a consumer that uses the shared info later
> +	 * must copy what it needs.
> +	 */
> +	XDP_FLAGS_SINFO_EXT		= BIT(3),
>  };
>  
>  struct xdp_buff {
> @@ -178,17 +189,26 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
>  
>  /* Reserve memory area at end-of data area.
>   *
> - * This macro reserves tailroom in the XDP buffer by limiting the
> - * XDP/BPF data access to data_hard_end.  Notice same area (and size)
> - * is used for XDP_PASS, when constructing the SKB via build_skb().
> + * This reserves tailroom in the XDP buffer by limiting the XDP/BPF data
> + * access to data_hard_end.  Notice same area (and size) is used for
> + * XDP_PASS, when constructing the SKB via build_skb(). Buffers with
> + * %XDP_FLAGS_SINFO_EXT keep the shared info elsewhere and reserve none.
>   */
> -#define xdp_data_hard_end(xdp)				\
> -	((xdp)->data_hard_start + (xdp)->frame_sz -	\
> -	 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
> +static __always_inline void *xdp_data_hard_end(const struct xdp_buff *xdp)
> +{
> +	u32 tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> +
> +	if (xdp->flags & XDP_FLAGS_SINFO_EXT)
> +		tailroom = 0;
> +	return xdp->data_hard_start + xdp->frame_sz - tailroom;
> +}
>  
>  static inline struct skb_shared_info *
>  xdp_get_shared_info_from_buff(const struct xdp_buff *xdp)
>  {
> +	if (xdp->flags & XDP_FLAGS_SINFO_EXT)
> +		return xdp->rxq->ext_sinfo;
> +
>  	return (struct skb_shared_info *)xdp_data_hard_end(xdp);
>  }
>  
> diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h
> index a40ad3f90f13..fc22314e72c4 100644
> --- a/include/net/xdp_sock_drv.h
> +++ b/include/net/xdp_sock_drv.h
> @@ -41,11 +41,6 @@ static inline u32 xsk_pool_get_headroom(struct xsk_buff_pool *pool)
>  	return XDP_PACKET_HEADROOM + pool->headroom;
>  }
>  
> -static inline u32 xsk_pool_get_tailroom(bool mbuf)
> -{
> -	return mbuf ? SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) : 0;
> -}
> -
>  static inline u32 xsk_pool_get_chunk_size(struct xsk_buff_pool *pool)
>  {
>  	return pool->chunk_size;
> @@ -56,20 +51,13 @@ static inline u32 __xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool)
>  	return xsk_pool_get_chunk_size(pool) - xsk_pool_get_headroom(pool);
>  }
>  
> +/* Device RX buffers typically come in 128-byte units. The shared info
> + * of zero-copy buffers lives in the pool, see xp_set_rxq_info(), so the
> + * device may write up to the end of the chunk.
> + */
>  static inline u32 xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool)
>  {
> -	u32 frame_size =  __xsk_pool_get_rx_frame_size(pool);
> -	struct xdp_umem *umem = pool->umem;
> -	bool mbuf;
> -
> -	/* Reserve tailroom only for zero-copy pools that opted into
> -	 * multi-buffer. The reserved area is used for skb_shared_info,
> -	 * matching the XDP core's xdp_data_hard_end() layout.
> -	 */
> -	mbuf = pool->dev && (umem->flags & XDP_UMEM_SG_FLAG);
> -	frame_size -= xsk_pool_get_tailroom(mbuf);
> -
> -	return ALIGN_DOWN(frame_size, 128);
> +	return ALIGN_DOWN(__xsk_pool_get_rx_frame_size(pool), 128);
>  }
>  
>  static inline u32 xsk_pool_get_rx_frag_step(struct xsk_buff_pool *pool)
> @@ -152,7 +140,6 @@ static inline void xsk_buff_free(struct xdp_buff *xdp)
>  		xp_free(pos);
>  	}
>  
> -	xdp_get_shared_info_from_buff(xdp)->nr_frags = 0;
>  	xdp_buff_clear_frags_flag(xdp);
>  out:
>  	xp_free(xskb);
> @@ -226,8 +213,10 @@ static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size)
>  	xdp->data = xdp->data_hard_start + XDP_PACKET_HEADROOM;
>  	xdp->data_meta = xdp->data;
>  	xdp->data_end = xdp->data + size;
> -	/* Frags flag is cleared when the frags of a head are released */
> -	xdp->flags &= XDP_FLAGS_HAS_FRAGS;
> +	/* Frags flag is cleared when the frags of a head are released. The
> +	 * shared info flag stays, see xp_set_rxq_info().
> +	 */
> +	xdp->flags &= XDP_FLAGS_HAS_FRAGS | XDP_FLAGS_SINFO_EXT;
>  }
>  
>  static inline dma_addr_t xsk_buff_raw_get_dma(struct xsk_buff_pool *pool,
> diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h
> index 02e89350faf9..f43e618ae707 100644
> --- a/include/net/xsk_buff_pool.h
> +++ b/include/net/xsk_buff_pool.h
> @@ -59,6 +59,8 @@ struct xsk_buff_pool {
>  	spinlock_t rx_lock;
>  	struct list_head free_list;
>  	struct list_head xskb_list;
> +	/* Fragment list of the packet being built, out of userspace reach */
> +	struct skb_shared_info sinfo;
>  	u32 heads_cnt;
>  	u16 queue_id;
>  
> diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
> index cd8643360eb3..e78a43c3c3e9 100644
> --- a/net/xdp/xdp_umem.c
> +++ b/net/xdp/xdp_umem.c
> @@ -203,8 +203,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
>  	if (!unaligned_chunks && chunks_rem)
>  		return -EINVAL;
>  
> -	if (headroom > chunk_size - XDP_PACKET_HEADROOM -
> -		       SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) - 128)
> +	if (headroom > chunk_size - XDP_PACKET_HEADROOM - 128)
>  		return -EINVAL;
>  
>  	if (mr->flags & XDP_UMEM_TX_METADATA_LEN) {
> diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
> index 5ec092f7cb6f..553630170229 100644
> --- a/net/xdp/xsk_buff_pool.c
> +++ b/net/xdp/xsk_buff_pool.c
> @@ -125,8 +125,14 @@ void xp_set_rxq_info(struct xsk_buff_pool *pool, struct xdp_rxq_info *rxq)
>  {
>  	u32 i;
>  
> -	for (i = 0; i < pool->heads_cnt; i++)
> +	/* Userspace may write the UMEM. Keep the shared info in the pool,
> +	 * and let the device write up to the end of each chunk.
> +	 */
> +	for (i = 0; i < pool->heads_cnt; i++) {
>  		pool->heads[i].xdp.rxq = rxq;
> +		pool->heads[i].xdp.flags |= XDP_FLAGS_SINFO_EXT;
> +	}
> +	rxq->ext_sinfo = &pool->sinfo;
>  }
>  EXPORT_SYMBOL(xp_set_rxq_info);
>  
> @@ -229,12 +235,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool,
>  		segs = 1;
>  	}
>  
> -	/* open-code xsk_pool_get_rx_frame_size() as pool->dev is not
> -	 * set yet at this point; we are before getting down to driver
> -	 */
> -	frame_size = __xsk_pool_get_rx_frame_size(pool) -
> -		     xsk_pool_get_tailroom(mbuf);
> -	frame_size = ALIGN_DOWN(frame_size, 128);
> +	frame_size = xsk_pool_get_rx_frame_size(pool);
>  
>  	if (needed > frame_size * segs) {
>  		err = -EINVAL;
> @@ -629,7 +630,7 @@ struct xdp_buff *xp_alloc(struct xsk_buff_pool *pool)
>  
>  	xskb->xdp.data = xskb->xdp.data_hard_start + XDP_PACKET_HEADROOM;
>  	xskb->xdp.data_meta = xskb->xdp.data;
> -	xskb->xdp.flags &= XDP_FLAGS_HAS_FRAGS;
> +	xskb->xdp.flags &= XDP_FLAGS_HAS_FRAGS | XDP_FLAGS_SINFO_EXT;
>  
>  	if (pool->dev)
>  		xp_dma_sync_for_device(pool, xskb->dma, pool->frame_len);
> -- 
> 2.56.1
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net 2/3] xsk: Keep the shared info of zero-copy buffers in kernel memory
  2026-11-27 14:21 ` [PATCH net 2/3] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
  2026-11-27 19:26   ` Maciej Fijalkowski
@ 2026-11-28 14:22   ` sashiko-bot
  2026-11-28 15:14   ` netdev-bot+sashiko
  2 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-11-28 14:22 UTC (permalink / raw)
  To: Björn Töpel, bpf; +Cc: intel-wired-lan

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Critical] xsk: skb_shinfo() buffer overflow in
  xdp_build_skb_from_zc() on XDP_PASS
- [Medium] xsk: lost XDP_FLAGS_SINFO_EXT flag on buffer reuse in
  buf_to_xdp()
--

commit 8a374e24c8b71b5be821eeab702cf5c5a6b0a6c4
Author: Björn Töpel <bjorn@kernel.org>

xsk: Keep the shared info of zero-copy buffers in kernel memory

This commit moves the skb_shared_info of AF_XDP zero-copy RX buffers from
the UMEM chunk tailroom into struct xsk_buff_pool and drops the tailroom
reservation from the chunk and headroom limits.

> diff --git a/include/net/xdp.h b/include/net/xdp.h
> index 07231adfb5f82..68dc9caacfa93 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h
[ ... ]
> @@ -178,17 +189,26 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
>  
>  /* Reserve memory area at end-of data area.
>   *
> - * This macro reserves tailroom in the XDP buffer by limiting the
> - * XDP/BPF data access to data_hard_end.  Notice same area (and size)
> - * is used for XDP_PASS, when constructing the SKB via build_skb().
> + * This reserves tailroom in the XDP buffer by limiting the XDP/BPF data
> + * access to data_hard_end.  Notice same area (and size) is used for
> + * XDP_PASS, when constructing the SKB via build_skb(). Buffers with
> + * %XDP_FLAGS_SINFO_EXT keep the shared info elsewhere and reserve none.
>   */
> -#define xdp_data_hard_end(xdp)				\
> -	((xdp)->data_hard_start + (xdp)->frame_sz -	\
> -	 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
> +static __always_inline void *xdp_data_hard_end(const struct xdp_buff *xdp)
> +{
> +	u32 tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> +
> +	if (xdp->flags & XDP_FLAGS_SINFO_EXT)
> +		tailroom = 0;
> +	return xdp->data_hard_start + xdp->frame_sz - tailroom;
> +}

[Severity: Critical]
Can xdp_build_skb_from_zc() overflow the allocated skb buffer and overwrite
skb_shinfo(skb) on XDP_PASS?

With XDP_FLAGS_SINFO_EXT removing the skb_shared_info tailroom reservation
from xdp_data_hard_end() and xsk_pool_get_rx_frame_size(), packet data in a
zero-copy buffer can now extend all the way to xdp->data_hard_start +
xdp->frame_sz.  However, xdp_build_skb_from_zc() still allocates the skb
buffer using truesize = xdp->frame_sz:

net/core/xdp.c:xdp_build_skb_from_zc() {
	...
	u32 len = xdp->data_end - xdp->data_meta;
	u32 truesize = xdp->frame_sz;
	...
	data = page_pool_dev_alloc_va(pp, &truesize);
	if (unlikely(!data))
		goto out;

	skb = napi_build_skb(data, truesize);
	if (unlikely(!skb)) {
		page_pool_free_va(pp, data, true);
		goto out;
	}

	skb_reserve(skb, xdp->data_meta - xdp->data_hard_start);

	memcpy(__skb_put(skb, len), xdp->data_meta, LARGEST_ALIGN(len));
	...
}

Because napi_build_skb() carves SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
out of the end of truesize, any zero-copy frame whose headroom plus
LARGEST_ALIGN(len) reaches into the last 320 bytes of xdp->frame_sz (such
as any multi-buffer head buffer on ice or idpf, or a buffer using the larger
UMEM headroom now permitted by xdp_umem_reg()) will copy past skb->end into
skb_shinfo(skb) and potentially past data + truesize into adjacent memory.

> diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h
> index a40ad3f90f13c..fc22314e72c4e 100644
> --- a/include/net/xdp_sock_drv.h
> +++ b/include/net/xdp_sock_drv.h
[ ... ]
> @@ -226,8 +213,10 @@ static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size)
>  	xdp->data = xdp->data_hard_start + XDP_PACKET_HEADROOM;
>  	xdp->data_meta = xdp->data;
>  	xdp->data_end = xdp->data + size;
> -	/* Frags flag is cleared when the frags of a head are released */
> -	xdp->flags &= XDP_FLAGS_HAS_FRAGS;
> +	/* Frags flag is cleared when the frags of a head are released. The
> +	 * shared info flag stays, see xp_set_rxq_info().
> +	 */
> +	xdp->flags &= XDP_FLAGS_HAS_FRAGS | XDP_FLAGS_SINFO_EXT;
>  }

[Severity: Medium]
Can an xdp_buff_xsk lose XDP_FLAGS_SINFO_EXT permanently when recycled after
virtio_net processes a mergeable multi-buffer RX packet?

xp_set_rxq_info() sets XDP_FLAGS_SINFO_EXT once at queue setup, and both
xp_alloc() and xsk_buff_set_size() only mask xdp->flags with &= rather than
setting the bit.  In virtio_net, buf_to_xdp() clears xdp->flags on follow-on
buffers before xsk_append_merge_buffer() frees them back to the pool:

drivers/net/virtio_net.c:buf_to_xdp() {
	...
	if (first_buf) {
		xsk_buff_set_size(xdp, len);
	} else {
		xdp_prepare_buff(xdp, xdp->data_hard_start,
				 XDP_PACKET_HEADROOM - vi->hdr_len, len, 1);
		xdp->flags = 0;
	}
	...
}

When that buffer is later reallocated as a head buffer, XDP_FLAGS_SINFO_EXT
remains cleared, causing xdp_get_shared_info_from_buff() to point back into
the UMEM chunk tailroom and xdp_data_hard_end() to subtract sizeof(struct
skb_shared_info) again.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127142131.3527737-1-bjorn@kernel.org?part=2

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net 1/3] libeth: xsk: Count each XDP_TX buffer on its own
  2026-11-27 14:21 ` [PATCH net 1/3] libeth: xsk: Count each XDP_TX buffer on its own Björn Töpel
@ 2026-11-28 15:14   ` netdev-bot+sashiko
  0 siblings, 0 replies; 11+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 15:14 UTC (permalink / raw)
  To: bjorn
  Cc: magnus.karlsson, maciej.fijalkowski, aleksander.lobakin, ast,
	daniel, hawk, john.fastabend, davem, edumazet, kuba, pabeni,
	willemb, andrii, eddyz87, memxor, shuah, netdev, bpf, horms, sdf,
	martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai,
	anthony.l.nguyen, przemyslaw.kitszel, larysa.zaremba,
	tushar.vyavahare, kerneljasonxing, bastien.curutchet,
	colin.i.king, intel-wired-lan, linux-kselftest

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 (1) · Medium: 0 · Low: 1 (1)

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The in-flight count still goes the wrong way.
- [Low] The kernel-doc for struct libeth_sqe in include/net/libeth/tx.h
  no longer matches LIBETH_SQE_XSK_TX / LIBETH_SQE_XSK_TX_FRAG SQEs.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
  libeth_xsk_tx_queue_bulk() (include/net/libeth/xsk.h) mishandles a…
- [Low] Dismissed (baseline false).

--

libeth: xsk: Count each XDP_TX buffer on its own

At bulk flush time, libeth no longer reads the shared info of an XSk
XDP_TX frame to get the fragment count and byte totals. Each SQE now
records the length of its own buffer. On completion, every head or
fragment SQE takes one off the in-flight count, and the head also
counts the packet.

> diff --git a/include/net/libeth/tx.h b/include/net/libeth/tx.h
> index c3db5c6f16410..25cad55664363 100644
> --- a/include/net/libeth/tx.h
> +++ b/include/net/libeth/tx.h
> @@ -22,7 +22,8 @@
>   * @LIBETH_SQE_XDP_XMIT: &xdp_frame, unmap and xdp_return_frame_bulk(), stats
>   * @LIBETH_SQE_XDP_XMIT_FRAG: &xdp_frame frag, only unmap DMA
>   * @LIBETH_SQE_XSK_TX: &libeth_xdp_buff on XSk queue, xsk_buff_free(), stats
> - * @LIBETH_SQE_XSK_TX_FRAG: &libeth_xdp_buff frag on XSk queue, xsk_buff_free()
> + * @LIBETH_SQE_XSK_TX_FRAG: &libeth_xdp_buff frag on XSk queue, xsk_buff_free(),
> + *			    stats
>   */
>  enum libeth_sqe_type {
>  	LIBETH_SQE_EMPTY		= 0U,

[Severity: Low]
The enum doc is updated here. Should the struct libeth_sqe kernel-doc in
the same file be updated as well? It still describes per-frame values:

 * @nr_frags: number of frags in the frame this buffer belongs to
 * @packets: number of physical packets sent for this frame
 * @bytes: number of physical bytes sent for this frame

After this patch, libeth_xsk_tx_fill_buf() stores only the length of
its own buffer in sqe->bytes. It also no longer calls
libeth_xdp_tx_fill_stats(), so nothing writes sqe->nr_frags for XSk
XDP_TX SQEs. The field keeps whatever an earlier user of that ring slot
left there.

Nothing reads these fields as frame totals today, so this only affects
the documentation.

> diff --git a/include/net/libeth/xdp.h b/include/net/libeth/xdp.h
> index 898723ab62e81..66a3c4ec9967e 100644
> --- a/include/net/libeth/xdp.h
> +++ b/include/net/libeth/xdp.h
> @@ -1794,12 +1794,19 @@ __libeth_xdp_complete_tx(struct libeth_sqe *sqe, struct libeth_cq_pp *cp,
>  	switch (type) {
>  	case LIBETH_SQE_XDP_TX:
>  	case LIBETH_SQE_XDP_XMIT:
> -	case LIBETH_SQE_XSK_TX:
>  		cp->xdp_tx -= sqe->nr_frags;
>  
>  		cp->xss->packets++;
>  		cp->xss->bytes += sqe->bytes;
>  		break;
> +	case LIBETH_SQE_XSK_TX:
> +		cp->xss->packets++;
> +		fallthrough;
> +	case LIBETH_SQE_XSK_TX_FRAG:
> +		/* One buffer per SQE, see libeth_xsk_tx_fill_buf() */
> +		cp->xdp_tx--;

[Severity: High]
Does this decrement move the in-flight count the right way once idpf
applies it?

idpf_xsksq_complete_slow() builds cp without an initializer for xdp_tx,
so the field starts at 0. The result is then subtracted from the queue
counter:

drivers/net/ethernet/intel/idpf/xsk.c:idpf_xsksq_complete_slow() {
	struct libeth_cq_pp cp = {
		.dev	= xdpsq->pool->dev,
		.bq	= &bq,
		.xss	= &ss,
		.napi	= true,
	};
    ...
	xdpsq->xdp_tx -= cp.xdp_tx;
    ...
}

After T buffers complete, cp.xdp_tx is (u32)-T, so the final
subtraction gives xdpsq->xdp_tx + T. The send side adds to the same
counter:

include/net/libeth/xdp.h:libeth_xdp_tx_xmit_bulk() {
    ...
	if (sq.xdp_tx)
		*sq.xdp_tx += n;
    ...
}

So xdpsq->xdp_tx seems to grow on both send and completion, and only
gets back to 0 when the u32 wraps. idpf_xdpsq_complete() in idpf/xdp.c
applies the delta the same way. The existing cp->xdp_tx -=
sqe->nr_frags for XDP_TX/XDP_XMIT follows the same convention.

The only reader is the fast path in idpf_xsksq_complete():

	if (likely(!xdpsq->xdp_tx)) {
		...
		xsk_frames = done_frames;

		goto finalize;
	}

If the counter never returns to 0, this fast path stays off after the
first XSk XDP_TX buffer is sent on the queue.

What happens if the counter wraps to exactly 0 while XSK_TX or
XSK_TX_FRAG SQEs are still outstanding? Every finished descriptor would
then go to xsk_tx_completed() as an xmit completion.
libeth_xdp_complete_tx() would be skipped, so those XDP_TX buffers would
never go back to the pool.

That looks like the same "wrong number of completions" result the
commit message says it fixes. The commit message also says:

  Head and fragments each take one off the in-flight count

Given how idpf applies the delta, each completed SQE appears to add one
instead. Later patches in the series don't seem to touch this either.

Should libeth accumulate a positive count here (cp->xdp_tx++, and
cp->xdp_tx += sqe->nr_frags above)? Or should idpf add cp.xdp_tx
instead of subtracting it?

[Severity: Low]
This isn't a bug introduced by this patch, but the kernel-doc for
struct libeth_cq_pp in include/net/libeth/tx.h says:

 * @xdp_tx: number of XDP-not-XSk frames processed

__libeth_xdp_complete_tx() actually counts buffers, and that includes
XSk XDP_TX buffers. The old code already counted LIBETH_SQE_XSK_TX
here. Could the wording be fixed while this code is being changed?

> +		cp->xss->bytes += sqe->bytes;
> +		break;
>  	default:
>  		break;
>  	}
> diff --git a/include/net/libeth/xsk.h b/include/net/libeth/xsk.h
> index 249b1c7407881..2cd4252a3445f 100644
> --- a/include/net/libeth/xsk.h
> +++ b/include/net/libeth/xsk.h
> @@ -129,6 +129,10 @@ libeth_xsk_tx_fill_buf(struct libeth_xdp_tx_frame frm, u32 i,
>  
>  	sqe = &sq->sqes[i];
>  	sqe->xsk = xdp;
> +	/* Count each buffer on its own SQE. The shared info of the frame
> +	 * may change before the bulk is flushed.
> +	 */
> +	sqe->bytes = desc.len;
>  
>  	if (!(desc.flags & LIBETH_XDP_TX_FIRST)) {
>  		sqe->type = LIBETH_SQE_XSK_TX_FRAG;

[ ... ]

[Severity: High]
This is a pre-existing issue and was not introduced by this patch. It
is in the same XSk XDP_TX path: does libeth_xsk_tx_queue_bulk() in this
file handle a flush failure in the middle of a frame correctly?

	for (struct libeth_xdp_buff *head = xdp; ; ) {
		xdp = container_of(xsk_buff_get_frag(&head->base),
				   typeof(*xdp), base);
		if (!xdp) {
			...
			xdp_buff_clear_frags_flag(&head->base);
			break;
		}

		if (unlikely(bq->count == LIBETH_XDP_TX_BULK) &&
		    unlikely(!flush_bulk(bq, LIBETH_XDP_TX_XSK))) {
			ret = false;
			break;
		}

		libeth_xsk_tx_queue_frag(bq, xdp);
	}

By this point, xsk_buff_get_frag() has already removed the frag from
pool->xskb_list with list_del_init(). If the bulk is full and
flush_bulk() fails because the XDPSQ has no free descriptors, the loop
breaks and that frag is neither queued nor freed. Does this leak one
UMEM buffer from the pool on every such failure?

The head is also left in a bad state. xdp_buff_clear_frags_flag(),
added by commit 90e5d84086d9 ("libeth: xsk: do not free in-flight frags
on XDP_TX completion"), only runs on the !xdp exit. So the head keeps
XDP_FLAGS_HAS_FRAGS.

At that point the head is either already in the HW ring from an earlier
mid-frame flush, or still in the bulk. Without LIBETH_XDP_TX_DROP,
libeth_xdp_tx_exception() only memmove()s it.

When the head is later completed or dropped, libeth_xsk_buff_free_slow()
calls xsk_buff_free(). Because the frags flag is still set, that frees
everything on the pool-wide list:

include/net/xdp_sock_drv.h:xsk_buff_free() {
    ...
	if (likely(!xdp_buff_has_frags(xdp)))
		goto out;

	list_for_each_entry_safe(pos, tmp, xskb_list, list_node) {
		list_del_init(&pos->list_node);
		xp_free(pos);
	}
    ...
}

The list can then hold frags of another frame being queued, or of a
partial Rx frame stashed across NAPI polls. Could those buffers go back
to the pool while still in use, and later be freed a second time through
their own SQEs?

The remaining frags of the failed frame also stay on xskb_list. They
would then be picked up as frags of the next multi-buffer frame.

This goes back to b3ad8450b4dc, and 90e5d84086d9 only covered the
success exit. Would it help to free the popped frag (or put it back) on
this error path, and handle the head's frags flag consistently?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127142131.3527737-1-bjorn%40kernel.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net 2/3] xsk: Keep the shared info of zero-copy buffers in kernel memory
  2026-11-27 14:21 ` [PATCH net 2/3] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
  2026-11-27 19:26   ` Maciej Fijalkowski
  2026-11-28 14:22   ` sashiko-bot
@ 2026-11-28 15:14   ` netdev-bot+sashiko
  2 siblings, 0 replies; 11+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 15:14 UTC (permalink / raw)
  To: bjorn
  Cc: magnus.karlsson, maciej.fijalkowski, aleksander.lobakin, ast,
	daniel, hawk, john.fastabend, davem, edumazet, kuba, pabeni,
	willemb, andrii, eddyz87, memxor, shuah, netdev, bpf, horms, sdf,
	martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai,
	anthony.l.nguyen, przemyslaw.kitszel, larysa.zaremba,
	tushar.vyavahare, kerneljasonxing, bastien.curutchet,
	colin.i.king, intel-wired-lan, linux-kselftest

Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.

Critical: 1 · High: 1 · Medium: 2 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Critical] Heap overflow in xdp_build_skb_from_zc() (net/core/xdp.c).
- [High] xdp_build_skb_from_zc() (net/core/xdp.c) copies with
  memcpy(__skb_put(skb, len), xdp->data_meta, LARGEST_ALIGN(len)), which…
- [Medium] xp_set_rxq_info() (net/xdp/xsk_buff_pool.c) has a publication-
  order race with a live datapath.
- [Medium] xsk: lost XDP_FLAGS_SINFO_EXT flag on buffer reuse in
  buf_to_xdp()
- [Low] The comment in bpf_xdp_adjust_tail() (net/core/filter.c:4513)
  still says "Notice that xdp_data_hard_end have reserved some tailroom".
- [Low] The new 'struct skb_shared_info sinfo' member of struct
  xsk_buff_pool (include/net/xsk_buff_pool.h) is placed in the section…

--

xsk: Keep the shared info of zero-copy buffers in kernel memory

This patch moves the skb_shared_info of zero-copy XSk multi-buffer packets
out of the UMEM chunk tailroom and into the buffer pool. The pool copy is
reached through a new xdp_rxq_info.ext_sinfo pointer and a new
XDP_FLAGS_SINFO_EXT buffer flag. Zero-copy buffers no longer reserve
tailroom, so the device can fill the whole chunk and bpf_xdp_adjust_tail()
can grow a packet up to the chunk end.

> diff --git a/include/net/xdp.h b/include/net/xdp.h
> index 07231adfb5f82..68dc9caacfa93 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h

[ ... ]

> @@ -178,17 +189,26 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
>
>  /* Reserve memory area at end-of data area.
>   *
> - * This macro reserves tailroom in the XDP buffer by limiting the
> - * XDP/BPF data access to data_hard_end.  Notice same area (and size)
> - * is used for XDP_PASS, when constructing the SKB via build_skb().
> + * This reserves tailroom in the XDP buffer by limiting the XDP/BPF data
> + * access to data_hard_end.  Notice same area (and size) is used for
> + * XDP_PASS, when constructing the SKB via build_skb(). Buffers with
> + * %XDP_FLAGS_SINFO_EXT keep the shared info elsewhere and reserve none.
>   */
> -#define xdp_data_hard_end(xdp)				\
> -	((xdp)->data_hard_start + (xdp)->frame_sz -	\
> -	 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
> +static __always_inline void *xdp_data_hard_end(const struct xdp_buff *xdp)
> +{
> +	u32 tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> +
> +	if (xdp->flags & XDP_FLAGS_SINFO_EXT)
> +		tailroom = 0;
> +	return xdp->data_hard_start + xdp->frame_sz - tailroom;
> +}

[Severity: Low]
This isn't a bug, but bpf_xdp_adjust_tail() in net/core/filter.c still has
this comment above its linear grow check:

	/* Notice that xdp_data_hard_end have reserved some tailroom */
	if (unlikely(data_end > data_hard_end))
		return -EINVAL;

xp_set_rxq_info() now sets XDP_FLAGS_SINFO_EXT on every zero-copy XSk
buffer. For those buffers xdp_data_hard_end() reserves no tailroom, so
data_end can reach the end of the UMEM chunk.

Should that comment be updated as well?

[ ... ]

> diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h
> index a40ad3f90f13c..fc22314e72c4e 100644
> --- a/include/net/xdp_sock_drv.h
> +++ b/include/net/xdp_sock_drv.h

[ ... ]

> @@ -56,20 +51,13 @@ static inline u32 __xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool)
>  	return xsk_pool_get_chunk_size(pool) - xsk_pool_get_headroom(pool);
>  }
>
> +/* Device RX buffers typically come in 128-byte units. The shared info
> + * of zero-copy buffers lives in the pool, see xp_set_rxq_info(), so the
> + * device may write up to the end of the chunk.
> + */
>  static inline u32 xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool)
>  {
> -	u32 frame_size =  __xsk_pool_get_rx_frame_size(pool);
> -	struct xdp_umem *umem = pool->umem;
> -	bool mbuf;
> -
> -	/* Reserve tailroom only for zero-copy pools that opted into
> -	 * multi-buffer. The reserved area is used for skb_shared_info,
> -	 * matching the XDP core's xdp_data_hard_end() layout.
> -	 */
> -	mbuf = pool->dev && (umem->flags & XDP_UMEM_SG_FLAG);
> -	frame_size -= xsk_pool_get_tailroom(mbuf);
> -
> -	return ALIGN_DOWN(frame_size, 128);
> +	return ALIGN_DOWN(__xsk_pool_get_rx_frame_size(pool), 128);
>  }

[Severity: Critical]
Can this overflow the skb_shared_info of the skb built by
xdp_build_skb_from_zc() in net/core/xdp.c?

Multi-buffer pools no longer have the tailroom subtracted, so the device
fills the head buffer up to data_hard_start + frame_sz, which is the end
of the chunk. xdp_build_skb_from_zc() still sizes the new skb head from
frame_sz:

net/core/xdp.c:xdp_build_skb_from_zc() {
	u32 len = xdp->data_end - xdp->data_meta;
	u32 truesize = xdp->frame_sz;
	...
	data = page_pool_dev_alloc_va(pp, &truesize);
	...
	skb = napi_build_skb(data, truesize);
	...
	skb_reserve(skb, xdp->data_meta - xdp->data_hard_start);

	memcpy(__skb_put(skb, len), xdp->data_meta, LARGEST_ALIGN(len));
	...
}

napi_build_skb() puts skb_shared_info at data + truesize -
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)). __skb_put() does not check
tail against end.

Take a 4K chunk with headroom 0, XDP_USE_SG and a jumbo frame.
rx_frame_size is now ALIGN_DOWN(4096 - 256, 128) = 3840, so the head
buffer holds 3840 bytes and data_end - data_hard_start is 4096.
napi_build_skb(data, 4096) leaves 3776 usable bytes.

The copy then writes packet bytes from the wire over all 320 bytes of the
skb_shared_info that was just initialized. That includes flags,
frag_list, dataref and destructor_arg. With 2K chunks the copy reaches
2048 bytes into a 1728 byte area.

Before this patch an SG pool got rx_frame_size = 3456, so
data_end - data_hard_start was at most 3712, which fit below 3776.

Single-buffer pools hit the same overflow when an XDP program grows the
tail to the chunk end with bpf_xdp_adjust_tail(). xdp_data_hard_end() now
returns the chunk end for these buffers.

This looks reachable from the XDP_PASS paths in ice_clean_rx_irq_zc(),
__libeth_xsk_run_pass() (idpf) and gve DQO. The commit message says the
device may now write the whole chunk, but this consumer is left
unchanged.

Should truesize be sized from (data_end - data_hard_start) +
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)), or should the copy be
bounded some other way?

[Severity: High]
A related question: can the LARGEST_ALIGN(len) copy in
xdp_build_skb_from_zc() now read past the end of the UMEM chunk?

	memcpy(__skb_put(skb, len), xdp->data_meta, LARGEST_ALIGN(len));

LARGEST_ALIGN() rounds len up to __LARGEST_ALIGN, which is 16 on x86_64
and arm64. Before this patch every zero-copy frame kept at least
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) bytes of chunk after
data_end, so the rounded read stayed inside the chunk.

data_end can now equal the chunk end in two ways:

- a full SG head buffer, when the headroom is a multiple of 128
- bpf_xdp_adjust_tail() growing the packet to xdp_data_hard_end()

If len is not a multiple of 16, the copy reads up to 15 bytes past the
chunk. That happens with 4 or 8 bytes of metadata from
bpf_xdp_adjust_meta(), or with a UMEM headroom such as 4, which
xdp_umem_reg() accepts.

For the last chunk of an aligned UMEM whose size is a multiple of
PAGE_SIZE, the chunk end is the end of the vmap() area created by
xdp_umem_addr_map(). Could this read fault on the guard page in NAPI
context?

The rounded write also runs the same number of bytes past the new skb's
tail, and past truesize. This adds to the skb_shared_info overwrite
described above.

[ ... ]

> diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h
> index 02e89350faf9a..f43e618ae707c 100644
> --- a/include/net/xsk_buff_pool.h
> +++ b/include/net/xsk_buff_pool.h
> @@ -59,6 +59,8 @@ struct xsk_buff_pool {
>  	spinlock_t rx_lock;
>  	struct list_head free_list;
>  	struct list_head xskb_list;
> +	/* Fragment list of the packet being built, out of userspace reach */
> +	struct skb_shared_info sinfo;
>  	u32 heads_cnt;
>  	u16 queue_id;
>

[Severity: Low]
This isn't a bug, but struct xsk_buff_pool documents this section as
"Members only used in the control path first.". The data path members
start at the cacheline aligned fq.

sinfo is about 320 bytes. It is read and written for every multi-buffer
zero-copy packet through rxq->ext_sinfo: in xsk_buff_add_frag(), the
bpf_xdp_* helpers, xsk_rcv_zc() and the driver XDP_TX paths.

Would it fit better with the data path members?

[ ... ]

> diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
> index 5ec092f7cb6f7..5536301702297 100644
> --- a/net/xdp/xsk_buff_pool.c
> +++ b/net/xdp/xsk_buff_pool.c
> @@ -125,8 +125,14 @@ void xp_set_rxq_info(struct xsk_buff_pool *pool, struct xdp_rxq_info *rxq)
>  {
>  	u32 i;
>
> -	for (i = 0; i < pool->heads_cnt; i++)
> +	/* Userspace may write the UMEM. Keep the shared info in the pool,
> +	 * and let the device write up to the end of each chunk.
> +	 */
> +	for (i = 0; i < pool->heads_cnt; i++) {
>  		pool->heads[i].xdp.rxq = rxq;
> +		pool->heads[i].xdp.flags |= XDP_FLAGS_SINFO_EXT;
> +	}
> +	rxq->ext_sinfo = &pool->sinfo;

[Severity: Medium]
Does the shared info flag really stay for virtio_net in zero-copy
mode?

xp_set_rxq_info() sets XDP_FLAGS_SINFO_EXT on the heads only once,
when the pool is bound to the rxq. After that, xp_alloc() and
xsk_buff_set_size() only mask xdp->flags, and xp_alloc_batch() does
not touch them. Once the flag is cleared on a head, nothing sets it
again.

buf_to_xdp() in drivers/net/virtio_net.c clears it for every buffer
after the first one of a mergeable packet:

	} else {
		xdp_prepare_buff(xdp, xdp->data_hard_start,
				 XDP_PACKET_HEADROOM - vi->hdr_len, len, 1);
		xdp->flags = 0;
	}

xsk_append_merge_buffer() then returns that buffer to the pool with
xsk_buff_free(). The same xdp_buff_xsk can later come back through
xsk_buff_alloc_batch() as the first buffer of a packet. Then
xsk_buff_set_size() keeps the cleared flag, and the buffer stays
without XDP_FLAGS_SINFO_EXT for the rest of the pool's lifetime.

For such a head, xdp_data_hard_end() subtracts
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) again. The length check
in buf_to_xdp() still accepts frames up to
xsk_pool_get_rx_frame_size(), which no longer leaves that tailroom.

A full frame then ends past data_hard_end, and bpf_xdp_adjust_tail()
returns -EINVAL for any offset that leaves data_end there. With the
larger headroom that xdp_umem_reg() now accepts, data_hard_end can
even fall below xdp->data.

xdp_get_shared_info_from_buff() also points back into the
userspace-writable chunk tailroom. That area now holds packet data.
This is the situation the patch is meant to remove.

Any other zero-copy driver that assigns xdp->flags on a pool buffer
would hit the same problem.

Should xp_alloc() and xsk_buff_set_size() set XDP_FLAGS_SINFO_EXT
instead of only keeping it? xp_alloc_batch() would need the same
treatment, since virtio_net allocates through it. Alternatively,
should buf_to_xdp() clear only XDP_FLAGS_HAS_FRAGS?

[Severity: Medium]
Is there a window here where a head already has XDP_FLAGS_SINFO_EXT and
the new rxq, but rxq->ext_sinfo is still NULL?

xdp_rxq_info_init() in __xdp_rxq_info_reg() zeroed the new rxq.
ext_sinfo is stored only after the loop, with no barrier, and
xdp_get_shared_info_from_buff() returns it without a NULL check:

	if (xdp->flags & XDP_FLAGS_SINFO_EXT)
		return xdp->rxq->ext_sinfo;

mlx5e_safe_switch_params() opens the new channels while the old ones are
still active:

mlx5e_safe_switch_params()
  mlx5e_open_channels(priv, new_chs)
    ...
      mlx5e_alloc_rq()
        xsk_pool_set_rxq_info(rq->xsk_pool, &rq->xdp_rxq)

The loop covers one head per UMEM chunk, and the old NAPI keeps serving
the same pool while it runs. The old NAPI can then process a head whose
rxq already points at the new rxq.

An XDP program that reaches the shared info would then dereference NULL.
One example is bpf_xdp_pointer(), which reads sinfo->nr_frags when called
from bpf_dynptr_slice() with offset equal to the linear size and len 0.
I could not fully confirm that the verifier accepts a zero-size slice
there.

The plain read-modify-write of heads[i].xdp.flags can also race with the
datapath's own flag updates in xp_alloc() and xsk_buff_set_size(), and
with the setting and clearing of XDP_FLAGS_HAS_FRAGS. That could lose
XDP_FLAGS_HAS_FRAGS or bring it back.

The rxq pointer swap under a live datapath already existed. The NULL
ext_sinfo window is new with this patch.

Would storing rxq->ext_sinfo before publishing rxq on the heads, with
release/acquire or WRITE_ONCE() ordering, close this window? Requiring a
quiesced datapath here would also work.

>  }
>  EXPORT_SYMBOL(xp_set_rxq_info);

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127142131.3527737-1-bjorn%40kernel.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-11-28 15:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 14:21 [PATCH net 0/3] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
2026-11-27 14:21 ` [PATCH net 1/3] libeth: xsk: Count each XDP_TX buffer on its own Björn Töpel
2026-11-28 15:14   ` netdev-bot+sashiko
2026-11-27 14:21 ` [PATCH net 2/3] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
2026-11-27 19:26   ` Maciej Fijalkowski
2026-11-28 14:22   ` sashiko-bot
2026-11-28 15:14   ` netdev-bot+sashiko
2026-11-27 14:21 ` [PATCH net 3/3] selftests/bpf: Drop the zero-copy tailroom from the xsk tests Björn Töpel
2026-11-27 15:49   ` Maciej Fijalkowski
2026-11-27 16:56     ` Björn Töpel
2026-11-27 14:24 ` [PATCH net 0/3] xsk: Keep the shared info of zero-copy buffers in kernel memory netdev-bot+sinfo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox