syzbot


possible deadlock in btrfs_tree_lock_nested

Status: upstream: reported on 2025/01/06 01:21
Subsystems: btrfs
[Documentation on labels]
Reported-by: syzbot+63913e558c084f7f8fdc@syzkaller.appspotmail.com
First crash: 6d13h, last: 4h27m
Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [btrfs?] possible deadlock in btrfs_tree_lock_nested 0 (1) 2025/01/06 01:21

Sample crash report:
BTRFS info (device loop0): balance: start -d -m
BTRFS info (device loop0): relocating block group 6881280 flags data|metadata
BTRFS info (device loop0): relocating block group 5242880 flags data|metadata
======================================================
WARNING: possible circular locking dependency detected
6.13.0-rc6-syzkaller-00038-g09a0fa92e5b4 #0 Not tainted
------------------------------------------------------
syz.0.0/5322 is trying to acquire lock:
ffff888032c79698 (btrfs-tree-01){++++}-{4:4}, at: btrfs_tree_read_lock_nested+0x2f/0x250 fs/btrfs/locking.c:146

but task is already holding lock:
ffff888032c794b8 (btrfs-treloc-02/1){+.+.}-{4:4}, at: btrfs_tree_lock_nested+0x2f/0x250 fs/btrfs/locking.c:189

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (btrfs-treloc-02/1){+.+.}-{4:4}:
       reacquire_held_locks+0x3eb/0x690 kernel/locking/lockdep.c:5374
       __lock_release kernel/locking/lockdep.c:5563 [inline]
       lock_release+0x396/0xa30 kernel/locking/lockdep.c:5870
       up_write+0x79/0x590 kernel/locking/rwsem.c:1629
       btrfs_force_cow_block+0x14b3/0x1fd0 fs/btrfs/ctree.c:660
       btrfs_cow_block+0x371/0x830 fs/btrfs/ctree.c:755
       btrfs_search_slot+0xc01/0x3180 fs/btrfs/ctree.c:2153
       replace_path+0x1243/0x2740 fs/btrfs/relocation.c:1224
       merge_reloc_root+0xc46/0x1ad0 fs/btrfs/relocation.c:1692
       merge_reloc_roots+0x3b3/0x980 fs/btrfs/relocation.c:1942
       relocate_block_group+0xb0a/0xd40 fs/btrfs/relocation.c:3754
       btrfs_relocate_block_group+0x77d/0xd90 fs/btrfs/relocation.c:4087
       btrfs_relocate_chunk+0x12c/0x3b0 fs/btrfs/volumes.c:3494
       __btrfs_balance+0x1b0f/0x26b0 fs/btrfs/volumes.c:4278
       btrfs_balance+0xbdc/0x10c0 fs/btrfs/volumes.c:4655
       btrfs_ioctl_balance+0x493/0x7c0 fs/btrfs/ioctl.c:3670
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:906 [inline]
       __se_sys_ioctl+0xf5/0x170 fs/ioctl.c:892
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #1 (btrfs-tree-01/1){+.+.}-{4:4}:
       lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
       down_write_nested+0xa2/0x220 kernel/locking/rwsem.c:1693
       btrfs_tree_lock_nested+0x2f/0x250 fs/btrfs/locking.c:189
       btrfs_init_new_buffer fs/btrfs/extent-tree.c:5052 [inline]
       btrfs_alloc_tree_block+0x41c/0x1440 fs/btrfs/extent-tree.c:5132
       btrfs_force_cow_block+0x526/0x1fd0 fs/btrfs/ctree.c:573
       btrfs_cow_block+0x371/0x830 fs/btrfs/ctree.c:755
       btrfs_search_slot+0xc01/0x3180 fs/btrfs/ctree.c:2153
       btrfs_insert_empty_items+0x9c/0x1a0 fs/btrfs/ctree.c:4351
       btrfs_insert_empty_item fs/btrfs/ctree.h:688 [inline]
       btrfs_insert_inode_ref+0x2bb/0xf80 fs/btrfs/inode-item.c:330
       btrfs_rename_exchange fs/btrfs/inode.c:7990 [inline]
       btrfs_rename2+0xcb7/0x2b90 fs/btrfs/inode.c:8374
       vfs_rename+0xbdb/0xf00 fs/namei.c:5067
       do_renameat2+0xd94/0x13f0 fs/namei.c:5224
       __do_sys_renameat2 fs/namei.c:5258 [inline]
       __se_sys_renameat2 fs/namei.c:5255 [inline]
       __x64_sys_renameat2+0xce/0xe0 fs/namei.c:5255
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (btrfs-tree-01){++++}-{4:4}:
       check_prev_add kernel/locking/lockdep.c:3161 [inline]
       check_prevs_add kernel/locking/lockdep.c:3280 [inline]
       validate_chain+0x18ef/0x5920 kernel/locking/lockdep.c:3904
       __lock_acquire+0x1397/0x2100 kernel/locking/lockdep.c:5226
       lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
       down_read_nested+0xb5/0xa50 kernel/locking/rwsem.c:1649
       btrfs_tree_read_lock_nested+0x2f/0x250 fs/btrfs/locking.c:146
       btrfs_tree_read_lock fs/btrfs/locking.h:188 [inline]
       read_block_for_search+0x718/0xbb0 fs/btrfs/ctree.c:1610
       btrfs_search_slot+0x1274/0x3180 fs/btrfs/ctree.c:2237
       replace_path+0x1243/0x2740 fs/btrfs/relocation.c:1224
       merge_reloc_root+0xc46/0x1ad0 fs/btrfs/relocation.c:1692
       merge_reloc_roots+0x3b3/0x980 fs/btrfs/relocation.c:1942
       relocate_block_group+0xb0a/0xd40 fs/btrfs/relocation.c:3754
       btrfs_relocate_block_group+0x77d/0xd90 fs/btrfs/relocation.c:4087
       btrfs_relocate_chunk+0x12c/0x3b0 fs/btrfs/volumes.c:3494
       __btrfs_balance+0x1b0f/0x26b0 fs/btrfs/volumes.c:4278
       btrfs_balance+0xbdc/0x10c0 fs/btrfs/volumes.c:4655
       btrfs_ioctl_balance+0x493/0x7c0 fs/btrfs/ioctl.c:3670
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:906 [inline]
       __se_sys_ioctl+0xf5/0x170 fs/ioctl.c:892
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

