lockdep reports a possible circular locking in the following use case:

1) setup a loop device backed by a partition on a mass storage device

2) mount loop device

3) read from the loop device

4) unplug the mass storage device while reading (i know this is nasty,
but users do this kind of stuff ...)


[42950404.410000] usb 1-3: USB disconnect, address 3
[42950404.460000] sd 1:0:0:0: [sdb] Result: hostbyte=DID_NO_CONNECT
driverbyte=DRIVER_OK,SUGGEST_OK
[42950404.470000] end_request: I/O error, dev sdb, sector 181704
[42950404.470000] Buffer I/O error on device sdb1, logical block 22709
[42950404.480000] Buffer I/O error on device sdb1, logical block 22710
[42950404.480000] Buffer I/O error on device sdb1, logical block 22711
[42950404.490000] Buffer I/O error on device sdb1, logical block 22712
[42950404.500000] Buffer I/O error on device sdb1, logical block 22717
[42950404.500000] Buffer I/O error on device sdb1, logical block 22718
[42950404.500000] Buffer I/O error on device sdb1, logical block 22719
[42950404.500000] Buffer I/O error on device sdb1, logical block 22720
[42950404.500000] Buffer I/O error on device sdb1, logical block 22721
[42950404.500000] Buffer I/O error on device sdb1, logical block 22722
[42950404.540000] watchdog: executing timer ...
[42950404.540000] sd 1:0:0:0: [sdb] Result: hostbyte=DID_NO_CONNECT
driverbyte=DRIVER_OK,SUGGEST_OK
[42950404.550000] end_request: I/O error, dev sdb, sector 181736
[42950405.250000]
[42950405.250000] ================================================== =====
[42950405.250000] [ INFO: possible circular locking dependency detected ]
[42950405.250000] 2.6.26.3 #20
[42950405.250000] -------------------------------------------------------
[42950405.250000] exe/7044 is trying to acquire lock:
[42950405.250000] (&bdev->bd_mutex){--..}, at: []
__blkdev_put+0x28/0x158
[42950405.250000]
[42950405.250000] but task is already holding lock:
[42950405.250000] (&lo->lo_ctl_mutex){--..}, at: []
lo_ioctl+0x3c/0x8c0
[42950405.250000]
[42950405.250000] which lock already depends on the new lock.
[42950405.250000]
[42950405.250000]
[42950405.250000] the existing dependency chain (in reverse order) is:
[42950405.250000]
[42950405.250000] -> #1 (&lo->lo_ctl_mutex){--..}:
[42950405.250000] [] lock_acquire+0x8c/0xa8
[42950405.250000] [] mutex_lock_nested+0xa8/0x2b0
[42950405.250000] [] lo_open+0x28/0x44
[42950405.250000] [] do_open+0x98/0x2e8
[42950405.250000] [] blkdev_open+0x38/0x78
[42950405.250000] [] __dentry_open+0x10c/0x2b0
[42950405.250000] [] nameidata_to_filp+0x44/0x50
[42950405.250000] [] do_filp_open+0x1cc/0x774
[42950405.250000] [] do_sys_open+0x58/0xe4
[42950405.250000] [] sys_open+0x24/0x28
[42950405.250000] [] ret_fast_syscall+0x0/0x2c
[42950405.250000]
[42950405.250000] -> #0 (&bdev->bd_mutex){--..}:
[42950405.250000] [] lock_acquire+0x8c/0xa8
[42950405.250000] [] mutex_lock_nested+0xa8/0x2b0
[42950405.250000] [] __blkdev_put+0x28/0x158
[42950405.250000] [] blkdev_put+0x14/0x18
[42950405.250000] [] blkdev_close+0x30/0x44
[42950405.250000] [] __fput+0xbc/0x1b4
[42950405.250000] [] fput+0x34/0x38
[42950405.250000] [] loop_clr_fd+0x120/0x15c
[42950405.250000] [] lo_ioctl+0x218/0x8c0
[42950405.250000] [] blkdev_driver_ioctl+0x80/0x8c
[42950405.250000] [] blkdev_ioctl+0x258/0x884
[42950405.250000] [] block_ioctl+0x2c/0x30
[42950405.250000] [] vfs_ioctl+0x38/0x9c
[42950405.250000] [] do_vfs_ioctl+0x70/0x304
[42950405.250000] [] sys_ioctl+0x40/0x64
[42950405.250000] [] ret_fast_syscall+0x0/0x2c
[42950405.250000]
[42950405.250000] other info that might help us debug this:
[42950405.250000]
[42950405.250000] 1 lock held by exe/7044:
[42950405.250000] #0: (&lo->lo_ctl_mutex){--..}, at: []
lo_ioctl+0x3c/0x8c0
[42950405.250000]
[42950405.250000] stack backtrace:
[42950405.250000] [] (dump_stack+0x0/0x14) from []
(print_circular_bug_tail+0x80/0x94)
[42950405.250000] [] (print_circular_bug_tail+0x0/0x94) from
[] (__lock_acquire+0xce4/0xffc)
[42950405.250000] r5:c1c98418 r4:c1c983e0
[42950405.250000] [] (__lock_acquire+0x0/0xffc) from
[] (lock_acquire+0x8c/0xa8)
[42950405.250000] [] (lock_acquire+0x0/0xa8) from []
(mutex_lock_nested+0xa8/0x2b0)
[42950405.250000] r6:c191c000 r5:60000013 r4:c0fc0ccc
[42950405.250000] [] (mutex_lock_nested+0x0/0x2b0) from
[] (__blkdev_put+0x28/0x158)
[42950405.250000] [] (__blkdev_put+0x0/0x158) from
[] (blkdev_put+0x14/0x18)
[42950405.250000] [] (blkdev_put+0x0/0x18) from []
(blkdev_close+0x30/0x44)
[42950405.250000] [] (blkdev_close+0x0/0x44) from []
(__fput+0xbc/0x1b4)
[42950405.250000] r4:00000008
[42950405.250000] [] (__fput+0x0/0x1b4) from []
(fput+0x34/0x38)
[42950405.250000] [] (fput+0x0/0x38) from []
(loop_clr_fd+0x120/0x15c)
[42950405.250000] [] (loop_clr_fd+0x0/0x15c) from []
(lo_ioctl+0x218/0x8c0)
[42950405.250000] [] (lo_ioctl+0x0/0x8c0) from []
(blkdev_driver_ioctl+0x80/0x8c)
[42950405.250000] [] (blkdev_driver_ioctl+0x0/0x8c) from
[] (blkdev_ioctl+0x258/0x884)
[42950405.250000] [] (blkdev_ioctl+0x0/0x884) from
[] (block_ioctl+0x2c/0x30)
[42950405.250000] [] (block_ioctl+0x0/0x30) from []
(vfs_ioctl+0x38/0x9c)
[42950405.250000] r4:c128e2e0
[42950405.250000] [] (vfs_ioctl+0x0/0x9c) from []
(do_vfs_ioctl+0x70/0x304)
[42950405.250000] r6:00000000 r5:c128e2e0 r4:c1b120ec
[42950405.250000] [] (do_vfs_ioctl+0x0/0x304) from
[] (sys_ioctl+0x40/0x64)
[42950405.250000] r8:c003bd04 r7:00000036 r6:00004c01 r5:fffffff7
r4:c128e2e0
[42950405.250000] [] (sys_ioctl+0x0/0x64) from []
(ret_fast_syscall+0x0/0x2c)
[42950405.250000] r6:00000000 r5:00000001 r4:00000003

the kernel version is 2.6.26.3 (can't test with 2.6.27 due to an USB
issue) running on a ep9307 (ARM) CPU