linux-stable/drivers/pci
Igor Mammedov d300dd19e4 PCI: acpiphp: Use pci_assign_unassigned_bridge_resources() only for non-root bus
commit cc22522fd5 upstream.

40613da52b ("PCI: acpiphp: Reassign resources on bridge if necessary")
changed acpiphp hotplug to use pci_assign_unassigned_bridge_resources()
which depends on bridge being available, however enable_slot() can be
called without bridge associated:

  1. Legitimate case of hotplug on root bus (widely used in virt world)

  2. A (misbehaving) firmware, that sends ACPI Bus Check notifications to
     non existing root ports (Dell Inspiron 7352/0W6WV0), which end up at
     enable_slot(..., bridge = 0) where bus has no bridge assigned to it.
     acpihp doesn't know that it's a bridge, and bus specific 'PCI
     subsystem' can't augment ACPI context with bridge information since
     the PCI device to get this data from is/was not available.

Issue is easy to reproduce with QEMU's 'pc' machine, which supports PCI
hotplug on hostbridge slots. To reproduce, boot kernel at commit
40613da52b in VM started with following CLI (assuming guest root fs is
installed on sda1 partition):

  # qemu-system-x86_64 -M pc -m 1G -enable-kvm -cpu host \
        -monitor stdio -serial file:serial.log           \
        -kernel arch/x86/boot/bzImage                    \
        -append "root=/dev/sda1 console=ttyS0"           \
        guest_disk.img

Once guest OS is fully booted at qemu prompt:

  (qemu) device_add e1000

(check serial.log) it will cause NULL pointer dereference at:

  void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
  {
    struct pci_bus *parent = bridge->subordinate;

  BUG: kernel NULL pointer dereference, address: 0000000000000018

   ? pci_assign_unassigned_bridge_resources+0x1f/0x260
   enable_slot+0x21f/0x3e0
   acpiphp_hotplug_notify+0x13d/0x260
   acpi_device_hotplug+0xbc/0x540
   acpi_hotplug_work_fn+0x15/0x20
   process_one_work+0x1f7/0x370
   worker_thread+0x45/0x3b0

The issue was discovered on Dell Inspiron 7352/0W6WV0 laptop with following
sequence:

  1. Suspend to RAM
  2. Wake up with the same backtrace being observed:
  3. 2nd suspend to RAM attempt makes laptop freeze

Fix it by using __pci_bus_assign_resources() instead of
pci_assign_unassigned_bridge_resources() as we used to do, but only in case
when bus doesn't have a bridge associated (to cover for the case of ACPI
event on hostbridge or non existing root port).

That lets us keep hotplug on root bus working like it used to and at the
same time keeps resource reassignment usable on root ports (and other 1st
level bridges) that was fixed by 40613da52b.

Fixes: 40613da52b ("PCI: acpiphp: Reassign resources on bridge if necessary")
Link: https://lore.kernel.org/r/20230726123518.2361181-2-imammedo@redhat.com
Reported-by: Woody Suwalski <terraluna977@gmail.com>
Tested-by: Woody Suwalski <terraluna977@gmail.com>
Tested-by: Michal Koutný <mkoutny@suse.com>
Link: https://lore.kernel.org/r/11fc981c-af49-ce64-6b43-3e282728bd1a@gmail.com
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-08-30 16:31:55 +02:00
..
controller PCI: rockchip: Use u32 variable to access 32-bit registers 2023-08-11 11:45:21 +02:00
endpoint PCI: endpoint: Fix missing destroy_workqueue() 2021-05-22 10:59:43 +02:00
hotplug PCI: acpiphp: Use pci_assign_unassigned_bridge_resources() only for non-root bus 2023-08-30 16:31:55 +02:00
pcie PCI/ASPM: Avoid link retraining race 2023-08-11 11:45:29 +02:00
switch
Kconfig
Makefile
access.c PCI: Reduce warnings on possible RW1C corruption 2022-04-15 14:14:50 +02:00
ats.c
bus.c
ecam.c
host-bridge.c
iov.c
irq.c PCI: Check for alloc failure in pci_request_irq() 2023-01-18 11:30:21 +01:00
mmap.c
msi.c PCI/MSI: Mask MSI-X vectors only on success 2021-12-22 09:19:02 +01:00
of.c
pci-acpi.c PM: ACPI: PCI: Drop acpi_pm_set_bridge_wakeup() 2020-12-30 11:26:08 +01:00
pci-driver.c
pci-label.c PCI/sysfs: Fix dsm_label_utf16s_to_utf8s() buffer overrun 2021-07-20 16:16:12 +02:00
pci-mid.c
pci-pf-stub.c
pci-stub.c
pci-sysfs.c PCI/sysfs: Fix double free in error path 2023-01-18 11:30:44 +01:00
pci.c PCI/PM: Avoid putting EloPOS E2/S2/H2 PCIe Ports in D3cold 2023-08-11 11:45:20 +02:00
pci.h PCI: thunder: Fix compile testing 2021-05-22 10:59:48 +02:00
probe.c PCI: Release OF node in pci_scan_device()'s error path 2021-05-22 10:59:42 +02:00
proc.c
quirks.c PCI: Add function 1 DMA alias quirk for Marvell 88SE9235 2023-08-11 11:45:20 +02:00
remove.c
rom.c
search.c
setup-bus.c
setup-irq.c
setup-res.c PCI: Sanitise firmware BAR assignments behind a PCI-PCI bridge 2022-10-26 13:19:22 +02:00
slot.c PCI: Fix pci_slot_release() NULL pointer dereference 2020-12-30 11:26:17 +01:00
syscall.c PCI: Return ~0 data on pciconfig_read() CAP_SYS_ADMIN failure 2021-09-22 11:48:00 +02:00
vc.c
vpd.c
xen-pcifront.c