From: "Björn Töpel" <bjorn@kernel.org>
To: Magnus Karlsson <magnus.karlsson@intel.com>,
Maciej Fijalkowski <maciej.fijalkowski@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
Cc: "Stuart Clark" <stuclar@meta.com>,
"Björn Töpel" <bjorn@kernel.org>,
"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: [PATCH net-next 01/15] xdp: Let memory providers offer XDP a view of their net_iovs
Date: Tue, 24 Nov 2026 13:56:36 +0100 [thread overview]
Message-ID: <20261124125654.183091-1-bjorn@kernel.org> (raw)
In-Reply-To: <20261124112707.118678-1-bjorn@kernel.org>
Currently, a net_iov is memory that the kernel does not read.
netmem_address() and skb_frag_address() give NULL for it, and XDP
code, which takes buffer addresses the same way, cannot read it
either. Some providers back net_iovs with memory that the CPU can
reach and XDP must read, such as the UMEM of an AF_XDP socket that
receives in the device's buffer layout, later in this series. io_uring
zcrx could do the same.
Such memory is net_iov and not pages because it is user memory pinned
with GUP. mm owns the struct page fields that page_pool takes over
(lru, where pp_magic and pp live, and mapping), a chunk larger than a
page lies inside a hugetlb folio instead of being a page of its own,
and the provider keeps state per chunk. io_uring zcrx wraps pinned
user pages in net_iovs for the same reasons.
Let a net_iov area offer an XDP view, an address for each of its
net_iovs that XDP code may read and write. Add xdp_netmem_address()
for the head of an XDP buffer and xdp_frag_address() for its
fragments, and use them in bpf_xdp_pointer(), bpf_xdp_copy_buf(),
bpf_xdp_pull_data() and the tail growth of bpf_xdp_adjust_tail().
The area keeps the address and size of the view and the log2 of the
net_iov size, so net_iov i lies at xdp_vaddr + (i << xdp_shift). For
pages the helpers give page_address(), and for a net_iov without a
view they give NULL. dmabuf and io_uring zcrx areas are allocated
zeroed, so they offer no view. AF_XDP sinks are the first to offer
one.
XDP may read a net_iov only through these helpers, and only if its
provider offers a view. Such buffers must not become skb frags or
xdp_frames. For the core and the stack every net_iov stays unreadable,
netmem_address() and skb_frag_address() still give NULL, and
skb->unreadable is still set for every net_iov frag. Other readers get
NULL for a net_iov with a view too, so they fail closed.
The other rules for providers stay. Native XDP runs next to a provider
only if it opts in, and providers without an XDP view still need
header split. AF_XDP sinks are exempt from both through MP_XDP_ONLY.
Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
include/net/netmem.h | 8 ++++++++
include/net/xdp.h | 34 ++++++++++++++++++++++++++++++++++
net/core/filter.c | 8 ++++----
3 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/include/net/netmem.h b/include/net/netmem.h
index fb693bc1702a..4cf4ee1cd55d 100644
--- a/include/net/netmem.h
+++ b/include/net/netmem.h
@@ -104,6 +104,14 @@ struct net_iov_area {
/* Array of net_iovs for this area. */
struct net_iov *niovs;
size_t num_niovs;
+ /* XDP view, see xdp_netmem_address(): XDP may read and write net_iov i
+ * at xdp_vaddr + (i << xdp_shift), xdp_vsize bytes in all. NULL if the
+ * provider offers none. The core and the stack take every net_iov as
+ * unreadable either way.
+ */
+ void *xdp_vaddr;
+ size_t xdp_vsize;
+ unsigned int xdp_shift;
};
static inline struct net_iov_area *net_iov_owner(const struct net_iov *niov)
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 07231adfb5f8..1629e347b71f 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -164,6 +164,40 @@ xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
#endif
}
+/* XDP view of net_iovs: a memory provider may give XDP an address for its
+ * net_iovs, see &net_iov_area.xdp_vaddr. XDP code may read and write a
+ * net_iov only through these helpers, and only if its provider offers a
+ * view; such buffers must not become skb frags or xdp_frames. For the core
+ * and the stack every net_iov stays unreadable: netmem_address() and
+ * skb_frag_address() give NULL for it. A net_iov without a view gives NULL
+ * here too, so a reader that does not use these helpers fails closed.
+ */
+static __always_inline void *xdp_net_iov_address(const struct net_iov *niov)
+{
+ const struct net_iov_area *area = net_iov_owner(niov);
+
+ if (!area->xdp_vaddr)
+ return NULL;
+ return area->xdp_vaddr +
+ ((unsigned long)net_iov_idx(niov) << area->xdp_shift);
+}
+
+/* Address of @netmem, which a driver uses as the head of an XDP buffer */
+static __always_inline void *xdp_netmem_address(netmem_ref netmem)
+{
+ if (netmem_is_net_iov(netmem))
+ return xdp_net_iov_address(netmem_to_net_iov(netmem));
+ return __netmem_address(netmem);
+}
+
+/* Address of the bytes of @frag of an XDP buffer */
+static __always_inline void *xdp_frag_address(const skb_frag_t *frag)
+{
+ void *addr = xdp_netmem_address(skb_frag_netmem(frag));
+
+ return addr ? addr + skb_frag_off(frag) : NULL;
+}
+
static __always_inline void
xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
int headroom, int data_len, const bool meta_valid)
diff --git a/net/core/filter.c b/net/core/filter.c
index f42ecfb5841f..d5774b2577e7 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4310,7 +4310,7 @@ void bpf_xdp_copy_buf(struct xdp_buff *xdp, unsigned long off,
break;
ptr_off += ptr_len;
- ptr_buf = skb_frag_address(next_frag);
+ ptr_buf = xdp_frag_address(next_frag);
ptr_len = skb_frag_size(next_frag);
next_frag++;
}
@@ -4338,7 +4338,7 @@ void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len)
u32 frag_size = skb_frag_size(&sinfo->frags[i]);
if (offset < frag_size) {
- addr = skb_frag_address(&sinfo->frags[i]);
+ addr = xdp_frag_address(&sinfo->frags[i]);
size = frag_size;
break;
}
@@ -4429,7 +4429,7 @@ static int bpf_xdp_frags_increase_tail(struct xdp_buff *xdp, int offset)
if (unlikely(offset > tailroom))
return -EINVAL;
- memset(skb_frag_address(frag) + skb_frag_size(frag), 0, offset);
+ memset(xdp_frag_address(frag) + skb_frag_size(frag), 0, offset);
skb_frag_size_add(frag, offset);
sinfo->xdp_frags_size += offset;
if (rxq->mem.type == MEM_TYPE_XSK_BUFF_POOL)
@@ -12835,7 +12835,7 @@ __bpf_kfunc int bpf_xdp_pull_data(struct xdp_md *x, u32 len)
skb_frag_t *frag = &sinfo->frags[i];
u32 shrink = min_t(u32, delta, skb_frag_size(frag));
- memcpy(xdp->data_end, skb_frag_address(frag), shrink);
+ memcpy(xdp->data_end, xdp_frag_address(frag), shrink);
xdp->data_end += shrink;
sinfo->xdp_frags_size -= shrink;
--
2.56.1
next prev parent reply other threads:[~2026-11-24 12:57 UTC|newest]
Thread overview: 16+ 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 ` Björn Töpel [this message]
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-24 12:56 ` [PATCH net-next 03/15] net: Add memory providers that only feed XDP 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-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-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 12:56 ` [PATCH net-next 07/15] xsk: Deliver to the socket in the device's buffer layout Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 08/15] xsk: Receive " Björn Töpel
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-24 12:56 ` [PATCH net-next 13/15] eth: bnxt: " 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-24 12:56 ` [PATCH net-next 15/15] Documentation: networking: Describe AF_XDP RX in the device's layout 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=20261124125654.183091-1-bjorn@kernel.org \
--to=bjorn@kernel.org \
--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=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=maciej.fijalkowski@intel.com \
--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