Netdev List
 help / color / mirror / Atom feed
* [PATCH net v5 0/6] igb: fix runtime PM resume issues
@ 2026-11-24 23:57 Antonio Quartulli
  2026-11-24 23:57 ` [PATCH net v5 1/6] igb: don't touch rings that don't exist when disabling an XSK pool Antonio Quartulli
                   ` (6 more replies)
  0 siblings, 7 replies; 18+ messages in thread
From: Antonio Quartulli @ 2026-11-24 23:57 UTC (permalink / raw)
  To: intel-wired-lan
  Cc: Antonio Quartulli, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Janis Edvarts Lacis, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Sriram Yagnaraman, Kurt Kanzenbach, Maciej Fijalkowski,
	Heiner Kallweit, Joe Damato, Sven Auhagen, netdev, linux-kernel,
	bpf

igb can be runtime suspended when the link goes down (with
power/control set to auto). Resuming it calls functions that need RTNL
without holding it (patches 2 and 4), XDP and XSK changes race with a
resume (patch 5), and devices that can't signal a wake-up are suspended
anyway, so their port stays down when the link comes back (patch 6).

Patch 1 fixes the XSK pool disable path when the device has fewer rings
than the stack has queues: a NULL dereference with VFs (a single Tx
queue on 82576), or after a fallback from MSI-X to MSI on resume. Patch
3 keeps such queues while they still have an XSK pool, so that the pool
can still be disabled.

Tested with the 82576 emulated by QEMU, including, with test-only hooks,
a runtime resume and a simulated system sleep (the suspend/resume
callbacks called directly, as the test kernel has no CONFIG_SUSPEND)
with the device forced to come back with MSI and a single queue.
Patches 1 and 3 were tested with a zero-copy AF_XDP socket: closing it
after enabling a VF oopses (queue 1, stock igb and v3) or warns and
leaks (queue 2, v4), and warns after a resume forced to use MSI (v4);
patch 5 by closing a socket and attaching an XDP program while runtime
suspended. Not tested: real hardware and PME wake-up, a real system
sleep, the MSI-X allocation failure itself, the window before the work
item runs, SR-IOV with runtime PM, and a device that can wake up. Not
run under KASAN.

Sashiko also found two pre-existing issues in the XSK queue disable/
enable paths (the Tx NAPI isn't stopped when Rx and Tx don't share a
vector; a failed buffer reallocation leaves the queue half torn down);
they will be fixed separately.

igc has the same issues (see the notes); Joe Damato offered to test on
igc, so its fix will be sent separately.

Changes in v5:
- new patch 3: keep the stack's Rx queues that still have an XSK pool
  (Janis)
- patch 4: cancel the work item before a suspend (Sashiko)
- new patch 5: resume the device before changing XDP or XSK settings
  (Sashiko)
- patch 6: check pci_dev_run_wake() when scheduling the suspend
  (Sashiko)

Changes in v4:
- patch 1: also handle queues with an Rx but no Tx ring, as with VFs:
  tear down the Rx ring and skip only the Tx part (Sashiko); subject
  changed from "don't disable rings ..." to "don't touch rings ..."

Changes in v3:
- new patch 1
- patch 2: set the real queue counts on system sleep resume and from a
  work item on runtime resume, and drop packets for queues the device
  doesn't have until then (Janis, Sashiko)
- patch 3 (now 4): link the NAPIs from the same work item

Changes in v2:
- patch 2 (v2 patch 1): keep setting the queue counts in __igb_open(),
  only skipping them on resume (Sashiko)
- mention the tested hardware in the commit messages

v4: https://lore.kernel.org/netdev/20261120210134.133238-1-antonio@mandelbit.com/
v3: https://lore.kernel.org/netdev/20261119140412.163202-1-antonio@mandelbit.com/
v2: https://lore.kernel.org/netdev/20261116153041.3002666-1-antonio@mandelbit.com/
v1: https://lore.kernel.org/netdev/20261113105835.3821433-1-antonio@mandelbit.com/

Antonio Quartulli (6):
  igb: don't touch rings that don't exist when disabling an XSK pool
  igb: fix RTNL assertion when resuming from runtime suspend
  igb: keep the stack's Rx queues that still have an XSK pool
  igb: link queues to NAPIs under RTNL after runtime resume
  igb: resume the device before changing XDP or XSK settings
  igb: only allow runtime PM if the device can wake up

 drivers/net/ethernet/intel/igb/igb.h      |   1 +
 drivers/net/ethernet/intel/igb/igb_main.c | 144 +++++++++++++++++-----
 drivers/net/ethernet/intel/igb/igb_xsk.c  |  37 ++++--
 3 files changed, 143 insertions(+), 39 deletions(-)

-- 
2.56.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH net v5 1/6] igb: don't touch rings that don't exist when disabling an XSK pool
  2026-11-24 23:57 [PATCH net v5 0/6] igb: fix runtime PM resume issues Antonio Quartulli
@ 2026-11-24 23:57 ` Antonio Quartulli
  2026-11-28 13:36   ` Janis Edvarts Lacis
  2026-11-29  0:37   ` netdev-bot+sashiko
  2026-11-24 23:57 ` [PATCH net v5 2/6] igb: fix RTNL assertion when resuming from runtime suspend Antonio Quartulli
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 18+ messages in thread
From: Antonio Quartulli @ 2026-11-24 23:57 UTC (permalink / raw)
  To: intel-wired-lan
  Cc: Antonio Quartulli, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Janis Edvarts Lacis, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Sriram Yagnaraman, Kurt Kanzenbach, Maciej Fijalkowski, netdev,
	linux-kernel, bpf, stable

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. This also stops a NULL
dereference when the socket is closed while the device is runtime
suspended, which frees its rings.

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>
---
v5: the message also mentions the runtime suspended case (no code
changes)
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


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net v5 2/6] igb: fix RTNL assertion when resuming from runtime suspend
  2026-11-24 23:57 [PATCH net v5 0/6] igb: fix runtime PM resume issues Antonio Quartulli
  2026-11-24 23:57 ` [PATCH net v5 1/6] igb: don't touch rings that don't exist when disabling an XSK pool Antonio Quartulli
@ 2026-11-24 23:57 ` Antonio Quartulli
  2026-11-28 13:37   ` Janis Edvarts Lacis
  2026-11-29  0:37   ` netdev-bot+sashiko
  2026-11-24 23:57 ` [PATCH net v5 3/6] igb: keep the stack's Rx queues that still have an XSK pool Antonio Quartulli
                   ` (4 subsequent siblings)
  6 siblings, 2 replies; 18+ messages in thread
From: Antonio Quartulli @ 2026-11-24 23:57 UTC (permalink / raw)
  To: intel-wired-lan
  Cc: Antonio Quartulli, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Janis Edvarts Lacis, Heiner Kallweit, netdev, linux-kernel,
	stable

Since commit ac8c58f5b535 ("igb: fix deadlock caused by taking RTNL in
RPM resume path") __igb_resume() doesn't take RTNL for runtime resume,
but __igb_open() still calls netif_set_real_num_{tx,rx}_queues(), which
require it. An asynchronous runtime resume (e.g. after the link comes
back) then triggers "RTNL: assertion failed".

Only set the real queue counts in __igb_open() when RTNL is held (open
and system sleep resume), and set them from a work item taking RTNL on
runtime resume. Until it runs, after a fallback to fewer queues on
resume (MSI-X to MSI), the stack can use queues the device doesn't
have: drop those packets in igb_xmit_frame() instead of mapping several
stack queues, each with its own xmit lock, onto the same ring. The
stack can't be kept off those queues instead, as __igb_open() and
netif_device_attach() start all of them and changing the count needs
RTNL.

Tested with the 82576 emulated by QEMU.

Fixes: ac8c58f5b535 ("igb: fix deadlock caused by taking RTNL in RPM resume path")
Cc: stable@vger.kernel.org
Closes: https://bugzilla.ipfire.org/show_bug.cgi?id=13562
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
v5: no changes
v4: no changes
v3:
- set the real queue counts when RTNL is held (open and system sleep
  resume), and from a work item on runtime resume, instead of not at all
  on resume (Janis, Sashiko)
- until then, drop packets for queues the device doesn't have
- stable: netif_set_real_num_queues() needs 5.15+ and
  dev_core_stats_tx_dropped_inc() 5.18+; older backports can use the
  separate tx/rx calls and netdev->stats.tx_dropped
v2:
- keep setting the queue counts in __igb_open() after igb_request_irq(),
  only skipping them on resume (Sashiko)
- drop the reference to igc

Note: igc has the same issue: it sets the real queue counts only in
igc_open(), before requesting the IRQs, and never on resume. A fix will
follow separately once it has been tested on igc hardware (Joe offered
to test).

 drivers/net/ethernet/intel/igb/igb.h      |  1 +
 drivers/net/ethernet/intel/igb/igb_main.c | 73 ++++++++++++++++-------
 2 files changed, 54 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb.h b/drivers/net/ethernet/intel/igb/igb.h
index 8c9b020..79d7fcc 100644
--- a/drivers/net/ethernet/intel/igb/igb.h
+++ b/drivers/net/ethernet/intel/igb/igb.h
@@ -586,6 +586,7 @@ struct igb_adapter {
 
 	struct work_struct reset_task;
 	struct work_struct watchdog_task;
+	struct work_struct rtnl_resume_task;
 	bool fc_autoneg;
 	u8  tx_timeout_factor;
 	struct timer_list blink_timer;
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index d4a897a..2f51edc 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -110,6 +110,7 @@ static void igb_init_queue_configuration(struct igb_adapter *adapter);
 static int igb_sw_init(struct igb_adapter *);
 int igb_open(struct net_device *);
 int igb_close(struct net_device *);
+static void igb_rtnl_resume_task(struct work_struct *);
 static void igb_configure(struct igb_adapter *);
 static void igb_configure_tx(struct igb_adapter *);
 static void igb_configure_rx(struct igb_adapter *);
@@ -3426,6 +3427,7 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	INIT_WORK(&adapter->reset_task, igb_reset_task);
 	INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
+	INIT_WORK(&adapter->rtnl_resume_task, igb_rtnl_resume_task);
 
 	/* Initialize link properties that are user-changeable */
 	adapter->fc_autoneg = true;
@@ -3889,6 +3891,7 @@ static void igb_remove(struct pci_dev *pdev)
 
 	cancel_work_sync(&adapter->reset_task);
 	cancel_work_sync(&adapter->watchdog_task);
+	cancel_work_sync(&adapter->rtnl_resume_task);
 
 #ifdef CONFIG_IGB_DCA
 	if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
@@ -4123,10 +4126,31 @@ static int igb_sw_init(struct igb_adapter *adapter)
 	return 0;
 }
 
+/* Some settings need RTNL, which isn't held when resuming from runtime
+ * suspend: apply them from here instead, if the device is still up.
+ */
+static void igb_rtnl_resume_task(struct work_struct *work)
+{
+	struct igb_adapter *adapter = container_of(work, struct igb_adapter,
+						   rtnl_resume_task);
+
+	rtnl_lock();
+	if (!test_bit(__IGB_DOWN, &adapter->state) &&
+	    netif_running(adapter->netdev)) {
+		if (netif_set_real_num_queues(adapter->netdev,
+					      adapter->num_tx_queues,
+					      adapter->num_rx_queues))
+			netdev_err(adapter->netdev,
+				   "error setting real queue count\n");
+	}
+	rtnl_unlock();
+}
+
 /**
  *  __igb_open - Called when a network interface is made active
  *  @netdev: network interface device structure
  *  @resuming: indicates whether we are in a resume call
+ *  @rtnl_held: indicates whether RTNL is held
  *
  *  Returns 0 on success, negative value on failure
  *
@@ -4136,7 +4160,8 @@ static int igb_sw_init(struct igb_adapter *adapter)
  *  handler is registered with the OS, the watchdog timer is started,
  *  and the stack is notified that the interface is ready.
  **/
-static int __igb_open(struct net_device *netdev, bool resuming)
+static int __igb_open(struct net_device *netdev, bool resuming,
+		      bool rtnl_held)
 {
 	struct igb_adapter *adapter = netdev_priv(netdev);
 	struct pci_dev *pdev = adapter->pdev;
@@ -4179,16 +4204,15 @@ static int __igb_open(struct net_device *netdev, bool resuming)
 	if (err)
 		goto err_req_irq;
 
-	/* Notify the stack of the actual queue counts. */
-	err = netif_set_real_num_tx_queues(adapter->netdev,
-					   adapter->num_tx_queues);
-	if (err)
-		goto err_set_queues;
-
-	err = netif_set_real_num_rx_queues(adapter->netdev,
-					   adapter->num_rx_queues);
-	if (err)
-		goto err_set_queues;
+	/* Notify the stack of the actual queue counts. This needs RTNL: on
+	 * runtime resume igb_rtnl_resume_task() does it.
+	 */
+	if (rtnl_held) {
+		err = netif_set_real_num_queues(netdev, adapter->num_tx_queues,
+						adapter->num_rx_queues);
+		if (err)
+			goto err_set_queues;
+	}
 
 	/* From here on the code is the same as igb_up() */
 	clear_bit(__IGB_DOWN, &adapter->state);
@@ -4242,7 +4266,7 @@ err_setup_tx:
 
 int igb_open(struct net_device *netdev)
 {
-	return __igb_open(netdev, false);
+	return __igb_open(netdev, false, true);
 }
 
 /**
@@ -6617,12 +6641,7 @@ cleanup_tx_tstamp:
 static inline struct igb_ring *igb_tx_queue_mapping(struct igb_adapter *adapter,
 						    struct sk_buff *skb)
 {
-	unsigned int r_idx = skb->queue_mapping;
-
-	if (r_idx >= adapter->num_tx_queues)
-		r_idx = r_idx % adapter->num_tx_queues;
-
-	return adapter->tx_ring[r_idx];
+	return adapter->tx_ring[skb->queue_mapping];
 }
 
 static netdev_tx_t igb_xmit_frame(struct sk_buff *skb,
@@ -6636,6 +6655,17 @@ static netdev_tx_t igb_xmit_frame(struct sk_buff *skb,
 	if (skb_put_padto(skb, 17))
 		return NETDEV_TX_OK;
 
+	/* After a fallback to fewer queues on runtime resume, the stack can
+	 * use more queues than the device has until igb_rtnl_resume_task()
+	 * updates it: drop those packets instead of sharing a ring between
+	 * queues, which aren't serialized with each other.
+	 */
+	if (unlikely(skb->queue_mapping >= adapter->num_tx_queues)) {
+		dev_kfree_skb_any(skb);
+		dev_core_stats_tx_dropped_inc(netdev);
+		return NETDEV_TX_OK;
+	}
+
 	return igb_xmit_frame_ring(skb, igb_tx_queue_mapping(adapter, skb));
 }
 
@@ -9639,8 +9669,11 @@ static int __igb_resume(struct device *dev, bool rpm)
 
 	if (!rpm)
 		rtnl_lock();
-	if (!err && netif_running(netdev))
-		err = __igb_open(netdev, true);
+	if (!err && netif_running(netdev)) {
+		err = __igb_open(netdev, true, !rpm);
+		if (!err && rpm)
+			schedule_work(&adapter->rtnl_resume_task);
+	}
 
 	if (!err)
 		netif_device_attach(netdev);
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net v5 3/6] igb: keep the stack's Rx queues that still have an XSK pool
  2026-11-24 23:57 [PATCH net v5 0/6] igb: fix runtime PM resume issues Antonio Quartulli
  2026-11-24 23:57 ` [PATCH net v5 1/6] igb: don't touch rings that don't exist when disabling an XSK pool Antonio Quartulli
  2026-11-24 23:57 ` [PATCH net v5 2/6] igb: fix RTNL assertion when resuming from runtime suspend Antonio Quartulli
