mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chi Zhiling <chizhiling@163.com>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: exfat@lists.linux.dev, linux-kernel@vger.kernel.org,
	Yuezhang.Mo@sony.com, dxdt@dev.snart.me, sj1557.seo@samsung.com,
	Chi Zhiling <chizhiling@kylinos.cn>
Subject: Re: [PATCH v2 4/7] exfat: drop i_rwsem from exfat_page_mkwrite
Date: Wed, 14 Oct 2026 16:11:41 +0800	[thread overview]
Message-ID: <07bfc007-145b-4ec5-a94e-c9f7bc3eedad@163.com> (raw)
In-Reply-To: <CAKYAXd-+whfZ9_Zrgi0awH2tPxuVLW2O7=6e-w5JcBNBMRrSbw@mail.gmail.com>

On 10/14/2026 9:19 AM, Namjae Jeon wrote:
>> @@ -969,8 +969,9 @@ static vm_fault_t exfat_page_mkwrite(struct vm_fault *vmf)
>>          loff_t new_valid_size, mmap_valid_size, fault_page_start;
>>          bool dirty = false;
>>
>> -       if (!inode_trylock(inode))
>> -               return VM_FAULT_RETRY;
> exfat_page_mkwrite() reads the file size before iomap_page_mkwrite()
> locks the page. Because inode_trylock was removed, another thread can
> grow the file in between. exfat_cont_expand() does not take
> invalidate_lock, so the shared lock does not stop it.
> 
> mmap write fault                              ftruncate/fallocate
> Snapshot i_size = 1000
> new_valid_size = 1000
> dirty = false
>                                                Extend i_size to 3000
>                                                valid_size stays 1000
> iomap_page_mkwrite() locks folio
> Checks the current i_size (3000) and succeeds
> dirty is still false, so VDL is not advanced
> 
> MM makes the page writable
> Store at offset 2000, no new page_mkwrite()
> 
> The data at offset 2000 is beyond valid_size, so it can later be read
> as zero. Could you check and fix this race?

This is the issue Yuezhang mentioned earlier, and he has already 
submitted a fix:

https://lore.kernel.org/exfat/20261010101200.1211462-2-Yuezhang.Mo@sony.com/

> 
> +       sb_start_pagefault(inode->i_sb);
> +       file_update_time(vmf->vma->vm_file);
> +       filemap_invalidate_lock_shared(inode->i_mapping);
> 
> With i_size = 12 KB and valid_size = 0, DIO write to [0, 4 KiB  can
> race with an mmap write fault at offset 8 KB. The fault zeroes and
> dirties the gap [0, 8 KiB), then advances valid_size.
> 
> DIO write [0,4 KiB)                         mmap fault at 8 KiB
> Starts writing data
>                                               Reads the gap as zero
>                                               Dirties pages 0 and 1
>                                               Advances valid_size
> Completes
> Post-DIO invalidation cannot remove
> the dirty page
> Writeback can overwrite DIO data with zeros
> 
> Removing  inode_trylock()  from exfat_page_mkwrite() can introduce
> several racy issues. Could you check that the affected paths are
> properly synchronized?

Concurrent DIO and mmap writes are undefined behavior, and other 
filesystems may have similar issues.

I've spent quite a while thinking about this, but I still don't have a 
good solution. So I added the following patch to the patch series:

"exfat: publish i_size and valid_size on direct I/O completion".

The purpose of this patch is to prevent stale on-disk data from being 
exposed when DIO and mmap writes happen concurrently. However, the 
trade-off is that concurrent DIO writes may have their data unexpectedly 
zeroed.

Do you have any thoughts on this?

Thanks!


  reply	other threads:[~2026-10-14  8:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13  3:38 [PATCH v2 0/7] exfat: fix valid_size update races Chi Zhiling
2026-10-13  3:38 ` [PATCH v2 1/7] exfat: advance valid_size under the folio lock for buffered writes Chi Zhiling
2026-10-13  3:38 ` [PATCH v2 2/7] exfat: advance valid_size while zeroing new ranges Chi Zhiling
2026-10-13  3:38 ` [PATCH v2 3/7] exfat: validate cached iomaps during buffered writes Chi Zhiling
2026-10-14  1:19   ` Namjae Jeon
2026-10-14  7:07     ` Chi Zhiling
2026-10-13  3:38 ` [PATCH v2 4/7] exfat: drop i_rwsem from exfat_page_mkwrite Chi Zhiling
2026-10-14  1:19   ` Namjae Jeon
2026-10-14  8:11     ` Chi Zhiling [this message]
2026-10-14 23:29       ` Chi Zhiling
2026-10-13  3:38 ` [PATCH v2 5/7] exfat: do not re-zero the valid range in exfat_page_mkwrite Chi Zhiling
2026-10-13  3:38 ` [PATCH v2 6/7] exfat: complete direct writes synchronously when they update metadata Chi Zhiling
2026-10-13  3:38 ` [PATCH v2 7/7] exfat: publish i_size and valid_size on direct I/O completion Chi Zhiling
2026-10-13  4:04 ` [PATCH v2 0/7] exfat: fix valid_size update races Namjae Jeon
2026-10-13  6:02   ` 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=07bfc007-145b-4ec5-a94e-c9f7bc3eedad@163.com \
    --to=chizhiling@163.com \
    --cc=Yuezhang.Mo@sony.com \
    --cc=chizhiling@kylinos.cn \
    --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®