igb: fix runtime PM resume issues
Subsystems (5)
v3 cover igb: fix runtime PM resume issues
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 3), and devices that can't signal a wake-up are suspended anyway, so their port stays down when the link comes back (patch 4). Patch 1 fixes a NULL dereference in the XSK pool disable path when the stack has more queues than the device, which can happen after a fallback from MSI-X to MSI on resume.
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. 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, and SR-IOV.
igc has the same issues (see the notes); Joe Damato offered to test on igc, so its fix will be sent separately.
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: 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
v2: https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/
Antonio Quartulli (4):
igb: don't disable rings that don't exist when disabling an XSK pool
igb: fix RTNL assertion when resuming from runtime suspend
igb: link queues to NAPIs under RTNL after runtime resume
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 | 96 +++++++++++++++++------ drivers/net/ethernet/intel/igb/igb_xsk.c | 7 +- 3 files changed, 80 insertions(+), 24 deletions(-)
Signature · 1 line
2.56.1
PATCH v3 1/4 igb: don't disable rings that don't exist when disabling an XSK pool
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, e.g. after igb falls back from MSI-X to MSI on resume. Disabling the pool of such a queue then passes a NULL ring to igb_txrx_ring_disable().
Only disable and re-enable the rings the device has, as igb_xsk_pool_enable() and igb_xsk_wakeup() already check.
Compile-tested only: the XSK pool path isn't reachable with the QEMU 82576 setup used for the rest of the series.
---
v3: new patch.
drivers/net/ethernet/intel/igb/igb_xsk.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/igb/igb_xsk.c +6 -1
@@ -148,7 +148,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);
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH net v3 1/4] igb: don't disable rings that don't exist when disabling an XSK pool
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] igb: missing num_tx_queues check in igb_xsk_pool_disable() dereferences NULL --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] igb: missing num_tx_queues check in igb_xsk_pool_disable() dereferences NULL
--
commit e4f6db572e101ec4f5da6fee01a7451218673315
Author: Antonio Quartulli <[email protected]>
igb: don't disable rings that don't exist when disabling an XSK pool
This commit checks qid against adapter->num_rx_queues in igb_xsk_pool_disable() so rings that do not exist are not disabled or re-enabled.
Quoted 7 lines
drivers/net/ethernet/intel/igb/igb_xsk.c +0
-0@@ -148,7 +148,12 @@ static int igb_xsk_pool_disable(struct igb_adapter *adapter, u16 qid)return -EINVAL ;
drivers/net/ethernet/intel/igb/igb_xsk.c static int igb_xsk_pool_disable(struct igb_adapter *adapter, u16 qid) · line 158
Quoted 10 lines
drivers/net/ethernet/intel/igb/igb_xsk.c +6
-1rx_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);
[Severity: Medium]
Can igb_txrx_ring_disable() still dereference a NULL adapter->tx_ring[qid] when qid >= adapter->num_tx_queues?
In igb_set_interrupt_capability(), allocating SR-IOV VFs forces adapter->num_tx_queues to 1 while leaving adapter->num_rx_queues at adapter->rss_queues (up to 2 on 82576):
drivers/net/ethernet/intel/igb/igb_main.c:igb_set_interrupt_capability() {
...
adapter->num_rx_queues = adapter->rss_queues;
if (adapter->vfs_allocated_count)
adapter->num_tx_queues = 1;
else
adapter->num_tx_queues = adapter->rss_queues;
...
}Because igb_xsk_pool_enable() also only checks qid >= adapter->num_rx_queues, disabling a pool bound to qid 1 when SR-IOV is active passes qid < adapter->num_rx_queues and reaches igb_txrx_ring_disable(), which immediately dereferences adapter->tx_ring[1] (NULL).
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH net v3 1/4] igb: don't disable rings that don't exist when disabling an XSK pool
In reply to Antonio QuartulliApparently Sashiko has hit a little, but valid, interesting hitch on this patch.
Will need a respin.
Regards,
pw-bot: cr
Quoted 40 lines · Antonio Quartulli
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, e.g. after igb falls back from MSI-X to MSI on resume. Disabling the pool of such a queue then passes a NULL ring toigb_txrx_ring_disable().Only disable and re-enable the rings the device has, as
igb_xsk_pool_enable()andigb_xsk_wakeup()already check.Compile-tested only: the XSK pool path isn't reachable with the QEMU 82576 setup used for the rest of the series.
Fixes 80f6ccf9f116 ("igb: Introduce XSK data structures and helpers")Cc [email protected] # 6.14+Signed-off-by Antonio Quartulli <[email protected]>---
v3: new patch.drivers/net/ethernet/intel/igb/igb_xsk.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/net/ethernet/intel/igb/igb_xsk.c +6
-1@@ -148,7 +148,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);
Signature · 5 lines
Antonio Quartulli CEO and Co-Founder Mandelbit Srl https://www.mandelbit.com
PATCH v3 2/4 igb: fix RTNL assertion when resuming from runtime suspend
In reply to Antonio QuartulliSince 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.
---
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(-)
drivers/net/ethernet/intel/igb/igb.h +1 -0
@@ -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;
drivers/net/ethernet/intel/igb/igb_main.c +53 -20
137 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH v3 3/4 igb: link queues to NAPIs under RTNL after runtime resume
In reply to Antonio Quartulli__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. These are only freed while __IGB_DOWN is set, which is cleared once they are allocated again, so the work item checks __IGB_DOWN under RTNL.
Tested with the 82576 emulated by QEMU.
---
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 | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +14 -2
@@ -4126,8 +4126,18 @@ static int igb_sw_init(struct igb_adapter *adapter)return 0 ; } +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. The +* q_vectors are only freed while __IGB_DOWN is set, which is cleared once +* they are allocated again, so checking it under RTNL is safe. */ static void igb_rtnl_resume_task (struct work_struct *work) {
@@ -4142,6 +4152,7 @@ static void igb_rtnl_resume_task(struct work_struct *work) adapter->num_rx_queues))netdev_err (adapter->netdev,"error setting real queue count\n" ); +igb_link_queue_napis (adapter); }rtnl_unlock (); }
@@ -4220,7 +4231,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. */
Signature · 1 line
2.56.1
PATCH v3 4/4 igb: only allow runtime PM if the device can wake up
In reply to Antonio Quartulliigb 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.
Allow runtime PM only if pci_dev_run_wake() is true, as e1000e and r8169 do. Devices that can't wake up no longer runtime suspend, even with power/control set to auto.
Tested with the 82576 emulated by QEMU.
---
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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +7 -2
@@ -3654,7 +3654,11 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)dev_pm_set_driver_flags (&pdev->dev,DPM_FLAG_NO_DIRECT_COMPLETE ); -pm_runtime_put_noidle (&pdev->dev); +/* A device that can't wake up wouldn't notice the link coming back +* while runtime suspended +*/ +if (pci_dev_run_wake (pdev)) +pm_runtime_put_noidle (&pdev->dev);return 0 ; err_register:
@@ -3876,7 +3880,8 @@ static void igb_remove(struct pci_dev *pdev)struct igb_adapter *adapter =netdev_priv (netdev);struct e1000_hw *hw = &adapter->hw; -pm_runtime_get_noresume (&pdev->dev); +if (pci_dev_run_wake (pdev)) +pm_runtime_get_noresume (&pdev->dev);#ifdef CONFIG_IGB_HWMON igb_sysfs_exit (adapter);#endif
Signature · 1 line
2.56.1