From: "Björn Töpel" <bjorn@kernel.org>
To: Magnus Karlsson <magnus.karlsson@gmail.com>
Cc: Magnus Karlsson <magnus.karlsson@intel.com>,
Maciej Fijalkowski <maciej.fijalkowski@intel.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Alexander Duyck <alexanderduyck@fb.com>,
Saeed Mahameed <saeedm@nvidia.com>,
Tariq Toukan <tariqt@nvidia.com>, Mark Bloch <mbloch@nvidia.com>,
Leon Romanovsky <leon@kernel.org>,
Michael Chan <michael.chan@broadcom.com>,
Pavan Chebbi <pavan.chebbi@broadcom.com>,
Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org>,
bpf@vger.kernel.org, netdev@vger.kernel.org,
Stuart Clark <stuclar@meta.com>,
Stanislav Fomichev <sdf@fomichev.me>,
Simon Horman <horms@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Mina Almasry <almasrymina@google.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Randy Dunlap <rdunlap@infradead.org>,
kernel-team@meta.com,
Dimitri Daskalakis <dimitri.daskalakis1@gmail.com>,
Bobby Eshleman <bobbyeshleman@meta.com>,
Mohsin Bashir <mohsin.bashr@gmail.com>,
Kees Cook <kees@kernel.org>, Breno Leitao <leitao@debian.org>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
Tao Cui <cuitao@kylinos.cn>,
Vadim Fedorenko <vadim.fedorenko@linux.dev>,
"Mike Marciniszyn (Meta)" <mike.marciniszyn@gmail.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
Jiayuan Chen <jiayuan.chen@linux.dev>,
Martin Karsten <mkarsten@uwaterloo.ca>,
Nikolay Aleksandrov <razor@blackwall.org>,
David Wei <dw@davidwei.uk>,
Pavel Begunkov <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: Tue, 24 Nov 2026 16:12:56 +0100 [thread overview]
Message-ID: <875wxmp8jr.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <CAJ8uoz3f2MPpDevbMY3q_Nx=SQ2Om1ojAxBTsYhNw1V9_NXQMA@mail.gmail.com>
Magnus Karlsson <magnus.karlsson@gmail.com> writes:
> On Tue, 24 Nov 2026 at 13:59, Björn Töpel <bjorn@kernel.org> 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
next prev parent reply other threads:[~2026-11-24 15:12 UTC|newest]
Thread overview: 18+ 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-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-24 12:56 ` [PATCH net-next 03/15] net: Add memory providers that only feed XDP 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-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-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 [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-24 12:56 ` [PATCH net-next 08/15] xsk: Receive " 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-24 12:56 ` [PATCH net-next 13/15] eth: bnxt: " 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-24 12:56 ` [PATCH net-next 15/15] Documentation: networking: Describe AF_XDP RX in the device's layout Björn Töpel
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=875wxmp8jr.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@gmail.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@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®