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

but task is already holding lock:
ffff888114cbc0a8 (&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+0x1a3/0x1550
       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+0x413/0x630
       filename_mkdirat+0x285/0x510
       __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/0x2cf0
       lock_acquire+0x106/0x350
       __mutex_lock+0x1a3/0x1550
       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+0x2e2/0x8f0
       generic_file_write_iter+0x14a/0x680
       do_iter_readv_writev+0x619/0x8c0
       vfs_writev+0x33c/0x990
       __se_sys_pwritev2+0x184/0x2a0
       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.3341/1995:
 #0: ffff88811f288410 (sb_writers#22){.+.+}-{0:0}, at: vfs_writev+0x2aa/0x990
 #1: ffff88810ca39c90 (&sb->s_type->i_mutex_key#33){+.+.}-{4:4}, at: generic_file_write_iter+0x11e/0x680
 #2: ffff88810ca39af0 (&HFS_I(inode)->extents_lock){+.+.}-{4:4}, at: hfs_extend_file+0xf2/0x15e0
 #3: ffff888114cbc0a8 (&tree->tree_lock/1){+.+.}-{4:4}, at: hfs_find_init+0x18e/0x300

stack backtrace:
CPU: 0 UID: 0 PID: 1995 Comm: syz.4.3341 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+0x15a5/0x2cf0
 lock_acquire+0x106/0x350
 __mutex_lock+0x1a3/0x1550
 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+0x2e2/0x8f0
 generic_file_write_iter+0x14a/0x680
 do_iter_readv_writev+0x619/0x8c0
 vfs_writev+0x33c/0x990
 __se_sys_pwritev2+0x184/0x2a0
 do_syscall_64+0x15f/0xf80
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fb62439cdd9
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:00007fb6251f4028 EFLAGS: 00000246 ORIG_RAX: 0000000000000148
RAX: ffffffffffffffda RBX: 00007fb624616180 RCX: 00007fb62439cdd9
RDX: 0000000000000001 RSI: 0000200000000100 RDI: 0000000000000008
RBP: 00007fb624432d69 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000005405 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fb624616218 R14: 00007fb624616180 R15: 00007ffcbc2191b8
 </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.3341/1995
Modules linked in:
CPU: 0 UID: 0 PID: 1995 Comm: syz.4.3341 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
RIP: 0010:hfs_bnode_create+0x461/0x4f0
Code: e8 8b 89 ee e8 00 b9 77 fe e9 cf fc ff ff e8 86 cd 15 ff 4c 89 ef e8 1e 7b fb 08 48 c7 c7 a0 2e e8 8b 89 ee e8 e0 b8 77 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:ffffc90005f06b00 EFLAGS: 00010246
RAX: 000000000000001f RBX: ffff888114cbc000 RCX: 96f7b1dcc3700800
RDX: ffffc90023804000 RSI: 00000000000715c2 RDI: 00000000000715c3
RBP: 0000000000000000 R08: ffffc90005f06887 R09: 1ffff92000be0d10
R10: dffffc0000000000 R11: fffff52000be0d11 R12: 0000000000000000
R13: ffff888114cbc0d8 R14: ffff888114ee3d00 R15: dffffc0000000000
FS:  00007fb6251f46c0(0000) GS:ffff88818dc8c000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000055c6cfb487b8 CR3: 00000001098e0000 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+0x2e2/0x8f0
 generic_file_write_iter+0x14a/0x680
 do_iter_readv_writev+0x619/0x8c0
 vfs_writev+0x33c/0x990
 __se_sys_pwritev2+0x184/0x2a0
 do_syscall_64+0x15f/0xf80
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fb62439cdd9
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:00007fb6251f4028 EFLAGS: 00000246 ORIG_RAX: 0000000000000148
RAX: ffffffffffffffda RBX: 00007fb624616180 RCX: 00007fb62439cdd9
RDX: 0000000000000001 RSI: 0000200000000100 RDI: 0000000000000008
RBP: 00007fb624432d69 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000005405 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fb624616218 R14: 00007fb624616180 R15: 00007ffcbc2191b8
 </TASK>
