android_kernel_motorola_sm6225/drivers/acpi
Lv Zheng a1a69b297e ACPI / IPMI: Fix race caused by the unprotected ACPI IPMI user
This patch uses reference counting to fix the race caused by the
unprotected ACPI IPMI user.

There are two rules for using the ipmi_si APIs:
 1. In ipmi_si, ipmi_destroy_user() can ensure that no ipmi_recv_msg will
    be passed to ipmi_msg_handler(), but ipmi_request_settime() can not
    use an invalid ipmi_user_t.  This means the ipmi_si users must ensure
    that there won't be any local references on ipmi_user_t before invoking
    ipmi_destroy_user().
 2. In ipmi_si, the smi_gone()/new_smi() callbacks are protected by
    smi_watchers_mutex, so their execution is serialized.  But as a
    new smi can re-use a freed intf_num, it requires that the callback
    implementation must not use intf_num as an identification mean or it
    must ensure all references to the previous smi are all dropped before
    exiting smi_gone() callback.

As the acpi_ipmi_device->user_interface check in acpi_ipmi_space_handler()
can happen before setting user_interface to NULL and codes after the check
in acpi_ipmi_space_handler() can happen after user_interface becomes NULL,
the on-going acpi_ipmi_space_handler() still can pass an invalid
acpi_ipmi_device->user_interface to ipmi_request_settime().  Such race
conditions are not allowed by the IPMI layer's API design as a crash will
happen in ipmi_request_settime() if something like that happens.

This patch follows the ipmi_devintf.c design:
 1. Invoke ipmi_destroy_user() after the reference count of
    acpi_ipmi_device drops to 0.  References of acpi_ipmi_device dropping
    to 0 also means tx_msg related to this acpi_ipmi_device are all freed.
    This matches the IPMI layer's API calling rule on ipmi_destroy_user()
    and ipmi_request_settime().
 2. ipmi_flush_tx_msg() is performed so that no on-going tx_msg can still be
    running in acpi_ipmi_space_handler().  And it is invoked after invoking
    __ipmi_dev_kill() where acpi_ipmi_device is deleted from the list with a
    "dead" flag set, and the "dead" flag check is also introduced to the
    point where a tx_msg is going to be added to the tx_msg_list so that no
    new tx_msg can be created after returning from the __ipmi_dev_kill().
 3. The waiting codes in ipmi_flush_tx_msg() is deleted because it is not
    required since this patch ensures no acpi_ipmi reference is still held
    for ipmi_user_t before calling ipmi_destroy_user() and
    ipmi_destroy_user() can ensure no more ipmi_msg_handler() can happen
    after returning from ipmi_destroy_user().
 4. The flushing of tx_msg is also moved out of ipmi_lock in this patch.

The forthcoming IPMI operation region handler installation changes also
requires acpi_ipmi_device be handled in this style.

