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 08/15] xsk: Receive in the device's buffer layout
Date: Mon, 30 Nov 2026 15:47:14 +0100	[thread overview]
Message-ID: <aw2Mct5zt+68akXR@boxer> (raw)
In-Reply-To: <20261124125654.183091-8-bjorn@kernel.org>

On Tue, Nov 24, 2026 at 01:56:43PM +0100, Björn Töpel wrote:
> Currently, userspace cannot use the device's buffer layout of the
> previous two patches.
> 
> Accept XDP_UMEM_DRV_LAYOUT at UMEM registration, with aligned
> page-sized chunks and no headroom, and install the provider when a
> socket with such a UMEM binds to a queue.
> 
> A queue in the device's buffer layout has one receiving socket, the
> first that binds with an RX ring. Another socket with an RX ring gets
> -EBUSY, also after the receiving socket went, as nothing would fill
> its RX ring. Sockets that share the UMEM may transmit in copy mode.
> The provider goes when the receiving socket closes, not with the last
> socket of the pool, so that the program can be detached right after.
> The UMEM has no copy mode, so a bind with XDP_COPY fails, and a bind
> that cannot install the provider fails instead of falling back.
> 
> recvmsg() and poll() wake the queue NAPI when the RX need_wakeup flag
> asks for it, as they wake the driver for zero copy. A wakeup that
> races with unbind finds no queue, and recvmsg() returns -ENETDOWN. The
> queue NAPI changes the need_wakeup flags while sendmsg(), recvmsg()
> and poll() read them without a lock, so mark those accesses, and let
> poll() read the flags once.
> 
> Signed-off-by: Björn Töpel <bjorn@kernel.org>

minor comments

