From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13FFAC433E2 for ; Mon, 14 Sep 2020 17:06:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7BAB206F4 for ; Mon, 14 Sep 2020 17:06:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600103214; bh=x7TMu42l2iyUZ9WwWu72BNXvkgmZ15HkeM+3qESgTwA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=sZfmEFft3T3WVoFFyunAgCeTRAr86nLu06hpXuNW4JGzAa20kQ+agnOhWYwy8ASZz 3XLZXRzIVIQIhK8Bk6WL0zHJPXUVdwXY9a9B6Ej02D3GDezo2xFaBWD0bzhvZYhkQ2 MCQkj8GolPLbCKVvLeEIOPebJ6WmQH9V+f9xPGVM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726019AbgINRGs (ORCPT ); Mon, 14 Sep 2020 13:06:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:32804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726609AbgINNFV (ORCPT ); Mon, 14 Sep 2020 09:05:21 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BDD1D22210; Mon, 14 Sep 2020 13:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600088666; bh=x7TMu42l2iyUZ9WwWu72BNXvkgmZ15HkeM+3qESgTwA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xcrpAqsXhzSHfH1LOVFpeRYLi7TI8uTThTVo6ADVvBUdx70kEbpslGoJVeQqyXQjF YueFKkwUgx7QfOeC6i8DgX9Ynp0mj62zBkYzM+/QKGVv8I5jlHj5Dw1Kl44t4hR9WQ 3p00fSbyxggWBrDELYPm69zXkYbL1wD/KyEGmtkM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sahitya Tummala , Chao Yu , Jaegeuk Kim , Sasha Levin , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH AUTOSEL 5.8 23/29] f2fs: fix indefinite loop scanning for free nid Date: Mon, 14 Sep 2020 09:03:52 -0400 Message-Id: <20200914130358.1804194-23-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914130358.1804194-1-sashal@kernel.org> References: <20200914130358.1804194-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64FD8C433E2 for ; Mon, 14 Sep 2020 13:05:04 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F2ED422247; Mon, 14 Sep 2020 13:05:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="a+9+xlx6"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="nV3sqyhF"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="xcrpAqsX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2ED422247 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1kHoAJ-0004f3-GA; Mon, 14 Sep 2020 13:05:03 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHoA1-0004eN-Tc for linux-f2fs-devel@lists.sourceforge.net; Mon, 14 Sep 2020 13:04:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=hhBDY+viT3Rr6gWNvJHGO2PF4mbGKHWxNMBGyi+wBE8=; b=a+9+xlx6FAK7FDQ3Mobj+Swyq/ YwVHCjAhfSEqf1vPj4ARbDMBNRHhAeqc5OwIdl2I7l64kidUNhSJS4Y2wHWfvIe78gSY6KmMzzyAw 4nr44T4R9o68+6DaKQw0kk53Pr/IGSJ+28ooZQfO74PhWOttjdYXI7ZSaoIk9slis1xM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=hhBDY+viT3Rr6gWNvJHGO2PF4mbGKHWxNMBGyi+wBE8=; b=nV3sqyhF6evDC8cFc9beBDjUQb njhY01hOz6Za1e6a9oRGxvfiPMUtFFD29xb6B+rxA5q82hdEt+n229Ef+iESj1snjFrFvHvJGvW/v X+u8KkRsffG0MuMH+EwZJpZZFt8cutzx1mezzjM1Pdg0OO3WX1xIoL3/CuZKE4D67OrE=; Received: from mail.kernel.org ([198.145.29.99]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1kHo9v-009A2V-7L for linux-f2fs-devel@lists.sourceforge.net; Mon, 14 Sep 2020 13:04:45 +0000 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BDD1D22210; Mon, 14 Sep 2020 13:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600088666; bh=x7TMu42l2iyUZ9WwWu72BNXvkgmZ15HkeM+3qESgTwA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xcrpAqsXhzSHfH1LOVFpeRYLi7TI8uTThTVo6ADVvBUdx70kEbpslGoJVeQqyXQjF YueFKkwUgx7QfOeC6i8DgX9Ynp0mj62zBkYzM+/QKGVv8I5jlHj5Dw1Kl44t4hR9WQ 3p00fSbyxggWBrDELYPm69zXkYbL1wD/KyEGmtkM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Date: Mon, 14 Sep 2020 09:03:52 -0400 Message-Id: <20200914130358.1804194-23-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914130358.1804194-1-sashal@kernel.org> References: <20200914130358.1804194-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-Headers-End: 1kHo9v-009A2V-7L Subject: [f2fs-dev] [PATCH AUTOSEL 5.8 23/29] f2fs: fix indefinite loop scanning for free nid X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sasha Levin , Jaegeuk Kim , linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 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 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel