From: Mina Almasry <almasrymina@google.com>
To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Jakub Kicinski <kuba@kernel.org>,
Willem de Bruijn <willemb@google.com>,
Eric Dumazet <edumazet@kernel.org>,
Mina Almasry <almasrymina@google.com>,
Kaiyuan Zhang <kaiyuanz@google.com>,
io-uring@vger.kernel.org, Stanislav Fomichev <sdf@fomichev.me>,
Paolo Abeni <pabeni@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Simon Horman <horms@kernel.org>,
Pavel Begunkov <asml.silence@gmail.com>,
Jens Axboe <axboe@kernel.dk>,
Stanislav Fomichev <sdf.kernel@gmail.com>,
Bobby Eshleman <bobbyeshleman@meta.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Neal Cardwell <ncardwell@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>
Subject: [PATCH net-next v2 2/4] netmem: store memory provider private pointer directly in struct net_iov
Date: Mon, 2 Nov 2026 23:18:25 +0000 [thread overview]
Message-ID: <20261102231827.4088254-3-almasrymina@google.com> (raw)
In-Reply-To: <20261102231827.4088254-1-almasrymina@google.com>
Resolving the memory provider instance from a struct net_iov currently
chases niov->owner (struct net_iov_area) and then dereferences the
provider-specific container struct (such as net_devmem_dmabuf_binding
or io_zcrx_area->ifq).
Alias void *mp_priv over the unused _pp_mapping_pad slot inside struct
net_iov (keeping sizeof(struct net_iov) == 64 bytes unchanged) and populate
it in net_iov_init() for both TX and RX net_iovs so callers can obtain the
provider instance pointer in a single load from the net_iov cacheline.
Signed-off-by: Mina Almasry <almasrymina@google.com>
---
include/net/netmem.h | 15 +++++++++++++--
io_uring/zcrx.c | 2 +-
net/core/devmem.c | 3 ++-
net/core/devmem.h | 3 +--
net/core/net_test.c | 10 +++++-----
5 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/include/net/netmem.h b/include/net/netmem.h
index fb693bc1702a4..c869be9c4d266 100644
--- a/include/net/netmem.h
+++ b/include/net/netmem.h
@@ -95,11 +95,20 @@ enum net_iov_type {
* supported.
*/
struct net_iov {
- struct netmem_desc desc;
+ union {
+ struct netmem_desc desc;
+ struct {
+ unsigned long _pad[3];
+ void *mp_priv;
+ };
+ };
enum net_iov_type type;
struct net_iov_area *owner;
};
+static_assert(offsetof(struct net_iov, mp_priv) ==
+ offsetof(struct netmem_desc, _pp_mapping_pad));
+
struct net_iov_area {
/* Array of net_iovs for this area. */
struct net_iov *niovs;
@@ -120,10 +129,12 @@ static inline unsigned int net_iov_idx(const struct net_iov *niov)
*/
static inline void net_iov_init(struct net_iov *niov,
struct net_iov_area *owner,
- enum net_iov_type type)
+ enum net_iov_type type,
+ void *mp_priv)
{
niov->owner = owner;
niov->type = type;
+ niov->mp_priv = mp_priv;
}
/* netmem */
diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index 6d7abb1636e7f..6ec618d325606 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -562,7 +562,7 @@ static int __zcrx_create_area(struct io_zcrx_ifq *ifq,
for (i = 0; i < nr_iovs; i++) {
struct net_iov *niov = &area->nia.niovs[i];
- net_iov_init(niov, &area->nia, NET_IOV_IOURING);
+ net_iov_init(niov, &area->nia, NET_IOV_IOURING, ifq);
area->freelist[i] = i;
atomic_set(&area->user_refs[i], 0);
}
diff --git a/net/core/devmem.c b/net/core/devmem.c
index 32fafbfa1359e..fe99c005cbc5e 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -323,7 +323,8 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
nr_niovs = len >> niov_shift;
for (i = 0; i < nr_niovs; i++, niov_idx++) {
niov = &binding->area.niovs[niov_idx];
- net_iov_init(niov, &binding->area, NET_IOV_DMABUF);
+ net_iov_init(niov, &binding->area, NET_IOV_DMABUF,
+ binding);
if (net_mp_niov_set_dma_addr(niov, dma_addr)) {
err = -EFAULT;
NL_SET_ERR_MSG(extack,
diff --git a/net/core/devmem.h b/net/core/devmem.h
index 8fa089776610a..942b8caf36e99 100644
--- a/net/core/devmem.h
+++ b/net/core/devmem.h
@@ -102,8 +102,7 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
static inline struct net_devmem_dmabuf_binding *
net_devmem_iov_binding(const struct net_iov *niov)
{
- return container_of(net_iov_owner(niov),
- struct net_devmem_dmabuf_binding, area);
+ return niov->mp_priv;
}
static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov)
diff --git a/net/core/net_test.c b/net/core/net_test.c
index 2b5080c226636..63124dbf3c9a8 100644
--- a/net/core/net_test.c
+++ b/net/core/net_test.c
@@ -857,7 +857,7 @@ static void netmem_ref_test_net_iov(struct kunit *test)
PERCPU_REF_INIT_ATOMIC, GFP_KERNEL);
KUNIT_ASSERT_EQ(test, err, 0);
- net_iov_init(&niov, &binding.area, NET_IOV_DMABUF);
+ net_iov_init(&niov, &binding.area, NET_IOV_DMABUF, &binding);
netmem = net_iov_to_netmem(&niov);
base_ref = atomic_long_read(&binding.ref.data->count);
@@ -1145,7 +1145,7 @@ static void netmem_ref_test_release_data(struct kunit *test)
percpu_ref_init(&binding.ref, dummy_percpu_ref_release,
PERCPU_REF_INIT_ATOMIC, GFP_KERNEL),
0);
- net_iov_init(&niov, &binding.area, NET_IOV_DMABUF);
+ net_iov_init(&niov, &binding.area, NET_IOV_DMABUF, &binding);
netmem = net_iov_to_netmem(&niov);
netmem_set_pp(netmem, pool);
netmem_or_pp_magic(netmem, PP_SIGNATURE);
@@ -1206,7 +1206,7 @@ static void netmem_ref_test_skb_segment(struct kunit *test)
percpu_ref_init(&binding.ref, dummy_percpu_ref_release,
PERCPU_REF_INIT_ATOMIC, GFP_KERNEL),
0);
- net_iov_init(&niov, &binding.area, NET_IOV_DMABUF);
+ net_iov_init(&niov, &binding.area, NET_IOV_DMABUF, &binding);
niov_nm = net_iov_to_netmem(&niov);
netmem_set_pp(niov_nm, pool);
netmem_or_pp_magic(niov_nm, PP_SIGNATURE);
@@ -1508,7 +1508,7 @@ static void netmem_ref_test_try_coalesce(struct kunit *test)
percpu_ref_init(&binding.ref, dummy_percpu_ref_release,
PERCPU_REF_INIT_ATOMIC, GFP_KERNEL),
0);
- net_iov_init(&niov, &binding.area, NET_IOV_DMABUF);
+ net_iov_init(&niov, &binding.area, NET_IOV_DMABUF, &binding);
niov_nm = net_iov_to_netmem(&niov);
netmem_set_pp(niov_nm, pool);
netmem_or_pp_magic(niov_nm, PP_SIGNATURE);
@@ -1654,7 +1654,7 @@ static void netmem_ref_test_tcp_devmem_recv(struct kunit *test)
KUNIT_ASSERT_EQ(test, ret, 0);
}
binding.area.niovs = &niov;
- net_iov_init(&niov, &binding.area, NET_IOV_DMABUF);
+ net_iov_init(&niov, &binding.area, NET_IOV_DMABUF, &binding);
niov_nm = net_iov_to_netmem(&niov);
netmem_set_pp(niov_nm, pool);
netmem_or_pp_magic(niov_nm, PP_SIGNATURE);
--
2.56.0.385.gac671c819a-goog
next prev parent reply other threads:[~2026-11-02 23:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 23:18 [PATCH net-next v2 0/4] net: prevent mixing incompatible memory providers in skbs Mina Almasry
2026-11-02 23:18 ` [PATCH net-next v2 1/4] net: fix skb->unreadable propagation in skb_split() and skb_shift() Mina Almasry
2026-11-02 23:18 ` Mina Almasry [this message]
2026-11-02 23:18 ` [PATCH net-next v2 3/4] net: add skb_frags_can_coalesce() helper Mina Almasry
2026-11-02 23:18 ` [PATCH net-next v2 4/4] net: prevent mixing frags from different memory providers or bindings Mina Almasry
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=20261102231827.4088254-3-almasrymina@google.com \
--to=almasrymina@google.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=bobbyeshleman@meta.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=io-uring@vger.kernel.org \
--cc=kaiyuanz@google.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf.kernel@gmail.com \
--cc=sdf@fomichev.me \
--cc=willemb@google.com \
/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®