linux/drivers/pci/pcie
Bjorn Helgaas a579ba49a9 PCI/portdrv: Compute MSI/MSI-X IRQ vectors after final allocation
When setting up portdrv MSI/MSI-X interrupts, we previously allocated the
maximum possible number of vectors, read the Interrupt Message Numbers for
each service, saved the IRQ for each, freed the vectors, and finally used
the largest Message Number to reallocate only as many vectors as we need.

The problem is that freeing the vectors invalidates their IRQs, so the
saved IRQ numbers may now be invalid, which can result in errors like
this:

  pcie_pme: probe of 0000:00:00.0:pcie001 failed with error -22
  pciehp 0000:00:00.0:pcie004: Cannot get irq 20 for the hotplug controller
  aer: probe of 0000:00:00.0:pcie002 failed with error -22
  dpc 0000:00:00.0:pcie010: request IRQ22 failed: -22

Change the setup so we save the Interrupt Message Numbers (not the IRQs)
before we free the original setup, then use the Message Numbers to compute
the IRQs (via pci_irq_vector()) *after* we reallocate the vectors.

This should always be safe for MSI-X because the Message Numbers are fixed.
For MSI, the hardware is allowed to change Message Numbers when we update
the MSI Multiple Message Enable field when reallocating the vectors, but
since we allocate enough vectors to accommodate the largest Message Number
we found, that's unlikely.  See PCIe r3.1, sec 7.8.2, 7.10.10, 7.31.2.

Fixes: 3674cc49da ("PCI/portdrv: Use pci_irq_alloc_vectors()")
Based-on-patch-by: Dongdong Liu <liudongdong3@huawei.com>
Tested-by: Dongdong Liu <liudongdong3@huawei.com>  # HiSilicon hip08
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
2017-10-21 11:07:21 -05:00
..
aer Merge branch 'pci/trivial' into next 2017-09-07 13:24:20 -05:00
aspm.c PCI/ASPM: Always set link->downstream to avoid NULL dereference on remove 2017-03-07 14:23:30 -06:00
Kconfig PCI/ASPM: Add support for L1 substates 2017-02-14 17:43:51 -06:00
Makefile PCI: Add Precision Time Measurement (PTM) support 2016-08-15 13:44:08 -05:00
pcie-dpc.c PCI/DPC: Add local struct device pointers 2017-08-24 11:30:02 -05:00
pme.c PCI / PM: Fix native PME handling during system suspend/resume 2017-07-13 01:50:07 +02:00
portdrv_acpi.c Merge branches 'pci/dpc', 'pci/resource' and 'pci/thunderbolt' into next 2016-05-03 11:49:21 -05:00
portdrv_bus.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
portdrv_core.c PCI/portdrv: Compute MSI/MSI-X IRQ vectors after final allocation 2017-10-21 11:07:21 -05:00
portdrv_pci.c dmi: Mark all struct dmi_system_id instances const 2017-09-14 11:59:30 +02:00
portdrv.h PCI/portdrv: Support multiple interrupts for MSI as well as MSI-X 2017-06-16 18:04:13 -05:00
ptm.c PCI: Add PTM clock granularity information 2016-08-25 08:32:34 -05:00