alistair23-linux/drivers/pci/hotplug
Rajat Jain c4f2f5e498 PCI: pciehp: Ensure very fast hotplug events are also processed
Today, this is how all the hotplug and unplug events work:

Hotplug / Removal needs to be done
  => Set slot->state (protected by slot->lock) to either
    POWERON_STATE (for enabling) or POWEROFF_STATE (for disabling).
  => Submit the work item for pciehp_power_thread() to slot->wq.

Problem:
  There is a problem if the hotplug events can happen fast enough that
  they do not give SW enough time to add or remove the new devices.

  => Assume: Event for unplug comes (e.g. surprise removal). But
     before the pciehp_power_thread() work item was executed, the
     card was replaced by another card, causing surprise hotplug event.

  => What goes wrong:
    => The hot-removal event sets slot->state to POWEROFF_STATE, and
       schedules the pciehp_power_thread().
    => The hot-add event sets slot->state to POWERON_STATE, and
       schedules the pciehp_power_thread().
    => Now the pciehp_power_thread() is scheduled twice, and on both
       occasions it will find POWERON_STATE and will try to add the
       devices on the slot, and will fail complaining that the devices
       already exist.

  => Why this is a problem: If the device was replaced between the hot
     removal and hot-add, then we should unload the old driver and
     reload the new one. This does not happen today. The kernel or the
     driver is not even aware that the device was replaced.

     The problem is that the pciehp_power_thread() only looks at the
     slot->state which would only contain the *latest* state - not
     the actual event (add / remove) that was the intent of the IRQ
     handler who submitted the work.

What this patch does:

  => Hotplug events pass on an actual request (for addition or removal)
     to pciehp_power_thread() which is local to that work item
     submission.

  => pciehp_power_thread() does not need to look at slote->state and
     hence no locks needed in that.

  => Essentially this results in all the hotplug and unplug events
     "replayed" by pciehp_power_thread().

Signed-off-by: Rajat Jain <rajatxjain@gmail.com>
Signed-off-by: Rajat Jain <rajatjain@juniper.net>
Signed-off-by: Guenter Roeck <groeck@juniper.net>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2014-02-11 16:13:01 -07:00
..
acpi_pcihp.c ACPI: Eliminate the DEVICE_ACPI_HANDLE() macro 2013-11-14 23:17:21 +01:00
acpiphp.h ACPI / hotplug / PCI: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
acpiphp_core.c ACPI / hotplug / PCI: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
acpiphp_glue.c ACPI and power management updates for 3.14-rc1 2014-01-24 15:51:02 -08:00
acpiphp_ibm.c ACPI: Clean up inclusions of ACPI header files 2013-12-07 01:03:14 +01:00
cpci_hotplug.h
cpci_hotplug_core.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
cpci_hotplug_pci.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
cpcihp_generic.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
cpcihp_zt5550.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
cpcihp_zt5550.h PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
cpqphp.h
cpqphp_core.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
cpqphp_ctrl.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
cpqphp_nvram.c
cpqphp_nvram.h
cpqphp_pci.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
cpqphp_sysfs.c cpqphp_sysfs: switch to fixed_size_llseek() 2013-06-29 12:57:52 +04:00
ibmphp.h PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
ibmphp_core.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
ibmphp_ebda.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
ibmphp_hpc.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
ibmphp_pci.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
ibmphp_res.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
Kconfig PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
Makefile PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
pci_hotplug_core.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
pciehp.h PCI: pciehp: Use link change notifications for hot-plug and removal 2014-02-10 18:12:44 -07:00
pciehp_acpi.c PCI updates for v3.13: 2013-11-22 10:53:47 -08:00
pciehp_core.c Merge branch 'pci/dead-code' into next 2014-01-13 16:47:08 -07:00
pciehp_ctrl.c PCI: pciehp: Ensure very fast hotplug events are also processed 2014-02-11 16:13:01 -07:00
pciehp_hpc.c PCI: pciehp: Disable link notification across slot reset 2014-02-11 16:13:01 -07:00
pciehp_pci.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
pcihp_skeleton.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
pcihp_slot.c PCI: Simplify pcie_bus_configure_settings() interface 2013-08-22 10:47:02 -06:00
rpadlpar.h
rpadlpar_core.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
rpadlpar_sysfs.c
rpaphp.h PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
rpaphp_core.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
rpaphp_pci.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
rpaphp_slot.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
s390_pci_hpc.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
sgi_hotplug.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
shpchp.h PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
shpchp_core.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
shpchp_ctrl.c
shpchp_hpc.c PCI: Fix whitespace, capitalization, and spelling errors 2013-11-14 11:28:18 -07:00
shpchp_pci.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
shpchp_sysfs.c