@ 2026-11-24 23:57 ` Antonio Quartulli
  2026-11-28 13:37   ` Janis Edvarts Lacis
  2026-11-29  0:37   ` netdev-bot+sashiko
  2026-11-24 23:57 ` [PATCH net v5 4/6] igb: link queues to NAPIs under RTNL after runtime resume Antonio Quartulli
                   ` (3 subsequent siblings)
  6 siblings, 2 replies; 18+ messages in thread
From: Antonio Quartulli @ 2026-11-24 23:57 UTC (permalink / raw)
  To: intel-wired-lan
  Cc: Antonio Quartulli, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Janis Edvarts Lacis, Sriram Yagnaraman, Kurt Kanzenbach,
	Maciej Fijalkowski, netdev, linux-kernel, stable

When igb lowers its queue counts by itself, after a fallback from MSI-X
to MSI on resume or when enabling VFs, xsk_get_pool_from_qid() doesn't
find the pool of a socket bound to a removed queue anymore. Disabling
it then fails ("Failed to disable zero-copy!") and the pool's DMA
mappings are never unmapped.

ethtool refuses to remove a queue that still has an XSK pool, but igb
can't refuse a VF enable or a resume fallback. Keep the real Rx queue
count up to the highest queue that still has an XSK pool instead, so
that the pool can still be disabled, and lower it at the next open. The
Tx count follows the device: an XSK pool is always bound to both an Rx
and a Tx queue, and the lookup finds it through the Rx one.

Tested with the 82576 emulated by QEMU and a zero-copy AF_XDP socket,
bound to queue 2 when enabling a VF, and to queue 1 across a runtime
resume forced to use MSI with a single queue (with a test hook): closing
it warned and leaked before, not anymore.

Fixes: 80f6ccf9f116 ("igb: Introduce XSK data structures and helpers")
Cc: stable@vger.kernel.org # 6.14+
Reported-by: Janis Edvarts Lacis <janislacis06@gmail.com>
Closes: https://lore.kernel.org/netdev/xupy6jbpnziq2qji54zjbvm7neggrwkxg3sfrhlolmrd6ysifl@zptk6ynkbu5f/
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
v5: new patch (Janis)

 drivers/net/ethernet/intel/igb/igb_main.c | 27 ++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 2f51edc..6961646 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -4126,6 +4126,26 @@ static int igb_sw_init(struct igb_adapter *adapter)
 	return 0;
 }
 
+/* ethtool refuses to remove a queue that still has an XSK pool. igb can't
+ * refuse when it lowers its queue counts by itself, so keep the stack's Rx
+ * queue instead, or the pool couldn't be disabled anymore: lower the count
+ * once it's gone, at the next open.
+ */
+static int igb_set_real_num_queues(struct igb_adapter *adapter)
+{
+	struct net_device *netdev = adapter->netdev;
+	unsigned int rxq = adapter->num_rx_queues;
+	unsigned int i;
+
+	for (i = netdev->real_num_rx_queues; i > rxq; i--)
+		if (xsk_get_pool_from_qid(netdev, i - 1)) {
+			rxq = i;
+			break;
+		}
+
+	return netif_set_real_num_queues(netdev, adapter->num_tx_queues, rxq);
+}
+
 /* Some settings need RTNL, which isn't held when resuming from runtime
  * suspend: apply them from here instead, if the device is still up.
  */
@@ -4137,9 +4157,7 @@ static void igb_rtnl_resume_task(struct work_struct *work)
 	rtnl_lock();
 	if (!test_bit(__IGB_DOWN, &adapter->state) &&
 	    netif_running(adapter->netdev)) {
-		if (netif_set_real_num_queues(adapter->netdev,
-					      adapter->num_tx_queues,
-					      adapter->num_rx_queues))
+		if (igb_set_real_num_queues(adapter))
 			netdev_err(adapter->netdev,
 				   "error setting real queue count\n");
 	}
@@ -4208,8 +4226,7 @@ static int __igb_open(struct net_device *netdev, bool resuming,
 	 * runtime resume igb_rtnl_resume_task() does it.
 	 */
 	if (rtnl_held) {
-		err = netif_set_real_num_queues(netdev, adapter->num_tx_queues,
-						adapter->num_rx_queues);
+		err = igb_set_real_num_queues(adapter);
 		if (err)
 			goto err_set_queues;
 	}
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net v5 4/6] igb: link queues to NAPIs under RTNL after runtime resume
  2026-11-24 23:57 [PATCH net v5 0/6] igb: fix runtime PM resume issues Antonio Quartulli
                   ` (2 preceding siblings ...)
  2026-11-24 23:57 ` [PATCH net v5 3/6] igb: keep the stack's Rx queues that still have an XSK pool Antonio Quartulli
@ 2026-11-24 23:57 ` Antonio Quartulli
  2026-11-28 13:38   ` Janis Edvarts Lacis
  2026-11-24 23:57 ` [PATCH net v5 5/6] igb: resume the device before changing XDP or XSK settings Antonio Quartulli
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 18+ messages in thread
From: Antonio Quartulli @ 2026-11-24 23:57 UTC (permalink / raw)
  To: intel-wired-lan
  Cc: Antonio Quartulli, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Janis Edvarts Lacis, Kurt Kanzenbach, Joe Damato, netdev,
	linux-kernel, stable

__igb_open() links queues to NAPIs with netif_queue_set_napi(), which
requires RTNL, but RTNL isn't held when resuming from runtime suspend:
this triggers "RTNL: assertion failed".

Link them in __igb_open() only when RTNL is held, and from the work
item that sets the real queue counts on runtime resume. The links can't
be kept across a suspend, because __igb_shutdown() frees the q_vectors.
A suspend now cancels the work item before freeing them, so it only runs
after the resume that scheduled it allocated them, and it checks
__IGB_DOWN under RTNL for a close in the meantime.

Tested with the 82576 emulated by QEMU.

Fixes: b75a1dea500f ("igb: Link queues to NAPI instances")
Cc: stable@vger.kernel.org # 6.16+
Closes: https://bugzilla.ipfire.org/show_bug.cgi?id=13562
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
v5: cancel the work item before a suspend (Sashiko)
v4: no changes
v3: link the NAPIs from the work item added by the previous patch, and
in __igb_open() whenever RTNL is held (also on system sleep resume);
dropped Joe's Reviewed-by, as the patch changed
v2: no code changes; mention the tested hardware

Note: igc has the same issue: __igc_open() also links queues to NAPIs
(igc_set_queue_napi()) on the RTNL-less runtime resume path. A fix will
follow separately once it has been tested on igc hardware.

 drivers/net/ethernet/intel/igb/igb_main.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 6961646..acd9a33 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -4146,8 +4146,19 @@ static int igb_set_real_num_queues(struct igb_adapter *adapter)
 	return netif_set_real_num_queues(netdev, adapter->num_tx_queues, rxq);
 }
 
+static void igb_link_queue_napis(struct igb_adapter *adapter)
+{
+	int i;
+
+	for (i = 0; i < adapter->num_q_vectors; i++)
+		igb_set_queue_napi(adapter, i, &adapter->q_vector[i]->napi);
+}
+
 /* Some settings need RTNL, which isn't held when resuming from runtime
- * suspend: apply them from here instead, if the device is still up.
+ * suspend: apply them from here instead, if the device is still up. A
+ * suspend cancels this work before freeing the q_vectors, so it only runs
+ * after the resume that scheduled it allocated them; checking __IGB_DOWN
+ * under RTNL covers a close in the meantime.
  */
 static void igb_rtnl_resume_task(struct work_struct *work)
 {
@@ -4160,6 +4171,7 @@ static void igb_rtnl_resume_task(struct work_struct *work)
 		if (igb_set_real_num_queues(adapter))
 			netdev_err(adapter->netdev,
 				   "error setting real queue count\n");
+		igb_link_queue_napis(adapter);
 	}
 	rtnl_unlock();
 }
