F2FS-fs (loop1): Mounted with checkpoint version = 48b305e5
F2FS-fs (loop1): f2fs_check_nid_range: out-of-range nid=1000000, run fsck to fix.
======================================================
WARNING: possible circular locking dependency detected
6.2.0-rc5-syzkaller-00047-g7c46948a6e9c #0 Not tainted
------------------------------------------------------
syz-executor.1/10739 is trying to acquire lock:
ffff88808121c088 (&sbi->sb_lock){++++}-{3:3}, at: f2fs_down_write fs/f2fs/f2fs.h:2213 [inline]
ffff88808121c088 (&sbi->sb_lock){++++}-{3:3}, at: f2fs_handle_error+0xe0/0x230 fs/f2fs/super.c:3926

but task is already holding lock:
ffff88802d19f308 (&fi->i_xattr_sem){.+.+}-{3:3}, at: f2fs_down_read fs/f2fs/f2fs.h:2188 [inline]
ffff88802d19f308 (&fi->i_xattr_sem){.+.+}-{3:3}, at: f2fs_getxattr+0x98/0x1490 fs/f2fs/xattr.c:530

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #5 (&fi->i_xattr_sem){.+.+}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       down_read+0x39/0x50 kernel/locking/rwsem.c:1509
       f2fs_down_read fs/f2fs/f2fs.h:2188 [inline]
       f2fs_getxattr+0x98/0x1490 fs/f2fs/xattr.c:530
       __f2fs_get_acl+0x52/0x900 fs/f2fs/acl.c:179
       f2fs_acl_create fs/f2fs/acl.c:377 [inline]
       f2fs_init_acl+0xd2/0x9b0 fs/f2fs/acl.c:420
       f2fs_init_inode_metadata+0x99a/0xf80 fs/f2fs/dir.c:591
       f2fs_add_regular_entry+0x8ce/0xea0 fs/f2fs/dir.c:775
       f2fs_add_dentry fs/f2fs/dir.c:816 [inline]
       f2fs_do_add_link+0x2a7/0x470 fs/f2fs/dir.c:855
       f2fs_add_link fs/f2fs/f2fs.h:3564 [inline]
       f2fs_create+0x324/0x530 fs/f2fs/namei.c:363
       lookup_open fs/namei.c:3413 [inline]
       open_last_lookups fs/namei.c:3481 [inline]
       path_openat+0x12ac/0x2dd0 fs/namei.c:3711
       do_filp_open+0x264/0x4f0 fs/namei.c:3741
       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 (&fi->i_sem){++++}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       down_write+0x9c/0x270 kernel/locking/rwsem.c:1562
       f2fs_down_write fs/f2fs/f2fs.h:2213 [inline]
       f2fs_add_regular_entry+0x8bc/0xea0 fs/f2fs/dir.c:774
       f2fs_add_dentry fs/f2fs/dir.c:816 [inline]
       f2fs_do_add_link+0x2a7/0x470 fs/f2fs/dir.c:855
       f2fs_add_link fs/f2fs/f2fs.h:3564 [inline]
       f2fs_create+0x324/0x530 fs/f2fs/namei.c:363
       lookup_open fs/namei.c:3413 [inline]
       open_last_lookups fs/namei.c:3481 [inline]
       path_openat+0x12ac/0x2dd0 fs/namei.c:3711
       do_filp_open+0x264/0x4f0 fs/namei.c:3741
       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 (&sbi->cp_rwsem){++++}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       down_read+0x39/0x50 kernel/locking/rwsem.c:1509
       f2fs_down_read fs/f2fs/f2fs.h:2188 [inline]
       f2fs_lock_op fs/f2fs/f2fs.h:2231 [inline]
       f2fs_zero_range+0x41b/0x16d0 fs/f2fs/file.c:1563
       f2fs_fallocate+0x470/0x6e0 fs/f2fs/file.c:1839
       vfs_fallocate+0x515/0x670 fs/open.c:323
       ksys_fallocate fs/open.c:346 [inline]
       __do_sys_fallocate fs/open.c:354 [inline]
       __se_sys_fallocate fs/open.c:352 [inline]
       __x64_sys_fallocate+0xb9/0x100 fs/open.c:352
       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

-> #2 (mapping.invalidate_lock#9){++++}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       down_read+0x39/0x50 kernel/locking/rwsem.c:1509
       filemap_invalidate_lock_shared include/linux/fs.h:811 [inline]
       filemap_fault+0x2fb/0x1060 mm/filemap.c:3146
       f2fs_filemap_fault+0x75/0xb0 fs/f2fs/file.c:44
       __do_fault+0x136/0x4f0 mm/memory.c:4163
       do_shared_fault mm/memory.c:4569 [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+0x18bc/0x26b0 mm/memory.c:5219
       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){++++}-{3:3}:
       lock_acquire+0x182/0x3c0 kernel/locking/lockdep.c:5668
       __might_fault+0xb2/0x110 mm/memory.c:5647
       _copy_to_user+0x26/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+0xaf72/0xb540 fs/f2fs/file.c:4169
       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 (&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+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_write+0x9c/0x270 kernel/locking/rwsem.c:1562
       f2fs_down_write fs/f2fs/f2fs.h:2213 [inline]
       f2fs_handle_error+0xe0/0x230 fs/f2fs/super.c:3926
       f2fs_check_nid_range fs/f2fs/node.c:39 [inline]
       __get_node_page+0xd9a/0x1570 fs/f2fs/node.c:1415
       read_xattr_block fs/f2fs/xattr.c:305 [inline]
       lookup_all_xattrs fs/f2fs/xattr.c:354 [inline]
       f2fs_getxattr+0x743/0x1490 fs/f2fs/xattr.c:531
       __f2fs_get_acl+0x52/0x900 fs/f2fs/acl.c:179
       f2fs_acl_create fs/f2fs/acl.c:377 [inline]
       f2fs_init_acl+0xd2/0x9b0 fs/f2fs/acl.c:420
       f2fs_init_inode_metadata+0x99a/0xf80 fs/f2fs/dir.c:591
       f2fs_add_regular_entry+0x8ce/0xea0 fs/f2fs/dir.c:775
       f2fs_add_dentry fs/f2fs/dir.c:816 [inline]
       f2fs_do_add_link+0x2a7/0x470 fs/f2fs/dir.c:855
       f2fs_add_link fs/f2fs/f2fs.h:3564 [inline]
       f2fs_mkdir+0x2ec/0x520 fs/f2fs/namei.c:767
       vfs_mkdir+0x3b3/0x590 fs/namei.c:4036
       do_mkdirat+0x25b/0x530 fs/namei.c:4061
       __do_sys_mkdir fs/namei.c:4081 [inline]
       __se_sys_mkdir fs/namei.c:4079 [inline]
       __x64_sys_mkdir+0x6a/0x80 fs/namei.c:4079
       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:
  &sbi->sb_lock --> &fi->i_sem --> &fi->i_xattr_sem

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&fi->i_xattr_sem);
                               lock(&fi->i_sem);
                               lock(&fi->i_xattr_sem);
  lock(&sbi->sb_lock);

 *** DEADLOCK ***

