Re: [PATCH net-next 06/15] xsk: Lend UMEM chunks to the page pools of a queue

From: Björn Töpel

Date: Tue Nov 24 2026 - 10:13:26 EST


Magnus Karlsson <magnus.karlsson@xxxxxxxxx> writes:

> On Tue, 24 Nov 2026 at 13:59, Björn Töpel <bjorn@xxxxxxxxxx> wrote:
>> +/* RX buffers follow the device's layout: a page-sized chunk may hold
>> + * several of them, a packet may span chunks, and the device picks the
>> + * offsets. A FILL entry lends a chunk to the kernel. Needs aligned
>> + * page-sized chunks and no headroom.
>> + */
>> +#define XDP_UMEM_DRV_LAYOUT (1 << 4)
>
> First of all, this looks a lot better than the previous patch set.
> Much simpler from a driver point of view, fewer changes to core
> networking code, and that with just a small change/extension to the
> uAPI.

Thanks, I do as well. Credits to Kuba that took me down this path.

> But I do not think this name is good. Most users of this API do not
> care about driver details such as the layout. Why not call it
> something that has to do with what has changed from the user's point
> of view? Previously we had implicit ownership transfers. You got a
> packet in Rx, you own the chunk. Now we have explicit ownership
> transfer. You do not own the chunk the packet is in, unless you get
> the new flag back (introduced later). So something with "explicit
> ownership" or something similar would be better. Or focus the name on
> that you can support larger chunks, but that is for later patches so
> might not be the best choice.

Magnus... naming is hard! Good point. There are two things in play; You
cannot choose your geometry, and explicit ownership.

XDP_UMEM_EXPLICIT_OWNERSHIP?
XDP_UMEM_EXPLICIT_RELEASE?
XDP_UMEM_CHUNK_COMPLETION?
XDP_UMEM_PACKED_RX?

I'm leaning towards XDP_UMEM_EXPLICIT_RELEASE, and naming the flag
XDP_RX_CHUNK_RELEASED?

>> diff --git a/net/xdp/xsk_sink.c b/net/xdp/xsk_sink.c
>> new file mode 100644
>> index 000000000000..b78116f25e71
>> --- /dev/null
>> +++ b/net/xdp/xsk_sink.c

>> +static netmem_ref xsk_sink_alloc_netmems(struct page_pool *pp, gfp_t gfp)
>> +{
>> + struct xsk_sink *sink = pp->mp_priv;
>> + /* The NAPI owns the need_wakeup flags */
>> + bool napi = in_softirq() && !in_hardirq();
>> + struct xsk_queue *fq;
>> + dma_addr_t dma;
>> + u32 i, n;
>> +
>> + /* The page pool refills only an empty cache */
>> + if (WARN_ON_ONCE(pp->alloc.count))
>> + return 0;
>> +
>> + spin_lock_bh(&sink->lock);
>> + n = xsk_sink_take_fill(sink, pp);
>> + n = xsk_sink_take_released(sink, pp, n);
>> + fq = sink->fq;
>> + /* Ask for kicks only while FILL runs dry, as zero copy drivers do: a
>> + * kick schedules the NAPI, which a busy poller would rather run
>> + * itself. Process context refills new queues only and leaves the
>> + * flags to their NAPI and to bind.
>> + */
>> + if (napi && fq && sink->pool->uses_need_wakeup) {
>
> Was not need_wakeup a requirement for using this new mode? If so, why
> not just set it somewhere and not test it after that?

Argh, indeed. 08/15 makes XDP_USE_NEED_WAKEUP mandatory and removes both
checks when it enables the mode. I'll move that so the requirement is
clear from the start. Good catch.

>> +int xsk_sink_bind(struct xsk_buff_pool *pool, struct net_device *dev,
>> + u16 queue_id, u16 flags)
>> +{
>> + u32 needed = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT;
>> + struct pp_memory_provider_params p = { .mp_ops = &xsk_sink_ops };
>> + struct device *dma_dev;
>> + struct xsk_sink *sink;
>> + int err;
>> +
>> + if (flags & XDP_USE_SG)
>> + needed |= NETDEV_XDP_ACT_RX_SG;
>> + if (flags & XDP_COPY || !dev->queue_mgmt_ops ||
>> + (dev->xdp_features & needed) != needed ||
>> + queue_id >= dev->real_num_rx_queues)
>> + return -EOPNOTSUPP;
>> +
>> + /* The program of another device would see a leased queue's packets */
>> + if (netif_rxq_is_leased(dev, queue_id))
>> + return -EOPNOTSUPP;
>> +
>> + /* The device of the queue's page pools, which may differ per queue */
>> + dma_dev = netdev_queue_get_dma_dev(dev, queue_id, NETDEV_QUEUE_TYPE_RX);
>> + if (!dma_dev)
>> + return -EOPNOTSUPP;
>> +
>> + /* Without a program, drivers would build skbs from the buffers */
>> + if (!dev_xdp_drv_prog_held(dev))
>> + return -ENOENT;
>> +
>> + err = xp_dma_map(pool, dma_dev, XSK_SINK_DMA_ATTR, pool->umem->pgs,
>> + pool->umem->npgs);
>> + if (err)
>> + return err;
>> +
>> + sink = xsk_sink_create(pool, dma_dev);
>> + if (IS_ERR(sink)) {
>> + xp_dma_unmap(pool, XSK_SINK_DMA_ATTR);
>> + return PTR_ERR(sink);
>> + }
>> +
>> + /* Until the first refill of the NAPI: the queue may need FILL to
>> + * start. Set before the NAPI runs, which owns the flags after that.
>> + */
>> + if (pool->uses_need_wakeup)
>> + xsk_set_rx_need_wakeup(pool);
>> +
>> + /* The core keeps sink buffers to the socket once the queue runs */
>> + static_branch_inc(&xdp_sink_key);
>> + sink->rxq = __netif_get_rx_queue(dev, queue_id);
>> + pool->sink = sink;
>> + p.mp_priv = sink;
>> + err = netif_mp_open_rxq(dev, queue_id, &p, NULL);
>> + if (err) {
>> + xsk_sink_detach(pool);
>> + return err;
>> + }
>> +
>> + return 0;
>> +}
>
> At a first glance it feels like some of this code could be shared with
> the current bind, but I guess you have already tried and it is not
> worth it, or? The commonality seems somewhat spread out.

Pool setup and registration are already shared in xp_assign_dev(). The
main difference is how we start the queue. Classic ZC calls the driver
with XDP_SETUP_XSK_POOL; this path maps the UMEM and installs a memory
provider with netif_mp_open_rxq().

I'll look for checks we can share without mixing the two setup and
unwind paths.


Thanks for having a look!
Björn