F2FS-fs (loop3): invalid crc value
F2FS-fs (loop3): Found nat_bits in checkpoint
F2FS-fs (loop3): Mounted with checkpoint version = 48b305e4
======================================================
WARNING: possible circular locking dependency detected
6.5.0-rc7-syzkaller-gfe4469582053 #0 Not tainted
------------------------------------------------------
syz-executor.3/11291 is trying to acquire lock:
ffff0001344c3160 (&fi->i_sem){+.+.}-{3:3}, at: f2fs_down_write fs/f2fs/f2fs.h:2133 [inline]
ffff0001344c3160 (&fi->i_sem){+.+.}-{3:3}, at: f2fs_add_inline_entry+0x350/0x650 fs/f2fs/inline.c:644

but task is already holding lock:
ffff0001344c1978 (&fi->i_xattr_sem){.+.+}-{3:3}, at: f2fs_down_read fs/f2fs/f2fs.h:2108 [inline]
ffff0001344c1978 (&fi->i_xattr_sem){.+.+}-{3:3}, at: f2fs_add_dentry fs/f2fs/dir.c:783 [inline]
ffff0001344c1978 (&fi->i_xattr_sem){.+.+}-{3:3}, at: f2fs_do_add_link+0x2ac/0x5a4 fs/f2fs/dir.c:827

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&fi->i_xattr_sem){.+.+}-{3:3}:
       down_read+0x58/0x2fc kernel/locking/rwsem.c:1520
       f2fs_down_read fs/f2fs/f2fs.h:2108 [inline]
       f2fs_getxattr+0x9c/0x11b0 fs/f2fs/xattr.c:532
       __f2fs_get_acl+0x6c/0x5e4 fs/f2fs/acl.c:179
       f2fs_acl_create fs/f2fs/acl.c:377 [inline]
       f2fs_init_acl+0xe8/0x8f0 fs/f2fs/acl.c:420
       f2fs_init_inode_metadata+0x840/0x11a8 fs/f2fs/dir.c:558
       f2fs_add_regular_entry+0x760/0xe0c fs/f2fs/dir.c:740
       f2fs_add_dentry fs/f2fs/dir.c:788 [inline]
       f2fs_do_add_link+0x300/0x5a4 fs/f2fs/dir.c:827
       f2fs_add_link fs/f2fs/f2fs.h:3554 [inline]
       f2fs_create+0x2c0/0x494 fs/f2fs/namei.c:377
       lookup_open fs/namei.c:3492 [inline]
       open_last_lookups fs/namei.c:3560 [inline]
       path_openat+0xf80/0x27f8 fs/namei.c:3790
       do_filp_open+0x1bc/0x3cc fs/namei.c:3820
       do_sys_openat2+0x124/0x1b8 fs/open.c:1407
       do_sys_open fs/open.c:1422 [inline]
       __do_sys_openat fs/open.c:1438 [inline]
       __se_sys_openat fs/open.c:1433 [inline]
       __arm64_sys_openat+0x1f0/0x240 fs/open.c:1433
       __invoke_syscall arch/arm64/kernel/syscall.c:37 [inline]
       invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51
       el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136
       do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155
       el0_svc+0x58/0x16c arch/arm64/kernel/entry-common.c:678
       el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
       el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:591

-> #0 (&fi->i_sem){+.+.}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3142 [inline]
       check_prevs_add kernel/locking/lockdep.c:3261 [inline]
       validate_chain kernel/locking/lockdep.c:3876 [inline]
       __lock_acquire+0x3370/0x75e8 kernel/locking/lockdep.c:5144
       lock_acquire+0x23c/0x71c kernel/locking/lockdep.c:5761
       down_write+0x50/0xc0 kernel/locking/rwsem.c:1573
       f2fs_down_write fs/f2fs/f2fs.h:2133 [inline]
       f2fs_add_inline_entry+0x350/0x650 fs/f2fs/inline.c:644
       f2fs_add_dentry fs/f2fs/dir.c:784 [inline]
       f2fs_do_add_link+0x2c4/0x5a4 fs/f2fs/dir.c:827
       f2fs_add_link+0xd0/0x120 fs/f2fs/f2fs.h:3554
       f2fs_rename fs/f2fs/namei.c:1097 [inline]
       f2fs_rename2+0x1814/0x2138 fs/f2fs/namei.c:1332
       vfs_rename+0x830/0xbe4 fs/namei.c:4857
       do_renameat2+0x9f4/0x10b0 fs/namei.c:5009
       __do_sys_renameat2 fs/namei.c:5042 [inline]
       __se_sys_renameat2 fs/namei.c:5039 [inline]
       __arm64_sys_renameat2+0xe0/0xfc fs/namei.c:5039
       __invoke_syscall arch/arm64/kernel/syscall.c:37 [inline]
       invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51
       el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136
       do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155
       el0_svc+0x58/0x16c arch/arm64/kernel/entry-common.c:678
       el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
       el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:591

other info that might help us debug this:

 Possible unsafe locking scenario:

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

 *** DEADLOCK ***

