From: "Björn Töpel" <bjorn@kernel.org>
To: netdev-bot+sashiko@kernel.org
Cc: magnus.karlsson@intel.com, maciej.fijalkowski@intel.com,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, andrew+netdev@lunn.ch, ast@kernel.org,
daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
ilias.apalodimas@linaro.org, alexanderduyck@fb.com,
saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com,
leon@kernel.org, michael.chan@broadcom.com,
pavan.chebbi@broadcom.com, corbet@lwn.net, shuah@kernel.org,
bpf@vger.kernel.org, netdev@vger.kernel.org, stuclar@meta.com,
sdf@fomichev.me, horms@kernel.org, martin.lau@linux.dev,
almasrymina@google.com, song@kernel.org, yonghong.song@linux.dev,
jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
rdunlap@infradead.org, kernel-team@meta.com,
dimitri.daskalakis1@gmail.com, bobbyeshleman@meta.com,
mohsin.bashr@gmail.com, kees@kernel.org, leitao@debian.org,
maxime.chevallier@bootlin.com, cuitao@kylinos.cn,
vadim.fedorenko@linux.dev, mike.marciniszyn@gmail.com,
kuniyu@google.com, jiayuan.chen@linux.dev, mkarsten@uwaterloo.ca,
razor@blackwall.org, dw@davidwei.uk, asml.silence@gmail.com,
linux-rdma@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 06/15] xsk: Lend UMEM chunks to the page pools of a queue
Date: Wed, 25 Nov 2026 21:02:55 +0100 [thread overview]
Message-ID: <87pkvsn0gg.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <179561569684.3135.6558736307763434214@kernel.org>
netdev-bot+sashiko@kernel.org writes:
> Thank you for your contribution! Sashiko AI review found 6 potential
> issue(s) to consider.
>
> Critical: 0 · High: 2 · Medium: 2 · Low: 2
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [High] When a DRV_LAYOUT UMEM is shared across two queues of one netdev
> whose per-queue DMA devices differ, xsk_sink_bind() gives the second…
> - [High] xsk: xsk_sink_take_fill() recycles old-pool chunks instead of
> releasing them
> - [Medium] The 'chunk lent twice' check only works inside one sink, so a
> UMEM shared across queues or devices with XDP_SHARED_UMEM gets around…
> - [Medium] xsk: xp_assign_dev() blocks standard zero-copy when
> MP_XDP_ONLY is active
> - [Low] A DRV_LAYOUT bind accepts XDP_ZEROCOPY but delivers neither zero-
> copy TX nor a zero-copy report.
> - [Low] xsk_sink_nl_fill() returns 0 and emits no attribute, so a page
> pool backed by an AF_XDP sink cannot be identified in page-pool-…
>
> --
>
> xsk: Lend UMEM chunks to the page pools of a queue
>
> This adds a sink memory provider. With it, the chunks of a UMEM
> registered with XDP_UMEM_DRV_LAYOUT back the RX page pools of the bound
> queue, and the device lays out RX buffers in those chunks as it does in
> pages. FILL entries lend chunks to the kernel, the UMEM is DMA mapped
> once at bind, and binding requires a held native XDP program.
>
>> diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
>> index 5ec092f7cb6f7..7ece7d9e39376 100644
>> --- a/net/xdp/xsk_buff_pool.c
>> +++ b/net/xdp/xsk_buff_pool.c
>
> [ ... ]
>
>> @@ -211,6 +215,13 @@ int xp_assign_dev(struct xsk_buff_pool *pool,
>> */
>> hlist_add_head(&pool->dev_node, &netdev->xsk_pools);
>>
>> + if (pool->umem->flags & XDP_UMEM_DRV_LAYOUT) {
>> + err = xsk_sink_bind(pool, netdev, queue_id, flags);
>> + if (err)
>> + goto err_unbind;
>> + return 0;
>> + }
>
> [Severity: Medium]
> After xsk_sink_bind() installs the provider on one queue,
> dev_get_min_mp_channel_count() returns non-zero for the whole device.
> It checks mp_params.mp_priv on every RX queue and does not skip
> MP_XDP_ONLY providers. Further down, xp_assign_dev() still uses it to
> gate classic zero copy:
>
> if (dev_get_min_mp_channel_count(netdev)) {
> err = -EBUSY;
> goto err_unreg_pool;
> }
>
> So once a DRV_LAYOUT socket is bound to one queue, a regular AF_XDP
> socket on another queue of the same device fails with -EBUSY if it
> asked for XDP_ZEROCOPY. Without that flag it silently falls back to
> copy mode.
>
> Earlier in this series, dev_mp_blocks_xdp() replaced this helper in
> dev_xdp_install(), netif_xdp_propagate() and the ethtool rings path,
> because an MP_XDP_ONLY provider does not stop native XDP. Was this
> caller left out on purpose? If not, would dev_mp_blocks_xdp() be the
> right test here? A sink on the queue being bound is already caught by
> the earlier xsk_get_pool_from_qid() check, so the device-wide test
> only needs to catch providers that block XDP.
Not on purpose, will fix!
> [Severity: Low]
> This branch returns success without setting pool->umem->zc, so xsk_bind()
> ends up with xs->zc = false. Should a bind that passes XDP_ZEROCOPY be
> accepted here?
>
> xsk_sink_bind() rejects XDP_COPY but lets XDP_ZEROCOPY through:
>
> if (flags & XDP_COPY || !dev->queue_mgmt_ops ||
>
> TX on such a socket still goes through xsk_generic_xmit(). Also,
> getsockopt(XDP_OPTIONS) sets XDP_OPTIONS_ZEROCOPY only when xs->zc is
> true, so it reports copy mode even though RX is zero copy through the
> page pool.
>
> So a bind that asks for forced zero copy succeeds, TX runs in copy mode,
> and XDP_OPTIONS says the socket is not zero copy. The documentation patch
> later in the series says these sockets transmit in copy mode. It does not
> say that XDP_ZEROCOPY is accepted or what XDP_OPTIONS reports. Both become
> uAPI once registration accepts the flag. Could this be made consistent,
> either by rejecting XDP_ZEROCOPY or by reporting the RX mode?
It should be rejected. Will fix.
> [ ... ]
>
>> diff --git a/net/xdp/xsk_sink.c b/net/xdp/xsk_sink.c
>> new file mode 100644
>> index 0000000000000..b78116f25e712
>> --- /dev/null
>> +++ b/net/xdp/xsk_sink.c
>
> [ ... ]
>
>> +static u32 xsk_sink_take_fill(struct xsk_sink *sink, struct page_pool *pp)
>> +{
>
> [ ... ]
>
>> + for (i = 0; i < entries; i++) {
>> + addr = ring->desc[(cons + i) & mask];
>> + niov = &niovs[array_index_nospec((u32)(addr >> PAGE_SHIFT),
>> + nr)];
>> + /* A chunk lent twice would be in two places at once */
>> + if (unlikely(addr >= (u64)nr << PAGE_SHIFT ||
>> + READ_ONCE(niov->mp_state) == XSK_SINK_LENT)) {
>> + fq->invalid_descs++;
>> + continue;
>> + }
>
> [Severity: High]
> Once the next patch hands chunks back to userspace while they stay
> attached to the page pool that received into them, can this branch
> starve a new page pool on a queue restart?
>
> netdev_rx_queue_reconfig() calls ndo_queue_mem_alloc() and, for most
> drivers, ndo_queue_start() before ndo_queue_mem_free() destroys the
> old page pool. When the new pool pp first refills, every chunk that
> userspace posts back on FILL still has the old pool as owner, and
> sink->released is still empty.
>
> For each such chunk, xsk_sink_take_fill() marks it XSK_SINK_LENT,
> consumes the FILL entry and calls page_pool_put_unrefed_netmem() on
> the old pool. For a net_iov, __page_pool_page_can_be_recycled() is
> always true, so the chunk lands in owner->alloc.cache or owner->ring.
> page_pool_return_netmem(), and with it xsk_sink_release_netmem(),
> runs only when that ring is full. The chunk never reaches
> sink->released.
>
> So xsk_sink_take_fill() can consume up to PP_ALLOC_CACHE_SIZE FILL
> entries and still return 0. xsk_sink_take_released() then finds
> nothing, and xsk_sink_alloc_netmems() returns 0 and bumps
> queue_empty_descs even though FILL was not empty. The driver's ring
> fill in ndo_queue_mem_alloc() or ndo_queue_start() can then fail, or
> the new queue comes up without buffers.
>
> After page_pool_destroy() runs on the old pool, the chunks still held
> by userspace keep it inflight. Its ring is then scrubbed only from
> page_pool_release_retry(), once every DEFER_TIME. Until that happens,
> each refill of the new pool keeps pushing FILL chunks into the ring
> of a pool that is going away.
>
> Should a chunk whose owner is not pp be released to the sink, or moved
> to pp directly, rather than recycled into the old pool? Once a new
> pool exists for the queue, does the old pool ever need these chunks
> back?
Hmm, I'll try to address this.
> [Severity: Medium]
> Does this check still hold when the UMEM is shared with XDP_SHARED_UMEM
> across queues or devices?
>
> xp_assign_dev_shared() now sends DRV_LAYOUT UMEMs into xp_assign_dev()
> with flags = 0. A socket that shares the UMEM on another queue or device
> gets its own xsk_buff_pool and its own FILL ring. Then
> xsk_sink_bind()->xsk_sink_create() allocates a separate niov array over
> the same umem->chunks:
>
> sink->area.niovs = kvcalloc(nr, sizeof(*niov), GFP_KERNEL_ACCOUNT);
>
> The mp_state checked here belongs only to this sink, and it is checked
> under this sink's lock. Suppose userspace posts the same chunk address on
> both FILL rings. Each sink sees XSK_SINK_USER and lends the chunk. Two RX
> queues then DMA into the same UMEM page, and both sockets later get that
> chunk back as free.
>
> The commit message says:
>
> A chunk that is lent twice, or lies outside the UMEM, counts as an
> invalid FILL entry, so userspace cannot make the device use a chunk
> twice.
>
> Is this guarantee meant to cover the shared UMEM case? As far as I can
> tell, the end of the series refuses a second receiving socket only on the
> same pool. The cross-queue branch of xsk_bind() still creates a second,
> independent sink.
Partly. The check is per queue, but the kernel does not need more! Each
sink has its own net_iovs, so a chunk on two FILL rings leaves the
kernel state on both sinks consistent. Two devices then write the same
chunk, which only correupts the application's OWN data. The kernel keeps
nothing in the UMEM and takes no bounds from it.
Let's try to fix the commit message and af_xdp.rst to make it clearer.
> [ ... ]
>
>> +static int xsk_sink_nl_fill(void *mp_priv, struct sk_buff *rsp,
>> + struct netdev_rx_queue *rxq)
>> +{
>> + return 0;
>> +}
>
> [Severity: Low]
> Should this emit an attribute that identifies the provider?
> page_pool_nl_fill() calls:
>
> if (pool->mp_ops && pool->mp_ops->nl_fill(pool->mp_priv, rsp, NULL))
>
> That call is the only way a page-pool dump says which memory provider
> backs a pool. In devmem, mp_dmabuf_devmem_nl_fill() emits
> NETDEV_A_PAGE_POOL_DMABUF and NETDEV_A_QUEUE_DMABUF, and io_uring zcrx
> emits its IO_URING nest.
>
> With this stub, a page pool backed by UMEM chunks looks like an ordinary
> pool in page-pool-get dumps. Queue dumps still show NETDEV_A_QUEUE_XSK
> through rxq->pool, but the page-pool side has nothing. The function is
> unchanged at the end of the series.
Maybe add an empty xsk nest?
> [ ... ]
>
>> +int xsk_sink_bind(struct xsk_buff_pool *pool, struct net_device *dev,
>> + u16 queue_id, u16 flags)
>> +{
>
> [ ... ]
>
>> + /* 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);
>
> [Severity: High]
> Can the second queue end up with IOVAs that were mapped for a different
> struct device here?
>
> Take a DRV_LAYOUT UMEM shared across two queues of one netdev.
> xp_dma_map() first calls xp_find_dma_map(), which matches only on the
> netdev:
>
> if (dma_map->netdev == pool->netdev)
> return dma_map;
>
> xp_init_dma_info() then copies that map's dma_pages into the pool and
> sets pool->dev = dma_map->dev, which is the first queue's device. Nothing
> compares dma_dev with dma_map->dev.
>
> xsk_sink_create() builds every net_iov DMA address from
> pool->dma_pages[i], but stores sink->dev = dma_dev, the second queue's
> device. So this check in xsk_sink_init() passes:
>
> if (pp->p.dev != sink->dev || pp->p.offset + pp->p.max_len > PAGE_SIZE)
>
> The second queue's page pool then posts IOVAs from the first device's
> mapping to the second device. xsk_sink_alloc_netmems() also calls
> dma_sync_single_range_for_device(pp->p.dev, ...) on addresses that
> pp->p.dev never mapped.
>
> mlx5e_queue_get_dma_dev() returns ch->pdev, which differs per channel on
> multi-PF and socket-direct NICs. The mlx5 patch later in this series lets
> mlx5 RQs use this provider.
>
> If the two functions sit in separate IOMMU domains, won't the second
> device DMA to IOVAs that are unmapped in its domain, or mapped to
> something else there?
>
> The devmem bind path already rejects queues whose DMA devices differ, for
> this reason. Should xsk_sink_bind() do the same?
Probably. I'll try to address it.
pw-bot: cr
next prev parent reply other threads:[~2026-11-25 20:02 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 11:26 [PATCH net-next 00/15] xsk: Receive in the device's buffer layout Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 01/15] xdp: Let memory providers offer XDP a view of their net_iovs Björn Töpel
2026-11-25 14:07 ` netdev-bot+sashiko
2026-11-25 19:34 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 02/15] xdp: Keep the shared info of a buffer in kernel memory Björn Töpel
2026-11-25 14:07 ` netdev-bot+sashiko
2026-11-25 19:39 ` Björn Töpel
2026-11-25 15:17 ` Maciej Fijalkowski
2026-11-25 19:36 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 03/15] net: Add memory providers that only feed XDP Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 19:43 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 04/15] page_pool: Let memory providers take back net_iovs Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 19:45 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 05/15] xdp: Run programs on buffers that must not hold kernel structures Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 19:55 ` Björn Töpel
2026-11-25 15:22 ` Maciej Fijalkowski
2026-11-25 15:28 ` Maciej Fijalkowski
2026-11-25 19:50 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 06/15] xsk: Lend UMEM chunks to the page pools of a queue Björn Töpel
2026-11-24 14:34 ` Magnus Karlsson
2026-11-24 15:12 ` Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:02 ` Björn Töpel [this message]
2026-11-24 12:56 ` [PATCH net-next 07/15] xsk: Deliver to the socket in the device's buffer layout Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:11 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 08/15] xsk: Receive " Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:16 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 09/15] eth: fbnic: Support XDP redirect Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 10/15] eth: fbnic: Receive into XDP-only memory providers Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 11/15] net: Add netif_rxq_has_xdp_only_mp() Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 12/15] eth: mlx5e: Receive into XDP-only memory providers Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:26 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 13/15] eth: bnxt: " Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-25 20:33 ` Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 14/15] selftests: net: xsk: Test the device's RX buffer layout Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
2026-11-24 12:56 ` [PATCH net-next 15/15] Documentation: networking: Describe AF_XDP RX in the device's layout Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pkvsn0gg.fsf@all.your.base.are.belong.to.us \
--to=bjorn@kernel.org \
--cc=alexanderduyck@fb.com \
--cc=almasrymina@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrii@kernel.org \
--cc=asml.silence@gmail.com \
--cc=ast@kernel.org \
--cc=bobbyeshleman@meta.com \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=cuitao@kylinos.cn \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dimitri.daskalakis1@gmail.com \
--cc=dw@davidwei.uk \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=ilias.apalodimas@linaro.org \
--cc=jiayuan.chen@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kees@kernel.org \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=leitao@debian.org \
--cc=leon@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=martin.lau@linux.dev \
--cc=maxime.chevallier@bootlin.com \
--cc=mbloch@nvidia.com \
--cc=memxor@gmail.com \
--cc=michael.chan@broadcom.com \
--cc=mike.marciniszyn@gmail.com \
--cc=mkarsten@uwaterloo.ca \
--cc=mohsin.bashr@gmail.com \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavan.chebbi@broadcom.com \
--cc=razor@blackwall.org \
--cc=rdunlap@infradead.org \
--cc=saeedm@nvidia.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=stuclar@meta.com \
--cc=tariqt@nvidia.com \
--cc=vadim.fedorenko@linux.dev \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®