Thread (49 messages) read the whole thread 49 messages, 4 authors, 2025-07-28

Re: [PATCH net-next v9 1/8] netmem: introduce struct netmem_desc mirroring struct page

From: Pavel Begunkov <asml.silence@gmail.com>
Date: 2025-07-15 09:59:57
Also in: bpf, linux-mm, linux-rdma, lkml

On 7/14/25 20:17, Mina Almasry wrote:
On Mon, Jul 14, 2025 at 4:28 AM Pavel Begunkov [off-list ref] wrote:
...>> diff --git a/include/net/netmem.h b/include/net/netmem.h
quoted
index 535cf17b9134..41f3a3fd6b6c 100644
--- a/include/net/netmem.h
+++ b/include/net/netmem.h
@@ -247,6 +247,8 @@ static inline unsigned long netmem_pfn_trace(netmem_ref netmem)
         return page_to_pfn(netmem_to_page(netmem));
   }

+#define pp_page_to_nmdesc(page)        ((struct netmem_desc *)(page))
+
   /* __netmem_clear_lsb - convert netmem_ref to struct net_iov * for access to
    * common fields.
    * @netmem: netmem reference to extract as net_iov.
@@ -262,11 +264,18 @@ static inline unsigned long netmem_pfn_trace(netmem_ref netmem)
    *
    * Return: the netmem_ref cast to net_iov* regardless of its underlying type.
    */
-static inline struct net_iov *__netmem_clear_lsb(netmem_ref netmem)
+static inline struct net_iov *__netmem_to_niov(netmem_ref netmem)
   {
         return (struct net_iov *)((__force unsigned long)netmem & ~NET_IOV);
   }

+static inline struct netmem_desc *netmem_to_nmdesc(netmem_ref netmem)
+{
+       if (netmem_is_net_iov(netmem))
+               return &__netmem_to_niov(netmem)->desc;
+       return pp_page_to_nmdesc(__netmem_to_page(netmem));
+}
+
I think instead of netmem_to_nmdesc, you want __netmem_clear_lsb to
return a netmem_desc instead of net_iov.
Same thing, the diff just renames __netmem_clear_lsb -> netmem_to_nmdesc
on top.
__netmem_clear_lsb returning a net_iov was always a bit of a hack. The
return value of __netmem_clear_lsb is clearly not a net_iov, but we
needed to access the pp fields, and net_iov encapsulates the pp
fields.
Right, and netmem_desc nicely solves that. I remember suggesting such
a common type during review to the initial netmem / niov patches as well.

-- 
Pavel Begunkov
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help