From: netdev-bot+sashiko@kernel.org
To: bjorn@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 07/15] xsk: Deliver to the socket in the device's buffer layout
Date: Wed, 25 Nov 2026 14:08:20 +0000 [thread overview]
Message-ID: <179561570080.3135.17027149687263984243@kernel.org> (raw)
In-Reply-To: <20261124125654.183091-7-bjorn@kernel.org>
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 1
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] xsk: page_pool_put_unrefed_netmem() in take_fill/scrub recycles
to old pool
- [Medium] Handed-off chunks can stay on sink->handed indefinitely, so
they never reach userspace.
- [Low] The new sink branch in xdp_do_redirect() (net/core/filter.c)
clears ri->map_id/map_type and returns xsk_sink_redirect()'s result…
--
xsk: Deliver to the socket in the device's buffer layout
This patch delivers redirected sink buffers to the receiving AF_XDP
socket of the queue. Each buffer becomes one RX descriptor, chained with
XDP_PKT_CONTD. Chunks go back to userspace with a new XDP_RX_CHUNK_FREE
flag, either on the descriptor of the buffer that freed the chunk or as an
empty descriptor posted from a hand-off list at a later flush or refill
of the queue NAPI.
> diff --git a/net/core/filter.c b/net/core/filter.c
> index d5774b2577e72..30b35d00e6b2f 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -4775,6 +4775,15 @@ int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,
> struct bpf_redirect_info *ri = bpf_net_ctx_get_ri();
> enum bpf_map_type map_type = ri->map_type;
>
> + /* A sink buffer goes to an AF_XDP socket of its queue */
> + if (static_branch_unlikely(&xdp_sink_key) && xdp_buff_is_sink(xdp)) {
> + void *fwd = ri->tgt_value;
> +
> + ri->map_id = 0;
> + ri->map_type = BPF_MAP_TYPE_UNSPEC;
> + return xsk_sink_redirect(xdp, map_type, fwd);
> + }
[Severity: Low]
Is it intended that sink redirects skip the redirect tracepoints? This
branch returns before __xdp_do_redirect_xsk() or
__xdp_do_redirect_frame() run. Those are where the existing redirect
paths emit their events:
net/core/filter.c:__xdp_do_redirect_xsk() {
...
_trace_xdp_redirect_map(dev, xdp_prog, fwd, map_type, map_id, ri->tgt_index);
return 0;
err:
_trace_xdp_redirect_map_err(dev, xdp_prog, fwd, map_type, map_id, ri->tgt_index, err);
...
}
As a result, neither xdp:xdp_redirect_map nor xdp:xdp_redirect_map_err
fires for sink buffers. That covers successful deliveries and every
error that xsk_sink_redirect() returns:
-EOPNOTSUPP for a non-XSKMAP target, such as a devmap or cpumap
redirect. Before this patch, that failed in __xdp_do_redirect_frame()
with a traced error.
-EINVAL for a target that is not the receiving socket.
-ENOBUFS when the RX ring is full.
-EINVAL for the drops in xsk_sink_rcv().
Tools that count redirects and redirect errors through these tracepoints,
such as xdp-monitor, would see nothing for sink queues. The commit
message doesn't mention this, and filter.c isn't changed later in the
series.
Could the tracepoints be emitted on this path too?
> +
> if (map_type == BPF_MAP_TYPE_XSKMAP)
> return __xdp_do_redirect_xsk(ri, dev, xdp, xdp_prog);
>
[ ... ]
> diff --git a/net/xdp/xsk_sink.c b/net/xdp/xsk_sink.c
> index b78116f25e712..9f1f7cf822667 100644
> --- a/net/xdp/xsk_sink.c
> +++ b/net/xdp/xsk_sink.c
[ ... ]
> @@ -172,12 +192,78 @@ static u32 xsk_sink_take_released(struct xsk_sink *sink, struct page_pool *pp,
> return n;
> }
>
> +/* Posts the chunks that page pools handed off as empty RX descriptors
> + * while the ring has room, and puts the rest back on the list. Their order
> + * does not matter, as userspace tells chunks by their address. Only one
> + * NAPI runs a queue at a time, so this is the only consumer of the list
> + * while the queue runs, and xsk_sink_scrub() the only one after it stopped.
> + *
> + * Context: the queue NAPI
> + */
> +static void xsk_sink_give_back(struct xsk_sink *sink, struct xdp_sock *xs)
> +{
> + struct llist_node *node, *last;
> + u32 idx;
> +
> + if (llist_empty(&sink->handed) || !xskq_prod_nb_free(xs->rx, 1))
> + return;
> +
> + node = llist_del_all(&sink->handed);
> + while (node && xskq_prod_nb_free(xs->rx, 1)) {
[ ... ]
> + }
> + if (!node)
> + return;
> +
> + /* The ring is full, so userspace is behind */
> + for (last = node; last->next; last = last->next)
> + ;
> + llist_add_batch(node, last, &sink->handed);
> +}
[ ... ]
> @@ -185,17 +271,34 @@ static netmem_ref xsk_sink_alloc_netmems(struct page_pool *pp, gfp_t gfp)
> if (WARN_ON_ONCE(pp->alloc.count))
> return 0;
>
[ ... ]
> + /* Pairs with xsk_sink_add_sock() */
> + xs = smp_load_acquire(&sink->xs);
> + if (xs && napi && !llist_empty(&sink->handed)) {
> + xsk_sink_give_back(sink, xs);
> + xskq_prod_submit(xs->rx);
> + xs->sk.sk_data_ready(&xs->sk);
> + }
> +
> spin_lock_bh(&sink->lock);
> n = xsk_sink_take_fill(sink, pp);
> n = xsk_sink_take_released(sink, pp, n);
> fq = sink->fq;
[Severity: High]
Does the put in xsk_sink_scrub(), and the one in xsk_sink_take_fill()
for a chunk of another page pool, ever reach xsk_sink_release_netmem()?
With this patch, a chunk that goes back to userspace through
xsk_sink_drop_buf() or xsk_sink_give_back() is in XSK_SINK_USER, but
netmem_get_pp() still points at the page pool that allocated it. When
userspace lends it again and a different page pool refills,
xsk_sink_take_fill() gives it to that owner:
net/xdp/xsk_sink.c:xsk_sink_take_fill() {
...
owner = netmem_get_pp(netmem);
if (owner && owner != pp) {
page_pool_put_unrefed_netmem(owner, netmem, -1, false);
continue;
}
...
}
page_pool_put_unrefed_netmem() does not release a net_iov, though.
__page_pool_page_can_be_recycled() is always true for net_iovs, so
__page_pool_put_page() keeps the chunk and it lands in owner->ring, or
in the owner's alloc cache when page_pool_napi_local() says so. Only
page_pool_return_netmem() calls the provider's release_netmem, and on
this path that only happens when the ring is full, or when
page_pool_scrub() of a destroyed pool empties the ring.
That seems to matter in three places:
On a queue restart where the driver fills the new queue before the
old page pool goes away, as bnxt does from bnxt_queue_mem_alloc()
and fbnic from fbnic_queue_start(), every chunk that userspace lends
again moves from FILL into the old pool's ring. sink->released is
empty at that point, so xsk_sink_alloc_netmems() can return 0 for
the new pool and count fq->queue_empty_descs, even with a full FILL
ring. Can that make bnxt fail the restart with -ENOMEM?
Where the old pool is destroyed first, as in mlx5e_queue_start(),
the chunks that userspace holds keep it in flight, so
page_pool_destroy() scrubs its ring once and leaves the rest to
release_dw. Chunks that the new pool takes from FILL after that
sit in the old ring until page_pool_release_retry() runs, up to
DEFER_TIME later.
On unbind, netif_mp_close_rxq() destroys the page pool while
XSK_SINK_USER chunks and the hand-off list are still charged to it.
xsk_sink_scrub() then runs from xsk_sink_stop() and puts them into
the ring of that destroyed pool. They only reach
xsk_sink_release_netmem() once the deferred release runs a second
later, and the page pool and the sink stay around until then.
Should the provider release these chunks itself, the way
page_pool_return_netmem() would, instead of putting them through the
recycling path? Or is there another way for the owner to let go of a
chunk that it lent to userspace?
[ ... ]
> if (napi && fq && sink->pool->uses_need_wakeup) {
> - if (n)
> + if (n && llist_empty(&sink->handed))
> xsk_clear_rx_need_wakeup(sink->pool);
> else
> xsk_set_rx_need_wakeup(sink->pool);
[ ... ]
> @@ -226,12 +329,61 @@ static bool xsk_sink_release_netmem(struct page_pool *pp, netmem_ref netmem)
> return false;
> }
>
> +/* The last put of a chunk with a buffer in userspace: it goes back to
> + * userspace, still charged to @pp. The next flush or refill of the queue
> + * NAPI posts its empty descriptor.
> + */
> +static bool xsk_sink_hand_off(struct page_pool *pp, netmem_ref netmem)
> +{
> + struct net_iov *niov = netmem_to_net_iov(netmem);
> + struct xsk_sink *sink = pp->mp_priv;
> + struct llist_node *node;
> +
> + niov->mp_hand_off = false;
> + node = &sink->nodes[net_iov_idx(niov)];
> + llist_add(node, &sink->handed);
> + return true;
> +}
[Severity: Medium]
Can chunks stay on sink->handed indefinitely?
The commit message says that a handed-off chunk "gives it back at the
next flush of the queue NAPI, or at a refill while no packets come". It
also says that "the refill asks the socket for a kick while any chunk
waits, so that a reader that fell behind gets them once it has drained
its ring".
While the queue runs, only two places take chunks from sink->handed.
The first is xsk_sink_flush(). It is only reached from xsk_flush(), and
only for a socket on the XSKMAP flush list:
net/xdp/xsk.c:xsk_flush() {
struct xsk_sink *sink = xs->pool->sink;
if (sink)
xsk_sink_flush(sink);
...
}
A socket only joins that list after a successful xsk_sink_redirect() in
the same poll.
The second is xsk_sink_alloc_netmems(). The page pool only calls it on
the slow path, when both the alloc cache and the ptr_ring are empty.
In mlx5, xdp_do_flush() runs inside mlx5e_poll_rx_cq() through
mlx5e_xdp_rx_poll_complete(). The WQE pages are released later in the
same poll:
mlx5e_post_rx_mpwqes()
mlx5e_free_rx_mpwqe()
mlx5e_page_release_fragmented()
page_pool_put_unrefed_netmem()
page_pool_hand_off()
xsk_sink_hand_off()
llist_add(node, &sink->handed)
So the final put of a chunk whose mp_hand_off was set in
xsk_sink_drop_buf() always comes after that poll's flush.
The other pages freed there go straight into the pp cache with
allow_direct. As a result, the refill in the same loop usually doesn't
reach alloc_netmems either.
When the RX ring is full, xsk_sink_give_back() puts the leftover chunks
back on the list. While the ring stays full, xsk_sink_rcv() returns
-ENOBUFS, so the socket never joins the flush list. Dropped buffers also
keep the pp cache from running dry.
In both cases, a later NAPI run with no successful delivery and a
non-empty cache posts none of the waiting chunks. That includes an idle
link, and the NAPI run that the next patch's xsk_sink_wakeup() starts
through napi_schedule().
The need_wakeup decision in xsk_sink_alloc_netmems() quoted above has a
related gap, because it is only evaluated at refill time.
If the refill ran before a late hand-off, the flag stays cleared and
userspace is not asked to kick.
If the refill saw a non-empty list, the flag stays set. Each poll() or
recvmsg() then kicks a NAPI that can't post the chunks.
The chunks seem to come back only when another packet is delivered, or
when the device runs its page pool cache dry. Could an application that
waits for XDP_RX_CHUNK_FREE stall for as long as the link is idle? For
example, one that waits to refill the fill ring or to reuse chunks for
TX.
This also looks like it remains at the end of the series. The fbnic
patch moves its flush after the refill, but mlx5 and bnxt do not.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124112707.118678-1-bjorn%40kernel.org
next prev parent reply other threads:[~2026-11-25 14:08 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 11:26 [PATCH net-next 00/15] xsk: Receive " 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-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-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-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-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-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-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 [this message]
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-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-24 12:56 ` [PATCH net-next 13/15] eth: bnxt: " Björn Töpel
2026-11-25 14:08 ` netdev-bot+sashiko
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=179561570080.3135.17027149687263984243@kernel.org \
--to=netdev-bot+sashiko@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=bjorn@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@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®