Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp174856rwd; Mon, 12 Jun 2023 11:45:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ41sU7sZNoDWahaWa6P7n2m82yUTsC9/oOzho+HJah1bBlgQAeiMxc6tYYIGzoLQaGAixiG X-Received: by 2002:a17:902:c2c4:b0:1ae:55c8:6b60 with SMTP id c4-20020a170902c2c400b001ae55c86b60mr5972134pla.1.1686595539733; Mon, 12 Jun 2023 11:45:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686595539; cv=none; d=google.com; s=arc-20160816; b=FlwLKAyeciEuYvPISq/lBTxMtTsKD6TWf128DzpkqJx+r8BJIr6wpEbaRT+ykhWM+V Qc1RpfevkgRWo+pAQDaFQ5j8B7/095PGaOd+v6lXmVIxlHljaOMYYL47YOMvf6jk3z6B 5m84mULbKbfd2LzpHB1Im+gDx6zP+q8+/3Ob9crLSsg5yk/p+GiVqs6xA9rPQ0jw+QE7 0+g0aXIatBxBx1t88Cue7MXej7EyNm5e6qnAd/yLKyCqCVBNUj12sRkpAurpio6GiWdl uRaNXs6cjQnqTQnnzb5rFxZJvnGLQ0XkVO8C6A6WFKeeqL5Qc4Jb1VurdNtt5XHFLczo MhBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=NMEvv/gGiSVl+qG10Wxp1VYIbyZTCcH5Sgt3y00Mn3Y=; b=dWeGnH8FvkHwsuIiHJoGLF6b1SiqlxllEPwyFslGL8vXWYuu1REfu6Y6eYhJcSqrok cswMeNXHtBCncAi3kVi9Oua3DgNBQNWbdFwbBGp0WBfamdMVLbk+teIfcZ2FN63SQETB hRKd39XfrMyeR2XSYkvfkzYw9wyyLr0ivi8iTo9KhAch1cREbL7KfvoHbl90tieDrXko Pvm+sHTaZLMEOYNaStuDyiAARL6wV+rpZyRxiETM52PBj8ewLCp/xgx6M/WFqG6cJbcy u5IpOHWL2pp2Fb7RTA5XRQ2e3j4DHUxlQ4WcwjtypLBUKIQTVZ5kBj5qgerBEgpV6/cj KHog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iajpz+lP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z16-20020a170903019000b001b3e1afe784si484631plg.132.2023.06.12.11.45.27; Mon, 12 Jun 2023 11:45:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iajpz+lP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237876AbjFLS3Y (ORCPT + 99 others); Mon, 12 Jun 2023 14:29:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237901AbjFLS3H (ORCPT ); Mon, 12 Jun 2023 14:29:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B1751FDB for ; Mon, 12 Jun 2023 11:28:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DFD2762D01 for ; Mon, 12 Jun 2023 18:28:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25848C433EF; Mon, 12 Jun 2023 18:28:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686594524; bh=c+yC6Rpmu7pRoA+uZdVLb6zb7tJTIGh/t+XCxSFYxDs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iajpz+lP7/dk43ai9rqBh+O7PPCHDIZd05sufNM+6EO7KM9eKW3Z1qTrWvYZZh/FU iFXUPYu5iGQs25ISSPV4Km+kUF2Z3mqiIqiDXfvy0OfyQvrJqXhy6Sq9CUNoVvDRYH aCOv/YJmbv8WZdg/1OoiUC6+t/xDaGgukIWc3HDDNI7tZ70/5UbWx6C6+T8ubIbx53 U86tXtY3KZ8sBet2znXFUojKWc2YqTmoU61PLhSGZ0VdK1hIzEP1GE/ybSOZyMTH17 NRjnqCxSjIQTvzNkJD4zyOiDdxetYJZ9Rt0puZm71mmZUbZeDWbnGT4nz3lT3umAY4 H4bFUz3GMhwVg== Date: Mon, 12 Jun 2023 11:28:42 -0700 From: Jaegeuk Kim To: Yangtao Li Cc: Chao Yu , Nick Terrell , linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] f2fs: add sanity compress level check for compressed file Message-ID: References: <20230407183148.23231-1-frank.li@vivo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230407183148.23231-1-frank.li@vivo.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/08, Yangtao Li wrote: > Commit 3fde13f817e2 ("f2fs: compress: support compress level") > forgot to do basic compress level check, let's add it. > > Signed-off-by: Yangtao Li > --- > fs/f2fs/inode.c | 106 +++++++++++++++++++++++++++++++++++------------- > 1 file changed, 77 insertions(+), 29 deletions(-) > > diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c > index bb5b365a195d..c2460f51bf80 100644 > --- a/fs/f2fs/inode.c > +++ b/fs/f2fs/inode.c > @@ -10,6 +10,8 @@ > #include > #include > #include > +#include > +#include > > #include "f2fs.h" > #include "node.h" > @@ -202,6 +204,79 @@ void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page) > ri->i_inode_checksum = cpu_to_le32(f2fs_inode_chksum(sbi, page)); > } > > +static bool sanity_check_compress_inode(struct inode *inode, > + struct f2fs_inode *ri) > +{ > + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > + unsigned char compress_level; > + > + if (ri->i_compress_algorithm >= COMPRESS_MAX) { > + f2fs_warn(sbi, > + "%s: inode (ino=%lx) has unsupported compress algorithm: %u, run fsck to fix", > + __func__, inode->i_ino, ri->i_compress_algorithm); > + goto err; > + } > + if (le64_to_cpu(ri->i_compr_blocks) > > + SECTOR_TO_BLOCK(inode->i_blocks)) { > + f2fs_warn(sbi, > + "%s: inode (ino=%lx) has inconsistent i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix", > + __func__, inode->i_ino, le64_to_cpu(ri->i_compr_blocks), > + SECTOR_TO_BLOCK(inode->i_blocks)); > + goto err; > + } > + if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE || > + ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) { > + f2fs_warn(sbi, > + "%s: inode (ino=%lx) has unsupported log cluster size: %u, run fsck to fix", > + __func__, inode->i_ino, ri->i_log_cluster_size); > + goto err; > + } > + > + compress_level = le16_to_cpu(ri->i_compress_flag) >> > + COMPRESS_LEVEL_OFFSET; > + switch (ri->i_compress_algorithm) { > + case COMPRESS_LZO: > +#ifdef CONFIG_F2FS_FS_LZO > + if (compress_level) > + goto err_level; > +#endif > + break; > + case COMPRESS_LZORLE: > +#ifdef CONFIG_F2FS_FS_LZORLE > + if (compress_level) > + goto err_level; > +#endif > + break; > + case COMPRESS_LZ4: > +#ifdef CONFIG_F2FS_FS_LZ4 > +#ifdef CONFIG_F2FS_FS_LZ4HC > + if ((compress_level && compress_level < LZ4HC_MIN_CLEVEL) || > + compress_level > LZ4HC_MAX_CLEVEL) > +#else > + if (compress_level) > +#endif > + goto err_level; > +#endif > + break; > + case COMPRESS_ZSTD: > +#ifdef CONFIG_F2FS_FS_ZSTD > + if (!compress_level || compress_level > zstd_max_clevel()) I think compress_level=0 is wrong, since that'll be changed to the default level later. I'll modify to assign the correct level, so please revisit this patch later. > + goto err_level; > +#endif > + break; > + default: > + goto err_level; > + } > + > + return true; > +err_level: > + f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported compress level: %u, run fsck to fix", > + __func__, inode->i_ino, compress_level); > +err: > + set_sbi_flag(sbi, SBI_NEED_FSCK); > + return false; > +} > + > static bool sanity_check_inode(struct inode *inode, struct page *node_page) > { > struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > @@ -286,35 +361,8 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page) > if (f2fs_has_extra_attr(inode) && f2fs_sb_has_compression(sbi) && > fi->i_flags & F2FS_COMPR_FL && > F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, > - i_log_cluster_size)) { > - if (ri->i_compress_algorithm >= COMPRESS_MAX) { > - set_sbi_flag(sbi, SBI_NEED_FSCK); > - f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported " > - "compress algorithm: %u, run fsck to fix", > - __func__, inode->i_ino, > - ri->i_compress_algorithm); > - return false; > - } > - if (le64_to_cpu(ri->i_compr_blocks) > > - SECTOR_TO_BLOCK(inode->i_blocks)) { > - set_sbi_flag(sbi, SBI_NEED_FSCK); > - f2fs_warn(sbi, "%s: inode (ino=%lx) has inconsistent " > - "i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix", > - __func__, inode->i_ino, > - le64_to_cpu(ri->i_compr_blocks), > - SECTOR_TO_BLOCK(inode->i_blocks)); > - return false; > - } > - if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE || > - ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) { > - set_sbi_flag(sbi, SBI_NEED_FSCK); > - f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported " > - "log cluster size: %u, run fsck to fix", > - __func__, inode->i_ino, > - ri->i_log_cluster_size); > - return false; > - } > - } > + i_log_cluster_size)) > + return sanity_check_compress_inode(inode, ri); > > return true; > } > -- > 2.35.1