mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Björn Töpel" <bjorn@kernel.org>
To: Stanislav Fomichev <sdf.kernel@gmail.com>
Cc: Magnus Karlsson <magnus.karlsson@intel.com>,
	Maciej Fijalkowski <maciej.fijalkowski@intel.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Alexander Duyck <alexanderduyck@fb.com>,
	kernel-team@meta.com, Andrew Lunn <andrew+netdev@lunn.ch>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	Pavel Begunkov <asml.silence@gmail.com>,
	Jens Axboe <axboe@kernel.dk>, Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	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>,
	netdev@vger.kernel.org, bpf@vger.kernel.org,
	io-uring@vger.kernel.org,
	"Mike Marciniszyn (Meta)" <mike.marciniszyn@gmail.com>,
	Weiming Shi <bestswngs@gmail.com>,
	Nikolay Aleksandrov <razor@blackwall.org>,
	David Wei <dw@davidwei.uk>,
	Alexander Lobakin <aleksander.lobakin@intel.com>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Mina Almasry <almasrymina@google.com>
Subject: Re: [RFC net-next 06/15] xdp: Track non-page netmem in receive buffers
Date: Mon, 12 Oct 2026 16:12:53 +0200	[thread overview]
Message-ID: <8733ubc8ii.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <asPXa7k-_drxXiI0@devvm7509.cco0.facebook.com>

Stanislav Fomichev <sdf.kernel@gmail.com> writes:

