From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796401660; b=u0UL2nzsn/Va+MWXPRD8CG76+UOEVwtFRl3s4JsoPrZ2SZg1VkQlWD6s5YRBr5NOc/j9 UAQTTPnyQGfgkMhgVIc8rvp1855GCTBB7xv1JRBiIC28JpId8HJo4sZTYt8o+bxlgRK6P BynflMzCDCG9FyFYNTniG7btSvahQDO5U86aE/Z/nSlkhzNZGFcFPnLpp5paLmoOzMhHG SPVRsGofsF82NuneLQU1U5TxJ6J3FVI6GsrORqlG86+TMB5NgHpPIkgjtIF+YiNECWVxP E+TSyymIvQiMHoxsWvA5XQHIRL7mUzsRlmHEM49laz9SjHjGeGBMILAJTz3VxcMQlAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796401660; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=2LMkYRTeqw34yFVH5rmu3fod1f0Y7ynxU6iL2gWVyCg=; b=x16p3MgdjjwzirBjaUtkaFEikgaQSLhdLtNs+Gvw6QvBtNqFFqM1m2oYITOxO8HcFk+o PHy22YGU1QEPb/gMD8m74rl6vUYNtSlYXLsDxBsPj7pRjcDnWo0Pm7/qGa3QYIASxnOH/ 2hukBrCefHHzOer9apm0jHTPZ6YsT0KqtmKSviGsCxmc306INxnrnH+bbh4lmcbr96mGN /W418CJ10H6NmbZqQaPZiMle0gJEatAJzes1+g8aYWz054siucM8aw2KxMEr784OIL4AS YM2AOUVoyGVAwBpX8c36Ps+19Nb/V4j2zOHMBTz/dXb6RX891LMNHIdNbzqocKaH8nA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iJD1gK1c; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2460606A32D; Fri, 4 Dec 2026 16:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iJD1gK1c Received: by smtp.kernel.org (Postfix) with ESMTPSA id E28DB1F000CE; Fri, 4 Dec 2026 16:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796401660; bh=2LMkYRTeqw34yFVH5rmu3fod1f0Y7ynxU6iL2gWVyCg=; h=From:To:Cc:Subject:Date; b=iJD1gK1cyjVTP99/t65IkSxk8dRhfSko2xbTSAk93edhJOfmQ0jPixsHcEFHXjsn/ IHKZ0O2rtF9LX4TDZ3dpYUaulyQqN4VkstWU0yXCebIOuJN7o9AKplSXJ0VSn1mqKu 1F3S5Y3ryzaxs5iKB0Nty4qvPoEz2leJrPyb5mRBb+uj/pePc6jYjzbQslJe5d7T8c wcJ5zsJarMWcwPZQpYFVCnZHXlbwmGCb0Ev7QHzWLJH0UbqqWMkbAuTdwSE2Mt2zaf 1stnjpDZUKKZxSetYmYanR9SA3RS44AqtcZSbOe3jiaV0ULICvWs1c5E4VraTDI7lg qUdQ3v84MCehA== From: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Nikolay Aleksandrov , Andrew Lunn , Ilias Apalodimas , Magnus Karlsson , Maciej Fijalkowski , Donald Hunter , Alexander Duyck , Saeed Mahameed , Tariq Toukan , Mark Bloch , Leon Romanovsky , Shuah Khan , Jonathan Corbet , netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Simon Horman , Stanislav Fomichev , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , David Wei , Tao Cui , linux-kernel@vger.kernel.org, kernel-team@meta.com, "Mike Marciniszyn (Meta)" , linux-rdma@vger.kernel.org, linux-kselftest@vger.kernel.org, Shuah Khan , Randy Dunlap , linux-doc@vger.kernel.org Subject: [PATCH net-next v2 00/15] xsk: Return UMEM chunks explicitly Date: Fri, 4 Dec 2026 17:27:05 +0100 Message-ID: <20261204162723.755897-1-bjorn@kernel.org> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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@kernel.org/; - "eth: fbnic: Support XDP redirect", https://lore.kernel.org/netdev/20261203180924.3862144-1-bjorn@kernel.org/; - "net/mlx5e: Report a down device as -ENETDOWN to queue restarts", https://lore.kernel.org/netdev/20261201113925.1245805-1-bjorn@kernel.org/; - "ethtool: Allow the channel count that a memory provider needs", https://lore.kernel.org/netdev/20261201115458.1254880-1-bjorn@kernel.org/; - "bpf: Use the checked TCP header length in the syncookie helpers", https://lore.kernel.org/netdev/20261201091755.1130605-1-bjorn@kernel.org/. v1: https://lore.kernel.org/netdev/20261124112707.118678-1-bjorn@kernel.org/ 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