F2FS-fs (loop4): Found nat_bits in checkpoint F2FS-fs (loop4): Mounted with checkpoint version = 48b305e5 F2FS-fs (loop4): f2fs_check_nid_range: out-of-range nid=1, run fsck to fix. ====================================================== WARNING: possible circular locking dependency detected 6.2.0-rc7-syzkaller-00199-g420b2d431d18 #0 Not tainted ------------------------------------------------------ syz-executor.4/10548 is trying to acquire lock: ffff888021a48088 (&sbi->sb_lock){++++}-{3:3}, at: f2fs_down_write fs/f2fs/f2fs.h:2213 [inline] ffff888021a48088 (&sbi->sb_lock){++++}-{3:3}, at: f2fs_handle_error+0xef/0x240 fs/f2fs/super.c:3926 but task is already holding lock: ffff888028239930 (&nm_i->nat_tree_lock){++++}-{3:3}, at: f2fs_down_read fs/f2fs/f2fs.h:2188 [inline] ffff888028239930 (&nm_i->nat_tree_lock){++++}-{3:3}, at: scan_free_nid_bits fs/f2fs/node.c:2425 [inline] ffff888028239930 (&nm_i->nat_tree_lock){++++}-{3:3}, at: __f2fs_build_free_nids fs/f2fs/node.c:2473 [inline] ffff888028239930 (&nm_i->nat_tree_lock){++++}-{3:3}, at: f2fs_build_free_nids+0x325/0x11a0 fs/f2fs/node.c:2531 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #5 (&nm_i->nat_tree_lock){++++}-{3:3}: lock_acquire+0x235/0x630 kernel/locking/lockdep.c:5668 down_read+0x3d/0x50 kernel/locking/rwsem.c:1509 f2fs_down_read fs/f2fs/f2fs.h:2188 [inline] f2fs_get_node_info+0xf3/0x12d0 fs/f2fs/node.c:564 __write_node_page+0x70c/0x2730 fs/f2fs/node.c:1616 f2fs_sync_node_pages+0xed4/0x16f0 fs/f2fs/node.c:2020 block_operations fs/f2fs/checkpoint.c:1275 [inline] f2fs_write_checkpoint+0xe55/0x1ce0 fs/f2fs/checkpoint.c:1655 __write_checkpoint_sync fs/f2fs/checkpoint.c:1772 [inline] __checkpoint_and_complete_reqs+0xda/0x3b0 fs/f2fs/checkpoint.c:1791 issue_checkpoint_thread+0xda/0x260 fs/f2fs/checkpoint.c:1822 kthread+0x270/0x300 kernel/kthread.c:376 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308 -> #4 (&sbi->node_change){++++}-{3:3}: lock_acquire+0x235/0x630 kernel/locking/lockdep.c:5668 down_read+0x3d/0x50 kernel/locking/rwsem.c:1509 f2fs_vm_page_mkwrite+0x767/0x1440 fs/f2fs/file.c:116 do_page_mkwrite+0x1a1/0x600 mm/memory.c:2943 do_shared_fault mm/memory.c:4579 [inline] do_fault mm/memory.c:4647 [inline] handle_pte_fault mm/memory.c:4931 [inline] __handle_mm_fault mm/memory.c:5073 [inline] handle_mm_fault+0x2163/0x51e0 mm/memory.c:5219 do_user_addr_fault arch/x86/mm/fault.c:1428 [inline] handle_page_fault arch/x86/mm/fault.c:1519 [inline] exc_page_fault+0x673/0x880 arch/x86/mm/fault.c:1575 asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:570 copy_user_enhanced_fast_string+0xe/0x40 arch/x86/lib/copy_user_64.S:165 copy_user_generic arch/x86/include/asm/uaccess_64.h:37 [inline] raw_copy_to_user arch/x86/include/asm/uaccess_64.h:58 [inline] copyout lib/iov_iter.c:170 [inline] _copy_to_iter+0x2f6/0x1070 lib/iov_iter.c:529 copy_page_to_iter+0xe7/0x1d0 lib/iov_iter.c:727 copy_folio_to_iter include/linux/uio.h:172 [inline] filemap_read+0x276d/0x3220 mm/filemap.c:2745 f2fs_file_read_iter+0x139/0xf20 fs/f2fs/file.c:4374 call_read_iter include/linux/fs.h:2183 [inline] new_sync_read fs/read_write.c:389 [inline] vfs_read+0x7e2/0xbe0 fs/read_write.c:470 ksys_read+0x1a0/0x2c0 fs/read_write.c:613 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd -> #3 (mapping.invalidate_lock#8){.+.+}-{3:3}: lock_acquire+0x235/0x630 kernel/locking/lockdep.c:5668 down_read+0x3d/0x50 kernel/locking/rwsem.c:1509 filemap_invalidate_lock_shared include/linux/fs.h:811 [inline] f2fs_vm_page_mkwrite+0x547/0x1440 fs/f2fs/file.c:104 do_page_mkwrite+0x1a1/0x600 mm/memory.c:2943 do_shared_fault mm/memory.c:4579 [inline] do_fault mm/memory.c:4647 [inline] handle_pte_fault mm/memory.c:4931 [inline] __handle_mm_fault mm/memory.c:5073 [inline] handle_mm_fault+0x2163/0x51e0 mm/memory.c:5219 do_user_addr_fault arch/x86/mm/fault.c:1428 [inline] handle_page_fault arch/x86/mm/fault.c:1519 [inline] exc_page_fault+0x673/0x880 arch/x86/mm/fault.c:1575 asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:570 copy_user_enhanced_fast_string+0xe/0x40 arch/x86/lib/copy_user_64.S:165 copy_user_generic arch/x86/include/asm/uaccess_64.h:37 [inline] raw_copy_to_user arch/x86/include/asm/uaccess_64.h:58 [inline] copyout lib/iov_iter.c:170 [inline] _copy_to_iter+0x2f6/0x1070 lib/iov_iter.c:529 copy_page_to_iter+0xe7/0x1d0 lib/iov_iter.c:727 copy_folio_to_iter include/linux/uio.h:172 [inline] filemap_read+0x276d/0x3220 mm/filemap.c:2745 f2fs_file_read_iter+0x139/0xf20 fs/f2fs/file.c:4374 call_read_iter include/linux/fs.h:2183 [inline] new_sync_read fs/read_write.c:389 [inline] vfs_read+0x7e2/0xbe0 fs/read_write.c:470 ksys_read+0x1a0/0x2c0 fs/read_write.c:613 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd -> #2 (sb_pagefaults#2){.+.+}-{0:0}: lock_acquire+0x235/0x630 kernel/locking/lockdep.c:5668 percpu_down_read include/linux/percpu-rwsem.h:51 [inline] __sb_start_write+0x58/0x1a0 include/linux/fs.h:1814 sb_start_pagefault include/linux/fs.h:1918 [inline] f2fs_vm_page_mkwrite+0x47b/0x1440 fs/f2fs/file.c:99 do_page_mkwrite+0x1a1/0x600 mm/memory.c:2943 do_shared_fault mm/memory.c:4579 [inline] do_fault mm/memory.c:4647 [inline] handle_pte_fault mm/memory.c:4931 [inline] __handle_mm_fault mm/memory.c:5073 [inline] handle_mm_fault+0x2163/0x51e0 mm/memory.c:5219 do_user_addr_fault arch/x86/mm/fault.c:1428 [inline] handle_page_fault arch/x86/mm/fault.c:1519 [inline] exc_page_fault+0x673/0x880 arch/x86/mm/fault.c:1575 asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:570 copy_user_enhanced_fast_string+0xe/0x40 arch/x86/lib/copy_user_64.S:165 copy_user_generic arch/x86/include/asm/uaccess_64.h:37 [inline] raw_copy_to_user arch/x86/include/asm/uaccess_64.h:58 [inline] copyout lib/iov_iter.c:170 [inline] _copy_to_iter+0x2f6/0x1070 lib/iov_iter.c:529 copy_page_to_iter+0xe7/0x1d0 lib/iov_iter.c:727 copy_folio_to_iter include/linux/uio.h:172 [inline] filemap_read+0x276d/0x3220 mm/filemap.c:2745 f2fs_file_read_iter+0x139/0xf20 fs/f2fs/file.c:4374 call_read_iter include/linux/fs.h:2183 [inline] new_sync_read fs/read_write.c:389 [inline] vfs_read+0x7e2/0xbe0 fs/read_write.c:470 ksys_read+0x1a0/0x2c0 fs/read_write.c:613 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd -> #1 (&mm->mmap_lock){++++}-{3:3}: lock_acquire+0x235/0x630 kernel/locking/lockdep.c:5668 __might_fault+0xba/0x120 mm/memory.c:5647 _copy_to_user+0x2a/0x130 lib/usercopy.c:29 copy_to_user include/linux/uaccess.h:169 [inline] f2fs_ioc_get_encryption_pwsalt fs/f2fs/file.c:2365 [inline] __f2fs_ioctl+0xaf1d/0xb500 fs/f2fs/file.c:4169 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:870 [inline] __se_sys_ioctl+0xf1/0x160 fs/ioctl.c:856 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd -> #0 (&sbi->sb_lock){++++}-{3:3}: check_prev_add kernel/locking/lockdep.c:3097 [inline] check_prevs_add kernel/locking/lockdep.c:3216 [inline] validate_chain+0x166b/0x58e0 kernel/locking/lockdep.c:3831 __lock_acquire+0x125b/0x1f80 kernel/locking/lockdep.c:5055 lock_acquire+0x235/0x630 kernel/locking/lockdep.c:5668 down_write+0x3a/0x60 kernel/locking/rwsem.c:1562 f2fs_down_write fs/f2fs/f2fs.h:2213 [inline] f2fs_handle_error+0xef/0x240 fs/f2fs/super.c:3926 scan_free_nid_bits fs/f2fs/node.c:2439 [inline] __f2fs_build_free_nids fs/f2fs/node.c:2473 [inline] f2fs_build_free_nids+0x514/0x11a0 fs/f2fs/node.c:2531 f2fs_alloc_nid+0x221/0x740 fs/f2fs/node.c:2577 f2fs_new_inode+0x135/0x1090 fs/f2fs/namei.c:221 f2fs_mkdir+0x127/0x530 fs/f2fs/namei.c:756 vfs_mkdir+0x3ba/0x590 fs/namei.c:4036 do_mkdirat+0x246/0x500 fs/namei.c:4061 __do_sys_mkdirat fs/namei.c:4076 [inline] __se_sys_mkdirat fs/namei.c:4074 [inline] __x64_sys_mkdirat+0x89/0xa0 fs/namei.c:4074 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd other info that might help us debug this: Chain exists of: &sbi->sb_lock --> &sbi->node_change --> &nm_i->nat_tree_lock Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(&nm_i->nat_tree_lock); lock(&sbi->node_change); lock(&nm_i->nat_tree_lock); lock(&sbi->sb_lock); *** DEADLOCK *** 4 locks held by syz-executor.4/10548: #0: ffff888020edc460 (sb_writers#18){.+.+}-{0:0}, at: mnt_want_write+0x3f/0x90 fs/namespace.c:508 #1: ffff888072928a40 (&type->i_mutex_dir_key#11/1){+.+.}-{3:3}, at: inode_lock_nested include/linux/fs.h:791 [inline] #1: ffff888072928a40 (&type->i_mutex_dir_key#11/1){+.+.}-{3:3}, at: filename_create+0x25a/0x530 fs/namei.c:3807 #2: ffff888028239ac8 (&nm_i->build_lock){+.+.}-{3:3}, at: f2fs_build_free_nids+0xcc/0x11a0 fs/f2fs/node.c:2530 #3: ffff888028239930 (&nm_i->nat_tree_lock){++++}-{3:3}, at: f2fs_down_read fs/f2fs/f2fs.h:2188 [inline] #3: ffff888028239930 (&nm_i->nat_tree_lock){++++}-{3:3}, at: scan_free_nid_bits fs/f2fs/node.c:2425 [inline] #3: ffff888028239930 (&nm_i->nat_tree_lock){++++}-{3:3}, at: __f2fs_build_free_nids fs/f2fs/node.c:2473 [inline] #3: ffff888028239930 (&nm_i->nat_tree_lock){++++}-{3:3}, at: f2fs_build_free_nids+0x325/0x11a0 fs/f2fs/node.c:2531 stack backtrace: CPU: 1 PID: 10548 Comm: syz-executor.4 Not tainted 6.2.0-rc7-syzkaller-00199-g420b2d431d18 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/21/2023 Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x1e7/0x2d0 lib/dump_stack.c:106 check_noncircular+0x2fe/0x3b0 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+0x166b/0x58e0 kernel/locking/lockdep.c:3831 __lock_acquire+0x125b/0x1f80 kernel/locking/lockdep.c:5055 lock_acquire+0x235/0x630 kernel/locking/lockdep.c:5668 down_write+0x3a/0x60 kernel/locking/rwsem.c:1562 f2fs_down_write fs/f2fs/f2fs.h:2213 [inline] f2fs_handle_error+0xef/0x240 fs/f2fs/super.c:3926 scan_free_nid_bits fs/f2fs/node.c:2439 [inline] __f2fs_build_free_nids fs/f2fs/node.c:2473 [inline] f2fs_build_free_nids+0x514/0x11a0 fs/f2fs/node.c:2531 f2fs_alloc_nid+0x221/0x740 fs/f2fs/node.c:2577 f2fs_new_inode+0x135/0x1090 fs/f2fs/namei.c:221 f2fs_mkdir+0x127/0x530 fs/f2fs/namei.c:756 vfs_mkdir+0x3ba/0x590 fs/namei.c:4036 do_mkdirat+0x246/0x500 fs/namei.c:4061 __do_sys_mkdirat fs/namei.c:4076 [inline] __se_sys_mkdirat fs/namei.c:4074 [inline] __x64_sys_mkdirat+0x89/0xa0 fs/namei.c:4074 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd RIP: 0033:0x7f9ad5e8c0f9 Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 19 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 b8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f9ad6b71168 EFLAGS: 00000246 ORIG_RAX: 0000000000000102 RAX: ffffffffffffffda RBX: 00007f9ad5fabf80 RCX: 00007f9ad5e8c0f9 RDX: 0000000000000000 RSI: 0000000020000000 RDI: ffffffffffffff9c RBP: 00007f9ad5ee7ae9 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007ffe6d52caef R14: 00007f9ad6b71300 R15: 0000000000022000 F2FS-fs (loop4): f2fs_check_nid_range: out-of-range nid=2, run fsck to fix. F2FS-fs (loop4): Inconsistent i_blocks, ino:8, iblocks:0, sectors:8