@@ -4237,7 +4249,8 @@ static int __igb_open(struct net_device *netdev, bool resuming,
 	for (i = 0; i < adapter->num_q_vectors; i++) {
 		napi = &adapter->q_vector[i]->napi;
 		napi_enable(napi);
-		igb_set_queue_napi(adapter, i, napi);
+		if (rtnl_held)
+			igb_set_queue_napi(adapter, i, napi);
 	}
 
 	/* Clear any pending interrupts. */
@@ -9548,6 +9561,11 @@ static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake,
 	u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
 	bool wake;
 
+	/* Don't let a work item queued by an earlier resume run once the
+	 * q_vectors are freed or reallocated
+	 */
+	cancel_work_sync(&adapter->rtnl_resume_task);
+
 	rtnl_lock();
 	netif_device_detach(netdev);
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net v5 5/6] igb: resume the device before changing XDP or XSK settings
  2026-11-24 23:57 [PATCH net v5 0/6] igb: fix runtime PM resume issues Antonio Quartulli
                   ` (3 preceding siblings ...)
  2026-11-24 23:57 ` [PATCH net v5 4/6] igb: link queues to NAPIs under RTNL after runtime resume Antonio Quartulli
@ 2026-11-24 23:57 ` Antonio Quartulli
  2026-11-28 13:38   ` Janis Edvarts Lacis
  2026-11-29  0:37   ` netdev-bot+sashiko
  2026-11-24 23:57 ` [PATCH net v5 6/6] igb: only allow runtime PM if the device can wake up Antonio Quartulli
  2026-11-28 13:32 ` [PATCH net v5 0/6] igb: fix runtime PM resume issues Janis Edvarts Lacis
  6 siblings, 2 replies; 18+ messages in thread
From: Antonio Quartulli @ 2026-11-24 23:57 UTC (permalink / raw)
  To: intel-wired-lan
  Cc: Antonio Quartulli, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Janis Edvarts Lacis, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
	Sven Auhagen, Sriram Yagnaraman, Kurt Kanzenbach,
	Maciej Fijalkowski, netdev, linux-kernel, bpf, stable

igb_xdp() can run while the device is runtime suspended or resuming,
and __igb_resume() rebuilds the queue counts and the rings without
RTNL. igb_xdp_setup() and igb_xsk_pool_setup() can then see a queue
count whose rings don't exist yet (NULL dereference), or a NAPI that
isn't enabled yet (napi_disable() never returns). Changing the XDP
program of a runtime suspended device also opened it twice.

Resume the device for the duration of igb_xdp(), as ethtool does. Like
the other resumes done with RTNL held, this can still deadlock with a
runtime suspend already in progress, which takes RTNL itself; closing
an AF_XDP socket or changing the XDP program is now one of them.

Tested with the 82576 emulated by QEMU by closing a zero-copy AF_XDP
socket and attaching an XDP program while the device is runtime
suspended; the latter no longer warns in __netif_napi_del_locked()
because of the double open. The races themselves weren't reproduced.

Fixes: 9cbc948b5a20 ("igb: add XDP support")
Fixes: 80f6ccf9f116 ("igb: Introduce XSK data structures and helpers")
Cc: stable@vger.kernel.org
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
v5: new patch (Sashiko)

 drivers/net/ethernet/intel/igb/igb_main.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index acd9a33..80ae03d 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -2942,16 +2942,28 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)
 static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 {
 	struct igb_adapter *adapter = netdev_priv(dev);
+	int err;
+
+	/* The rings only exist while the device is resumed, and resuming
+	 * rebuilds them without RTNL
+	 */
+	pm_runtime_get_sync(&adapter->pdev->dev);
 
 	switch (xdp->command) {
 	case XDP_SETUP_PROG:
-		return igb_xdp_setup(dev, xdp);
+		err = igb_xdp_setup(dev, xdp);
+		break;
 	case XDP_SETUP_XSK_POOL:
-		return igb_xsk_pool_setup(adapter, xdp->xsk.pool,
-					  xdp->xsk.queue_id);
+		err = igb_xsk_pool_setup(adapter, xdp->xsk.pool,
+					 xdp->xsk.queue_id);
+		break;
 	default:
-		return -EINVAL;
+		err = -EINVAL;
 	}
+
+	pm_runtime_put(&adapter->pdev->dev);
+
+	return err;
 }
 
 int igb_xdp_xmit_back(struct igb_adapter *adapter, struct xdp_buff *xdp)
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH net v5 6/6] igb: only allow runtime PM if the device can wake up
  2026-11-24 23:57 [PATCH net v5 0/6] igb: fix runtime PM resume issues Antonio Quartulli
                   ` (4 preceding siblings ...)
  2026-11-24 23:57 ` [PATCH net v5 5/6] igb: resume the device before changing XDP or XSK settings Antonio Quartulli
@ 2026-11-24 23:57 ` Antonio Quartulli
  2026-11-28 13:40   ` Janis Edvarts Lacis
  2026-11-28 13:32 ` [PATCH net v5 0/6] igb: fix runtime PM resume issues Janis Edvarts Lacis
  6 siblings, 1 reply; 18+ messages in thread
From: Antonio Quartulli @ 2026-11-24 23:57 UTC (permalink / raw)
  To: intel-wired-lan
  Cc: Antonio Quartulli, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Janis Edvarts Lacis, netdev, linux-kernel, stable

igb lets the device be runtime suspended even if it can't signal a
wake-up from D3. Such a device doesn't notice the link coming back, so
the port stays down until it is resumed from user space.

Only schedule a runtime suspend if pci_dev_run_wake() is true. Devices
that can't wake up no longer runtime suspend, even with power/control
set to auto. Checking it when scheduling the suspend, rather than at
probe and remove as e1000e and r8169 do, keeps the runtime PM usage
count balanced if the result changes while the driver is bound.

Tested with the 82576 emulated by QEMU.

Fixes: 749ab2cd1270 ("igb: add basic runtime PM support")
Cc: stable@vger.kernel.org
Closes: https://bugzilla.ipfire.org/show_bug.cgi?id=13562
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
v5: check pci_dev_run_wake() when scheduling the suspend rather than
at probe and remove, which keeps the usage count balanced (Sashiko)
v4: no changes
v3: no changes
v2: no code changes; mention the tested hardware

Note: igc has the same issue: igc_probe() also allows runtime PM
regardless of pci_dev_run_wake().

 drivers/net/ethernet/intel/igb/igb_main.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 80ae03d..853bdf4 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -5625,6 +5625,15 @@ static void igb_watchdog(struct timer_list *t)
 	schedule_work(&adapter->watchdog_task);
 }
 
+/* A device that can't wake up wouldn't notice the link coming back while
+ * runtime suspended
+ */
+static void igb_schedule_runtime_suspend(struct igb_adapter *adapter)
+{
+	if (pci_dev_run_wake(adapter->pdev))
+		pm_schedule_suspend(&adapter->pdev->dev, MSEC_PER_SEC * 5);
+}
+
 static void igb_watchdog_task(struct work_struct *work)
 {
 	struct igb_adapter *adapter = container_of(work,
@@ -5777,8 +5786,7 @@ no_wait:
 					return;
 				}
 			}
-			pm_schedule_suspend(netdev->dev.parent,
-					    MSEC_PER_SEC * 5);
+			igb_schedule_runtime_suspend(adapter);
 
 		/* also check for alternate media here */
 		} else if (!netif_carrier_ok(netdev) &&
@@ -9741,7 +9749,7 @@ static int igb_runtime_idle(struct device *dev)
 	struct igb_adapter *adapter = netdev_priv(netdev);
 
 	if (!igb_has_link(adapter))
-		pm_schedule_suspend(dev, MSEC_PER_SEC * 5);
+		igb_schedule_runtime_suspend(adapter);
 
 	return -EBUSY;
 }
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH net v5 0/6] igb: fix runtime PM resume issues
  2026-11-24 23:57 [PATCH net v5 0/6] igb: fix runtime PM resume issues Antonio Quartulli
                   ` (5 preceding siblings ...)
  2026-11-24 23:57 ` [PATCH net v5 6/6] igb: only allow runtime PM if the device can wake up Antonio Quartulli
@ 2026-11-28 13:32 ` Janis Edvarts Lacis
  6 siblings, 0 replies; 18+ messages in thread
From: Janis Edvarts Lacis @ 2026-11-28 13:32 UTC (permalink / raw)
  To: Antonio Quartulli
  Cc: intel-wired-lan, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Stanislav Fomichev, Sriram Yagnaraman,
	Kurt Kanzenbach, Maciej Fijalkowski, Heiner Kallweit, Joe Damato,
	Sven Auhagen, netdev, linux-kernel, bpf

On 25 Nov 00:57, Antonio Quartulli wrote:
>igb can be runtime suspended when the link goes down (with
>power/control set to auto). Resuming it calls functions that need RTNL
>without holding it (patches 2 and 4), XDP and XSK changes race with a
>resume (patch 5), and devices that can't signal a wake-up are suspended
>anyway, so their port stays down when the link comes back (patch 6).
>
>Patch 1 fixes the XSK pool disable path when the device has fewer rings
>than the stack has queues: a NULL dereference with VFs (a single Tx
>queue on 82576), or after a fallback from MSI-X to MSI on resume. Patch
>3 keeps such queues while they still have an XSK pool, so that the pool
>can still be disabled.
>
>Tested with the 82576 emulated by QEMU, including, with test-only hooks,
>a runtime resume and a simulated system sleep (the suspend/resume
>callbacks called directly, as the test kernel has no CONFIG_SUSPEND)
>with the device forced to come back with MSI and a single queue.
>Patches 1 and 3 were tested with a zero-copy AF_XDP socket: closing it
>after enabling a VF oopses (queue 1, stock igb and v3) or warns and
>leaks (queue 2, v4), and warns after a resume forced to use MSI (v4);
>patch 5 by closing a socket and attaching an XDP program while runtime
>suspended. Not tested: real hardware and PME wake-up, a real system
>sleep, the MSI-X allocation failure itself, the window before the work
>item runs, SR-IOV with runtime PM, and a device that can wake up. Not
>run under KASAN.
>
>Sashiko also found two pre-existing issues in the XSK queue disable/
>enable paths (the Tx NAPI isn't stopped when Rx and Tx don't share a
>vector; a failed buffer reallocation leaves the queue half torn down);
>they will be fixed separately.
>
>igc has the same issues (see the notes); Joe Damato offered to test on
>igc, so its fix will be sent separately.
>
>Changes in v5:
>- new patch 3: keep the stack's Rx queues that still have an XSK pool
>  (Janis)
>- patch 4: cancel the work item before a suspend (Sashiko)
>- new patch 5: resume the device before changing XDP or XSK settings
>  (Sashiko)
>- patch 6: check pci_dev_run_wake() when scheduling the suspend
>  (Sashiko)
>
>Changes in v4:
>- patch 1: also handle queues with an Rx but no Tx ring, as with VFs:
>  tear down the Rx ring and skip only the Tx part (Sashiko); subject
>  changed from "don't disable rings ..." to "don't touch rings ..."
>
>Changes in v3:
>- new patch 1
>- patch 2: set the real queue counts on system sleep resume and from a
>  work item on runtime resume, and drop packets for queues the device
>  doesn't have until then (Janis, Sashiko)
>- patch 3 (now 4): link the NAPIs from the same work item
>
>Changes in v2:
>- patch 2 (v2 patch 1): keep setting the queue counts in __igb_open(),
>  only skipping them on resume (Sashiko)
>- mention the tested hardware in the commit messages
>
>v4: https://lore.kernel.org/netdev/20261120210134.133238-1-antonio@mandelbit.com/
>v3: https://lore.kernel.org/netdev/20261119140412.163202-1-antonio@mandelbit.com/
>v2: https://lore.kernel.org/netdev/20261116153041.3002666-1-antonio@mandelbit.com/
>v1: https://lore.kernel.org/netdev/20261113105835.3821433-1-antonio@mandelbit.com/
>
>Antonio Quartulli (6):
>  igb: don't touch rings that don't exist when disabling an XSK pool
>  igb: fix RTNL assertion when resuming from runtime suspend
>  igb: keep the stack's Rx queues that still have an XSK pool
>  igb: link queues to NAPIs under RTNL after runtime resume
>  igb: resume the device before changing XDP or XSK settings
>  igb: only allow runtime PM if the device can wake up
>
> drivers/net/ethernet/intel/igb/igb.h      |   1 +
> drivers/net/ethernet/intel/igb/igb_main.c | 144 +++++++++++++++++-----
> drivers/net/ethernet/intel/igb/igb_xsk.c  |  37 ++++--
> 3 files changed, 143 insertions(+), 39 deletions(-)
>
>-- 
>2.56.1
>
Reviewed-by: Janis Edvarts Lacis <janislacis06@gmail.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net v5 1/6] igb: don't touch rings that don't exist when disabling an XSK pool
  2026-11-24 23:57 ` [PATCH net v5 1/6] igb: don't touch rings that don't exist when disabling an XSK pool Antonio Quartulli
