[RFC v3 16/18] netmem: introduce a netmem API, virt_to_head_netmem()

Byungchul Park
2025-05-29T03:11:11Z

To eliminate the use of struct page in page pool, the page pool code
should use netmem descriptor and APIs instead.

As part of the work, introduce a netmem API to convert a virtual address
to a head netmem allowing the code to use it rather than the existing
API, virt_to_head_page() for struct page.

Signed-off-by: Byungchul Park <byungchul@sk.com>
---
include/net/netmem.h | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/include/net/netmem.h b/include/net/netmem.h
index ef639b5c70ec..f05a8b008d00 100644
--- a/include/net/netmem.h
+++ b/include/net/netmem.h
@@ -270,6 +270,13 @@ static inline netmem_ref netmem_compound_head(netmem_ref netmem)
return page_to_netmem(compound_head(netmem_to_page(netmem)));
}

+static inline netmem_ref virt_to_head_netmem(const void *x)
+{
+ netmem_ref netmem = virt_to_netmem(x);
+
+ return netmem_compound_head(netmem);
+}
+
/**
* __netmem_address - unsafely get pointer to the memory backing @netmem
* @netmem: netmem reference to get the pointer for
--
2.17.1