🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
5 messages
5 total messages Started by Antonio Quartulli Fri, 20 Nov 2026 21:01
[PATCH net v4 1/4] igb: don't touch rings that don't exist when disabling an XSK pool
#19958
Author: Antonio Quartulli
Date: Fri, 20 Nov 2026 21:01
114 lines
14056 bytes
xsk_get_pool_from_qid() checks the queue id against the stack's real
queue counts, which can be higher than the number of rings the device
has: on 82576, enabling VFs leaves a single Tx queue while keeping two
Rx queues, and igb can fall back from MSI-X to MSI with a single queue
on resume. Disabling the pool of such a queue, e.g. one bound to queue 1
before enabling VFs, then passes a NULL Tx ring to
igb_txrx_ring_disable().

Only disable and re-enable the rings the device has: skip the queue if
it has no Rx ring, and only the Tx part if it has no Tx ring, so that
an Rx ring using the pool still stops using it.

Tested with the 82576 emulated by QEMU and a zero-copy AF_XDP socket on
queue 1: closing it after enabling a VF no longer oopses and the Rx ring
no longer references the pool afterwards (checked with a debug print, as
QEMU doesn't spread traffic over the PF queues with VFs), and without
VFs queue 1 keeps receiving after the close. Not run under KASAN.

Fixes: 80f6ccf9f116 ("igb: Introduce XSK data structures and helpers")
Cc: stable@vger.kernel.org # 6.14+
Link: https://lore.kernel.org/netdev/20261116153041.3002666-2-antonio@mandelbit.com/
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
v4: also handle queues with an Rx but no Tx ring, as with VFs (Sashiko):
tear down the Rx ring and skip only the Tx part; tested with a
zero-copy AF_XDP socket; subject was "don't disable rings that don't exist
..."
v3: new patch.

 drivers/net/ethernet/intel/igb/igb_xsk.c | 37 +++++++++++++++++-------
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_xsk.c b/drivers/net/ethernet/intel/igb/igb_xsk.c
index ce4a7b5..3b4212a 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;
+}
+
 static void igb_txrx_ring_disable(struct igb_adapter *adapter, u16 qid)
 {
-	struct igb_ring *tx_ring = adapter->tx_ring[qid];
+	struct igb_ring *tx_ring = igb_xsk_tx_ring(adapter, qid);
 	struct igb_ring *rx_ring = adapter->rx_ring[qid];
 	struct e1000_hw *hw = &adapter->hw;
 
-	set_bit(IGB_RING_FLAG_TX_DISABLED, &tx_ring->flags);
-
-	wr32(E1000_TXDCTL(tx_ring->reg_idx), 0);
+	if (tx_ring) {
+		set_bit(IGB_RING_FLAG_TX_DISABLED, &tx_ring->flags);
+		wr32(E1000_TXDCTL(tx_ring->reg_idx), 0);
+	}
 	wr32(E1000_RXDCTL(rx_ring->reg_idx), 0);
 
 	synchronize_net();
@@ -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));
+	}
 	igb_clean_rx_ring(rx_ring);
-
 	memset(&rx_ring->rx_stats, 0, sizeof(rx_ring->rx_stats));
