kernel-ark/drivers/base
Yijing Wang e4a60d1390 sysfs: driver core: Fix glue dir race condition by gdp_mutex
There is a race condition when removing glue directory.
It can be reproduced in following test:

path 1: Add first child device
device_add()
    get_device_parent()
            /*find parent from glue_dirs.list*/
            list_for_each_entry(k, &dev->class->p->glue_dirs.list, entry)
                    if (k->parent == parent_kobj) {
                            kobj = kobject_get(k);
                            break;
                    }
            ....
            class_dir_create_and_add()

path2: Remove last child device under glue dir
device_del()
    cleanup_device_parent()
            cleanup_glue_dir()
                    kobject_put(glue_dir);

If path2 has been called cleanup_glue_dir(), but not
call kobject_put(glue_dir), the glue dir is still
in parent's kset list. Meanwhile, path1 find the glue
dir from the glue_dirs.list. Path2 may release glue dir
before path1 call kobject_get(). So kernel will report
the warning and bug_on.

This is a "classic" problem we have of a kref in a list
that can be found while the last instance could be removed
at the same time.

This patch reuse gdp_mutex to fix this race condition.

The following calltrace is captured in kernel 3.4, but
the latest kernel still has this bug.

-----------------------------------------------------
<4>[ 3965.441471] WARNING: at ...include/linux/kref.h:41 kobject_get+0x33/0x40()
<4>[ 3965.441474] Hardware name: Romley
<4>[ 3965.441475] Modules linked in: isd_iop(O) isd_xda(O)...
...
<4>[ 3965.441605] Call Trace:
<4>[ 3965.441611]  [<ffffffff8103717a>] warn_slowpath_common+0x7a/0xb0
<4>[ 3965.441615]  [<ffffffff810371c5>] warn_slowpath_null+0x15/0x20
<4>[ 3965.441618]  [<ffffffff81215963>] kobject_get+0x33/0x40
<4>[ 3965.441624]  [<ffffffff812d1e45>] get_device_parent.isra.11+0x135/0x1f0
<4>[ 3965.441627]  [<ffffffff812d22d4>] device_add+0xd4/0x6d0
<4>[ 3965.441631]  [<ffffffff812d0dbc>] ? dev_set_name+0x3c/0x40
....
<2>[ 3965.441912] kernel BUG at ..../fs/sysfs/group.c:65!
<4>[ 3965.441915] invalid opcode: 0000 [#1] SMP
...
<4>[ 3965.686743]  [<ffffffff811a677e>] sysfs_create_group+0xe/0x10
<4>[ 3965.686748]  [<ffffffff810cfb04>] blk_trace_init_sysfs+0x14/0x20
<4>[ 3965.686753]  [<ffffffff811fcabb>] blk_register_queue+0x3b/0x120
<4>[ 3965.686756]  [<ffffffff812030bc>] add_disk+0x1cc/0x490
....
-------------------------------------------------------

Signed-off-by: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: Weng Meiling <wengmeiling.weng@huawei.com>
Cc: <stable@vger.kernel.org> #3.4+
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-11-07 08:17:43 -08:00
..
power PM / Sleep: fix async suspend_late/freeze_late error handling 2014-10-27 18:42:26 +01:00
regmap Merge remote-tracking branch 'regmap/topic/cache' into regmap-next 2014-09-29 20:49:42 +01:00
attribute_container.c attribute_container: fix coding style issues 2014-09-23 22:55:15 -07:00
base.h driver core: Move driver_data back to struct device 2014-05-27 12:37:18 -07:00
bus.c Merge branch 'master' into for-next 2014-02-20 14:54:28 +01:00
class.c sysfs: make attr namespace interface less convoluted 2013-09-26 14:50:01 -07:00
component.c component: fix bug with legacy API 2014-07-04 18:05:05 +01:00
container.c ACPI / hotplug / driver core: Handle containers in a special way 2013-12-29 15:25:48 +01:00
core.c sysfs: driver core: Fix glue dir race condition by gdp_mutex 2014-11-07 08:17:43 -08:00
cpu.c x86: align x86 arch with generic CPU modalias handling 2014-02-18 12:45:38 -08:00
dd.c driver core: Remove kerneldoc from local function 2014-09-23 23:10:11 -07:00
devcoredump.c device coredump: add new device coredump class 2014-09-23 22:53:15 -07:00
devres.c devres: Improve devm_kasprintf()/kvasprintf() support 2014-09-23 23:32:50 -07:00
devtmpfs.c devtmpfs: Calling delete_path() only when necessary 2013-12-19 10:10:32 -08:00
dma-coherent.c drivers: dma-coherent: add initialization from device tree 2014-10-14 02:18:12 +02:00
dma-contiguous.c drivers: of: add return value to of_reserved_mem_device_init() 2014-10-29 16:33:14 -07:00
dma-mapping.c common: dma-mapping: introduce common remapping functions 2014-10-09 22:25:52 -04:00
driver.c driver core: add #include <linux/sysfs.h> to core files. 2013-08-27 10:24:15 -07:00
firmware_class.c firmware_class: make sure fw requests contain a name 2014-09-23 23:26:58 -07:00
firmware.c
hypervisor.c
init.c ACPI / hotplug / driver core: Handle containers in a special way 2013-12-29 15:25:48 +01:00
isa.c
Kconfig CMA: document cma=0 2014-10-09 22:26:02 -04:00
Makefile device coredump: add new device coredump class 2014-09-23 22:53:15 -07:00
map.c
memory.c memory-hotplug: add sysfs valid_zones attribute 2014-10-09 22:25:52 -04:00
module.c
node.c mm: remove noisy remainder of the scan_unevictable interface 2014-10-09 22:25:55 -04:00
pinctrl.c drivers: pinctrl sleep and idle states in the core 2013-06-16 11:56:52 +02:00
platform.c PM / Domains: Move dev_pm_domain_attach|detach() to pm_domain.h 2014-09-30 01:16:44 +02:00
soc.c mode_t whack-a-mole: ->is_visible() returns umode_t... 2012-05-29 23:28:42 -04:00
syscore.c genirq: Simplify wakeup mechanism 2014-09-01 13:48:59 +02:00
topology.c topology: Fix compilation warning when not in SMP 2014-04-16 14:13:26 -07:00
transport_class.c