[PATCH net-next v2 00/15] xsk: Return UMEM chunks explicitly

From: Björn Töpel

Date: Fri Dec 04 2026 - 11:27:47 EST


Currently, AF_XDP zero copy fills one UMEM chunk per buffer at the
UMEM headroom, and each RX descriptor gives its chunk back. Drivers
carry a second RX path for that layout, and cannot use their own
buffer sizes or pack small packets into a page.

This series adds explicit chunk return. With XDP_UMEM_EXPLICIT_RETURN,
the device lays out buffers in chunks as in pages, so a chunk may hold
several buffers and a packet may span chunks. Each buffer reaches the
socket as an RX descriptor. A chunk comes back on a descriptor with
XDP_RX_CHUNK_RETURNED, or without one once the receiving socket is
gone. The application cannot influence where packets land, how many
share a chunk, or the headroom.

The design came out of off-list discussions with Magnus, Maciej,
Stanislav and Jakub, where Jakub proposed letting the device keep its
own buffer layout.

The chunks back the bound queue's RX page pools through an AF_XDP
memory provider, so drivers need no AF_XDP code. fbnic and mlx5 add 54
and 165 lines, to handle buffers as netmem, refuse settings that the
provider cannot take and, for mlx5, restart queues with a provider
bound. A native XDP program steers packets to the socket. The kernel
keeps nothing in the chunks, as userspace may write them at any time.

The provider takes no lock. The driver uses the queue's buffers from
one context at a time, its NAPI or an operation that runs only while
that NAPI cannot use the rings. It runs that NAPI once after the queue
starts, and passes the buffers only to the queue's socket. That
context writes every return at once, as the RX ring keeps room for
each chunk the kernel owes, so packets drop a little before the ring
is full.

This posting drops XDP_PASS and XDP_TX of these buffers. Both need a
copy, which a follow-up adds. Until then, management traffic should
use other queues. Sockets transmit in copy mode only.

Performance in Mpps with 4 KiB chunks and preferred busy polling, so
application and NAPI share one CPU. Native XDP drops each packet and
AF_XDP sockets only return it, untouched. Min-max of 3 runs, 5 for
mlx5 XDP_DROP below 300 B; * is within 2% of the offered load, ** a
PCIe limit (Gen4 x4).

MTU 1500:

offered native explicit classic
frame NIC XDP_DROP return zero copy
66 B mlx5 61.0 31.38-32.71 18.19-18.25 23.40-23.87
fbnic 65.3 37.68-38.15 26.61-26.96 n/a
128 B mlx5 37.0 31.07-31.27** 18.09-18.28 23.22-23.64
fbnic 40.5 37.99-38.21 26.81-27.14 n/a
300 B mlx5 19.3 17.70-17.71** 17.72-17.73** 17.72-17.73**
fbnic 17.4 17.38-17.43* 17.41-17.52* n/a
1500 B mlx5 4.10 4.10* 4.10* 4.09*
fbnic 4.04 4.03-4.08* 4.03-4.05* n/a

MTU 5000, where classic zero copy cannot bind on mlx5; fbnic has none:

offered native explicit classic
frame NIC XDP_DROP return zero copy
300 B mlx5 19.3 17.78** 17.21-17.48** n/a
fbnic 17.4 17.41-17.48* 17.39-17.46* n/a
1500 B mlx5 4.10 4.10* 4.10* n/a
fbnic 4.04 4.04-4.06* 4.03-4.04* n/a
3000 B mlx5 2.07 2.07* 2.07* n/a
fbnic 2.02 2.02* 2.02* n/a
5000 B mlx5 1.24 1.24* 1.24* n/a
fbnic 1.21 1.20-1.21* 1.20-1.21* n/a

Native XDP (XDP_DROP, XDP_TX and XDP_REDIRECT), classic AF_XDP and the
kernel UDP and TCP paths run at the rate of the base on mlx5, fbnic
and bnxt, within the run-to-run spread.

This series transmits in copy mode; the full branch, with bnxt,
zero-copy TX and the follow-up optimizations, and its numbers are at
https://github.com/fb-bjorn/linux/tree/xsk-explicit-return-v2.

Dependencies:
- "xsk: Keep the shared info of zero-copy buffers in kernel memory",
https://lore.kernel.org/netdev/20261204142030.626820-1-bjorn@xxxxxxxxxx/;
- "eth: fbnic: Support XDP redirect",
https://lore.kernel.org/netdev/20261203180924.3862144-1-bjorn@xxxxxxxxxx/;
- "net/mlx5e: Report a down device as -ENETDOWN to queue restarts",
https://lore.kernel.org/netdev/20261201113925.1245805-1-bjorn@xxxxxxxxxx/;
- "ethtool: Allow the channel count that a memory provider needs",
https://lore.kernel.org/netdev/20261201115458.1254880-1-bjorn@xxxxxxxxxx/;
- "bpf: Use the checked TCP header length in the syncookie helpers",
https://lore.kernel.org/netdev/20261201091755.1130605-1-bjorn@xxxxxxxxxx/.

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

