Netdev List
 help / color / mirror / Atom feed
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: "Björn Töpel" <bjorn@kernel.org>
Cc: Magnus Karlsson <magnus.karlsson@intel.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	"John Fastabend" <john.fastabend@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	"Alexander Duyck" <alexanderduyck@fb.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	"Tariq Toukan" <tariqt@nvidia.com>,
	Mark Bloch <mbloch@nvidia.com>, Leon Romanovsky <leon@kernel.org>,
	Michael Chan <michael.chan@broadcom.com>,
	Pavan Chebbi <pavan.chebbi@broadcom.com>,
	Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org>,
	<bpf@vger.kernel.org>, <netdev@vger.kernel.org>,
	"Stuart Clark" <stuclar@meta.com>,
	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>
Subject: Re: [PATCH net-next 05/15] xdp: Run programs on buffers that must not hold kernel structures
Date: Wed, 25 Nov 2026 16:22:03 +0100	[thread overview]
Message-ID: <awb9GzkXa9Z9LxuP@boxer> (raw)
In-Reply-To: <20261124125654.183091-5-bjorn@kernel.org>

On Tue, Nov 24, 2026 at 01:56:40PM +0100, Björn Töpel wrote:
> Currently, the core refuses native XDP programs next to a memory
> provider. An AF_XDP sink needs XDP to steer its packets and to use the
> RX metadata kfuncs. Its buffers are UMEM chunks that XDP may read
> through the kernel mapping, but that userspace may write at any time,
> also while the kernel reads them. If drivers build XDP buffers on them
> as on pages, the core puts kernel structures into them, such as the
> shared info of a multi-buffer packet, the xdp_frame of XDP_TX and
> redirects, and the skb of XDP_PASS.
> 
> Let programs run on sink buffers as on pages, and keep every kernel
> structure out of them.
> 
> A sink offers an XDP view of its UMEM, so drivers build the buffer as
> for a page, while netmem_address() and skb_frag_address() still give
> NULL for sink net_iovs. Programs and helpers read and write the packet
> in place, fragments included. xdp_prepare_buff() tells a sink head by
> its address, with one range check under a static key, and marks the
> buffer before the driver adds fragments. Other buffers pay nothing
> while no sink is bound.
> 
> A marked buffer keeps its shared info in the queue, with
> XDP_FLAGS_SINFO_EXT, set up when the driver registers a sink page pool
> as its memory model.
> 
> A sink buffer may only go to the AF_XDP socket of its queue. The core
> turns XDP_TX and XDP_PASS into XDP_DROP, so drivers need no checks of
> their own. XDP_ABORTED and invalid verdicts reach the driver, which
> traces them and drops the packet. Frame conversion and skb
> construction refuse sink buffers too, so devmap and cpumap drop them,
> and sink net_iovs never become skb frags, so every net_iov frag stays
> unreadable.
> 
> As userspace may change the bytes meanwhile, the kernel takes bounds
> only from its own fields, and only the program and its helpers read
> the bytes. A helper that reads bytes twice must check a copy.
> 
> Signed-off-by: Björn Töpel <bjorn@kernel.org>
> ---
>  include/net/netmem.h          |  5 ++-
>  include/net/page_pool/types.h |  7 ++--
>  include/net/xdp.h             | 60 +++++++++++++++++++++++++++++++++--
>  net/core/xdp.c                | 46 +++++++++++++++++++++++++--
>  4 files changed, 108 insertions(+), 10 deletions(-)

