syzbot


possible deadlock in btrfs_page_mkwrite (2)

Status: upstream: reported on 2024/11/24 04:23
Reported-by: syzbot+6a2724ea3346ab3e5530@syzkaller.appspotmail.com
First crash: 27d, last: 27d
Similar bugs (1)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-5.15 possible deadlock in btrfs_page_mkwrite 2 154d 243d 0/3 auto-obsoleted due to no activity on 2024/10/27 17:02

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
5.15.173-syzkaller #0 Not tainted
------------------------------------------------------
syz.1.110/4838 is trying to acquire lock:
ffff0000e92b0498 (&ei->i_mmap_lock){++++}-{3:3}, at: btrfs_page_mkwrite+0x530/0xde8 fs/btrfs/inode.c:8950

but task is already holding lock:
ffff0000e265c558 (sb_pagefaults#3){.+.+}-{0:0}, at: do_page_mkwrite+0x144/0x37c mm/memory.c:2920

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #7 (sb_pagefaults#3){.+.+}-{0:0}:
       percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
       __sb_start_write include/linux/fs.h:1813 [inline]
       sb_start_pagefault include/linux/fs.h:1912 [inline]
       btrfs_page_mkwrite+0x254/0xde8 fs/btrfs/inode.c:8922
       do_page_mkwrite+0x144/0x37c mm/memory.c:2920
       wp_page_shared+0x14c/0x398 mm/memory.c:3257
       do_wp_page+0x7cc/0x9c4 mm/memory.c:3358
       handle_pte_fault mm/memory.c:4666 [inline]
       __handle_mm_fault mm/memory.c:4783 [inline]
       handle_mm_fault+0x1bdc/0x33a8 mm/memory.c:4881
       __do_page_fault arch/arm64/mm/fault.c:505 [inline]
       do_page_fault+0x700/0xb60 arch/arm64/mm/fault.c:605
       do_mem_abort+0x70/0x1d8 arch/arm64/mm/fault.c:819
       el0_da+0x94/0x20c arch/arm64/kernel/entry-common.c:494
       el0t_64_sync_handler+0xc0/0xe4 arch/arm64/kernel/entry-common.c:629
       el0t_64_sync+0x1a0/0x1a4 arch/arm64/kernel/entry.S:584

-> #6 (&mm->mmap_lock){++++}-{3:3}:
       __might_fault+0xc8/0x128 mm/memory.c:5355
       filldir64+0x2bc/0x9e4 fs/readdir.c:335
       dir_emit_dot include/linux/fs.h:3721 [inline]
       hfsplus_readdir+0x398/0xf68 fs/hfsplus/dir.c:159
       iterate_dir+0x1f4/0x4ec
       __do_sys_getdents64 fs/readdir.c:369 [inline]
       __se_sys_getdents64 fs/readdir.c:354 [inline]
       __arm64_sys_getdents64+0x1c4/0x4c4 fs/readdir.c:354
       __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
       invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:52
       el0_svc_common+0x138/0x258 arch/arm64/kernel/syscall.c:142
       do_el0_svc+0x58/0x14c arch/arm64/kernel/syscall.c:181
       el0_svc+0x7c/0x1f0 arch/arm64/kernel/entry-common.c:608
       el0t_64_sync_handler+0x84/0xe4 arch/arm64/kernel/entry-common.c:626
       el0t_64_sync+0x1a0/0x1a4 arch/arm64/kernel/entry.S:584

-> #5 (&tree->tree_lock){+.+.}-{3:3}:
       __mutex_lock_common+0x194/0x2154 kernel/locking/mutex.c:596
       __mutex_lock kernel/locking/mutex.c:729 [inline]
       mutex_lock_nested+0xa4/0xf8 kernel/locking/mutex.c:743
       hfsplus_find_init+0x144/0x1bc fs/hfsplus/bfind.c:28
       hfsplus_lookup+0x17c/0x98c fs/hfsplus/dir.c:44
       __lookup_slow+0x250/0x388 fs/namei.c:1663
       lookup_slow+0x60/0x84 fs/namei.c:1680
       walk_component+0x394/0x4cc fs/namei.c:1976
       lookup_last fs/namei.c:2431 [inline]
       path_lookupat+0x13c/0x3d0 fs/namei.c:2455
       filename_lookup+0x1c4/0x4c8 fs/namei.c:2484
       user_path_at_empty+0x5c/0x1a4 fs/namei.c:2883
       user_path_at include/linux/namei.h:57 [inline]
       do_sys_truncate+0xb4/0x1b4 fs/open.c:132
       __do_sys_truncate fs/open.c:146 [inline]
       __se_sys_truncate fs/open.c:144 [inline]
       __arm64_sys_truncate+0x5c/0x70 fs/open.c:144
       __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
       invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:52
       el0_svc_common+0x138/0x258 arch/arm64/kernel/syscall.c:142
       do_el0_svc+0x58/0x14c arch/arm64/kernel/syscall.c:181
       el0_svc+0x7c/0x1f0 arch/arm64/kernel/entry-common.c:608
       el0t_64_sync_handler+0x84/0xe4 arch/arm64/kernel/entry-common.c:626
       el0t_64_sync+0x1a0/0x1a4 arch/arm64/kernel/entry.S:584

-> #4 (&type->i_mutex_dir_key#14){.+.+}-{3:3}:
       down_read+0xc0/0x398 kernel/locking/rwsem.c:1498
       inode_lock_shared include/linux/fs.h:799 [inline]
       lookup_slow+0x50/0x84 fs/namei.c:1679
       walk_component+0x394/0x4cc fs/namei.c:1976
       lookup_last fs/namei.c:2431 [inline]
       path_lookupat+0x13c/0x3d0 fs/namei.c:2455
       filename_lookup+0x1c4/0x4c8 fs/namei.c:2484
       kern_path+0x4c/0x194 fs/namei.c:2582
       lookup_bdev+0xc0/0x25c block/bdev.c:979
       device_matched fs/btrfs/volumes.c:568 [inline]
       btrfs_free_stale_devices+0x658/0x9ec fs/btrfs/volumes.c:608
       btrfs_forget_devices+0x5c/0x98 fs/btrfs/volumes.c:1395
       btrfs_control_ioctl+0x12c/0x248 fs/btrfs/super.c:2451
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:874 [inline]
       __se_sys_ioctl fs/ioctl.c:860 [inline]
       __arm64_sys_ioctl+0x14c/0x1c8 fs/ioctl.c:860
       __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
       invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:52
       el0_svc_common+0x138/0x258 arch/arm64/kernel/syscall.c:142
       do_el0_svc+0x58/0x14c arch/arm64/kernel/syscall.c:181
       el0_svc+0x7c/0x1f0 arch/arm64/kernel/entry-common.c:608
       el0t_64_sync_handler+0x84/0xe4 arch/arm64/kernel/entry-common.c:626
       el0t_64_sync+0x1a0/0x1a4 arch/arm64/kernel/entry.S:584

-> #3 (&fs_devs->device_list_mutex){+.+.}-{3:3}:
       __mutex_lock_common+0x194/0x2154 kernel/locking/mutex.c:596
       __mutex_lock kernel/locking/mutex.c:729 [inline]
       mutex_lock_nested+0xa4/0xf8 kernel/locking/mutex.c:743
       btrfs_run_dev_stats+0xe4/0xe24 fs/btrfs/volumes.c:7949
       commit_cowonly_roots+0x17c/0x808 fs/btrfs/transaction.c:1290
       btrfs_commit_transaction+0xef4/0x30f0 fs/btrfs/transaction.c:2392
       btrfs_clear_free_space_tree+0x5d0/0x9bc fs/btrfs/free-space-tree.c:1264
       btrfs_start_pre_rw_mount+0x24c/0x578 fs/btrfs/disk-io.c:3079
       open_ctree+0x2290/0x28f4 fs/btrfs/disk-io.c:3634
       btrfs_fill_super+0x1b4/0x2c8 fs/btrfs/super.c:1387
       btrfs_mount_root+0x6f8/0x7f8 fs/btrfs/super.c:1752
       legacy_get_tree+0xd4/0x16c fs/fs_context.c:611
       vfs_get_tree+0x90/0x274 fs/super.c:1530
       fc_mount fs/namespace.c:1000 [inline]
       vfs_kern_mount+0xdc/0x178 fs/namespace.c:1030
       btrfs_mount+0x328/0x9b8 fs/btrfs/super.c:1812
       legacy_get_tree+0xd4/0x16c fs/fs_context.c:611
       vfs_get_tree+0x90/0x274 fs/super.c:1530
       do_new_mount+0x278/0x8fc fs/namespace.c:3012
       path_mount+0x594/0x101c fs/namespace.c:3342
       do_mount fs/namespace.c:3355 [inline]
       __do_sys_mount fs/namespace.c:3563 [inline]
       __se_sys_mount fs/namespace.c:3540 [inline]
       __arm64_sys_mount+0x510/0x5e0 fs/namespace.c:3540
       __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
       invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:52
       el0_svc_common+0x138/0x258 arch/arm64/kernel/syscall.c:142
       do_el0_svc+0x58/0x14c arch/arm64/kernel/syscall.c:181
       el0_svc+0x7c/0x1f0 arch/arm64/kernel/entry-common.c:608
       el0t_64_sync_handler+0x84/0xe4 arch/arm64/kernel/entry-common.c:626
       el0t_64_sync+0x1a0/0x1a4 arch/arm64/kernel/entry.S:584

-> #2 (&fs_info->tree_log_mutex){+.+.}-{3:3}:
       __lock_release kernel/locking/lockdep.c:5339 [inline]
       lock_release+0x340/0xa1c kernel/locking/lockdep.c:5643
       __mutex_unlock_slowpath+0xe0/0x6d4 kernel/locking/mutex.c:851
       mutex_unlock+0x8c/0xe0 kernel/locking/mutex.c:536
       btrfs_commit_transaction+0x1650/0x30f0 fs/btrfs/transaction.c:2439
       btrfs_clear_free_space_tree+0x5d0/0x9bc fs/btrfs/free-space-tree.c:1264
       btrfs_start_pre_rw_mount+0x24c/0x578 fs/btrfs/disk-io.c:3079
       open_ctree+0x2290/0x28f4 fs/btrfs/disk-io.c:3634
       btrfs_fill_super+0x1b4/0x2c8 fs/btrfs/super.c:1387
       btrfs_mount_root+0x6f8/0x7f8 fs/btrfs/super.c:1752
       legacy_get_tree+0xd4/0x16c fs/fs_context.c:611
       vfs_get_tree+0x90/0x274 fs/super.c:1530
       fc_mount fs/namespace.c:1000 [inline]
       vfs_kern_mount+0xdc/0x178 fs/namespace.c:1030
       btrfs_mount+0x328/0x9b8 fs/btrfs/super.c:1812
       legacy_get_tree+0xd4/0x16c fs/fs_context.c:611
       vfs_get_tree+0x90/0x274 fs/super.c:1530
       do_new_mount+0x278/0x8fc fs/namespace.c:3012
       path_mount+0x594/0x101c fs/namespace.c:3342
       do_mount fs/namespace.c:3355 [inline]
       __do_sys_mount fs/namespace.c:3563 [inline]
       __se_sys_mount fs/namespace.c:3540 [inline]
       __arm64_sys_mount+0x510/0x5e0 fs/namespace.c:3540
       __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
       invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:52
       el0_svc_common+0x138/0x258 arch/arm64/kernel/syscall.c:142
       do_el0_svc+0x58/0x14c arch/arm64/kernel/syscall.c:181
       el0_svc+0x7c/0x1f0 arch/arm64/kernel/entry-common.c:608
       el0t_64_sync_handler+0x84/0xe4 arch/arm64/kernel/entry-common.c:626
       el0t_64_sync+0x1a0/0x1a4 arch/arm64/kernel/entry.S:584

-> #1 (sb_internal#5){.+.+}-{0:0}:
       percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
       __sb_start_write include/linux/fs.h:1813 [inline]
       sb_start_intwrite include/linux/fs.h:1930 [inline]
       start_transaction+0x644/0x1480 fs/btrfs/transaction.c:678
       btrfs_join_transaction+0x30/0x40 fs/btrfs/transaction.c:791
       btrfs_dirty_inode+0xb4/0x1c0 fs/btrfs/inode.c:6436
       btrfs_update_time+0x248/0x270 fs/btrfs/inode.c:6478
       inode_update_time fs/inode.c:1868 [inline]
       file_update_time+0x35c/0x3f0 fs/inode.c:2058
       file_modified+0x74/0xb4 fs/inode.c:2081
       generic_remap_file_range_prep+0x924/0x9c8 fs/remap_range.c:358
       btrfs_remap_file_range_prep fs/btrfs/reflink.c:847 [inline]
       btrfs_remap_file_range+0x470/0xc08 fs/btrfs/reflink.c:880
       vfs_copy_file_range+0xad4/0x1138 fs/read_write.c:1510
       __do_sys_copy_file_range fs/read_write.c:1588 [inline]
       __se_sys_copy_file_range fs/read_write.c:1551 [inline]
       __arm64_sys_copy_file_range+0x5f8/0x9d8 fs/read_write.c:1551
       __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
       invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:52
       el0_svc_common+0x138/0x258 arch/arm64/kernel/syscall.c:142
       do_el0_svc+0x58/0x14c arch/arm64/kernel/syscall.c:181
       el0_svc+0x7c/0x1f0 arch/arm64/kernel/entry-common.c:608
       el0t_64_sync_handler+0x84/0xe4 arch/arm64/kernel/entry-common.c:626
       el0t_64_sync+0x1a0/0x1a4 arch/arm64/kernel/entry.S:584

-> #0 (&ei->i_mmap_lock){++++}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3053 [inline]
       check_prevs_add kernel/locking/lockdep.c:3172 [inline]
       validate_chain kernel/locking/lockdep.c:3788 [inline]
       __lock_acquire+0x32d4/0x7638 kernel/locking/lockdep.c:5012
       lock_acquire+0x240/0x77c kernel/locking/lockdep.c:5623
       down_read+0xc0/0x398 kernel/locking/rwsem.c:1498
       btrfs_page_mkwrite+0x530/0xde8 fs/btrfs/inode.c:8950
       do_page_mkwrite+0x144/0x37c mm/memory.c:2920
       wp_page_shared+0x14c/0x398 mm/memory.c:3257
       do_wp_page+0x7cc/0x9c4 mm/memory.c:3358
       handle_pte_fault mm/memory.c:4666 [inline]
       __handle_mm_fault mm/memory.c:4783 [inline]
       handle_mm_fault+0x1bdc/0x33a8 mm/memory.c:4881
       __do_page_fault arch/arm64/mm/fault.c:505 [inline]
       do_page_fault+0x700/0xb60 arch/arm64/mm/fault.c:605
       do_mem_abort+0x70/0x1d8 arch/arm64/mm/fault.c:819
       el0_da+0x94/0x20c arch/arm64/kernel/entry-common.c:494
       el0t_64_sync_handler+0xc0/0xe4 arch/arm64/kernel/entry-common.c:629
       el0t_64_sync+0x1a0/0x1a4 arch/arm64/kernel/entry.S:584

other info that might help us debug this:

Chain exists of:
  &ei->i_mmap_lock --> &mm->mmap_lock --> sb_pagefaults#3

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(sb_pagefaults#3);
                               lock(&mm->mmap_lock);
                               lock(sb_pagefaults#3);
  lock(&ei->i_mmap_lock);

 *** DEADLOCK ***

2 locks held by syz.1.110/4838:
 #0: ffff0000c901a958 (&mm->mmap_lock){++++}-{3:3}, at: mmap_read_trylock include/linux/mmap_lock.h:136 [inline]
 #0: ffff0000c901a958 (&mm->mmap_lock){++++}-{3:3}, at: do_page_fault+0x380/0xb60 arch/arm64/mm/fault.c:586
 #1: ffff0000e265c558 (sb_pagefaults#3){.+.+}-{0:0}, at: do_page_mkwrite+0x144/0x37c mm/memory.c:2920

stack backtrace:
CPU: 1 PID: 4838 Comm: syz.1.110 Not tainted 5.15.173-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
Call trace:
 dump_backtrace+0x0/0x530 arch/arm64/kernel/stacktrace.c:152
 show_stack+0x2c/0x3c arch/arm64/kernel/stacktrace.c:216
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x108/0x170 lib/dump_stack.c:106
 dump_stack+0x1c/0x58 lib/dump_stack.c:113
 print_circular_bug+0x150/0x1b8 kernel/locking/lockdep.c:2011
 check_noncircular+0x2cc/0x378 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 kernel/locking/lockdep.c:3788 [inline]
 __lock_acquire+0x32d4/0x7638 kernel/locking/lockdep.c:5012
 lock_acquire+0x240/0x77c kernel/locking/lockdep.c:5623
 down_read+0xc0/0x398 kernel/locking/rwsem.c:1498
 btrfs_page_mkwrite+0x530/0xde8 fs/btrfs/inode.c:8950
 do_page_mkwrite+0x144/0x37c mm/memory.c:2920
 wp_page_shared+0x14c/0x398 mm/memory.c:3257
 do_wp_page+0x7cc/0x9c4 mm/memory.c:3358
 handle_pte_fault mm/memory.c:4666 [inline]
 __handle_mm_fault mm/memory.c:4783 [inline]
 handle_mm_fault+0x1bdc/0x33a8 mm/memory.c:4881
 __do_page_fault arch/arm64/mm/fault.c:505 [inline]
 do_page_fault+0x700/0xb60 arch/arm64/mm/fault.c:605
 do_mem_abort+0x70/0x1d8 arch/arm64/mm/fault.c:819
 el0_da+0x94/0x20c arch/arm64/kernel/entry-common.c:494
 el0t_64_sync_handler+0xc0/0xe4 arch/arm64/kernel/entry-common.c:629
 el0t_64_sync+0x1a0/0x1a4 arch/arm64/kernel/entry.S:584

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