Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 67c3c46

Browse files
chaseyugregkh
authored andcommitted
f2fs: fix to avoid racing in between read and OPU dio write
[ Upstream commit 0cac511 ] If lfs mode is on, buffered read may race w/ OPU dio write as below, it may cause buffered read hits unwritten data unexpectly, and for dio read, the race condition exists as well. Thread A Thread B - f2fs_file_write_iter - f2fs_dio_write_iter - __iomap_dio_rw - f2fs_iomap_begin - f2fs_map_blocks - __allocate_data_block - allocated blkaddr #x - iomap_dio_submit_bio - f2fs_file_read_iter - filemap_read - f2fs_read_data_folio - f2fs_mpage_readpages - f2fs_map_blocks : get blkaddr #x - f2fs_submit_read_bio IRQ - f2fs_read_end_io : read IO on blkaddr #x complete IRQ - iomap_dio_bio_end_io : direct write IO on blkaddr #x complete In LFS mode, if there is inflight dio, let's wait for its completion, this policy won't cover all race cases, however it is a tradeoff which avoids abusing lock around IO paths. Fixes: f847c69 ("f2fs: allow out-place-update for direct IO in LFS mode") Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6c59f87 commit 67c3c46

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

fs/f2fs/file.c

+4
Original file line numberDiff line numberDiff line change
@@ -4541,6 +4541,10 @@ static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
45414541
f2fs_trace_rw_file_path(iocb->ki_filp, iocb->ki_pos,
45424542
iov_iter_count(to), READ);
45434543

4544+
/* In LFS mode, if there is inflight dio, wait for its completion */
4545+
if (f2fs_lfs_mode(F2FS_I_SB(inode)))
4546+
inode_dio_wait(inode);
4547+
45444548
if (f2fs_should_use_dio(inode, iocb, to)) {
45454549
ret = f2fs_dio_read_iter(iocb, to);
45464550
} else {

0 commit comments

Comments
 (0)