From: Chi Zhiling <chizhiling@163.com>
To: linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org,
linux-fsdevel@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>,
Christian Brauner <brauner@kernel.org>,
"Darrick J. Wong" <djwong@kernel.org>,
Christoph Hellwig <hch@lst.de>,
Chi Zhiling <chizhiling@kylinos.cn>
Subject: [PATCH v3 6/8] exfat: drop i_rwsem from exfat_page_mkwrite
Date: Fri, 16 Oct 2026 11:33:47 +0800 [thread overview]
Message-ID: <20261016033349.3104509-7-chizhiling@163.com> (raw)
In-Reply-To: <20261016033349.3104509-1-chizhiling@163.com>
From: Chi Zhiling <chizhiling@kylinos.cn>
exfat_page_mkwrite() takes i_rwsem with inode_trylock() and returns
VM_FAULT_RETRY when that fails. The MM subsystem does not propagate
VM_FAULT_RETRY from ->page_mkwrite(), so the fault still completes and
the page becomes writable without exfat_page_mkwrite() ever advancing
valid_size.
Blocking on i_rwsem is not an option either: ->page_mkwrite() runs under
mmap_lock, so waiting for i_rwsem would create an mmap_lock -> i_rwsem
ordering that can deadlock.
Now that valid_size is advanced under the folio lock, i_rwsem is no
longer needed here. Take mapping->invalidate_lock shared instead, which
serializes the fault against truncate.
Without i_rwsem, i_size can shrink between the read fault and
->page_mkwrite(), so re-check that the faulting page still starts within
i_size before preparing the range below it; a truncate that slipped in
between would otherwise let the helper populate and dirty folios beyond
EOF and advance valid_size past i_size.
Fixes: 6630ea49103c ("exfat: move extend valid_size into ->page_mkwrite()")
Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
---
fs/exfat/file.c | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index 6d4f50795332..23b8a36acaf7 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -989,26 +989,25 @@ static vm_fault_t exfat_page_mkwrite(struct vm_fault *vmf)
loff_t new_valid_size, mmap_valid_size, fault_page_start;
int err;
- if (!inode_trylock(inode))
- return VM_FAULT_RETRY;
+ sb_start_pagefault(inode->i_sb);
+ file_update_time(vmf->vma->vm_file);
+ filemap_invalidate_lock_shared(inode->i_mapping);
fault_page_start = ((loff_t)vmf->pgoff) << PAGE_SHIFT;
- /*
- * Zero only the gap below the faulting page. The read
- * fault populated its folio and iomap_page_mkwrite()
- * will dirty it.
- */
- err = exfat_prepare_valid_range(inode, fault_page_start);
- if (err < 0) {
- inode_unlock(inode);
- return vmf_fs_error(err);
+ if (i_size_read(inode) > fault_page_start) {
+ /*
+ * Zero only the gap below the faulting page. The read
+ * fault populated its folio and iomap_page_mkwrite()
+ * will dirty it.
+ */
+ err = exfat_prepare_valid_range(inode, fault_page_start);
+ if (err < 0) {
+ ret = vmf_fs_error(err);
+ goto out;
+ }
}
- sb_start_pagefault(inode->i_sb);
- file_update_time(vmf->vma->vm_file);
-
- filemap_invalidate_lock_shared(inode->i_mapping);
ret = iomap_page_mkwrite(vmf, &exfat_iomap_ops, NULL);
if (ret == VM_FAULT_LOCKED) {
@@ -1021,10 +1020,9 @@ static vm_fault_t exfat_page_mkwrite(struct vm_fault *vmf)
exfat_advance_zeroed_size(ei,
round_up(new_valid_size, i_blocksize(inode)));
}
-
+out:
filemap_invalidate_unlock_shared(inode->i_mapping);
sb_end_pagefault(inode->i_sb);
- inode_unlock(inode);
return ret;
}
--
2.53.0
next prev parent reply other threads:[~2026-10-16 3:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 3:33 [PATCH v3 0/8] exfat: fix valid_size update races Chi Zhiling
2026-10-16 3:33 ` [PATCH v3 1/8] iomap: export iomap_bio_read_folio_range_sync() Chi Zhiling
2026-10-16 3:33 ` [PATCH v3 2/8] exfat: zero the invalid tail of the straddle block under the folio lock Chi Zhiling
2026-10-16 3:33 ` [PATCH v3 3/8] exfat: advance valid_size under the folio lock for buffered writes Chi Zhiling
2026-10-16 3:33 ` [PATCH v3 4/8] exfat: advance valid_size while zeroing new ranges Chi Zhiling
2026-10-16 3:33 ` [PATCH v3 5/8] exfat: validate cached iomaps during buffered writes Chi Zhiling
2026-10-16 3:33 ` Chi Zhiling [this message]
2026-10-16 3:33 ` [PATCH v3 7/8] exfat: complete direct writes synchronously when they update metadata Chi Zhiling
2026-10-16 3:33 ` [PATCH v3 8/8] exfat: publish i_size and valid_size on direct I/O completion 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=20261016033349.3104509-7-chizhiling@163.com \
--to=chizhiling@163.com \
--cc=brauner@kernel.org \
--cc=chizhiling@kylinos.cn \
--cc=djwong@kernel.org \
--cc=exfat@lists.linux.dev \
--cc=hch@lst.de \
--cc=linkinjeon@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@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®