linux/drivers/pci/pcie
Huang Ying 90b5c1d7c4 PCI/PM: Fix deadlock when unbinding device if parent in D3cold
If a PCI device and its parents are put into D3cold, unbinding the
device will trigger deadlock as follow:

- driver_unbind
  - device_release_driver
    - device_lock(dev)				<--- previous lock here
    - __device_release_driver
      - pm_runtime_get_sync
        ...
          - rpm_resume(dev)
            - rpm_resume(dev->parent)
              ...
                - pci_pm_runtime_resume
                  ...
                  - pci_set_power_state
                    - __pci_start_power_transition
                      - pci_wakeup_bus(dev->parent->subordinate)
                        - pci_walk_bus
                          - device_lock(dev)	<--- deadlock here


If we do not do device_lock in pci_walk_bus, we can avoid deadlock.
Device_lock in pci_walk_bus is introduced in commit:
d71374dafb, corresponding email thread
is: https://lkml.org/lkml/2006/5/26/38.  The patch author Zhang Yanmin
said device_lock is added to pci_walk_bus because:

  Some error handling functions call pci_walk_bus. For example, PCIe
  aer. Here we lock the device, so the driver wouldn't detach from the
  device, as the cb might call driver's callback function.

So I fixed the deadlock as follows:

- remove device_lock from pci_walk_bus
- add device_lock into callback if callback will call driver's callback

I checked pci_walk_bus users one by one, and found only PCIe aer needs
device lock.

Signed-off-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
CC: stable@vger.kernel.org		# v3.6+
CC: Zhang Yanmin <yanmin.zhang@intel.com>
2012-11-02 10:07:17 -06:00
..
aer PCI/PM: Fix deadlock when unbinding device if parent in D3cold 2012-11-02 10:07:17 -06:00
aspm.c PCI/ASPM: Use PCI Express Capability accessors 2012-08-23 10:11:12 -06:00
Kconfig PCI: pcie: Add support for setting default ASPM policy 2012-02-17 09:22:03 -08:00
Makefile PCI: PCIe: Move PCIe PME code to the pcie directory 2010-08-24 13:47:48 -07:00
pme.c PCI/PME: Use PCI Express Capability accessors 2012-08-23 10:11:11 -06:00
portdrv_acpi.c PCI/ACPI: Request _OSC control once for each root bridge (v3) 2011-01-14 08:55:41 -08:00
portdrv_bus.c PCI: Introduce pci_pcie_type(dev) to replace pci_dev->pcie_type 2012-08-23 09:40:57 -06:00
portdrv_core.c Merge branch 'pci/shengzhou-irq' into next 2012-09-10 16:35:40 -06:00
portdrv_pci.c Merge commit 'v3.6-rc5' into next 2012-09-13 08:41:01 -06:00
portdrv.h PCI: Add pcie_hp=nomsi to disable MSI/MSI-X for pciehp driver 2012-02-23 12:29:35 -08:00