Re: [PATCH net-next v1 04/11] xsk: Allocate UMEM chunks through page_pool
From: Björn Töpel
Date: Sun Nov 15 2026 - 13:56:07 EST
Mina Almasry <almasrymina@xxxxxxxxxx> writes:
> On Tue, Nov 10, 2026 at 2:21 AM Björn Töpel <bjorn@xxxxxxxxxx> wrote:
>> diff --git a/include/net/xdp.h b/include/net/xdp.h
>> index 1105bb9e3292..5ab7802ac4e1 100644
>> --- a/include/net/xdp.h
>> +++ b/include/net/xdp.h
>> @@ -368,7 +368,7 @@ static inline bool xdp_buff_add_frag(struct xdp_buff *xdp, netmem_ref netmem,
>>
>> if (unlikely(netmem_is_pfmemalloc(netmem)))
>> xdp_buff_set_frag_pfmemalloc(xdp);
>> - if (unlikely(netmem_is_net_iov(netmem)))
>> + if (unlikely(netmem_is_net_iov(netmem) && !netmem_address(netmem)))
>> xdp_buff_set_frag_unreadable(xdp);
>>
>
>
> netmem_is_net_iov() check became redundant.
Hmm, not quite... netmem_address() is also NULL for a highmem page
without a mapping, and the stack reads those through kmap, so they
aren't unreadable. The net_iov test keeps them out. I'll add a comment.
>> diff --git a/net/xdp/xsk_pp.c b/net/xdp/xsk_pp.c
>> new file mode 100644
>> index 000000000000..fdd55265a6cd
>> --- /dev/null
>> +++ b/net/xdp/xsk_pp.c
>> @@ -0,0 +1,246 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* AF_XDP UMEM as a page pool memory provider
>> + *
>> + * Each aligned UMEM chunk is a readable net_iov with one owner at a time:
>> + *
>> + * userspace --FILL--> page pool --release--> reuse --alloc--> page pool
>> + * ^ |
>> + * +-----RX ring-------+
>> + */
>> +
>> +#include <net/page_pool/helpers.h>
>> +#include <net/page_pool/memory_provider.h>
>> +#include <net/xdp_sock_drv.h>
>> +
>> +#include "xsk.h"
>> +#include "xsk_queue.h"
>> +
>> +enum xsk_pp_chunk {
>> + XSK_PP_USER, /* owned by userspace */
>> + XSK_PP_POOL, /* owned by a page pool */
>> + XSK_PP_REUSE, /* on the reuse stack */
>> +};
>
> maybe should be xsk_mp_chunk.
>
> But also, why is this 3? Usually the mp's track allocated and free. I
> assume PP_REUSE is actually free, but I'm curious why it matters to
> your mp whether the pool or the userspace holds the memory (or whether
> the net stack holds it. Can't it hold it?)
REUSE is free, yes. USER and POOL are both allocated, but userspace
gives chunks back by writing addresses to FILL, and it can write any
address, also one of a chunk the kernel still owns. Taking that entry
would hand the device the same chunk twice. So the provider only takes
FILL entries for chunks in USER, and drops the rest. io_uring zcrx
checks the same with user_refs, and devmem with the socket's token
xarray.
The stack can't hold a chunk, see my reply on patch 3.
>> +
>> +struct xsk_pp {
>
> maybe xsk_mp? this is a memory provider right?
Yes, I'll rename it to xsk_mp, the enum too.
Björn