diff --git a/include/net/netmem.h b/include/net/netmem.h index 193de0d21490..7f36c734edcd 100644 --- a/include/net/netmem.h +++ b/include/net/netmem.h @@ -409,21 +409,21 @@ static inline bool net_is_devmem_iov(const struct net_iov *niov) } #endif -void get_net_iov(struct net_iov *niov); -void put_net_iov(struct net_iov *niov); +void net_iov_inc_ref(struct net_iov *niov); +void net_iov_dec_ref(struct net_iov *niov); /** * get_netmem - acquire a non-page_pool reference on a netmem * @netmem: netmem to reference * * Acquires a non-pp backing reference (page._refcount via get_page() or - * binding->ref via get_net_iov()) regardless of page_pool membership. + * binding->ref via net_iov_inc_ref()) regardless of page_pool membership. * Counterpart to put_netmem(). */ static __always_inline void get_netmem(netmem_ref netmem) { if (netmem_is_net_iov(netmem)) - get_net_iov(netmem_to_net_iov(netmem)); + net_iov_inc_ref(netmem_to_net_iov(netmem)); else get_page(netmem_to_page(netmem)); } @@ -433,13 +433,13 @@ static __always_inline void get_netmem(netmem_ref netmem) * @netmem: netmem to unreference * * Drops a non-pp backing reference (page._refcount via put_page() or - * binding->ref via put_net_iov()) regardless of page_pool membership. + * binding->ref via net_iov_dec_ref()) regardless of page_pool membership. * Counterpart to get_netmem(). */ static __always_inline void put_netmem(netmem_ref netmem) { if (netmem_is_net_iov(netmem)) - put_net_iov(netmem_to_net_iov(netmem)); + net_iov_dec_ref(netmem_to_net_iov(netmem)); else put_page(netmem_to_page(netmem)); } diff --git a/net/core/devmem.c b/net/core/devmem.c index fd1b72744564..32fafbfa1359 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -387,12 +387,12 @@ struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id) return binding; } -void net_devmem_get_net_iov(struct net_iov *niov) +void net_devmem_net_iov_inc_ref(struct net_iov *niov) { net_devmem_dmabuf_binding_get(net_devmem_iov_binding(niov)); } -void net_devmem_put_net_iov(struct net_iov *niov) +void net_devmem_net_iov_dec_ref(struct net_iov *niov) { net_devmem_dmabuf_binding_put(net_devmem_iov_binding(niov)); } diff --git a/net/core/devmem.h b/net/core/devmem.h index ad24bca20618..8fa089776610 100644 --- a/net/core/devmem.h +++ b/net/core/devmem.h @@ -43,7 +43,7 @@ struct net_devmem_dmabuf_binding { * those refs are dropped and the binding is no longer desired or in * use. * - * net_devmem_get_net_iov() on dmabuf net_iovs will increment this + * net_devmem_net_iov_inc_ref() on dmabuf net_iovs will increment this * reference, making sure that the binding remains alive until all the * net_iovs are no longer used. net_iovs allocated from this binding * that are stuck in the TX path for any reason (such as awaiting @@ -131,8 +131,8 @@ net_devmem_dmabuf_binding_put(struct net_devmem_dmabuf_binding *binding) percpu_ref_put(&binding->ref); } -void net_devmem_get_net_iov(struct net_iov *niov); -void net_devmem_put_net_iov(struct net_iov *niov); +void net_devmem_net_iov_inc_ref(struct net_iov *niov); +void net_devmem_net_iov_dec_ref(struct net_iov *niov); void net_devmem_free_dmabuf(struct net_iov *ppiov); @@ -151,11 +151,11 @@ net_devmem_dmabuf_binding_put(struct net_devmem_dmabuf_binding *binding) { } -static inline void net_devmem_get_net_iov(struct net_iov *niov) +static inline void net_devmem_net_iov_inc_ref(struct net_iov *niov) { } -static inline void net_devmem_put_net_iov(struct net_iov *niov) +static inline void net_devmem_net_iov_dec_ref(struct net_iov *niov) { } diff --git a/net/core/net_test.c b/net/core/net_test.c index cebd83e596d0..6fdab6a55b4d 100644 --- a/net/core/net_test.c +++ b/net/core/net_test.c @@ -861,11 +861,11 @@ static void netmem_ref_test_net_iov(struct kunit *test) netmem = net_iov_to_netmem(&niov); base_ref = atomic_long_read(&binding.ref.data->count); - /* Non-PP net_iov: get/put_net_iov & get/put_netmem */ - get_net_iov(&niov); + /* Non-PP net_iov: net_iov_inc/dec_ref & get/put_netmem */ + net_iov_inc_ref(&niov); KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), base_ref + 1); - put_net_iov(&niov); + net_iov_dec_ref(&niov); KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), base_ref); @@ -886,12 +886,12 @@ static void netmem_ref_test_net_iov(struct kunit *test) netmem_or_pp_magic(netmem, PP_SIGNATURE); atomic_long_set(&niov.desc.pp_ref_count, 2); - /* Layer 0 & 1: get_net_iov / get_netmem grab non-pp ref even on PP */ - get_net_iov(&niov); + /* Layer 0 & 1: net_iov_inc_ref / get_netmem grab non-pp ref on PP */ + net_iov_inc_ref(&niov); KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), base_ref + 1); KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L); - put_net_iov(&niov); + net_iov_dec_ref(&niov); KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), base_ref); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index b79d8b702a0b..a0f2d930ebf5 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -7643,38 +7643,38 @@ bool csum_and_copy_from_iter_full(void *addr, size_t bytes, EXPORT_SYMBOL(csum_and_copy_from_iter_full); /** - * get_net_iov - acquire a non-page_pool reference on a net_iov + * net_iov_inc_ref - acquire a non-page_pool reference on a net_iov * @niov: net_iov to reference * * Acquires a non-pp backing reference (binding->ref) on @niov regardless of * page_pool membership, warning if @niov does not support non-pp references. - * Counterpart to put_net_iov(). + * Counterpart to net_iov_dec_ref(). */ -void get_net_iov(struct net_iov *niov) +void net_iov_inc_ref(struct net_iov *niov) { if (net_is_devmem_iov(niov)) - net_devmem_get_net_iov(niov); + net_devmem_net_iov_inc_ref(niov); else DEBUG_NET_WARN_ON_ONCE(true); } -EXPORT_SYMBOL(get_net_iov); +EXPORT_SYMBOL(net_iov_inc_ref); /** - * put_net_iov - release a non-page_pool reference on a net_iov + * net_iov_dec_ref - release a non-page_pool reference on a net_iov * @niov: net_iov to unreference * * Drops a non-pp backing reference (binding->ref) on @niov regardless of * page_pool membership, warning if @niov does not support non-pp references. - * Counterpart to get_net_iov(). + * Counterpart to net_iov_inc_ref(). */ -void put_net_iov(struct net_iov *niov) +void net_iov_dec_ref(struct net_iov *niov) { if (net_is_devmem_iov(niov)) - net_devmem_put_net_iov(niov); + net_devmem_net_iov_dec_ref(niov); else DEBUG_NET_WARN_ON_ONCE(true); } -EXPORT_SYMBOL(put_net_iov); +EXPORT_SYMBOL(net_iov_dec_ref); struct vlan_type_depth __vlan_get_protocol_offset(const struct sk_buff *skb, __be16 type, -- knotmirror 0.0.1 From 2620efb2cec11628ff419dc876981e1f8fed664a Mon Sep 17 00:00:00 2001 From: Mina Almasry Date: Wed, 21 Oct 2026 01:55:58 +0000 Subject: [PATCH 2/2] netmem: rename get/put_netmem() to netmem_inc/dec_ref() Follow the object_action() naming convention for netmem non-page_pool reference helpers by renaming get_netmem() and put_netmem() to netmem_inc_ref() and netmem_dec_ref(). Use netmem_inc_ref() and netmem_dec_ref() rather than netmem_ref() and netmem_unref() because netmem_ref is already a typedef (typedef unsigned long __bitwise netmem_ref). Suggested-by: Jakub Kicinski Signed-off-by: Mina Almasry Link: https://patch.msgid.link/20261021015558.4124825-3-almasrymina@google.com Signed-off-by: Jakub Kicinski --- drivers/net/veth.c | 2 +- include/linux/skbuff_ref.h | 8 ++++---- include/net/netmem.h | 12 ++++++------ net/core/datagram.c | 2 +- net/core/net_test.c | 16 ++++++++-------- net/tls/tls_device.c | 2 +- net/tls/tls_device_fallback.c | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 8746d0d1f591..54fceb64f426 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -751,7 +751,7 @@ static void veth_xdp_get(struct xdp_buff *xdp) return; for (i = 0; i < sinfo->nr_frags; i++) - get_netmem(skb_frag_netmem(&sinfo->frags[i])); + netmem_inc_ref(skb_frag_netmem(&sinfo->frags[i])); } static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, diff --git a/include/linux/skbuff_ref.h b/include/linux/skbuff_ref.h index f768a3fa1d60..b6f6da556ee9 100644 --- a/include/linux/skbuff_ref.h +++ b/include/linux/skbuff_ref.h @@ -18,7 +18,7 @@ bool napi_pp_get_page(netmem_ref netmem); * * Acquires pp_ref_count via napi_pp_get_page() if @recycle is true and * @netmem belongs to a page_pool; otherwise acquires a non-pp backing - * reference via get_netmem(). Counterpart to skb_netmem_unref(). + * reference via netmem_inc_ref(). Counterpart to skb_netmem_unref(). */ static __always_inline void skb_netmem_ref(netmem_ref netmem, bool recycle) { @@ -26,7 +26,7 @@ static __always_inline void skb_netmem_ref(netmem_ref netmem, bool recycle) if (recycle && napi_pp_get_page(netmem)) return; #endif - get_netmem(netmem); + netmem_inc_ref(netmem); } /** @@ -53,7 +53,7 @@ bool napi_pp_put_page(netmem_ref netmem); * * Drops pp_ref_count via napi_pp_put_page() if @recycle is true and @netmem * belongs to a page_pool; otherwise drops a non-pp backing reference via - * put_netmem(). Counterpart to skb_netmem_ref(). + * netmem_dec_ref(). Counterpart to skb_netmem_ref(). */ static __always_inline void skb_netmem_unref(netmem_ref netmem, bool recycle) { @@ -61,7 +61,7 @@ static __always_inline void skb_netmem_unref(netmem_ref netmem, bool recycle) if (recycle && napi_pp_put_page(netmem)) return; #endif - put_netmem(netmem); + netmem_dec_ref(netmem); } /** diff --git a/include/net/netmem.h b/include/net/netmem.h index 7f36c734edcd..fb693bc1702a 100644 --- a/include/net/netmem.h +++ b/include/net/netmem.h @@ -413,14 +413,14 @@ void net_iov_inc_ref(struct net_iov *niov); void net_iov_dec_ref(struct net_iov *niov); /** - * get_netmem - acquire a non-page_pool reference on a netmem + * netmem_inc_ref - acquire a non-page_pool reference on a netmem * @netmem: netmem to reference * * Acquires a non-pp backing reference (page._refcount via get_page() or * binding->ref via net_iov_inc_ref()) regardless of page_pool membership. - * Counterpart to put_netmem(). + * Counterpart to netmem_dec_ref(). */ -static __always_inline void get_netmem(netmem_ref netmem) +static __always_inline void netmem_inc_ref(netmem_ref netmem) { if (netmem_is_net_iov(netmem)) net_iov_inc_ref(netmem_to_net_iov(netmem)); @@ -429,14 +429,14 @@ static __always_inline void get_netmem(netmem_ref netmem) } /** - * put_netmem - release a non-page_pool reference on a netmem + * netmem_dec_ref - release a non-page_pool reference on a netmem * @netmem: netmem to unreference * * Drops a non-pp backing reference (page._refcount via put_page() or * binding->ref via net_iov_dec_ref()) regardless of page_pool membership. - * Counterpart to get_netmem(). + * Counterpart to netmem_inc_ref(). */ -static __always_inline void put_netmem(netmem_ref netmem) +static __always_inline void netmem_dec_ref(netmem_ref netmem) { if (netmem_is_net_iov(netmem)) net_iov_dec_ref(netmem_to_net_iov(netmem)); diff --git a/net/core/datagram.c b/net/core/datagram.c index 173b5d97bd40..ecc30a6f8302 100644 --- a/net/core/datagram.c +++ b/net/core/datagram.c @@ -735,7 +735,7 @@ zerocopy_fill_skb_from_devmem(struct sk_buff *skb, struct iov_iter *from, size = min_t(size_t, size, length); size = min_t(size_t, size, iter_iov_len(from)); - get_netmem(net_iov_to_netmem(niov)); + netmem_inc_ref(net_iov_to_netmem(niov)); skb_add_rx_frag_netmem(skb, i, net_iov_to_netmem(niov), off, size, PAGE_SIZE); iov_iter_advance(from, size); diff --git a/net/core/net_test.c b/net/core/net_test.c index 6fdab6a55b4d..2b5080c22663 100644 --- a/net/core/net_test.c +++ b/net/core/net_test.c @@ -536,10 +536,10 @@ static void netmem_ref_test_page(struct kunit *test) netmem = page_to_netmem(page); base_ref = page_ref_count(page); - /* Layer 1: get_netmem / put_netmem use page non-pp refcount */ - get_netmem(netmem); + /* Layer 1: netmem_inc_ref / netmem_dec_ref use page non-pp refcount */ + netmem_inc_ref(netmem); KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref + 1); - put_netmem(netmem); + netmem_dec_ref(netmem); KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); #ifdef CONFIG_PAGE_POOL @@ -600,12 +600,12 @@ static void netmem_ref_test_pp_page(struct kunit *test) base_ref = page_ref_count(page); base_pp_ref = atomic_long_read(&page->pp_ref_count); - /* Layer 1: get_netmem / put_netmem always use non-pp refcount */ - get_netmem(netmem); + /* Layer 1: netmem_inc/dec_ref always use non-pp refcount */ + netmem_inc_ref(netmem); KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref + 1); KUNIT_EXPECT_EQ(test, atomic_long_read(&page->pp_ref_count), base_pp_ref); - put_netmem(netmem); + netmem_dec_ref(netmem); KUNIT_EXPECT_EQ(test, page_ref_count(page), base_ref); /* Layer 2: napi_pp_get/put_page use pp_ref_count */ @@ -861,7 +861,7 @@ static void netmem_ref_test_net_iov(struct kunit *test) netmem = net_iov_to_netmem(&niov); base_ref = atomic_long_read(&binding.ref.data->count); - /* Non-PP net_iov: net_iov_inc/dec_ref & get/put_netmem */ + /* Non-PP net_iov: net_iov_inc/dec_ref & netmem_inc/dec_ref */ net_iov_inc_ref(&niov); KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), base_ref + 1); @@ -886,7 +886,7 @@ static void netmem_ref_test_net_iov(struct kunit *test) netmem_or_pp_magic(netmem, PP_SIGNATURE); atomic_long_set(&niov.desc.pp_ref_count, 2); - /* Layer 0 & 1: net_iov_inc_ref / get_netmem grab non-pp ref on PP */ + /* Layer 0 & 1: net_iov/netmem_inc_ref grab non-pp ref on PP */ net_iov_inc_ref(&niov); KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count), base_ref + 1); diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index 2382d00aef8f..1a5f328d80a5 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -143,7 +143,7 @@ static void destroy_record(struct tls_record_info *record) int i; for (i = 0; i < record->num_frags; i++) - put_netmem(skb_frag_netmem(&record->frags[i])); + netmem_dec_ref(skb_frag_netmem(&record->frags[i])); kfree(record); } diff --git a/net/tls/tls_device_fallback.c b/net/tls/tls_device_fallback.c index 35cc510db432..b547027cc879 100644 --- a/net/tls/tls_device_fallback.c +++ b/net/tls/tls_device_fallback.c @@ -256,7 +256,7 @@ static int fill_sg_in(struct scatterlist *sg_in, for (i = 0; remaining > 0; i++) { skb_frag_t *frag = &record->frags[i]; - get_netmem(skb_frag_netmem(frag)); + netmem_inc_ref(skb_frag_netmem(frag)); sg_set_page(sg_in + i, skb_frag_page(frag), skb_frag_size(frag), skb_frag_off(frag));