Changes since v1:
- v1 was "xsk: Receive in the device's buffer layout". The flags are
now XDP_UMEM_EXPLICIT_RETURN and XDP_RX_CHUNK_RETURNED, not
XDP_UMEM_DRV_LAYOUT and XDP_RX_CHUNK_FREE, after Magnus. xsk_sink
is now xsk_mp, and "sink" is "XDP-only" in kernel names;
- v1 patch 2 became a net series, see Dependencies, which also moves
the shared info of classic zero-copy buffers out of the UMEM,
after Maciej;
- v1 patch 9, fbnic XDP_REDIRECT, is a dependency. v1 patch 11
is part of patch 2, and v1 patch 12 is split into patches 10 and
11. bnxt, v1 patch 13, comes back in a follow-up, after fixes to
its queue restarts. Patches 8, 12 and 13 are new;
- binding also needs CAP_NET_ADMIN, and XDP_ZEROCOPY fails as
XDP_COPY did. Classic zero copy may bind next to an XDP-only
provider on another queue;
- an empty head with metadata reaches the socket as a zero-length
first descriptor with XDP_PKT_CONTD. v1 dropped such packets;
- a returned chunk counts against no page pool, so a restart while
bound does not starve the new queue;
- the provider takes no lock, as the driver uses a queue's buffers
from one context at a time. Returns go into RX ring room kept for
them, and need_wakeup reports only an empty FILL ring;
- the provider drops the references of a run of buffers at once, and
mlx5 lets go of a page after its last stride, so fewer chunks need
an extra empty descriptor;
- the provider goes with the last socket of the queue, not with the
receiving socket. Once the receiver is gone, the queue drops what
it redirects and the chunks the kernel owes return. The rest
return with the last socket, and a program detach right after that
may briefly fail with EBUSY;
- redirects show in the xdp_redirect_map tracepoints, and page-pool
dumps carry a new, empty xsk nest, NETDEV_A_PAGE_POOL_XSK;
- mlx5 takes the provider on striding RQs only. While a queue has
one, it refuses to leave them, PTP, HTB offload and growing the
RQs of a down device. A channel switch closes the old channels
first;
- xskxceiver's --drv-layout is now --explicit-return, -H checks the
headroom, and RX_RING_FULL_RETURNS is new. The test now fits the
reworked xsk selftests, and drivers/net/xsk.py runs its rx cases
with explicit return on a NIC. The af_xdp.rst section
"Device Buffer Layout" is now "Explicit Chunk Return", with a part
for drivers;
- many fixes from a machine review of v1, listed in each patch.

Björn Töpel (15):
xdp: Let memory providers expose net_iovs to XDP
net: Add memory providers that only feed XDP
page_pool: Let memory providers take back net_iovs
xdp: Run programs on XDP-only buffers
xsk: Back a queue's page pools with UMEM chunks
xsk: Deliver packets and return chunks explicitly
xsk: Receive with explicit chunk return
xsk: Drop references of a run of buffers at once
eth: fbnic: Receive into XDP-only memory providers
net/mlx5e: Handle restarts with XDP-only providers
net/mlx5e: Receive into XDP-only memory providers
net/mlx5e: Release XDP-only pages earlier
net/mlx5e: Test for XDP-only pages per RQ
selftests: net: xsk: Test explicit chunk return
Documentation: xsk: Describe explicit chunk return

Documentation/netlink/specs/netdev.yaml | 8 +
Documentation/networking/af_xdp.rst | 244 ++++-
drivers/net/ethernet/mellanox/mlx5/core/en.h | 1 +
.../net/ethernet/mellanox/mlx5/core/en_main.c | 100 +-
.../net/ethernet/mellanox/mlx5/core/en_rx.c | 83 +-
.../net/ethernet/meta/fbnic/fbnic_ethtool.c | 22 +
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 41 +-
drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 8 +
drivers/net/netkit.c | 2 +-
include/linux/netdevice.h | 2 +
include/net/netdev_queues.h | 1 +
include/net/netdev_rx_queue.h | 5 +
include/net/netmem.h | 31 +-
include/net/page_pool/helpers.h | 4 +-
include/net/page_pool/memory_provider.h | 22 +
include/net/page_pool/types.h | 24 +-
include/net/xdp.h | 117 ++-
include/net/xdp_sock.h | 8 +
include/net/xsk_buff_pool.h | 3 +
include/uapi/linux/if_xdp.h | 23 +-
include/uapi/linux/netdev.h | 1 +
net/core/dev.c | 56 +-
net/core/filter.c | 46 +-
net/core/netdev_rx_queue.c | 51 +-
net/core/page_pool.c | 71 +-
net/core/xdp.c | 55 ++
net/ethtool/rings.c | 5 +-
net/xdp/Kconfig | 1 +
net/xdp/Makefile | 2 +-
net/xdp/xdp_umem.c | 5 +
net/xdp/xsk.c | 110 ++-
net/xdp/xsk_buff_pool.c | 38 +-
net/xdp/xsk_mp.c | 900 ++++++++++++++++++
net/xdp/xsk_mp.h | 21 +
tools/include/uapi/linux/if_xdp.h | 23 +-
tools/include/uapi/linux/netdev.h | 1 +
tools/testing/selftests/drivers/net/xsk.py | 28 +-
.../testing/selftests/net/lib/xsk/test_xsk.c | 556 ++++++++++-
.../testing/selftests/net/lib/xsk/test_xsk.h | 9 +
.../selftests/net/lib/xsk/xskxceiver.c | 57 +-
40 files changed, 2659 insertions(+), 126 deletions(-)
create mode 100644 net/xdp/xsk_mp.c
create mode 100644 net/xdp/xsk_mp.h


base-commit: e5ba10df689a988da8480e4f3e2a6cd88a506f97
--
2.56.1