Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3308852pxk; Mon, 21 Sep 2020 10:14:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMFCZHkTnfUNlmuGpNi0ke8bj1kl+rjmMMWUStGXBF2hqVcMvqp7oF0H1Bv+fBMl42DMOZ X-Received: by 2002:aa7:d04d:: with SMTP id n13mr716138edo.354.1600708473285; Mon, 21 Sep 2020 10:14:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600708473; cv=none; d=google.com; s=arc-20160816; b=gxWmqY+OUlQ1/TZ6o7IbZtw35DTzmyEzs3Ql23afDDeV4pKEAw2kUQ+aBght8HAmJZ HxUmj/2Cwn0/WAyjHxsaLhb0vdZwyvuk1s8W4znlsjT1fS/WTZiy9HmlMqHfba1/ESCP 7MD9NLMVd9iNUCN/Y6fJwCFahhsff9ytcq0P4+V/aHR4THzeRRNcqZXpXwXR9UhdmjxS SHDFN2jxkRrmil3oHF9vrZFI0iB9ItT9iI2nBbuyrWRNzhwSAZuuE9P7ZAirI7s5QezS NdrKu+j04EXBkEGOuq0YYM49HZqzz1qLibeQFJYAYvCtFYXKtl7lx/MAbayM8AwYDnxM ge4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hhBDY+viT3Rr6gWNvJHGO2PF4mbGKHWxNMBGyi+wBE8=; b=M+WfDSSI+G0syVKj2D93D66sQ53OlEzSJMnGeClx0kx1MNnAP8P1UF5/B5/jW+8hSy Y+7zKB+KQ0mJcpmx6F+q05VT+87gOUG6JFztSb06+vp7d/nfC1VscIZ2N1LP0Ez8mjpz qH1z/5VAEP9oZ2wrpd5dBzAcHu06SEmryGhU+l8CogRI6+zK283fvNuO8EL9nrZ7lTNI /m8fKy6YeDZ+PhaJ/W01FW5FIHAwJ3DX51L+MZhUlEzVCUzSwsFshzdathqLz5V1RlLh TJLXjJisfripyH/RGWqiYZncsg2pwYJjWQric2NP1+9hpUNn46i1XgvYp+yTRV9ePKBH tHLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Z3eXAeVM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cy19si8895933edb.313.2020.09.21.10.14.07; Mon, 21 Sep 2020 10:14:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Z3eXAeVM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729315AbgIUQ4Y (ORCPT + 99 others); Mon, 21 Sep 2020 12:56:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:50798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729224AbgIUQpE (ORCPT ); Mon, 21 Sep 2020 12:45:04 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6E32723976; Mon, 21 Sep 2020 16:45:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706703; bh=x7TMu42l2iyUZ9WwWu72BNXvkgmZ15HkeM+3qESgTwA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z3eXAeVMXGlx8mwpDKtMOYYhRTsuGc+z6Et2AmW2+cVdgefrCM7Lp5Ns1YqOBoq+1 TQBvib0gFt2GJdwwHWpoEFJ4JV5SwOAteD75aOOFz3IpjCoAdsi7iJN1nmTaw+sYEH nzyo9UZkeeiYqfk30DmEs1hH7/h/MhJGWTH9iPMs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sahitya Tummala , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.8 030/118] f2fs: fix indefinite loop scanning for free nid Date: Mon, 21 Sep 2020 18:27:22 +0200 Message-Id: <20200921162037.717047554@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162036.324813383@linuxfoundation.org> References: <20200921162036.324813383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sahitya Tummala [ Upstream commit e2cab031ba7b5003cd12185b3ef38f1a75e3dae8 ] If the sbi->ckpt->next_free_nid is not NAT block aligned and if there are free nids in that NAT block between the start of the block and next_free_nid, then those free nids will not be scanned in scan_nat_page(). This results into mismatch between nm_i->available_nids and the sum of nm_i->free_nid_count of all NAT blocks scanned. And nm_i->available_nids will always be greater than the sum of free nids in all the blocks. Under this condition, if we use all the currently scanned free nids, then it will loop forever in f2fs_alloc_nid() as nm_i->available_nids is still not zero but nm_i->free_nid_count of that partially scanned NAT block is zero. Fix this to align the nm_i->next_scan_nid to the first nid of the corresponding NAT block. Signed-off-by: Sahitya Tummala Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/node.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 98736d0598b8d..0fde35611df18 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -2375,6 +2375,9 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info *sbi, if (unlikely(nid >= nm_i->max_nid)) nid = 0; + if (unlikely(nid % NAT_ENTRY_PER_BLOCK)) + nid = NAT_BLOCK_OFFSET(nid) * NAT_ENTRY_PER_BLOCK; + /* Enough entries */ if (nm_i->nid_cnt[FREE_NID] >= NAT_ENTRY_PER_BLOCK) return 0; -- 2.25.1