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
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ 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] 7+ 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-24 23:57 ` [PATCH net v5 2/6] igb: fix RTNL assertion when resuming from runtime suspend Antonio Quartulli
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ 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] 7+ 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-24 23:57 ` [PATCH net v5 3/6] igb: keep the stack's Rx queues that still have an XSK pool Antonio Quartulli
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ 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] 7+ 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-24 23:57 ` [PATCH net v5 4/6] igb: link queues to NAPIs under RTNL after runtime resume Antonio Quartulli
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ 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] 7+ 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-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 ` [PATCH net v5 6/6] igb: only allow runtime PM if the device can wake up Antonio Quartulli
  5 siblings, 0 replies; 7+ 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] 7+ 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-24 23:57 ` [PATCH net v5 6/6] igb: only allow runtime PM if the device can wake up Antonio Quartulli
  5 siblings, 0 replies; 7+ 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] 7+ 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
  5 siblings, 0 replies; 7+ 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] 7+ messages in thread

end of thread, other threads:[~2026-11-24 23:57 UTC | newest]

Thread overview: 7+ 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-24 23:57 ` [PATCH net v5 2/6] igb: fix RTNL assertion when resuming from runtime suspend Antonio Quartulli
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 ` [PATCH net v5 4/6] igb: link queues to NAPIs under RTNL after runtime resume Antonio Quartulli
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 ` [PATCH net v5 6/6] igb: only allow runtime PM if the device can wake up Antonio Quartulli

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