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, Mina Almasry <almasrymina@google.com>,
	"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,
	Stuart Clark <stuclar@meta.com>
Subject: Re: [PATCH net-next v1 03/11] xdp: Copy buffers with restricted lifetime
Date: Wed, 11 Nov 2026 05:27:51 -0800	[thread overview]
Message-ID: <87eccra46g.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <avOZa6jLnmvYkk2H@devvm16445.scu0.facebook.com>

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

> On 11/10, Björn Töpel wrote:

>> diff --git a/include/net/xdp.h b/include/net/xdp.h
>> index 07231adfb5f8..1105bb9e3292 100644
>> --- a/include/net/xdp.h
>> +++ b/include/net/xdp.h
>> @@ -81,6 +81,16 @@ enum xdp_buff_flags {
>>  	 * XDP program is not attached.
>>  	 */
>>  	XDP_FLAGS_FRAGS_UNREADABLE	= BIT(2),
>> +	/* Internal: the head netmem and the shared info are in &xdp_buff.ext.
>> +	 * Not copied to xdp_frames or skbs.
>> +	 */
>> +	XDP_FLAGS_EXT			= BIT(3),
>> +};
>> +
>> +/* For a head buffer that cannot hold kernel data, see xdp_init_buff_netmem() */
>> +struct xdp_buff_ext {
>> +	netmem_ref netmem;
>
> nit: netmem -> head ? and the same for xdp_init_buff_netmem netmem arg?

Yup, will fix.

>> @@ -138,7 +153,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_EXT;
>
> The only consumer is xdp_update_skb_frags_info, so probably not worth
> filtering out XDP_FLAGS_EXT here? Or is it for
> xdp_update_frame_from_buff? Can we explicitly clear it at the caller? 

It was for xdp_update_frame_from_buff(), but looking closer EXT never
gets there...

I'll drop the mask. Thanks!

>> diff --git a/net/core/devmem.c b/net/core/devmem.c
>> index 8f190b574beb..dea4a4a17e86 100644
>> --- a/net/core/devmem.c
>> +++ b/net/core/devmem.c
>> @@ -698,5 +698,5 @@ static const struct memory_provider_ops dmabuf_devmem_ops = {
>>  	.release_netmem		= mp_dmabuf_devmem_release_page,
>>  	.nl_fill		= mp_dmabuf_devmem_nl_fill,
>>  	.uninstall		= mp_dmabuf_devmem_uninstall,
>> -	.caps			= MP_CAP_FRAG,
>> +	.caps			= MP_CAP_FRAG | MP_CAP_RETAIN,
>
> Not sure I understand this part, can you explain?
> These are MP_CAP_RETAIN because they are unreadable?

No, RETAIN is about lifetime: the stack may hold page pool references
after the RX poll, e.g. skbs on a TCP receive queue. That's how devmem
and zcrx work; without it the stack would try to copy them, and they'd
trip the DEBUG_NET check in skb_add_rx_frag_netmem().

A provider without RETAIN gets copied, so it must be readable. I'll try
to make that more clear in the kdoc, and probably refuse a provider that
is neither.

>> diff --git a/net/core/xdp.c b/net/core/xdp.c
>> index 1d679e8fd649..0cf46d492d91 100644
>> --- a/net/core/xdp.c
>> +++ b/net/core/xdp.c
>> @@ -23,6 +23,8 @@
>>  #include <trace/events/xdp.h>
>>  #include <net/xdp_sock_drv.h>
>>  
>> +#include "dev.h"
>> +
>>  #define REG_STATE_NEW		0x0
>>  #define REG_STATE_REGISTERED	0x1
>>  #define REG_STATE_UNREGISTERED	0x2
>> @@ -559,10 +561,41 @@ void xdp_return_buff(struct xdp_buff *xdp)
>>  			     xdp->rxq->mem.type, true, xdp);
>>  
>>  out:
>> -	__xdp_return(virt_to_netmem(xdp->data), xdp->rxq->mem.type, true, xdp);
>> +	__xdp_return(xdp_buff_head_netmem(xdp), xdp->rxq->mem.type, true, xdp);
>>  }
>>  EXPORT_SYMBOL_GPL(xdp_return_buff);
>>  
>> +bool __xdp_buff_needs_copy(const struct xdp_buff *xdp)
>> +{
>> +	const struct skb_shared_info *sinfo;
>> +	u32 i;
>> +
>> +	/* Provider buffers come only from page pool queues */
>> +	if (xdp->rxq->mem.type != MEM_TYPE_PAGE_POOL)
>> +		return false;
>> +	if (!netmem_can_retain(xdp_buff_head_netmem(xdp)))
>> +		return true;
>> +	if (likely(!xdp_buff_has_frags(xdp)))
>> +		return false;
>> +
>> +	sinfo = xdp_get_shared_info_from_buff(xdp);
>> +	for (i = 0; i < sinfo->nr_frags; i++) {
>> +		if (!netmem_can_retain(skb_frag_netmem(&sinfo->frags[i])))
>> +			return true;
>
> Do we want/need to go that deep? Can we have a skb-like assumptions that
> mixing retain and non-retain in the same shinfo is not allowed?

Yep, let's make that the rule. I'll remove the deep checks.


Björn

  reply	other threads:[~2026-11-11 13:27 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 10:20 [PATCH net-next v1 00/11] xsk: Zero copy through page-pool memory providers Björn Töpel
2026-11-10 10:20 ` [PATCH net-next v1 01/11] net: Get skb fragment addresses through netmem Björn Töpel
2026-11-10 10:20 ` [PATCH net-next v1 02/11] net: Add memory provider capabilities Björn Töpel
2026-11-10 22:19   ` Stanislav Fomichev
2026-11-11 12:41     ` Björn Töpel
2026-11-10 10:20 ` [PATCH net-next v1 03/11] xdp: Copy buffers with restricted lifetime Björn Töpel
2026-11-10 22:32   ` Stanislav Fomichev
2026-11-11 13:27     ` Björn Töpel [this message]
2026-11-10 10:20 ` [PATCH net-next v1 04/11] xsk: Allocate UMEM chunks through page_pool Björn Töpel
2026-11-10 15:08   ` Magnus Karlsson
2026-11-11 13:51     ` Björn Töpel
2026-11-10 23:02   ` Stanislav Fomichev
2026-11-11 13:59     ` Björn Töpel
2026-11-10 10:20 ` [PATCH net-next v1 05/11] xsk: Install UMEM page pool providers in the core Björn Töpel
2026-11-10 23:50   ` Stanislav Fomichev
2026-11-11 14:01     ` Björn Töpel
2026-11-11  8:59   ` Magnus Karlsson
2026-11-10 10:20 ` [PATCH net-next v1 06/11] page_pool: Coordinate refill with memory providers Björn Töpel
2026-11-10 23:51   ` Stanislav Fomichev
2026-11-10 10:20 ` [PATCH net-next v1 07/11] xsk: Deliver provider chunks without copying Björn Töpel
2026-11-10 10:20 ` [PATCH net-next v1 08/11] eth: fbnic: Support XDP redirect Björn Töpel
2026-11-10 10:20 ` [PATCH net-next v1 09/11] eth: fbnic: Use netmem for RX headers and XDP_TX Björn Töpel
2026-11-10 10:20 ` [PATCH net-next v1 10/11] eth: fbnic: Support RX buffers it cannot split Björn Töpel
2026-11-10 10:20 ` [PATCH net-next v1 11/11] eth: fbnic: Support AF_XDP 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=87eccra46g.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=stuclar@meta.com \
    --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®