> ---
>  net/xdp/xdp_umem.c |  5 +++
>  net/xdp/xsk.c      | 82 +++++++++++++++++++++++++++++++++++++++-------
>  net/xdp/xsk_sink.c | 25 ++++++++++++--
>  net/xdp/xsk_sink.h |  1 +
>  4 files changed, 98 insertions(+), 15 deletions(-)
> 
> diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
> index cd8643360eb3..5989e5e0e17e 100644
> --- a/net/xdp/xdp_umem.c
> +++ b/net/xdp/xdp_umem.c
> @@ -153,6 +153,7 @@ static int xdp_umem_account_pages(struct xdp_umem *umem)
>  		XDP_UMEM_UNALIGNED_CHUNK_FLAG | \
>  		XDP_UMEM_TX_SW_CSUM | \
>  		XDP_UMEM_TX_METADATA_LEN | \
> +		XDP_UMEM_DRV_LAYOUT | \
>  	0)
>  
>  static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
> @@ -207,6 +208,10 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
>  		       SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) - 128)
>  		return -EINVAL;
>  
> +	if (mr->flags & XDP_UMEM_DRV_LAYOUT &&
> +	    (unaligned_chunks || chunk_size != PAGE_SIZE || headroom))
> +		return -EINVAL;
> +
>  	if (mr->flags & XDP_UMEM_TX_METADATA_LEN) {
>  		if (mr->tx_metadata_len >= 256 || mr->tx_metadata_len % 8)
>  			return -EINVAL;
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 0753fac8d4a8..c015894a6ccb 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -55,7 +55,8 @@ void xsk_set_rx_need_wakeup(struct xsk_buff_pool *pool)
>  		return;
>  
>  	pool->fq->ring->flags |= XDP_RING_NEED_WAKEUP;
> -	pool->cached_need_wakeup |= XDP_WAKEUP_RX;
> +	WRITE_ONCE(pool->cached_need_wakeup,
> +		   pool->cached_need_wakeup | XDP_WAKEUP_RX);

could the ONCE'ing around need_wakeup be sent separately out of the set maybe?

>  }
>  EXPORT_SYMBOL(xsk_set_rx_need_wakeup);
>  
> @@ -72,7 +73,8 @@ void xsk_set_tx_need_wakeup(struct xsk_buff_pool *pool)
>  	}
>  	rcu_read_unlock();
>  
> -	pool->cached_need_wakeup |= XDP_WAKEUP_TX;
> +	WRITE_ONCE(pool->cached_need_wakeup,
> +		   pool->cached_need_wakeup | XDP_WAKEUP_TX);
>  }
>  EXPORT_SYMBOL(xsk_set_tx_need_wakeup);
>  
> @@ -82,7 +84,8 @@ void xsk_clear_rx_need_wakeup(struct xsk_buff_pool *pool)
>  		return;
>  
>  	pool->fq->ring->flags &= ~XDP_RING_NEED_WAKEUP;
> -	pool->cached_need_wakeup &= ~XDP_WAKEUP_RX;
> +	WRITE_ONCE(pool->cached_need_wakeup,
> +		   pool->cached_need_wakeup & ~XDP_WAKEUP_RX);
>  }
>  EXPORT_SYMBOL(xsk_clear_rx_need_wakeup);
>  
> @@ -99,7 +102,8 @@ void xsk_clear_tx_need_wakeup(struct xsk_buff_pool *pool)
>  	}
>  	rcu_read_unlock();
>  
> -	pool->cached_need_wakeup &= ~XDP_WAKEUP_TX;
> +	WRITE_ONCE(pool->cached_need_wakeup,
> +		   pool->cached_need_wakeup & ~XDP_WAKEUP_TX);
>  }
>  EXPORT_SYMBOL(xsk_clear_tx_need_wakeup);
>  
> @@ -817,9 +821,16 @@ u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, u32 nb_pkts)
>  }
>  EXPORT_SYMBOL(xsk_tx_peek_release_desc_batch);
>  
> +/* Context: RCU read side, see xsk_sink_unbind() for a sink */
>  static int xsk_wakeup(struct xdp_sock *xs, u8 flags)
>  {
>  	struct net_device *dev = xs->dev;
> +	struct xsk_sink *sink;
> +
> +	if (xsk_drv_layout(xs)) {
> +		sink = READ_ONCE(xs->pool->sink);
> +		return sink ? xsk_sink_wakeup(sink) : -ENETDOWN;

nahh. return xsk_sink_wakeup() is enough.

> +	}
>  
>  	return dev->netdev_ops->ndo_xsk_wakeup(dev, xs->queue_id, flags);
>  }
> @@ -1418,7 +1429,7 @@ static int __xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len
>  		return 0;
>  
>  	pool = xs->pool;
> -	if (pool->cached_need_wakeup & XDP_WAKEUP_TX) {
> +	if (READ_ONCE(pool->cached_need_wakeup) & XDP_WAKEUP_TX) {
>  		if (xs->zc)
>  			return xsk_wakeup(xs, XDP_WAKEUP_TX);
>  		return xsk_generic_xmit(sk);
> @@ -1458,7 +1469,9 @@ static int __xsk_recvmsg(struct socket *sock, struct msghdr *m, size_t len, int
>  	if (xsk_no_wakeup(sk))
>  		return 0;
>  
> -	if (xs->pool->cached_need_wakeup & XDP_WAKEUP_RX && xs->zc)
> +	/* A sink socket receives without driver zero copy */
> +	if (READ_ONCE(xs->pool->cached_need_wakeup) & XDP_WAKEUP_RX &&
> +	    (xs->zc || xsk_drv_layout(xs)))
>  		return xsk_wakeup(xs, XDP_WAKEUP_RX);
>  	return 0;
>  }
> @@ -1481,6 +1494,7 @@ static __poll_t xsk_poll(struct file *file, struct socket *sock,
>  	struct sock *sk = sock->sk;
>  	struct xdp_sock *xs = xdp_sk(sk);
>  	struct xsk_buff_pool *pool;
> +	u8 need_wakeup;
>  
>  	sock_poll_wait(file, sock, wait);
>  
> @@ -1489,13 +1503,19 @@ static __poll_t xsk_poll(struct file *file, struct socket *sock,
>  		goto out;
>  
>  	pool = xs->pool;
> +	/* Drivers change it from their NAPI */
> +	need_wakeup = READ_ONCE(pool->cached_need_wakeup);
>  
> -	if (pool->cached_need_wakeup) {
> -		if (xs->zc)
> -			xsk_wakeup(xs, pool->cached_need_wakeup);
> -		else if (xs->tx)
> -			/* Poll needs to drive Tx also in copy mode */
> -			xsk_generic_xmit(sk);
> +	if (need_wakeup) {

code flattening maybe?

	if (!need_wakeup)
		goto or_masks;
	
	if (xs->zc) {
		...
	else {
		...
	}

or_masks:
	if (xs->rx && !xskq_prod_is_empty(xs->rx))

> +		if (xs->zc) {
> +			xsk_wakeup(xs, need_wakeup);
> +		} else {
> +			if (xsk_drv_layout(xs) && need_wakeup & XDP_WAKEUP_RX)
> +				xsk_wakeup(xs, XDP_WAKEUP_RX);
> +			if (xs->tx)
> +				/* Poll needs to drive Tx also in copy mode */
> +				xsk_generic_xmit(sk);
> +		}
>  	}
>  
>  	if (xs->rx && !xskq_prod_is_empty(xs->rx))
> @@ -1585,6 +1605,29 @@ static void xsk_delete_from_maps(struct xdp_sock *xs)
>  	}

  parent reply	other threads:[~2026-11-30 14:47 UTC|newest]

Thread overview: 46+ 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-25 19:34     ` Björn Töpel
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 19:39     ` Björn Töpel
2026-11-25 15:17   ` Maciej Fijalkowski
2026-11-25 19:36     ` Björn Töpel
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-25 19:43     ` Björn Töpel
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-25 19:45     ` Björn Töpel
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 19:55     ` Björn Töpel
2026-11-25 15:22   ` Maciej Fijalkowski
2026-11-25 15:28     ` Maciej Fijalkowski
2026-11-25 19:50     ` Björn Töpel
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-25 20:02     ` Björn Töpel
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-25 20:11     ` Björn Töpel
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-25 20:16     ` Björn Töpel
2026-11-30 14:47   ` Maciej Fijalkowski [this message]
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-25 20:26     ` Björn Töpel
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-25 20:33     ` Björn Töpel
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=aw2Mct5zt+68akXR@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