Patch "f2fs: fix to avoid racing in between read and OPU dio write" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    f2fs: fix to avoid racing in between read and OPU dio write

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     f2fs-fix-to-avoid-racing-in-between-read-and-opu-dio.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit e3f6306afcb1826509607f3ffba94673f5ad8622
Author: Chao Yu <chao@xxxxxxxxxx>
Date:   Thu Jun 27 15:15:21 2024 +0800

    f2fs: fix to avoid racing in between read and OPU dio write
    
    [ Upstream commit 0cac51185e65dc2a20686184e02f3cafc99eb202 ]
    
    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: f847c699cff3 ("f2fs: allow out-place-update for direct IO in LFS mode")
    Signed-off-by: Chao Yu <chao@xxxxxxxxxx>
    Signed-off-by: Jaegeuk Kim <jaegeuk@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 81394c08ef850..f03320c47c823 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -4490,6 +4490,10 @@ static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
 	if (trace_f2fs_dataread_start_enabled())
 		f2fs_trace_rw_file_path(iocb, iov_iter_count(to), READ);
 
+	/* In LFS mode, if there is inflight dio, wait for its completion */
+	if (f2fs_lfs_mode(F2FS_I_SB(inode)))
+		inode_dio_wait(inode);
+
 	if (f2fs_should_use_dio(inode, iocb, to)) {
 		ret = f2fs_dio_read_iter(iocb, to);
 	} else {




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux