All of lore.kernel.org
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs: fix to avoid potential section-unaligned pinfile
@ 2026-06-29 11:49 ` Chao Yu
  0 siblings, 0 replies; 14+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2026-06-29 11:49 UTC (permalink / raw)
  To: jaegeuk; +Cc: stable, Daeho Jeong, linux-kernel, linux-f2fs-devel

Blocks of pinfile may not aligned to section size due to wrong use
on pinfile, result in heavy overhead of GC, let avoid this by
adding additional check condition in f2fs_setattr().

- truncate -s 8mb pinfile
: random checkpoint may persist filesize w/ inode
- fallocate -o 0 -l 8mb pinfile
 - f2fs_fallocate
  - f2fs_expand_inode_data
   - f2fs_allocate_pinning_section
   - f2fs_map_blocks
    - f2fs_map_lock
    - __allocate_data_block
    - file_need_truncate
    : w/ FADVISE_TRUNC_BIT, we can expect unaligned mapping can be
      truncated while open() if f2fs is not umount abnormally
    - f2fs_map_unlock
    : following f2fs checkpoint and sudden power-cut

- mount
- open pinfile
 - f2fs_file_open
  - finish_preallocate_blocks
   - truncate_setsize
   : filesize is 8mb
   - f2fs_truncate
   : can only truncate block outside filesize, rather than truncating
     unaligned blocks inside filesize

Fixes: f5a53edcf01e ("f2fs: support aligned pinned file")
Cc: stable@kernel.org
Cc: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Chao Yu <chao@kernel.org>
---
 fs/f2fs/file.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index f4facd409d9b..11cc8d79c235 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1107,17 +1107,23 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 			!IS_ALIGNED(attr->ia_size,
 			F2FS_BLK_TO_BYTES(fi->i_cluster_size)))
 			return -EINVAL;
-		/*
-		 * To prevent scattered pin block generation, we don't allow
-		 * smaller/equal size unaligned truncation for pinned file.
-		 * We only support overwrite IO to pinned file, so don't
-		 * care about larger size truncation.
-		 */
-		if (f2fs_is_pinned_file(inode) &&
-			attr->ia_size <= i_size_read(inode) &&
-			!IS_ALIGNED(attr->ia_size,
-			F2FS_BLK_TO_BYTES(CAP_BLKS_PER_SEC(sbi))))
-			return -EINVAL;
+
+		if (f2fs_is_pinned_file(inode)) {
+			/*
+			 * It may break section-aligned fallocate recovery
+			 * mechanism, so do not allow larger size truncation.
+			 */
+			if (attr->ia_size > i_size_read(inode))
+				return -EINVAL;
+			/*
+			 * To prevent scattered pin block generation, we don't
+			 * allow smaller/equal size unaligned truncation for
+			 * pinned file.
+			 */
+			else if (!IS_ALIGNED(attr->ia_size,
+				F2FS_BLK_TO_BYTES(CAP_BLKS_PER_SEC(sbi))))
+				return -EINVAL;
+		}
 	}
 
 	if (is_quota_modification(idmap, inode, attr)) {
-- 
2.49.0



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2026-07-14  3:00 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-29 11:49 [f2fs-dev] [PATCH] f2fs: fix to avoid potential section-unaligned pinfile Chao Yu via Linux-f2fs-devel
2026-06-29 11:49 ` Chao Yu
2026-06-30  8:50 ` [f2fs-dev] " Zhiguo Niu
2026-06-30  8:50   ` Zhiguo Niu
2026-06-30 11:02   ` Chao Yu
2026-06-30 11:02     ` Chao Yu via Linux-f2fs-devel
2026-07-01  3:26     ` Zhiguo Niu
2026-07-01  3:26       ` Zhiguo Niu
2026-07-02 14:26 ` Jaegeuk Kim via Linux-f2fs-devel
2026-07-02 14:26   ` Jaegeuk Kim
2026-07-03  0:17   ` Chao Yu
2026-07-03  0:17     ` Chao Yu via Linux-f2fs-devel
2026-07-14  3:00 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
2026-07-14  3:00   ` patchwork-bot+f2fs

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.