Article View: linux.kernel.netdev
Article #21777[PATCH net-next 15/15] Documentation: networking: Describe AF_XDP RX in the device's layout
From: Björn Töpel
Date: Tue, 24 Nov 2026 12:56
Date: Tue, 24 Nov 2026 12:56
148 lines
15681 bytes
15681 bytes
For applications, XDP_UMEM_DRV_LAYOUT changes who owns a chunk and when, what the XDP program may read and write, which verdicts it may return, and how chunks come back. None of it is documented yet. Describe for application writers the setup and its errors, the program, receiving and giving chunks back, need_wakeup, devices that need DMA syncs, and how TX shares the chunks. Signed-off-by: Björn Töpel <bjorn@kernel.org> --- Documentation/networking/af_xdp.rst | 114 +++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/Documentation/networking/af_xdp.rst b/Documentation/networking/af_xdp.rst index 538e71adb759..4e37a6074a52 100644 --- a/Documentation/networking/af_xdp.rst +++ b/Documentation/networking/af_xdp.rst @@ -429,7 +429,9 @@ There is also an option to set the headroom of each single buffer in the UMEM. If you set this to N bytes, it means that the packet will start N bytes into the buffer leaving the first N bytes for the application to use. The final option is the flags field, but it will -be dealt with in separate sections for each UMEM flag. +be dealt with in separate sections for each UMEM flag. With the +XDP_UMEM_DRV_LAYOUT flag, chunks are pages that the device fills in +its own layout, see the "Device Buffer Layout" section. SO_BINDTODEVICE setsockopt -------------------------- @@ -761,6 +763,116 @@ processing. Note that the Tx batch API guarantees that it will provide a batch of Tx descriptors that ends with full packet at the end. This to facilitate extending a zero-copy driver with multi-buffer support. +Device Buffer Layout +==================== + +In zero-copy mode, the driver fills one UMEM frame per buffer, at the +UMEM headroom, and needs a receive path of its own for AF_XDP. With +the XDP_UMEM_DRV_LAYOUT UMEM flag, the device places buffers in UMEM +chunks as it places them in the pages of its page pool: several +buffers may share a chunk, a packet may span chunks, and the device +picks the offsets. The XDP program reads and writes packets in place, +in the UMEM, but the kernel stores none of its own structures in the +chunks. + +The UMEM backs the page pools of the bound queue through a memory +provider, so the driver needs no AF_XDP code. A driver supports the +mode if it runs native XDP with XDP_REDIRECT, takes its receive +buffers from a page pool of netmem that allows such providers, and +can restart a queue. + +Setting up +---------- + +* Register the UMEM with XDP_UMEM_DRV_LAYOUT, aligned chunks of + PAGE_SIZE, and no headroom. The UMEM must hold more chunks than the + queue keeps posted to the device and in its page pool cache, 128 + chunks with 4K pages, or the bind fails with ENOSPC. The first + number depends on the driver, the ring size and the MTU. + +* Attach a native XDP program to the device itself through netlink, + not through a BPF link or an upper device such as a bond, before the + bind. The bind fails with ENOENT without one. The program cannot be + detached while the UMEM backs the queue (EBUSY). + +* Put chunks on the FILL ring before the bind. The bind starts the + queue with the chunks it finds there, and the queue drops packets + while it has none. + +* Bind with XDP_USE_NEED_WAKEUP, as only a wakeup restarts a queue + that used up the FILL ring, and with XDP_USE_SG to receive packets + that span chunks. A bind without XDP_USE_NEED_WAKEUP fails with + EINVAL. XDP_COPY fails with EOPNOTSUPP, as does a device + without native XDP_REDIRECT or queue management. One socket per + queue receives: a second socket with an RX ring gets EBUSY, and so + does any socket with an RX ring once the receiving socket is gone. + Sockets that share the UMEM with XDP_SHARED_UMEM may transmit. + +The XDP program +--------------- + +The program works on the packet in place, in the UMEM: direct packet +access, bpf_xdp_load_bytes(), bpf_xdp_store_bytes(), dynptrs, +bpf_xdp_adjust_head(), bpf_xdp_adjust_tail(), bpf_xdp_adjust_meta() +and the RX metadata kfuncs work as with pages, on every buffer of the +packet. What the program writes is in the UMEM for the application to +see. The kernel keeps its own data, such as the fragment list of a +packet that spans buffers, in kernel memory, so the application cannot +change what the kernel relies on. The application may still change +the packet at any time, also while the program runs: two reads of the +same bytes may differ. + +Buffers of the bound queue may only go to its receiving socket. Every +verdict but XDP_REDIRECT drops the packet, XDP_PASS included, and +redirects to anything but the receiving socket fail. + +Redirect through an XSKMAP entry that holds the receiving socket. + +Receiving +--------- + +A FILL entry lends a whole chunk to the kernel, by its address. Each +buffer of a packet becomes one RX descriptor that points at the data, +anywhere in a chunk, and XDP_PKT_CONTD chains the buffers of a packet +as described in the multi-buffer section. Metadata that the program +wrote is in front of the first buffer, where the program put it; a +packet whose metadata does not fit in front of its first buffer, in +the same chunk, is dropped. + +The kernel gives a chunk back with XDP_RX_CHUNK_FREE in the options of +an RX descriptor: + +* On a descriptor with data, the flag means that the kernel is done + with the chunk of that descriptor. The application owns the whole + chunk again. + +* A descriptor with length zero, at the address of a chunk, only gives + that chunk back. The kernel posts one when the device let go of the + chunk after its last buffer reached the socket. Such a descriptor is + never part of a packet. + +A chunk may go on the FILL ring again once it came back and the +application is done with all its buffers. The kernel never gives back +single buffers, so a packet that the application holds keeps its +chunk. Chunks whose buffers all stayed in the kernel, as for dropped +packets, stay lent. + +The kernel asks for a wakeup on the FILL ring only while it has run +out of FILL entries; recvmsg() or poll() then restarts the queue. With +preferred busy polling, the application's poll runs the queue's NAPI. + +Devices that need DMA syncs work as they do with page pools: the +kernel syncs a chunk for the device when the FILL ring lends it, and +the driver syncs each buffer for the CPU before the program runs. + +Transmitting +------------ + +Sockets in this mode transmit in copy mode. A buffer that the +application received may go on the TX ring. Its chunk may go on the +FILL ring only once the chunk came back and every TX descriptor that +points into it is on the COMPLETION ring. + Sample application ================== There is a xdpsock benchmarking/test application that can be found at -- 2.56.1
Technical Details
Message-ID:
<20261124125654.183091-15-bjorn@kernel.org>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370362-linux-kernel-netdev=dewy.ruReferences:
<20261124112707.118678-1-bjorn@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370362-linux-kernel-netdev=dewy.ru From: bjorn@kernel.org (Björn Töpel) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next 15/15] Documentation: networking: Describe AF_XDP RX in the device's layout Date: Tue, 24 Nov 2026 13:56:50 +0100 Organization: Usenet Network Message-ID: <20261124125654.183091-15-bjorn@kernel.org> References: <20261124112707.118678-1-bjorn@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="4139179"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:X7ouN0y3dwKZgSqFmxn3HMmf1oQ= sha256:izIRh2kvSaEFDRhRcU4atzQFawPmdPhz8TmiIaDVI+c= sha1:TzkWfhv64SEdzbM/wD8ZD1RY0eg= sha256:T5Lc5sXN9iu4prN7RpEAZUtnxZehae7Lr+QBKGxkr0g= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 7F7E9125E15; Tue, 24 Nov 2026 16:00:22 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TlZqzLbTgdCc; Tue, 24 Nov 2026 16:00:19 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-370362-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 471CC125E0A; Tue, 24 Nov 2026 16:00:10 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 8BCFE60474D; Tue, 24 Nov 2026 13:00:10 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795525209; b=wpFITcoZV4uZLD/lSUzLk/a7p7WznHpNsPEcMO09FWdy40fP5pYSzPEzBzBCk8ODEKO1 cPzeyfdOBaQB5P7O3YkdyNeVf4JU83zxnW2yma5fIrbet0InyPKs9BjqLG9CgSXhPM6XY uPaDkz7OmteNouh26B2UbMp2ivu1LMttXEs2c9ERmlK2Z5IPjgJOPwV7mglqWXv/mxdGx wyZ4iqY4jNczmaJEk/zhE//kd+uZFtUMuGTnjVq5+jqJD/QBFmCnZ3U6M+tQROMlIp5ZS +g/3Nq2oW0flTKCUmQAt/ROn9roglu+XDH0rMm7HospKn/Yv+qhhjjL59Q0+wLSe3MQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795525209; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=71BoVSHnE+GD+Dgl6FXGb+jcMgjjSfPvCEpcdkQChEA=; b=VqdvzM6tWW4Ec0e79SULPfzgdBZZfz8qjV05S61i88bQJOy+9620psgVqesbT5KVGSfv 88gPyG99IseTlxziJGCGKt7dsVq0ivQMJGknxNRTz1zZKTodVQ4yKJ3o/wUbIG4z3vWIo cXVvrdxAGZXfWOuIltHqx1ba9OCjoDltnYAalGiucaoG+8qmz4Ck36gGskBU9voeUS+Wa 2XDin8jLK6NIEyHWBodCtAgVXaa+naatrjcr0ZsjN1QCs5CQE5sAM8E7kLGjLdV+7dM8A W0MinoEa+0TWOK9vQnDTNciUh9bhTiDYMsaNUbCBFlYuvWWnM1nijlJl79KJ80bXyQw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=E86WLCWj; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C5298606A33E; Tue, 24 Nov 2026 13:00:09 +0000 (UTC) X-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=E86WLCWj X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795525204; b=xsd5cjfTxbqp50lPooXiXYlLFJwMbHP5Jv8vhrt2uXvfw+l9K0bc5o4k8alG4LcLeFar 9VmTH/ZkaS8RomDCKn9OIt8OhawSv7qJZI6UqQm1h4W440X2WmW8+d5sHmWOfzVZSwgDc 9eQxwPq1MNFSv1SfXyKOOPG9P5ttihKgBkSsoHdhITMvUFX4X5aev8bkq/alrYfF+t21S +qm2ogZ0gQOx6xXioGpC3IVJXCvx083aXSeA5P2Y9eAjQx6L32jHCnTjdosgktTUEXRK+ DgGUdWB0EpW1I0vVoNdREx49b0jDDz8PbpJM8ybyDhqTE+mhtM4gVDwn6BjuktsQtqw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795525204; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=71BoVSHnE+GD+Dgl6FXGb+jcMgjjSfPvCEpcdkQChEA=; b=HF21hN101rY8uVx+ZGk+DxpY50TADwheJrb+opcEj1Cr6/mUBNWwf632xYmT7ZkIS2Dx I80X4ulEVlsZqN0xscBlV1aWZPIY7SmO1psQ7D1Idful32gD3ZWjXWV56B9BnsweGFBqG lmCxzv62FnF5G1y9kGoqh4hJPtqVotbt1M/7WA6kl/7bdnYijS+RUDWjJfHwRxbOfD8ey SEs+NUnuLhLItjb2vXqw7JoX5Qd6+avZnlfn4x7MmdVDZjziRCFEC0T1rbLG2idy7KkuJ 7LlivEtY+hidPhxO7pT7LzCBsi16eP0pWqclsXN0PW8XO1pDQcnNqe5Bm/w2elwCoEA== X-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=E86WLCWj; arc=none smtp.remote-ip=100.103.45.18 X-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 E0EA8606A322; Tue, 24 Nov 2026 13:00:03 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B07E1F000EB; Tue, 24 Nov 2026 12:59:52 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795525203; bh=71BoVSHnE+GD+Dgl6FXGb+jcMgjjSfPvCEpcdkQChEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=E86WLCWjW/dY4qNrjCcvSgN4bRHl901N+otwhHt70E0TMaHKYQSW5I7hgi+LAGxfq ZxNXgrh4lDpc6FDf/Ynrj5beVp71XcI3kUJbPuyDC4L1kF+VdDMWhEaviqH8TeWdtT ui4VnFe4H8joiI1mUVh/PJymfuXR6hUdk5HyA07d5ojk+4UV+16icOSL07RlUFMNZ0 mx536iKYMFFus57c2465mz+u5d3TSknYeFbxhIdG1UalTGK8RID02MDxV8BE3BBhWD TKo/PI5cNDXZUzeAxaaPYg1+VuMIHiTA9Wvzf9HoyVw45e9tab4/NjtsVR9P9euQQi GyQNqx6hdrYeA== X-Cc: Stuart Clark <stuclar@meta.com>, Björn Töpel <bjorn@kernel.org>, Stanislav Fomichev <sdf@fomichev.me>, Simon Horman <horms@kernel.org>, Martin KaFai Lau <martin.lau@linux.dev>, Mina Almasry <almasrymina@google.com>, Song Liu <song@kernel.org>, Yonghong Song <yonghong.song@linux.dev>, Jiri Olsa <jolsa@kernel.org>, Emil Tsalapatis <emil@etsalapatis.com>, Ihor Solodrai <ihor.solodrai@linux.dev>, Randy Dunlap <rdunlap@infradead.org>, kernel-team@meta.com, Dimitri Daskalakis <dimitri.daskalakis1@gmail.com>, Bobby Eshleman <bobbyeshleman@meta.com>, Mohsin Bashir <mohsin.bashr@gmail.com>, Kees Cook <kees@kernel.org>, Breno Leitao <leitao@debian.org>, Maxime Chevallier <maxime.chevallier@bootlin.com>, Tao Cui <cuitao@kylinos.cn>, Vadim Fedorenko <vadim.fedorenko@linux.dev>, "Mike Marciniszyn (Meta)" <mike.marciniszyn@gmail.com>, Kuniyuki Iwashima <kuniyu@google.com>, Jiayuan Chen <jiayuan.chen@linux.dev>, Martin Karsten <mkarsten@uwaterloo.ca>, Nikolay Aleksandrov <razor@blackwall.org>, David Wei <dw@davidwei.uk>, Pavel Begunkov <asml.silence@gmail.com>, linux-rdma@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: git-send-email 2.56.1 X-In-Reply-To: <20261124112707.118678-1-bjorn@kernel.org> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list