Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2491019lqp; Sun, 24 Mar 2024 23:21:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXL8pvzoAST+Dzo6RwoL2dbLkG3o7XBCeqIsMZ0eN0oppuKfKe3mj2ZB80Zgbx/U9AZpTYadpZZZQJZpksGGZhPZeG4K2xC1OIVyognBg== X-Google-Smtp-Source: AGHT+IHb46S4hyiSZgvwvDLk3W+/Nu4238ebVDKqVc/+GqcO1JHcQyi5KU8aWqu6pb5CaX5sGuhE X-Received: by 2002:a05:622a:19a8:b0:431:57e7:a0af with SMTP id u40-20020a05622a19a800b0043157e7a0afmr1918006qtc.17.1711347680133; Sun, 24 Mar 2024 23:21:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711347680; cv=pass; d=google.com; s=arc-20160816; b=et6PsCmYCqffnScj8TkzMPaQdjyQwfUoVKCK2jlExGBdAS/WXVVHl+tsw+lBHJMNjv eWCLxq0/574W5l36gPTpDYyLTCZumTptQiO40OGvCo+v9JEVyZ2/vQxMMPU7f25E1KkQ xkbT4TJemhCq1KdC0yCfsJH6XBS/HRYmUPPn11QIy+ayf2gG5pm60mu5SUjqmgPWwQjG Pal+DqjGeoWPF1naPnanjrVlsO6flfuwDOJCeVPfvKU0+TAm5fCJQLyCvfRGPkQhzu+P +y4rM69aSJrBZ87n9xuIsGFbuF88tGZsZyt1zJJ5DdxUUzXpUAaSEXuJ/o1zjQnPfOq/ IfKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=SgPZns7jvXv+QZMGkuVq9+PoXb1IX3MR9CmwctsKRo0=; fh=+KxPTYXXxCWHOu7TF00w8wc8LE5rguNythB+aM9DBBU=; b=kXJzEjOlAUrL+mH95zqrntAEs6tN2Io3VEbI8FrstihkV7M1GO8LkX5WB33Auup47I 7zd4cHSFiT73XrCnX616GqvaS4RZtFD8lSTlu+AqkXgvNnM/tBrsMzt7gT+nZCT+UjPY QQlTuaFL5+rUPi+7Wr8wirCOD1+Aah6oYlh09rWowWyUV7GR+yDFhm7GycqcT0NApc9E 5Jda/8v4qshkWI6/VOHmiHAjQ4tZITu2TRJtsW9Bl8oYD73DGkqji29jPJbcdw1hVjR9 QBsLRwbCMIM365zt/4Ix4z02Gr2imKEJ6Mg6ptdxe3cd0ixPpsXE8JTnk8WDnEmw4hzK bY9A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MNTm2Y2t; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114622-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114622-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id cb16-20020a05622a1f9000b00430a6018435si5201052qtb.738.2024.03.24.23.21.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 23:21:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-114622-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MNTm2Y2t; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114622-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114622-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D38671C2C55A for ; Mon, 25 Mar 2024 06:21:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43DC12A4912; Sun, 24 Mar 2024 23:56:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MNTm2Y2t" 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 6B682234500; Sun, 24 Mar 2024 23:18:00 +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=1711322281; cv=none; b=jqozN2D2a0Ss1jy1EfsJAhes3YrIKMi32V7DdIp963bTtnRGog9dsVP8b3tqvcwNqLeOxIRHfK0lSB4fCOI5gjGO02WjF7yLKBEz5+zSvXGU1Z/SVMzRHqBAMtzvU1oBROYYD/rsuNLqa4RyB/d7Wfv3smlaRjzl7JJKrqo8vaM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322281; c=relaxed/simple; bh=KF94tE9wc8iQd/yr9pjHcO4zDQAEnIv2U/NDSyNuoXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PrZms/Ay+4ybUIaqghA4JPfuKnD286lYrgFfsuAUe1pQ3+M6SeLsdWBrzAfwVhjMxuogD7iZCfaUBRTaHi/tcYo1dr6CKrwSvzpYPXpruDf2Hs/7nJMOSWOt+lTUxWW8vHDi/Wg7avLIloMs9eiQjHdbB2mFEdOo3RdVimldPic= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MNTm2Y2t; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EEABC433F1; Sun, 24 Mar 2024 23:17:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322280; bh=KF94tE9wc8iQd/yr9pjHcO4zDQAEnIv2U/NDSyNuoXY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MNTm2Y2t567o92JGDqgjBuG0CIL2oGr10dSN8tZxr8gTCRdBraSxh576y+8wo62cD q8WHsXxWsqdiCcTFr5GK6/wog8L8va5xgW/BMczejkC0PRniMT4s1K8RlW9xoT7wwJ bUmwoujFtuUduv8rkFl2wGy0UllNvZfuWBzd78CohkpensrNmVEAkDpgvimMVLNt1D 64Y38aoSqUpOZU7nQnlQvvHIIZfcCDw7kBMGlJ/VSq8OdZkXdfYMNsUZSasqtRKW02 mUe7EtbhmSjQbx6N5cW91PvxF4yK0AhePZ+U02tFwg8wY7Vbuok2gJpGuOPm7+kyDH dichUQ6e9jufA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Chao Yu , Zhiguo Niu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 6.1 363/451] f2fs: fix to avoid potential panic during recovery Date: Sun, 24 Mar 2024 19:10:39 -0400 Message-ID: <20240324231207.1351418-364-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Chao Yu [ Upstream commit 21ec68234826b1b54ab980a8df6e33c74cfbee58 ] During recovery, if FAULT_BLOCK is on, it is possible that f2fs_reserve_new_block() will return -ENOSPC during recovery, then it may trigger panic. Also, if fault injection rate is 1 and only FAULT_BLOCK fault type is on, it may encounter deadloop in loop of block reservation. Let's change as below to fix these issues: - remove bug_on() to avoid panic. - limit the loop count of block reservation to avoid potential deadloop. Fixes: 956fa1ddc132 ("f2fs: fix to check return value of f2fs_reserve_new_block()") Reported-by: Zhiguo Niu Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/f2fs.h | 5 +++++ fs/f2fs/recovery.c | 33 ++++++++++++++++----------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index a81091a5e282d..f5d69893d2d92 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -74,6 +74,11 @@ struct f2fs_fault_info { extern const char *f2fs_fault_name[FAULT_MAX]; #define IS_FAULT_SET(fi, type) ((fi)->inject_type & BIT(type)) + +/* maximum retry count for injected failure */ +#define DEFAULT_FAILURE_RETRY_COUNT 8 +#else +#define DEFAULT_FAILURE_RETRY_COUNT 1 #endif /* diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index 53a6487f91e44..f5efc37a2b513 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -582,6 +582,19 @@ static int check_index_in_prev_nodes(struct f2fs_sb_info *sbi, return 0; } +static int f2fs_reserve_new_block_retry(struct dnode_of_data *dn) +{ + int i, err = 0; + + for (i = DEFAULT_FAILURE_RETRY_COUNT; i > 0; i--) { + err = f2fs_reserve_new_block(dn); + if (!err) + break; + } + + return err; +} + static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, struct page *page) { @@ -683,14 +696,8 @@ 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)); + + err = f2fs_reserve_new_block_retry(&dn); if (err) goto err; continue; @@ -698,16 +705,8 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, /* dest is valid block, try to recover from src to dest */ 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)); + err = f2fs_reserve_new_block_retry(&dn); if (err) goto err; } -- 2.43.0