> On 10/02, Björn Töpel wrote:
>> A page-pool memory provider can give net_iov buffers, and
>> virt_to_page() does not work for them. An xdp_buff holds only the
>> data pointer, so code that returns or converts a buffer cannot find
>> its net_iov.
>> 
>> Add NET_IOV_XSK, the net_iov type for AF_XDP. Add the internal flag
>> XDP_FLAGS_HAS_NETMEM. When it is set, the xdp_buff holds a netmem
>> reference in the union with the devmap TX queue, which only devmap
>> egress uses. The flag is cleared when flags are copied to an skb or
>> an xdp_frame. xdp_convert_buff_to_frame() sends such a buffer to the
>> zero-copy copy path.
>> 
>> A fragment from a readable net_iov area no longer marks the buffer's
>> fragments as unreadable. The skb layer still treats every net_iov as
>> unreadable, so such a buffer must be copied before it becomes an
>> skb. Later patches in this series do that.
>> 
>> skb_shared_info holds kernel pointers, so it cannot be in UMEM,
>> which userspace can write. A netmem xdp_buff points to a
>> skb_shared_info that the RX queue keeps in kernel memory instead.
>> xdp_init_buff_from_netmem() sets this up. Page-backed buffers still
>> use their tailroom.
>> 
>> On 64-bit, struct xdp_buff grows from 56 to 64 bytes. struct
>> xdp_buff_xsk stays at 128 bytes on x86-64. Where the largest
>> alignment is 8 bytes, as on s390, it grows from 120 to 128 bytes, so
>> a pool needs 8 more bytes per UMEM chunk. Only helpers that need the
>> netmem or the fragment info test the new flag. Page-backed receive
>> and return paths do not.
>> 
>> Signed-off-by: Björn Töpel <bjorn@kernel.org>
>> ---
>>  include/net/netmem.h |  1 +
>>  include/net/xdp.h    | 56 ++++++++++++++++++++++++++++++++++++++++----
>>  2 files changed, 52 insertions(+), 5 deletions(-)
>> 
>> diff --git a/include/net/netmem.h b/include/net/netmem.h
>> index e6dff0b01581..76e4fe878863 100644
>> --- a/include/net/netmem.h
>> +++ b/include/net/netmem.h
>> @@ -68,6 +68,7 @@ DECLARE_STATIC_KEY_FALSE(page_pool_mem_providers);
>>  enum net_iov_type {
>>  	NET_IOV_DMABUF,
>>  	NET_IOV_IOURING,
>> +	NET_IOV_XSK,
>>  };
>>  
>>  /* A memory descriptor representing abstract networking I/O vectors,
>> diff --git a/include/net/xdp.h b/include/net/xdp.h
>> index 07231adfb5f8..80931490ca3a 100644
>> --- a/include/net/xdp.h
>> +++ b/include/net/xdp.h
>> @@ -11,6 +11,7 @@
>>  #include <linux/netdevice.h>
>>  #include <linux/skbuff.h> /* skb_shared_info */
>>  
>> +#include <net/netmem.h>
>>  #include <net/page_pool/types.h>
>>  
>>  /**
>> @@ -81,6 +82,8 @@ enum xdp_buff_flags {
>>  	 * XDP program is not attached.
>>  	 */
>>  	XDP_FLAGS_FRAGS_UNREADABLE	= BIT(2),
>> +	/* The txq/netmem union contains a receive netmem reference. */
>> +	XDP_FLAGS_HAS_NETMEM		= BIT(3),
>>  };
>>  
>>  struct xdp_buff {
>> @@ -89,7 +92,12 @@ struct xdp_buff {
>>  	void *data_meta;
>>  	void *data_hard_start;
>>  	struct xdp_rxq_info *rxq;
>> -	struct xdp_txq_info *txq;
>> +	union {
>> +		/* Valid for DEVMAP egress programs. */
>> +		struct xdp_txq_info *txq;
>> +		/* Valid for receive buffers backed by non-page netmem. */
>> +		netmem_ref netmem;
>> +	};
>>  
>>  	union {
>>  		struct {
>> @@ -104,6 +112,8 @@ struct xdp_buff {
>>  		u64 frame_sz_flags_init;
>>  #endif
>>  	};
>> +	/* Kernel-owned fragment metadata for non-page netmem. */
>> +	struct skb_shared_info *sinfo;
>>  };
>>  
>>  static __always_inline void xdp_reinit_buff(struct xdp_buff *xdp)
>> @@ -138,7 +148,7 @@ static __always_inline void xdp_buff_set_frag_unreadable(struct xdp_buff *xdp)
>>  
>>  static __always_inline u32 xdp_buff_get_skb_flags(const struct xdp_buff *xdp)
>>  {
>> -	return xdp->flags;
>> +	return xdp->flags & ~XDP_FLAGS_HAS_NETMEM;
>>  }
>>  
>>  static __always_inline void xdp_buff_clear_frag_pfmemalloc(struct xdp_buff *xdp)
>> @@ -150,6 +160,10 @@ static __always_inline void
>>  xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
>>  {
>>  	xdp->rxq = rxq;
>> +	/* Do not initialize the txq/netmem union here. DEVMAP generic XDP
>> +	 * sets txq before this helper is called; receive drivers set netmem
>> +	 * explicitly.
>> +	 */
>>  
>>  #ifdef __LITTLE_ENDIAN
>>  	/*
>> @@ -176,6 +190,33 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
>>  	xdp->data_meta = meta_valid ? data : data + 1;
>>  }
>>  
>> +static __always_inline bool xdp_buff_has_netmem(const struct xdp_buff *xdp)
>> +{
>> +	return !!(xdp->flags & XDP_FLAGS_HAS_NETMEM);
>> +}
>> +
>
> [..]
>
>> +static __always_inline netmem_ref
>> +xdp_buff_get_netmem(const struct xdp_buff *xdp)
>> +{
>> +	if (xdp_buff_has_netmem(xdp))
>> +		return xdp->netmem;
>> +
>> +	return virt_to_netmem(xdp->data);
>> +}
>
> You keep adding methods that are not used in the patch where they are added.
> I keep getting confused :-p
>
> For virt_to_netmem, maybe a meta question: does xsk pool need a treatment
> similar to the socket path? Where we did s/page/netmem_ref/ ? Then might
> be less reasons to special case?

Fair point! I'll move the helpers with their users and see what
netmem_ref can unify. UMEM still needs the saved descriptor for
returning buffers and kernel-owned fragment info...

  reply	other threads:[~2026-10-12 14:12 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02 19:00 [RFC net-next 00/15] xsk: Zero copy through page-pool memory providers Björn Töpel
2026-10-02 19:00 ` [RFC net-next 01/15] xdp: Size zero-copy skb heads by their contents Björn Töpel
2026-10-02 19:00 ` [RFC net-next 02/15] eth: fbnic: Report the logical XDP RX queue Björn Töpel
2026-10-02 19:00 ` [RFC net-next 03/15] net: Add memory provider capabilities Björn Töpel
2026-10-03  4:13   ` Mina Almasry
2026-10-09 14:54     ` Björn Töpel
2026-10-05 16:26   ` Stanislav Fomichev
2026-10-12 13:34     ` Björn Töpel
2026-10-02 19:00 ` [RFC net-next 04/15] net: Let memory providers set RX buffer headroom Björn Töpel
2026-10-05 16:52   ` Stanislav Fomichev
2026-10-12 13:35     ` Björn Töpel
2026-10-02 19:00 ` [RFC net-next 05/15] page_pool: Extend memory provider operations Björn Töpel
2026-10-05 16:51   ` Stanislav Fomichev
2026-10-12 13:53     ` Björn Töpel
2026-10-02 19:00 ` [RFC net-next 06/15] xdp: Track non-page netmem in receive buffers Björn Töpel
2026-10-05 17:01   ` Stanislav Fomichev
2026-10-12 14:12     ` Björn Töpel [this message]
2026-10-02 19:00 ` [RFC net-next 07/15] xsk: Keep the DMA mapping in the buffer pool Björn Töpel
2026-10-02 19:00 ` [RFC net-next 08/15] xsk: Handle a detached FILL ring in RX wakeup Björn Töpel
2026-10-02 19:00 ` [RFC net-next 09/15] xsk: Add a page-pool memory provider for UMEM Björn Töpel
2026-10-05 17:38   ` Stanislav Fomichev
2026-10-12 14:14     ` Björn Töpel
2026-10-02 19:00 ` [RFC net-next 10/15] xsk: Add RX helpers for page-pool drivers Björn Töpel
2026-10-02 19:00 ` [RFC net-next 11/15] xdp: Copy provider buffers on pass and redirect Björn Töpel
2026-10-02 19:00 ` [RFC net-next 12/15] xsk: Receive provider UMEM without copying Björn Töpel
2026-10-02 19:00 ` [RFC net-next 13/15] eth: fbnic: Support AF_XDP zero-copy receive Björn Töpel
2026-10-05 17:51   ` Stanislav Fomichev
2026-10-12 14:16     ` Björn Töpel
2026-10-02 19:00 ` [RFC net-next 14/15] eth: fbnic: Support AF_XDP zero-copy transmit Björn Töpel
2026-10-02 19:00 ` [RFC net-next 15/15] Documentation: xsk: Document page-pool zero copy Björn Töpel

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=8733ubc8ii.fsf@all.your.base.are.belong.to.us \
    --to=bjorn@kernel.org \
    --cc=aleksander.lobakin@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=axboe@kernel.dk \
    --cc=bestswngs@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=corbet@lwn.net \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --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=io-uring@vger.kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=mike.marciniszyn@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.org \
    --cc=rdunlap@infradead.org \
    --cc=sdf.kernel@gmail.com \
    --cc=sdf@fomichev.me \
    --cc=skhan@linuxfoundation.org \
    --cc=song@kernel.org \
    --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

all inboxes | Powered by JetHome®