linux/drivers/pci
Philipp Stanner fc8c818e75 PCI: Fix potential deadlock in pcim_intx()
25216afc9d ("PCI: Add managed pcim_intx()") moved the allocation step for
pci_intx()'s device resource from pcim_enable_device() to pcim_intx(). As
before, pcim_enable_device() sets pci_dev.is_managed to true; and it is
never set to false again.

Due to the lifecycle of a struct pci_dev, it can happen that a second
driver obtains the same pci_dev after a first driver ran.  If one driver
uses pcim_enable_device() and the other doesn't, this causes the other
driver to run into managed pcim_intx(), which will try to allocate when
called for the first time.

Allocations might sleep, so calling pci_intx() while holding spinlocks
becomes then invalid, which causes lockdep warnings and could cause
deadlocks:

  ========================================================
  WARNING: possible irq lock inversion dependency detected
  6.11.0-rc6+ #59 Tainted: G        W
  --------------------------------------------------------
  CPU 0/KVM/1537 just changed the state of lock:
  ffffa0f0cff965f0 (&vdev->irqlock){-...}-{2:2}, at:
  vfio_intx_handler+0x21/0xd0 [vfio_pci_core] but this lock took another,
  HARDIRQ-unsafe lock in the past: (fs_reclaim){+.+.}-{0:0}

and interrupts could create inverse lock ordering between them.

other info that might help us debug this:

  Possible interrupt unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(fs_reclaim);
			       local_irq_disable();
			       lock(&vdev->irqlock);
			       lock(fs_reclaim);
  <Interrupt>
    lock(&vdev->irqlock);

  *** DEADLOCK ***

Have pcim_enable_device()'s release function, pcim_disable_device(), set
pci_dev.is_managed to false so that subsequent drivers using the same
struct pci_dev do not implicitly run into managed code.

Link: https://lore.kernel.org/r/20240905072556.11375-2-pstanner@redhat.com
Fixes: 25216afc9d ("PCI: Add managed pcim_intx()")
Reported-by: Alex Williamson <alex.williamson@redhat.com>
Closes: https://lore.kernel.org/all/20240903094431.63551744.alex.williamson@redhat.com/
Suggested-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Philipp Stanner <pstanner@redhat.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Tested-by: Alex Williamson <alex.williamson@redhat.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
2024-09-12 07:52:50 -05:00
..
controller Merge branch 'pci/misc' 2024-07-19 10:10:33 -05:00
endpoint Driver core changes for 6.11-rc1 2024-07-25 10:42:22 -07:00
hotplug powerpc updates for 6.11 2024-07-19 21:00:33 -07:00
msi Switch ARM/ARM64 over to the modern per device MSI domains: 2024-07-22 14:02:19 -07:00
pcie Merge branch 'pci/misc' 2024-07-19 10:10:33 -05:00
pwrctl Kconfig: reduce the amount of power sequencing noise 2024-07-18 13:56:40 +02:00
switch PCI: switchtec: Make switchtec_class constant 2024-06-10 15:03:30 -05:00
access.c PCI: Revert the cfg_access_lock lockdep mechanism 2024-06-04 12:10:05 -05:00
ats.c PCI/ATS: Use FIELD_GET() 2023-10-24 16:55:45 -05:00
bus.c pci-v6.11-changes 2024-07-19 19:03:18 -07:00
devres.c PCI: Fix potential deadlock in pcim_intx() 2024-09-12 07:52:50 -05:00
doe.c PCI/DOE: Support discovery version 2 2024-04-09 09:33:15 -05:00
ecam.c
host-bridge.c
iomap.c PCI: Document hybrid devres hazards 2024-07-10 04:20:01 +00:00
iov.c PCI: Use resource names in PCI log messages 2023-12-15 17:28:42 -06:00
irq.c PCI: Place interrupt related code into irq.c 2024-01-29 17:01:31 -06:00
Kconfig PCI/pwrctl: Add PCI power control core code 2024-06-12 13:20:56 +02:00
Makefile PCI/pwrctl: Add PCI power control core code 2024-06-12 13:20:56 +02:00
mmap.c PCI/sysfs: Compile pci-sysfs.c only if CONFIG_SYSFS=y 2024-03-05 16:08:43 -06:00
of_property.c PCI: of_property: Add interrupt-controller property in PCI device nodes 2024-07-08 17:40:30 -06:00
of.c pci-v6.11-changes 2024-07-19 19:03:18 -07:00
p2pdma.c PCI/P2PDMA: Fix a sleeping issue in a RCU read section 2024-02-08 15:31:43 -06:00
pci-acpi.c PCI: Move PRESERVE_BOOT_CONFIG _DSM evaluation to pci_register_host_bridge() 2024-06-03 16:13:38 -05:00
pci-bridge-emul.c
pci-bridge-emul.h
pci-driver.c driver core: have match() callback in struct bus_type take a const * 2024-07-03 15:16:54 +02:00
pci-label.c
pci-mid.c PCI/PM: Switch to new Intel CPU model defines 2024-06-11 17:08:14 -05:00
pci-pf-stub.c PCI: Add missing MODULE_DESCRIPTION() macros 2024-07-08 08:35:35 +00:00
pci-stub.c PCI: Add missing MODULE_DESCRIPTION() macros 2024-07-08 08:35:35 +00:00
pci-sysfs.c PCI/sysfs: Demacrofy pci_dev_resource_resize_attr(n) functions 2024-03-05 16:10:17 -06:00
pci.c pci-v6.11-changes 2024-07-19 19:03:18 -07:00
pci.h Merge branch 'pci/controller/rockchip' 2024-07-19 10:10:32 -05:00
probe.c pci-v6.11-changes 2024-07-19 19:03:18 -07:00
proc.c
quirks.c PCI: Add ACS quirk for Broadcom BCM5760X NIC 2024-05-28 11:13:28 -05:00
remove.c PCI/pwrctl: Create platform devices for child OF nodes of the port node 2024-06-12 13:20:56 +02:00
rom.c
search.c
setup-bus.c PCI: Relax bridge window tail sizing rules 2024-06-12 14:51:30 -05:00
setup-res.c PCI: Use resource names in PCI log messages 2023-12-15 17:28:42 -06:00
slot.c
syscall.c
vc.c PCI/VC: Use FIELD_GET() 2023-10-24 16:55:45 -05:00
vgaarb.c pci-v6.7-changes 2023-11-02 14:05:18 -10:00
vpd.c
xen-pcifront.c