mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yuezhang Mo <Yuezhang.Mo@sony.com>
To: exfat@lists.linux.dev
Cc: linux-kernel@vger.kernel.org, linkinjeon@kernel.org,
	sj1557.seo@samsung.com, chizhiling@163.com, dxdt@dev.snart.me,
	Yuezhang Mo <Yuezhang.Mo@sony.com>
Subject: [PATCH v1] exfat: mark straddling folio RO for 4K block size
Date: Wed, 30 Sep 2026 18:43:33 +0800	[thread overview]
Message-ID: <20260930104332.4022207-2-Yuezhang.Mo@sony.com> (raw)

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


             reply	other threads:[~2026-09-30 10:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 10:43 Yuezhang Mo [this message]
2026-10-01  5:05 ` Chi Zhiling

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260930104332.4022207-2-Yuezhang.Mo@sony.com \
    --to=yuezhang.mo@sony.com \
    --cc=chizhiling@163.com \
    --cc=dxdt@dev.snart.me \
    --cc=exfat@lists.linux.dev \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sj1557.seo@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®