Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: antonio@mandelbit.com
Cc: intel-wired-lan@lists.osuosl.org, anthony.l.nguyen@intel.com,
	przemyslaw.kitszel@intel.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, janislacis06@gmail.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH net v4 1/4] igb: don't touch rings that don't exist when disabling an XSK pool
Date: Tue, 24 Nov 2026 21:38:43 +0000	[thread overview]
Message-ID: <179555632368.3135.16785834510606239982@kernel.org> (raw)
In-Reply-To: <20261120210134.133238-2-antonio@mandelbit.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 (2) · Medium: 0 · Low: 0

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] The new `qid < adapter->num_rx_queues` guard in
  igb_xsk_pool_disable() (and `qid < adapter->num_tx_queues` in…

Pre-existing issues:
- [High] igb_txrx_ring_disable() and igb_txrx_ring_enable() in
  drivers/net/ethernet/intel/igb/igb_xsk.c only stop and restart…
- [High] On error, igb_xsk_pool_disable() returns early with the queue
  half torn down.

--

igb: don't touch rings that don't exist when disabling an XSK pool

This commit makes igb_txrx_ring_disable() and igb_txrx_ring_enable() skip
the Tx ring when qid is not below num_tx_queues. It also makes
igb_xsk_pool_disable() skip the ring teardown when qid is not below
num_rx_queues. The goal is to stop passing a NULL ring when the stack
knows about more queues than the device has, for example on 82576 with
VFs or after an MSI fallback on resume.

Link: https://lore.kernel.org/netdev/20261116153041.3002666-2-antonio@mandelbit.com/

> diff --git a/drivers/net/ethernet/intel/igb/igb_xsk.c b/drivers/net/ethernet/intel/igb/igb_xsk.c
> index ce4a7b58cad2f..3b4212a9521e0 100644
> --- a/drivers/net/ethernet/intel/igb/igb_xsk.c
> +++ b/drivers/net/ethernet/intel/igb/igb_xsk.c
> @@ -31,15 +31,22 @@ static int igb_realloc_rx_buffer_info(struct igb_ring *ring, bool pool_present)
>  	return 0;
>  }
>  
> +/* With VFs, the device has a single Tx queue but can have more Rx queues */
> +static struct igb_ring *igb_xsk_tx_ring(struct igb_adapter *adapter, u16 qid)
> +{
> +	return qid < adapter->num_tx_queues ? adapter->tx_ring[qid] : NULL;
> +}
> +

[ ... ]

> @@ -47,24 +54,27 @@ static void igb_txrx_ring_disable(struct igb_adapter *adapter, u16 qid)
>  	/* Rx/Tx share the same napi context. */
>  	napi_disable(&rx_ring->q_vector->napi);
>  
> -	igb_clean_tx_ring(tx_ring);
> +	if (tx_ring) {
> +		igb_clean_tx_ring(tx_ring);
> +		memset(&tx_ring->tx_stats, 0, sizeof(tx_ring->tx_stats));
> +	}

[Severity: High]
This isn't a bug introduced by this patch, but does the "Rx/Tx share the
same napi context" assumption always hold here?

igb_set_flag_queue_pairs() only sets IGB_FLAG_QUEUE_PAIRS in some cases:

	if (adapter->rss_queues > (max_rss_queues / 2))
		adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
	else
		adapter->flags &= ~IGB_FLAG_QUEUE_PAIRS;

Without the flag, igb_alloc_q_vectors() gives each Rx ring its own vector.
The Tx rings then sit on separate Tx-only vectors, each with its own NAPI.
Examples are an i350 or 82576 without VFs on a machine with 4 or fewer
CPUs, or an i210 with 2 queues. The comment in igb_xsk_wakeup() in this
same file says the NAPI is only shared "If IGB_FLAG_QUEUE_PAIRS is
active".

In that setup, napi_disable(&rx_ring->q_vector->napi) leaves the Tx
ring's NAPI running. It can still be scheduled by late write-back
interrupts or by the watchdog's EICS kick. igb_poll() on that vector
then does:

	if (q_vector->tx.ring)
		clean_complete = igb_clean_tx_irq(q_vector, budget);

Also, igb_clean_tx_irq() does not check IGB_RING_FLAG_TX_DISABLED.

Can igb_clean_tx_irq() and igb_clean_tx_ring() then walk the same entries
from tx_ring->next_to_clean at the same time? Neither one clears
tx_buffer->skb or xdpf. So napi_consume_skb() or xdp_return_frame() on
one side, and dev_kfree_skb_any() or xdp_return_frame() on the other,
could free the same skb or xdp_frame twice.

igb_clean_tx_irq() could also write back a stale next_to_clean after
igb_clean_tx_ring() has reset it to 0. igb_configure_tx_ring() in
igb_txrx_ring_enable() does not reset that index. It does memset
tx_buffer_info and rewrite TDH/TDT while the Tx NAPI may still be
polling.

The patch keeps this flow for every qid that has a Tx ring.

[ ... ]

