Re: [PATCH v1 0/5] exfat: fix valid_size handling and locking

From: Chi Zhiling

Date: Wed Sep 30 2026 - 22:53:42 EST


On 9/30/26 6:01 PM, Namjae Jeon wrote:
On Sun, Sep 27, 2026 at 5:04 PM Chi Zhiling <chizhiling@xxxxxxx> wrote:

From: Chi Zhiling <chizhiling@xxxxxxxxxx>

valid_size marks the on-disk up-to-date region of an exFAT file. It is
advanced from the write path, from read/zeroing completion, and via
truncate, while it is read without i_rwsem from ->iomap_begin and from bio
completion context. This series fixes several races and stale-data windows
that follow from that split ownership.

Patches 1-2 are self-contained fixes: an append write may be moved to EOF
by generic_write_checks(), so valid_size must be advanced using the
recalculated position; and exfat_zero_new_range() must mark non-uptodate
pages dirty so the whole page is written back.

Patches 3-4 are prerequisites for patch 5: truncate now holds the
invalidate lock so it is mutually exclusive with mmap writes, and
valid_size/zeroed_size become atomic so they can be read safely outside
i_rwsem. Patch 5 then takes exfat_page_mkwrite() out from under i_rwsem,
since blocking on the inode lock under mmap_lock could deadlock and its
VM_FAULT_RETRY result is not honored, and advances valid_size under the
folio lock to keep the page cache and valid_size consistent.

Link: https://lore.kernel.org/exfat/10029d6f-13cc-4d17-a2f9-b093a8339dde@xxxxxxx/T/#t

Chi Zhiling (5):
exfat: advance valid_size to EOF for append writes
exfat: dirty all new pages when extending valid_size
exfat: hold the invalidate lock while truncating
exfat: make valid_size and zeroed_size atomic
exfat: use folio lock to protect valid_size
Could you check the review comments from Sashiko ?

https://sashiko.dev/#/patchset/20260927080305.831641-1-chizhiling%40163.com

Okay, I’ll take a close look at this review comment.

I also noticed that the comment mentions that concurrent DIO and page faults may lead to data corruption. I believe this is a long-standing issue, and I don’t currently have a good way to fix it.


Thanks!