@ 2026-11-28 13:36   ` Janis Edvarts Lacis
  2026-11-29  0:37   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: Janis Edvarts Lacis @ 2026-11-28 13:36 UTC (permalink / raw)
  To: Antonio Quartulli
  Cc: intel-wired-lan, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Stanislav Fomichev, Sriram Yagnaraman,
	Kurt Kanzenbach, Maciej Fijalkowski, netdev, linux-kernel, bpf,
	stable

On 25 Nov 00:57, 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. This also stops a NULL
>dereference when the socket is closed while the device is runtime
>suspended, which frees its rings.
>
>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>
>---
>v5: the message also mentions the runtime suspended case (no code
>changes)
>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
>
Reviewed-by: Janis Edvarts Lacis <janislacis06@gmail.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net v5 2/6] igb: fix RTNL assertion when resuming from runtime suspend
  2026-11-24 23:57 ` [PATCH net v5 2/6] igb: fix RTNL assertion when resuming from runtime suspend Antonio Quartulli
@ 2026-11-28 13:37   ` Janis Edvarts Lacis
  2026-11-29  0:37   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: Janis Edvarts Lacis @ 2026-11-28 13:37 UTC (permalink / raw)
  To: Antonio Quartulli
  Cc: intel-wired-lan, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Heiner Kallweit, netdev, linux-kernel, stable

On 25 Nov 00:57, Antonio Quartulli wrote:
>Since commit ac8c58f5b535 ("igb: fix deadlock caused by taking RTNL in
>RPM resume path") __igb_resume() doesn't take RTNL for runtime resume,
>but __igb_open() still calls netif_set_real_num_{tx,rx}_queues(), which
>require it. An asynchronous runtime resume (e.g. after the link comes
>back) then triggers "RTNL: assertion failed".
>
>Only set the real queue counts in __igb_open() when RTNL is held (open
>and system sleep resume), and set them from a work item taking RTNL on
>runtime resume. Until it runs, after a fallback to fewer queues on
>resume (MSI-X to MSI), the stack can use queues the device doesn't
>have: drop those packets in igb_xmit_frame() instead of mapping several
>stack queues, each with its own xmit lock, onto the same ring. The
>stack can't be kept off those queues instead, as __igb_open() and
>netif_device_attach() start all of them and changing the count needs
>RTNL.
>
>Tested with the 82576 emulated by QEMU.
>
>Fixes: ac8c58f5b535 ("igb: fix deadlock caused by taking RTNL in RPM resume path")
>Cc: stable@vger.kernel.org
>Closes: https://bugzilla.ipfire.org/show_bug.cgi?id=13562
>Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
>---
>v5: no changes
>v4: no changes
>v3:
>- set the real queue counts when RTNL is held (open and system sleep
>  resume), and from a work item on runtime resume, instead of not at all
>  on resume (Janis, Sashiko)
>- until then, drop packets for queues the device doesn't have
>- stable: netif_set_real_num_queues() needs 5.15+ and
>  dev_core_stats_tx_dropped_inc() 5.18+; older backports can use the
>  separate tx/rx calls and netdev->stats.tx_dropped
>v2:
>- keep setting the queue counts in __igb_open() after igb_request_irq(),
>  only skipping them on resume (Sashiko)
>- drop the reference to igc
>
>Note: igc has the same issue: it sets the real queue counts only in
>igc_open(), before requesting the IRQs, and never on resume. A fix will
>follow separately once it has been tested on igc hardware (Joe offered
>to test).
>
> drivers/net/ethernet/intel/igb/igb.h      |  1 +
> drivers/net/ethernet/intel/igb/igb_main.c | 73 ++++++++++++++++-------
> 2 files changed, 54 insertions(+), 20 deletions(-)
>
>diff --git a/drivers/net/ethernet/intel/igb/igb.h b/drivers/net/ethernet/intel/igb/igb.h
>index 8c9b020..79d7fcc 100644
>--- a/drivers/net/ethernet/intel/igb/igb.h
>+++ b/drivers/net/ethernet/intel/igb/igb.h
>@@ -586,6 +586,7 @@ struct igb_adapter {
>
> 	struct work_struct reset_task;
> 	struct work_struct watchdog_task;
>+	struct work_struct rtnl_resume_task;
> 	bool fc_autoneg;
> 	u8  tx_timeout_factor;
> 	struct timer_list blink_timer;
>diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
>index d4a897a..2f51edc 100644
>--- a/drivers/net/ethernet/intel/igb/igb_main.c
>+++ b/drivers/net/ethernet/intel/igb/igb_main.c
>@@ -110,6 +110,7 @@ static void igb_init_queue_configuration(struct igb_adapter *adapter);
> static int igb_sw_init(struct igb_adapter *);
> int igb_open(struct net_device *);
> int igb_close(struct net_device *);
>+static void igb_rtnl_resume_task(struct work_struct *);
> static void igb_configure(struct igb_adapter *);
> static void igb_configure_tx(struct igb_adapter *);
> static void igb_configure_rx(struct igb_adapter *);
>@@ -3426,6 +3427,7 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>
> 	INIT_WORK(&adapter->reset_task, igb_reset_task);
> 	INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
>+	INIT_WORK(&adapter->rtnl_resume_task, igb_rtnl_resume_task);
>
> 	/* Initialize link properties that are user-changeable */
> 	adapter->fc_autoneg = true;
>@@ -3889,6 +3891,7 @@ static void igb_remove(struct pci_dev *pdev)
>
> 	cancel_work_sync(&adapter->reset_task);
> 	cancel_work_sync(&adapter->watchdog_task);
>+	cancel_work_sync(&adapter->rtnl_resume_task);
>
> #ifdef CONFIG_IGB_DCA
> 	if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
>@@ -4123,10 +4126,31 @@ static int igb_sw_init(struct igb_adapter *adapter)
> 	return 0;
> }
>
>+/* Some settings need RTNL, which isn't held when resuming from runtime
>+ * suspend: apply them from here instead, if the device is still up.
>+ */
>+static void igb_rtnl_resume_task(struct work_struct *work)
>+{
>+	struct igb_adapter *adapter = container_of(work, struct igb_adapter,
>+						   rtnl_resume_task);
>+
>+	rtnl_lock();
>+	if (!test_bit(__IGB_DOWN, &adapter->state) &&
>+	    netif_running(adapter->netdev)) {
>+		if (netif_set_real_num_queues(adapter->netdev,
>+					      adapter->num_tx_queues,
>+					      adapter->num_rx_queues))
>+			netdev_err(adapter->netdev,
>+				   "error setting real queue count\n");
>+	}
>+	rtnl_unlock();
>+}
>+
> /**
>  *  __igb_open - Called when a network interface is made active
>  *  @netdev: network interface device structure
>  *  @resuming: indicates whether we are in a resume call
>+ *  @rtnl_held: indicates whether RTNL is held
>  *
>  *  Returns 0 on success, negative value on failure
>  *
>@@ -4136,7 +4160,8 @@ static int igb_sw_init(struct igb_adapter *adapter)
>  *  handler is registered with the OS, the watchdog timer is started,
>  *  and the stack is notified that the interface is ready.
>  **/
>-static int __igb_open(struct net_device *netdev, bool resuming)
>+static int __igb_open(struct net_device *netdev, bool resuming,
>+		      bool rtnl_held)
> {
> 	struct igb_adapter *adapter = netdev_priv(netdev);
> 	struct pci_dev *pdev = adapter->pdev;
>@@ -4179,16 +4204,15 @@ static int __igb_open(struct net_device *netdev, bool resuming)
> 	if (err)
> 		goto err_req_irq;
>
>-	/* Notify the stack of the actual queue counts. */
>-	err = netif_set_real_num_tx_queues(adapter->netdev,
>-					   adapter->num_tx_queues);
>-	if (err)
>-		goto err_set_queues;
>-
>-	err = netif_set_real_num_rx_queues(adapter->netdev,
>-					   adapter->num_rx_queues);
>-	if (err)
>-		goto err_set_queues;
>+	/* Notify the stack of the actual queue counts. This needs RTNL: on
>+	 * runtime resume igb_rtnl_resume_task() does it.
>+	 */
>+	if (rtnl_held) {
>+		err = netif_set_real_num_queues(netdev, adapter->num_tx_queues,
>+						adapter->num_rx_queues);
>+		if (err)
>+			goto err_set_queues;
>+	}
>
> 	/* From here on the code is the same as igb_up() */
> 	clear_bit(__IGB_DOWN, &adapter->state);
>@@ -4242,7 +4266,7 @@ err_setup_tx:
>
> int igb_open(struct net_device *netdev)
> {
>-	return __igb_open(netdev, false);
>+	return __igb_open(netdev, false, true);
> }
>
> /**
>@@ -6617,12 +6641,7 @@ cleanup_tx_tstamp:
> static inline struct igb_ring *igb_tx_queue_mapping(struct igb_adapter *adapter,
> 						    struct sk_buff *skb)
> {
>-	unsigned int r_idx = skb->queue_mapping;
>-
>-	if (r_idx >= adapter->num_tx_queues)
>-		r_idx = r_idx % adapter->num_tx_queues;
>-
>-	return adapter->tx_ring[r_idx];
>+	return adapter->tx_ring[skb->queue_mapping];
> }
>
> static netdev_tx_t igb_xmit_frame(struct sk_buff *skb,
>@@ -6636,6 +6655,17 @@ static netdev_tx_t igb_xmit_frame(struct sk_buff *skb,
> 	if (skb_put_padto(skb, 17))
> 		return NETDEV_TX_OK;
>
>+	/* After a fallback to fewer queues on runtime resume, the stack can
>+	 * use more queues than the device has until igb_rtnl_resume_task()
>+	 * updates it: drop those packets instead of sharing a ring between
>+	 * queues, which aren't serialized with each other.
>+	 */
>+	if (unlikely(skb->queue_mapping >= adapter->num_tx_queues)) {
>+		dev_kfree_skb_any(skb);
>+		dev_core_stats_tx_dropped_inc(netdev);
>+		return NETDEV_TX_OK;
>+	}
>+
> 	return igb_xmit_frame_ring(skb, igb_tx_queue_mapping(adapter, skb));
> }
>
>@@ -9639,8 +9669,11 @@ static int __igb_resume(struct device *dev, bool rpm)
>
> 	if (!rpm)
> 		rtnl_lock();
>-	if (!err && netif_running(netdev))
>-		err = __igb_open(netdev, true);
>+	if (!err && netif_running(netdev)) {
>+		err = __igb_open(netdev, true, !rpm);
>+		if (!err && rpm)
>+			schedule_work(&adapter->rtnl_resume_task);
>+	}
>
> 	if (!err)
> 		netif_device_attach(netdev);
>-- 
>2.56.1
>
Reviewed-by: Janis Edvarts Lacis <janislacis06@gmail.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net v5 3/6] igb: keep the stack's Rx queues that still have an XSK pool
  2026-11-24 23:57 ` [PATCH net v5 3/6] igb: keep the stack's Rx queues that still have an XSK pool Antonio Quartulli
