mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiale Yao <yaojiale02@163.com>
To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>,
	Eric Biggers <ebiggers@google.com>,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 2/5] f2fs: drain in-flight DIO before buffered writes
Date: Sun, 25 Oct 2026 20:41:11 +0800	[thread overview]
Message-ID: <20261025124115.3178287-3-yaojiale02@163.com> (raw)
In-Reply-To: <20261025124115.3178287-1-yaojiale02@163.com>

An asynchronous iomap direct write can remain in flight after the inode
lock is released. A buffered write can then dirty page cache before the
direct write completes its post-I/O invalidation, causing the
invalidation to fail and record -EIO in the mapping error sequence.

The pre-write checks can also zero post-EOF page cache while an earlier
direct write is still active.

Wait for in-flight DIO before post-EOF page-cache operations and before
buffered writes. Return -EAGAIN for a NOWAIT write that would need the
blocking post-EOF operation.

Fixes: a1e09b03e6f5 ("f2fs: use iomap for direct I/O")
Cc: stable@vger.kernel.org
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
 fs/f2fs/file.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 0c759cc99054..d3d0ebf2f6c3 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -5328,6 +5328,7 @@ static ssize_t f2fs_write_checks(struct kiocb *iocb, struct iov_iter *from)
 {
 	struct file *file = iocb->ki_filp;
 	struct inode *inode = file_inode(file);
+	loff_t end_pos;
 	ssize_t count;
 	int err;
 
@@ -5345,8 +5346,14 @@ static ssize_t f2fs_write_checks(struct kiocb *iocb, struct iov_iter *from)
 	if (err)
 		return err;
 
-	err = f2fs_zero_post_eof_page(inode,
-		iocb->ki_pos + iov_iter_count(from), true, true);
+	end_pos = iocb->ki_pos + iov_iter_count(from);
+	if (end_pos > i_size_read(inode)) {
+		if (iocb->ki_flags & IOCB_NOWAIT)
+			return -EAGAIN;
+		inode_dio_wait(inode);
+	}
+
+	err = f2fs_zero_post_eof_page(inode, end_pos, true, true);
 	if (err)
 		return err;
 	return count;
@@ -5436,6 +5443,8 @@ static ssize_t f2fs_buffered_write_iter(struct kiocb *iocb,
 	if (iocb->ki_flags & IOCB_NOWAIT)
 		return -EOPNOTSUPP;
 
+	inode_dio_wait(inode);
+
 	ret = generic_perform_write(iocb, from);
 
 	if (ret > 0) {
-- 
2.34.1


  parent reply	other threads:[~2026-10-25 12:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-25 12:41 [PATCH 0/5] fs: " Jiale Yao
2026-10-25 12:41 ` [PATCH 1/5] filemap: " Jiale Yao
2026-10-26 13:31   ` Jan Kara
2026-10-27 14:52     ` Christoph Hellwig
2026-10-25 12:41 ` Jiale Yao [this message]
2026-10-25 12:41 ` [PATCH 3/5] xfs: " Jiale Yao
2026-10-26  0:52   ` Dave Chinner
2026-10-25 12:41 ` [PATCH 4/5] xfs: drain in-flight DIO before zoned " Jiale Yao
2026-10-25 12:41 ` [PATCH 5/5] zonefs: drain in-flight DIO before " Jiale Yao

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=20261025124115.3178287-3-yaojiale02@163.com \
    --to=yaojiale02@163.com \
    --cc=chao@kernel.org \
    --cc=ebiggers@google.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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®