======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
syz.4.2515/20006 is trying to acquire lock:
ffff88811caa4e28 (&HFS_I(tree->inode)->extents_lock){+.+.}-{4:4}, at: hfs_extend_file+0xf2/0x15e0

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

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&tree->tree_lock/1){+.+.}-{4:4}:
       mutex_lock_nested+0x5a/0x1d0
       hfs_find_init+0x18e/0x300
       hfs_extend_file+0x35c/0x15e0
       hfs_bmap_reserve+0x107/0x430
       hfs_cat_create+0x20f/0x800
       hfs_mkdir+0x79/0xe0
       vfs_mkdir+0x40b/0x630
       filename_mkdirat+0x289/0x520
       __se_sys_mkdirat+0x35/0x150
       do_syscall_64+0x15f/0xf80
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (&HFS_I(tree->inode)->extents_lock){+.+.}-{4:4}:
       __lock_acquire+0x15a5/0x2d10
       mutex_lock_nested+0x5a/0x1d0
       hfs_extend_file+0xf2/0x15e0
       hfs_bmap_reserve+0x107/0x430
       __hfs_ext_write_extent+0x1fa/0x470
       __hfs_ext_cache_extent+0x6b/0x9b0
       hfs_extend_file+0x39b/0x15e0
       hfs_get_block+0x412/0xc50
       __block_write_begin_int+0x6c6/0x1910
       cont_write_begin+0x737/0xae0
       hfs_write_begin+0x66/0xb0
       cont_write_begin+0x2e7/0xae0
       hfs_write_begin+0x66/0xb0
       generic_perform_write+0x2af/0x8b0
       generic_file_write_iter+0x14b/0x690
       vfs_write+0x629/0xba0
       __x64_sys_pwrite64+0x19c/0x230
       do_syscall_64+0x15f/0xf80
       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/1);
                               lock(&HFS_I(tree->inode)->extents_lock);
                               lock(&tree->tree_lock/1);
  lock(&HFS_I(tree->inode)->extents_lock);

 *** DEADLOCK ***

4 locks held by syz.4.2515/20006:
 #0: ffff888114a38480 (sb_writers#18){.+.+}-{0:0}, at: vfs_write+0x22d/0xba0
 #1: ffff88811caa4900 (&sb->s_type->i_mutex_key#28){++++}-{4:4}, at: generic_file_write_iter+0x11f/0x690
 #2: ffff88811caa4728 (&HFS_I(inode)->extents_lock){+.+.}-{4:4}, at: hfs_extend_file+0xf2/0x15e0
 #3: ffff888112a8a0a0 (&tree->tree_lock/1){+.+.}-{4:4}, at: hfs_find_init+0x18e/0x300

stack backtrace:
CPU: 1 UID: 0 PID: 20006 Comm: syz.4.2515 Not tainted syzkaller #0 PREEMPT_{RT,(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+0x15a5/0x2d10
 lock_acquire+0x106/0x350
 mutex_lock_nested+0x5a/0x1d0
 hfs_extend_file+0xf2/0x15e0
 hfs_bmap_reserve+0x107/0x430
 __hfs_ext_write_extent+0x1fa/0x470
 __hfs_ext_cache_extent+0x6b/0x9b0
 hfs_extend_file+0x39b/0x15e0
 hfs_get_block+0x412/0xc50
 __block_write_begin_int+0x6c6/0x1910
 cont_write_begin+0x737/0xae0
 hfs_write_begin+0x66/0xb0
 cont_write_begin+0x2e7/0xae0
 hfs_write_begin+0x66/0xb0
 generic_perform_write+0x2af/0x8b0
 generic_file_write_iter+0x14b/0x690
 vfs_write+0x629/0xba0
 __x64_sys_pwrite64+0x19c/0x230
 do_syscall_64+0x15f/0xf80
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fab4a40cdd9
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:00007fab4865e028 EFLAGS: 00000246 ORIG_RAX: 0000000000000012
RAX: ffffffffffffffda RBX: 00007fab4a685fa0 RCX: 00007fab4a40cdd9
RDX: 00000000ffffff07 RSI: 0000200000000140 RDI: 0000000000000009
RBP: 00007fab4a4a2d69 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000008000c61 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fab4a686038 R14: 00007fab4a685fa0 R15: 00007ffec3eff6e8
 </TASK>
hfs: new node 0 already hashed?
------------[ cut here ]------------
1
WARNING: fs/hfs/bnode.c:520 at hfs_bnode_create+0x461/0x4f0, CPU#0: syz.4.2515/20006
Modules linked in:
CPU: 0 UID: 0 PID: 20006 Comm: syz.4.2515 Not tainted syzkaller #0 PREEMPT_{RT,(full)} 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
RIP: 0010:hfs_bnode_create+0x461/0x4f0
Code: 67 8b 89 ee e8 20 9c 7e fe e9 cf fc ff ff e8 e6 0c 1c ff 4c 89 ef e8 ce 24 82 08 48 c7 c7 a0 c2 67 8b 89 ee e8 00 9c 7e fe 90 <0f> 0b 90 eb b0 44 89 f1 80 e1 07 80 c1 03 38 c1 0f 8c d6 fb ff ff
RSP: 0018:ffffc90005d26c80 EFLAGS: 00010246
RAX: 000000000000001f RBX: ffff888112a8a000 RCX: 7fea48cf2df6d400
RDX: ffffc90029f9f000 RSI: 0000000000025eb5 RDI: 0000000000025eb6
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: dffffc0000000000 R11: fffff52000ba4d41 R12: 0000000000000000
R13: ffff888112a8a0d0 R14: ffff888114a6fa00 R15: dffffc0000000000
FS:  00007fab4865e6c0(0000) GS:ffff88818e91f000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fa468320ff8 CR3: 00000001063ae000 CR4: 00000000000006f0
Call Trace:
 <TASK>
 hfs_bmap_alloc+0x5c1/0x650
 hfs_btree_inc_height+0x100/0xad0
 hfs_brec_insert+0x7ef/0xc90
 __hfs_ext_write_extent+0x2a1/0x470
 __hfs_ext_cache_extent+0x6b/0x9b0
 hfs_extend_file+0x39b/0x15e0
 hfs_get_block+0x412/0xc50
 __block_write_begin_int+0x6c6/0x1910
 cont_write_begin+0x737/0xae0
 hfs_write_begin+0x66/0xb0
 cont_write_begin+0x2e7/0xae0
 hfs_write_begin+0x66/0xb0
 generic_perform_write+0x2af/0x8b0
 generic_file_write_iter+0x14b/0x690
 vfs_write+0x629/0xba0
 __x64_sys_pwrite64+0x19c/0x230
 do_syscall_64+0x15f/0xf80
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fab4a40cdd9
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:00007fab4865e028 EFLAGS: 00000246 ORIG_RAX: 0000000000000012
RAX: ffffffffffffffda RBX: 00007fab4a685fa0 RCX: 00007fab4a40cdd9
RDX: 00000000ffffff07 RSI: 0000200000000140 RDI: 0000000000000009
RBP: 00007fab4a4a2d69 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000008000c61 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fab4a686038 R14: 00007fab4a685fa0 R15: 00007ffec3eff6e8
 </TASK>
