[PATCH net v4 1/4] igb: don't touch rings that don't exist when disabling an XSK pool

From: Antonio Quartulli

Date: Fri Nov 20 2026 - 16:02:04 EST


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@xxxxxxxxxxxxxxx # 6.14+
Link: https://lore.kernel.org/netdev/20261116153041.3002666-2-antonio@xxxxxxxxxxxxx/
Signed-off-by: Antonio Quartulli <antonio@xxxxxxxxxxxxx>
---
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