5 locks held by syz-executor.1/10739:
 #0: ffff888042668460 (sb_writers#15){.+.+}-{0:0}, at: mnt_want_write+0x3b/0x80 fs/namespace.c:508
 #1: ffff88802d19ec90 (&type->i_mutex_dir_key#10/1){+.+.}-{3:3}, at: inode_lock_nested include/linux/fs.h:791 [inline]
 #1: ffff88802d19ec90 (&type->i_mutex_dir_key#10/1){+.+.}-{3:3}, at: filename_create+0x22a/0x4f0 fs/namei.c:3807
 #2: ffff88808121c3b0 (&sbi->cp_rwsem){++++}-{3:3}, at: f2fs_down_read fs/f2fs/f2fs.h:2188 [inline]
 #2: ffff88808121c3b0 (&sbi->cp_rwsem){++++}-{3:3}, at: f2fs_lock_op fs/f2fs/f2fs.h:2231 [inline]
 #2: ffff88808121c3b0 (&sbi->cp_rwsem){++++}-{3:3}, at: f2fs_mkdir+0x21e/0x520 fs/f2fs/namei.c:766
 #3: ffff88802d19cca8 (&fi->i_sem){++++}-{3:3}, at: f2fs_down_write fs/f2fs/f2fs.h:2213 [inline]
 #3: ffff88802d19cca8 (&fi->i_sem){++++}-{3:3}, at: f2fs_add_regular_entry+0x8bc/0xea0 fs/f2fs/dir.c:774
 #4: ffff88802d19f308 (&fi->i_xattr_sem){.+.+}-{3:3}, at: f2fs_down_read fs/f2fs/f2fs.h:2188 [inline]
 #4: ffff88802d19f308 (&fi->i_xattr_sem){.+.+}-{3:3}, at: f2fs_getxattr+0x98/0x1490 fs/f2fs/xattr.c:530

stack backtrace:
CPU: 0 PID: 10739 Comm: syz-executor.1 Not tainted 6.2.0-rc5-syzkaller-00047-g7c46948a6e9c #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/12/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1b1/0x290 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_write+0x9c/0x270 kernel/locking/rwsem.c:1562
 f2fs_down_write fs/f2fs/f2fs.h:2213 [inline]
 f2fs_handle_error+0xe0/0x230 fs/f2fs/super.c:3926
 f2fs_check_nid_range fs/f2fs/node.c:39 [inline]
 __get_node_page+0xd9a/0x1570 fs/f2fs/node.c:1415
 read_xattr_block fs/f2fs/xattr.c:305 [inline]
 lookup_all_xattrs fs/f2fs/xattr.c:354 [inline]
 f2fs_getxattr+0x743/0x1490 fs/f2fs/xattr.c:531
 __f2fs_get_acl+0x52/0x900 fs/f2fs/acl.c:179
 f2fs_acl_create fs/f2fs/acl.c:377 [inline]
 f2fs_init_acl+0xd2/0x9b0 fs/f2fs/acl.c:420
 f2fs_init_inode_metadata+0x99a/0xf80 fs/f2fs/dir.c:591
 f2fs_add_regular_entry+0x8ce/0xea0 fs/f2fs/dir.c:775
 f2fs_add_dentry fs/f2fs/dir.c:816 [inline]
 f2fs_do_add_link+0x2a7/0x470 fs/f2fs/dir.c:855
 f2fs_add_link fs/f2fs/f2fs.h:3564 [inline]
 f2fs_mkdir+0x2ec/0x520 fs/f2fs/namei.c:767
 vfs_mkdir+0x3b3/0x590 fs/namei.c:4036
 do_mkdirat+0x25b/0x530 fs/namei.c:4061
 __do_sys_mkdir fs/namei.c:4081 [inline]
 __se_sys_mkdir fs/namei.c:4079 [inline]
 __x64_sys_mkdir+0x6a/0x80 fs/namei.c:4079
 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:0x7f41d2c8c0c9
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:00007f41d39d4168 EFLAGS: 00000246 ORIG_RAX: 0000000000000053
RAX: ffffffffffffffda RBX: 00007f41d2dabf80 RCX: 00007f41d2c8c0c9
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000020000040
RBP: 00007f41d2ce7ae9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffdfca5c7af R14: 00007f41d39d4300 R15: 0000000000022000
 </TASK>