-	memset(&tx_ring->tx_stats, 0, sizeof(tx_ring->tx_stats));
 }
 
 static void igb_txrx_ring_enable(struct igb_adapter *adapter, u16 qid)
 {
-	struct igb_ring *tx_ring = adapter->tx_ring[qid];
+	struct igb_ring *tx_ring = igb_xsk_tx_ring(adapter, qid);
 	struct igb_ring *rx_ring = adapter->rx_ring[qid];
 
-	igb_configure_tx_ring(adapter, tx_ring);
+	if (tx_ring)
+		igb_configure_tx_ring(adapter, tx_ring);
 	igb_configure_rx_ring(adapter, rx_ring);
 
 	synchronize_net();
 
-	clear_bit(IGB_RING_FLAG_TX_DISABLED, &tx_ring->flags);
+	if (tx_ring)
+		clear_bit(IGB_RING_FLAG_TX_DISABLED, &tx_ring->flags);
 
 	/* call igb_desc_unused which always leaves
 	 * at least 1 descriptor unused to make sure
@@ -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;
 	if (if_running)
 		igb_txrx_ring_disable(adapter, qid);
 
-- 
2.56.1
Re: [PATCH net v4 1/4] igb: don't touch rings that don't exist when disabling an XSK pool
#20013
Author: Janis Edvarts Lacis
Date: Fri, 20 Nov 2026 23:17
28 lines
12496 bytes
On 20 Nov 22:01, Antonio Quartulli wrote:
>xsk_get_pool_from_qid() checks the queue id against the stack's real
>queue counts, which can be higher than the number of rings the device
>has: on 82576, enabling VFs leaves a single Tx queue while keeping two
>Rx queues, and igb can fall back from MSI-X to MSI with a single queue
>on resume. Disabling the pool of such a queue, e.g. one bound to queue 1
>before enabling VFs, then passes a NULL Tx ring to
>igb_txrx_ring_disable().
>
>Only disable and re-enable the rings the device has: skip the queue if
>it has no Rx ring, and only the Tx part if it has no Tx ring, so that
>an Rx ring using the pool still stops using it.
>

What happens if a pool is bound to, say, queue 1 and the socket stays 
open across a runtime resume that falls back from MSI-X to MSI 
(queue 1 becomes invalid)?

If the socket is closed after igb_rtnl_resume_task() has reduced both
real queue counts to one, xsk_get_pool_from_qid() will return NULL for
queue 1. As I read it, igb_xsk_pool_disable() then returns -EINVAL
before doing the cleanup and resources get leaked.

I may be mistaken here, if so, please let me know :)

Best regards,
Janis
Re: [PATCH net v4 1/4] igb: don't touch rings that don't exist when disabling an XSK pool
#21286
Author: Antonio Quartulli
Date: Mon, 23 Nov 2026 20:28
59 lines
12201 bytes

On 21/11/2026 00:17, Janis Edvarts Lacis wrote:
> On 20 Nov 22:01, Antonio Quartulli wrote:
>> xsk_get_pool_from_qid() checks the queue id against the stack's real
>> queue counts, which can be higher than the number of rings the device
>> has: on 82576, enabling VFs leaves a single Tx queue while keeping two
>> Rx queues, and igb can fall back from MSI-X to MSI with a single queue
>> on resume. Disabling the pool of such a queue, e.g. one bound to queue 1
>> before enabling VFs, then passes a NULL Tx ring to
>> igb_txrx_ring_disable().
>>
>> Only disable and re-enable the rings the device has: skip the queue if
>> it has no Rx ring, and only the Tx part if it has no Tx ring, so that
>> an Rx ring using the pool still stops using it.
>>
> 
> What happens if a pool is bound to, say, queue 1 and the socket stays 
> open across a runtime resume that falls back from MSI-X to MSI (queue 1 
> becomes invalid)?
> 
> If the socket is closed after igb_rtnl_resume_task() has reduced both
> real queue counts to one, xsk_get_pool_from_qid() will return NULL for
> queue 1. As I read it, igb_xsk_pool_disable() then returns -EINVAL
> before doing the cleanup and resources get leaked.
> 
> I may be mistaken here, if so, please let me know :)

Hi Janis,

actually you're not mistaken, thanks for spotting it.
Once the real Rx queue count is lowered below a queue with a bound XSK 
pool, xsk_get_pool_from_qid() no longer finds the pool, the disable 
fails ("Failed to disable zero-copy!") and the pool's DMA mappings are 
never unmapped.

igb already does this today (it lowers the counts on runtime resume, 
just without RTNL), and so does any shrink done by the driver itself 
(e.g. SR-IOV reinit), so it's worth fixing here.

In v5 igb I will follow what ethtool does for channel changes: when the
driver lowers its queue counts, it keeps the real Rx count up to the
highest queue that still has an XSK pool, so the pool can still be
disabled and unmapped (the rings are skipped as they don't exist). The
Tx count follows the device, and the Rx count is lowered at the next
open.

This said, I will first wait for Sashiko to report any other potential 
issue and then I'll work on v5.

Best regards,

-- 
Antonio Quartulli

CEO and Co-Founder
Mandelbit Srl
https://www.mandelbit.com
Re: [PATCH net v4 1/4] igb: don't touch rings that don't exist when disabling an XSK pool
#22098
Author: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 21:38
204 lines
15844 bytes
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
Re: [PATCH net v4 1/4] igb: don't touch rings that don't exist when disabling an XSK pool
#22182
Author: Antonio Quartulli
Date: Tue, 24 Nov 2026 23:56
46 lines
10848 bytes

On 24/11/2026 22:38, netdev-bot+sashiko@kernel.org wrote:
> 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…
> 

The race with a runtime resume is real, though it predates this patch:
v5 adds a patch that resumes the device for the duration of igb_xdp(),
which also covers the same race in igb_xdp_setup().


> 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.
> 

The two pre-existing issues are real too (the Tx NAPI isn't stopped
when Rx and Tx don't share a vector, and a failed buffer reallocation
leaves the queue half torn down). They're independent from this series,
so I'll fix them separately. The zero-copy tests ran without queue
pairs and didn't hit the first one


Regards,

-- 
Antonio Quartulli

CEO and Co-Founder
Mandelbit Srl
https://www.mandelbit.com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads