linux/drivers/acpi
Sergey Senozhatsky 69d94ec6d8 Battery: sysfs_remove_battery(): possible circular locking
Commit 9c921c22a7
Author: Lan Tianyu <tianyu.lan@intel.com>

    ACPI / Battery: Resolve the race condition in the sysfs_remove_battery()

fixed BUG https://bugzilla.kernel.org/show_bug.cgi?id=35642 , but as a side
effect made lockdep unhappy with sysfs_remove_battery():

[14818.477168]
[14818.477170] =======================================================
[14818.477200] [ INFO: possible circular locking dependency detected ]
[14818.477221] 3.1.0-dbg-07865-g1280ea8-dirty #668
[14818.477236] -------------------------------------------------------
[14818.477257] s2ram/1599 is trying to acquire lock:
[14818.477276]  (s_active#8){++++.+}, at: [<ffffffff81169147>] sysfs_addrm_finish+0x31/0x5a
[14818.477323]
[14818.477325] but task is already holding lock:
[14818.477350]  (&battery->lock){+.+.+.}, at: [<ffffffffa0047278>] sysfs_remove_battery+0x10/0x4b [battery]
[14818.477395]
[14818.477397] which lock already depends on the new lock.
[14818.477399]
[..]
[14818.479121] stack backtrace:
[14818.479148] Pid: 1599, comm: s2ram Not tainted 3.1.0-dbg-07865-g1280ea8-dirty #668
[14818.479175] Call Trace:
[14818.479198]  [<ffffffff814828c3>] print_circular_bug+0x293/0x2a4
[14818.479228]  [<ffffffff81070cb5>] __lock_acquire+0xfe4/0x164b
[14818.479260]  [<ffffffff81169147>] ? sysfs_addrm_finish+0x31/0x5a
[14818.479288]  [<ffffffff810718d2>] lock_acquire+0x138/0x1ac
[14818.479316]  [<ffffffff81169147>] ? sysfs_addrm_finish+0x31/0x5a
[14818.479345]  [<ffffffff81168a79>] sysfs_deactivate+0x9b/0xec
[14818.479373]  [<ffffffff81169147>] ? sysfs_addrm_finish+0x31/0x5a
[14818.479405]  [<ffffffff81169147>] sysfs_addrm_finish+0x31/0x5a
[14818.479433]  [<ffffffff81167bc5>] sysfs_hash_and_remove+0x54/0x77
[14818.479461]  [<ffffffff811681b9>] sysfs_remove_file+0x12/0x14
[14818.479488]  [<ffffffff81385bf8>] device_remove_file+0x12/0x14
[14818.479516]  [<ffffffff81386504>] device_del+0x119/0x17c
[14818.479542]  [<ffffffff81386575>] device_unregister+0xe/0x1a
[14818.479570]  [<ffffffff813c6ef9>] power_supply_unregister+0x23/0x27
[14818.479601]  [<ffffffffa004729c>] sysfs_remove_battery+0x34/0x4b [battery]
[14818.479632]  [<ffffffffa004778f>] battery_notify+0x2c/0x3a [battery]
[14818.479662]  [<ffffffff8148fe82>] notifier_call_chain+0x74/0xa1
[14818.479692]  [<ffffffff810624b4>] __blocking_notifier_call_chain+0x6c/0x89
[14818.479722]  [<ffffffff810624e0>] blocking_notifier_call_chain+0xf/0x11
[14818.479751]  [<ffffffff8107e40e>] pm_notifier_call_chain+0x15/0x27
[14818.479770]  [<ffffffff8107ee1a>] enter_state+0xa7/0xd5
[14818.479782]  [<ffffffff8107e341>] state_store+0xaa/0xc0
[14818.479795]  [<ffffffff8107e297>] ? pm_async_store+0x45/0x45
[14818.479807]  [<ffffffff81248837>] kobj_attr_store+0x17/0x19
[14818.479820]  [<ffffffff81167e27>] sysfs_write_file+0x103/0x13f
[14818.479834]  [<ffffffff81109037>] vfs_write+0xad/0x13d
[14818.479847]  [<ffffffff811092b2>] sys_write+0x45/0x6c
[14818.479860]  [<ffffffff81492f92>] system_call_fastpath+0x16/0x1b

This patch introduces separate lock to struct acpi_battery to
grab in sysfs_remove_battery() instead of battery->lock.
So fix by Lan Tianyu is still there, we just grab independent lock.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Tested-by: Lan Tianyu <tianyu.lan@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
2011-08-05 22:15:18 -04:00
..
acpica Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6 2011-05-29 11:19:16 -07:00
apei x86: remove 32-bit versions of readq()/writeq() 2011-05-25 08:39:44 -07:00
ac.c Merge branch 'procfs-cleanup' into release 2011-01-12 05:00:07 -05:00
acpi_ipmi.c IPMI/ACPI: Add the IPMI opregion driver to enable ACPI to access BMC controller 2010-12-14 00:22:14 -05:00
acpi_memhotplug.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
acpi_pad.c ACPI: minor printk format change in acpi_pad 2011-03-23 01:36:45 -04:00
atomicio.c x86: remove 32-bit versions of readq()/writeq() 2011-05-25 08:39:44 -07:00
battery.c Battery: sysfs_remove_battery(): possible circular locking 2011-08-05 22:15:18 -04:00
blacklist.c Merge branch 'msi-dmi' into release 2010-10-08 22:37:46 -04:00
bus.c ACPI: Add D3 cold state 2011-05-29 02:21:08 -04:00
button.c ACPI button: remove unused procfs I/F 2011-03-22 23:20:35 -04:00
cm_sbs.c ACPI: Move definition of PREFIX from acpi_bus.h to internal..h 2009-08-28 19:57:27 -04:00
container.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
custom_method.c ACPI: Split out custom_method functionality into an own driver 2011-05-29 01:50:40 -04:00
debugfs.c ACPI: Split out custom_method functionality into an own driver 2011-05-29 01:50:40 -04:00
dock.c ACPICA: Rename some function and variable names 2011-01-12 04:24:40 -05:00
ec_sys.c ACPI: Remove the unused EC sysdev class 2011-03-18 18:22:20 -04:00
ec.c Merge branch 'ec-cleanup' into release 2011-05-29 04:40:39 -04:00
event.c llseek: automatically add .llseek fop 2010-10-15 15:53:27 +02:00
fan.c ACPI / Fan: Rework the handling of power resources 2011-01-12 04:48:45 -05:00
glue.c ACPI / PM: Drop special ACPI wakeup flags 2011-01-07 01:18:00 -05:00
hed.c ACPI Hardware Error Device (PNP0C33) support 2010-05-19 22:40:24 -04:00
internal.h ACPI: Cleanup custom_method debug stuff 2011-05-29 01:50:04 -04:00
Kconfig Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6 2011-05-29 11:19:16 -07:00
Makefile Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6 2011-05-29 11:19:16 -07:00
numa.c x86-64, NUMA: Unify {acpi|amd}_{numa_init|scan_nodes}() arguments and return values 2011-02-16 12:13:06 +01:00
nvs.c ACPI / PM: Use existing ACPI iomaps for NVS save/restore (v2) 2011-02-24 19:58:42 +01:00
osl.c Merge branches 'acpica', 'aml-custom', 'bugzilla-16548', 'bugzilla-20242', 'd3-cold', 'ec-asus' and 'thermal-fix' into release 2011-05-29 04:38:48 -04:00
pci_bind.c PCI / ACPI / PM: Platform support for PCI PME wake-up 2010-02-22 16:21:02 -08:00
pci_irq.c ACPI: remove unused declaration of proc_fs.h 2010-10-15 22:03:36 -04:00
pci_link.c ACPI: Use syscore_ops instead of sysdev class and sysdev 2011-03-18 18:22:21 -04:00
pci_root.c PCI/ACPI: Report _OSC control mask returned on failure to get control 2011-05-10 15:43:37 -07:00
pci_slot.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
power.c ACPI / PM: Check status of power resources under mutexes 2011-01-12 05:05:39 -05:00
proc.c ACPI / PM: Use device wakeup flags for handling ACPI wakeup devices 2011-01-07 01:17:41 -05:00
processor_core.c ACPI: processor: fix processor_physically_present in UP kernel 2011-05-29 02:17:56 -04:00
processor_driver.c ACPI: use __init where possible in processor driver 2011-03-02 20:56:53 -05:00
processor_idle.c x86 idle: clarify AMD erratum 400 workaround 2011-05-29 03:38:57 -04:00
processor_perflib.c [CPUFREQ] use dynamic debug instead of custom infrastructure 2011-05-04 11:50:57 -04:00
processor_thermal.c ACPI thermal: remove two unused functions 2010-12-11 02:01:47 -05:00
processor_throttling.c Merge branch 'x86/urgent' into x86-mm 2011-05-02 14:16:47 +02:00
reboot.c ACPI: Make sure the FADT is at least rev 2 before using the reset register 2011-03-22 23:52:49 -04:00
sbs.c ACPI: delete CONFIG_ACPI_PROCFS_POWER and power procfs I/F in 2.6.39 2011-01-12 00:36:17 -05:00
sbshc.c sbshc: acpi_device_class "smbus_host_controller" too long 2010-05-06 02:38:25 -04:00
sbshc.h
scan.c ACPI / PM: Avoid infinite recurrence while registering power resources 2011-04-26 11:33:18 +02:00
sleep.c Merge branch 'linus' into release 2011-03-23 02:34:54 -04:00
sleep.h ACPI: static sleep_states[] and acpi_gts_bfs_check 2010-10-19 13:44:37 -04:00
sysfs.c ACPI: Cleanup custom_method debug stuff 2011-05-29 01:50:04 -04:00
tables.c ACPI: delete the "acpi=ht" boot option 2010-03-14 20:58:38 -04:00
thermal.c ACPI / Fan: Rework the handling of power resources 2011-01-12 04:48:45 -05:00
utils.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
video_detect.c ACPI / Video: Probe for output switch method when searching video devices. 2011-02-12 01:40:16 +01:00
video.c treewide: fix a few typos in comments 2011-05-10 10:16:21 +02:00
wakeup.c ACPI / Wakeup: Enable button GPEs unconditionally during initialization 2011-02-12 01:39:53 +01:00