linux-stable/drivers/pci
Maciej W. Rozycki 1680dbf512 PCI: Sanitise firmware BAR assignments behind a PCI-PCI bridge
commit 0e32818397 upstream.

When pci_assign_resource() is unable to assign resources to a BAR, it uses
pci_revert_fw_address() to fall back to a firmware assignment (if any).
Previously pci_revert_fw_address() assumed all addresses could reach the
device, but this is not true if the device is below a bridge that only
forwards addresses within its windows.

This problem was observed on a Tyan Tomcat IV S1564D system where the BIOS
did not assign valid addresses to several bridges and USB devices:

  pci 0000:00:11.0: PCI-to-PCIe bridge to [bus 01-ff]
  pci 0000:00:11.0:   bridge window [io  0xe000-0xefff]
  pci 0000:01:00.0: PCIe Upstream Port to [bus 02-ff]
  pci 0000:01:00.0:   bridge window [io  0x0000-0x0fff]   # unreachable
  pci 0000:02:02.0: PCIe Downstream Port to [bus 05-ff]
  pci 0000:02:02.0:   bridge window [io  0x0000-0x0fff]   # unreachable
  pci 0000:05:00.0: PCIe-to-PCI bridge to [bus 06-ff]
  pci 0000:05:00.0:   bridge window [io  0x0000-0x0fff]   # unreachable
  pci 0000:06:08.0: USB UHCI 1.1
  pci 0000:06:08.0: BAR 4: [io  0xfce0-0xfcff]            # unreachable
  pci 0000:06:08.1: USB UHCI 1.1
  pci 0000:06:08.1: BAR 4: [io  0xfce0-0xfcff]            # unreachable
  pci 0000:06:08.0: can't claim BAR 4 [io  0xfce0-0xfcff]: no compatible bridge window
  pci 0000:06:08.1: can't claim BAR 4 [io  0xfce0-0xfcff]: no compatible bridge window

During the first pass of assigning unassigned resources, there was not
enough I/O space available, so we couldn't assign the 06:08.0 BAR and
reverted to the firmware assignment (still unreachable).  Reverting the
06:08.1 assignment failed because it conflicted with 06:08.0:

  pci 0000:00:11.0:   bridge window [io  0xe000-0xefff]
  pci 0000:01:00.0: no space for bridge window [io  size 0x2000]
  pci 0000:02:02.0: no space for bridge window [io  size 0x1000]
  pci 0000:05:00.0: no space for bridge window [io  size 0x1000]
  pci 0000:06:08.0: BAR 4: no space for [io  size 0x0020]
  pci 0000:06:08.0: BAR 4: trying firmware assignment [io  0xfce0-0xfcff]
  pci 0000:06:08.1: BAR 4: no space for [io  size 0x0020]
  pci 0000:06:08.1: BAR 4: trying firmware assignment [io  0xfce0-0xfcff]
  pci 0000:06:08.1: BAR 4: [io  0xfce0-0xfcff] conflicts with 0000:06:08.0 [io  0xfce0-0xfcff]

A subsequent pass assigned valid bridge windows and a valid 06:08.1 BAR,
but left the 06:08.0 BAR alone, so the UHCI device was still unusable:

  pci 0000:00:11.0:   bridge window [io  0xe000-0xefff] released
  pci 0000:00:11.0:   bridge window [io  0x1000-0x2fff]   # reassigned
  pci 0000:01:00.0:   bridge window [io  0x1000-0x2fff]   # reassigned
  pci 0000:02:02.0:   bridge window [io  0x2000-0x2fff]   # reassigned
  pci 0000:05:00.0:   bridge window [io  0x2000-0x2fff]   # reassigned
  pci 0000:06:08.0: BAR 4: assigned [io  0xfce0-0xfcff]   # left alone
  pci 0000:06:08.1: BAR 4: assigned [io  0x2000-0x201f]
  ...
  uhci_hcd 0000:06:08.0: host system error, PCI problems?
  uhci_hcd 0000:06:08.0: host controller process error, something bad happened!
  uhci_hcd 0000:06:08.0: host controller halted, very bad!
  uhci_hcd 0000:06:08.0: HCRESET not completed yet!
  uhci_hcd 0000:06:08.0: HC died; cleaning up

