BPF List
 help / color / mirror / Atom feed
* [PATCH net v2 0/4] xsk: Keep the shared info of zero-copy buffers in kernel memory
@ 2026-11-30 12:37 Björn Töpel
  2026-11-30 12:37 ` [PATCH net v2 1/4] libeth: xsk: Count each XDP_TX buffer on its own Björn Töpel
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Björn Töpel @ 2026-11-30 12:37 UTC (permalink / raw)
  To: Magnus Karlsson, Maciej Fijalkowski, Alexander Lobakin,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, 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,
	intel-wired-lan, Clément Lecigne

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 4 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. Patches 2 and 3 fix skb builders that relied on the old
tailroom: the generic one sized the skb head from the frame size, and
i40e, igb, igc and ixgbe read past the data.

Sashiko found the shared info issue in its review of the AF_XDP device
buffer layout series [1], and the issues fixed by patches 2 and 3 in
its review of v1. Clément reported the issue of patch 2 earlier [2].
Patch 3 was reproduced on igb in QEMU; the others were not triggered
at runtime.

I tested this on mlx5 hardware, and on igb, virtio-net and veth in
QEMU. None of them receives multi-buffer packets in zero copy or uses
the generic skb builder, so i40e, ice, idpf and gve 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.

Changes in v2:
- Patch 1: fix the kernel-doc of struct libeth_sqe (Sashiko)
- New patch 2: size zero-copy skbs from the data, and copy the exact
  length (Sashiko, Clément)
- New patch 3: copy the exact length in i40e, igb, igc and ixgbe
  (Sashiko)
- Patch 4: set the flag on every buffer when the pool is created, and
  again in xp_alloc() and xsk_buff_set_size(), as virtio_net clears
  the flags of some buffers (Sashiko)
- Patch 4: publish the shared info before the buffers point to the
  queue (Sashiko)
- Patch 4: update the comment in bpf_xdp_adjust_tail() (Sashiko)
- Drop the selftest patch, it goes to net-next once net is merged
  (Maciej)
- The libeth XDP_TX completion count that Sashiko found going the
  wrong way is older and unrelated to the shared info; Separate fix

v1: https://lore.kernel.org/netdev/20261127142131.3527737-1-bjorn@kernel.org/

[1] https://lore.kernel.org/netdev/179561567996.3135.9952128421877275714@kernel.org/
[2] https://lore.kernel.org/bpf/20260629072300.1664622-1-clecigne@google.com/

Björn Töpel (4):
  libeth: xsk: Count each XDP_TX buffer on its own
  xdp: Size zero-copy skbs from the data, not the frame size
  intel: Copy the exact length of XSk packets to skbs
  xsk: Keep the shared info of zero-copy buffers in kernel memory

 drivers/net/ethernet/intel/i40e/i40e_xsk.c   |  3 +-
 drivers/net/ethernet/intel/igb/igb_xsk.c     |  3 +-
 drivers/net/ethernet/intel/igc/igc_main.c    |  3 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c |  3 +-
 include/net/libeth/tx.h                      |  8 ++--
 include/net/libeth/xdp.h                     |  9 ++++-
 include/net/libeth/xsk.h                     |  6 ++-
 include/net/xdp.h                            | 32 +++++++++++++---
 include/net/xdp_sock_drv.h                   | 26 +++----------
 include/net/xsk_buff_pool.h                  |  1 +
 net/core/filter.c                            |  2 +-
 net/core/xdp.c                               | 40 ++++++++++++++------
 net/xdp/xdp_umem.c                           |  3 +-
 net/xdp/xsk_buff_pool.c                      | 20 ++++++----
 14 files changed, 96 insertions(+), 63 deletions(-)


base-commit: e2fb9368a41662bc54624f9be87ea8989b109306
-- 
2.56.1


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

end of thread, other threads:[~2026-11-30 12:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 12:37 [PATCH net v2 0/4] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
2026-11-30 12:37 ` [PATCH net v2 1/4] libeth: xsk: Count each XDP_TX buffer on its own Björn Töpel
2026-11-30 12:37 ` [PATCH net v2 2/4] xdp: Size zero-copy skbs from the data, not the frame size Björn Töpel
2026-11-30 12:37 ` [PATCH net v2 3/4] intel: Copy the exact length of XSk packets to skbs Björn Töpel
2026-11-30 12:37 ` [PATCH net v2 4/4] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel

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