Re: [PATCH v1] exfat: mark straddling folio RO for 4K block size

From: Chi Zhiling

Date: Thu Oct 01 2026 - 01:06:43 EST


On 9/30/26 6:43 PM, Yuezhang Mo wrote:
The maximum file system block size supported by exFAT is 4096 bytes.
When extending a file whose EOF is not page aligned, the straddling
folio must be marked RO so that a subsequent mmap write can trigger
->page_mkwrite() and extend the valid data size.

This is normally handled by pagecache_isize_extended(), which marks
the straddling folio RO when the filesystem block size is smaller
than 4K. However, pagecache_isize_extended() returns early when the
filesystem block size is PAGE_SIZE:

if (from >= to || bsize >= PAGE_SIZE)
return;

As a result, on an exFAT filesystem with a 4K block size, the PTE
for the straddling folio remains writable after a file extension.
A subsequent mmap write operation that modifies the straddling folio
beyond the old EOF, will not trigger ->page_mkwrite(), leaving
valid_size unchanged.

This was found by running xfstests generic/030 on a block device with
a 4096-byte sector size: the test fails without this fix and passes
with it.

Fix this by marking the straddling folio RO in exfat_cont_expand()
when the filesystem block size is 4K and the old EOF is not page
aligned. This mirrors what pagecache_isize_extended() does for smaller
filesystem block sizes.

Fixes: 82a81a7352bc ("exfat: add iomap buffered I/O support")
Signed-off-by: Yuezhang Mo <Yuezhang.Mo@xxxxxxxx>
---
fs/exfat/file.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index a2a9ee1a20048..390bfae3f3aa4 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -17,6 +17,7 @@
#include <linux/fileattr.h>
#include <linux/iomap.h>
#include <linux/pagemap.h>
+#include <linux/rmap.h>
#include "exfat_raw.h"
#include "exfat_fs.h"
@@ -91,6 +92,20 @@ static int exfat_cont_expand(struct inode *inode, loff_t size)
*/
pagecache_isize_extended(inode, oldsize, inode->i_size);
+ if (i_blocksize(inode) >= PAGE_SIZE && (oldsize & (PAGE_SIZE - 1))) {
+ struct folio *folio;
+
+ folio = filemap_lock_folio(inode->i_mapping,
+ oldsize >> PAGE_SHIFT);
+ if (!IS_ERR(folio)) {
+ if (folio_mkclean(folio))
+ folio_mark_dirty(folio);
+
+ folio_unlock(folio);
+ folio_put(folio);
+ }
+ }

I think fixing this issue specifically for the block size = 4K case may not be thorough enough, because pagecache_isize_extended() may also fail to work when the block size is smaller than 4K.

We should set the folio containing valid_size to RO whenever valid_size != i_size and valid_size is not page-aligned, regardless of the block size.

+
inode->i_blocks = round_up(size, sbi->cluster_size) >> 9;
mark_inode_dirty(inode);