Article View: linux.kernel.netdev
Article #14552Re: [PATCH net-next v1 03/11] xdp: Copy buffers with restricted lifetime
From: Björn Töpel
Date: Wed, 11 Nov 2026 13:27
Date: Wed, 11 Nov 2026 13:27
117 lines
13125 bytes
13125 bytes
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
Technical Details
Message-ID:
<87eccra46g.fsf@all.your.base.are.belong.to.us>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361080-linux-kernel-netdev=dewy.ruReferences:
<20261110102039.1002605-1-bjorn@kernel.org> <20261110102039.1002605-4-bjorn@kernel.org> <avOZa6jLnmvYkk2H@devvm16445.scu0.facebook.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361080-linux-kernel-netdev=dewy.ru From: bjorn@kernel.org (Björn Töpel) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v1 03/11] xdp: Copy buffers with restricted lifetime Date: Wed, 11 Nov 2026 05:27:51 -0800 Organization: Usenet Network Message-ID: <87eccra46g.fsf@all.your.base.are.belong.to.us> References: <20261110102039.1002605-1-bjorn@kernel.org> <20261110102039.1002605-4-bjorn@kernel.org> <avOZa6jLnmvYkk2H@devvm16445.scu0.facebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: usenet.network; logging-data="859971"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:FVK0w1ZPVMrn0JSehwJoUVhMuPo= sha256:8fYuGHRD2XDvF7TeZoCIKVm5Y25gYydWNNF9xy3gLY0= sha1:XM7A2E2y4FMEj1Ol+GlKv+7gG9c= sha256:UHl7FY6cKk5IEobn6y0FyTTgK08dgzyO9F187kHk8MM= 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 400EA113EF8; Wed, 11 Nov 2026 16:28:31 +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 qOJQviZpO76H; Wed, 11 Nov 2026 16:28:27 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-361080-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 22D54113EC4; Wed, 11 Nov 2026 16:28:18 +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 1189A621E30; Wed, 11 Nov 2026 13:28:03 +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=1794403681; b=L0GDoaCJawsJMw7YFW6RBSEQRPFtFol8rkl2u35ZegDoVXHjopw2lzpTbcZx//6p+L0U zt8i437YxnzWs1zblhJFB77C6oMlVnMOzI2KInuHzFT62XfBKewW2KO+wlADT8v+DLU7A c2oDjo4yHE3BeC+MHuGLQje6KnS/QSbwGJntMNchZTxFdJL3qNl1aMizOlCk8nIL2EPYK fl4cFZTYCR3O/OvzcmuNDmJao/zqt5W4NQr+9dCej76895f1xtAMTFnh78F3sPFlGJ87y K4iqdz0Qv0myAqug7LXwRZuXaU/pBtY3S65Ss6kQaPOGktOYFhOF1GI82tvrV+evO2w== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794403681; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: In-Reply-To:References:Date:Message-ID:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=5TobANsfNbQPE7bHGqRUO1+IBRipYYGScGTtUnijg5Y=; b=s/9AZImgoEoITJxR+uewir37M5ArWoZU6bvuNZnrWLbasZxbl9271mzECc6+v1ry+YIG DeXmxzyDfdA4oO3UnJy6cOe+b7Qs248LjZCUaKiDbznn8/PTqp6/YBVSCieLVzrQzIrW5 geuIaCRJhe3dbYMpGRwqzNh4hWk/fPTGEkU51SFg+ydKXJcV/5/RmvezY+ibocnvGmhuK d2Rx+RgBal5DYt6bVuVmX9/Um9bUfwv9RV0z675/xIHDkjiQitMBm/0M6sW3uOrrlSA66 U0DDhkk1al/NeWjLSnEFbj7RQlLLIw6hQQqaij/x4mmJB2IpSl91NjgQax/NsL02eEA== 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=NEdkPhkE; 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 73D75606A331; Wed, 11 Nov 2026 13:28:01 +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=NEdkPhkE 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=1794403675; b=MHUpu2dPnJTpe3pFhfaexDAF/xZgpBk77PH1fNmIepvvkKYhYk4W1dAjDY/mbZly5ov1 TsTtDOfgDvMFQSxjM6+oRQtAlG3o7OVQ/pcCYiISoQK+mfQ1JvpUVCb3ooeyPriqbbE9q iTrcpHEiAv7c6LGKkrOTzqbwTzxWCBoxSExVV8S8gRggA7KaTLjR1CwhNFNG+cJ5FUyyP L0FHsF6s6AnhZWRxC7s3e3sIVuGGX7eL44QU91WHQGos/zhPBA3IDmAevoSGf6X0ORuQZ mPIhjyiEJ45fvzn8TrFX03Bwj557y02FnSZe/eLtN2zfjKci+zaarGqMzhZDr4D7/CA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794403675; h=Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To:References: Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=5TobANsfNbQPE7bHGqRUO1+IBRipYYGScGTtUnijg5Y=; b=t1rdQ2P5X5f+rf1hlU4xu+mWkN4QUQXQH8jftQrpkzpgyLyEZC9BF34PuAyjyRGViA2s OFqhcO+IZ/NjKq0LuUpC57dwyGoaFwMXceSp0dTxJ4tpuajomjvac12mpUHD0wrmeTM4b 7HI2cPPPpxsVYBoEB55+rbl/rV1YFCPVf0N0PVpM50wORljxhEJ48DYg50ttdURIXKhyD WSkjWrQgDnis2nnFRR8oNt0prqdS0iTAHzP3K6gOie1wt4njZ+m+wJPzm3JXD4WQaa9ee wEo5Zu6VLwVPBaB3IprQDS4mBHx+w8lv9y6ePFcw0/qVFWacT/LzJcbt2EE6Z7PxuBQ== 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=NEdkPhkE; 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 8D8E2606A31C; Wed, 11 Nov 2026 13:27:55 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6368F1F00A05; Wed, 11 Nov 2026 13:27:54 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794403675; bh=5TobANsfNbQPE7bHGqRUO1+IBRipYYGScGTtUnijg5Y=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=NEdkPhkEYUeNthxyHswKlC+LjnE3+C8o+r69jP/kWWwPJmNjwUjX+n+MMVxp86fU3 nRjyHg29mW4zKgB9zMfQeSzMvvHdf2fKf94JxaWhgLL2UNMd7ycqXvlqYBgcx4uhXr YNd/LCvK63k37DwGXK6b0TQDBrIGUpyAfYnNWJlIJlGu+t2gyajY4rYAs18sR8WJ/x nMUEA4I988zdXET2E/tBIaZpQ2YcNX39oUAB+DEYSftb5YPfi2iJpdFO8M5uQWpbyh GauZxaMl/9tkIxRUqgCf6TE/U4Jrnhpnix3hcgOcAIFMfnQHTfRsfI3a89cyrPU9+6 LZg4ZR/DaB6zA== X-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> X-In-Reply-To: <avOZa6jLnmvYkk2H@devvm16445.scu0.facebook.com> 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