======================================================
WARNING: possible circular locking dependency detected
6.2.0-rc2-next-20230105 #1 Not tainted
------------------------------------------------------
syz-executor.5/15094 is trying to acquire lock:
ffff88800ff14170 (&journal->j_barrier){+.+.}-{3:3}, at: jbd2_journal_lock_updates+0x162/0x310

but task is already holding lock:
ffff88800ff12b90 (&sbi->s_writepages_rwsem){++++}-{0:0}, at: ext4_change_inode_journal_flag+0x17f/0x550

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #4 (&sbi->s_writepages_rwsem){++++}-{0:0}:
       ext4_writepages+0x1a9/0x5f0
       do_writepages+0x1ad/0x650
       filemap_fdatawrite_wbc+0x14b/0x1b0
       __filemap_fdatawrite_range+0xba/0x100
       filemap_write_and_wait_range+0xa5/0x130
       __ext4_ioctl+0x15ad/0x43d0
       __x64_sys_ioctl+0x19e/0x210
       do_syscall_64+0x3f/0x90
       entry_SYSCALL_64_after_hwframe+0x72/0xdc

-> #3 (mapping.invalidate_lock){++++}-{3:3}:
       down_write+0x94/0x220
       ext4_setattr+0x956/0x2700
ieee80211 phy50: Selected rate control algorithm 'minstrel_ht'
       notify_change+0xca5/0x1400
       do_truncate+0x143/0x200
       do_sys_ftruncate+0x53c/0x760
       do_syscall_64+0x3f/0x90
       entry_SYSCALL_64_after_hwframe+0x72/0xdc

-> #2 (&sb->s_type->i_mutex_key#6){++++}-{3:3}:
       down_read+0x9c/0x450
       ext4_bmap+0x52/0x470
       bmap+0xb0/0x130
       jbd2_journal_bmap+0xac/0x190
       jbd2_journal_flush+0x857/0xc10
       __ext4_ioctl+0x9db/0x43d0
       __x64_sys_ioctl+0x19e/0x210
       do_syscall_64+0x3f/0x90
       entry_SYSCALL_64_after_hwframe+0x72/0xdc

-> #1 (&journal->j_checkpoint_mutex){+.+.}-{3:3}:
       mutex_lock_io_nested+0x14c/0x1330
       jbd2_journal_flush+0x19e/0xc10
       __ext4_ioctl+0x9db/0x43d0
       __x64_sys_ioctl+0x19e/0x210
       do_syscall_64+0x3f/0x90
       entry_SYSCALL_64_after_hwframe+0x72/0xdc

-> #0 (&journal->j_barrier){+.+.}-{3:3}:
       __lock_acquire+0x2a02/0x5e70
       lock_acquire.part.0+0x11e/0x340
       __mutex_lock+0x136/0x14e0
       jbd2_journal_lock_updates+0x162/0x310
       ext4_change_inode_journal_flag+0x187/0x550
       ext4_fileattr_set+0x14fa/0x19f0
       vfs_fileattr_set+0x7a2/0xbd0
       do_vfs_ioctl+0xfa6/0x15d0
       __x64_sys_ioctl+0x110/0x210
       do_syscall_64+0x3f/0x90
       entry_SYSCALL_64_after_hwframe+0x72/0xdc

other info that might help us debug this:

Chain exists of:
  &journal->j_barrier --> mapping.invalidate_lock --> &sbi->s_writepages_rwsem

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&sbi->s_writepages_rwsem);
                               lock(mapping.invalidate_lock);
                               lock(&sbi->s_writepages_rwsem);
  lock(&journal->j_barrier);

 *** DEADLOCK ***

4 locks held by syz-executor.5/15094:
 #0: ffff88800ff10438 (sb_writers#3){.+.+}-{0:0}, at: do_vfs_ioctl+0xf6b/0x15d0
 #1: ffff888039875d70 (&sb->s_type->i_mutex_key#6){++++}-{3:3}, at: vfs_fileattr_set+0x14c/0xbd0
 #2: ffff888039875f10 (mapping.invalidate_lock){++++}-{3:3}, at: ext4_change_inode_journal_flag+0x126/0x550
 #3: ffff88800ff12b90 (&sbi->s_writepages_rwsem){++++}-{0:0}, at: ext4_change_inode_journal_flag+0x17f/0x550

stack backtrace:
CPU: 1 PID: 15094 Comm: syz-executor.5 Not tainted 6.2.0-rc2-next-20230105 #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014
Call Trace:
 <TASK>
 dump_stack_lvl+0x8f/0xb7
 check_noncircular+0x263/0x2e0
 __lock_acquire+0x2a02/0x5e70
 lock_acquire.part.0+0x11e/0x340
 __mutex_lock+0x136/0x14e0
 jbd2_journal_lock_updates+0x162/0x310
 ext4_change_inode_journal_flag+0x187/0x550
 ext4_fileattr_set+0x14fa/0x19f0
 vfs_fileattr_set+0x7a2/0xbd0
 do_vfs_ioctl+0xfa6/0x15d0
 __x64_sys_ioctl+0x110/0x210
 do_syscall_64+0x3f/0x90
 entry_SYSCALL_64_after_hwframe+0x72/0xdc
RIP: 0033:0x7f6b68badb19
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 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 bc ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f6b66123188 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007f6b68cc0f60 RCX: 00007f6b68badb19
RDX: 0000000020000040 RSI: 0000000040086602 RDI: 0000000000000003
RBP: 00007f6b68c07f6d R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffc604295ef R14: 00007f6b66123300 R15: 0000000000022000
 </TASK>
mac80211_hwsim: wmediumd released netlink socket, switching to perfect channel medium
process 'syz-executor.3' launched '/dev/fd/-1/./file0' with NULL argv: empty string added
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.6'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.6'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.6'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.3'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.4'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.3'.
loop0: detected capacity change from 0 to 40
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.4'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.3'.
syz-executor.0: attempt to access beyond end of device
loop0: rw=2049, sector=40, nr_sectors = 4 limit=40
buffer_io_error: 17 callbacks suppressed
Buffer I/O error on dev loop0, logical block 10, lost async page write
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.6'.
loop0: detected capacity change from 0 to 40
syz-executor.0: attempt to access beyond end of device
loop0: rw=2049, sector=40, nr_sectors = 4 limit=40
Buffer I/O error on dev loop0, logical block 10, lost async page write
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.4'.
loop0: detected capacity change from 0 to 40
syz-executor.0: attempt to access beyond end of device
loop0: rw=2049, sector=40, nr_sectors = 4 limit=40
Buffer I/O error on dev loop0, logical block 10, lost async page write
__nla_validate_parse: 16 callbacks suppressed
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.0'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.4'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.7'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.5'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.2'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.6'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.3'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.2'.
netlink: 420 bytes leftover after parsing attributes in process `syz-executor.3'.