> @@ -148,7 +158,12 @@ static int igb_xsk_pool_disable(struct igb_adapter *adapter, u16 qid)
>  		return -EINVAL;
>  
>  	rx_ring = adapter->rx_ring[qid];
> -	if_running = netif_running(adapter->netdev) && igb_xdp_is_enabled(adapter);
> +	/* The stack can know more queues than the device has, e.g. after a
> +	 * fallback to fewer queues on resume: skip the rings it doesn't have.
> +	 */
> +	if_running = netif_running(adapter->netdev) &&
> +		     igb_xdp_is_enabled(adapter) &&
> +		     qid < adapter->num_rx_queues;

[Severity: High]
Is this check enough for the resume case named in the comment?

The check reads num_rx_queues under RTNL, but __igb_resume() rebuilds that
state without RTNL. It calls igb_init_interrupt_scheme() before
rtnl_lock(), and for runtime PM it never takes RTNL. Inside that call,
igb_set_interrupt_capability() publishes:

	adapter->num_rx_queues = adapter->rss_queues;

This happens before igb_alloc_q_vectors() fills in adapter->rx_ring[i]
and adapter->tx_ring[i]. Suspend had already set those to NULL through
igb_free_q_vectors(). netif_running() stays true across suspend, and
adapter->xdp_prog is kept.

Suppose an XSK pool teardown runs under RTNL while a runtime resume is in
progress on pm_wq. The teardown could come from closing a zero-copy
socket, or from xp_release_deferred(). Could it see qid < num_rx_queues
while adapter->rx_ring[qid] is still NULL? If so, igb_txrx_ring_disable()
would dereference NULL:

	wr32(E1000_RXDCTL(rx_ring->reg_idx), 0);

The num_tx_queues and tx_ring[] read in igb_xsk_tx_ring() has the same
race.

There is also a slightly later window where the ring exists but its NAPI
has not been enabled yet. Would napi_disable() then spin while holding
RTNL and the netdev lock? Meanwhile, __igb_open() in the resume path
would be waiting for the netdev lock in napi_enable() (runtime PM) or for
RTNL (system resume).

The later patches in this series ("igb: fix RTNL assertion when resuming
from runtime suspend" and "igb: link queues to NAPIs under RTNL after
runtime resume") still leave igb_init_interrupt_scheme() outside RTNL. So
this race seems to remain at the end of the series.

>  	if (if_running)
>  		igb_txrx_ring_disable(adapter, qid);
>  

[Severity: High]
This is a pre-existing issue, but the error path just after this hunk in
igb_xsk_pool_disable() returns with the queue half torn down:

	xsk_pool_dma_unmap(pool, IGB_RX_DMA_ATTR);

	if (if_running) {
		err = igb_realloc_rx_buffer_info(rx_ring, false);
		if (err)
			return err;

		igb_txrx_ring_enable(adapter, qid);
	}

If the vmalloc() in igb_realloc_rx_buffer_info() fails,
igb_txrx_ring_enable() is never called. That leaves:

- the Rx q_vector NAPI disabled
- IGB_RING_FLAG_TX_DISABLED set
- rx_ring->xsk_pool and tx_ring->xsk_pool pointing at the pool that is
  about to be freed
- rx_buffer_info_zc still attached to the ring

Can the next igb_down() then hang? It can come from close, reset, an XDP
program change or suspend. igb_down() calls napi_disable() on every
q_vector, and napi_disable_locked() never exits on a NAPI that is already
disabled:

	while (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) {
		usleep_range(20, 200);
		val = READ_ONCE(n->state);
	}

This loop runs with RTNL and the netdev lock held.

Without queue pairs, the Tx NAPI keeps running. Could it read the stale
tx_ring->xsk_pool through igb_clean_tx_irq() after the pool is freed?

igb_xsk_pool_enable() has the same pattern. When
igb_realloc_rx_buffer_info(rx_ring, true) fails, it unmaps the DMA and
returns with the rings stopped and the NAPI disabled.

With this patch, the Rx-only teardown also goes through this error path.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120210134.133238-1-antonio%40mandelbit.com

  parent reply	other threads:[~2026-11-24 21:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 21:01 [PATCH net v4 0/4] igb: fix runtime PM resume issues Antonio Quartulli
2026-11-20 21:01 ` [PATCH net v4 1/4] igb: don't touch rings that don't exist when disabling an XSK pool Antonio Quartulli
2026-11-20 23:17   ` Janis Edvarts Lacis
2026-11-23 20:28     ` Antonio Quartulli
2026-11-24 21:38   ` netdev-bot+sashiko [this message]
2026-11-20 21:01 ` [PATCH net v4 2/4] igb: fix RTNL assertion when resuming from runtime suspend Antonio Quartulli
2026-11-20 21:01 ` [PATCH net v4 3/4] igb: link queues to NAPIs under RTNL after runtime resume Antonio Quartulli
2026-11-24 21:38   ` netdev-bot+sashiko
2026-11-20 21:01 ` [PATCH net v4 4/4] igb: only allow runtime PM if the device can wake up Antonio Quartulli
2026-11-24 21:38   ` 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=179555632368.3135.16785834510606239982@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=antonio@mandelbit.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=janislacis06@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=stable@vger.kernel.org \
    /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