Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3285485pxk; Mon, 21 Sep 2020 09:41:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLtndcWR/GfjHVxI8pGG0mRT1vRkJpNTbbe/WWAISrW6H1XkvKiDum8Lyx7yPZqq+C+tk7 X-Received: by 2002:a17:906:4bc4:: with SMTP id x4mr349996ejv.240.1600706505970; Mon, 21 Sep 2020 09:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600706505; cv=none; d=google.com; s=arc-20160816; b=L5GQSTCB1G7zOSqh4G4iLzu5KR3tYwXh93YcSebJR+eU8V7/bvVl0s9oUlVv9xsmuP KROdeUUq8yh5GnK1usXH0FP/2KQvyZt3xb6TbGJZh5opQJ/Zldzt8xHvdzKORth2tx4L 0xpBULPi+8YvlmjyyQt9h2NcBa9mbfFwhH8m8ViNj2Ksmqei46U248wiFIp51FL6yUp9 EGTVuhkmM1uzDowi9R/No4lyQMerRaedsO7yTJRQ+lPwMiBjWlzlLj0vYR7eaLzidzA8 0PpXNcTVoSCcKRhm2zrSBy4C/FIq6LqQylaMl48/aGHo74ewg/ARz8xNOrMC0ztGgC0H uu6g== 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=PHCPQ2Q4mL492D7ajatINvqvchNbdO75ZKXAGNip7t4=; b=r6vcscI6o4ThF5hbykR5a0Mv8aGxY3Y/nBfF6hKvbboeilb80z8Hto2VQLi7/u6hQY pmuYc+JrvXhwUdLWOK+FVVqlqLR0o1E/L66kdsjilpHik1cmLKRP20zGr+J5q/DRtYdY NdgWV/HVWuBjlJ6iPrNprE5GpTDr3npX2jn3ZQPl7Ntfgv/tTEc0nkZeLe3ky55VkLvW vVQI7PQYrQzulzeHNd1ZFFJjpiildbQHC6ME7d30Fu0LH57QvRPEZJNW9V1ucu/AsnUL DsShRu+qoAVh1avs1h1XSkgnlotgCke3ilYA+/6DaIRU8EYvGRBq2YMsjfqOSVr6wxB1 X/bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sEbdBuEs; 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 l2si8548187ejc.209.2020.09.21.09.41.22; Mon, 21 Sep 2020 09:41:45 -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=sEbdBuEs; 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 S1728588AbgIUQjb (ORCPT + 99 others); Mon, 21 Sep 2020 12:39:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:41448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728260AbgIUQj2 (ORCPT ); Mon, 21 Sep 2020 12:39:28 -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 3D5D5238E6; Mon, 21 Sep 2020 16:39:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706367; bh=cQyjucVY8CZsvRzxCHhH1L4lHDaLKcIcO8qKgRX20JI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sEbdBuEssflJ6k4s18eE3A3vobTHGYleTiwudjSLs1wCKVAPXMhfBmq+23wkgat8X LJSa9hfyOn5YdP8zuRhHnfHrI4i2zhWl304SJJ2+5Ntjj6sa9N3wtfxUF4q/BIg5vt MYy8LS42eyaNzJ8cKA7WiUuruukJ4woNMv3zeZ3U= 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 4.14 72/94] f2fs: fix indefinite loop scanning for free nid Date: Mon, 21 Sep 2020 18:27:59 +0200 Message-Id: <20200921162038.835192494@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162035.541285330@linuxfoundation.org> References: <20200921162035.541285330@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 e7b8e2b35e226..f8006f62c5467 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -2011,6 +2011,9 @@ static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) 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_LIST] >= NAT_ENTRY_PER_BLOCK) return; -- 2.25.1