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 62F83409617 for ; Tue, 30 Jun 2026 11:02:38 +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=1782817359; cv=none; b=QrWQQ9mCxGnkwEl/ADXyTXqshQ2r2KotXqHbiFRCzQUJzzEL7HHsTd504iagj0JpsNu2ib3KEu5EuxHxMCtyXtf12UahdB26TlGCsS+MiqtNRYAHzIUyQHoi3XO+ETImivUnEjrXE/r0IXErnLNDDTAHbgcIPYrRV05SmSQLS0g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782817359; c=relaxed/simple; bh=XzMhpk6ZGtNlzHxa/DXb8LfLMcpRAYkxv+HpfE+vEgM=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=j6OwikAxafetk24NVNeg4lzEw28mMkKmEEPIERSBX4pHueSkFuVGwgVJR9BGuqLd2/mhltJfN9asgmsX0egRz7e8Xnp5mEuJK6gr10Bfv8NASrOHZnd4DocfM9U2HYsSPolL7zmqwnNitVzjV8WVA15//i9tcT3FSRLABkBxc+c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZoSlMyGS; 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="ZoSlMyGS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 921AE1F000E9; Tue, 30 Jun 2026 11:02:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782817358; bh=WMJgU7k3s4TM2At+hKoin8UaWXfonWN6mqvCqCeU92Y=; h=Date:Cc:Subject:To:References:From:In-Reply-To; b=ZoSlMyGSHyoiDOQ3D6rPo2K7Yd2B4u61PcS3/N8AZ60xZsRbhT473TwqQPTH9xmXL dVGeJ6JbrY3j/K30qV0SwSBS1MF0sye4/wXsIkfan3kjYgteB+6WOftMkOWrKvCfkY wQ0FC2ZBjslO6biu9jIuQ5iamqDiZxN8KSUrJAEqCrUcq0mbFkpm7HGotTRlYspvDj 8fmTxwDRx9/25XeMeSH2bW5zd5VP1cosLKBJ8w0wL6mBLdrrYrM9aOJ49eadXTIdCs CP/Baqua0HoWUPCVrssYupRO4+f4XApJWe92Ty7wr+UtzfuJBc9ayZB69zUo20HQOn mgmxPpIrCo0dA== Message-ID: <5ad89199-f5e8-43a7-971a-575ff27c1d40@kernel.org> Date: Tue, 30 Jun 2026 19:02:34 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, jaegeuk@kernel.org, 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 To: Zhiguo Niu References: <20260629114918.224537-1-chao@kernel.org> Content-Language: en-US From: Chao Yu In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 6/30/26 16:50, Zhiguo Niu wrote: > Chao Yu via Linux-f2fs-devel > 于2026年6月29日周一 19:52写道: >> >> 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 > Hi Chao, > 8MB is section alinged when fallocated by f2fs_allocate_pinning_section?? > so How could there are unaligned blocks inside filesize? Zhiguo, As partial blkaddrs were persisted and recovered, see comments around f2fs_map_unlock(). >> >> 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; > Is it ok if we allow larger size truncation and also limit it to > aligned "F2FS_BLK_TO_BYTES(CAP_BLKS_PER_SEC(sbi)"? No, I think above example will still suffer section-unaligned issue. Thanks, > thanks! >> + /* >> + * 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