linux-stable/drivers/pci
Yicong Yang c3c6dc1853 PCI: Avoid pci_dev_lock() AB/BA deadlock with sriov_numvfs_store()
[ Upstream commit a91ee0e9fc ]

The sysfs sriov_numvfs_store() path acquires the device lock before the
config space access lock:

  sriov_numvfs_store
    device_lock                 # A (1) acquire device lock
    sriov_configure
      vfio_pci_sriov_configure  # (for example)
        vfio_pci_core_sriov_configure
          pci_disable_sriov
            sriov_disable
              pci_cfg_access_lock
                pci_wait_cfg    # B (4) wait for dev->block_cfg_access == 0

Previously, pci_dev_lock() acquired the config space access lock before the
device lock:

  pci_dev_lock
    pci_cfg_access_lock
      dev->block_cfg_access = 1 # B (2) set dev->block_cfg_access = 1
    device_lock                 # A (3) wait for device lock

Any path that uses pci_dev_lock(), e.g., pci_reset_function(), may
deadlock with sriov_numvfs_store() if the operations occur in the sequence
(1) (2) (3) (4).

Avoid the deadlock by reversing the order in pci_dev_lock() so it acquires
the device lock before the config space access lock, the same as the
sriov_numvfs_store() path.

[bhelgaas: combined and adapted commit log from Jay Zhou's independent
subsequent posting:
https://lore.kernel.org/r/20220404062539.1710-1-jianjay.zhou@huawei.com]
Link: https://lore.kernel.org/linux-pci/1583489997-17156-1-git-send-email-yangyicong@hisilicon.com/
Also-posted-by: Jay Zhou <jianjay.zhou@huawei.com>
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-06-14 16:53:47 +02:00
..
dwc PCI: qcom: Add missing reset for ipq806x 2020-12-29 13:46:44 +01:00
endpoint PCI: endpoint: Fix for concurrent memory allocation in OB address region 2020-04-24 08:00:37 +02:00
host PCI: aardvark: Fix reading MSI interrupt number 2022-05-12 12:17:11 +02:00
hotplug PCI: pciehp: Clear cmd_busy bit in polling mode 2022-04-20 09:08:12 +02:00
pcie PCI/ASPM: Add missing newline in sysfs 'policy' 2020-08-21 09:48:10 +02:00
switch PCI/switchtec: Fix init_completion race condition with poll_wait() 2020-04-24 08:00:27 +02:00
Kconfig
Makefile
access.c PCI: Reduce warnings on possible RW1C corruption 2022-04-20 09:08:18 +02:00
ats.c
bus.c PCI: Add device even if driver attach failed 2020-12-02 08:34:39 +01:00
ecam.c
host-bridge.c
hotplug-pci.c
htirq.c
iov.c PCI/IOV: Fix memory leak in pci_iov_add_virtfn() 2020-02-28 16:35:59 +01:00
irq.c
mmap.c
msi.c PCI/MSI: Mask MSI-X vectors only on success 2021-12-22 09:18:00 +01:00
of.c
pci-acpi.c PM: ACPI: PCI: Drop acpi_pm_set_bridge_wakeup() 2020-12-29 13:47:04 +01:00
pci-driver.c PCI/PM: Always return devices to D0 when thawing 2019-12-21 10:47:40 +01:00
pci-label.c PCI/sysfs: Fix dsm_label_utf16s_to_utf8s() buffer overrun 2021-07-20 16:17:53 +02:00
pci-mid.c
pci-stub.c
pci-sysfs.c
pci.c PCI: Avoid pci_dev_lock() AB/BA deadlock with sriov_numvfs_store() 2022-06-14 16:53:47 +02:00
pci.h PCI: thunder: Fix compile testing 2021-05-22 10:57:42 +02:00
probe.c PCI: Release OF node in pci_scan_device()'s error path 2021-05-22 10:57:38 +02:00
proc.c
quirks.c PCI: Add function 1 DMA alias quirk for Marvell 88SE9125 SATA controller 2022-01-27 09:00:48 +01:00
remove.c
rom.c
search.c
setup-bus.c PCI: Don't disable bridge BARs when assigning bus resources 2020-02-14 16:32:21 -05:00
setup-irq.c
setup-res.c
slot.c PCI: Fix pci_slot_release() NULL pointer dereference 2020-12-29 13:47:11 +01:00
syscall.c PCI: Return ~0 data on pciconfig_read() CAP_SYS_ADMIN failure 2021-09-22 11:45:25 +02:00
vc.c
vpd.c
xen-pcifront.c