Chain exists of:
  btrfs-tree-01 --> btrfs-tree-01/1 --> btrfs-treloc-02/1

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(btrfs-treloc-02/1);
                               lock(btrfs-tree-01/1);
                               lock(btrfs-treloc-02/1);
  rlock(btrfs-tree-01);

 *** DEADLOCK ***

8 locks held by syz.0.0/5322:
 #0: ffff888040ec4420 (sb_writers#13){.+.+}-{0:0}, at: mnt_want_write_file+0x5e/0x200 fs/namespace.c:559
 #1: ffff888052ea60d0 (&fs_info->reclaim_bgs_lock){+.+.}-{4:4}, at: __btrfs_balance+0x4c2/0x26b0 fs/btrfs/volumes.c:4183
 #2: ffff888052ea4850 (&fs_info->cleaner_mutex){+.+.}-{4:4}, at: btrfs_relocate_block_group+0x775/0xd90 fs/btrfs/relocation.c:4086
 #3: ffff888040ec4610 (sb_internal#2){.+.+}-{0:0}, at: merge_reloc_root+0x5ed/0x1ad0 fs/btrfs/relocation.c:1659
 #4: ffff888052ea6470 (btrfs_trans_num_writers){++++}-{0:0}, at: join_transaction+0x405/0xda0 fs/btrfs/transaction.c:288
 #5: ffff888052ea6498 (btrfs_trans_num_extwriters){++++}-{0:0}, at: join_transaction+0x405/0xda0 fs/btrfs/transaction.c:288
 #6: ffff88801ef64a58 (btrfs-tree-01/1){+.+.}-{4:4}, at: btrfs_tree_lock_nested+0x2f/0x250 fs/btrfs/locking.c:189
 #7: ffff888032c794b8 (btrfs-treloc-02/1){+.+.}-{4:4}, at: btrfs_tree_lock_nested+0x2f/0x250 fs/btrfs/locking.c:189

