Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp2259246rdb; Mon, 25 Dec 2023 03:14:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGidGVCB7hHWc2TFWjJcuk0BPdFEBoBFT8zIFkxypSzXs5y4ae4lhS+hRdD3evbxE/tgg6M X-Received: by 2002:a05:622a:60f:b0:423:74c4:34eb with SMTP id z15-20020a05622a060f00b0042374c434ebmr8652646qta.20.1703502865425; Mon, 25 Dec 2023 03:14:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703502865; cv=none; d=google.com; s=arc-20160816; b=JQqUVBXrxcYVLn2yQ6zybjhfVJ31xrTSUqR2+LLlyzsGOcRdDrMHvn4ZSQkJZYzKCw dtjluMgKtgW9ZWTPmTO6RHfdVKVy0oC/6wCSjMyyBxLG5Y39kaKa5975j2XFoUobOeom vUcagYVk373mkRQ+O6n0yy9bECnnhXtFYVQFNqvvf1eARNGdP8cYrTjl8x2hvni90JhJ 4SHqXZ8/8DEmMLr6dtMBpcbzsxy9gXts+kafdo2hTSId1aj4fGa2BrIoAR2iug3VztSa U/LwYXsZxnK7tqHT7PvYOr9ags5qRQ5dIiQvIeUTOYgGwb7tx4o2ozIDtu4RAbtBP7Je 5U+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from; bh=bJKmg5dWC6PvhPyN/ILONUpG+S84b3jK30LUbs6ODL8=; fh=JkrfyujbIDmycozXR7ZDiVuf6xBFur6C1+1NEIITJEI=; b=RsXADWajdl8oAxajDU5V2MfW5vpN0A7Qx3z4yF+eqxwI0Lh0XIO5s3kC/c4csZXzgO AZg/v2i5H5rkrkuKNtdX94gWDEqds7nyYyYRykKejwNpkgn4PNTFzNUZPUdnDD1C1p+N Y9lZLG4soMCAv3rN1JeAV0fxq62SF5Yl6801bzlQkxjIl2YKt6xnd2iqpnJyRAU5s4Yv XhQOKn+czutz9PA61DN95BZAOIfUbl7/CPv9LT2gkvZUeFwnWfobpGBX2KpV7E8a2sW6 TpDY1k8ZMEjAeoxQDNcNHdQLigwg5k62PCFBOIbNU3FIhQzWlnp1Vf8gimdVj/BT3l24 MaTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-11008-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11008-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id l15-20020a05622a174f00b004277aca7048si10107352qtk.371.2023.12.25.03.14.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Dec 2023 03:14:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11008-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-11008-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11008-linux.lists.archive=gmail.com@vger.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 240691C209E2 for ; Mon, 25 Dec 2023 11:14:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2E995101A; Mon, 25 Dec 2023 11:14:17 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (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 5E7095100A for ; Mon, 25 Dec 2023 11:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 3BPBDK38091375; Mon, 25 Dec 2023 19:13:20 +0800 (+08) (envelope-from Zhiguo.Niu@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4SzFTq2vzPz2QYWd5; Mon, 25 Dec 2023 19:06:55 +0800 (CST) Received: from bj08434pcu.spreadtrum.com (10.0.73.87) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 25 Dec 2023 19:13:18 +0800 From: Zhiguo Niu To: , CC: , , , , Subject: [PATCH V1] f2fs: fix potentail deadloop issue in do_recover_data Date: Mon, 25 Dec 2023 19:11:55 +0800 Message-ID: <1703502715-11936-1-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL:SHSQR01.spreadtrum.com 3BPBDK38091375 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; besides, the mainly error -ENOSPC has been handled as bug on, so other error cases can be proecssed normally without looping. 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: -- 1.9.1