]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
f2fs: fix to wait dio completion
authorChao Yu <chao@kernel.org>
Thu, 27 Jun 2024 07:17:11 +0000 (15:17 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:47:24 +0000 (12:47 +0100)
commit 96cfeb0389530ae32ade8a48ae3ae1ac3b6c009d upstream.

It should wait all existing dio write IOs before block removal,
otherwise, previous direct write IO may overwrite data in the
block which may be reused by other inode.

Cc: stable@vger.kernel.org
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Alva Lan <alvalan9@foxmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/f2fs/file.c

index 9ecf39c2b47d917265f8dedf1e6e8265c7dd7828..81ebbc1d37a62f6c7da69c20a3215b070e41ff13 100644 (file)
@@ -957,6 +957,13 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
                                return err;
                }
 
+               /*
+                * wait for inflight dio, blocks should be removed after
+                * IO completion.
+                */
+               if (attr->ia_size < old_size)
+                       inode_dio_wait(inode);
+
                down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
                down_write(&F2FS_I(inode)->i_mmap_sem);
 
@@ -1777,6 +1784,12 @@ static long f2fs_fallocate(struct file *file, int mode,
        if (ret)
                goto out;
 
+       /*
+        * wait for inflight dio, blocks should be removed after IO
+        * completion.
+        */
+       inode_dio_wait(inode);
+
        if (mode & FALLOC_FL_PUNCH_HOLE) {
                if (offset >= inode->i_size)
                        goto out;