======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
syz.2.3484/5757 is trying to acquire lock:
ffff88811b1b40a8 (&tree->tree_lock#2/1){+.+.}-{4:4}, at: hfs_find_init+0x18d/0x300

but task is already holding lock:
ffff8881a663aaa0 (&HFS_I(tree->inode)->extents_lock){+.+.}-{4:4}, at: hfs_extend_file+0xf9/0x1680

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&HFS_I(tree->inode)->extents_lock){+.+.}-{4:4}:
       __mutex_lock+0x19d/0x1550
       hfs_extend_file+0xf9/0x1680
       hfs_bmap_reserve+0x108/0x430
       __hfs_ext_write_extent+0x1fc/0x470
       hfs_ext_write_extent+0x17d/0x210
       hfs_write_inode+0x117/0xa00
       __writeback_single_inode+0x69d/0x1220
       writeback_single_inode+0x544/0xf70
       write_inode_now+0x1c2/0x290
       hfs_file_fsync+0xa4/0x140
       generic_file_write_iter+0x280/0x330
       iter_file_splice_write+0xa31/0x1240
       direct_splice_actor+0x101/0x160
       splice_direct_to_actor+0x57b/0xcb0
       do_splice_direct+0x195/0x290
       do_sendfile+0x52e/0x7c0
       __se_sys_sendfile64+0x144/0x1a0
       do_syscall_64+0x166/0x520
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (&tree->tree_lock#2/1){+.+.}-{4:4}:
       __lock_acquire+0x15ff/0x2e50
       lock_acquire+0x115/0x350
       __mutex_lock+0x19d/0x1550
       hfs_find_init+0x18d/0x300
       hfs_extend_file+0x367/0x1680
       hfs_bmap_reserve+0x108/0x430
       hfs_cat_create+0x23d/0x870
       hfs_mkdir+0x73/0xe0
       vfs_mkdir+0x40c/0x620
       filename_mkdirat+0x285/0x510
       __se_sys_mkdir+0x34/0x150
       do_syscall_64+0x166/0x520
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

 Possible unsafe locking scenario:

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

 *** DEADLOCK ***

locks held by syz.2.3484/5757: 4, last CPU#1:
 #0: ffff88810ebb8460 (sb_writers#30){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90
 #1: ffff8881a6639a40 (&type->i_mutex_dir_key#22/1){+.+.}-{4:4}, at: filename_create+0x200/0x370
 #2: ffff88811fb060a8 (&tree->tree_lock#2){+.+.}-{4:4}, at: hfs_find_init+0x18d/0x300
 #3: ffff8881a663aaa0 (&HFS_I(tree->inode)->extents_lock){+.+.}-{4:4}, at: hfs_extend_file+0xf9/0x1680

stack backtrace:
CPU: 1 UID: 0 PID: 5757 Comm: syz.2.3484 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+0x2e2/0x300
 check_noncircular+0x12f/0x150
 __lock_acquire+0x15ff/0x2e50
 lock_acquire+0x115/0x350
 __mutex_lock+0x19d/0x1550
 hfs_find_init+0x18d/0x300
 hfs_extend_file+0x367/0x1680
 hfs_bmap_reserve+0x108/0x430
 hfs_cat_create+0x23d/0x870
 hfs_mkdir+0x73/0xe0
 vfs_mkdir+0x40c/0x620
 filename_mkdirat+0x285/0x510
 __se_sys_mkdir+0x34/0x150
 do_syscall_64+0x166/0x520
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f9788f9e159
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:00007f9789db8028 EFLAGS: 00000246 ORIG_RAX: 0000000000000053
RAX: ffffffffffffffda RBX: 00007f9789225fa0 RCX: 00007f9788f9e159
RDX: 0000000000000000 RSI: 00000000000001b8 RDI: 0000200000000180
RBP: 00007f978903506b R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f9789226038 R14: 00007f9789225fa0 R15: 00007ffee91c5cd8
 </TASK>
syz.2.3484: attempt to access beyond end of device
loop2: rw=8390657, sector=163, nr_sectors = 1 limit=64
Buffer I/O error on dev loop2, logical block 163, lost async page write
syz.2.3484: attempt to access beyond end of device
loop2: rw=8390657, sector=167, nr_sectors = 1 limit=64
Buffer I/O error on dev loop2, logical block 167, lost async page write
syz.2.3484: attempt to access beyond end of device
loop2: rw=8390657, sector=169, nr_sectors = 1 limit=64
Buffer I/O error on dev loop2, logical block 169, lost async page write
syz.2.3484: attempt to access beyond end of device
loop2: rw=8390657, sector=171, nr_sectors = 1 limit=64
Buffer I/O error on dev loop2, logical block 171, lost async page write
syz.2.3484: attempt to access beyond end of device
loop2: rw=8390657, sector=172, nr_sectors = 1 limit=64
Buffer I/O error on dev loop2, logical block 172, lost async page write
syz.2.3484: attempt to access beyond end of device
loop2: rw=8390657, sector=173, nr_sectors = 1 limit=64
Buffer I/O error on dev loop2, logical block 173, lost async page write
syz.2.3484: attempt to access beyond end of device
loop2: rw=8390657, sector=174, nr_sectors = 1 limit=64
Buffer I/O error on dev loop2, logical block 174, lost async page write
syz.2.3484: attempt to access beyond end of device
loop2: rw=8390657, sector=175, nr_sectors = 1 limit=64
Buffer I/O error on dev loop2, logical block 175, lost async page write
syz.2.3484: attempt to access beyond end of device
loop2: rw=8390657, sector=176, nr_sectors = 1 limit=64
Buffer I/O error on dev loop2, logical block 176, lost async page write
syz.2.3484: attempt to access beyond end of device
loop2: rw=8390657, sector=177, nr_sectors = 1 limit=64
Buffer I/O error on dev loop2, logical block 177, lost async page write
