syzbot


possible deadlock in btrfs_commit_transaction

Status: upstream: reported C repro on 2022/11/15 06:18
Reported-by: syzbot+52d708a0bca2efc4c9df@syzkaller.appspotmail.com
First crash: 11d, last: 14h28m

Cause bisection: failed (bisect log)
Patch testing requests:
Created Duration User Patch Repo Result
2022/11/15 12:38 29m hdanton@sina.com patch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git e01d50cbd6ee OK log

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.1.0-rc6-syzkaller-00176-g08ad43d554ba #0 Not tainted
------------------------------------------------------
syz-executor539/3633 is trying to acquire lock:
ffff8880217524d8 (btrfs-root-00){.+.+}-{3:3}, at: __btrfs_tree_read_lock fs/btrfs/locking.c:134 [inline]
ffff8880217524d8 (btrfs-root-00){.+.+}-{3:3}, at: btrfs_tree_read_lock fs/btrfs/locking.c:140 [inline]
ffff8880217524d8 (btrfs-root-00){.+.+}-{3:3}, at: btrfs_read_lock_root_node+0x2b4/0x400 fs/btrfs/locking.c:279

but task is already holding lock:
ffff88807cebccc0 (&fs_info->reloc_mutex){+.+.}-{3:3}, at: btrfs_commit_transaction+0x13e8/0x3760 fs/btrfs/transaction.c:2316

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #5 (&fs_info->reloc_mutex){+.+.}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       __mutex_lock_common+0x1bd/0x26e0 kernel/locking/mutex.c:603
       __mutex_lock kernel/locking/mutex.c:747 [inline]
       mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:799
       btrfs_record_root_in_trans+0x153/0x180 fs/btrfs/transaction.c:484
       start_transaction+0x3af/0x1180 fs/btrfs/transaction.c:721
       btrfs_create_common+0x2c6/0x420 fs/btrfs/inode.c:6633
       lookup_open fs/namei.c:3413 [inline]
       open_last_lookups fs/namei.c:3481 [inline]
       path_openat+0x12d0/0x2df0 fs/namei.c:3710
       do_filp_open+0x264/0x4f0 fs/namei.c:3740
       do_sys_openat2+0x124/0x4e0 fs/open.c:1310
       do_sys_open fs/open.c:1326 [inline]
       __do_sys_open fs/open.c:1334 [inline]
       __se_sys_open fs/open.c:1330 [inline]
       __x64_sys_open+0x221/0x270 fs/open.c:1330
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #4 (btrfs_trans_num_extwriters){++++}-{0:0}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       join_transaction+0x19f/0xe60 fs/btrfs/transaction.c:299
       start_transaction+0x6fb/0x1180 fs/btrfs/transaction.c:658
       btrfs_create_common+0x2c6/0x420 fs/btrfs/inode.c:6633
       lookup_open fs/namei.c:3413 [inline]
       open_last_lookups fs/namei.c:3481 [inline]
       path_openat+0x12d0/0x2df0 fs/namei.c:3710
       do_filp_open+0x264/0x4f0 fs/namei.c:3740
       do_sys_openat2+0x124/0x4e0 fs/open.c:1310
       do_sys_open fs/open.c:1326 [inline]
       __do_sys_open fs/open.c:1334 [inline]
       __se_sys_open fs/open.c:1330 [inline]
       __x64_sys_open+0x221/0x270 fs/open.c:1330
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #3 (btrfs_trans_num_writers){++++}-{0:0}:
       reacquire_held_locks+0x386/0x650 kernel/locking/lockdep.c:5193
       __lock_release kernel/locking/lockdep.c:5382 [inline]
       lock_release+0x2e2/0x820 kernel/locking/lockdep.c:5688
       percpu_up_read include/linux/percpu-rwsem.h:99 [inline]
       __sb_end_write include/linux/fs.h:1821 [inline]
       sb_end_intwrite+0x1e/0x1a0 include/linux/fs.h:1877
       __btrfs_end_transaction+0x388/0x790 fs/btrfs/transaction.c:995
       btrfs_dirty_inode+0x177/0x1c0 fs/btrfs/inode.c:6099
       inode_update_time fs/inode.c:1871 [inline]
       __file_update_time fs/inode.c:2088 [inline]
       file_update_time+0x3df/0x5d0 fs/inode.c:2119
       btrfs_page_mkwrite+0x3a8/0xc80 fs/btrfs/inode.c:8431
       do_page_mkwrite+0x19e/0x5e0 mm/memory.c:2978
       do_shared_fault mm/memory.c:4619 [inline]
       do_fault mm/memory.c:4687 [inline]
       handle_pte_fault mm/memory.c:4955 [inline]
       __handle_mm_fault mm/memory.c:5097 [inline]
       handle_mm_fault+0x1c63/0x3630 mm/memory.c:5218
       do_user_addr_fault+0x69b/0xcb0 arch/x86/mm/fault.c:1428
       handle_page_fault arch/x86/mm/fault.c:1519 [inline]
       exc_page_fault+0x7a/0x110 arch/x86/mm/fault.c:1575
       asm_exc_page_fault+0x22/0x30 arch/x86/include/asm/idtentry.h:570

