BTRFS info (device loop1): enabling ssd optimizations ====================================================== WARNING: possible circular locking dependency detected 5.15.165-syzkaller #0 Not tainted ------------------------------------------------------ syz.1.1605/10191 is trying to acquire lock: ffff888061485e60 (&type->i_mutex_dir_key#8){++++}-{3:3}, at: inode_lock_shared include/linux/fs.h:799 [inline] ffff888061485e60 (&type->i_mutex_dir_key#8){++++}-{3:3}, at: lookup_slow+0x45/0x70 fs/namei.c:1679 but task is already holding lock: ffff88805a1f30e0 (&fs_devs->device_list_mutex){+.+.}-{3:3}, at: btrfs_free_stale_devices+0x14b/0xb00 fs/btrfs/volumes.c:603 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #3 (&fs_devs->device_list_mutex){+.+.}-{3:3}: lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623 __mutex_lock_common+0x1da/0x25a0 kernel/locking/mutex.c:596 __mutex_lock kernel/locking/mutex.c:729 [inline] mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:743 write_all_supers+0x13fd/0x4650 fs/btrfs/disk-io.c:4159 btrfs_sync_log+0x1f78/0x2a00 fs/btrfs/tree-log.c:3327 btrfs_sync_file+0xc56/0x1120 fs/btrfs/file.c:2378 generic_write_sync include/linux/fs.h:2984 [inline] btrfs_file_write_iter+0x7e5/0xed0 fs/btrfs/file.c:2111 do_iter_readv_writev+0x594/0x7a0 do_iter_write+0x1e6/0x760 fs/read_write.c:855 vfs_writev fs/read_write.c:928 [inline] do_pwritev+0x219/0x360 fs/read_write.c:1025 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x66/0xd0 -> #2 (&fs_info->tree_log_mutex){+.+.}-{3:3}: lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623 __mutex_lock_common+0x1da/0x25a0 kernel/locking/mutex.c:596 __mutex_lock kernel/locking/mutex.c:729 [inline] mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:743 btrfs_sync_log+0x1e77/0x2a00 fs/btrfs/tree-log.c:3308 btrfs_sync_file+0xc56/0x1120 fs/btrfs/file.c:2378 generic_write_sync include/linux/fs.h:2984 [inline] btrfs_file_write_iter+0x7e5/0xed0 fs/btrfs/file.c:2111 do_iter_readv_writev+0x594/0x7a0 do_iter_write+0x1e6/0x760 fs/read_write.c:855 vfs_writev fs/read_write.c:928 [inline] do_pwritev+0x219/0x360 fs/read_write.c:1025 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x66/0xd0 -> #1 (sb_internal#2){.+.+}-{0:0}: lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623 percpu_down_read include/linux/percpu-rwsem.h:51 [inline] __sb_start_write include/linux/fs.h:1811 [inline] sb_start_intwrite include/linux/fs.h:1928 [inline] start_transaction+0x5a8/0x11a0 fs/btrfs/transaction.c:678 btrfs_create+0x16d/0x680 fs/btrfs/inode.c:6892 lookup_open fs/namei.c:3462 [inline] open_last_lookups fs/namei.c:3532 [inline] path_openat+0x130a/0x2f20 fs/namei.c:3739 do_filp_open+0x21c/0x460 fs/namei.c:3769 do_sys_openat2+0x13b/0x4f0 fs/open.c:1253 do_sys_open fs/open.c:1269 [inline] __do_sys_openat fs/open.c:1285 [inline] __se_sys_openat fs/open.c:1280 [inline] __x64_sys_openat+0x243/0x290 fs/open.c:1280 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x66/0xd0 -> #0 (&type->i_mutex_dir_key#8){++++}-{3:3}: check_prev_add kernel/locking/lockdep.c:3053 [inline] check_prevs_add kernel/locking/lockdep.c:3172 [inline] validate_chain+0x1649/0x5930 kernel/locking/lockdep.c:3788 __lock_acquire+0x1295/0x1ff0 kernel/locking/lockdep.c:5012 lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623 down_read+0x45/0x2e0 kernel/locking/rwsem.c:1498 inode_lock_shared include/linux/fs.h:799 [inline] lookup_slow+0x45/0x70 fs/namei.c:1679 walk_component+0x48c/0x610 fs/namei.c:1976 lookup_last fs/namei.c:2431 [inline] path_lookupat+0x16f/0x450 fs/namei.c:2455 filename_lookup+0x230/0x5c0 fs/namei.c:2484 kern_path+0x37/0x180 fs/namei.c:2582 lookup_bdev+0xc1/0x280 block/bdev.c:979 device_matched fs/btrfs/volumes.c:568 [inline] btrfs_free_stale_devices+0x71f/0xb00 fs/btrfs/volumes.c:608 btrfs_forget_devices+0x52/0x80 fs/btrfs/volumes.c:1395 btrfs_control_ioctl+0x108/0x210 fs/btrfs/super.c:2451 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:874 [inline] __se_sys_ioctl+0xf1/0x160 fs/ioctl.c:860 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x66/0xd0 other info that might help us debug this: Chain exists of: &type->i_mutex_dir_key#8 --> &fs_info->tree_log_mutex --> &fs_devs->device_list_mutex Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(&fs_devs->device_list_mutex); lock(&fs_info->tree_log_mutex); lock(&fs_devs->device_list_mutex); lock(&type->i_mutex_dir_key#8); *** DEADLOCK *** 2 locks held by syz.1.1605/10191: #0: ffffffff8ce019a8 (uuid_mutex){+.+.}-{3:3}, at: btrfs_forget_devices+0x1a/0x80 fs/btrfs/volumes.c:1394 #1: ffff88805a1f30e0 (&fs_devs->device_list_mutex){+.+.}-{3:3}, at: btrfs_free_stale_devices+0x14b/0xb00 fs/btrfs/volumes.c:603 stack backtrace: CPU: 0 PID: 10191 Comm: syz.1.1605 Not tainted 5.15.165-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024 Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x1e3/0x2d0 lib/dump_stack.c:106 check_noncircular+0x2f8/0x3b0 kernel/locking/lockdep.c:2133 check_prev_add kernel/locking/lockdep.c:3053 [inline] check_prevs_add kernel/locking/lockdep.c:3172 [inline] validate_chain+0x1649/0x5930 kernel/locking/lockdep.c:3788 __lock_acquire+0x1295/0x1ff0 kernel/locking/lockdep.c:5012 lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623 down_read+0x45/0x2e0 kernel/locking/rwsem.c:1498 inode_lock_shared include/linux/fs.h:799 [inline] lookup_slow+0x45/0x70 fs/namei.c:1679 walk_component+0x48c/0x610 fs/namei.c:1976 lookup_last fs/namei.c:2431 [inline] path_lookupat+0x16f/0x450 fs/namei.c:2455 filename_lookup+0x230/0x5c0 fs/namei.c:2484 kern_path+0x37/0x180 fs/namei.c:2582 lookup_bdev+0xc1/0x280 block/bdev.c:979 device_matched fs/btrfs/volumes.c:568 [inline] btrfs_free_stale_devices+0x71f/0xb00 fs/btrfs/volumes.c:608 btrfs_forget_devices+0x52/0x80 fs/btrfs/volumes.c:1395 btrfs_control_ioctl+0x108/0x210 fs/btrfs/super.c:2451 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:874 [inline] __se_sys_ioctl+0xf1/0x160 fs/ioctl.c:860 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x3b/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x66/0xd0 RIP: 0033:0x7f788f695e79 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f788db12038 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 00007f788f831f80 RCX: 00007f788f695e79 RDX: 00000000200004c0 RSI: 0000000050009405 RDI: 0000000000000005 RBP: 00007f788f70393e R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 0000000000000000 R14: 00007f788f831f80 R15: 00007fffe8b9aaf8