stack backtrace:
CPU: 0 UID: 0 PID: 5322 Comm: syz.0.0 Not tainted 6.13.0-rc6-syzkaller-00038-g09a0fa92e5b4 #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
 print_circular_bug+0x13a/0x1b0 kernel/locking/lockdep.c:2074
 check_noncircular+0x36a/0x4a0 kernel/locking/lockdep.c:2206
 check_prev_add kernel/locking/lockdep.c:3161 [inline]
 check_prevs_add kernel/locking/lockdep.c:3280 [inline]
 validate_chain+0x18ef/0x5920 kernel/locking/lockdep.c:3904
 __lock_acquire+0x1397/0x2100 kernel/locking/lockdep.c:5226
 lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
 down_read_nested+0xb5/0xa50 kernel/locking/rwsem.c:1649
 btrfs_tree_read_lock_nested+0x2f/0x250 fs/btrfs/locking.c:146
 btrfs_tree_read_lock fs/btrfs/locking.h:188 [inline]
 read_block_for_search+0x718/0xbb0 fs/btrfs/ctree.c:1610
 btrfs_search_slot+0x1274/0x3180 fs/btrfs/ctree.c:2237
 replace_path+0x1243/0x2740 fs/btrfs/relocation.c:1224
 merge_reloc_root+0xc46/0x1ad0 fs/btrfs/relocation.c:1692
 merge_reloc_roots+0x3b3/0x980 fs/btrfs/relocation.c:1942
 relocate_block_group+0xb0a/0xd40 fs/btrfs/relocation.c:3754
 btrfs_relocate_block_group+0x77d/0xd90 fs/btrfs/relocation.c:4087
 btrfs_relocate_chunk+0x12c/0x3b0 fs/btrfs/volumes.c:3494
 __btrfs_balance+0x1b0f/0x26b0 fs/btrfs/volumes.c:4278
 btrfs_balance+0xbdc/0x10c0 fs/btrfs/volumes.c:4655
 btrfs_ioctl_balance+0x493/0x7c0 fs/btrfs/ioctl.c:3670
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:906 [inline]
 __se_sys_ioctl+0xf5/0x170 fs/ioctl.c:892
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fce15385d29
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:00007fce16223038 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007fce15576160 RCX: 00007fce15385d29
RDX: 0000000020000180 RSI: 00000000c4009420 RDI: 0000000000000008
RBP: 00007fce15401b08 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 00007fce15576160 R15: 00007ffdcf313d48
 </TASK>
BTRFS info (device loop0): found 236 extents, stage: move data extents
BTRFS info (device loop0): 1 enospc errors during balance
BTRFS info (device loop0): balance: canceled

Crashes (14):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2025/01/08 09:53 upstream 09a0fa92e5b4 f3558dbf .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
2025/01/07 13:28 upstream fbfd64d25c7a f3558dbf .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
2025/01/07 04:02 upstream fbfd64d25c7a f3558dbf .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
2025/01/05 01:12 upstream ab75170520d4 f3558dbf .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
2025/01/04 23:33 upstream ab75170520d4 f3558dbf .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
2025/01/04 23:19 upstream ab75170520d4 f3558dbf .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
2025/01/03 21:22 upstream 0bc21e701a6f 96d578a3 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
2025/01/03 15:07 upstream 0bc21e701a6f 96d578a3 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
2025/01/03 10:41 upstream 0bc21e701a6f d3ccff63 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
2025/01/03 03:07 upstream 0bc21e701a6f d3ccff63 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
2025/01/02 17:43 upstream 56e6a3499e14 d3ccff63 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
2025/01/02 15:32 upstream 56e6a3499e14 d3ccff63 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
2025/01/02 07:46 upstream 56e6a3499e14 d3ccff63 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
2025/01/02 01:18 upstream 56e6a3499e14 d3ccff63 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root possible deadlock in btrfs_tree_lock_nested
* Struck through repros no longer work on HEAD.