From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 394FB283FDD for ; Thu, 2 Jul 2026 14:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783002402; cv=none; b=KMeUM+KQij2r67Ame5GZKLukXLATJOHNtSxb+CQM594UUfPW3ER7zM62V8OnMF/h22vW8lMbOSrmbgB2nrOQJmUNMfPblOFUcLACXwpxK6H8CtaiGFfNJP1S/rgrTjyKngeYiPz0AhMph6whX6Rs+WWnacvDDYOVs5P8f1AHf/c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783002402; c=relaxed/simple; bh=vB2lenBrQICYHvqjB6w/BwaUZPzCCGhGusiAver6cpA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AGv2ORsrwS9f1paiPZ+eShY+p5Q5mEwMXNbpTmrd3HZ1bwtT1I3/1+OesAlfYNSqS9tR627c4y/oqQN/IS7i2PuS3rjbosGl4DsOD4Z2CjMo8r/vsnZ+HJLxyJQUUy7/74l+e7Ak9HN/tmbwSL9tBrYJACJPxOC/VCaTmgYuFCU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oS6/KPMD; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oS6/KPMD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D3FA1F000E9; Thu, 2 Jul 2026 14:26:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783002400; bh=DeMLPBZwQFsjXJk4oZ0hNQRYybAoVSTD2iSvI8asCj0=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=oS6/KPMDhH5aVrMaL4kMgowUFPEzYIB2WMI8aSyqa85md1IR8amTInodPBZBczL8J 0DslWt3ea5ZqH9rY50w2kFHXwpM3XI44lclix57jEeBHPSK0sFRdHB5p1Twx14BHCh Q/HHIcP4+zcMM3j71ayEsL/KahIqut9tu7YAXUdxdPiCzkjj12N0N+z+BfRDQ/yDpg G2Pdcjbn3knSymhq1VgUM7/KYDGgH+d2/zrOsD09OD2kjcrn5cvcvclVvh/W6dsFhg EgKZEK1q1SFhmIK8rkQtXiTsWsi+vao7FX04GMS71SBZp8qAyemidiMZXiBjcjwpUk 6w1hSQFZjYlmQ== Date: Thu, 2 Jul 2026 14:26:39 +0000 From: Jaegeuk Kim To: Chao Yu Cc: stable@kernel.org, Daeho Jeong , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to avoid potential section-unaligned pinfile Message-ID: References: <20260629114918.224537-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260629114918.224537-1-chao@kernel.org> Hi Chao, On 06/29, Chao Yu via Linux-f2fs-devel wrote: > 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 Have we reproduced this? > > Fixes: f5a53edcf01e ("f2fs: support aligned pinned file") > Cc: stable@kernel.org > Cc: Daeho Jeong > Signed-off-by: Chao Yu > --- > 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