From: sashiko-bot@kernel.org
To: "Björn Töpel" <bjorn@kernel.org>, bpf@vger.kernel.org
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH net-next 08/15] xsk: Receive in the device's buffer layout
Date: Wed, 25 Nov 2026 13:00:14 +0000 [thread overview]
Message-ID: <sashiko-outbox-233418@kernel.org> (raw)
In-Reply-To: <20261124125654.183091-8-bjorn@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] xsk: skipped synchronous unbind in xsk_sink_release() for
TX-only pool
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] xsk: data race on pool->cached_need_wakeup in
xsk_set_rx_need_wakeup() [1]
--
commit 66e818b77c20713dcc88b2972bf6bf3dfff915da
Author: Björn Töpel <bjorn@kernel.org>
xsk: Receive in the device's buffer layout
This commit wires up XDP_UMEM_DRV_LAYOUT so AF_XDP sockets can register a UMEM
in the device's buffer layout, install the sink memory provider on bind, and
wake the queue NAPI from recvmsg() and poll().
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 0753fac8d4a85..c015894a6ccba 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -55,7 +55,8 @@ void xsk_set_rx_need_wakeup(struct xsk_buff_pool *pool)
> return;
>
> pool->fq->ring->flags |= XDP_RING_NEED_WAKEUP;
> - pool->cached_need_wakeup |= XDP_WAKEUP_RX;
> + WRITE_ONCE(pool->cached_need_wakeup,
> + pool->cached_need_wakeup | XDP_WAKEUP_RX);
> }
> EXPORT_SYMBOL(xsk_set_rx_need_wakeup);
>
> @@ -72,7 +73,8 @@ void xsk_set_tx_need_wakeup(struct xsk_buff_pool *pool)
> }
> rcu_read_unlock();
>
> - pool->cached_need_wakeup |= XDP_WAKEUP_TX;
> + WRITE_ONCE(pool->cached_need_wakeup,
> + pool->cached_need_wakeup | XDP_WAKEUP_TX);
> }
> EXPORT_SYMBOL(xsk_set_tx_need_wakeup);
>
> @@ -82,7 +84,8 @@ void xsk_clear_rx_need_wakeup(struct xsk_buff_pool *pool)
> return;
>
> pool->fq->ring->flags &= ~XDP_RING_NEED_WAKEUP;
> - pool->cached_need_wakeup &= ~XDP_WAKEUP_RX;
> + WRITE_ONCE(pool->cached_need_wakeup,
> + pool->cached_need_wakeup & ~XDP_WAKEUP_RX);
> }
> EXPORT_SYMBOL(xsk_clear_rx_need_wakeup);
>
> @@ -99,7 +102,8 @@ void xsk_clear_tx_need_wakeup(struct xsk_buff_pool *pool)
> }
> rcu_read_unlock();
>
> - pool->cached_need_wakeup &= ~XDP_WAKEUP_TX;
> + WRITE_ONCE(pool->cached_need_wakeup,
> + pool->cached_need_wakeup & ~XDP_WAKEUP_TX);
> }
> EXPORT_SYMBOL(xsk_clear_tx_need_wakeup);
[Severity: High]
This problem wasn't introduced by this patch, but can concurrent updates to
pool->cached_need_wakeup lose wakeup flags [1] when RX and TX run in
separate NAPI contexts?
On drivers with separate RX and TX NAPI instances sharing the same
xsk_buff_pool (such as virtio_net), WRITE_ONCE() still performs a non-atomic
read-modify-write on pool->cached_need_wakeup:
CPU0 (RX NAPI) CPU1 (TX NAPI)
xsk_set_rx_need_wakeup() xsk_set_tx_need_wakeup()
read pool->cached_need_wakeup
read pool->cached_need_wakeup
write XDP_WAKEUP_RX
write XDP_WAKEUP_TX <-- drops RX flag
Dropping XDP_WAKEUP_RX or XDP_WAKEUP_TX stops userspace from waking the
queue to replenish the FILL ring or drain the TX ring, stalling packet
processing.
[ ... ]
> @@ -1585,6 +1605,29 @@ static void xsk_delete_from_maps(struct xdp_sock *xs)
> }
> }
>
> +/* The pool may outlive the socket, see xp_put_pool(). A queue in the
> + * device's buffer layout stops receiving when its receiving socket goes,
> + * so that its program can go right after.
> + */
> +static void xsk_sink_release(struct xdp_sock *xs)
> +{
> + struct xsk_buff_pool *pool = READ_ONCE(xs->pool);
> + struct net_device *dev;
> +
> + if (!pool || !READ_ONCE(pool->sink))
> + return;
> +
> + rtnl_lock();
> + dev = pool->netdev;
> + if (dev) {
> + netdev_lock_ops(dev);
> + if (pool->sink && xsk_sink_sock(pool->sink) == xs)
> + xsk_sink_unbind(pool);
> + netdev_unlock_ops(dev);
> + }
> + rtnl_unlock();
> +}
[Severity: Medium]
Does xsk_sink_release() skip xsk_sink_unbind() when a TX-only socket creates
a pool with XDP_UMEM_DRV_LAYOUT and closes before any RX socket binds?
xsk_bind() allows a socket with xs->tx set and xs->rx == NULL to create a
pool, and xp_assign_dev() unconditionally calls xsk_sink_bind() when
XDP_UMEM_DRV_LAYOUT is set. Because xsk_sink_add_sock() only sets sink->xs
when xs->rx is non-NULL, sink->xs remains NULL:
net/xdp/xsk_sink.c:xsk_sink_add_sock() {
if (xs->rx && !sink->xs) {
/* The NAPI acquires the socket once it is set up */
smp_store_release(&sink->xs, xs);
}
}
When the TX-only socket is closed, xsk_sink_sock(pool->sink) == xs is false
(NULL != xs), so xsk_sink_unbind() is not run synchronously in xsk_release().
Because AF_XDP sockets use SOCK_RCU_FREE and xp_put_pool() defers pool
destruction to a workqueue, the MP_XDP_ONLY provider stays attached after
close() returns and causes an immediate XDP program detach to fail with
-EBUSY.
[1] https://sashiko.dev/#/bug/linux-3603ff9e-34c0-4710-bf99-5f028a2aa37d
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124112707.118678-1-bjorn@kernel.org?part=8
next prev parent reply other threads:[~2026-11-25 13:00 UTC|newest]
Thread overview: 26+ 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 13:00 ` sashiko-bot
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-25 13:00 ` sashiko-bot
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 13:00 ` sashiko-bot
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 13:00 ` sashiko-bot
2026-11-24 12:56 ` [PATCH net-next 08/15] xsk: Receive " Björn Töpel
2026-11-25 13:00 ` sashiko-bot [this message]
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 13:00 ` sashiko-bot
2026-11-24 12:56 ` [PATCH net-next 13/15] eth: bnxt: " Björn Töpel
2026-11-25 13:00 ` sashiko-bot
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 13:00 ` sashiko-bot
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=sashiko-outbox-233418@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=sashiko-reviews@lists.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