Linux kernel crash report:
------------[ cut here ]------------
kernel BUG at fs/ext4/mballoc.c:4294!
invalid opcode: 0000 [#1] PREEMPT SMP KASAN
CPU: 1 PID: 3613 Comm: syz-executor426 Not tainted 6.0.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/22/2022
RIP: 0010:ext4_mb_use_inode_pa+0x5f0/0x650 fs/ext4/mballoc.c:4294
Code: 48 c7 c7 a0 16 cb 8c 4c 89 e6 48 89 ea e8 98 1d 2b 02 e9 42 fd ff ff e8 de d7 50 ff 0f 0b e8 d7 d7 50 ff 0f 0b e8 d0 d7 50 ff <0f> 0b 48 8b 0c 24 80 e1 07 80 c1 03 38 c1 0f 8c 58 ff ff ff 48 8b
RSP: 0018:ffffc9000379e7c8 EFLAGS: 00010293
RAX: ffffffff8236b1b0 RBX: 00000000ffffffff RCX: ffff888024fcd880
RDX: 0000000000000000 RSI: 0000000000000002 RDI: 0000000000000001
RBP: 1ffff1100e86149d R08: ffffffff8236af2b R09: ffffed100e86149b
R10: ffffed100e86149b R11: 1ffff1100e86149a R12: 0000000000000080
R13: dffffc0000000000 R14: 0000000000000002 R15: ffff88807430a4e8
FS:  00007f16182da700(0000) GS:ffff8880b9b00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000000 CR3: 000000002658b000 CR4: 00000000003506e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 ext4_mb_use_preallocated+0xcfd/0xf20 fs/ext4/mballoc.c:4392
 ext4_mb_new_blocks+0x539/0x3e80 fs/ext4/mballoc.c:5602
 ext4_ext_map_blocks+0x17b4/0x65b0 fs/ext4/extents.c:4285
 ext4_map_blocks+0xa49/0x1cc0 fs/ext4/inode.c:645
 ext4_iomap_alloc fs/ext4/inode.c:3407 [inline]
 ext4_iomap_begin+0x8e3/0xd20 fs/ext4/inode.c:3457
 iomap_iter+0x606/0x8a0 fs/iomap/iter.c:74
 __iomap_dio_rw+0x16e7/0x20d0 fs/iomap/direct-io.c:601
 iomap_dio_rw+0x42/0xa0 fs/iomap/direct-io.c:690
 ext4_dio_write_iter fs/ext4/file.c:566 [inline]
 ext4_file_write_iter+0x168f/0x1ad0 fs/ext4/file.c:677
 do_iter_write+0x6c2/0xc20 fs/read_write.c:861
 iter_file_splice_write+0x7fc/0xfc0 fs/splice.c:686
 do_splice_from fs/splice.c:764 [inline]
 direct_splice_actor+0xe6/0x1c0 fs/splice.c:931
 splice_direct_to_actor+0x4e4/0xc00 fs/splice.c:886
 do_splice_direct+0x279/0x3d0 fs/splice.c:974
 do_sendfile+0x5fb/0xf80 fs/read_write.c:1255
 __do_sys_sendfile64 fs/read_write.c:1323 [inline]
 __se_sys_sendfile64+0x14f/0x1b0 fs/read_write.c:1309
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f161834f729
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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f16182da2f8 EFLAGS: 00000246 ORIG_RAX: 0000000000000028
RAX: ffffffffffffffda RBX: 00007f16183d5410 RCX: 00007f161834f729
RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000000000000004
RBP: 00007f16183a1cf4 R08: 0000000000000000 R09: 0000000000000000
R10: 00008400fffffffa R11: 0000000000000246 R12: 00007f16183a18d0
R13: 00007f16183a10a8 R14: 0030656c69662f2e R15: 00007f16183d5418
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:ext4_mb_use_inode_pa+0x5f0/0x650 fs/ext4/mballoc.c:4294
Code: 48 c7 c7 a0 16 cb 8c 4c 89 e6 48 89 ea e8 98 1d 2b 02 e9 42 fd ff ff e8 de d7 50 ff 0f 0b e8 d7 d7 50 ff 0f 0b e8 d0 d7 50 ff <0f> 0b 48 8b 0c 24 80 e1 07 80 c1 03 38 c1 0f 8c 58 ff ff ff 48 8b
RSP: 0018:ffffc9000379e7c8 EFLAGS: 00010293
RAX: ffffffff8236b1b0 RBX: 00000000ffffffff RCX: ffff888024fcd880
RDX: 0000000000000000 RSI: 0000000000000002 RDI: 0000000000000001
RBP: 1ffff1100e86149d R08: ffffffff8236af2b R09: ffffed100e86149b
R10: ffffed100e86149b R11: 1ffff1100e86149a R12: 0000000000000080
R13: dffffc0000000000 R14: 0000000000000002 R15: ffff88807430a4e8
FS:  00007f16182da700(0000) GS:ffff8880b9b00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000000 CR3: 000000002658b000 CR4: 00000000003506e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400


Fix patch:
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 109d07629f81..847a2f806b8f 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -528,6 +528,12 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
 		ret = -EAGAIN;
 		goto out;
 	}
+	/*
+	 * Make sure inline data cannot be created anymore since we are going
+	 * to allocate blocks for DIO. We know the inode does not have any
+	 * inline data now because ext4_dio_supported() checked for that.
+	 */
+	ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
 
 	offset = iocb->ki_pos;
 	count = ret;