mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] exfat: mark straddling folio RO for 4K block size
@ 2026-09-30 10:43 Yuezhang Mo
  2026-10-01  5:05 ` Chi Zhiling
  0 siblings, 1 reply; 2+ messages in thread
From: Yuezhang Mo @ 2026-09-30 10:43 UTC (permalink / raw)
  To: exfat; +Cc: linux-kernel, linkinjeon, sj1557.seo, chizhiling, dxdt, Yuezhang Mo

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@sony.com>
---
 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);
+		}
+	}
+
 	inode->i_blocks = round_up(size, sbi->cluster_size) >> 9;
 	mark_inode_dirty(inode);
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] exfat: mark straddling folio RO for 4K block size
  2026-09-30 10:43 [PATCH v1] exfat: mark straddling folio RO for 4K block size Yuezhang Mo
@ 2026-10-01  5:05 ` Chi Zhiling
  0 siblings, 0 replies; 2+ messages in thread
From: Chi Zhiling @ 2026-10-01  5:05 UTC (permalink / raw)
  To: Yuezhang Mo, exfat; +Cc: linux-kernel, linkinjeon, sj1557.seo, dxdt

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@sony.com>
> ---
>   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);
>   


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-01  5:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-30 10:43 [PATCH v1] exfat: mark straddling folio RO for 4K block size Yuezhang Mo
2026-10-01  5:05 ` Chi Zhiling

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®