Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3354217pxb; Mon, 9 Nov 2020 09:02:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJxiuszrckqtqSeZc6xqtZm2j0X0tgvk0TYVntRkuUHqbL6XNwYBRKntN2YDHlU6Japkff4c X-Received: by 2002:aa7:ccd2:: with SMTP id y18mr16679588edt.11.1604941347021; Mon, 09 Nov 2020 09:02:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604941347; cv=none; d=google.com; s=arc-20160816; b=lp9u7JZyx89n0jGN8PoFppzd5xhNI+GiVZbRPE9Gc74+7BqdoI/n9ll8yh7ejE7OVP 9/eHPhkoExmr/SMmmAiB6seJ8CrBgTxgN3N/jNIExZM6TlfjfN2nCrSISCCphEScmFHt UnJgccx0qVv2+K17vpx+9Doo7UrwTyw6MLDhiMw2WUmavd4qjjfk0fMPfDnAcNbJuBZ+ lNeJd89vlP5eZQCTBzMwz6kn5BM9rE+n5fheB3OVaY+sduXJWcsdSXZ3kB/hsD0D/2wx RGhCpArOCVXdzA2fMIIQcyeGFdyb+LAlnAUInU2hvbeFyS/3oC7FWQqwiLoVhr71JUOD +SIg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=7JE4QSsK9QrrB2lOOAUjCi2qEBkw9gZsyDIAx0aolVE=; b=cNZDCaO0h1Yg9S6/fgefLBDEORjfWVYIpdtbUhEPIwQESYqmrWJoH2pwN7hvzVgNOL 5qCBxMngs4aeyCeQ1FLo01FxP8L5vo2ci0wO8tdUon+W72cuHEMMo1tjP17DQMdn6aPS c3WXlWm2exwlhyZIjEDnyqRQ7zYitB9eUhuLVmzDj4L5MHrceNQ7/SUnwncAwlydKAh4 Hc4j1ngYFF/P5CyfdhEa/EU2oo6LupTDeN4lT/cw26jbE2Q6OKwew5fLvKvlzvzvDlQM rF7/U2HHPL05TNMmkTdH5b8Ykz8iY0vb1M2IRveHoaLRjSXSosw2LLcL1gNMcYDyxnxN 4fBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kP5DkISn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nw21si7338647ejb.708.2020.11.09.09.02.03; Mon, 09 Nov 2020 09:02:27 -0800 (PST) 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=kP5DkISn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731025AbgKIRAP (ORCPT + 99 others); Mon, 9 Nov 2020 12:00:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:58240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730704AbgKIRAO (ORCPT ); Mon, 9 Nov 2020 12:00:14 -0500 Received: from localhost (unknown [104.132.1.66]) (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 692ED20789; Mon, 9 Nov 2020 17:00:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604941214; bh=e1fR8c3/u8ILpeETIXysn5Lg1umCymg7KmWhq+/rSak=; h=From:To:Cc:Subject:Date:From; b=kP5DkISnxV6x/qbDaYiMpCPbZTtX1cYBuTloAuAHYN0cKWH+492W5UCRq8ENlkNr3 49ktkkiX8+QvRgbRi8zIBpxEJ+NAfzdFZA9BgT6zpzeVwRyyKk7vFi+8Wq7jzk3N22 iHN7yeslNZv0kO/6KHWWyFgtWbChLvIEe7te+jdo= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Jaegeuk Kim , Light Hsieh Subject: [PATCH] f2fs: avoid race condition for shinker count Date: Mon, 9 Nov 2020 09:00:12 -0800 Message-Id: <20201109170012.2129411-1-jaegeuk@kernel.org> X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Light reported sometimes shinker gets nat_cnt < dirty_nat_cnt resulting in wrong do_shinker work. Basically the two counts should not happen like that. So, I suspect this race condtion where: - f2fs_try_to_free_nats __flush_nat_entry_set nat_cnt=2, dirty_nat_cnt=2 __clear_nat_cache_dirty spin_lock(nat_list_lock) list_move() spin_unlock(nat_list_lock) spin_lock(nat_list_lock) list_del() spin_unlock(nat_list_lock) nat_cnt=1, dirty_nat_cnt=2 nat_cnt=1, dirty_nat_cnt=1 Reported-by: Light Hsieh Signed-off-by: Jaegeuk Kim --- fs/f2fs/node.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 42394de6c7eb..e8ec65e40f06 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -269,11 +269,10 @@ static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i, { spin_lock(&nm_i->nat_list_lock); list_move_tail(&ne->list, &nm_i->nat_entries); - spin_unlock(&nm_i->nat_list_lock); - set_nat_flag(ne, IS_DIRTY, false); set->entry_cnt--; nm_i->dirty_nat_cnt--; + spin_unlock(&nm_i->nat_list_lock); } static unsigned int __gang_lookup_nat_set(struct f2fs_nm_info *nm_i, -- 2.29.2.222.g5d2a92d10f8-goog