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

but task is already holding lock:
ffff88811470c0a0 (&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_create+0x75/0xe0
       path_openat+0x13b4/0x38a0
       do_file_open+0x23e/0x4a0
       do_sys_openat2+0x113/0x200
       __x64_sys_openat+0x138/0x170
       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
       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
       __blockdev_direct_IO+0x1645/0x3470
       hfs_direct_IO+0x11b/0x220
       generic_file_direct_write+0x1dc/0x3e0
       __generic_file_write_iter+0x120/0x240
       generic_file_write_iter+0x14b/0x690
       iter_file_splice_write+0x9a6/0x10f0
       direct_splice_actor+0x104/0x160
       splice_direct_to_actor+0x545/0xc80
       do_splice_direct+0x19b/0x2a0
       do_sendfile+0x547/0x7e0
       __se_sys_sendfile64+0x144/0x1a0
       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.0.548/9583:
 #0: ffff888176128480 (sb_writers#16){.+.+}-{0:0}, at: direct_splice_actor+0x49/0x160
 #1: ffff8881730a4200 (&sb->s_type->i_mutex_key#49){++++}-{4:4}, at: generic_file_write_iter+0x11f/0x690
 #2: ffff8881730a4028 (&HFS_I(inode)->extents_lock){+.+.}-{4:4}, at: hfs_extend_file+0xf2/0x15e0
 #3: ffff88811470c0a0 (&tree->tree_lock/1){+.+.}-{4:4}, at: hfs_find_init+0x18e/0x300

stack backtrace:
CPU: 1 UID: 0 PID: 9583 Comm: syz.0.548 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
 __blockdev_direct_IO+0x1645/0x3470
 hfs_direct_IO+0x11b/0x220
 generic_file_direct_write+0x1dc/0x3e0
 __generic_file_write_iter+0x120/0x240
 generic_file_write_iter+0x14b/0x690
 iter_file_splice_write+0x9a6/0x10f0
 direct_splice_actor+0x104/0x160
 splice_direct_to_actor+0x545/0xc80
 do_splice_direct+0x19b/0x2a0
 do_sendfile+0x547/0x7e0
 __se_sys_sendfile64+0x144/0x1a0
 do_syscall_64+0x15f/0xf80
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f3e4dd5cdd9
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:00007f3e4bfae028 EFLAGS: 00000246 ORIG_RAX: 0000000000000028
RAX: ffffffffffffffda RBX: 00007f3e4dfd5fa0 RCX: 00007f3e4dd5cdd9
RDX: 0000000000000000 RSI: 0000000000000007 RDI: 0000000000000005
RBP: 00007f3e4ddf2d69 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000020fffe82 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f3e4dfd6038 R14: 00007f3e4dfd5fa0 R15: 00007ffc16213018
 </TASK>
hfs: new node 0 already hashed?
------------[ cut here ]------------
1
WARNING: fs/hfs/bnode.c:520 at hfs_bnode_create+0x461/0x4f0, CPU#1: syz.0.548/9583
Modules linked in:
CPU: 1 UID: 0 PID: 9583 Comm: syz.0.548 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:ffffc90007d86880 EFLAGS: 00010246
RAX: 000000000000001f RBX: ffff88811470c000 RCX: 0ff90e674f3b8d00
RDX: ffffc90026cb7000 RSI: 00000000000291a6 RDI: 00000000000291a7
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: dffffc0000000000 R11: fffff52000fb0cc1 R12: 0000000000000000
R13: ffff88811470c0d0 R14: ffff88817361be00 R15: dffffc0000000000
FS:  00007f3e4bfae6c0(0000) GS:ffff8882a9f1f000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f3e43b69000 CR3: 0000000173be0000 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
 __blockdev_direct_IO+0x1645/0x3470
 hfs_direct_IO+0x11b/0x220
 generic_file_direct_write+0x1dc/0x3e0
 __generic_file_write_iter+0x120/0x240
 generic_file_write_iter+0x14b/0x690
 iter_file_splice_write+0x9a6/0x10f0
 direct_splice_actor+0x104/0x160
 splice_direct_to_actor+0x545/0xc80
 do_splice_direct+0x19b/0x2a0
 do_sendfile+0x547/0x7e0
 __se_sys_sendfile64+0x144/0x1a0
 do_syscall_64+0x15f/0xf80
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f3e4dd5cdd9
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:00007f3e4bfae028 EFLAGS: 00000246 ORIG_RAX: 0000000000000028
RAX: ffffffffffffffda RBX: 00007f3e4dfd5fa0 RCX: 00007f3e4dd5cdd9
RDX: 0000000000000000 RSI: 0000000000000007 RDI: 0000000000000005
RBP: 00007f3e4ddf2d69 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000020fffe82 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f3e4dfd6038 R14: 00007f3e4dfd5fa0 R15: 00007ffc16213018
 </TASK>