@ 2026-11-28 13:37   ` Janis Edvarts Lacis
  2026-11-29  0:37   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: Janis Edvarts Lacis @ 2026-11-28 13:37 UTC (permalink / raw)
  To: Antonio Quartulli
  Cc: intel-wired-lan, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Sriram Yagnaraman, Kurt Kanzenbach, Maciej Fijalkowski, netdev,
	linux-kernel, stable

On 25 Nov 00:57, Antonio Quartulli wrote:
>When igb lowers its queue counts by itself, after a fallback from MSI-X
>to MSI on resume or when enabling VFs, xsk_get_pool_from_qid() doesn't
>find the pool of a socket bound to a removed queue anymore. Disabling
>it then fails ("Failed to disable zero-copy!") and the pool's DMA
>mappings are never unmapped.
>
>ethtool refuses to remove a queue that still has an XSK pool, but igb
>can't refuse a VF enable or a resume fallback. Keep the real Rx queue
>count up to the highest queue that still has an XSK pool instead, so
>that the pool can still be disabled, and lower it at the next open. The
>Tx count follows the device: an XSK pool is always bound to both an Rx
>and a Tx queue, and the lookup finds it through the Rx one.
>
>Tested with the 82576 emulated by QEMU and a zero-copy AF_XDP socket,
>bound to queue 2 when enabling a VF, and to queue 1 across a runtime
>resume forced to use MSI with a single queue (with a test hook): closing
>it warned and leaked before, not anymore.
>
>Fixes: 80f6ccf9f116 ("igb: Introduce XSK data structures and helpers")
>Cc: stable@vger.kernel.org # 6.14+
>Reported-by: Janis Edvarts Lacis <janislacis06@gmail.com>
>Closes: https://lore.kernel.org/netdev/xupy6jbpnziq2qji54zjbvm7neggrwkxg3sfrhlolmrd6ysifl@zptk6ynkbu5f/
>Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
>---
>v5: new patch (Janis)
>
> drivers/net/ethernet/intel/igb/igb_main.c | 27 ++++++++++++++++++-----
> 1 file changed, 22 insertions(+), 5 deletions(-)
>
>diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
>index 2f51edc..6961646 100644
>--- a/drivers/net/ethernet/intel/igb/igb_main.c
>+++ b/drivers/net/ethernet/intel/igb/igb_main.c
>@@ -4126,6 +4126,26 @@ static int igb_sw_init(struct igb_adapter *adapter)
> 	return 0;
> }
>
>+/* ethtool refuses to remove a queue that still has an XSK pool. igb can't
>+ * refuse when it lowers its queue counts by itself, so keep the stack's Rx
>+ * queue instead, or the pool couldn't be disabled anymore: lower the count
>+ * once it's gone, at the next open.
>+ */
>+static int igb_set_real_num_queues(struct igb_adapter *adapter)
>+{
>+	struct net_device *netdev = adapter->netdev;
>+	unsigned int rxq = adapter->num_rx_queues;
>+	unsigned int i;
>+
>+	for (i = netdev->real_num_rx_queues; i > rxq; i--)
>+		if (xsk_get_pool_from_qid(netdev, i - 1)) {
>+			rxq = i;
>+			break;
>+		}
>+
>+	return netif_set_real_num_queues(netdev, adapter->num_tx_queues, rxq);
>+}
>+
> /* Some settings need RTNL, which isn't held when resuming from runtime
>  * suspend: apply them from here instead, if the device is still up.
>  */
>@@ -4137,9 +4157,7 @@ static void igb_rtnl_resume_task(struct work_struct *work)
> 	rtnl_lock();
> 	if (!test_bit(__IGB_DOWN, &adapter->state) &&
> 	    netif_running(adapter->netdev)) {
>-		if (netif_set_real_num_queues(adapter->netdev,
>-					      adapter->num_tx_queues,
>-					      adapter->num_rx_queues))
>+		if (igb_set_real_num_queues(adapter))
> 			netdev_err(adapter->netdev,
> 				   "error setting real queue count\n");
> 	}
>@@ -4208,8 +4226,7 @@ static int __igb_open(struct net_device *netdev, bool resuming,
> 	 * runtime resume igb_rtnl_resume_task() does it.
> 	 */
> 	if (rtnl_held) {
>-		err = netif_set_real_num_queues(netdev, adapter->num_tx_queues,
>-						adapter->num_rx_queues);
>+		err = igb_set_real_num_queues(adapter);
> 		if (err)
> 			goto err_set_queues;
> 	}
>-- 
>2.56.1
>
Reviewed-by: Janis Edvarts Lacis <janislacis06@gmail.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net v5 4/6] igb: link queues to NAPIs under RTNL after runtime resume
  2026-11-24 23:57 ` [PATCH net v5 4/6] igb: link queues to NAPIs under RTNL after runtime resume Antonio Quartulli
@ 2026-11-28 13:38   ` Janis Edvarts Lacis
  0 siblings, 0 replies; 18+ messages in thread
From: Janis Edvarts Lacis @ 2026-11-28 13:38 UTC (permalink / raw)
  To: Antonio Quartulli
  Cc: intel-wired-lan, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Kurt Kanzenbach, Joe Damato, netdev, linux-kernel, stable

On 25 Nov 00:57, Antonio Quartulli wrote:
>__igb_open() links queues to NAPIs with netif_queue_set_napi(), which
>requires RTNL, but RTNL isn't held when resuming from runtime suspend:
>this triggers "RTNL: assertion failed".
>
>Link them in __igb_open() only when RTNL is held, and from the work
>item that sets the real queue counts on runtime resume. The links can't
>be kept across a suspend, because __igb_shutdown() frees the q_vectors.
>A suspend now cancels the work item before freeing them, so it only runs
>after the resume that scheduled it allocated them, and it checks
>__IGB_DOWN under RTNL for a close in the meantime.
>
>Tested with the 82576 emulated by QEMU.
>
>Fixes: b75a1dea500f ("igb: Link queues to NAPI instances")
>Cc: stable@vger.kernel.org # 6.16+
>Closes: https://bugzilla.ipfire.org/show_bug.cgi?id=13562
>Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
>---
>v5: cancel the work item before a suspend (Sashiko)
>v4: no changes
>v3: link the NAPIs from the work item added by the previous patch, and
>in __igb_open() whenever RTNL is held (also on system sleep resume);
>dropped Joe's Reviewed-by, as the patch changed
>v2: no code changes; mention the tested hardware
>
>Note: igc has the same issue: __igc_open() also links queues to NAPIs
>(igc_set_queue_napi()) on the RTNL-less runtime resume path. A fix will
>follow separately once it has been tested on igc hardware.
>
> drivers/net/ethernet/intel/igb/igb_main.c | 22 ++++++++++++++++++++--
> 1 file changed, 20 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
>index 6961646..acd9a33 100644
>--- a/drivers/net/ethernet/intel/igb/igb_main.c
>+++ b/drivers/net/ethernet/intel/igb/igb_main.c
>@@ -4146,8 +4146,19 @@ static int igb_set_real_num_queues(struct igb_adapter *adapter)
> 	return netif_set_real_num_queues(netdev, adapter->num_tx_queues, rxq);
> }
>
>+static void igb_link_queue_napis(struct igb_adapter *adapter)
>+{
>+	int i;
>+
>+	for (i = 0; i < adapter->num_q_vectors; i++)
>+		igb_set_queue_napi(adapter, i, &adapter->q_vector[i]->napi);
>+}
>+
> /* Some settings need RTNL, which isn't held when resuming from runtime
>- * suspend: apply them from here instead, if the device is still up.
>+ * suspend: apply them from here instead, if the device is still up. A
>+ * suspend cancels this work before freeing the q_vectors, so it only runs
>+ * after the resume that scheduled it allocated them; checking __IGB_DOWN
>+ * under RTNL covers a close in the meantime.
>  */
> static void igb_rtnl_resume_task(struct work_struct *work)
> {
>@@ -4160,6 +4171,7 @@ static void igb_rtnl_resume_task(struct work_struct *work)
> 		if (igb_set_real_num_queues(adapter))
> 			netdev_err(adapter->netdev,
> 				   "error setting real queue count\n");
>+		igb_link_queue_napis(adapter);
> 	}
> 	rtnl_unlock();
> }
>@@ -4237,7 +4249,8 @@ static int __igb_open(struct net_device *netdev, bool resuming,
> 	for (i = 0; i < adapter->num_q_vectors; i++) {
> 		napi = &adapter->q_vector[i]->napi;
> 		napi_enable(napi);
>-		igb_set_queue_napi(adapter, i, napi);
>+		if (rtnl_held)
>+			igb_set_queue_napi(adapter, i, napi);
> 	}
>
> 	/* Clear any pending interrupts. */
>@@ -9548,6 +9561,11 @@ static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake,
> 	u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
> 	bool wake;
>
>+	/* Don't let a work item queued by an earlier resume run once the
>+	 * q_vectors are freed or reallocated
>+	 */
>+	cancel_work_sync(&adapter->rtnl_resume_task);
>+
> 	rtnl_lock();
> 	netif_device_detach(netdev);
>
>-- 
>2.56.1
>
Reviewed-by: Janis Edvarts Lacis <janislacis06@gmail.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net v5 5/6] igb: resume the device before changing XDP or XSK settings
  2026-11-24 23:57 ` [PATCH net v5 5/6] igb: resume the device before changing XDP or XSK settings Antonio Quartulli
