Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI/ASPM: Fix link_state teardown on device removal

Upon removal of the last device on a bus, the link_state of the bridge
leading to that bus is sought to be torn down by having pci_stop_dev()
call pcie_aspm_exit_link_state().

When ASPM was originally introduced by commit 7d715a6c1ae5 ("PCI: add
PCI Express ASPM support"), it determined whether the device being
removed is the last one by calling list_empty() on the bridge's
subordinate devices list. That didn't work because the device is only
removed from the list slightly later in pci_destroy_dev().

Commit 3419c75e15f8 ("PCI: properly clean up ASPM link state on device
remove") attempted to fix it by calling list_is_last(), but that's not
correct either because it checks whether the device is at the *end* of
the list, not whether it's the last one *left* in the list. If the user
removes the device which happens to be at the end of the list via sysfs
but other devices are preceding the device in the list, the link_state
is torn down prematurely.

The real fix is to move the invocation of pcie_aspm_exit_link_state() to
pci_destroy_dev() and reinstate the call to list_empty(). Remove a
duplicate check for dev->bus->self because pcie_aspm_exit_link_state()
already contains an identical check.

Fixes: 7d715a6c1ae5 ("PCI: add PCI Express ASPM support")
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Shaohua Li <shaohua.li@intel.com>
Cc: stable@vger.kernel.org # v2.6.26

authored by

Lukas Wunner and committed by
Bjorn Helgaas
aeae4f3e 7876320f

+2 -4
+1 -1
drivers/pci/pcie/aspm.c
··· 991 991 * All PCIe functions are in one slot, remove one function will remove 992 992 * the whole slot, so just wait until we are the last function left. 993 993 */ 994 - if (!list_is_last(&pdev->bus_list, &parent->subordinate->devices)) 994 + if (!list_empty(&parent->subordinate->devices)) 995 995 goto out; 996 996 997 997 link = parent->link_state;
+1 -3
drivers/pci/remove.c
··· 25 25 26 26 pci_dev_assign_added(dev, false); 27 27 } 28 - 29 - if (dev->bus->self) 30 - pcie_aspm_exit_link_state(dev); 31 28 } 32 29 33 30 static void pci_destroy_dev(struct pci_dev *dev) ··· 38 41 list_del(&dev->bus_list); 39 42 up_write(&pci_bus_sem); 40 43 44 + pcie_aspm_exit_link_state(dev); 41 45 pci_bridge_d3_update(dev); 42 46 pci_free_resources(dev); 43 47 put_device(&dev->dev);