linux/drivers/pci/hotplug
Rafael J. Wysocki 3757b94802 ACPI / hotplug: Fix concurrency issues and memory leaks
This changeset is aimed at fixing a few different but related
problems in the ACPI hotplug infrastructure.

First of all, since notify handlers may be run in parallel with
acpi_bus_scan(), acpi_bus_trim() and acpi_bus_hot_remove_device()
and some of them are installed for ACPI handles that have no struct
acpi_device objects attached (i.e. before those objects are created),
those notify handlers have to take acpi_scan_lock to prevent races
from taking place (e.g. a struct acpi_device is found to be present
for the given ACPI handle, but right after that it is removed by
acpi_bus_trim() running in parallel to the given notify handler).
Moreover, since some of them call acpi_bus_scan() and
acpi_bus_trim(), this leads to the conclusion that acpi_scan_lock
should be acquired by the callers of these two funtions rather by
these functions themselves.

For these reasons, make all notify handlers that can handle device
addition and eject events take acpi_scan_lock and remove the
acpi_scan_lock locking from acpi_bus_scan() and acpi_bus_trim().
Accordingly, update all of their users to make sure that they
are always called under acpi_scan_lock.

Furthermore, since eject operations are carried out asynchronously
with respect to the notify events that trigger them, with the help
of acpi_bus_hot_remove_device(), even if notify handlers take the
ACPI scan lock, it still is possible that, for example,
acpi_bus_trim() will run between acpi_bus_hot_remove_device() and
the notify handler that scheduled its execution and that
acpi_bus_trim() will remove the device node passed to
acpi_bus_hot_remove_device() for ejection.  In that case, the struct
acpi_device object obtained by acpi_bus_hot_remove_device() will be
invalid and not-so-funny things will ensue.  To protect agaist that,
make the users of acpi_bus_hot_remove_device() run get_device() on
ACPI device node objects that are about to be passed to it and make
acpi_bus_hot_remove_device() run put_device() on them and check if
their ACPI handles are not NULL (make acpi_device_unregister() clear
the device nodes' ACPI handles for that check to work).

Finally, observe that acpi_os_hotplug_execute() actually can fail,
in which case its caller ought to free memory allocated for the
context object to prevent leaks from happening.  It also needs to
run put_device() on the device node that it ran get_device() on
previously in that case.  Modify the code accordingly.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
2013-02-13 14:36:47 +01:00
..
acpi_pcihp.c module_param: make bool parameters really bool (drivers & misc) 2012-01-13 09:32:20 +10:30
acpiphp_core.c PCI: acpiphp: merge acpiphp_debug and debug 2012-07-10 17:02:37 -06:00
acpiphp_glue.c ACPI / hotplug: Fix concurrency issues and memory leaks 2013-02-13 14:36:47 +01:00
acpiphp_ibm.c module_param: make bool parameters really bool (drivers & misc) 2012-01-13 09:32:20 +10:30
acpiphp.h PCI: acpiphp: merge acpiphp_debug and debug 2012-07-10 17:02:37 -06:00
cpci_hotplug_core.c PCI: hotplug: ensure a consistent return value in error case 2012-07-16 09:25:56 -06:00
cpci_hotplug_pci.c PCI: cpci_hotplug: use generic pci_hp_add_bridge() 2012-06-13 15:42:26 -06:00
cpci_hotplug.h PCI: cpci_hotplug: stop managing hotplug_slot->name 2008-10-22 16:42:39 -07:00
cpcihp_generic.c PCI/cpcihp: Use hotplug-safe pci_get_domain_bus_and_slot() 2012-09-12 14:13:59 -06:00
cpcihp_zt5550.c PCI: Remove __dev* markings 2012-11-28 13:16:47 -08:00
cpcihp_zt5550.h
cpqphp_core.c PCI: hotplug: ensure a consistent return value in error case 2012-07-16 09:25:56 -06:00
cpqphp_ctrl.c PCI: cpqphp: Remove unreachable path 2012-09-10 16:45:41 -06:00
cpqphp_nvram.c PCI Hotplug: cpqphp: fix comment style 2009-06-11 12:04:08 -07:00
cpqphp_nvram.h
cpqphp_pci.c PCI: cpqhp: use generic pci_hp_add_bridge() 2012-06-13 15:42:26 -06:00
cpqphp_sysfs.c drivers: autoconvert trivial BKL users to private mutex 2010-10-05 15:01:04 +02:00
cpqphp.h PCI: Make current and maximum bus speeds part of the PCI core 2010-02-22 16:15:17 -08:00
ibmphp_core.c PCI changes for the 3.6 merge window: 2012-07-24 16:17:07 -07:00
ibmphp_ebda.c pci: hotplug: Fix typo in pci 2012-07-24 12:59:30 +02:00
ibmphp_hpc.c PCI hotplug: ibmphp-hpc: semaphore cleanup 2010-10-15 13:09:48 -07:00
ibmphp_pci.c pci: hotplug: Fix typo in pci 2012-07-24 12:59:30 +02:00
ibmphp_res.c ibmphp: Rename add_range() to add_bus_range() to avoid conflict 2010-02-10 17:45:09 -08:00
ibmphp.h PCI: ibmphp: stop managing hotplug_slot->name 2008-10-22 16:42:41 -07:00
Kconfig s390/pci: PCI hotplug support via SCLP 2012-11-30 17:47:25 +01:00
Makefile s390/pci: PCI hotplug support via SCLP 2012-11-30 17:47:25 +01:00
pci_hotplug_core.c module_param: make bool parameters really bool (drivers & misc) 2012-01-13 09:32:20 +10:30
pciehp_acpi.c PCI/pciehp: Use PCI Express Capability accessors 2012-08-23 10:11:11 -06:00
pciehp_core.c PCI: pciehp: Use per-slot workqueues to avoid deadlock 2013-01-12 13:56:33 -07:00
pciehp_ctrl.c PCI: pciehp: Use per-slot workqueues to avoid deadlock 2013-01-12 13:56:33 -07:00
pciehp_hpc.c PCI: pciehp: Use per-slot workqueues to avoid deadlock 2013-01-12 13:56:33 -07:00
pciehp_pci.c PCI: pciehp: use generic pci_hp_add_bridge() 2012-06-13 15:42:26 -06:00
pciehp.h PCI: pciehp: Use per-slot workqueues to avoid deadlock 2013-01-12 13:56:33 -07:00
pcihp_skeleton.c PCI: hotplug: ensure a consistent return value in error case 2012-07-16 09:25:56 -06:00
pcihp_slot.c PCI/hotplug: Use PCI Express Capability accessors 2012-08-23 10:11:11 -06:00
rpadlpar_core.c powerpc/eeh: Remove EEH PE for normal PCI hotplug 2012-09-18 15:32:23 +10:00
rpadlpar_sysfs.c
rpadlpar.h
rpaphp_core.c module_param: make bool parameters really bool (drivers & misc) 2012-01-13 09:32:20 +10:30
rpaphp_pci.c PCI hotplug: rpaphp: make debug var unique 2008-10-20 10:54:27 -07:00
rpaphp_slot.c headers: kobject.h redux 2011-01-10 08:51:44 -08:00
rpaphp.h module_param: make bool parameters really bool (drivers & misc) 2012-01-13 09:32:20 +10:30
s390_pci_hpc.c s390/pci: PCI hotplug support via SCLP 2012-11-30 17:47:25 +01:00
sgi_hotplug.c ACPI / hotplug: Fix concurrency issues and memory leaks 2013-02-13 14:36:47 +01:00
shpchp_core.c PCI: shpchp: Use per-slot workqueues to avoid deadlock 2013-01-14 10:23:22 -07:00
shpchp_ctrl.c PCI: shpchp: Use per-slot workqueues to avoid deadlock 2013-01-14 10:23:22 -07:00
shpchp_hpc.c PCI hotplug: shpchp: don't blindly claim non-AMD 0x7450 device IDs 2011-11-14 09:43:14 -08:00
shpchp_pci.c PCI: shpchp: use generic pci_hp_add_bridge() 2012-06-13 15:42:26 -06:00
shpchp_sysfs.c PCI: replace struct pci_bus secondary/subordinate with busn_res 2012-06-13 15:42:22 -06:00
shpchp.h PCI: shpchp: Use per-slot workqueues to avoid deadlock 2013-01-14 10:23:22 -07:00