@ 2026-11-28 13:38   ` Janis Edvarts Lacis
  2026-11-29  0:37   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: Janis Edvarts Lacis @ 2026-11-28 13:38 UTC (permalink / raw)
  To: Antonio Quartulli
  Cc: intel-wired-lan, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Stanislav Fomichev, Sven Auhagen,
	Sriram Yagnaraman, Kurt Kanzenbach, Maciej Fijalkowski, netdev,
	linux-kernel, bpf

On 25 Nov 00:57, Antonio Quartulli wrote:
>igb_xdp() can run while the device is runtime suspended or resuming,
>and __igb_resume() rebuilds the queue counts and the rings without
>RTNL. igb_xdp_setup() and igb_xsk_pool_setup() can then see a queue
>count whose rings don't exist yet (NULL dereference), or a NAPI that
>isn't enabled yet (napi_disable() never returns). Changing the XDP
>program of a runtime suspended device also opened it twice.
>
>Resume the device for the duration of igb_xdp(), as ethtool does. Like
>the other resumes done with RTNL held, this can still deadlock with a
>runtime suspend already in progress, which takes RTNL itself; closing
>an AF_XDP socket or changing the XDP program is now one of them.
>
>Tested with the 82576 emulated by QEMU by closing a zero-copy AF_XDP
>socket and attaching an XDP program while the device is runtime
>suspended; the latter no longer warns in __netif_napi_del_locked()
>because of the double open. The races themselves weren't reproduced.
>
>Fixes: 9cbc948b5a20 ("igb: add XDP support")
>Fixes: 80f6ccf9f116 ("igb: Introduce XSK data structures and helpers")
>Cc: stable@vger.kernel.org
>Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
>---
>v5: new patch (Sashiko)
>
> drivers/net/ethernet/intel/igb/igb_main.c | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
>diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
>index acd9a33..80ae03d 100644
>--- a/drivers/net/ethernet/intel/igb/igb_main.c
>+++ b/drivers/net/ethernet/intel/igb/igb_main.c
>@@ -2942,16 +2942,28 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)
> static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp)
> {
> 	struct igb_adapter *adapter = netdev_priv(dev);
>+	int err;
>+
>+	/* The rings only exist while the device is resumed, and resuming
>+	 * rebuilds them without RTNL
>+	 */
>+	pm_runtime_get_sync(&adapter->pdev->dev);
>
> 	switch (xdp->command) {
> 	case XDP_SETUP_PROG:
>-		return igb_xdp_setup(dev, xdp);
>+		err = igb_xdp_setup(dev, xdp);
>+		break;
> 	case XDP_SETUP_XSK_POOL:
>-		return igb_xsk_pool_setup(adapter, xdp->xsk.pool,
>-					  xdp->xsk.queue_id);
>+		err = igb_xsk_pool_setup(adapter, xdp->xsk.pool,
>+					 xdp->xsk.queue_id);
>+		break;
> 	default:
>-		return -EINVAL;
>+		err = -EINVAL;
> 	}
>+
>+	pm_runtime_put(&adapter->pdev->dev);
>+
>+	return err;
> }
>
> int igb_xdp_xmit_back(struct igb_adapter *adapter, struct xdp_buff *xdp)
>-- 
>2.56.1
>
Reviewed-by: Janis Edvarts Lacis <janislacis06@gmail.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net v5 6/6] igb: only allow runtime PM if the device can wake up
  2026-11-24 23:57 ` [PATCH net v5 6/6] igb: only allow runtime PM if the device can wake up Antonio Quartulli
