From: sashiko-bot@kernel.org
To: "Satish Kharat" <satishkh@cisco.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH RFC net-next 10/12] net: enic: add AF_XDP zero-copy RX and TX
Date: Wed, 02 Dec 2026 01:16:20 +0000 [thread overview]
Message-ID: <sashiko-outbox-244593@kernel.org> (raw)
In-Reply-To: <20261130-enic-xdp-rfc-p1-20261130-v1-10-3be5458c9118@cisco.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] net: enic: TX need_wakeup not restored across stop/open in
enic_open()
- [High] net: enic: RX stall in enic_open() when XSK fill ring is
initially empty
- [High] net: enic: list corruption in enic_rq_alloc_buf() via
enic_xsk_buff_init()
- [Medium] net: enic: per-descriptor lock and false wakeup in
enic_rq_alloc_buf()
- [Medium] net: enic: per-packet XSK_RX TX completion locking and
enic_rq false sharing
- [Low] net: enic: unconditional spin_lock_bh() in
enic_xsk_rx_tx_flush() on RX poll
--
commit 867968ead5e974fd4a4138cb6db78c85d73c1863
Author: Satish Kharat <satishkh@cisco.com>
net: enic: add AF_XDP zero-copy RX and TX
This commit adds AF_XDP zero-copy receive and transmit support to the enic
driver, including UMEM pool setup, XSK RX buffer allocation and XDP
action handling, zero-copy TX batching, and ndo_xsk_wakeup support.
> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index 4c1ea75654bb0..d14bc66f4178e 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c
[ ... ]
> @@ -1982,9 +2002,11 @@ static int enic_open(struct net_device *netdev)
>
> /* enable rq before updating rq desc */
> vnic_rq_enable(&enic->rq[i].vrq);
> - vnic_rq_fill(&enic->rq[i].vrq, enic_rq_alloc_buf);
> + err = vnic_rq_fill(&enic->rq[i].vrq, enic_rq_alloc_buf);
> + enic_xsk_rx_refill_done(&enic->rq[i], err);
> /* Need at least one buffer on ring to get going */
> - if (vnic_rq_desc_used(&enic->rq[i].vrq) == 0) {
> + if (!enic->rq[i].xsk_rx_active &&
> + vnic_rq_desc_used(&enic->rq[i].vrq) == 0) {
> netdev_err(netdev, "Unable to alloc receive buffers\n");
> err = -ENOMEM;
> goto err_out_free_rq;
[Severity: High]
Can RX on queue i permanently stall when an XSK pool is bound without
XDP_USE_NEED_WAKEUP and the fill ring is initially empty during
enic_open()?
When xsk_buff_alloc() returns NULL here, vnic_rq_fill() returns -ENOMEM
with zero descriptors posted and enic_open() continues. Because
xsk_uses_need_wakeup(erq->xsk_pool) is false, enic_rq_alloc_buf() does not
set XDP_WAKEUP_RX in pool->cached_need_wakeup, and enic_open() never
schedules enic->napi[i] after napi_enable(&enic->napi[i]).
With no descriptors posted to the hardware RQ, no RX interrupt can fire.
Userspace __xsk_recvmsg() sees (pool->cached_need_wakeup & XDP_WAKEUP_RX)
== 0 and skips ndo_xsk_wakeup, while xsk_poll() only passes XDP_WAKEUP_TX,
which in MSI-X mode schedules only the WQ NAPI. As a result,
vnic_rq_fill() is never retried. Should enic_open() schedule
enic->napi[i] after napi_enable() when vnic_rq_fill() fails and
!enic_xsk_rx_need_wakeup(&enic->rq[i])?
> diff --git a/drivers/net/ethernet/cisco/enic/enic_rq.c b/drivers/net/ethernet/cisco/enic/enic_rq.c
> index 350e42c556ade..f30de4757613d 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_rq.c
> +++ b/drivers/net/ethernet/cisco/enic_rq.c
> @@ -282,6 +283,31 @@ int enic_rq_alloc_buf(struct vnic_rq *rq)
> struct vnic_rq_buf *buf = rq->to_use;
> struct page *page;
> unsigned int truesize = len + headroom;
> + struct xdp_buff *xdp;
> +
> + if (erq->xsk_rx_active) {
> + xdp = buf->os_buf;
> + if (!xdp) {
> + /* Set before checking the fill ring so userspace cannot
> + * miss need_wakeup when the ring is empty.
> + */
> + if (xsk_uses_need_wakeup(erq->xsk_pool))
> + enic_xsk_set_rx_need_wakeup(erq);
> + xdp = xsk_buff_alloc(erq->xsk_pool);
> + if (unlikely(!xdp)) {
> + rqstats->xsk_fill_empty++;
> + return -ENOMEM;
> + }
> + enic_xsk_buff_init(xdp);
> + }
[Severity: High]
Can enic_xsk_buff_init(xdp) corrupt rq->xsk_tx_done when the userspace fill
ring contains duplicate chunk addresses in aligned UMEM mode?
In aligned mode, xsk_buff_alloc() indexes directly into pool->heads[] by
the chunk address from the fill ring, so duplicate fill-ring entries return
the same struct xdp_buff pointer. If that buffer was previously
transmitted via XDP_TX and completed onto rq->xsk_tx_done, a later
vnic_rq_fill() popping the duplicate address reinitializes xskb->tx_done in
place without unlinking it or holding rq->xsk_tx_done_lock:
CPU0 (RQ NAPI) CPU1 (WQ NAPI)
enic_poll_msix_rq()
enic_xsk_rx_tx_flush()
...
enic_free_wq_buf()
enic_xsk_rx_tx_complete(xdp)
list_add_tail(&xskb->tx_done,
&rq->xsk_tx_done)
vnic_rq_fill()
enic_rq_alloc_buf()
xdp = xsk_buff_alloc(...)
enic_xsk_buff_init(xdp)
INIT_LIST_HEAD(&xskb->tx_done)
...
enic_poll_msix_rq()
enic_xsk_rx_tx_flush()
list_splice_init(&rq->xsk_tx_done, &done)
list_for_each_entry_safe(...) <-- spins forever in softirq
Overwriting xskb->tx_done.next to point to itself while linked on
rq->xsk_tx_done causes list_for_each_entry_safe() in enic_xsk_rx_tx_flush()
to loop endlessly when another entry follows xskb.
[Severity: Medium]
Does calling enic_xsk_set_rx_need_wakeup() before xsk_buff_alloc() on every
descriptor acquire rq->xsk_wakeup_lock per packet and advertise a false
XDP_RING_NEED_WAKEUP while the fill ring is non-empty?
vnic_rq_fill() invokes enic_rq_alloc_buf() in a per-descriptor loop, so
refilling N descriptors takes and releases spin_lock_bh(&rq->xsk_wakeup_lock)
N + 1 times (including enic_xsk_rx_refill_done()), contending with
enic_xsk_tx_service() on the WQ NAPI. It also leaves XDP_RING_NEED_WAKEUP
set in shared fill-ring flags across the entire refill loop and its MMIO
doorbell writes before enic_xsk_rx_refill_done() clears it, causing a
concurrent userspace producer to issue unnecessary wakeup syscalls on a
non-empty fill ring. Setting rx_need_wakeup only when xsk_buff_alloc()
returns NULL (and rechecking xsk_pool_can_alloc() under the lock) would
avoid both the per-descriptor lock and the transient wakeup flag.
> diff --git a/drivers/net/ethernet/cisco/enic/enic_xdp.c b/drivers/net/ethernet/cisco/enic/enic_xdp.c
> index dbb5f0e6c14f6..b6989a4dd79b3 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_xdp.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_xdp.c
[ ... ]
> @@ -225,6 +282,345 @@ bool enic_xdp_run(struct enic *enic, struct enic_rq *rq,
[ ... ]
> +bool enic_xsk_tx_service(struct enic *enic, unsigned int wq_index)
> +{
[ ... ]
> +out_need_wakeup:
> + spin_unlock(&wq->lock);
> + if (!done && xsk_uses_need_wakeup(pool)) {
> + spin_lock_bh(&enic->rq[wq_index].xsk_wakeup_lock);
> + xsk_clear_tx_need_wakeup(pool);
> + spin_unlock_bh(&enic->rq[wq_index].xsk_wakeup_lock);
> + }
> +
> + return done;
> +}
[Severity: High]
Can clearing TX need_wakeup here permanently wedge AF_XDP TX if the
interface goes through a stop/open cycle while the WQ NAPI is still
polling?
When enic_xsk_tx_service() posts a full batch (sent == capacity), done is
false and xsk_clear_tx_need_wakeup(pool) clears XDP_RING_NEED_WAKEUP in
the TX ring and XDP_WAKEUP_TX in pool->cached_need_wakeup because NAPI
expects to keep polling. If a stop/open cycle then runs across all queues
(for example via enic_xdp_reload_pool_swap() when binding or unbinding a
pool on another queue, enic_xdp_reload(), or _enic_change_mtu()),
__enic_stop() disables all NAPIs and cleans all in-flight WQ descriptors,
and enic_open() re-enables the WQ NAPIs without restoring
xsk_set_tx_need_wakeup(pool) or scheduling the WQ NAPI.
After enic_open(), the WQ NAPI is idle with no descriptors in flight to
raise a completion interrupt, and __xsk_sendmsg() and xsk_poll() see
(pool->cached_need_wakeup & XDP_WAKEUP_TX) == 0 and never call
ndo_xsk_wakeup. Restoring xsk_set_tx_need_wakeup(pool) (or scheduling the
WQ NAPI) for bound pools during enic_open() would prevent this stall.
> +
> +static void enic_xsk_schedule_napi(struct napi_struct *napi)
> +{
> + if (!napi_if_scheduled_mark_missed(napi))
> + napi_schedule(napi);
> +}
> +
> +void enic_xsk_rx_tx_complete(struct enic *enic, struct xdp_buff *xdp)
> +{
> + struct enic_xsk_buff *xskb = enic_xsk_buff(xdp);
> + unsigned int rq_index = xdp->rxq->queue_index;
> + struct enic_rq *rq;
> +
> + if (WARN_ON_ONCE(rq_index >= enic->rq_count) ||
> + WARN_ON_ONCE(!list_empty(&xskb->tx_done)))
> + return;
> +
> + rq = &enic->rq[rq_index];
> + spin_lock_bh(&rq->xsk_tx_done_lock);
> + list_add_tail(&xskb->tx_done, &rq->xsk_tx_done);
> + spin_unlock_bh(&rq->xsk_tx_done_lock);
> +
> + if (READ_ONCE(enic->xsk_wakeup_enabled) &&
> + vnic_dev_get_intr_mode(enic->vdev) == VNIC_DEV_INTR_MODE_MSIX)
> + enic_xsk_schedule_napi(&enic->napi[rq_index]);
> +}
[Severity: Medium]
Can VNIC_WQ_BUF_XSK_RX completions be batched in enic_wq_service() the way
VNIC_WQ_BUF_XSK completions are?
Right now enic_free_wq_buf() calls enic_xsk_rx_tx_complete() on every
completed descriptor while holding wq->lock, so each packet individually
acquires spin_lock_bh(&rq->xsk_tx_done_lock) and performs an atomic
cmpxchg on enic->napi[rq_index].state via enic_xsk_schedule_napi(). In
addition, struct enic_rq places xsk_wakeup_lock, xsk_tx_done_lock, and
xsk_tx_done right after the cacheline-aligned struct xdp_rxq_info xdp_rxq
(64 bytes), putting those WQ-modified locks on the same cacheline as the
read-mostly RX flags xdp_enabled, xsk_rx_active, and xdp_flush_pending.
> +
> +void enic_xsk_rx_tx_flush(struct enic *enic, unsigned int rq_index)
> +{
> + struct enic_rq *rq = &enic->rq[rq_index];
> + struct enic_xsk_buff *xskb, *tmp;
> + LIST_HEAD(done);
> +
> + spin_lock_bh(&rq->xsk_tx_done_lock);
> + list_splice_init(&rq->xsk_tx_done, &done);
> + spin_unlock_bh(&rq->xsk_tx_done_lock);
> +
> + list_for_each_entry_safe(xskb, tmp, &done, tx_done) {
> + list_del_init(&xskb->tx_done);
> + xsk_buff_free(&xskb->xdp);
> + }
> +}
[Severity: Low]
Should enic_xsk_rx_tx_flush() return early when list_empty(&rq->xsk_tx_done)
before taking spin_lock_bh(&rq->xsk_tx_done_lock)?
enic_poll() and enic_poll_msix_rq() call enic_xsk_rx_tx_flush() on every
positive-budget RX NAPI poll, so without an unlocked list_empty() check
every RX poll pays an atomic lock/unlock and BH disable/enable even when
AF_XDP is not in use.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-enic-xdp-rfc-p1-20261130-v1-0-3be5458c9118@cisco.com?part=10
next prev parent reply other threads:[~2026-12-02 1:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 1:15 [PATCH RFC net-next 00/12] enic: add native XDP and AF_XDP support Satish Kharat
2026-12-01 1:15 ` [PATCH RFC net-next 01/12] net: enic: bound skb TX rollback to current packet Satish Kharat
2026-12-01 1:15 ` [PATCH RFC net-next 02/12] net: enic: tag work queue descriptor ownership Satish Kharat
2026-12-01 1:15 ` [PATCH RFC net-next 03/12] net: enic: gate native XDP on mixed RQ descriptor capability Satish Kharat
2026-12-01 1:15 ` [PATCH RFC net-next 04/12] net: enic: expose per-queue XDP and AF_XDP counters Satish Kharat
2026-12-02 1:16 ` sashiko-bot
2026-12-01 1:15 ` [PATCH RFC net-next 05/12] net: enic: complete XDP frames by WQ descriptor ownership Satish Kharat
2026-12-01 1:15 ` [PATCH RFC net-next 06/12] net: enic: reserve XDP head and tailroom in RX pages Satish Kharat
2026-12-02 1:16 ` sashiko-bot
2026-12-01 1:15 ` [PATCH RFC net-next 07/12] net: enic: publish partial receive descriptor batches Satish Kharat
2026-12-02 1:16 ` sashiko-bot
2026-12-01 1:15 ` [PATCH RFC net-next 08/12] net: enic: add native XDP RX, TX, and redirect Satish Kharat
2026-12-02 1:16 ` sashiko-bot
2026-12-01 1:15 ` [PATCH RFC net-next 09/12] net: enic: batch AF_XDP TX completions by pool Satish Kharat
2026-12-01 1:15 ` [PATCH RFC net-next 10/12] net: enic: add AF_XDP zero-copy RX and TX Satish Kharat
2026-12-02 1:16 ` sashiko-bot [this message]
2026-12-01 1:15 ` [PATCH RFC net-next 11/12] selftests/xsk: exercise XDP detach with bound socket Satish Kharat
2026-12-01 1:15 ` [PATCH RFC net-next 12/12] net: enic: count XDP and AF_XDP TX in queue statistics Satish Kharat
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-244593@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=satishkh@cisco.com \
/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