The header comment of the file is also updated due to this design change.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Reviewed-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-09-30 19:46:12 +02:00
..
acpica ACPICA: Fix for a Store->ArgX when ArgX contains a reference to a field. 2013-09-06 15:39:59 +02:00
apei Merge branch 'x86-ras-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2013-09-04 11:07:04 -07:00
ac.c ACPI: Remove the old /proc/acpi/event interface 2013-07-15 13:56:36 +02:00
acpi_cmos_rtc.c ACPI: Add CMOS RTC Operation Region handler support 2013-06-27 21:35:37 +02:00
acpi_ipmi.c ACPI / IPMI: Fix race caused by the unprotected ACPI IPMI user 2013-09-30 19:46:12 +02:00
acpi_lpss.c ACPI / LPSS: don't crash if a device has no MMIO resources 2013-09-02 12:59:40 +02:00
acpi_memhotplug.c ACPI / memhotplug: Fix a stale pointer in error path 2013-07-15 01:26:18 +02:00
acpi_pad.c PTR_RET() is a weird name, and led to some confusing usage. We ended 2013-09-04 17:31:11 -07:00
acpi_platform.c ACPI / scan: Drop unnecessary label from acpi_create_platform_device() 2013-08-07 01:11:33 +02:00
acpi_processor.c ACPI / processor: Acquire writer lock to update CPU maps 2013-08-13 12:20:16 +02:00
battery.c Merge branch 'acpi-assorted' 2013-08-27 01:29:04 +02:00
bgrt.c acpi: bgrt: fix build error due to attribute change 2013-08-22 08:34:39 -07:00
blacklist.c ACPI: blacklist win8 OSI for buggy laptops 2013-08-25 21:31:12 +02:00
bus.c Merge branch 'acpi-assorted' 2013-08-27 01:29:04 +02:00
button.c ACPI: Remove the old /proc/acpi/event interface 2013-07-15 13:56:36 +02:00
cm_sbs.c
container.c Merge branch 'acpi-assorted' 2013-04-28 01:54:08 +02:00
custom_method.c The sweeping change is to make add_taint() explicitly indicate whether to disable 2013-02-25 15:41:43 -08:00
debugfs.c acpi: add export.h to files using THIS_MODULE/EXPORT_SYMBOL 2011-10-31 19:30:34 -04:00
device_pm.c ACPI / PM: Add state information to error message in acpi_device_set_power() 2013-08-03 21:13:22 +02:00
dock.c Merge branch 'acpi-assorted' 2013-08-27 01:29:04 +02:00
ec.c Merge branch 'acpi-assorted' 2013-08-30 14:13:50 +02:00
ec_sys.c ACPI / EC: access user space with get_user()/put_user() 2013-06-19 23:29:20 +02:00
event.c ACPI: Remove the old /proc/acpi/event interface 2013-07-15 13:56:36 +02:00
fan.c ACPI / PM: Use ACPI_STATE_D3_COLD instead of ACPI_STATE_D3 everywhere 2013-07-30 14:36:20 +02:00
glue.c ACPI / bind: Prefer device objects with _STA to those without it 2013-09-09 23:07:47 +02:00
hed.c ACPI: Remove useless type argument of driver .remove() operation 2013-01-26 00:37:24 +01:00
internal.h Merge back earlier 'acpi-assorted' material 2013-08-14 23:22:45 +02:00
Kconfig Merge branch 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux 2013-09-05 09:31:03 -07:00
Makefile i2c: move ACPI helpers into the core 2013-08-23 10:22:29 +02:00
numa.c ACPI / numa: Fix __init attribute location in slit_valid() 2013-08-13 12:35:42 +02:00
nvs.c ACPI / PM: print physical addresses consistently with other parts of kernel 2012-03-30 02:46:57 -04:00
osl.c Merge branch 'acpi-assorted' 2013-08-27 01:29:04 +02:00
pci_irq.c PCI/ACPI: Don't cache _PRT, and don't associate them with bus numbers 2013-02-16 11:58:34 -07:00
pci_link.c ACPI: Set length even for TYPE_END_TAG acpi resource 2013-03-24 01:00:38 +01:00
pci_root.c Merge branch 'pci/misc' into next 2013-08-29 17:23:33 -06:00
pci_slot.c ACPI / PCI: Make bus registration and unregistration symmetric 2013-07-23 03:58:42 +02:00
power.c Merge branch 'acpi-pm' 2013-08-27 01:28:17 +02:00
proc.c ACPI / PM: Walk physical_node_list under physical_node_lock 2013-08-06 02:26:22 +02:00
processor_core.c Merge back earlier 'acpi-assorted' material 2013-08-14 23:22:45 +02:00
processor_driver.c Merge branch 'acpi-processor' 2013-08-27 01:29:24 +02:00
processor_idle.c acpi: delete __cpuinit usage from all acpi files 2013-07-14 19:36:58 -04:00
processor_perflib.c ACPI: introduce helper function acpi_has_method() 2013-07-15 01:33:10 +02:00
processor_thermal.c ACPI / processor: Remove acpi_processor_get_limit_info() 2013-08-13 12:11:22 +02:00
processor_throttling.c ACPI: suppress compiler warnings in processor_throttling.c 2013-03-25 00:05:48 +01:00
reboot.c Revert "ACPI: ignore FADT reset-reg-sup flag" 2012-04-20 11:19:35 -07:00
resource.c ACPI: introduce helper function acpi_has_method() 2013-07-15 01:33:10 +02:00
sbs.c ACPI: Remove the old /proc/acpi/event interface 2013-07-15 13:56:36 +02:00
sbshc.c ACPI: Remove useless type argument of driver .remove() operation 2013-01-26 00:37:24 +01:00
sbshc.h
scan.c ACPI / scan: fix typo in comments of acpi_bus_unregister_driver() 2013-09-25 19:46:48 +02:00
sleep.c Merge branch 'acpi-assorted' 2013-08-27 01:29:04 +02:00
sleep.h ACPI: Drop power resources driver 2013-01-17 14:11:06 +01:00
sysfs.c Merge branch 'akpm' (updates from Andrew Morton) 2013-07-03 17:12:13 -07:00
tables.c ACPICA: Cleanup table handler naming conflicts. 2013-01-11 13:10:16 +01:00
thermal.c Merge branch 'acpi-assorted' 2013-08-30 14:13:50 +02:00
utils.c ACPI: introduce two helper functions for _EJ0 and _LCK 2013-07-15 01:33:10 +02:00
video.c Merge branch 'acpi-video' 2013-08-27 01:40:40 +02:00
video_detect.c Merge branch 'acpi-cleanup' 2013-08-27 01:25:28 +02:00
wakeup.c ACPI / Wakeup: Enable button GPEs unconditionally during initialization 2011-02-12 01:39:53 +01:00