If the address assigned by firmware is not reachable because it's not
within upstream bridge windows, fail instead of assigning the unusable
address from firmware.

[bhelgaas: commit log, use pci_upstream_bridge()]
Link: https://bugzilla.kernel.org/show_bug.cgi?id=16263
Link: https://lore.kernel.org/r/alpine.DEB.2.21.2203012338460.46819@angie.orcam.me.uk
Link: https://lore.kernel.org/r/alpine.DEB.2.21.2209211921250.29493@angie.orcam.me.uk
Fixes: 58c84eda07 ("PCI: fall back to original BIOS BAR addresses")
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: stable@vger.kernel.org # v2.6.35+
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-10-24 09:56:49 +02:00
..
controller PCI: aardvark: Fix reporting Slot capabilities on emulated bridge 2022-08-25 11:45:40 +02:00
endpoint PCI: endpoint: Don't stop controller when unbinding endpoint function 2022-08-17 15:15:28 +02:00
hotplug PCI: hotplug: Clean up include files 2022-04-05 11:13:33 -05:00
msi PCI/MSI: Remove bogus warning in pci_irq_get_affinity() 2022-02-04 09:54:20 +01:00
pcie Revert "PCI/portdrv: Don't disable AER reporting in get_port_device_capability()" 2022-09-05 10:31:27 +02:00
switch
Kconfig PCI/VGA: Move vgaarb to drivers/pci 2022-03-09 18:30:46 -06:00
Makefile PCI/VGA: Move vgaarb to drivers/pci 2022-03-09 18:30:46 -06:00
access.c PCI: Reduce warnings on possible RW1C corruption 2022-03-04 15:59:52 -06:00
ats.c
bus.c
ecam.c
host-bridge.c
iov.c PCI/IOV: Fix wrong kernel-doc identifier 2022-03-07 12:06:10 -07:00
irq.c
mmap.c
of.c IOMMU Updates for Linux v5.19 2022-05-31 09:56:54 -07:00
p2pdma.c PCI/P2PDMA: Whitelist Intel Skylake-E Root Ports at any devfn 2022-04-11 13:21:41 -05:00
pci-acpi.c pci-v5.19-changes 2022-05-27 15:25:10 -07:00
pci-bridge-emul.c Merge branch 'remotes/lorenzo/pci/mvebu' 2022-03-22 17:16:25 -05:00
pci-bridge-emul.h PCI: pci-bridge-emul: Add support for PCI Bridge Subsystem Vendor ID capability 2022-02-22 16:04:19 +00:00
pci-driver.c IOMMU Updates for Linux v5.19 2022-05-31 09:56:54 -07:00
pci-label.c
pci-mid.c
pci-pf-stub.c
pci-stub.c PCI: pci_stub: Set driver_managed_dma 2022-04-28 15:32:20 +02:00
pci-sysfs.c PCI: Use driver_set_override() instead of open-coding 2022-04-22 17:13:54 +02:00
pci.c PCI/PM: Fix bridge_d3_blacklist[] Elo i2 overwrite of Gigabyte X299 2022-05-31 15:06:19 -05:00
pci.h PCI: Add function for parsing 'slot-power-limit-milliwatt' DT property 2022-04-25 10:53:39 +01:00
probe.c pci-v5.17-changes 2022-01-16 08:08:11 +02:00
proc.c PCI: Remove unused assignments 2022-03-22 11:23:53 -05:00
quirks.c PCI: Add ACS quirk for Broadcom BCM5750x NICs 2022-08-25 11:45:39 +02:00
remove.c
rom.c
search.c
setup-bus.c Merge branch 'pci/misc' 2022-03-22 17:16:21 -05:00
setup-irq.c
setup-res.c PCI: Sanitise firmware BAR assignments behind a PCI-PCI bridge 2022-10-24 09:56:49 +02:00
slot.c
syscall.c
vc.c
vgaarb.c PCI/VGA: Replace full MIT license text with SPDX identifier 2022-03-09 18:31:34 -06:00
vpd.c
xen-pcifront.c xen/pcifront: use xenbus_setup_ring() and xenbus_teardown_ring() 2022-05-19 14:22:02 +02:00