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 04/15] page_pool: Let memory providers take back net_iovs
Date: Tue, 24 Nov 2026 13:56:39 +0100 [thread overview]
Message-ID: <20261124125654.183091-4-bjorn@kernel.org> (raw)
In-Reply-To: <20261124112707.118678-1-bjorn@kernel.org>
Currently, the only provider hook on the last put of a net_iov is
release_netmem(), which takes it out of its page pool. The AF_XDP
sink, later in this series, gives a chunk back to userspace only once
the device is done with it too, so it must see that last put. With
release_netmem(), the pool would take the chunk in again each time
userspace lends it back.
Let a provider mark a net_iov so that its last put goes to the
provider's hand_off() instead of the page pool cache, still charged to
the pool, for the provider to put back later.
The hand-off also covers the fragment allocator draining a marked
net_iov. Providers that mark net_iovs must implement hand_off(), and
nothing changes for others, as the mark is clear by default. Also give
providers a byte of their own in the net_iov, in the cache line they
touch anyway.
Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
include/net/netmem.h | 8 ++++++++
include/net/page_pool/memory_provider.h | 6 ++++++
net/core/page_pool.c | 20 +++++++++++++++++++-
3 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/include/net/netmem.h b/include/net/netmem.h
index 4cf4ee1cd55d..1be7298ac6d9 100644
--- a/include/net/netmem.h
+++ b/include/net/netmem.h
@@ -97,6 +97,12 @@ enum net_iov_type {
struct net_iov {
struct netmem_desc desc;
enum net_iov_type type;
+ /* The last put hands it to its memory provider instead of the page
+ * pool cache, see &memory_provider_ops.hand_off
+ */
+ bool mp_hand_off;
+ /* Owned by the memory provider */
+ u8 mp_state;
struct net_iov_area *owner;
};
@@ -132,6 +138,8 @@ static inline void net_iov_init(struct net_iov *niov,
{
niov->owner = owner;
niov->type = type;
+ niov->mp_hand_off = false;
+ niov->mp_state = 0;
}
/* netmem */
diff --git a/include/net/page_pool/memory_provider.h b/include/net/page_pool/memory_provider.h
index d52c7a450c68..bfc284158222 100644
--- a/include/net/page_pool/memory_provider.h
+++ b/include/net/page_pool/memory_provider.h
@@ -36,6 +36,12 @@ enum mp_flags {
struct memory_provider_ops {
netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp);
bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem);
+ /* Takes a free net_iov marked mp_hand_off that stays charged to the
+ * pool; the provider puts it back later. Returns false to have the
+ * pool recycle it instead. Called where the pool puts netmem, outside
+ * hard IRQ context. Needed by providers that mark net_iovs.
+ */
+ bool (*hand_off)(struct page_pool *pool, netmem_ref netmem);
int (*init)(struct page_pool *pool);
void (*destroy)(struct page_pool *pool);
int (*nl_fill)(void *mp_priv, struct sk_buff *rsp,
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 8a1ea21ccdcd..200b0569b9fe 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -840,6 +840,16 @@ static bool __page_pool_page_can_be_recycled(netmem_ref netmem)
!page_is_pfmemalloc(netmem_to_page(netmem)));
}
+/* A memory provider takes back a free net_iov it marked, see
+ * &memory_provider_ops.hand_off
+ */
+static bool page_pool_hand_off(struct page_pool *pool, netmem_ref netmem)
+{
+ return netmem_is_net_iov(netmem) &&
+ unlikely(netmem_to_net_iov(netmem)->mp_hand_off) &&
+ pool->mp_ops->hand_off(pool, netmem);
+}
+
/* If the page refcnt == 1, this will try to recycle the page.
* If pool->dma_sync is set, we'll try to sync the DMA area for
* the configured size min(dma_sync_size, pool->max_len).
@@ -852,6 +862,10 @@ __page_pool_put_page(struct page_pool *pool, netmem_ref netmem,
{
lockdep_assert_no_hardirq();
+ /* The provider takes the net_iovs it marked */
+ if (page_pool_hand_off(pool, netmem))
+ return 0;
+
/* This allocator is optimized for the XDP mode that uses
* one-frame-per-page, but have fallbacks that act like the
* regular page allocator APIs.
@@ -1051,6 +1065,9 @@ static netmem_ref page_pool_drain_frag(struct page_pool *pool,
if (likely(page_pool_unref_netmem(netmem, drain_count)))
return 0;
+ if (page_pool_hand_off(pool, netmem))
+ return 0;
+
if (__page_pool_page_can_be_recycled(netmem)) {
page_pool_dma_sync_for_device(pool, netmem, -1);
return netmem;
@@ -1067,7 +1084,8 @@ static void page_pool_free_frag(struct page_pool *pool)
pool->frag_page = 0;
- if (!netmem || page_pool_unref_netmem(netmem, drain_count))
+ if (!netmem || page_pool_unref_netmem(netmem, drain_count) ||
+ page_pool_hand_off(pool, netmem))
return;
page_pool_return_netmem(pool, netmem);
--
2.56.1
next prev parent reply other threads:[~2026-11-24 12:57 UTC|newest]
Thread overview: 55+ 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 13:00 ` sashiko-bot
2026-11-25 14:07 ` netdev-bot+sashiko
2026-11-25 19:34 ` Björn Töpel
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 19:39 ` Björn Töpel
2026-11-25 15:17 ` Maciej Fijalkowski
2026-11-25 19:36 ` 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-25 14:08 ` netdev-bot+sashiko
2026-11-25 19:43 ` Björn Töpel
2026-11-24 12:56 ` Björn Töpel [this message]
2026-11-25 14:08 ` [PATCH net-next 04/15] page_pool: Let memory providers take back net_iovs netdev-bot+sashiko
2026-11-25 19:45 ` 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-25 13:00 ` sashiko-bot
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 19:55 ` Björn Töpel
2026-11-25 15:22 ` Maciej Fijalkowski
2026-11-25 15:28 ` Maciej Fijalkowski
2026-11-25 19:50 ` 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 14:34 ` Magnus Karlsson
2026-11-24 15:12 ` Björn Töpel
2026-11-25 13:00 ` sashiko-bot
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:02 ` 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-25 13:00 ` sashiko-bot
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:11 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 08/15] xsk: Receive " Björn Töpel
2026-11-25 13:00 ` sashiko-bot
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:16 ` Björn Töpel
2026-11-30 14:47 ` Maciej Fijalkowski
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 13:00 ` sashiko-bot
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:26 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 13/15] eth: bnxt: " Björn Töpel
2026-11-25 13:00 ` sashiko-bot
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:33 ` 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-25 13:00 ` sashiko-bot
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
2026-11-25 13:00 ` [PATCH net-next 00/15] xsk: Receive in the device's buffer layout sashiko-bot
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-4-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.