From: Chi Zhiling <chizhiling@163.com>
To: exfat@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: Yuezhang.Mo@sony.com, dxdt@dev.snart.me, linkinjeon@kernel.org,
sj1557.seo@samsung.com, Chi Zhiling <chizhiling@kylinos.cn>
Subject: [PATCH v2 6/7] exfat: complete direct writes synchronously when they update metadata
Date: Tue, 13 Oct 2026 11:38:36 +0800 [thread overview]
Message-ID: <20261013033837.2748258-7-chizhiling@163.com> (raw)
In-Reply-To: <20261013033837.2748258-1-chizhiling@163.com>
From: Chi Zhiling <chizhiling@kylinos.cn>
The inode metadata for a direct write is updated in ->end_io(). That
handler runs without holding i_rwsem. As a result, the i_size update can
race with other operations.
Whenever a write extends beyond the current valid_size — that is,
whenever ->end_io() will have metadata to update — force synchronous
completion. This guarantees that the i_size update happens under the
inode lock.
Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
---
fs/exfat/file.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index 6209a991a118..efcfeab750c0 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -840,10 +840,16 @@ static ssize_t exfat_fallback_buffered_write(struct kiocb *iocb,
static ssize_t exfat_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
+ struct inode *inode = file_inode(iocb->ki_filp);
+ loff_t end = iocb->ki_pos + iov_iter_count(from);
+ unsigned int dio_flags = 0;
ssize_t ret;
+ if (end > exfat_get_valid_size(EXFAT_I(inode)))
+ dio_flags |= IOMAP_DIO_FORCE_WAIT;
+
ret = iomap_dio_rw(iocb, from, &exfat_write_iomap_ops,
- &exfat_write_dio_ops, 0, NULL, 0);
+ &exfat_write_dio_ops, dio_flags, NULL, 0);
if (ret == -ENOTBLK)
ret = 0;
else if (ret < 0)
--
2.53.0
next prev parent reply other threads:[~2026-10-13 3:39 UTC|newest]
Thread overview: 10+ 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-13 3:38 ` [PATCH v2 4/7] exfat: drop i_rwsem from exfat_page_mkwrite 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 ` Chi Zhiling [this message]
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=20261013033837.2748258-7-chizhiling@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®