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
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
acpiphp.h ACPI / hotplug / PCI: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
cpci_hotplug_core.c
cpci_hotplug_pci.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
cpci_hotplug.h
cpcihp_generic.c
cpcihp_zt5550.c
cpcihp_zt5550.h
cpqphp_core.c
cpqphp_ctrl.c
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.h
ibmphp_core.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
ibmphp_ebda.c
ibmphp_hpc.c
ibmphp_pci.c
ibmphp_res.c
ibmphp.h
Kconfig
Makefile
pci_hotplug_core.c
pciehp_acpi.c
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
pciehp.h PCI: pciehp: Use link change notifications for hot-plug and removal 2014-02-10 18:12:44 -07:00
pcihp_skeleton.c
pcihp_slot.c
rpadlpar_core.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
rpadlpar_sysfs.c
rpadlpar.h
rpaphp_core.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
rpaphp_pci.c
rpaphp_slot.c
rpaphp.h
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_core.c
shpchp_ctrl.c
shpchp_hpc.c
shpchp_pci.c PCI: hotplug: Use global PCI rescan-remove locking 2014-01-14 12:14:25 -07:00
shpchp_sysfs.c
shpchp.h