[PATCH v2] f2fs: drain in-flight DIO before buffered fallback
From: Jiale Yao
Date: Sun Oct 25 2026 - 21:36:19 EST
A partial direct write can fall back to buffered I/O for the unwritten
remainder. Other asynchronous direct writes may still be active after their
submitters release the inode lock. Their completion can invalidate pages
dirtied by the fallback before it flushes them, causing page-cache
invalidation failures and recording an I/O error.
Wait for all in-flight direct I/O before the fallback dirties page cache.
This only serializes the internal direct-to-buffered fallback and does not
change ordinary buffered write handling.
Fixes: a1e09b03e6f5 ("f2fs: use iomap for direct I/O")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jiale Yao <yaojiale02@xxxxxxx>
---
fs/f2fs/file.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 0c759cc99054..e54456e3a226 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -5596,6 +5596,7 @@ static ssize_t f2fs_dio_write_iter(struct kiocb *iocb, struct iov_iter *from,
* The direct write was partial, so we need to fall back to a
* buffered write for the remainder.
*/
+ inode_dio_wait(inode);
ret2 = f2fs_buffered_write_iter(iocb, from);
if (iov_iter_count(from))
--
2.34.1