syzbot


possible deadlock in btrfs_dirty_inode (2)

Status: upstream: reported on 2024/04/13 12:12
Reported-by: syzbot+356920590036380b9c75@syzkaller.appspotmail.com
First crash: 18d, last: 18d
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-5.15 possible deadlock in btrfs_dirty_inode 3 316d 335d 0/3 auto-obsoleted due to no activity on 2023/09/28 23:24
upstream possible deadlock in btrfs_dirty_inode btrfs C error done 48 522d 534d 0/26 auto-obsoleted due to no activity on 2023/05/16 05:18

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
5.15.154-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor.4/9480 is trying to acquire lock:
ffff8880745c4650 (sb_internal#3){.+.+}-{0:0}, at: btrfs_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6428

but task is already holding lock:
ffff88807a80e328 (&mm->mmap_lock){++++}-{3:3}, at: mmap_write_lock_killable include/linux/mmap_lock.h:87 [inline]
ffff88807a80e328 (&mm->mmap_lock){++++}-{3:3}, at: vm_mmap_pgoff+0x175/0x2d0 mm/util.c:549

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #3 (&mm->mmap_lock){++++}-{3:3}:
       lock_acquire+0x1db/0x4f0 kernel/locking/lockdep.c:5623
       down_read+0x45/0x2e0 kernel/locking/rwsem.c:1498
       mmap_read_lock+0x1c/0x50 include/linux/mmap_lock.h:117
       do_user_addr_fault arch/x86/mm/fault.c:1339 [inline]
       handle_page_fault arch/x86/mm/fault.c:1476 [inline]
       exc_page_fault+0x5ce/0x740 arch/x86/mm/fault.c:1532
       asm_exc_page_fault+0x22/0x30 arch/x86/include/asm/idtentry.h:568
       user_access_begin arch/x86/include/asm/uaccess.h:574 [inline]
       filldir+0x32b/0x720 fs/readdir.c:249
       dir_emit include/linux/fs.h:3674 [inline]
       call_filldir+0x41b/0x5d0 fs/ext4/dir.c:537
       ext4_dx_readdir fs/ext4/dir.c:613 [inline]
       ext4_readdir+0x2fc7/0x38e0 fs/ext4/dir.c:142
       iterate_dir+0x224/0x570
       __do_sys_getdents fs/readdir.c:286 [inline]
       __se_sys_getdents+0x1e8/0x4c0 fs/readdir.c:271
       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 (&type->i_mutex_dir_key#4){++++}-{3:3}:
       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:1388
       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

-> #1 (&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
       insert_dev_extents fs/btrfs/block-group.c:2379 [inline]
       btrfs_create_pending_block_groups+0x5c1/0x1130 fs/btrfs/block-group.c:2429
       __btrfs_end_transaction+0x296/0x780 fs/btrfs/transaction.c:1014
       flush_space+0x4cf/0xd50 fs/btrfs/space-info.c:674
       btrfs_async_reclaim_data_space+0x118/0x3e0 fs/btrfs/space-info.c:1169
       process_one_work+0x8a1/0x10c0 kernel/workqueue.c:2310
       worker_thread+0xaca/0x1280 kernel/workqueue.c:2457
       kthread+0x3f6/0x4f0 kernel/kthread.c:334
       ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:300

-> #0 (sb_internal#3){.+.+}-{0:0}:
       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
       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_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6428
       inode_update_time fs/inode.c:1829 [inline]
       touch_atime+0x34e/0x680 fs/inode.c:1902
       file_accessed include/linux/fs.h:2516 [inline]
       btrfs_file_mmap+0xbf/0x120 fs/btrfs/file.c:2424
       call_mmap include/linux/fs.h:2177 [inline]
       mmap_region+0x10e7/0x1670 mm/mmap.c:1791
       do_mmap+0x78d/0xe00 mm/mmap.c:1575
       vm_mmap_pgoff+0x1ca/0x2d0 mm/util.c:551
       ksys_mmap_pgoff+0x559/0x780 mm/mmap.c:1624
       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:
  sb_internal#3 --> &type->i_mutex_dir_key#4 --> &mm->mmap_lock

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&mm->mmap_lock);
                               lock(&type->i_mutex_dir_key#4);
                               lock(&mm->mmap_lock);
  lock(sb_internal#3);

 *** DEADLOCK ***

2 locks held by syz-executor.4/9480:
 #0: ffff88807a80e328 (&mm->mmap_lock){++++}-{3:3}, at: mmap_write_lock_killable include/linux/mmap_lock.h:87 [inline]
 #0: ffff88807a80e328 (&mm->mmap_lock){++++}-{3:3}, at: vm_mmap_pgoff+0x175/0x2d0 mm/util.c:549
 #1: ffff8880745c4460 (sb_writers#21){.+.+}-{0:0}, at: file_accessed include/linux/fs.h:2516 [inline]
 #1: ffff8880745c4460 (sb_writers#21){.+.+}-{0:0}, at: btrfs_file_mmap+0xbf/0x120 fs/btrfs/file.c:2424

stack backtrace:
CPU: 1 PID: 9480 Comm: syz-executor.4 Not tainted 5.15.154-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024
Call Trace:
 <TASK>
 __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
 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_dirty_inode+0xcc/0x1c0 fs/btrfs/inode.c:6428
 inode_update_time fs/inode.c:1829 [inline]
 touch_atime+0x34e/0x680 fs/inode.c:1902
 file_accessed include/linux/fs.h:2516 [inline]
 btrfs_file_mmap+0xbf/0x120 fs/btrfs/file.c:2424
 call_mmap include/linux/fs.h:2177 [inline]
 mmap_region+0x10e7/0x1670 mm/mmap.c:1791
 do_mmap+0x78d/0xe00 mm/mmap.c:1575
 vm_mmap_pgoff+0x1ca/0x2d0 mm/util.c:551
 ksys_mmap_pgoff+0x559/0x780 mm/mmap.c:1624
 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:0x7f91398bae69
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 20 00 00 90 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 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f9137e2d0c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000009
RAX: ffffffffffffffda RBX: 00007f91399e8f80 RCX: 00007f91398bae69
RDX: 0000000000000001 RSI: 0000000000003000 RDI: 0000000020000000
RBP: 00007f913990747a R08: 0000000000000005 R09: 0000000000000000
R10: 0000000000010012 R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000000b R14: 00007f91399e8f80 R15: 00007ffd99e69b08
 </TASK>

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/04/13 12:11 linux-5.15.y cdfd0a7f0139 c8349e48 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-5-15-kasan possible deadlock in btrfs_dirty_inode
* Struck through repros no longer work on HEAD.