-> #2 (sb_pagefaults){.+.+}-{0:0}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
       __sb_start_write include/linux/fs.h:1826 [inline]
       sb_start_pagefault include/linux/fs.h:1930 [inline]
       btrfs_page_mkwrite+0x1ea/0xc80 fs/btrfs/inode.c:8415
       do_page_mkwrite+0x19e/0x5e0 mm/memory.c:2978
       do_shared_fault mm/memory.c:4619 [inline]
       do_fault mm/memory.c:4687 [inline]
       handle_pte_fault mm/memory.c:4955 [inline]
       __handle_mm_fault mm/memory.c:5097 [inline]
       handle_mm_fault+0x1c63/0x3630 mm/memory.c:5218
       do_user_addr_fault+0x69b/0xcb0 arch/x86/mm/fault.c:1428
       handle_page_fault arch/x86/mm/fault.c:1519 [inline]
       exc_page_fault+0x7a/0x110 arch/x86/mm/fault.c:1575
       asm_exc_page_fault+0x22/0x30 arch/x86/include/asm/idtentry.h:570

-> #1 (&mm->mmap_lock#2){++++}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       __might_fault+0xb2/0x110 mm/memory.c:5646
       _copy_to_user+0x26/0x130 lib/usercopy.c:29
       copy_to_user include/linux/uaccess.h:169 [inline]
       btrfs_ioctl_get_subvol_rootref+0x8cf/0xa90 fs/btrfs/ioctl.c:3203
       btrfs_ioctl+0xb7c/0xc10 fs/btrfs/ioctl.c:5556
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:870 [inline]
       __se_sys_ioctl+0xfb/0x170 fs/ioctl.c:856
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

-> #0 (btrfs-root-00){.+.+}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3097 [inline]
       check_prevs_add kernel/locking/lockdep.c:3216 [inline]
       validate_chain+0x1898/0x6ae0 kernel/locking/lockdep.c:3831
       __lock_acquire+0x1292/0x1f60 kernel/locking/lockdep.c:5055
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       down_read_nested+0x3c/0x50 kernel/locking/rwsem.c:1634
       __btrfs_tree_read_lock fs/btrfs/locking.c:134 [inline]
       btrfs_tree_read_lock fs/btrfs/locking.c:140 [inline]
       btrfs_read_lock_root_node+0x2b4/0x400 fs/btrfs/locking.c:279
       btrfs_search_slot_get_root fs/btrfs/ctree.c:1665 [inline]
       btrfs_search_slot+0x495/0x2fe0 fs/btrfs/ctree.c:1985
       btrfs_update_root+0xf0/0xc60 fs/btrfs/root-tree.c:132
       commit_fs_roots+0x4d3/0x710 fs/btrfs/transaction.c:1441
       btrfs_commit_transaction+0x147f/0x3760 fs/btrfs/transaction.c:2353
       sync_filesystem+0x1bc/0x220 fs/sync.c:66
       generic_shutdown_super+0x6b/0x310 fs/super.c:474
       kill_anon_super+0x36/0x60 fs/super.c:1086
       btrfs_kill_super+0x3d/0x50 fs/btrfs/super.c:2441
       deactivate_locked_super+0xa7/0xf0 fs/super.c:332
       cleanup_mnt+0x494/0x520 fs/namespace.c:1186
       task_work_run+0x243/0x300 kernel/task_work.c:179
       exit_task_work include/linux/task_work.h:38 [inline]
       do_exit+0x664/0x2070 kernel/exit.c:820
       do_group_exit+0x1fd/0x2b0 kernel/exit.c:950
       __do_sys_exit_group kernel/exit.c:961 [inline]
       __se_sys_exit_group kernel/exit.c:959 [inline]
       __x64_sys_exit_group+0x3b/0x40 kernel/exit.c:959
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

other info that might help us debug this:

Chain exists of:
  btrfs-root-00 --> btrfs_trans_num_extwriters --> &fs_info->reloc_mutex

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&fs_info->reloc_mutex);
                               lock(btrfs_trans_num_extwriters);
                               lock(&fs_info->reloc_mutex);
  lock(btrfs-root-00);

 *** DEADLOCK ***

