mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chi Zhiling <chizhiling@163.com>
To: linux-kernel@vger.kernel.org, exfat@lists.linux.dev
Cc: Namjae Jeon <linkinjeon@kernel.org>,
	Sungjong Seo <sj1557.seo@samsung.com>,
	Yuezhang Mo <yuezhang.mo@sony.com>,
	Chi Zhiling <chizhiling@kylinos.cn>
Subject: [PATCH v2] exfat: drain dirty pages after forced shutdown
Date: Tue, 27 Oct 2026 13:47:40 +0800	[thread overview]
Message-ID: <20261027054740.1148201-1-chizhiling@163.com> (raw)

From: Chi Zhiling <chizhiling@kylinos.cn>

A forced shutdown sets EXFAT_FLAGS_SHUTDOWN, after which
exfat_writepages() returns -EIO.  Pages dirtied before the shutdown can
then never be written back, so a writer throttled in
balance_dirty_pages() while extending valid_size sleeps forever.

Stuck stack:
  balance_dirty_pages+0x4f0/0xb40
  exfat_prepare_valid_range+0x43/0x140
  exfat_file_write_iter+0x413/0x520
  iter_file_splice_write+0x32d/0x5a0
  direct_splice_actor+0x51/0x270
  splice_direct_to_actor+0xf5/0x270
  do_splice_direct+0x76/0xc0
  vfs_copy_file_range+0x244/0x710
  __do_sys_copy_file_range+0xe6/0x240
  do_syscall_64+0x106/0x5f0
  entry_SYSCALL_64_after_hwframe+0x77/0x7f

Do not reject writeback up front.  Reject it per folio from
->writeback_range() instead: iomap then ends writeback and clears the
dirty state without issuing I/O, which lets the dirty limits drain and
unblocks the writer.

Write syscalls and page faults are still rejected in
exfat_file_write_iter() and exfat_page_mkwrite().  A write that is
already in progress may continue to dirty folios; writeback retires
them without I/O as described above.

Fixes: f761fcdd289d0 ("exfat: Implement sops->shutdown and ioctl")
Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
---
 fs/exfat/file.c  | 3 +++
 fs/exfat/inode.c | 3 ---
 fs/exfat/iomap.c | 7 ++++++-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index 1386149916bb..c358899e77f3 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -975,6 +975,9 @@ static vm_fault_t exfat_page_mkwrite(struct vm_fault *vmf)
 	vm_fault_t ret;
 	loff_t new_valid_size, mmap_valid_size, fault_page_start;
 
+	if (exfat_forced_shutdown(inode->i_sb))
+		return vmf_fs_error(-EIO);
+
 	if (!inode_trylock(inode))
 		return VM_FAULT_RETRY;
 
diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c
index 5129df1e79b4..4bea9e9deb94 100644
--- a/fs/exfat/inode.c
+++ b/fs/exfat/inode.c
@@ -283,9 +283,6 @@ static int exfat_writepages(struct address_space *mapping,
 		.ops		= &exfat_writeback_ops,
 	};
 
-	if (unlikely(exfat_forced_shutdown(mapping->host->i_sb)))
-		return -EIO;
-
 	return iomap_writepages(&wpc);
 }
 
diff --git a/fs/exfat/iomap.c b/fs/exfat/iomap.c
index e50ecbfbfbe0..2089da8439e4 100644
--- a/fs/exfat/iomap.c
+++ b/fs/exfat/iomap.c
@@ -261,11 +261,16 @@ const struct iomap_ops exfat_write_iomap_ops = {
 static ssize_t exfat_writeback_range(struct iomap_writepage_ctx *wpc,
 		struct folio *folio, u64 offset, unsigned int len, u64 end_pos)
 {
+	struct inode *inode = wpc->inode;
+
+	if (exfat_forced_shutdown(inode->i_sb))
+		return -EIO;
+
 	if (offset < wpc->iomap.offset ||
 	    offset >= wpc->iomap.offset + wpc->iomap.length) {
 		int error;
 
-		error = __exfat_iomap_begin(wpc->inode, offset, len,
+		error = __exfat_iomap_begin(inode, offset, len,
 				0, &wpc->iomap, false);
 		if (error)
 			return error;
-- 
2.53.0


             reply	other threads:[~2026-10-27  5:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27  5:47 Chi Zhiling [this message]
2026-10-27  9:50 ` Namjae Jeon

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=20261027054740.1148201-1-chizhiling@163.com \
    --to=chizhiling@163.com \
    --cc=chizhiling@kylinos.cn \
    --cc=exfat@lists.linux.dev \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sj1557.seo@samsung.com \
    --cc=yuezhang.mo@sony.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®