6 locks held by syz-executor.3/11291:
 #0: ffff00012f22e410 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write+0x44/0x9c fs/namespace.c:403
 #1: ffff0001344c1300 (&type->i_mutex_dir_key#8/1){+.+.}-{3:3}, at: inode_lock_nested include/linux/fs.h:806 [inline]
 #1: ffff0001344c1300 (&type->i_mutex_dir_key#8/1){+.+.}-{3:3}, at: lock_rename fs/namei.c:3042 [inline]
 #1: ffff0001344c1300 (&type->i_mutex_dir_key#8/1){+.+.}-{3:3}, at: do_renameat2+0x50c/0x10b0 fs/namei.c:4948
 #2: ffff0001344c1bd8 (&sb->s_type->i_mutex_key#19){+.+.}-{3:3}, at: inode_lock_nested include/linux/fs.h:806 [inline]
 #2: ffff0001344c1bd8 (&sb->s_type->i_mutex_key#19){+.+.}-{3:3}, at: lock_two_inodes+0xdc/0x158 fs/inode.c:1140
 #3: ffff0001344c24b0 (&sb->s_type->i_mutex_key#19/4){+.+.}-{3:3}, at: inode_lock_nested include/linux/fs.h:806 [inline]
 #3: ffff0001344c24b0 (&sb->s_type->i_mutex_key#19/4){+.+.}-{3:3}, at: lock_two_inodes+0xf8/0x158 fs/inode.c:1142
 #4: ffff00013207c3b0 (&sbi->cp_rwsem){++++}-{3:3}, at: f2fs_down_read fs/f2fs/f2fs.h:2108 [inline]
 #4: ffff00013207c3b0 (&sbi->cp_rwsem){++++}-{3:3}, at: f2fs_lock_op fs/f2fs/f2fs.h:2151 [inline]
 #4: ffff00013207c3b0 (&sbi->cp_rwsem){++++}-{3:3}, at: f2fs_rename fs/f2fs/namei.c:1046 [inline]
 #4: ffff00013207c3b0 (&sbi->cp_rwsem){++++}-{3:3}, at: f2fs_rename2+0xb1c/0x2138 fs/f2fs/namei.c:1332
 #5: ffff0001344c1978 (&fi->i_xattr_sem){.+.+}-{3:3}, at: f2fs_down_read fs/f2fs/f2fs.h:2108 [inline]
 #5: ffff0001344c1978 (&fi->i_xattr_sem){.+.+}-{3:3}, at: f2fs_add_dentry fs/f2fs/dir.c:783 [inline]
 #5: ffff0001344c1978 (&fi->i_xattr_sem){.+.+}-{3:3}, at: f2fs_do_add_link+0x2ac/0x5a4 fs/f2fs/dir.c:827

stack backtrace:
CPU: 0 PID: 11291 Comm: syz-executor.3 Not tainted 6.5.0-rc7-syzkaller-gfe4469582053 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/04/2023
Call trace:
 dump_backtrace+0x1b8/0x1e4 arch/arm64/kernel/stacktrace.c:233
 show_stack+0x2c/0x44 arch/arm64/kernel/stacktrace.c:240
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd0/0x124 lib/dump_stack.c:106
 dump_stack+0x1c/0x28 lib/dump_stack.c:113
 print_circular_bug+0x150/0x1b8 kernel/locking/lockdep.c:2068
 check_noncircular+0x310/0x404 kernel/locking/lockdep.c:2195
 check_prev_add kernel/locking/lockdep.c:3142 [inline]
 check_prevs_add kernel/locking/lockdep.c:3261 [inline]
 validate_chain kernel/locking/lockdep.c:3876 [inline]
 __lock_acquire+0x3370/0x75e8 kernel/locking/lockdep.c:5144
 lock_acquire+0x23c/0x71c kernel/locking/lockdep.c:5761
 down_write+0x50/0xc0 kernel/locking/rwsem.c:1573
 f2fs_down_write fs/f2fs/f2fs.h:2133 [inline]
 f2fs_add_inline_entry+0x350/0x650 fs/f2fs/inline.c:644
 f2fs_add_dentry fs/f2fs/dir.c:784 [inline]
 f2fs_do_add_link+0x2c4/0x5a4 fs/f2fs/dir.c:827
 f2fs_add_link+0xd0/0x120 fs/f2fs/f2fs.h:3554
 f2fs_rename fs/f2fs/namei.c:1097 [inline]
 f2fs_rename2+0x1814/0x2138 fs/f2fs/namei.c:1332
 vfs_rename+0x830/0xbe4 fs/namei.c:4857
 do_renameat2+0x9f4/0x10b0 fs/namei.c:5009
 __do_sys_renameat2 fs/namei.c:5042 [inline]
 __se_sys_renameat2 fs/namei.c:5039 [inline]
 __arm64_sys_renameat2+0xe0/0xfc fs/namei.c:5039
 __invoke_syscall arch/arm64/kernel/syscall.c:37 [inline]
 invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51
 el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136
 do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155
 el0_svc+0x58/0x16c arch/arm64/kernel/entry-common.c:678
 el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696
 el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:591