>  	xdp_frame->data = xdp->data;
> @@ -763,6 +812,11 @@ static __always_inline u32 bpf_prog_run_xdp(const struct bpf_prog *prog,
>  	 */
>  	u32 act = __bpf_prog_run(prog, xdp, BPF_DISPATCHER_FUNC(xdp));
>  
> +	/* Sink buffers go to the AF_XDP socket of their queue, or nowhere */
> +	if (static_branch_unlikely(&xdp_sink_key) && xdp_buff_is_sink(xdp) &&
> +	    (act == XDP_PASS || act == XDP_TX))
> +		act = XDP_DROP;

I think it would be better to follow SEC(xdp.frags) approach and from
verifier POV disallow progs doing anything different than XDP_REDIRECT...?

Here you affect whole system.

Also, I don't follow currently why xdp pass is not allowed, management
traffic gonna be dead on this queue.

> +
>  	if (static_branch_unlikely(&bpf_master_redirect_enabled_key)) {
>  		if (act == XDP_TX && netif_is_bond_slave(xdp->rxq->dev))
>  			act = xdp_master_redirect(xdp);

  parent reply	other threads:[~2026-11-25 15:40 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 11:26 [PATCH net-next 00/15] xsk: Receive in the device's buffer layout Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 01/15] xdp: Let memory providers offer XDP a view of their net_iovs Björn Töpel
2026-11-25 14:07   ` netdev-bot+sashiko
2026-11-24 12:56 ` [PATCH net-next 02/15] xdp: Keep the shared info of a buffer in kernel memory Björn Töpel
2026-11-25 14:07   ` netdev-bot+sashiko
2026-11-25 15:17   ` Maciej Fijalkowski
2026-11-24 12:56 ` [PATCH net-next 03/15] net: Add memory providers that only feed XDP Björn Töpel
2026-11-25 14:08   ` netdev-bot+sashiko
2026-11-24 12:56 ` [PATCH net-next 04/15] page_pool: Let memory providers take back net_iovs Björn Töpel
2026-11-25 14:08   ` netdev-bot+sashiko
2026-11-24 12:56 ` [PATCH net-next 05/15] xdp: Run programs on buffers that must not hold kernel structures Björn Töpel
2026-11-25 14:08   ` netdev-bot+sashiko
2026-11-25 15:22   ` Maciej Fijalkowski [this message]
2026-11-25 15:28     ` Maciej Fijalkowski
2026-11-24 12:56 ` [PATCH net-next 06/15] xsk: Lend UMEM chunks to the page pools of a queue Björn Töpel
2026-11-24 14:34   ` Magnus Karlsson
2026-11-24 15:12     ` Björn Töpel
2026-11-25 14:08   ` netdev-bot+sashiko
2026-11-24 12:56 ` [PATCH net-next 07/15] xsk: Deliver to the socket in the device's buffer layout Björn Töpel
2026-11-25 14:08   ` netdev-bot+sashiko
2026-11-24 12:56 ` [PATCH net-next 08/15] xsk: Receive " Björn Töpel
2026-11-25 14:08   ` netdev-bot+sashiko
2026-11-24 12:56 ` [PATCH net-next 09/15] eth: fbnic: Support XDP redirect Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 10/15] eth: fbnic: Receive into XDP-only memory providers Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 11/15] net: Add netif_rxq_has_xdp_only_mp() Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 12/15] eth: mlx5e: Receive into XDP-only memory providers Björn Töpel
2026-11-25 14:08   ` netdev-bot+sashiko
2026-11-24 12:56 ` [PATCH net-next 13/15] eth: bnxt: " Björn Töpel
2026-11-25 14:08   ` netdev-bot+sashiko
2026-11-24 12:56 ` [PATCH net-next 14/15] selftests: net: xsk: Test the device's RX buffer layout Björn Töpel
2026-11-25 14:08   ` netdev-bot+sashiko
2026-11-24 12:56 ` [PATCH net-next 15/15] Documentation: networking: Describe AF_XDP RX in the device's layout Björn Töpel
2026-11-25 14:08   ` netdev-bot+sashiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awb9GzkXa9Z9LxuP@boxer \
    --to=maciej.fijalkowski@intel.com \
    --cc=alexanderduyck@fb.com \
    --cc=almasrymina@google.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrii@kernel.org \
    --cc=asml.silence@gmail.com \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bobbyeshleman@meta.com \
    --cc=bpf@vger.kernel.org \
    --cc=corbet@lwn.net \
    --cc=cuitao@kylinos.cn \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dimitri.daskalakis1@gmail.com \
    --cc=dw@davidwei.uk \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=emil@etsalapatis.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jiayuan.chen@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kees@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=leitao@debian.org \
    --cc=leon@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=magnus.karlsson@intel.com \
    --cc=martin.lau@linux.dev \
    --cc=maxime.chevallier@bootlin.com \
    --cc=mbloch@nvidia.com \
    --cc=memxor@gmail.com \
    --cc=michael.chan@broadcom.com \
    --cc=mike.marciniszyn@gmail.com \
    --cc=mkarsten@uwaterloo.ca \
    --cc=mohsin.bashr@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pavan.chebbi@broadcom.com \
    --cc=razor@blackwall.org \
    --cc=rdunlap@infradead.org \
    --cc=saeedm@nvidia.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=stuclar@meta.com \
    --cc=tariqt@nvidia.com \
    --cc=vadim.fedorenko@linux.dev \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox