Re: [PATCH net-next 04/15] page_pool: Let memory providers take back net_iovs

From: Björn Töpel

Date: Wed Nov 25 2026 - 14:46:13 EST


netdev-bot+sashiko@xxxxxxxxxx writes:

> Thank you for your contribution! Sashiko AI review found more severe
> issue(s) in other patches of this series. This mail is only an FYI, in case
> you want to address the nit picks below when you respin.
>
> Low priority / nit picks for your consideration:
>
> - [Low] page_pool_hand_off() in net/core/page_pool.c (lines 846-851)
> branches on netmem_is_net_iov() and casts the netmem down to a net_iov…
> - [Low] The kernel-doc for memory_provider_ops.hand_off in
> include/net/page_pool/memory_provider.h (lines 39-44) says a false…
>
> --
>
> page_pool: Let memory providers take back net_iovs
>
> This commit adds a hand_off() memory provider op and an mp_hand_off flag
> in struct net_iov. When a net_iov is marked, its last put goes to the
> provider instead of the page pool cache, and it stays charged to the
> pool. The hook is wired into __page_pool_put_page(),
> page_pool_drain_frag() and page_pool_free_frag(). The commit also adds a
> provider-owned mp_state byte.
>
>> diff --git a/include/net/page_pool/memory_provider.h b/include/net/page_pool/memory_provider.h
>> index d52c7a450c68e..bfc2841582225 100644
>> --- a/include/net/page_pool/memory_provider.h
>> +++ b/include/net/page_pool/memory_provider.h
>> @@ -36,6 +36,12 @@ enum mp_flags {
>> struct memory_provider_ops {
>> netmem_ref (*alloc_netmems)(struct page_pool *pool, gfp_t gfp);
>> bool (*release_netmem)(struct page_pool *pool, netmem_ref netmem);
>> + /* Takes a free net_iov marked mp_hand_off that stays charged to the
>> + * pool; the provider puts it back later. Returns false to have the
>> + * pool recycle it instead. Called where the pool puts netmem, outside
>> + * hard IRQ context. Needed by providers that mark net_iovs.
>> + */
>
> [Severity: Low]
>
> Is "Returns false to have the pool recycle it instead" true for every
> caller?

You're right, at destroy a false return releases the net_iov, which is
what a dying pool should do. I'll fix the comment.

> [Severity: Low]
>
> This isn't a bug, but does this fit the netmem abstraction rules?
> page_pool_hand_off() branches on netmem_is_net_iov() and downcasts with
> netmem_to_net_iov() inside page_pool core. Before this patch, page_pool.c
> had no netmem_to_net_iov() call.
>
> The netmem_ref kernel-doc in include/net/netmem.h says:
>
> Downcasting netmem_ref via netmem_to_page() or netmem_to_net_iov() in
> callers is not allowed unless a code path strictly requires a specific
> backing type ... In such cases, add a netmem helper here that handles
> both page and net_iov cases
>
> Documentation/networking/netmem.rst also says core code should avoid
> per-netmem-type branching. It also says new code must not assume that
> using a memory provider implies net_iov memory.
>
> The mp_hand_off flag lives in struct net_iov, and the hand_off() contract
> only covers net_iovs. So a provider that hands out page-backed netmems
> can't use this hook.
>
> Would a netmem.h helper fit better here? For example, something like
> netmem_mp_hand_off() that returns false for pages and is called from
> page_pool core.

Yeah, let's use a helper.