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 02/15] xdp: Keep the shared info of a buffer in kernel memory
Date: Wed, 25 Nov 2026 16:17:25 +0100 [thread overview]
Message-ID: <awb8BX2lbZ4sotpQ@boxer> (raw)
In-Reply-To: <20261124125654.183091-2-bjorn@kernel.org>
On Tue, Nov 24, 2026 at 01:56:37PM +0100, Björn Töpel wrote:
> Currently, the shared info of an XDP buffer, with the fragment list of
> a multi-buffer packet, lives at the end of the buffer's frame, in
> memory that the device writes. Helpers follow its fragments, drivers
> free them through it, and frame and skb conversion copy it, so memory
> that others may write while the kernel uses it must not hold it.
> Classic AF_XDP zero copy keeps it in the tail of a UMEM chunk, where
> userspace can rewrite it.
>
> Let an RX queue keep the shared info of its buffers in kernel memory.
> The queue gets one from xdp_rxq_info_reg_ext_sinfo(), and
> xdp_rxq_info_unreg_mem_model() frees it. A buffer with the new
> XDP_FLAGS_SINFO_EXT finds its shared info there.
>
> Whoever prepares a buffer sets the flag before adding fragments. The
> queue NAPI builds one buffer at a time, so one shared info per queue
> is enough. It is valid until the buffer is redirected, dropped or
> copied. Frame conversion and skb construction refuse buffers with the
> flag, as a frame or an skb would keep its shared info in the buffer.
> Nothing sets the flag until later in this series.
>
> xdp_data_hard_end() reserves no shared-info tailroom for such a
> buffer, so its data may reach the end of the frame. frame_sz then
> bounds every write past the data, such as tail growth and
> bpf_xdp_pull_data(), so the frame must not cover memory of other
> buffers. Drivers may then pack such buffers tighter.
>
> Signed-off-by: Björn Töpel <bjorn@kernel.org>
> ---
> include/net/xdp.h | 41 +++++++++++++++++++++++++++++++++++------
> net/core/xdp.c | 30 ++++++++++++++++++++++++++++++
> 2 files changed, 65 insertions(+), 6 deletions(-)
couldn't this effort be sent separately and address classic zc as well?
>
> diff --git a/include/net/xdp.h b/include/net/xdp.h
> index 1629e347b71f..944418111a86 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h
> @@ -65,6 +65,11 @@ struct xdp_rxq_info {
> u32 reg_state;
> struct xdp_mem_info mem;
> u32 frag_size;
> + /* Shared info of buffers with %XDP_FLAGS_SINFO_EXT, in kernel
> + * memory, see xdp_rxq_info_reg_ext_sinfo(). The queue builds one
> + * such buffer at a time.
> + */
> + struct skb_shared_info *ext_sinfo;
> } ____cacheline_aligned; /* perf critical, avoid false-sharing */
>
> struct xdp_txq_info {
> @@ -81,6 +86,15 @@ enum xdp_buff_flags {
> * XDP program is not attached.
> */
> XDP_FLAGS_FRAGS_UNREADABLE = BIT(2),
> + /* The shared info lives in &xdp_rxq_info.ext_sinfo, in kernel memory,
> + * not at the end of the frame. For memory that someone outside the
> + * kernel may write. Whoever prepares the buffer sets it before adding
> + * fragments, on a queue that has ext_sinfo. The queue NAPI builds one
> + * such buffer at a time: its shared info is valid until the buffer
> + * is redirected, dropped or copied. The data may reach the end of the
> + * frame, see xdp_data_hard_end(): the frame must hold nothing else.
> + */
> + XDP_FLAGS_SINFO_EXT = BIT(3),
> };
>
> struct xdp_buff {
> @@ -212,17 +226,27 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
>
> /* Reserve memory area at end-of data area.
> *
> - * This macro reserves tailroom in the XDP buffer by limiting the
> - * XDP/BPF data access to data_hard_end. Notice same area (and size)
> - * is used for XDP_PASS, when constructing the SKB via build_skb().
> + * This reserves tailroom in the XDP buffer by limiting the XDP/BPF data
> + * access to data_hard_end. Notice same area (and size) is used for
> + * XDP_PASS, when constructing the SKB via build_skb(). Buffers with
> + * %XDP_FLAGS_SINFO_EXT keep the shared info elsewhere and reserve none.
> */
> -#define xdp_data_hard_end(xdp) \
> - ((xdp)->data_hard_start + (xdp)->frame_sz - \
> - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
> +static __always_inline void *xdp_data_hard_end(const struct xdp_buff *xdp)
> +{
> + u32 tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> +
> + if (xdp->flags & XDP_FLAGS_SINFO_EXT)
> + tailroom = 0;
> + return xdp->data_hard_start + xdp->frame_sz - tailroom;
> +}
>
> static inline struct skb_shared_info *
> xdp_get_shared_info_from_buff(const struct xdp_buff *xdp)
> {
> + /* Kernel structures stay out of memory that userspace may write */
> + if (unlikely(xdp->flags & XDP_FLAGS_SINFO_EXT))
> + return xdp->rxq->ext_sinfo;
> +
> return (struct skb_shared_info *)xdp_data_hard_end(xdp);
> }
>
> @@ -454,6 +478,10 @@ int xdp_update_frame_from_buff(const struct xdp_buff *xdp,
> return -ENOSPC;
> }
>
> + /* A frame keeps its shared info in the buffer */
> + if (unlikely(xdp->flags & XDP_FLAGS_SINFO_EXT))
> + return -EFAULT;
> +
> xdp_frame->data = xdp->data;
> xdp_frame->len = xdp->data_end - xdp->data;
> xdp_frame->headroom = headroom - sizeof(*xdp_frame);
> @@ -533,6 +561,7 @@ bool xdp_rxq_info_is_reg(struct xdp_rxq_info *xdp_rxq);
> int xdp_rxq_info_reg_mem_model(struct xdp_rxq_info *xdp_rxq,
> enum xdp_mem_type type, void *allocator);
> void xdp_rxq_info_unreg_mem_model(struct xdp_rxq_info *xdp_rxq);
> +int xdp_rxq_info_reg_ext_sinfo(struct xdp_rxq_info *xdp_rxq);
> int xdp_reg_mem_model(struct xdp_mem_info *mem,
> enum xdp_mem_type type, void *allocator);
> void xdp_unreg_mem_model(struct xdp_mem_info *mem);
> diff --git a/net/core/xdp.c b/net/core/xdp.c
> index 1d679e8fd649..3472b03ee661 100644
> --- a/net/core/xdp.c
> +++ b/net/core/xdp.c
> @@ -142,6 +142,8 @@ void xdp_rxq_info_unreg_mem_model(struct xdp_rxq_info *xdp_rxq)
> }
>
> xdp_unreg_mem_model(&xdp_rxq->mem);
> + kfree(xdp_rxq->ext_sinfo);
> + xdp_rxq->ext_sinfo = NULL;
> }
> EXPORT_SYMBOL_GPL(xdp_rxq_info_unreg_mem_model);
>
> @@ -368,6 +370,30 @@ int xdp_rxq_info_reg_mem_model(struct xdp_rxq_info *xdp_rxq,
>
> EXPORT_SYMBOL_GPL(xdp_rxq_info_reg_mem_model);
>
> +/**
> + * xdp_rxq_info_reg_ext_sinfo - keep the shared info of buffers in the queue
> + * @xdp_rxq: registered RX queue
> + *
> + * For buffers in memory that someone outside the kernel may write: those
> + * with %XDP_FLAGS_SINFO_EXT keep their shared info in kernel memory of
> + * @xdp_rxq instead of at the end of their frame.
> + * xdp_rxq_info_unreg_mem_model() frees it.
> + *
> + * Return: 0 on success, or a negative errno.
> + */
> +int xdp_rxq_info_reg_ext_sinfo(struct xdp_rxq_info *xdp_rxq)
> +{
> + if (xdp_rxq->reg_state != REG_STATE_REGISTERED) {
> + WARN(1, "Missing register, driver bug");
> + return -EFAULT;
> + }
> +
> + if (!xdp_rxq->ext_sinfo)
> + xdp_rxq->ext_sinfo = kzalloc_obj(*xdp_rxq->ext_sinfo);
> + return xdp_rxq->ext_sinfo ? 0 : -ENOMEM;
> +}
> +EXPORT_SYMBOL_GPL(xdp_rxq_info_reg_ext_sinfo);
> +
> /**
> * xdp_reg_page_pool - register &page_pool as a memory provider for XDP
> * @pool: &page_pool to register
> @@ -638,6 +664,10 @@ struct sk_buff *xdp_build_skb_from_buff(const struct xdp_buff *xdp)
> u32 nr_frags = 0;
> int metalen;
>
> + /* An skb keeps its shared info in the buffer */
> + if (unlikely(xdp->flags & XDP_FLAGS_SINFO_EXT))
> + return NULL;
> +
> if (unlikely(xdp_buff_has_frags(xdp))) {
> sinfo = xdp_get_shared_info_from_buff(xdp);
> nr_frags = sinfo->nr_frags;
> --
> 2.56.1
>
next prev parent reply other threads:[~2026-11-25 15:38 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 [this message]
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
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=awb8BX2lbZ4sotpQ@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
all inboxes | Powered by JetHome®