android_kernel_motorola_sm6225/drivers/gpio
Ming Lei 864533ceb6 Fix circular locking dependency (3.3-rc2)
Hi,

On Wed, Feb 8, 2012 at 8:41 PM, Felipe Balbi <balbi@ti.com> wrote:
> Hi guys,
>
> I have just triggered the folllowing:
>
> [   84.860321] ======================================================
> [   84.860321] [ INFO: possible circular locking dependency detected ]
> [   84.860321] 3.3.0-rc2-00026-ge4e8a39 #474 Not tainted
> [   84.860321] -------------------------------------------------------
> [   84.860321] bash/949 is trying to acquire lock:
> [   84.860321]  (sysfs_lock){+.+.+.}, at: [<c0275358>] gpio_value_store+0x24/0xcc
> [   84.860321]
> [   84.860321] but task is already holding lock:
> [   84.860321]  (s_active#22){++++.+}, at: [<c016996c>] sysfs_write_file+0xdc/0x184
> [   84.911468]
> [   84.911468] which lock already depends on the new lock.
> [   84.911468]
> [   84.920043]
> [   84.920043] the existing dependency chain (in reverse order) is:
> [   84.920043]
> [   84.927886] -> #1 (s_active#22){++++.+}:
> [   84.927886]        [<c008f640>] check_prevs_add+0xdc/0x150
> [   84.927886]        [<c008fc18>] validate_chain.clone.24+0x564/0x694
> [   84.927886]        [<c0090cdc>] __lock_acquire+0x49c/0x980
> [   84.951660]        [<c0091838>] lock_acquire+0x98/0x100
> [   84.951660]        [<c016a8e8>] sysfs_deactivate+0xb0/0x100
> [   84.962982]        [<c016b1b4>] sysfs_addrm_finish+0x2c/0x6c
> [   84.962982]        [<c016b8bc>] sysfs_remove_dir+0x84/0x98
> [   84.962982]        [<c02590d8>] kobject_del+0x10/0x78
> [   84.974670]        [<c02c29e8>] device_del+0x140/0x170
> [   84.974670]        [<c02c2a24>] device_unregister+0xc/0x18
> [   84.985382]        [<c0276894>] gpio_unexport+0xbc/0xdc
> [   84.985382]        [<c02768c8>] gpio_free+0x14/0xfc
> [   85.001708]        [<c0276a28>] unexport_store+0x78/0x8c
> [   85.001708]        [<c02c5af8>] class_attr_store+0x18/0x24
> [   85.007293]        [<c0169990>] sysfs_write_file+0x100/0x184
> [   85.018981]        [<c0109d48>] vfs_write+0xb4/0x148
> [   85.018981]        [<c0109fd0>] sys_write+0x40/0x70
> [   85.018981]        [<c0013cc0>] ret_fast_syscall+0x0/0x3c
> [   85.035003]
> [   85.035003] -> #0 (sysfs_lock){+.+.+.}:
> [   85.035003]        [<c008f54c>] check_prev_add+0x680/0x698
> [   85.035003]        [<c008f640>] check_prevs_add+0xdc/0x150
> [   85.052093]        [<c008fc18>] validate_chain.clone.24+0x564/0x694
> [   85.052093]        [<c0090cdc>] __lock_acquire+0x49c/0x980
> [   85.052093]        [<c0091838>] lock_acquire+0x98/0x100
> [   85.069885]        [<c047e280>] mutex_lock_nested+0x3c/0x2f4
> [   85.069885]        [<c0275358>] gpio_value_store+0x24/0xcc
> [   85.069885]        [<c02c18dc>] dev_attr_store+0x18/0x24
> [   85.087158]        [<c0169990>] sysfs_write_file+0x100/0x184
> [   85.087158]        [<c0109d48>] vfs_write+0xb4/0x148
> [   85.098297]        [<c0109fd0>] sys_write+0x40/0x70
> [   85.098297]        [<c0013cc0>] ret_fast_syscall+0x0/0x3c
> [   85.109069]
> [   85.109069] other info that might help us debug this:
> [   85.109069]
> [   85.117462]  Possible unsafe locking scenario:
> [   85.117462]
> [   85.117462]        CPU0                    CPU1
> [   85.128417]        ----                    ----
> [   85.128417]   lock(s_active#22);
> [   85.128417]                                lock(sysfs_lock);
> [   85.128417]                                lock(s_active#22);
> [   85.142486]   lock(sysfs_lock);
> [   85.151794]
> [   85.151794]  *** DEADLOCK ***
> [   85.151794]
> [   85.151794] 2 locks held by bash/949:
> [   85.158020]  #0:  (&buffer->mutex){+.+.+.}, at: [<c01698b8>] sysfs_write_file+0x28/0x184
> [   85.170349]  #1:  (s_active#22){++++.+}, at: [<c016996c>] sysfs_write_file+0xdc/0x184
> [   85.170349]
> [   85.178588] stack backtrace:
> [   85.178588] [<c001b824>] (unwind_backtrace+0x0/0xf0) from [<c008de64>] (print_circular_bug+0x100/0x114)
> [   85.193023] [<c008de64>] (print_circular_bug+0x100/0x114) from [<c008f54c>] (check_prev_add+0x680/0x698)
> [   85.193023] [<c008f54c>] (check_prev_add+0x680/0x698) from [<c008f640>] (check_prevs_add+0xdc/0x150)
> [   85.212524] [<c008f640>] (check_prevs_add+0xdc/0x150) from [<c008fc18>] (validate_chain.clone.24+0x564/0x694)
> [   85.212524] [<c008fc18>] (validate_chain.clone.24+0x564/0x694) from [<c0090cdc>] (__lock_acquire+0x49c/0x980)
> [   85.233306] [<c0090cdc>] (__lock_acquire+0x49c/0x980) from [<c0091838>] (lock_acquire+0x98/0x100)
> [   85.233306] [<c0091838>] (lock_acquire+0x98/0x100) from [<c047e280>] (mutex_lock_nested+0x3c/0x2f4)
> [   85.242614] [<c047e280>] (mutex_lock_nested+0x3c/0x2f4) from [<c0275358>] (gpio_value_store+0x24/0xcc)
> [   85.261840] [<c0275358>] (gpio_value_store+0x24/0xcc) from [<c02c18dc>] (dev_attr_store+0x18/0x24)
> [   85.261840] [<c02c18dc>] (dev_attr_store+0x18/0x24) from [<c0169990>] (sysfs_write_file+0x100/0x184)
> [   85.271240] [<c0169990>] (sysfs_write_file+0x100/0x184) from [<c0109d48>] (vfs_write+0xb4/0x148)
> [   85.290008] [<c0109d48>] (vfs_write+0xb4/0x148) from [<c0109fd0>] (sys_write+0x40/0x70)
> [   85.298400] [<c0109fd0>] (sys_write+0x40/0x70) from [<c0013cc0>] (ret_fast_syscall+0x0/0x3c)
> -bash: echo: write error: Operation not permitted
>
> the way to trigger is:
>
> root@legolas:~# cd /sys/class/gpio/
> root@legolas:/sys/class/gpio# echo 2 > export
> root@legolas:/sys/class/gpio# echo 2 > unexport
> root@legolas:/sys/class/gpio# echo 2 > export
> root@legolas:/sys/class/gpio# cd gpio2/
> root@legolas:/sys/class/gpio/gpio2# echo 1 > value

Looks 'sysfs_lock' needn't to be held for unregister, so the patch below may
fix the problem.

Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
2012-02-15 13:06:07 -07:00
..
devres.c GPIO: add bindings for managed devices 2012-01-04 11:37:42 -07:00
gpio-74x164.c drivers/gpio: Fix drivers who are implicit users of module.h 2011-10-31 19:31:47 -04:00
gpio-ab8500.c gpio: ab8500: fix MODULE_ALIAS for ab8500 2011-07-28 16:19:23 -06:00
gpio-adp5520.c gpio: Convert GPIO drivers to module_platform_driver 2012-01-02 00:26:06 -07:00
gpio-adp5588.c gpiolib: output basic details and consolidate gpio device drivers 2011-12-12 13:40:16 -07:00
gpio-bt8xx.c gpiolib: output basic details and consolidate gpio device drivers 2011-12-12 13:40:16 -07:00
gpio-cs5535.c gpio: Convert GPIO drivers to module_platform_driver 2012-01-02 00:26:06 -07:00
gpio-da9052.c Changes queued in gpio/next for the start of the 3.3 merge window 2012-01-07 12:15:36 -08:00
gpio-davinci.c ARM: 7074/1: gpio: davinci: eliminate unused variable warnings 2011-09-05 11:26:34 +01:00
gpio-ep93xx.c drivers/gpio: Fix drivers who are implicit users of module.h 2011-10-31 19:31:47 -04:00
gpio-generic.c gpio: Convert GPIO drivers to module_platform_driver 2012-01-02 00:26:06 -07:00
gpio-it8761e.c gpio: reorganize drivers 2011-06-06 10:10:11 -06:00
gpio-janz-ttl.c gpio: Convert GPIO drivers to module_platform_driver 2012-01-02 00:26:06 -07:00
gpio-ks8695.c ARM: 7036/1: mach-ks8695: break out GPIO driver specifics 2011-08-22 09:12:54 +01:00
gpio-langwell.c gpio: langwell: ensure alternate function is cleared 2011-10-06 04:14:52 -06:00
gpio-lpc32xx.c ARM: 7045/1: mach-lpc32xx: break out GPIO driver specifics 2011-08-22 09:13:21 +01:00
gpio-max730x.c gpio: reorganize drivers 2011-06-06 10:10:11 -06:00
gpio-max732x.c gpio: reorganize drivers 2011-06-06 10:10:11 -06:00
gpio-max7300.c gpio: reorganize drivers 2011-06-06 10:10:11 -06:00
gpio-max7301.c gpio: reorganize drivers 2011-06-06 10:10:11 -06:00
gpio-mc9s08dz60.c ARM/mx35/3ds: gpio: add mc9s08dz60 gpio function 2012-01-30 07:49:08 -07:00
gpio-mc33880.c drivers/gpio: Fix drivers who are implicit users of module.h 2011-10-31 19:31:47 -04:00
gpio-mcp23s08.c drivers/gpio: Fix drivers who are implicit users of module.h 2011-10-31 19:31:47 -04:00
gpio-ml-ioh.c gpio-ml-ioh: cleanup __iomem annotation usage 2012-01-16 09:12:24 -07:00
gpio-mpc8xxx.c gpio: mpc8xxx: don't allow input-only pins to be output for MPC5121 2011-12-13 11:14:35 -07:00
gpio-mpc5200.c drivers/gpio: Fix drivers who are implicit users of module.h 2011-10-31 19:31:47 -04:00
gpio-msm-v1.c gpio_msm: Move Qualcomm v6 MSM driver into drivers 2011-08-01 04:58:00 -07:00
gpio-msm-v2.c gpio_msm: Move Qualcomm MSM v2 gpio driver into drivers 2011-08-01 04:58:00 -07:00
gpio-mxc.c Merge branch 'modsplit-Oct31_2011' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux 2011-11-06 19:44:47 -08:00
gpio-mxs.c Merge branch 'modsplit-Oct31_2011' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux 2011-11-06 19:44:47 -08:00
gpio-nomadik.c gpiolib: output basic details and consolidate gpio device drivers 2011-12-12 13:40:16 -07:00
gpio-omap.c Merge branch 'gpio/merge' of git://git.secretlab.ca/git/linux-2.6 2011-11-15 14:45:50 -02:00
gpio-pca953x.c gpio: pca953x: Staticise pca953x_get_altdata() 2011-11-21 20:53:15 +01:00
gpio-pcf857x.c gpiolib: output basic details and consolidate gpio device drivers 2011-12-12 13:40:16 -07:00
gpio-pch.c gpio-pch: cleanup __iomem annotation usage 2012-01-16 09:12:24 -07:00
gpio-pl061.c 2nd round of GPIO changes for v3.3 merge window 2012-01-14 13:25:23 -08:00
gpio-pxa.c ARM: pxa: add clk support in gpio driver 2011-11-15 19:09:36 +08:00
gpio-rdc321x.c gpio: Convert GPIO drivers to module_platform_driver 2012-01-02 00:26:06 -07:00
gpio-sa1100.c GPIO: sa1100: implement proper gpiolib gpio_to_irq conversion 2012-01-13 22:25:23 -07:00
gpio-samsung.c Device tree conversions for samsung and tegra 2012-01-09 14:28:38 -08:00
gpio-sch.c gpio: Convert GPIO drivers to module_platform_driver 2012-01-02 00:26:06 -07:00
gpio-sodaville.c gpio: Add a driver for Sodaville GPIO controller 2012-02-03 16:13:25 -07:00
gpio-stmpe.c gpio: Add support for stmpe variant 801 2012-01-09 00:37:44 +01:00
gpio-sx150x.c gpio: reorganize drivers 2011-06-06 10:10:11 -06:00
gpio-tc3589x.c gpio: reorganize drivers 2011-06-06 10:10:11 -06:00
gpio-tegra.c drivers/gpio/gpio-tegra.c: use devm_request_and_ioremap 2012-01-02 01:43:50 -07:00
gpio-timberdale.c gpio: Convert GPIO drivers to module_platform_driver 2012-01-02 00:26:06 -07:00
gpio-tnetv107x.c ARM: 7039/1: mach-davinci: move DaVinci TNET GPIO driver to GPIO subsystem 2011-08-22 09:12:55 +01:00
gpio-tps65910.c gpio: tps65910: Add sleep control support 2012-02-05 23:08:29 -07:00
gpio-tps65912.c tps65912: gpio: add gpio driver 2011-07-31 23:28:22 +02:00
gpio-twl4030.c gpio: reorganize drivers 2011-06-06 10:10:11 -06:00
gpio-ucb1400.c gpio: Convert GPIO drivers to module_platform_driver 2012-01-02 00:26:06 -07:00
gpio-vr41xx.c gpio: Convert GPIO drivers to module_platform_driver 2012-01-02 00:26:06 -07:00
gpio-vx855.c gpio: Convert GPIO drivers to module_platform_driver 2012-01-02 00:26:06 -07:00
gpio-wm831x.c Merge branch 'gpio/next' of git://git.secretlab.ca/git/linux-2.6 2011-07-22 14:50:57 -07:00
gpio-wm8350.c gpio: reorganize drivers 2011-06-06 10:10:11 -06:00
gpio-wm8994.c gpio: Add decode of WM8994 GPIO configuration 2012-01-02 00:27:01 -07:00
gpio-xilinx.c gpiolib: output basic details and consolidate gpio device drivers 2011-12-12 13:40:16 -07:00
gpiolib.c Fix circular locking dependency (3.3-rc2) 2012-02-15 13:06:07 -07:00
Kconfig gpio: Add a driver for Sodaville GPIO controller 2012-02-03 16:13:25 -07:00
Makefile gpio: Add a driver for Sodaville GPIO controller 2012-02-03 16:13:25 -07:00