* [PATCH] exfat: clear the volume dirty flag only when remounting read-only
@ 2026-09-03 9:26 Chi Zhiling
2026-09-03 23:28 ` Namjae Jeon
0 siblings, 1 reply; 3+ messages in thread
From: Chi Zhiling @ 2026-09-03 9:26 UTC (permalink / raw)
To: exfat, linux-kernel; +Cc: Namjae Jeon, Sungjong Seo, Yuezhang Mo, Chi Zhiling
From: Chi Zhiling <chizhiling@kylinos.cn>
exfat_reconfigure() does not hold s_lock while calling
sync_filesystem(). Therefore, the filesystem can become dirty again
between the sync and clearing the volume dirty flag, leaving a dirty
filesystem with a clean volume flag.
Holding s_lock across sync_filesystem() is not an option because it can
lead to a deadlock: writeback takes s_lock in exfat_write_inode().
Instead, clear the volume dirty flag only when remounting the filesystem
read-only, where no writer can modify the filesystem after the sync.
For a normal read-only remount, reconfigure_super() calls
sb_prepare_remount_readonly() before ->reconfigure(), which returns
-EBUSY if any writer is still active. Afterwards
sb_start_ro_state_change() sets sb->s_readonly_remount, so
mnt_get_write_access() fails with -EROFS and no new writer can start
until the reconfiguration finishes. Therefore no writer can race with
the sync and the clearing.
Forced remounts are different: with SB_FORCE, reconfigure_super() skips
sb_prepare_remount_readonly(), so the writers active at that moment are
not blocked and can still dirty the filesystem after the sync. Do not
clear the volume dirty flag in this case.
Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
---
fs/exfat/super.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fs/exfat/super.c b/fs/exfat/super.c
index a9ea36ba2693..268732571837 100644
--- a/fs/exfat/super.c
+++ b/fs/exfat/super.c
@@ -775,9 +775,12 @@ static int exfat_reconfigure(struct fs_context *fc)
fc->sb_flags |= SB_NODIRATIME;
sync_filesystem(sb);
- mutex_lock(&sbi->s_lock);
- exfat_clear_volume_dirty(sb);
- mutex_unlock(&sbi->s_lock);
+
+ if ((fc->sb_flags & (SB_FORCE | SB_RDONLY)) == SB_RDONLY) {
+ mutex_lock(&sbi->s_lock);
+ exfat_clear_volume_dirty(sb);
+ mutex_unlock(&sbi->s_lock);
+ }
if (new_opts->allow_utime == (unsigned short)-1)
new_opts->allow_utime = ~new_opts->fs_dmask & 0022;
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] exfat: clear the volume dirty flag only when remounting read-only
2026-09-03 9:26 [PATCH] exfat: clear the volume dirty flag only when remounting read-only Chi Zhiling
@ 2026-09-03 23:28 ` Namjae Jeon
2026-09-04 1:46 ` Chi Zhiling
0 siblings, 1 reply; 3+ messages in thread
From: Namjae Jeon @ 2026-09-03 23:28 UTC (permalink / raw)
To: Chi Zhiling; +Cc: exfat, linux-kernel, Sungjong Seo, Yuezhang Mo, Chi Zhiling
> diff --git a/fs/exfat/super.c b/fs/exfat/super.c
> index a9ea36ba2693..268732571837 100644
> --- a/fs/exfat/super.c
> +++ b/fs/exfat/super.c
> @@ -775,9 +775,12 @@ static int exfat_reconfigure(struct fs_context *fc)
> fc->sb_flags |= SB_NODIRATIME;
>
> sync_filesystem(sb);
> - mutex_lock(&sbi->s_lock);
> - exfat_clear_volume_dirty(sb);
> - mutex_unlock(&sbi->s_lock);
> +
> + if ((fc->sb_flags & (SB_FORCE | SB_RDONLY)) == SB_RDONLY) {
Could we also add !sb_rdonly(sb) here?
if ((fc->sb_flags & (SB_FORCE | SB_RDONLY)) == SB_RDONLY &&
!sb_rdonly(sb))
Thanks.
> + mutex_lock(&sbi->s_lock);
> + exfat_clear_volume_dirty(sb);
> + mutex_unlock(&sbi->s_lock);
> + }
>
> if (new_opts->allow_utime == (unsigned short)-1)
> new_opts->allow_utime = ~new_opts->fs_dmask & 0022;
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] exfat: clear the volume dirty flag only when remounting read-only
2026-09-03 23:28 ` Namjae Jeon
@ 2026-09-04 1:46 ` Chi Zhiling
0 siblings, 0 replies; 3+ messages in thread
From: Chi Zhiling @ 2026-09-04 1:46 UTC (permalink / raw)
To: Namjae Jeon; +Cc: exfat, linux-kernel, Sungjong Seo, Yuezhang Mo, Chi Zhiling
On 9/4/26 7:28 AM, Namjae Jeon wrote:
>> diff --git a/fs/exfat/super.c b/fs/exfat/super.c
>> index a9ea36ba2693..268732571837 100644
>> --- a/fs/exfat/super.c
>> +++ b/fs/exfat/super.c
>> @@ -775,9 +775,12 @@ static int exfat_reconfigure(struct fs_context *fc)
>> fc->sb_flags |= SB_NODIRATIME;
>>
>> sync_filesystem(sb);
>> - mutex_lock(&sbi->s_lock);
>> - exfat_clear_volume_dirty(sb);
>> - mutex_unlock(&sbi->s_lock);
>> +
>> + if ((fc->sb_flags & (SB_FORCE | SB_RDONLY)) == SB_RDONLY) {
> Could we also add !sb_rdonly(sb) here?
> if ((fc->sb_flags & (SB_FORCE | SB_RDONLY)) == SB_RDONLY &&
> !sb_rdonly(sb))
Yes, this way we do not call exfat_clear_volume_dirty() when remounting
from RO to RO. I will update it in v2.
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-04 1:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-03 9:26 [PATCH] exfat: clear the volume dirty flag only when remounting read-only Chi Zhiling
2026-09-03 23:28 ` Namjae Jeon
2026-09-04 1:46 ` Chi Zhiling
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®