Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1167248rdb; Wed, 24 Jan 2024 06:56:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGnh+GRDx17vGq7CJ5rUovuipO8Us5zxmGWA10zCuvwEay9IwyqRK6wcSK02AmiPoYZ4e+ X-Received: by 2002:a17:907:c08b:b0:a30:4cc6:fc22 with SMTP id st11-20020a170907c08b00b00a304cc6fc22mr1050788ejc.2.1706108208324; Wed, 24 Jan 2024 06:56:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706108208; cv=pass; d=google.com; s=arc-20160816; b=Xom848NTjfd26BLDZII4J9v3JJDjp6V2seKwSL5lNXuzHlffO9f6Qa8nEvIVbgbReS /0iQZ9/RFi44O8nH/JbH7qHShvzGO/5kRTeMYOvQY4pp8DZXXwAkpBxohr7IthbMJHnI +4v5BVZZ4m9xquPKr7TZe7SBVdsCFErkyHXryYJXkLr4zgUMuhmEm9AwKx07YyTgb7Al qu2deqSYjQJf3xaJ9F53iQuMJUYjlGDEQ7RYdEpEix+B9sfrlWCSllMMWNWVcvOr77i2 000izG/yWOD0tNtCOLkd6tuVRg3pm2s4rNsKdOp1DuW2puSbTXYHP+5CMzNIijLiRObG 1tHQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=6gUP3xZQzMw3jTBHI6Cc9TrKKQZZguSXBuD70gTvnik=; fh=9FJpETW6RBsfAd64bWh5hRpm2kkz4OD2bSmy/HaUZa8=; b=YrNITcKpIOqNLLrhMAdg5I7rbaqWcip23VqWNxvPToOEmOqCfmOuBUvyQgIjjgWdVD VItC/03iJ+PLVxFdN47KXFJdqXyNsOk35OmG0rDjS35ImnjI+gWnK1OvpmdURG5t1oUF vCW6X43sZL2EYo+z0O7Hi1CzRJbLa7bjRX9OCOontmqofjXd1tBW/iOb6q79o/SwkixW TmeedygQJ14Hrm4f0pFo8esbUHDd8ALW6B2ZdR/aicBnP+ICE9IjeID4CmJSJjDpwsQx ih6vYrZ/rm1n9lr++lbcpGApDY+pkAgcFLEq86sxEs1DWu4NTiwnvEi34TJCcUwlDgBZ BP/w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pj2mKTRr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-37208-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37208-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v9-20020a170906180900b00a30acd4988asi2162451eje.395.2024.01.24.06.56.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 06:56:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37208-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pj2mKTRr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-37208-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37208-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1B79A1F22BF6 for ; Wed, 24 Jan 2024 14:56:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 663141FAA; Wed, 24 Jan 2024 14:54:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pj2mKTRr" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 85F2532C88 for ; Wed, 24 Jan 2024 14:54:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706108078; cv=none; b=W6LD1rUvRn2pHuH5WYZiSH52c9xiQrDI8c7zYkc24gdyybkx/VjG3ykgo3Apmu43RTw696YTq2L+PbTx9RGZ+usHf6aVNtZG0WWlGKSGkmo3IrOF56U5ZyYpM1geme4TGpfwSpcYGumG8U+pW43QXOKKAxhEixD2mrhnGfgntxk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706108078; c=relaxed/simple; bh=EN20Jf/orEGnGWTKkhnrX0y5TE3fu6bVQexb33h8Zgw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LLP0HEykKo3EAMG5cQupvw6wyc5WtQm0YH95aVMXj8o2eUTvIJU62ZtqVTOncrmXiR+wz58punnmxCCowo6XU5cSZ4AyxVVoz+pK+OUUD7e2Uwdt15+lTOVbJUSk3BtWbpIXnyQTwr8GNufPJSgURuSPP01bvVUu0rBGyWtHndU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pj2mKTRr; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52974C433C7; Wed, 24 Jan 2024 14:54:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706108078; bh=EN20Jf/orEGnGWTKkhnrX0y5TE3fu6bVQexb33h8Zgw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=pj2mKTRrqqjBqq6BhTCRwxiKp3s55N2msA2nDLK63aWZfe2O8x6viPZ/yif0dl/Dr JMc6d/ZkZsn3hTGXrUzMeP8J2hsGCg98Gp/1wJKphm4jVpS4nT/q/nmH+h18dxx6W+ OQ9sPxQvy680F1F2F/eQNG/sYDTltLIaT6lGYIj2xZ7CI76GgK1FoIHMHWZFMerHEa gZ/1AXmwmGmdnXlMPMib4a+5S0dZ+UlgUH4jm0J7W5LlOf3IyU3enU+F3Yz1hTpKHf onsLVNDxC52CNR38XMGgRQS/XdVDIAFnkC1abKhIrCvAre0cVzD/Is+daLc9kySpj4 dKIQfZjFKBQNQ== Message-ID: Date: Wed, 24 Jan 2024 22:54:33 +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 Subject: Re: [PATCH V1] f2fs: fix potentail deadloop issue in do_recover_data To: Zhiguo Niu Cc: Zhiguo Niu , jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, ke.wang@unisoc.com References: <1703502715-11936-1-git-send-email-zhiguo.niu@unisoc.com> <74243f43-c129-4530-970c-4de2afcd307e@kernel.org> Content-Language: en-US From: Chao Yu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Zhiguo, Can you please check below version? Is it fine to you? https://lore.kernel.org/linux-f2fs-devel/20240124144915.19445-1-chao@kernel.org On 2024/1/22 13:46, Zhiguo Niu wrote: > Hi Chao > > On Mon, Jan 22, 2024 at 11:46 AM Chao Yu wrote: >> >> On 2023/12/25 19:11, Zhiguo Niu wrote: >>> There is a potentail deadloop issue in the corner case of >>> CONFIG_F2FS_FAULT_INJECTION is enabled and the return value >>> of f2fs_reserve_new_block is error but not -ENOSPC, such as >>> this error case: >>> if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC))) >>> return -EPERM; >> >> I don't see any path to trigger this error? am I missing something? >> >>> besides, the mainly error -ENOSPC has been handled as bug on, >>> so other error cases can be proecssed normally without looping. >> >> commit 975756c41332bc5e523e9f843271ed5ab6aaaaaa >> Author: Jaegeuk Kim >> Date: Thu May 19 11:57:21 2016 -0700 >> >> f2fs: avoid ENOSPC fault in the recovery process >> >> This patch avoids impossible error injection, ENOSPC, during recovery process. >> >> Please check above patch, I guess intention of adding such loop is >> to avoid mount failure due to fault injection was triggered in >> f2fs_reserve_new_block(). >> >> What about change as blew? >> - keep the loop to avoid mount failure. >> - remove bug_on() to avoid panic due to fault injection error. >> >> #define DEFAULT_RETRY_COUNT 8 >> >> for (loops = DEFAULT_RETRY_COUNT; loops > 0; loops--) { >> err = f2fs_reserve_new_block(&dn); >> if (!err || >> !IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) >> break; >> } > > Thanks for your detailed explanation and I understand. > It seems that the original process is also reasonable, > so it’s okay to keep it as it is. >> >> Thanks, >> >>> >>> Fixes: 956fa1ddc132 ("f2fs: fix to check return value of f2fs_reserve_new_block()") >>> Signed-off-by: Zhiguo Niu >>> --- >>> fs/f2fs/recovery.c | 26 ++++++++------------------ >>> 1 file changed, 8 insertions(+), 18 deletions(-) >>> >>> diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c >>> index 21381b7..5d658f6 100644 >>> --- a/fs/f2fs/recovery.c >>> +++ b/fs/f2fs/recovery.c >>> @@ -710,15 +710,10 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, >>> */ >>> if (dest == NEW_ADDR) { >>> f2fs_truncate_data_blocks_range(&dn, 1); >>> - do { >>> - err = f2fs_reserve_new_block(&dn); >>> - if (err == -ENOSPC) { >>> - f2fs_bug_on(sbi, 1); >>> - break; >>> - } >>> - } while (err && >>> - IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)); >>> - if (err) >>> + err = f2fs_reserve_new_block(&dn); >>> + if (err == -ENOSPC) >>> + f2fs_bug_on(sbi, 1); >>> + else if (err) >>> goto err; >>> continue; >>> } >>> @@ -727,15 +722,10 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, >>> if (f2fs_is_valid_blkaddr(sbi, dest, META_POR)) { >>> >>> if (src == NULL_ADDR) { >>> - do { >>> - err = f2fs_reserve_new_block(&dn); >>> - if (err == -ENOSPC) { >>> - f2fs_bug_on(sbi, 1); >>> - break; >>> - } >>> - } while (err && >>> - IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)); >>> - if (err) >>> + err = f2fs_reserve_new_block(&dn); >>> + if (err == -ENOSPC) >>> + f2fs_bug_on(sbi, 1); >>> + else if (err) >>> goto err; >>> } >>> retry_prev: