ocfs2: Mounting device (7,4) on (node local, slot 0) with ordered data mode.
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
syz.4.149/7190 is trying to acquire lock:
ffff88803cadddf8 (&oi->ip_xattr_sem){++++}-{4:4}, at: ocfs2_calc_xattr_init+0x20a/0xd80

but task is already holding lock:
ffff88803cae89c0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_reserve_suballoc_bits+0x15e/0x4640

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #3 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}:
       lock_acquire+0x120/0x360
       down_write+0x96/0x1f0
       ocfs2_evict_inode+0x153d/0x40e0
       evict+0x504/0x9c0
       vfs_rmdir+0x3ec/0x520
       do_rmdir+0x25f/0x550
       __x64_sys_rmdir+0x47/0x50
       do_syscall_64+0xfa/0x3b0
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #2 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}:
       lock_acquire+0x120/0x360
       down_write+0x96/0x1f0
       ocfs2_del_inode_from_orphan+0x134/0x740
       ocfs2_dio_end_io+0x479/0x10f0
       dio_complete+0x25b/0x790
       __blockdev_direct_IO+0x2e63/0x3490
       ocfs2_direct_IO+0x25f/0x2d0
       generic_file_direct_write+0x1db/0x3e0
       __generic_file_write_iter+0x11d/0x230
       ocfs2_file_write_iter+0x157a/0x1d10
       vfs_write+0x5c9/0xb30
       ksys_write+0x145/0x250
       do_syscall_64+0xfa/0x3b0
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #1 (&ocfs2_file_ip_alloc_sem_key){++++}-{4:4}:
       lock_acquire+0x120/0x360
       down_write+0x96/0x1f0
       ocfs2_try_remove_refcount_tree+0xb6/0x320
       ocfs2_truncate_file+0xda0/0x1420
       ocfs2_setattr+0x1520/0x1b40
       notify_change+0xb36/0xe40
       do_truncate+0x1a4/0x220
       path_openat+0x306c/0x3830
       do_filp_open+0x1fa/0x410
       do_sys_openat2+0x121/0x1c0
       __x64_sys_openat+0x138/0x170
       do_syscall_64+0xfa/0x3b0
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (&oi->ip_xattr_sem){++++}-{4:4}:
       validate_chain+0xb9b/0x2140
       __lock_acquire+0xab9/0xd20
       lock_acquire+0x120/0x360
       down_read+0x46/0x2e0
       ocfs2_calc_xattr_init+0x20a/0xd80
       ocfs2_mknod+0xc92/0x2050
       ocfs2_create+0x1a5/0x440
       path_openat+0x14f4/0x3830
       do_filp_open+0x1fa/0x410
       do_sys_openat2+0x121/0x1c0
       __x64_sys_open+0x11e/0x150
       do_syscall_64+0xfa/0x3b0
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

Chain exists of:
  &oi->ip_xattr_sem --> &ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE] --> &ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]);
                               lock(&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]);
                               lock(&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]);
  rlock(&oi->ip_xattr_sem);

 *** DEADLOCK ***

3 locks held by syz.4.149/7190:
 #0: ffff888119096428 (sb_writers#31){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90
 #1: ffff88803cade0c0 (&type->i_mutex_dir_key#23){++++}-{4:4}, at: path_openat+0x8da/0x3830
 #2: ffff88803cae89c0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_reserve_suballoc_bits+0x15e/0x4640

stack backtrace:
CPU: 0 UID: 0 PID: 7190 Comm: syz.4.149 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
Call Trace:
 <TASK>
 dump_stack_lvl+0x189/0x250
 print_circular_bug+0x2ee/0x310
 check_noncircular+0x134/0x160
 validate_chain+0xb9b/0x2140
 __lock_acquire+0xab9/0xd20
 lock_acquire+0x120/0x360
 down_read+0x46/0x2e0
 ocfs2_calc_xattr_init+0x20a/0xd80
 ocfs2_mknod+0xc92/0x2050
 ocfs2_create+0x1a5/0x440
 path_openat+0x14f4/0x3830
 do_filp_open+0x1fa/0x410
 do_sys_openat2+0x121/0x1c0
 __x64_sys_open+0x11e/0x150
 do_syscall_64+0xfa/0x3b0
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f15c898ebe9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f15c9891038 EFLAGS: 00000246 ORIG_RAX: 0000000000000002
RAX: ffffffffffffffda RBX: 00007f15c8bc5fa0 RCX: 00007f15c898ebe9
RDX: 0000000000000040 RSI: 0000000000141242 RDI: 0000200000000140
RBP: 00007f15c8a11e19 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f15c8bc6038 R14: 00007f15c8bc5fa0 R15: 00007fffd1e47be8
 </TASK>
