[PATCH v2 6/7] exfat: complete direct writes synchronously when they update metadata
From: Chi Zhiling
Date: Mon Oct 12 2026 - 23:39:35 EST
From: Chi Zhiling <chizhiling@xxxxxxxxxx>
The inode metadata for a direct write is updated in ->end_io(). That
handler runs without holding i_rwsem. As a result, the i_size update can
race with other operations.
Whenever a write extends beyond the current valid_size — that is,
whenever ->end_io() will have metadata to update — force synchronous
completion. This guarantees that the i_size update happens under the
inode lock.
Signed-off-by: Chi Zhiling <chizhiling@xxxxxxxxxx>
---
fs/exfat/file.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index 6209a991a118..efcfeab750c0 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -840,10 +840,16 @@ static ssize_t exfat_fallback_buffered_write(struct kiocb *iocb,
static ssize_t exfat_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
+ struct inode *inode = file_inode(iocb->ki_filp);
+ loff_t end = iocb->ki_pos + iov_iter_count(from);
+ unsigned int dio_flags = 0;
ssize_t ret;
+ if (end > exfat_get_valid_size(EXFAT_I(inode)))
+ dio_flags |= IOMAP_DIO_FORCE_WAIT;
+
ret = iomap_dio_rw(iocb, from, &exfat_write_iomap_ops,
- &exfat_write_dio_ops, 0, NULL, 0);
+ &exfat_write_dio_ops, dio_flags, NULL, 0);
if (ret == -ENOTBLK)
ret = 0;
else if (ret < 0)
--
2.53.0