Skip to contentSkip to conversation

f2fs: fix to wait dio completion

PATCH In review Alva Lan 2 participants 2 messages Jan 2, 2025 Stable branch

lore
Share & tools
lore

Alva Lan

author
#0 lore raw

PATCH 1/1 f2fs: fix to wait dio completion

From: Chao Yu <[email protected]>

[ Upstream commit 96cfeb0389530ae32ade8a48ae3ae1ac3b6c009d ]

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.

[ Resolve line conflicts to make it work on 6.6.y ]
---
 fs/f2fs/file.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
fs/f2fs/file.c +13 -0
index 196755a34833..ae129044c52f 100644
@@ -1037,6 +1037,13 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 				return err;
 		}
 
+		/*
+		 * wait for inflight dio, blocks should be removed after
+		 * IO completion.
+		 */
+		if (attr->ia_size < old_size)
+			inode_dio_wait(inode);
+
 		f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
 		filemap_invalidate_lock(inode->i_mapping);
 
@@ -1873,6 +1880,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;
Signature · 1 line
2.43.0
maintainer
#1 lore raw

[ Sasha's backport helper bot ]

Hi,

The upstream commit SHA1 provided is correct: 96cfeb0389530ae32ade8a48ae3ae1ac3b6c009d

WARNING: Author mismatch between patch and upstream commit:
Backport author: Alva Lan<[email protected]> Commit author: Chao Yu<[email protected]>

Status in newer kernel trees:
6.12.y | Present (exact SHA1)
6.6.y | Not found

Note: The patch differs from the upstream commit:
---
1: 96cfeb038953 ! 1: e3d82566464b f2fs: fix to wait dio completion
@@ Metadata
## Commit message ##
f2fs: fix to wait dio completion

+ [ Upstream commit 96cfeb0389530ae32ade8a48ae3ae1ac3b6c009d ]
+
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.
@@ Commit message

+ [ Resolve line conflicts to make it work on 6.6.y ]
+ Signed-off-by: Alva Lan <[email protected]>

## fs/f2fs/file.c ##
@@ fs/f2fs/file.c: int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
@@ fs/f2fs/file.c: int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
+ if (attr->ia_size < old_size)
+ inode_dio_wait(inode);
+
- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
+ f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
filemap_invalidate_lock(inode->i_mapping);

@@ fs/f2fs/file.c: static long f2fs_fallocate(struct file *file, int mode,
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.6.y        |  Success    |  Success   |