From: Namjae Jeon File expansion changes allocation and i_size while mmap write faults can initialize the invalid range. Cleaning only the old EOF folio does not serialize the whole expansion with those faults. Wait for direct I/O and hold invalidate_lock exclusively across cluster allocation, EOF cleanup and the i_size update. Apply this to the common expansion path used by ftruncate and fallocate. Fixes: 98431d2cd1eb ("exfat: mark straddling folio RO and zero the post-EOF range") Signed-off-by: Namjae Jeon --- fs/exfat/file.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/exfat/file.c b/fs/exfat/file.c index 47e95b14d570..0d1eeeeffa76 100644 --- a/fs/exfat/file.c +++ b/fs/exfat/file.c @@ -81,7 +81,7 @@ static void exfat_pagecache_isize_extended(struct inode *inode, loff_t from, folio_put(folio); } -static int exfat_cont_expand(struct inode *inode, loff_t size) +static int __exfat_cont_expand(struct inode *inode, loff_t size) { int ret; unsigned int num_clusters, new_num_clusters, last_clu; @@ -158,6 +158,17 @@ static int exfat_cont_expand(struct inode *inode, loff_t size) return -EIO; } +static int exfat_cont_expand(struct inode *inode, loff_t size) +{ + int ret; + + inode_dio_wait(inode); + filemap_invalidate_lock(inode->i_mapping); + ret = __exfat_cont_expand(inode, size); + filemap_invalidate_unlock(inode->i_mapping); + return ret; +} + /* * Preallocate space for a file. This implements exfat's fallocate file * operation, which gets called from sys_fallocate system call. User space -- 2.53.0