From: Stanislav Fomichev <sdf.kernel@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, hawk@kernel.org,
ilias.apalodimas@linaro.org, sdf@fomichev.me,
bobbyeshleman@meta.com, almasrymina@google.com,
kaiyuanz@google.com, linux-kernel@vger.kernel.org
Subject: [PATCH net-next v2 2/3] net: devmem: use memory provider helpers for net_iovs
Date: Fri, 25 Sep 2026 13:15:21 -0700 [thread overview]
Message-ID: <20260925201522.254717-3-sdf@fomichev.me> (raw)
In-Reply-To: <20260925201522.254717-1-sdf@fomichev.me>
Use public memory-provider helpers for DMA address storage and page-pool
association instead of open-coding page_pool state and accounting.
Zero the net_iov array because net_mp_niov_set_page_pool() ORs
PP_SIGNATURE into pp_magic. Reject DMA addresses that cannot be
represented in net_iov metadata.
Reviewed-by: Mina Almasry <almasrymina@google.com>
Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
---
net/core/devmem.c | 31 +++++++++++--------------------
1 file changed, 11 insertions(+), 20 deletions(-)
diff --git a/net/core/devmem.c b/net/core/devmem.c
index 704d02bd8bc8..71c83730d73d 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -17,11 +17,9 @@
#include <net/page_pool/memory_provider.h>
#include <net/sock.h>
#include <net/tcp.h>
-#include <trace/events/page_pool.h>
#include "devmem.h"
#include "mp_dmabuf_devmem.h"
-#include "page_pool_priv.h"
/* Device memory support */
@@ -273,7 +271,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
goto err_unmap;
}
}
- binding->area.niovs = kvmalloc_objs(*binding->area.niovs,
+ binding->area.niovs = kvzalloc_objs(*binding->area.niovs,
binding->area.num_niovs);
if (!binding->area.niovs) {
err = -ENOMEM;
@@ -300,8 +298,12 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
for (i = 0; i < nr_niovs; i++, niov_idx++) {
niov = &binding->area.niovs[niov_idx];
net_iov_init(niov, &binding->area, NET_IOV_DMABUF);
- page_pool_set_dma_addr_netmem(net_iov_to_netmem(niov),
- dma_addr);
+ if (net_mp_niov_set_dma_addr(niov, dma_addr)) {
+ err = -EFAULT;
+ NL_SET_ERR_MSG(extack,
+ "dmabuf DMA address cannot be represented");
+ goto err_free_niovs;
+ }
if (direction == DMA_TO_DEVICE)
binding->tx_vec[niov_idx] = niov;
else
@@ -467,19 +469,9 @@ netmem_ref mp_dmabuf_devmem_alloc_netmems(struct page_pool *pool, gfp_t gfp)
if (unlikely(!allocated))
return 0;
- for (i = 0; i < allocated; i++) {
- struct net_iov *niov = netmem_to_net_iov(netmems[i]);
-
- niov->desc.pp_magic = 0;
- niov->desc.pp = NULL;
- atomic_long_set(&niov->desc.pp_ref_count, 0);
-
- page_pool_set_pp_info(pool, netmems[i]);
-
- pool->pages_state_hold_cnt++;
- trace_page_pool_state_hold(pool, netmems[i],
- pool->pages_state_hold_cnt);
- }
+ for (i = 0; i < allocated; i++)
+ net_mp_niov_set_page_pool(pool,
+ netmem_to_net_iov(netmems[i]));
/* Return the last one, the rest stay in the page_pool cache. */
allocated--;
@@ -504,8 +496,7 @@ bool mp_dmabuf_devmem_release_page(struct page_pool *pool, netmem_ref netmem)
if (WARN_ON_ONCE(refcount != 1))
return false;
- page_pool_clear_pp_info(netmem);
-
+ net_mp_niov_clear_page_pool(netmem_to_net_iov(netmem));
net_devmem_free_dmabuf(netmem_to_net_iov(netmem));
/* We don't want the page pool put_page()ing our net_iovs. */
--
2.53.0-Meta
next prev parent reply other threads:[~2026-09-25 20:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 20:15 [PATCH net-next v2 0/3] net: consolidate devmem net_iov freelist and DMA handling Stanislav Fomichev
2026-09-25 20:15 ` [PATCH net-next v2 1/3] net: netmem: move to index based freelist Stanislav Fomichev
2026-09-25 20:15 ` Stanislav Fomichev [this message]
2026-09-25 20:15 ` [PATCH net-next v2 3/3] net: devmem: decode DMA addresses for TX Stanislav Fomichev
2026-09-29 9:43 ` Paolo Abeni
2026-09-29 13:39 ` Paolo Abeni
2026-09-29 15:55 ` Stanislav Fomichev
2026-09-29 14:10 ` [PATCH net-next v2 0/3] net: consolidate devmem net_iov freelist and DMA handling patchwork-bot+netdevbpf
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=20260925201522.254717-3-sdf@fomichev.me \
--to=sdf.kernel@gmail.com \
--cc=almasrymina@google.com \
--cc=bobbyeshleman@meta.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=ilias.apalodimas@linaro.org \
--cc=kaiyuanz@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
/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®