FAILED: patch "[PATCH] f2fs: fix to avoid potential section-unaligned pinfile" failed to apply to 6.12-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x d0a481fad5c7a3a56ecf54a099651216869f4d0a
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090949-defendant-bonsai-eda1@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From d0a481fad5c7a3a56ecf54a099651216869f4d0a Mon Sep 17 00:00:00 2001
From: Chao Yu <[email protected]>
Date: Mon, 29 Jun 2026 11:49:18 +0000
Subject: [PATCH] f2fs: fix to avoid potential section-unaligned pinfile
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
fs/f2fs/file.c +17 -11
@@ -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)) {
Sasha Levin
maintainerPATCH 1/3 f2fs: convert F2FS_I_SB to sbi in f2fs_setattr()
From: wangzijie <[email protected]>
[ Upstream commit 90c5ce37adf074ed85b26d1cd43074f29c0743ba ]
Introduce sbi in f2fs_setattr() and convert F2FS_I_SB to it. No logic change, just cleanup and prepare to get CAP_BLKS_PER_SEC(sbi).
Stable-dep-of: d0a481fad5c7 ("f2fs: fix to avoid potential section-unaligned pinfile")
--- fs/f2fs/file.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
fs/f2fs/file.c +7 -7
@@ -1015,9 +1015,10 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, {struct inode *inode =d_inode (dentry);struct f2fs_inode_info *fi =F2FS_I (inode); +struct f2fs_sb_info *sbi =F2FS_I_SB (inode);int err; -if (unlikely (f2fs_cp_error (F2FS_I_SB (inode)))) +if (unlikely (f2fs_cp_error (sbi)))return -EIO ; err =setattr_prepare (idmap, dentry, attr);
@@ -1056,12 +1057,11 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, }if (i_uid_needs_update (idmap, attr, inode) ||i_gid_needs_update (idmap, attr, inode)) { -f2fs_lock_op (F2FS_I_SB (inode)); +f2fs_lock_op (sbi); err =dquot_transfer (idmap, inode, attr);if (err) { -set_sbi_flag (F2FS_I_SB (inode), -SBI_QUOTA_NEED_REPAIR ); -f2fs_unlock_op (F2FS_I_SB (inode)); +set_sbi_flag (sbi,SBI_QUOTA_NEED_REPAIR ); +f2fs_unlock_op (sbi);return err; }/*
@@ -1071,7 +1071,7 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,i_uid_update (idmap, attr, inode);i_gid_update (idmap, attr, inode);f2fs_mark_inode_dirty_sync (inode, true); -f2fs_unlock_op (F2FS_I_SB (inode)); +f2fs_unlock_op (sbi); }if (attr->ia_valid &ATTR_SIZE ) {
@@ -1134,7 +1134,7 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,f2fs_mark_inode_dirty_sync (inode, true);/* inode change will produce dirty node pages flushed by checkpoint */ -f2fs_balance_fs (F2FS_I_SB (inode), true); +f2fs_balance_fs (sbi, true);return err; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 f2fs: don't allow unaligned truncation to smaller/equal size on pinned file
From: wangzijie <[email protected]>
[ Upstream commit d738f708564764ed591cb6ab50d55489f87c726a ]
To prevent scattered pin block generation, don't allow non-section aligned truncation to smaller or equal size on pinned file. But for truncation to larger size, after commit 3fdd89b452c2("f2fs: prevent writing without fallocate() for pinned files"), we only support overwrite IO to pinned file, so we don't need to consider attr->ia_size > i_size case.
Stable-dep-of: d0a481fad5c7 ("f2fs: fix to avoid potential section-unaligned pinfile")
--- fs/f2fs/file.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/f2fs/file.c +11 -0
@@ -1048,6 +1048,17 @@ 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 (is_quota_modification (idmap, inode, attr)) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 f2fs: fix to avoid potential section-unaligned pinfile
In reply to Sasha LevinFrom: Chao Yu <[email protected]>
[ Upstream commit d0a481fad5c7a3a56ecf54a099651216869f4d0a ]
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
--- fs/f2fs/file.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
fs/f2fs/file.c +17 -11
@@ -1048,17 +1048,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)) {
Signature · 1 line
2.53.0