@ 2026-11-28 13:40   ` Janis Edvarts Lacis
  0 siblings, 0 replies; 18+ messages in thread
From: Janis Edvarts Lacis @ 2026-11-28 13:40 UTC (permalink / raw)
  To: Antonio Quartulli
  Cc: intel-wired-lan, Tony Nguyen, Przemek Kitszel, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev, linux-kernel, stable

On 25 Nov 00:57, Antonio Quartulli wrote:
>igb lets the device be runtime suspended even if it can't signal a
>wake-up from D3. Such a device doesn't notice the link coming back, so
>the port stays down until it is resumed from user space.
>
>Only schedule a runtime suspend if pci_dev_run_wake() is true. Devices
>that can't wake up no longer runtime suspend, even with power/control
>set to auto. Checking it when scheduling the suspend, rather than at
>probe and remove as e1000e and r8169 do, keeps the runtime PM usage
>count balanced if the result changes while the driver is bound.
>
>Tested with the 82576 emulated by QEMU.
>
>Fixes: 749ab2cd1270 ("igb: add basic runtime PM support")
>Cc: stable@vger.kernel.org
>Closes: https://bugzilla.ipfire.org/show_bug.cgi?id=13562
>Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
>---
>v5: check pci_dev_run_wake() when scheduling the suspend rather than
>at probe and remove, which keeps the usage count balanced (Sashiko)
>v4: no changes
>v3: no changes
>v2: no code changes; mention the tested hardware
>
>Note: igc has the same issue: igc_probe() also allows runtime PM
>regardless of pci_dev_run_wake().
>
> drivers/net/ethernet/intel/igb/igb_main.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
>diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
>index 80ae03d..853bdf4 100644
>--- a/drivers/net/ethernet/intel/igb/igb_main.c
>+++ b/drivers/net/ethernet/intel/igb/igb_main.c
>@@ -5625,6 +5625,15 @@ static void igb_watchdog(struct timer_list *t)
> 	schedule_work(&adapter->watchdog_task);
> }
>
>+/* A device that can't wake up wouldn't notice the link coming back while
>+ * runtime suspended
>+ */
>+static void igb_schedule_runtime_suspend(struct igb_adapter *adapter)
>+{
>+	if (pci_dev_run_wake(adapter->pdev))
>+		pm_schedule_suspend(&adapter->pdev->dev, MSEC_PER_SEC * 5);
>+}
>+
> static void igb_watchdog_task(struct work_struct *work)
> {
> 	struct igb_adapter *adapter = container_of(work,
>@@ -5777,8 +5786,7 @@ no_wait:
> 					return;
> 				}
> 			}
>-			pm_schedule_suspend(netdev->dev.parent,
>-					    MSEC_PER_SEC * 5);
>+			igb_schedule_runtime_suspend(adapter);
>
> 		/* also check for alternate media here */
> 		} else if (!netif_carrier_ok(netdev) &&
>@@ -9741,7 +9749,7 @@ static int igb_runtime_idle(struct device *dev)
> 	struct igb_adapter *adapter = netdev_priv(netdev);
>
> 	if (!igb_has_link(adapter))
>-		pm_schedule_suspend(dev, MSEC_PER_SEC * 5);
>+		igb_schedule_runtime_suspend(adapter);
>
> 	return -EBUSY;
> }
>-- 
>2.56.1
>
Reviewed-by: Janis Edvarts Lacis <janislacis06@gmail.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net v5 1/6] igb: don't touch rings that don't exist when disabling an XSK pool
  2026-11-24 23:57 ` [PATCH net v5 1/6] igb: don't touch rings that don't exist when disabling an XSK pool Antonio Quartulli
  2026-11-28 13:36   ` Janis Edvarts Lacis
@ 2026-11-29  0:37   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-11-29  0:37 UTC (permalink / raw)
  To: antonio
  Cc: intel-wired-lan, anthony.l.nguyen, przemyslaw.kitszel,
	andrew+netdev, davem, edumazet, kuba, pabeni, janislacis06, kurt,
	joe, netdev, linux-kernel, stable

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

Critical: 0 · High: 1 (3) · Medium: 1 (1) · 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] At this commit, the new `qid < adapter->num_rx_queues` check in
  igb_xsk_pool_disable() and the num_tx_queues check in…
- [Medium] The new comment in igb_xsk_pool_disable()
  (drivers/net/ethernet/intel/igb/igb_xsk.c:161-163) and the commit…

Pre-existing issues:
- [High] The new gate in igb_xsk_pool_disable() is `netif_running() &&
  igb_xdp_is_enabled() && qid < adapter->num_rx_queues`…
- [High] igb_txrx_ring_disable() zeroes TXDCTL for tx_ring[qid], then
  calls igb_clean_tx_ring() and later igb_configure_tx_ring() on it.
- [High] In igb_xsk_pool_disable(), igb_realloc_rx_buffer_info(rx_ring,
  false) can fail with -ENOMEM (vmalloc).
- [Medium] This patch adds igb_xsk_tx_ring() ("With VFs, the device has a
  single Tx queue but can have more Rx queues") and changes the pool-…

--

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

This patch makes igb_txrx_ring_disable() and igb_txrx_ring_enable() skip
the Tx ring when qid is at or beyond num_tx_queues. It also makes
igb_xsk_pool_disable() skip ring teardown when qid is at or beyond
num_rx_queues, covering 82576 with VFs and the 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;
> +}
> +

[Severity: Medium]
This isn't a bug introduced by this patch, but this helper now treats a
queue that has an Rx ring using the pool and no Tx ring as a supported
state. Does igb_xsk_wakeup() need the same handling?

It still rejects such a queue before it gets to the XDP_WAKEUP_RX branch:

igb_xsk_wakeup() {
    ...
	if (qid >= adapter->num_tx_queues)
		return -EINVAL;

	ring = adapter->tx_ring[qid];

	if (!READ_ONCE(ring->xsk_pool))
		return -EINVAL;
    ...
}

Take a socket bound to queue 1 on 82576, with VFs enabled afterwards.
num_tx_queues becomes 1 while real_num_rx_queues stays 2, and
igb_configure_rx_ring() keeps Rx ring 1 in zero-copy mode. Every
need_wakeup Rx kick for that queue would then fail. Rx would only make
progress on hardware or watchdog interrupts.

igb_xsk_pool_enable() also uses a different validity rule: it checks
num_rx_queues plus both real_num_*_queues.

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

[ ... ]

> @@ -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 hold when IGB_FLAG_QUEUE_PAIRS is clear?

igb_set_flag_queue_pairs() leaves the flag clear on 82575/i211. On
82576/i350/i210 it also stays clear whenever rss_queues is at most
max_rss_queues / 2, e.g. 82576 or i350 on a host with 4 or fewer CPUs.

In that case igb_set_interrupt_capability() reserves one vector per Tx
queue, and igb_alloc_q_vectors() allocates the Rx-only vectors first. So
tx_ring[qid] sits on a different NAPI than rx_ring[qid], and that Tx NAPI
is still enabled here.

Three things can schedule that Tx NAPI:

  - an interrupt for descriptors completed before TXDCTL was cleared
  - the watchdog EICS kick
  - igb_xsk_wakeup(XDP_WAKEUP_TX)

It would then run igb_clean_tx_irq() while igb_clean_tx_ring() walks the
same tx_buffer_info entries.

igb_clean_tx_irq() doesn't check IGB_RING_FLAG_TX_DISABLED. Can both
paths free or unmap the same skb or xdp_frame, and both report xsk
completions?

The re-enable side has the same issue. igb_configure_tx_ring(), called
from igb_txrx_ring_enable(), can memset tx_buffer_info and reset the
indices while that NAPI is still walking them.

[ ... ]

> @@ -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.
> +	 */

[Severity: Medium]
Is this comment still accurate once a resume has completed?
__igb_resume() calls __igb_open(netdev, true), which passes the reduced
counts to the stack:

__igb_open() {
    ...
	/* Notify the stack of the actual queue counts. */
	err = netif_set_real_num_tx_queues(adapter->netdev,
					   adapter->num_tx_queues);
    ...
	err = netif_set_real_num_rx_queues(adapter->netdev,
					   adapter->num_rx_queues);
    ...
}

xsk_get_pool_from_qid() checks queue_id against real_num_rx_queues. After
the resume, xsk_get_pool_from_qid(dev, 1) returns NULL, so
igb_xsk_pool_disable() returns at the earlier check:

	pool = xsk_get_pool_from_qid(adapter->netdev, qid);
	if (!pool)
		return -EINVAL;

It never reaches the new num_rx_queues test. xsk_pool_dma_unmap() is
skipped, so the pool's DMA mapping leaks, and xp_disable_drv_zc() hits
its "Failed to disable zero-copy!" WARN. The leak and the WARN predate
this patch.

The new check seems to help only during the resume window itself, or
when __igb_open() fails before netif_set_real_num_*() runs. The same
applies to this part of the commit message:

  "and igb can fall back from MSI-X to MSI with a single queue on resume"

Two later patches in this series seem to fix this:

  - "igb: fix RTNL assertion when resuming from runtime suspend" stops
    lowering the real counts in __igb_open() on runtime resume.
  - "igb: keep the stack's Rx queues that still have an XSK pool" adds
    igb_set_real_num_queues().

Should the comment and commit message here describe only the cases this
patch handles?

> +	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);
>  

[Severity: High]
This isn't a bug introduced by this patch, since the old gate behaved
the same way. Does this check catch states where the rings exist and
num_rx_queues is non-zero, but the rings aren't actually up?

One such state is a failed resume. __igb_resume() first calls
igb_init_interrupt_scheme(adapter, true), which reallocates the rings
and q_vectors and restores num_rx_queues. If __igb_open(netdev, true)
then fails, the error labels free the ring resources, and napi_enable()
is never reached:

err_set_queues:
	igb_free_irq(adapter);
err_req_irq:
	igb_release_hw_control(adapter);
	igb_power_down_link(adapter);
	igb_free_all_rx_resources(adapter);
err_setup_rx:
	igb_free_all_tx_resources(adapter);

netif_running() stays true. The real queue counts were not lowered
either, so the pool is still found.

Another is PCI error recovery. igb_io_error_detected() calls igb_down(),
which napi_disable()s every q_vector, while netif_running() and the
queue counts stay the same.

Closing a zero-copy socket in either state takes this path:

xp_release_deferred()
  rtnl_lock()
  ndo_bpf
    igb_xsk_pool_disable()
      igb_txrx_ring_disable()
        napi_disable()

This NAPI is already disabled, or was never enabled. Would
napi_disable_locked() then spin forever with RTNL held?

If napi_disable() did return, igb_txrx_ring_enable() would call:

  - igb_configure_tx_ring(), which memsets the NULL tx_buffer_info
  - igb_configure_rx_ring(), which writes IGB_RX_DESC(ring, 0) with
    ring->desc == NULL

This is still the case at the end of the series. The
pm_runtime_get_sync() added to igb_xdp() later on doesn't help here.
After a failed runtime resume it returns an error that is ignored, and
it doesn't cover the PCI error path.

Would checking test_bit(__IGB_DOWN, &adapter->state) here, as
igb_xsk_wakeup() already does, close this?

[Severity: High]
Can this check race with a runtime resume?

The new num_rx_queues test here and the num_tx_queues test in
igb_xsk_tx_ring() rely on RTNL. __igb_resume(dev, true) rebuilds the same
state without it:

  - igb_init_interrupt_scheme() runs before the "if (!rpm) rtnl_lock()"
  - __igb_open() also runs without RTNL when rpm is true

igb_set_interrupt_capability() publishes the count:

	adapter->num_rx_queues = adapter->rss_queues;

igb_alloc_q_vectors() only fills adapter->rx_ring[] after that, and the
NAPIs are enabled later still, in __igb_open().

Suppose a zero-copy socket is closed while a runtime resume is running
on pm_wq. Can this check pass while rx_ring[qid] is still NULL, so that
igb_txrx_ring_disable() dereferences rx_ring->reg_idx? Or can it pass
while the ring is allocated but its NAPI isn't enabled yet, so that
napi_disable() never returns with RTNL held?

If so, the "socket is closed while the device is runtime suspended" case
from the commit message would still be reachable during the resume
itself.

The later patch "igb: resume the device before changing XDP or XSK
settings" in this series adds pm_runtime_get_sync()/pm_runtime_put()
around igb_xdp(). rpm_resume() waits for a resume that is already in
progress, so the window is closed at the end of the series.

[Severity: High]
This isn't a bug introduced by this patch, but the error path right
after this hunk seems to leave the queue half torn down:

igb_xsk_pool_disable() {
    ...
	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);
	}
    ...
}

Suppose the vmalloc in igb_realloc_rx_buffer_info() fails. By then
igb_txrx_ring_disable() has already:

  - zeroed TXDCTL/RXDCTL
  - set IGB_RING_FLAG_TX_DISABLED
  - disabled the Rx NAPI
  - cleaned both rings

None of that is undone.

rx_ring->xsk_pool and tx_ring->xsk_pool also stay set.
xp_disable_drv_zc() only warns on the error, and xp_release_deferred()
goes on to xp_destroy(pool).

Would the next igb_down() then spin in napi_disable() on the
already-disabled NAPI with RTNL held?

When queues aren't paired, can the Tx NAPI, which is still running,
reach the freed pool through igb_clean_tx_irq()?

	xsk_pool = READ_ONCE(tx_ring->xsk_pool);
	if (xsk_pool) {
		if (xsk_frames)
			xsk_tx_completed(xsk_pool, xsk_frames);
		if (xsk_uses_need_wakeup(xsk_pool))

igb_xsk_pool_enable() has the same pattern. If
igb_realloc_rx_buffer_info() fails there, the rings and NAPI disabled by
igb_txrx_ring_disable() are never re-enabled.

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net v5 2/6] igb: fix RTNL assertion when resuming from runtime suspend
  2026-11-24 23:57 ` [PATCH net v5 2/6] igb: fix RTNL assertion when resuming from runtime suspend Antonio Quartulli
  2026-11-28 13:37   ` Janis Edvarts Lacis
@ 2026-11-29  0:37   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-11-29  0:37 UTC (permalink / raw)
  To: antonio
  Cc: intel-wired-lan, anthony.l.nguyen, przemyslaw.kitszel,
	andrew+netdev, davem, edumazet, kuba, pabeni, janislacis06, kurt,
	joe, netdev, linux-kernel, stable

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] On runtime resume, __igb_resume() calls __igb_open(netdev, true,
  false).

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch's
  runtime-resume design depends on it and it stays reachable at the end…

--

igb: fix RTNL assertion when resuming from runtime suspend

On runtime resume, __igb_open() no longer sets the real queue counts.
They are now set from a new work item, igb_rtnl_resume_task(), which takes
RTNL. Until that work runs, igb_xmit_frame() drops packets for stack
queues the device doesn't have.

Closes: https://bugzilla.ipfire.org/show_bug.cgi?id=13562

> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
> index 131df3e09ba14..6b299a1429a8e 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c

[ ... ]

> @@ -4122,10 +4125,31 @@ static int igb_sw_init(struct igb_adapter *adapter)
>  	return 0;
>  }
>  
> +/* Some settings need RTNL, which isn't held when resuming from runtime
> + * suspend: apply them from here instead, if the device is still up.
> + */
> +static void igb_rtnl_resume_task(struct work_struct *work)
> +{
> +	struct igb_adapter *adapter = container_of(work, struct igb_adapter,
> +						   rtnl_resume_task);
> +
> +	rtnl_lock();
> +	if (!test_bit(__IGB_DOWN, &adapter->state) &&
> +	    netif_running(adapter->netdev)) {
> +		if (netif_set_real_num_queues(adapter->netdev,
> +					      adapter->num_tx_queues,
> +					      adapter->num_rx_queues))
> +			netdev_err(adapter->netdev,
> +				   "error setting real queue count\n");

[Severity: Low]
If netif_set_real_num_queues() fails here, does the stack stay out of step
with the hardware until the next ifdown/ifup or system resume?

On runtime resume, __igb_resume() calls __igb_open(netdev, true, false).
That skips the queue count update, but it still enables every ring,
programs RSS across adapter->num_rx_queues through
igb_configure()->igb_setup_mrqc(), and starts all stack TX queues.

Here is one way to reach it. An earlier runtime resume falls back from
MSI-X to MSI, so this work lowers real_num_{tx,rx}_queues to 1. A later
runtime resume gets MSI-X with N queues again, so the counts have to go
up. Raising them can fail with -ENOMEM while allocating the sysfs queue
kobjects or XPS maps.

When that happens, the NIC has N rings armed and RSS spreads RX over N
queues, but the stack only sees one TX queue and one RX queue. TX uses
only ring 0, RX skbs carry queue indices >= real_num_rx_queues, and
per-queue reporting is wrong.

Before this patch, a failure in __igb_open() unwound through
err_set_queues, so the stack and the hardware stayed consistent.

The same mismatch also exists, without any failure, between the resume
and the moment this work runs. The commit message only covers the
opposite direction, where the device has fewer queues than the stack. At
the end of the series this failure is still only logged.

Should this retry, or bring the hardware configuration back in line with
the stack?

> +	}
> +	rtnl_unlock();
> +}
> +

[ ... ]

> @@ -4178,16 +4203,15 @@ static int __igb_open(struct net_device *netdev, bool resuming)
>  	if (err)
>  		goto err_req_irq;
>  
> -	/* Notify the stack of the actual queue counts. */
> -	err = netif_set_real_num_tx_queues(adapter->netdev,
> -					   adapter->num_tx_queues);
> -	if (err)
> -		goto err_set_queues;
> -
> -	err = netif_set_real_num_rx_queues(adapter->netdev,
> -					   adapter->num_rx_queues);
> -	if (err)
> -		goto err_set_queues;
> +	/* Notify the stack of the actual queue counts. This needs RTNL: on
> +	 * runtime resume igb_rtnl_resume_task() does it.
> +	 */
> +	if (rtnl_held) {
> +		err = netif_set_real_num_queues(netdev, adapter->num_tx_queues,
> +						adapter->num_rx_queues);
> +		if (err)
> +			goto err_set_queues;
> +	}

[ ... ]

> @@ -9638,8 +9668,11 @@ static int __igb_resume(struct device *dev, bool rpm)
>  
>  	if (!rpm)
>  		rtnl_lock();
> -	if (!err && netif_running(netdev))
> -		err = __igb_open(netdev, true);
> +	if (!err && netif_running(netdev)) {
> +		err = __igb_open(netdev, true, !rpm);
> +		if (!err && rpm)
> +			schedule_work(&adapter->rtnl_resume_task);
> +	}

[Severity: High]
This is a pre-existing issue and was not introduced by this patch.
However, the runtime resume design here relies on it, and it can still
be reached at the end of the series. Can the runtime suspend path
deadlock against RTNL holders?

igb_runtime_suspend()->__igb_shutdown(pdev, NULL, 1) always takes RTNL:

drivers/net/ethernet/intel/igb/igb_main.c:__igb_shutdown() {
    ...
	rtnl_lock();
	netif_device_detach(netdev);
    ...
}

rpm_suspend() sets runtime_status to RPM_SUSPENDING before it calls the
callback. While the callback is blocked in rtnl_lock(), any RTNL holder
that does a synchronous runtime resume of the same PCI device waits in
rpm_resume() with no timeout:

drivers/base/power/runtime.c:rpm_resume() {
    ...
		for (;;) {
			prepare_to_wait(&dev->power.wait_queue, &wait,
					TASK_UNINTERRUPTIBLE);
			if (dev->power.runtime_status != RPM_RESUMING &&
			    dev->power.runtime_status != RPM_SUSPENDING)
				break;
    ...
}

Several RTNL holders do this. One is ethnl_ops_begin():

net/ethtool/netlink.c:ethnl_ops_begin() {
    ...
	if (dev->dev.parent)
		pm_runtime_get_sync(dev->dev.parent);

	netdev_assert_locked_ops_compat(dev);
    ...
}

Others are the ethtool ioctl path and
dev_close()->igb_close()->__igb_close(netdev, false), which calls
pm_runtime_get_sync(). igb_xdp() joins them once the later commit "igb:
resume the device before changing XDP or XSK settings" is applied.

The suspend waits for RTNL, and the RTNL holder waits for the suspend to
finish. Every other rtnl_lock() caller then hangs.

Ethtool netlink GET requests don't need CAP_NET_ADMIN. Once runtime PM is
enabled (power/control=auto) and the link is down, an unprivileged user
could hit this race.

This is the suspend-side counterpart of the resume deadlock fixed by
ac8c58f5b535. The commit message of "igb: resume the device before
changing XDP or XSK settings" says this deadlock remains, and no patch in
the series fixes it.

At the end of the series, __igb_shutdown() also calls
cancel_work_sync(&adapter->rtnl_resume_task) before rtnl_lock(). That
work takes RTNL, so does it become part of the same dependency cycle?

>  
>  	if (!err)
>  		netif_device_attach(netdev);

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net v5 3/6] igb: keep the stack's Rx queues that still have an XSK pool
  2026-11-24 23:57 ` [PATCH net v5 3/6] igb: keep the stack's Rx queues that still have an XSK pool Antonio Quartulli
  2026-11-28 13:37   ` Janis Edvarts Lacis
@ 2026-11-29  0:37   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-11-29  0:37 UTC (permalink / raw)
  To: antonio
  Cc: intel-wired-lan, anthony.l.nguyen, przemyslaw.kitszel,
	andrew+netdev, davem, edumazet, kuba, pabeni, janislacis06, kurt,
	joe, netdev, linux-kernel, stable

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] igb_set_real_num_queues()
  (drivers/net/ethernet/intel/igb/igb_main.c) keeps…

--

igb: keep the stack's Rx queues that still have an XSK pool

When igb lowers its own queue counts (an MSI fallback on resume, or a VF
enable), this patch keeps netdev->real_num_rx_queues up to the highest
queue that still has an XSK pool. That way the pool can still be found
and disabled. The count is lowered again at the next open.

Closes: https://lore.kernel.org/netdev/xupy6jbpnziq2qji54zjbvm7neggrwkxg3sfrhlolmrd6ysifl@zptk6ynkbu5f/

> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
> index 6b299a1429a8e..47a92447aab27 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -4125,6 +4125,26 @@ static int igb_sw_init(struct igb_adapter *adapter)
>  	return 0;
>  }
>  
> +/* ethtool refuses to remove a queue that still has an XSK pool. igb can't
> + * refuse when it lowers its queue counts by itself, so keep the stack's Rx
> + * queue instead, or the pool couldn't be disabled anymore: lower the count
> + * once it's gone, at the next open.
> + */
> +static int igb_set_real_num_queues(struct igb_adapter *adapter)
> +{
> +	struct net_device *netdev = adapter->netdev;
> +	unsigned int rxq = adapter->num_rx_queues;
> +	unsigned int i;
> +
> +	for (i = netdev->real_num_rx_queues; i > rxq; i--)
> +		if (xsk_get_pool_from_qid(netdev, i - 1)) {
> +			rxq = i;
> +			break;
> +		}

[Severity: Low]
Should this loop only keep queues whose pool is in zero-copy mode?

As written, any registered pool keeps the count up, including copy-mode
(XDP_COPY) pools. The comment above gives one reason for keeping the
queue: otherwise the pool couldn't be disabled. That reason only seems to
apply to zero-copy pools:

net/xdp/xsk_buff_pool.c:xp_disable_drv_zc() {
    ...
	if (pool->umem->zc) {
		bpf.command = XDP_SETUP_XSK_POOL;
    ...
}

A copy-mode pool on a removed queue is cleared by
__xsk_clear_pool_at_qid(). That function walks dev->_rx[] and dev->_tx[]
up to the allocated num_rx_queues and num_tx_queues, so the extra queues
were not needed for that case before this patch.

This case also looks easy to reach. igb only sets the real queue counts
through this helper, so before the first open real_num_rx_queues is still
16 from alloc_etherdev_mq(..., IGB_MAX_TX_QUEUES) in igb_probe(). While
the device is down, xsk_reg_pool_at_qid() accepts any qid below 16.

igb_xsk_pool_enable() rejects a zero-copy bind on such a queue:

	if (qid >= adapter->num_rx_queues)
		return -EINVAL;

If neither XDP_ZEROCOPY nor XDP_COPY is requested, xp_assign_dev() falls
back to copy mode and leaves the pool registered at that qid. An explicit
XDP_COPY bind skips the driver entirely.

On the next __igb_open(), or after a VF enable or MSI fallback with only a
copy-mode socket on a removed queue, this loop finds that pool and calls
netif_set_real_num_queues(netdev, num_tx_queues, qid + 1). The stack would
then report RX queues that have no hardware ring (rx-N sysfs entries and
netdev-genl queue dumps) until the socket is closed and the device is
reopened.

Would checking pool->umem->zc here limit the behavior to the case
described in the commit message and the comment?

> +
> +	return netif_set_real_num_queues(netdev, adapter->num_tx_queues, rxq);
> +}
> +

[ ... ]

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH net v5 5/6] igb: resume the device before changing XDP or XSK settings
  2026-11-24 23:57 ` [PATCH net v5 5/6] igb: resume the device before changing XDP or XSK settings Antonio Quartulli
  2026-11-28 13:38   ` Janis Edvarts Lacis
@ 2026-11-29  0:37   ` netdev-bot+sashiko
  1 sibling, 0 replies; 18+ messages in thread
