Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · 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). - [Medium] The runtime PM usage count can end up unbalanced, because the same decision is made twice. -- igb: only allow runtime PM if the device can wake up With this patch, igb_probe() drops the runtime PM reference taken by local_pci_probe() only when pci_dev_run_wake() is true. Devices that can't signal a wake-up from D3 are therefore never runtime suspended. igb_remove() takes the reference back under the same condition. 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 4617aba5759d2..36bd395e36dab 100644 > --- a/drivers/net/ethernet/intel/igb/igb_main.c > +++ b/drivers/net/ethernet/intel/igb/igb_main.c > @@ -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); [Severity: Medium] Can the runtime PM usage count get out of balance here? pci_dev_run_wake() runs once in igb_probe() and again in igb_remove(), and the first result isn't stored. pci_device_remove() then always ends with a put: drivers/pci/pci-driver.c:pci_device_remove() { ... /* Undo the runtime PM settings in local_pci_probe() */ pm_runtime_put_sync(dev); ... } The count only balances if both pci_dev_run_wake() calls return the same value. It looks like the result can change while the driver is bound. pci_dev_run_wake() checks pci_pme_capable(dev, pci_target_state(dev, true)). On ACPI-managed devices, acpi_pci_choose_state() caps the target state using a flag that root can change through sysfs: drivers/pci/pci-acpi.c:acpi_pci_choose_state() { ... if (pdev->no_d3cold || !pdev->d3cold_allowed) d_max = ACPI_STATE_D3_HOT; else d_max = ACPI_STATE_D3_COLD; ... } d3cold_allowed_store() writes pdev->d3cold_allowed, and nothing serializes that write against probe or remove. On a device that can raise PME from D3hot but not from D3cold, toggling the attribute flips the result of pci_dev_run_wake(). A second case is a device not managed by the platform, for example an igb NIC behind a Thunderbolt or USB4 dock. If it is surprise-removed while runtime suspended, the result also seems to change. pm_runtime_get_sync() in pci_device_remove() resumes the device, and pci_power_up() does: drivers/pci/pci.c:pci_power_up() { ... if (pci_dev_is_disconnected(dev)) { dev->current_state = PCI_D3cold; return -EIO; } ... } After that, pci_target_state() returns D3cold: drivers/pci/pci.c:pci_target_state() { ... if (dev->current_state == PCI_D3cold) return PCI_D3cold; ... } So igb_remove() tests the PME-from-D3cold bit, while igb_probe() tested the D3hot bit. If the call returns false at probe and true at remove, igb_remove() does an extra pm_runtime_get_noresume(). One usage count then leaks on each bind/unbind cycle. The device can't runtime suspend again, even after the driver is rebound. If it returns true at probe and false at remove, the final pm_runtime_put_sync() in pci_device_remove() underflows and logs "Runtime PM usage count underflow!". With power/control set to on, the extra put uses up the pm_runtime_forbid() reference instead, and a later pm_runtime_allow() underflows. Would it be safer to call pci_dev_run_wake() once in igb_probe(), store the result (for example as a bool in struct igb_adapter), and test that stored value in igb_remove()? e1000e and r8169 call pci_dev_run_wake() again at remove in the same way, so this pattern already exists in the tree. In igb, though, this would be a new imbalance, added by a fix that is tagged for stable. > #ifdef CONFIG_IGB_HWMON > igb_sysfs_exit(adapter); > #endif -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120210134.133238-1-antonio%40mandelbit.com
