linux-stable/drivers/pci/hotplug
Lukas Wunner 5b3f7b7d06 PCI: pciehp: Avoid slot access during reset
The ->reset_slot callback introduced by commits:

  2e35afaefe ("PCI: pciehp: Add reset_slot() method") and
  06a8d89af5 ("PCI: pciehp: Disable link notification across slot reset")

disables notification of Presence Detect Changed and Data Link Layer
State Changed events for the duration of a secondary bus reset.

However a bus reset not only triggers these events, but may also clear
the Presence Detect State bit in the Slot Status register and the Data
Link Layer Link Active bit in the Link Status register momentarily.
According to Sinan Kaya:

 "I know for a fact that bus reset clears the Data Link Layer Active bit
  as soon as link goes down.  It gets set again following link up.
  Presence detect depends on the HW implementation.  QDT root ports
  don't change presence detect for instance since nobody actually
  removed the card.  If an implementation supports in-band presence
  detect, the answer is yes.  As soon as the link goes down, presence
  detect bit will get cleared until recovery."
  https://lkml.kernel.org/r/42e72f83-3b24-f7ef-e5bc-290fae99259a@codeaurora.org

  In-band presence detect is also covered in Table 4-15 in PCIe r4.0,
  sec 4.2.6.

pciehp should therefore ensure that any parts of the driver that access
those bits do not run concurrently to a bus reset.  The only precaution
the commits took to that effect was to halt interrupt polling.  They
made no effort to drain the slot workqueue, cancel an outstanding
Attention Button work, or block slot enable/disable requests via sysfs
and in the ->probe hook.

Now that pciehp is converted to enable/disable the slot exclusively from
the IRQ thread, the only places accessing the two above-mentioned bits
are the IRQ thread and the ->probe hook.  Add locking to serialize them
with a bus reset.  This obviates the need to halt interrupt polling.
Do not add locking to the ->get_adapter_status sysfs callback to afford
users unfettered access to that bit.  Use an rw_semaphore in lieu of a
regular mutex to allow parallel execution of the non-reset code paths
accessing the critical bits, i.e. the IRQ thread and the ->probe hook.

Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Rajat Jain <rajatja@google.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Sinan Kaya <okaya@kernel.org>
2018-07-31 10:50:31 -05:00
..
acpi_pcihp.c PCI: shpchp: Separate existence of SHPC and permission to use it 2018-06-26 15:38:28 -05:00
acpiphp.h PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
acpiphp_core.c PCI: hotplug: Demidlayer registration with the core 2018-07-23 17:04:13 -05:00
acpiphp_glue.c ACPI / hotplug / PCI: Drop unnecessary parentheses 2018-06-04 12:08:06 -05:00
acpiphp_ibm.c More ACPI updates for v4.16-rc1 2018-02-09 09:44:25 -08:00
cpci_hotplug.h PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
cpci_hotplug_core.c PCI: hotplug: Demidlayer registration with the core 2018-07-23 17:04:13 -05:00
cpci_hotplug_pci.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
cpcihp_generic.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
cpcihp_zt5550.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
cpcihp_zt5550.h PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
cpqphp.h PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
cpqphp_core.c PCI: hotplug: Demidlayer registration with the core 2018-07-23 17:04:13 -05:00
cpqphp_ctrl.c PCI: cpqphp: Fix possible NULL pointer dereference 2018-02-28 14:35:54 -06:00
cpqphp_nvram.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
cpqphp_nvram.h PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
cpqphp_pci.c Merge branch 'pci/spdx' into next 2018-02-01 11:40:07 -06:00
cpqphp_sysfs.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
ibmphp.h PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
ibmphp_core.c PCI: hotplug: Demidlayer registration with the core 2018-07-23 17:04:13 -05:00
ibmphp_ebda.c PCI: hotplug: Demidlayer registration with the core 2018-07-23 17:04:13 -05:00
ibmphp_hpc.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
ibmphp_pci.c Merge branch 'pci/spdx' into next 2018-02-01 11:40:07 -06:00
ibmphp_res.c Merge branch 'pci/spdx' into next 2018-02-01 11:40:07 -06:00
Kconfig PCI: shpchp: Convert SHPC to be builtin only 2018-06-02 00:18:28 -05:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pci_hotplug_core.c PCI: hotplug: Demidlayer registration with the core 2018-07-23 17:04:13 -05:00
pciehp.h PCI: pciehp: Avoid slot access during reset 2018-07-31 10:50:31 -05:00
pciehp_core.c PCI: pciehp: Avoid slot access during reset 2018-07-31 10:50:31 -05:00
pciehp_ctrl.c PCI: pciehp: Become resilient to missed events 2018-07-23 17:04:16 -05:00
pciehp_hpc.c PCI: pciehp: Avoid slot access during reset 2018-07-31 10:50:31 -05:00
pciehp_pci.c PCI: pciehp: Declare pciehp_unconfigure_device() void 2018-07-23 17:04:11 -05:00
pnv_php.c PCI: hotplug: Demidlayer registration with the core 2018-07-23 17:04:13 -05:00
rpadlpar.h PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
rpadlpar_core.c pci-v4.16-changes 2018-02-06 09:59:40 -08:00
rpadlpar_sysfs.c pci-v4.16-changes 2018-02-06 09:59:40 -08:00
rpaphp.h pci-v4.16-changes 2018-02-06 09:59:40 -08:00
rpaphp_core.c PCI: hotplug: Demidlayer registration with the core 2018-07-23 17:04:13 -05:00
rpaphp_pci.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
rpaphp_slot.c PCI: hotplug: Demidlayer registration with the core 2018-07-23 17:04:13 -05:00
s390_pci_hpc.c PCI: hotplug: Demidlayer registration with the core 2018-07-23 17:04:13 -05:00
sgi_hotplug.c PCI: hotplug: Demidlayer registration with the core 2018-07-23 17:04:13 -05:00
shpchp.h PCI: shpchp: Add shpchp_is_native() 2018-06-04 12:08:06 -05:00
shpchp_core.c PCI: hotplug: Demidlayer registration with the core 2018-07-23 17:04:13 -05:00
shpchp_ctrl.c PCI: shpchp: Fix AMD POGO identification 2018-06-04 12:07:31 -05:00
shpchp_hpc.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
shpchp_pci.c Merge branch 'pci/spdx' into next 2018-02-01 11:40:07 -06:00
shpchp_sysfs.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00