5 locks held by syz-executor539/3633:
 #0: ffff8880733280e0 (&type->s_umount_key#44){+.+.}-{3:3}, at: deactivate_super+0x96/0xd0 fs/super.c:362
 #1: ffff88807cebe3f0 (btrfs_trans_completed){.+.+}-{0:0}, at: btrfs_commit_transaction+0x130f/0x3760 fs/btrfs/transaction.c:2295
 #2: ffff88807cebe3c8 (btrfs_trans_super_committed){.+.+}-{0:0}, at: btrfs_commit_transaction+0x133e/0x3760 fs/btrfs/transaction.c:2296
 #3: ffff88807cebe3a0 (btrfs_trans_unblocked){.+.+}-{0:0}, at: btrfs_commit_transaction+0x136d/0x3760 fs/btrfs/transaction.c:2297
 #4: ffff88807cebccc0 (&fs_info->reloc_mutex){+.+.}-{3:3}, at: btrfs_commit_transaction+0x13e8/0x3760 fs/btrfs/transaction.c:2316

stack backtrace:
CPU: 1 PID: 3633 Comm: syz-executor539 Not tainted 6.1.0-rc6-syzkaller-00176-g08ad43d554ba #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1b1/0x28e lib/dump_stack.c:106
 check_noncircular+0x2cc/0x390 kernel/locking/lockdep.c:2177
 check_prev_add kernel/locking/lockdep.c:3097 [inline]
 check_prevs_add kernel/locking/lockdep.c:3216 [inline]
 validate_chain+0x1898/0x6ae0 kernel/locking/lockdep.c:3831
 __lock_acquire+0x1292/0x1f60 kernel/locking/lockdep.c:5055
 lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
 down_read_nested+0x3c/0x50 kernel/locking/rwsem.c:1634
 __btrfs_tree_read_lock fs/btrfs/locking.c:134 [inline]
 btrfs_tree_read_lock fs/btrfs/locking.c:140 [inline]
 btrfs_read_lock_root_node+0x2b4/0x400 fs/btrfs/locking.c:279
 btrfs_search_slot_get_root fs/btrfs/ctree.c:1665 [inline]
 btrfs_search_slot+0x495/0x2fe0 fs/btrfs/ctree.c:1985
 btrfs_update_root+0xf0/0xc60 fs/btrfs/root-tree.c:132
 commit_fs_roots+0x4d3/0x710 fs/btrfs/transaction.c:1441
 btrfs_commit_transaction+0x147f/0x3760 fs/btrfs/transaction.c:2353
 sync_filesystem+0x1bc/0x220 fs/sync.c:66
 generic_shutdown_super+0x6b/0x310 fs/super.c:474
 kill_anon_super+0x36/0x60 fs/super.c:1086
 btrfs_kill_super+0x3d/0x50 fs/btrfs/super.c:2441
 deactivate_locked_super+0xa7/0xf0 fs/super.c:332
 cleanup_mnt+0x494/0x520 fs/namespace.c:1186
 task_work_run+0x243/0x300 kernel/task_work.c:179
 exit_task_work include/linux/task_work.h:38 [inline]
 do_exit+0x664/0x2070 kernel/exit.c:820
 do_group_exit+0x1fd/0x2b0 kernel/exit.c:950
 __do_sys_exit_group kernel/exit.c:961 [inline]
 __se_sys_exit_group kernel/exit.c:959 [inline]
 __x64_sys_exit_group+0x3b/0x40 kernel/exit.c:959
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7fef8b4ec279
Code: Unable to access opcode bytes at 0x7fef8b4ec24f.
RSP: 002b:00007ffebca0a078 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
RAX: ffffffffffffffda RBX: 00007fef8b566350 RCX: 00007fef8b4ec279
RDX: 000000000000003c RSI: 00000000000000e7 RDI: 0000000000000001
RBP: 0000000000000001 R08: ffffffffffffffc0 R09: 00007fef8b560e40
R10: 0000000000000000 R11: 0000000000000246 R12: 00007fef8b566350
R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000001
 </TASK>

Crashes (6):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci2-upstream-fs 2022/11/26 10:39 upstream 08ad43d554ba f4470a7b .config log report syz C possible deadlock in btrfs_commit_transaction
ci2-upstream-fs 2022/11/17 19:33 upstream 81ac25651a62 4ba8ab94 .config log report syz C possible deadlock in btrfs_commit_transaction
ci2-upstream-fs 2022/11/17 13:56 upstream cc675d22e422 3a127a31 .config log report syz C possible deadlock in btrfs_commit_transaction
ci2-upstream-fs 2022/11/17 02:19 upstream 59d0d52c30d4 3a127a31 .config log report syz C possible deadlock in btrfs_commit_transaction
ci2-upstream-fs 2022/11/15 14:31 upstream e01d50cbd6ee 97de9cfc .config log report syz C possible deadlock in btrfs_commit_transaction
ci2-upstream-fs 2022/11/15 05:15 upstream e01d50cbd6ee 97de9cfc .config log report syz C possible deadlock in btrfs_commit_transaction
* Struck through repros no longer work on HEAD.