From: netdev-bot+sashiko @ 2026-11-29  0:37 UTC (permalink / raw)
  To: antonio
  Cc: intel-wired-lan, anthony.l.nguyen, przemyslaw.kitszel,
	andrew+netdev, davem, edumazet, kuba, pabeni, janislacis06, kurt,
	joe, netdev, linux-kernel, stable

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

Critical: 0 · High: 1 · Medium: 1 · 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] In drivers/net/ethernet/intel/igb/igb_main.c, igb_xdp() calls
  pm_runtime_get_sync() at line 2950 and throws away the return value.
- [Medium] igb_xdp() in drivers/net/ethernet/intel/igb/igb_main.c now
  calls pm_runtime_get_sync() (line 2950) while its callers hold RTNL.

--

igb: resume the device before changing XDP or XSK settings

This commit wraps igb_xdp() in pm_runtime_get_sync()/pm_runtime_put(), so
XDP program and XSK pool changes run against a resumed device. The goal is
to stop igb_xdp_setup() and igb_xsk_pool_setup() from seeing rings that
don't exist yet, or NAPIs that aren't enabled yet, while __igb_resume()
rebuilds them without RTNL.

> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
> index 25941a6e25b9f..83c88169840ab 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -2942,16 +2942,28 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)
>  static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp)
>  {
>  	struct igb_adapter *adapter = netdev_priv(dev);
> +	int err;
> +
> +	/* The rings only exist while the device is resumed, and resuming
> +	 * rebuilds them without RTNL
> +	 */
> +	pm_runtime_get_sync(&adapter->pdev->dev);

[Severity: High]
What happens here if the runtime resume fails? The return value of
pm_runtime_get_sync() is thrown away. Nothing checks netif_device_present()
before igb_xdp_setup() or igb_xsk_pool_setup() runs.

Say __igb_open() fails during the resume, for example with -ENOMEM from
igb_setup_all_rx_resources() or a failure in igb_request_irq(). By then
__igb_resume() has already run igb_init_interrupt_scheme(), so the
q_vectors exist and num_rx_queues > 0. But every error label in
__igb_open() comes before this:

drivers/net/ethernet/intel/igb/igb_main.c:__igb_open() {
    ...
	clear_bit(__IGB_DOWN, &adapter->state);

	for (i = 0; i < adapter->num_q_vectors; i++) {
		napi = &adapter->q_vector[i]->napi;
		napi_enable(napi);
    ...
}

So the NAPIs still have SCHED/NPSVC set from netif_napi_add(), and the
descriptor memory has been freed. __igb_resume() also returns without
calling netif_device_attach().

Closing a zero-copy AF_XDP socket would then go through:

xp_release_deferred()
  rtnl_lock()
  xp_clear_dev()
    igb_xdp()
      pm_runtime_get_sync()          <- resume fails, ignored
      igb_xsk_pool_setup(pool == NULL)
        igb_xsk_pool_disable()
          igb_txrx_ring_disable()
            napi_disable()

The check in igb_xsk_pool_disable() still passes:

	if_running = netif_running(adapter->netdev) &&
		     igb_xdp_is_enabled(adapter) &&
		     qid < adapter->num_rx_queues;

Wouldn't napi_disable() spin forever with RTNL held, since that NAPI was
never enabled? Before that, igb_txrx_ring_disable() writes TXDCTL/RXDCTL
on a MAC that was reset and handed back to firmware. If napi_disable() did
return, igb_txrx_ring_enable() would refill rings whose descriptor memory
was freed.

For XDP_SETUP_PROG add/remove with the interface up, igb_close() does
nothing on the non-present device. igb_open() then runs a full open on the
device that failed to resume.

The commit message says the device is resumed "as ethtool does". However,
both __dev_ethtool() and ethnl_ops_begin() check the device after
resuming:

net/ethtool/netlink.c:ethnl_ops_begin() {
    ...
	if (dev->dev.parent)
		pm_runtime_get_sync(dev->dev.parent);

	if (!netif_device_present(dev) ||
	    dev->reg_state >= NETREG_UNREGISTERING) {
		ret = -ENODEV;
    ...
}

Should igb_xdp() check the same way? Returning an error on the pool
teardown path may not be enough on its own. xp_disable_drv_zc() WARNs in
that case, and the pool's DMA unmap would be skipped. The disable path may
still need to do its software cleanup when the hardware isn't resumed.

In this tree a failed resume doesn't set power.runtime_error, so each later
pm_runtime_get_sync() retries the resume callback. The direct trigger is a
failed resume inside igb_xdp()'s own pm_runtime_get_sync(). The last patch
in the series ("igb: only allow runtime PM if the device can wake up")
doesn't change igb_xdp().

[Severity: Medium]
Can this deadlock with a runtime suspend that is already in progress?
Every caller that reaches ndo_bpf here holds RTNL:

  dev_xdp_attach()
  xsk_bind() -> xp_assign_dev()
  xp_release_deferred() -> xp_clear_dev()

The igb runtime suspend callback takes RTNL after the PM core has set the
status to RPM_SUSPENDING:

igb_runtime_suspend()
  __igb_shutdown()
    cancel_work_sync(&adapter->rtnl_resume_task);
    rtnl_lock();

While the status is RPM_SUSPENDING, rpm_resume() for a synchronous caller
on a non-irq_safe device waits uninterruptibly on power.wait_queue. The
pm_wq worker waits for RTNL, and the igb_xdp() caller holds RTNL while it
waits for the suspend to finish. Lockdep won't report this.

The commit message mentions this ("closing an AF_XDP socket or changing
the XDP program is now one of them"). The same cycle already exists for
ethtool ops and for igb_open()/igb_close().

Before this patch, igb made no runtime PM calls on two paths:
AF_XDP zero-copy bind and teardown, and XDP program changes when the
interface is down or the program is only swapped. Both paths can now reach
this hang. The last patch in the series only limits when a suspend gets
scheduled. It doesn't remove the rtnl_lock() from the suspend callback.

Is there a way to avoid the synchronous resume under RTNL on these paths?

> 
>  	switch (xdp->command) {
>  	case XDP_SETUP_PROG:

[ ... ]

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2026-11-29  0:37 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 23:57 [PATCH net v5 0/6] igb: fix runtime PM resume issues Antonio Quartulli
2026-11-24 23:57 ` [PATCH net v5 1/6] igb: don't touch rings that don't exist when disabling an XSK pool Antonio Quartulli
2026-11-28 13:36   ` Janis Edvarts Lacis
2026-11-29  0:37   ` netdev-bot+sashiko
2026-11-24 23:57 ` [PATCH net v5 2/6] igb: fix RTNL assertion when resuming from runtime suspend Antonio Quartulli
2026-11-28 13:37   ` Janis Edvarts Lacis
2026-11-29  0:37   ` netdev-bot+sashiko
2026-11-24 23:57 ` [PATCH net v5 3/6] igb: keep the stack's Rx queues that still have an XSK pool Antonio Quartulli
2026-11-28 13:37   ` Janis Edvarts Lacis
2026-11-29  0:37   ` netdev-bot+sashiko
2026-11-24 23:57 ` [PATCH net v5 4/6] igb: link queues to NAPIs under RTNL after runtime resume Antonio Quartulli
2026-11-28 13:38   ` Janis Edvarts Lacis
2026-11-24 23:57 ` [PATCH net v5 5/6] igb: resume the device before changing XDP or XSK settings Antonio Quartulli
2026-11-28 13:38   ` Janis Edvarts Lacis
2026-11-29  0:37   ` netdev-bot+sashiko
2026-11-24 23:57 ` [PATCH net v5 6/6] igb: only allow runtime PM if the device can wake up Antonio Quartulli
2026-11-28 13:40   ` Janis Edvarts Lacis
2026-11-28 13:32 ` [PATCH net v5 0/6] igb: fix runtime PM resume issues Janis Edvarts Lacis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox