From: Mina Almasry <almasrymina@google.com>
To: netdev@vger.kernel.org
Cc: Mina Almasry <almasrymina@google.com>,
Eric Dumazet <edumazet@kernel.org>,
Neal Cardwell <ncardwell@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>,
Kaiyuan Zhang <kaiyuanz@google.com>,
Willem de Bruijn <willemb@google.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Josef Bacik <josef@toxicpanda.com>,
Stanislav Fomichev <sdf.kernel@gmail.com>,
Dragos Tatulea <dtatulea@nvidia.com>,
Pavel Begunkov <asml.silence@gmail.com>,
Bobby Eshleman <bobbyeshleman@meta.com>
Subject: [PATCH net-next v6 7/7] net: kunit: test incompatible memory provider rejection
Date: Fri, 20 Nov 2026 20:14:08 +0000 [thread overview]
Message-ID: <20261120201408.3445445-8-almasrymina@google.com> (raw)
In-Reply-To: <20261120201408.3445445-1-almasrymina@google.com>
Add KUnit subtests in netmem_ref_test_try_coalesce() verifying that:
- skb_try_coalesce() rejects coalescing two NET_IOV_DMABUF skbs
belonging to different bindings, and
- skb_try_coalesce() rejects coalescing a NET_IOV_DMABUF skb with a
NET_IOV_IOURING skb.
Signed-off-by: Mina Almasry <almasrymina@google.com>
---
net/core/net_test.c | 49 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 47 insertions(+), 2 deletions(-)
diff --git a/net/core/net_test.c b/net/core/net_test.c
index 1cfa947c11f2..3efff3f5368a 100644
--- a/net/core/net_test.c
+++ b/net/core/net_test.c
@@ -1639,9 +1639,10 @@ static void netmem_ref_test_try_coalesce(struct kunit *test)
.nid = NUMA_NO_NODE,
};
struct sk_buff *to, *from, *clone;
- struct net_iov niov = {};
+ struct net_iov_area area2 = {};
+ struct net_iov niov = {}, niov2 = {};
struct page *pp_page, *reg_page;
- netmem_ref pp_nm, niov_nm;
+ netmem_ref pp_nm, niov_nm, niov2_nm;
struct page_pool *pool;
long base_pp_ref, base_iov_ref;
int base_pp_page_ref, base_reg_ref;
@@ -1753,6 +1754,50 @@ static void netmem_ref_test_try_coalesce(struct kunit *test)
consume_skb(to);
KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L);
+ /* 4. Reject coalescing net_iov skbs from different bindings. */
+ net_iov_init(&niov2, &area2, NET_IOV_DMABUF);
+ niov2_nm = net_iov_to_netmem(&niov2);
+ netmem_set_pp(niov2_nm, pool);
+ netmem_or_pp_magic(niov2_nm, PP_SIGNATURE);
+ atomic_long_set(&niov2.desc.pp_ref_count, 2);
+ to = alloc_skb(0, GFP_KERNEL);
+ from = alloc_skb(0, GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, to);
+ KUNIT_ASSERT_NOT_NULL(test, from);
+ to->pp_recycle = 1;
+ from->pp_recycle = 1;
+ skb_add_rx_frag_netmem(to, 0, niov_nm, 0, 32, PAGE_SIZE);
+ napi_pp_get_page(niov_nm);
+ skb_add_rx_frag_netmem(from, 0, niov2_nm, 0, 32, PAGE_SIZE);
+ napi_pp_get_page(niov2_nm);
+ KUNIT_EXPECT_FALSE(test, skb_try_coalesce(to, from, &fragstolen,
+ &delta));
+ consume_skb(from);
+ consume_skb(to);
+ KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L);
+ KUNIT_EXPECT_EQ(test, atomic_long_read(&niov2.desc.pp_ref_count), 2L);
+
+ /* 5. Reject coalescing net_iov skbs from different providers. */
+ net_iov_init(&niov2, NULL, NET_IOV_IOURING);
+ to = alloc_skb(0, GFP_KERNEL);
+ from = alloc_skb(0, GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, to);
+ KUNIT_ASSERT_NOT_NULL(test, from);
+ to->pp_recycle = 1;
+ from->pp_recycle = 1;
+ skb_add_rx_frag_netmem(to, 0, niov_nm, 0, 32, PAGE_SIZE);
+ napi_pp_get_page(niov_nm);
+ skb_add_rx_frag_netmem(from, 0, niov2_nm, 0, 32, PAGE_SIZE);
+ napi_pp_get_page(niov2_nm);
+ KUNIT_EXPECT_FALSE(test, skb_try_coalesce(to, from, &fragstolen,
+ &delta));
+ consume_skb(from);
+ consume_skb(to);
+ KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L);
+ KUNIT_EXPECT_EQ(test, atomic_long_read(&niov2.desc.pp_ref_count), 2L);
+ netmem_clear_pp_magic(niov2_nm);
+ netmem_set_pp(niov2_nm, NULL);
+
page_pool_put_full_page(pool, pp_page, false);
page_pool_put_full_page(pool, pp_page, false);
__free_page(reg_page);
--
2.56.1.750.gf70dc682cf-goog
prev parent reply other threads:[~2026-11-20 20:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 20:14 [PATCH net-next v6 0/7] net: prevent mixing incompatible memory providers in skbs Mina Almasry
2026-11-20 20:14 ` [PATCH net-next v6 1/7] net: fix skb->unreadable propagation in skb_split() and skb_shift() Mina Almasry
2026-11-20 20:14 ` [PATCH net-next v6 2/7] net: devmem: prevent mixing TX bindings and reject non-devmem xmit Mina Almasry
2026-11-20 20:14 ` [PATCH net-next v6 3/7] tcp: fix unreadable net_iov handling in tcp_clone_payload() Mina Almasry
2026-11-20 20:14 ` [PATCH net-next v6 4/7] tcp: propagate skb_zcopy() uarg in tcp_mtu_probe() Mina Almasry
2026-11-20 20:14 ` [PATCH net-next v6 5/7] net: kunit: attach net_iov frags to target skbs in unreadable tests Mina Almasry
2026-11-20 20:14 ` [PATCH net-next v6 6/7] net: prevent mixing frags from different memory providers or bindings Mina Almasry
2026-11-20 20:14 ` Mina Almasry [this message]
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=20261120201408.3445445-8-almasrymina@google.com \
--to=almasrymina@google.com \
--cc=asml.silence@gmail.com \
--cc=bobbyeshleman@meta.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dtatulea@nvidia.com \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kaiyuanz@google.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--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