android_kernel_samsung_msm8976/drivers/acpi
Rafael J. Wysocki 21a31013f7 ACPI / dock / PCI: Synchronous handling of dock events for PCI devices
The interactions between the ACPI dock driver and the ACPI-based PCI
hotplug (acpiphp) are currently problematic because of ordering
issues during hot-remove operations.

First of all, the current ACPI glue code expects that physical
devices will always be deleted before deleting the companion ACPI
device objects.  Otherwise, acpi_unbind_one() will fail with a
warning message printed to the kernel log, for example:

[  185.026073] usb usb5: Oops, 'acpi_handle' corrupt
[  185.035150] pci 0000:1b:00.0: Oops, 'acpi_handle' corrupt
[  185.035515] pci 0000:18:02.0: Oops, 'acpi_handle' corrupt
[  180.013656]  port1: Oops, 'acpi_handle' corrupt

This means, in particular, that struct pci_dev objects have to
be deleted before the struct acpi_device objects they are "glued"
with.

Now, the following happens the during the undocking of an ACPI-based
dock station:
 1) hotplug_dock_devices() invokes registered hotplug callbacks to
    destroy physical devices associated with the ACPI device objects
    depending on the dock station.  It calls dd->ops->handler() for
    each of those device objects.
 2) For PCI devices dd->ops->handler() points to
    handle_hotplug_event_func() that queues up a separate work item
    to execute _handle_hotplug_event_func() for the given device and
    returns immediately.  That work item will be executed later.
 3) hotplug_dock_devices() calls dock_remove_acpi_device() for each
    device depending on the dock station.  This runs acpi_bus_trim()
    for each of them, which causes the underlying ACPI device object
    to be destroyed, but the work items queued up by
    handle_hotplug_event_func() haven't been started yet.
 4) _handle_hotplug_event_func() queued up in step 2) are executed
    and cause the above failure to happen, because the PCI devices
    they handle do not have the companion ACPI device objects any
    more (those objects have been deleted in step 3).

The possible breakage doesn't end here, though, because
hotplug_dock_devices() may return before at least some of the
_handle_hotplug_event_func() work items spawned by it have a
chance to complete and then undock() will cause _DCK to be
evaluated and that will cause the devices handled by the
_handle_hotplug_event_func() to go away possibly while they are
being accessed.

This means that dd->ops->handler() for PCI devices should not point
to handle_hotplug_event_func().  Instead, it should point to a
function that will do the work of _handle_hotplug_event_func()
synchronously.  For this reason, introduce such a function,
hotplug_event_func(), and modity acpiphp_dock_ops to point to
it as the handler.

Unfortunately, however, this is not sufficient, because if the dock
code were not changed further, hotplug_event_func() would now
deadlock with hotplug_dock_devices() that called it, since it would
run unregister_hotplug_dock_device() which in turn would attempt to
acquire the dock station's hp_lock mutex already acquired by
hotplug_dock_devices().

To resolve that deadlock use the observation that
unregister_hotplug_dock_device() won't need to acquire hp_lock
if PCI bridges the devices on the dock station depend on are
prevented from being removed prematurely while the first loop in
hotplug_dock_devices() is in progress.

To make that possible, introduce a mechanism by which the callers of
register_hotplug_dock_device() can provide "init" and "release"
routines that will be executed, respectively, during the addition
and removal of the physical device object associated with the
given ACPI device handle.  Make acpiphp use two new functions,
acpiphp_dock_init() and acpiphp_dock_release(), that call
get_bridge() and put_bridge(), respectively, on the acpiphp bridge
holding the given device, for this purpose.

In addition to that, remove the dock station's list of
"hotplug devices" and make the dock code always walk the whole list
of "dependent devices" instead in such a way that the loops in
hotplug_dock_devices() and dock_event() (replacing the loops over
"hotplug devices") will take references to the list entries that
register_hotplug_dock_device() has been called for.  That prevents
the "release" routines associated with those entries from being
called while the given entry is being processed and for PCI
devices this means that their bridges won't be removed (by a
concurrent thread) while hotplug_event_func() handling them is
being executed.

This change is based on two earlier patches from Jiang Liu.

References: https://bugzilla.kernel.org/show_bug.cgi?id=59501
Reported-and-tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Tracked-down-by: Jiang Liu <jiang.liu@huawei.com>
Tested-by: Illya Klymov <xanf@xanf.me>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Cc: 3.9+ <stable@vger.kernel.org>
2013-06-24 11:22:53 +02:00
..
acpica ACPICA: ACPICA: Fix for _INI regression 2013-05-08 15:31:53 +02:00
apei Merge branch 'acpi-fixes' 2013-06-07 12:35:23 +02:00
ac.c ACPI / AC: Add sleep quirk for Thinkpad e530 2013-05-12 14:03:15 +02:00
acpi_i2c.c
acpi_ipmi.c
acpi_lpss.c ACPI / LPSS: Power up LPSS devices during enumeration 2013-06-20 00:49:06 +02:00
acpi_memhotplug.c
acpi_pad.c
acpi_platform.c
battery.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-05-01 17:51:54 -07:00
bgrt.c
blacklist.c
bus.c
button.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-05-01 17:51:54 -07:00
cm_sbs.c
container.c
custom_method.c
debugfs.c
device_pm.c ACPI / LPSS: Power up LPSS devices during enumeration 2013-06-20 00:49:06 +02:00
dock.c ACPI / dock / PCI: Synchronous handling of dock events for PCI devices 2013-06-24 11:22:53 +02:00
ec.c ACPI / EC: Restart transaction even when the IBF flag set 2013-05-12 14:03:15 +02:00
ec_sys.c
event.c
fan.c
glue.c
hed.c
internal.h ACPI / dock: Initialize ACPI dock subsystem upfront 2013-06-23 00:59:55 +02:00
Kconfig
Makefile Power management and ACPI fixes for 3.10-rc3 2013-05-25 20:32:00 -07:00
numa.c
nvs.c
osl.c
pci_irq.c
pci_link.c
pci_root.c PCI: acpiphp: Re-enumerate devices when host bridge receives Bus Check 2013-05-17 14:12:06 -06:00
pci_slot.c
power.c ACPI / PM: Fix error code path for power resources initialization 2013-06-20 00:47:55 +02:00
proc.c
processor_core.c
processor_driver.c ACPI / PM: Move processor suspend/resume to syscore_ops 2013-05-12 14:03:14 +02:00
processor_idle.c ACPI / PM: Move processor suspend/resume to syscore_ops 2013-05-12 14:03:14 +02:00
processor_perflib.c
processor_thermal.c
processor_throttling.c
reboot.c
resource.c ACPI / resources: call acpi_get_override_irq() only for legacy IRQ resources 2013-06-19 23:55:59 +02:00
sbs.c proc: Supply a function to remove a proc entry by PDE 2013-05-01 17:29:46 -04:00
sbshc.c
sbshc.h
scan.c ACPI / dock: Initialize ACPI dock subsystem upfront 2013-06-23 00:59:55 +02:00
sleep.c
sleep.h
sysfs.c
tables.c
thermal.c
utils.c
video.c ACPI / video: Do not bind to device objects with a scan handler 2013-06-10 13:00:29 +02:00
video_detect.c ACPI / video: Add "Asus UL30A" to ACPI video detect blacklist 2013-05-23 01:41:45 +02:00
wakeup.c