======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
syz.5.4700/4669 is trying to acquire lock:
ffff88816b52b0a0 (&HFS_I(tree->inode)->extents_lock){+.+.}-{4:4}, at: hfs_extend_file+0xf9/0x1680

but task is already holding lock:
ffff88817199a0a8 (&tree->tree_lock#2/1){+.+.}-{4:4}, at: hfs_find_init+0x18d/0x300

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&tree->tree_lock#2/1){+.+.}-{4:4}:
       __mutex_lock+0x19d/0x1550
       hfs_find_init+0x18d/0x300
       hfs_extend_file+0x35f/0x1680
       hfs_bmap_reserve+0x108/0x430
       hfs_cat_create+0x221/0x810
       hfs_create+0x78/0xe0
       path_openat+0x133a/0x3830
       do_file_open+0x23e/0x4a0
       do_sys_openat2+0x115/0x200
       __x64_sys_openat+0x138/0x170
       do_syscall_64+0x174/0x580
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (&HFS_I(tree->inode)->extents_lock){+.+.}-{4:4}:
       __lock_acquire+0x1520/0x2cf0
       lock_acquire+0x106/0x350
       __mutex_lock+0x19d/0x1550
       hfs_extend_file+0xf9/0x1680
       hfs_bmap_reserve+0x108/0x430
       __hfs_ext_write_extent+0x1fc/0x470
       __hfs_ext_cache_extent+0x6e/0x9b0
       hfs_extend_file+0x3a0/0x1680
       hfs_get_block+0x401/0xbe0
       __block_write_begin_int+0x6c2/0x1900
       cont_write_begin+0x71b/0xac0
       hfs_write_begin+0x66/0xb0
       cont_write_begin+0x2d6/0xac0
       hfs_write_begin+0x66/0xb0
       hfs_file_truncate+0x1cf/0xb60
       hfs_inode_setattr+0x49a/0x6c0
       notify_change+0xbba/0xea0
       do_truncate+0x1c2/0x250
       do_ftruncate+0x4d4/0x580
       __x64_sys_ftruncate+0x8f/0xe0
       do_syscall_64+0x174/0x580
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&tree->tree_lock#2/1);
                               lock(&HFS_I(tree->inode)->extents_lock);
                               lock(&tree->tree_lock#2/1);
  lock(&HFS_I(tree->inode)->extents_lock);

 *** DEADLOCK ***

4 locks held by syz.5.4700/4669:
 #0: ffff88816dd26450 (sb_writers#27){.+.+}-{0:0}, at: do_ftruncate+0x474/0x580
 #1: ffff88816b52ca40 (&sb->s_type->i_mutex_key#42){+.+.}-{4:4}, at: do_truncate+0x18f/0x250
 #2: ffff88816b52c8a0 (&HFS_I(inode)->extents_lock){+.+.}-{4:4}, at: hfs_extend_file+0xf9/0x1680
 #3: ffff88817199a0a8 (&tree->tree_lock#2/1){+.+.}-{4:4}, at: hfs_find_init+0x18d/0x300

stack backtrace:
CPU: 0 UID: 0 PID: 4669 Comm: syz.5.4700 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+0xe8/0x150
 print_circular_bug+0x2e1/0x300
 check_noncircular+0x12e/0x150
 __lock_acquire+0x1520/0x2cf0
 lock_acquire+0x106/0x350
 __mutex_lock+0x19d/0x1550
 hfs_extend_file+0xf9/0x1680
 hfs_bmap_reserve+0x108/0x430
 __hfs_ext_write_extent+0x1fc/0x470
 __hfs_ext_cache_extent+0x6e/0x9b0
 hfs_extend_file+0x3a0/0x1680
 hfs_get_block+0x401/0xbe0
 __block_write_begin_int+0x6c2/0x1900
 cont_write_begin+0x71b/0xac0
 hfs_write_begin+0x66/0xb0
 cont_write_begin+0x2d6/0xac0
 hfs_write_begin+0x66/0xb0
 hfs_file_truncate+0x1cf/0xb60
 hfs_inode_setattr+0x49a/0x6c0
 notify_change+0xbba/0xea0
 do_truncate+0x1c2/0x250
 do_ftruncate+0x4d4/0x580
 __x64_sys_ftruncate+0x8f/0xe0
 do_syscall_64+0x174/0x580
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f853f79ce59
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 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 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f854057b028 EFLAGS: 00000246 ORIG_RAX: 000000000000004d
RAX: ffffffffffffffda RBX: 00007f853fa15fa0 RCX: 00007f853f79ce59
RDX: 0000000000000000 RSI: 0000000002007ffc RDI: 0000000000000004
RBP: 00007f853f832e6f R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f853fa16038 R14: 00007f853fa15fa0 R15: 00007ffcff947fb8
 </TASK>
