Bug 202745

Summary: pktcdvd triggers a lock inversion complaint
Product: IO/Storage Reporter: Bart Van Assche (bvanassche)
Component: Block LayerAssignee: Jens Axboe (axboe)
Status: NEW ---    
Severity: normal    
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: v5.1-rc1 (next-20190301) Subsystem:
Regression: No Bisected commit-id:

Description Bart Van Assche 2019-03-04 02:19:33 UTC
This is what appears during boot in the kernel log since at least kernel v4.8:


pktcdvd: pktcdvd0: writer mapped to sr0

============================================
WARNING: possible recursive locking detected
5.0.0-rc8-next-20190301-dbg+ #1 Not tainted
--------------------------------------------
systemd-udevd/3737 is trying to acquire lock:
0000000091432535 (&bdev->bd_mutex){+.+.}, at: __blkdev_get+0x10e/0xa00

but task is already holding lock:
00000000fb0b5b8d (&bdev->bd_mutex){+.+.}, at: __blkdev_get+0x10e/0xa00

other info that might help us debug this:
 Possible unsafe locking scenario:
       CPU0
       ----
  lock(&bdev->bd_mutex);
  lock(&bdev->bd_mutex);

 *** DEADLOCK ***
 May be due to missing lock nesting notation
3 locks held by systemd-udevd/3737:
 #0: 00000000fb0b5b8d (&bdev->bd_mutex){+.+.}, at: __blkdev_get+0x10e/0xa00
 #1: 00000000656f5dab (pktcdvd_mutex){+.+.}, at: pkt_open+0x9e/0x880 [pktcdvd]
 #2: 00000000a24adc46 (&ctl_mutex#2){+.+.}, at: pkt_open+0xac/0x880 [pktcdvd]

stack backtrace:
CPU: 1 PID: 3737 Comm: systemd-udevd Not tainted 5.0.0-rc8-next-20190301-dbg+ #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
 dump_stack+0x86/0xca
 __lock_acquire.cold.66+0x10d/0x2b8
 lock_acquire+0xe3/0x200
 __mutex_lock+0x106/0xc00
 mutex_lock_nested+0x1b/0x20
 __blkdev_get+0x10e/0xa00
 blkdev_get+0x371/0x5c0
 pkt_open+0x213/0x880 [pktcdvd]
 __blkdev_get+0x236/0xa00
 blkdev_get+0x1fa/0x5c0
 blkdev_open+0xe9/0x100
 do_dentry_open+0x29a/0x6b0
 vfs_open+0x58/0x60
 path_openat+0x723/0x1a30
 do_filp_open+0x121/0x1b0
 do_sys_open+0x1e2/0x2d0
 __x64_sys_openat+0x59/0x70
 do_syscall_64+0x77/0x220
 entry_SYSCALL_64_after_hwframe+0x49/0xbe