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
[email protected]
AI reviewRe: [PATCH net v3 1/4] igb: don't disable rings that don't exist when disabling an XSK pool
In reply to Antonio QuartulliThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 2 (2) · Medium: 0 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] The fix only covers the RX side.
- [High] The new guard qid < adapter->num_rx_queues in igb_xsk_pool_disable() is not serialized against the code that writes…
- [Low] Commit message accuracy (discarded by baseline).
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but if_running in igb_xsk_pool_disable() (and in igb_xsk_pool_enable()) uses…
- [High] This problem wasn't introduced by this patch, but the error paths of igb_xsk_pool_disable() (igb_xsk.c:162-165) and…
--
igb: don't disable rings that don't exist when disabling an XSK pool
The patch adds a qid < adapter->num_rx_queues bound to the if_running condition in igb_xsk_pool_disable(). With it, the function stops disabling and re-enabling rings the device doesn't have. The goal is to stop a NULL ring from reaching igb_txrx_ring_disable() when the stack knows about more queues than the device has.
Quoted 3 lines
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.
[Severity: Low]
This is minor. At this commit, a successful resume goes through __igb_open(netdev, true), which re-syncs the real queue counts:
err = netif_set_real_num_tx_queues(adapter->netdev,
adapter->num_tx_queues);The MSI-X to MSI example only leaves stale counts after the later patch "igb: fix RTNL assertion when resuming from runtime suspend". That patch makes __igb_resume() call __igb_open(netdev, true, !rpm), which skips the re-sync on runtime resume until igb_rtnl_resume_task() runs.
The guard also covers the runtime-suspended-while-up state. There, igb_free_q_vectors() has set num_rx_queues = 0 while netif_running() is still true.
Could the commit message and the new code comment mention that dependency, or use the runtime-suspended case as the example?
Quoted 5 lines
drivers/net/ethernet/intel/igb/igb_xsk.c +0
-0
drivers/net/ethernet/intel/igb/igb_xsk.c static int igb_xsk_pool_disable(struct igb_adapter *adapter, u16 qid) · line 156
Quoted 10 lines
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;
[Severity: High]
Is checking only num_rx_queues enough here? igb_txrx_ring_disable() and igb_txrx_ring_enable() also use the TX ring:
struct igb_ring *tx_ring = adapter->tx_ring[qid];
...
set_bit(IGB_RING_FLAG_TX_DISABLED, &tx_ring->flags);igb can run with fewer TX rings than RX rings. From 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;igb_get_max_rss_queues() allows 2 RSS queues on an 82576 with VFs.
Here is a possible sequence:
1. With SR-IOV off (e.g. 4 queues), bind a zero-copy AF_XDP socket to qid 1. igb_xsk_pool_enable() accepts it.
2. Write to sriov_numvfs:
igb_pci_sriov_configure()->igb_enable_sriov()->igb_sriov_reinit(). igb_clear_interrupt_scheme() sets tx_ring[1] to NULL, and igb_init_interrupt_scheme() allocates rx_ring[0..1] but only tx_ring[0]. The pool registered at qid 1 stays in place.
3. Close the socket:
xp_release_deferred()->xp_disable_drv_zc()->ndo_bpf()-> igb_xsk_pool_disable(adapter, 1). xsk_get_pool_from_qid() returns the pool because
1 < real_num_rx_queues. The new guard passes because
1 < num_rx_queues. igb_txrx_ring_disable() then calls set_bit() on NULL->flags with rtnl held.
The commit message says this matches "as igb_xsk_pool_enable() and igb_xsk_wakeup() already check". However, igb_xsk_wakeup() bounds qid by the TX count:
if (qid >= adapter->num_tx_queues)
return -EINVAL;igb_xsk_pool_enable() also checks real_num_tx_queues. Should this guard require qid < adapter->num_tx_queues as well, or NULL-check both ring pointers? No later patch in the series touches igb_xsk_pool_disable().
[Severity: High]
Is this check serialized against the resume path that writes num_rx_queues and the ring arrays?
igb_xsk_pool_disable() holds only rtnl. __igb_resume() calls igb_init_interrupt_scheme() without rtnl on runtime resume, and before rtnl_lock() on system resume. Inside it, igb_set_interrupt_capability() publishes num_rx_queues = rss_queues before igb_alloc_q_vector() fills tx_ring[] and rx_ring[].
When the device is runtime-suspended with the interface up, igb_free_q_vectors() has set num_rx_queues = 0 and the rings are NULL, but netif_running() is still true. Runtime resume can start asynchronously, for example from a PME on link-up:
CPU0 (XSK release, rtnl held)igb_xsk_pool_disable()
rx_ring = adapter->rx_ring[qid]; /* NULL */
CPU1 (runtime resume)igb_init_interrupt_scheme()
igb_set_interrupt_capability()
adapter->num_rx_queues = adapter->rss_queues;CPU0
qid < adapter->num_rx_queues /* now true */
igb_txrx_ring_disable()
tx_ring = adapter->tx_ring[qid];
set_bit(IGB_RING_FLAG_TX_DISABLED, &tx_ring->flags);If the rings are still NULL, this oopses. If they were just allocated, napi_disable() races with napi_enable() and ring setup on CPU1. igb_realloc_rx_buffer_info() is also called later with the stale local rx_ring, which is NULL.
Can the NULL ring this patch is meant to prevent still reach igb_txrx_ring_disable() through this window? The missing serialization in __igb_resume() predates this patch, and later patches in the series keep it.
drivers/net/ethernet/intel/igb/igb_xsk.c static int igb_xsk_pool_disable(struct igb_adapter *adapter, u16 qid) · line 158
Quoted 2 lines
drivers/net/ethernet/intel/igb/igb_xsk.c +0
-0if (if_running)igb_txrx_ring_disable (adapter, qid);
[Severity: High]
This isn't a bug introduced by this patch, but netif_running() plus a queue count bound doesn't show that the NAPI is enabled. Can igb_txrx_ring_disable() end up calling napi_disable() on a NAPI that was never enabled, or is already disabled?
netif_napi_add() sets NAPI_STATE_SCHED and NAPI_STATE_NPSVC. napi_disable_locked() then waits on them with no timeout:
while (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) {
usleep_range(20, 200);There are two ways to reach that state:
- In __igb_resume(), igb_init_interrupt_scheme() succeeds but __igb_open(netdev, true) fails before napi_enable(), for example in igb_setup_all_tx_resources(). __LINK_STATE_START and xdp_prog stay set.
- igb_xdp_setup() and igb_sriov_reinit() ignore an igb_open() failure after igb_close(), and igb_down() has already called napi_disable().
Closing an AF_XDP socket on such a qid then runs xp_release_deferred()->igb_xsk_pool_disable()->igb_txrx_ring_disable()-> napi_disable(), which loops forever with rtnl held. igb_xsk_pool_enable() uses the same condition.
Would checking __IGB_DOWN, as igb_xsk_wakeup() does, be a more reliable indicator here?
[Severity: High]
This is a pre-existing issue, but what happens when igb_realloc_rx_buffer_info() fails further down in igb_xsk_pool_disable()?
if (if_running) {
err = igb_realloc_rx_buffer_info(rx_ring, false);
if (err)
return err;
igb_txrx_ring_enable(adapter, qid);
}By this point igb_txrx_ring_disable() has set IGB_RING_FLAG_TX_DISABLED, zeroed TXDCTL/RXDCTL and called napi_disable(). The error return skips igb_txrx_ring_enable(), and rx_ring->xsk_pool and tx_ring->xsk_pool still point to the pool.
xp_disable_drv_zc() only warns:
if (err)
WARN(1, "Failed to disable zero-copy!\n");The core then clears and frees the pool, so the ring is left with a dangling xsk_pool pointer.
Any later igb_down(), from igb_close(), reset_task or igb_xdp_setup(), calls napi_disable() on the already-disabled NAPI and blocks forever with rtnl held. Binding a new XSK socket to that qid hangs the same way through igb_txrx_ring_disable().
igb_xsk_pool_enable() has the same imbalance after igb_realloc_rx_buffer_info(rx_ring, true) fails:
if (err) {
xsk_pool_dma_unmap(pool, IGB_RX_DMA_ATTR);
return err;
}Quoted 1 line
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119140412.163202-1-antonio%40mandelbit.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
[email protected]
AI reviewRe: [PATCH net v3 3/4] igb: link queues to NAPIs under RTNL after runtime resume
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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).
- [Medium] The patch's safety argument has a memory-ordering gap.
- [Low] In __igb_open(), the comment '/* From here on the code is the same as igb_up() */' sits right above the NAPI enable/link loop.
--
igb: link queues to NAPIs under RTNL after runtime resume
This patch makes __igb_open() skip igb_set_queue_napi() when RTNL is not held, which is the case on runtime resume. On that path, igb_rtnl_resume_task() now links the queues to their NAPIs. It checks __IGB_DOWN under RTNL before walking adapter->q_vector[].
Quoted 25 lines
drivers/net/ethernet/intel/igb/igb_main.c +11
-1@@ -4125,8 +4125,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) {
drivers/net/ethernet/intel/igb/igb_main.c static void igb_rtnl_resume_task(struct work_struct *work) · line 4157
Quoted 7 lines
drivers/net/ethernet/intel/igb/igb_main.c +1
-0@@ -4141,6 +4151,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 (); }
[Severity: Medium]
Is checking __IGB_DOWN under RTNL enough to make the q_vector[] walk in igb_link_queue_napis() safe?
RTNL covers the free side, because __igb_shutdown() calls igb_clear_interrupt_scheme() under rtnl_lock(). On runtime resume, though, the allocation side runs without RTNL:
__igb_resume(rpm = true)
igb_init_interrupt_scheme(adapter, true);
/* sets num_q_vectors and q_vector[i] */
__igb_open(netdev, true, false)
clear_bit(__IGB_DOWN, &adapter->state);
schedule_work(&adapter->rtnl_resume_task);clear_bit() has no release semantics. igb_rtnl_resume_task() reads the flag with a plain test_bit(). It then loads num_q_vectors and q_vector[i] with no acquire or smp_rmb() in between.
schedule_work() orders a work instance queued by this resume. Does anything order an older instance that has already started running (PENDING cleared) but is still blocked in rtnl_lock()? For example:
1. Runtime resume #1 queues rtnl_resume_task. The worker starts and blocks in rtnl_lock() behind another RTNL holder.
2. Runtime suspend runs __igb_shutdown(). Under RTNL, __igb_close()->igb_down() sets __IGB_DOWN, and igb_clear_interrupt_scheme() frees the q_vectors. Nothing cancels or flushes rtnl_resume_task.
3. Runtime resume #2 (for example a link-up PME) reallocates the q_vectors and clears __IGB_DOWN without RTNL.
4. The stale worker gets RTNL. Its rtnl_lock() pairs with an unrelated holder's rtnl_unlock(), not with the stores from resume #2.
Could the worker then see __IGB_DOWN clear while still reading a stale num_q_vectors? It could also read a q_vector[i] that is NULL, or one freed in the earlier cycle. igb_set_queue_napi() would then dereference q_vector->rx.ring.
This needs an RTNL stall that lasts through a whole suspend/resume cycle, plus a weakly ordered CPU. One fix is to pair clear_bit_unlock() (or smp_mb__before_atomic() before clear_bit()) in __igb_open() with test_bit_acquire() here. Another is to cancel or flush the work outside RTNL before the q_vectors are freed. Either would make the new comment's claim hold.
drivers/net/ethernet/intel/igb/igb_main.c static int __igb_open(struct net_device *netdev, bool resuming, · line 4235
Quoted 8 lines
drivers/net/ethernet/intel/igb/igb_main.c +2
-1@@ -4219,7 +4230,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); }
[Severity: Low]
This isn't a bug, but __igb_open() still has this comment just above the loop:
/* From here on the code is the same as igb_up() */ clear_bit(__IGB_DOWN, &adapter->state);
igb_up() still calls igb_set_queue_napi() every time. This loop now skips it when RTNL isn't held.
Should the comment mention this difference and the RTNL dependency? A later change that resyncs the two paths based on this comment could bring back the RTNL-less netif_queue_set_napi() call.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119140412.163202-1-antonio%40mandelbit.com
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
[email protected]
AI reviewRe: [PATCH net v3 4/4] igb: only allow runtime PM if the device can wake up
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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).
- [Medium] The fix checks wake capability only once, in igb_probe().
- [Low] Possible runtime PM usage-count imbalance in drivers/net/ethernet/intel/igb/igb_main.c.
--
igb: only allow runtime PM if the device can wake up
This patch changes igb_probe() so it drops the probe-time runtime PM usage reference only when pci_dev_run_wake() reports that the device can signal a wake-up. igb_remove() takes the reference back under the same condition. The aim is to stop the NIC from runtime suspending into a state where it cannot notice the link coming back.
Quoted 5 lines
drivers/net/ethernet/intel/igb/igb_main.c +0
-0
drivers/net/ethernet/intel/igb/igb_main.c static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 3661
Quoted 9 lines
drivers/net/ethernet/intel/igb/igb_main.c +5
-1@@ -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);
[Severity: Medium]
Is a check done only at probe time enough to keep the device out of a D-state it can't wake from?
The PCI core recomputes both the target state and the wake enable on every runtime suspend, after igb_runtime_suspend() has run:
pci_pm_runtime_suspend()
pci_finish_runtime_suspend()
drivers/pci/pci.c:pci_finish_runtime_suspend() {
...
target_state = pci_target_state(dev, device_can_wakeup(&dev->dev));
if (target_state == PCI_POWER_ERROR)
return -EIO;
__pci_enable_wake(dev, target_state, pci_dev_run_wake(dev));
error = pci_set_power_state(dev, target_state);
...
}If igb probes while d3cold_allowed is 0 or no_d3cold is set, acpi_pci_choose_state() caps the target at D3hot:
if (pdev->no_d3cold || !pdev->d3cold_allowed) d_max = ACPI_STATE_D3_HOT;
If the NIC has PME from D3hot, pci_dev_run_wake() is true there, so the usage reference gets dropped.
Later, root can set d3cold_allowed back to 1 through sysfs, or pci_d3cold_enable() can clear no_d3cold. The target can then become D3cold. On a NIC whose PME_Support has no D3cold bit, pci_dev_run_wake() is now false, and the core would put the device into D3cold with wake disabled.
Even then, igb_runtime_idle() still schedules a suspend whenever there is no link:
if (!igb_has_link(adapter)) pm_schedule_suspend(dev, MSEC_PER_SEC * 5);
Could this bring back the behaviour the commit message describes, where the port stays down until it is resumed from user space? Would it make sense to also refuse runtime suspend in igb_runtime_idle() or igb_runtime_suspend() (for example by returning -EBUSY) when pci_dev_run_wake() is false at that point?
I have only checked the code path here. I have not confirmed that real 82576/i350 parts on D3cold-capable platforms lack PME from D3cold.
drivers/net/ethernet/intel/igb/igb_main.c static void igb_remove(struct pci_dev *pdev) · line 3884
Quoted 10 lines
drivers/net/ethernet/intel/igb/igb_main.c +2
-1return 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);
[Severity: Low]
Can this pci_dev_run_wake() call give a different answer than the one in igb_probe()?
igb_probe() doesn't save its result. pci_dev_run_wake() recomputes it on every call from pci_pme_capable(dev, pci_target_state(dev, true)).
Several inputs to the target state can change at runtime:
- d3cold_allowed, which root can write through d3cold_allowed_store()
- no_d3cold
- PM_QOS_FLAG_NO_POWER_OFF in acpi_pm_device_sleep_state()
- acpi_target_system_state()
On a NIC with PME from D3hot but not from D3cold, changing d3cold_allowed between probe and unbind is enough to flip the answer.
pci_device_remove() relies on ->remove() undoing exactly what probe did:
drivers/pci/pci-driver.c:pci_device_remove() {
...
pm_runtime_get_sync(dev);
pm_runtime_barrier(dev);
drv->remove(pci_dev);
pm_runtime_put_noidle(dev);
...
pm_runtime_put_sync(dev);
}If probe saw false and remove sees true, one usage reference leaks. The device can then never runtime suspend again, even after rebinding with power/control set to auto.
If probe saw true and remove sees false, the final pm_runtime_put_sync() drops one reference too many. With power/control set to auto, the usage count underflows and the kernel warns. With power/control set to on, the forbid reference is used up and the user's setting is lost.
Before this patch, the put_noidle/get_noresume pair was unconditional and couldn't mismatch. e1000e and r8169 re-evaluate pci_dev_run_wake() in the same way.
Would it be safer to record the decision made in igb_probe(), for example as a flag in struct igb_adapter, and test that flag in igb_remove()?
Quoted 3 lines
drivers/net/ethernet/intel/igb/igb_main.c +0
-0#ifdef CONFIG_IGB_HWMON igb_sysfs_exit (adapter);#endif
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119140412.163202-1-antonio%40mandelbit.com