Thread (49 messages) 49 messages, 4 authors, 2025-07-28

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

From: Mina Almasry <hidden>
Date: 2025-07-14 19:17:24
Also in: bpf, linux-mm, linux-rdma, lkml

On Mon, Jul 14, 2025 at 4:28 AM Pavel Begunkov [off-list ref] wrote:
quoted hunk ↗ jump to hunk
On 7/14/25 05:23, Byungchul Park wrote:
quoted
On Sat, Jul 12, 2025 at 03:39:59PM +0100, Pavel Begunkov wrote:
quoted
On 7/10/25 09:28, Byungchul Park wrote:
quoted
To simplify struct page, the page pool members of struct page should be
moved to other, allowing these members to be removed from struct page.

Introduce a network memory descriptor to store the members, struct
netmem_desc, and make it union'ed with the existing fields in struct
net_iov, allowing to organize the fields of struct net_iov.
FWIW, regardless of memdesc business, I think it'd be great to have
this patch, as it'll help with some of the netmem casting ugliness and
shed some cycles as well. For example, we have a bunch of
niov -> netmem -> niov casts in various places.
If Jakub agrees with this, I will re-post this as a separate patch so
that works that require this base can go ahead.
I think it'd be a good idea. It's needed to clean up netmem handling,
and I'll convert io_uring and get rid of the union in niov.

The diff below should give a rough idea of what I want to use it for.
It kills __netmem_clear_lsb() to avoid casting struct page * to niov.
And saves some masking for zcrx, see page_pool_get_dma_addr_nmdesc(),
and there are more places like that.

diff --git a/include/net/netmem.h b/include/net/netmem.h
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.

__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.

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