Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp138952lqe; Wed, 27 Mar 2024 00:56:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUyakgdm0B5YcvN+teD35u9EfsaMDALgutxe2RamjQxiL9agzPkbiWSnBRjlybZ3zgu6ZMJ7cMTR537gLzlwofvUAgLScKaH4AGS4kKrw== X-Google-Smtp-Source: AGHT+IEoJ4s/sFiuqfqZOzGjOju+u87TLIt1oGH1n3lGkK+Amhy0SdaapX+iecwhtPVe9s8PCeWr X-Received: by 2002:a05:6214:da6:b0:696:3902:72e6 with SMTP id h6-20020a0562140da600b00696390272e6mr1945129qvh.51.1711526171636; Wed, 27 Mar 2024 00:56:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711526171; cv=pass; d=google.com; s=arc-20160816; b=inhZIurPn1GCxGXvtIFjNTGlFdnf+Ou0H8auad1cJcR2CEI+aERpwX2Ly/t2jczGUV w+E/0HjYOBQQKbjfIE33Y/URUt/22xgRqCyNR2qJRmaTZLV8xMCXG7CcL058ATcdrF2g z/6fCOU16E/UovQ4YgFaHj9xUbpeSrN/eRDWBVcNoaN3pRmv9G/ONEmdMoT5wYJ161S8 sGy3S1+HkJvNT8ZOl3GX8rvyndkPqm0S2MofAY3SPvrBbMHoc2+K4lNfkLJghZIz0hUF ns0NSEhxQeULT1ZEzA20ILc0z1R0CEU3n+M5RGnFmb/4f1qz5w6Ky7Kuftl7QviTE8dz 5iZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:to:from; bh=ri/8XUbygCYe6IZY6niv8E0/1ho14PqcOraf07HYPAg=; fh=TazUyFmBbwYqFjsNijml3vz8raRESieP8ZVe445mjXA=; b=Yodr+/SSNG3EVbwTUrEEaAOG8CrfFFwCQTdOD5DyPVw0tA2iC+X/9AzgydLC8xCP5o Xs37oV852iJbmbAeRKbFOUysnMYBLeDN7Dl6QQd+29/eKV//zwu7vRPunB1Ze4IpxW64 qgAStsBxOuUVKmAOGq3E+S9EXNl1FSxBBycljUpvCp7wnjAi/2ZzVLs1GbNdKHuQbxaG pdflFZMGK1e8QD5pVHKWQljKySjHmp9bbt74zzPTMsCgYuVdYk6EXoKBCY66h01V0XtG 7koOIfT9BqJuoFw0ZcCbc4UgrqfH1SeBTPaPW7f9D0751m8V6TLO5F2M2YVTJCLkJuPk v+OQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-120475-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120475-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 ed7-20020ad44ea7000000b00696a2fbefd9si2520322qvb.546.2024.03.27.00.56.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 00:56:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120475-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; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-120475-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120475-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 5C7201C261FA for ; Wed, 27 Mar 2024 07:56:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DFE642C68E; Wed, 27 Mar 2024 07:56:05 +0000 (UTC) Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [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 C21124C81 for ; Wed, 27 Mar 2024 07:56:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711526165; cv=none; b=ghiUOSt6S1bDU2D+AxoMhJIALPxqBGGmCZZhK6y4QCKw9ZuCbhie5GlLkD1CxvvM4j65E/JILYls81i0ILuHy8DaKH7aMFcOwy1Q3iIuGA00rtKxavs4BEwo2wmIPvIrzSIirYA0K3yswvALn/PgFrQCQT/JRnmEZrzk2qCDOx8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711526165; c=relaxed/simple; bh=UUlN669h6JKDJmNPQpWaHRrgFptpJalBabslS5/qzX0=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=AXEXqwSu6SojwCIfC6SAp6iu2L3mkqjse5REC3hm3bjzw59HgDDft99OEiGxj7pQLntcCS25kB9wQR6Yf0MngI/RKIos2ZCPumPlnpzFZrPRkXKIznw7QTRgP23lWMiOX0nW79EKVRzgeQov1xFvFCLS97U0hO/p1kkP0cOUl/4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 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 42R7tMMt081647; Wed, 27 Mar 2024 15:55:22 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4V4Jnv0Sg0z2Klktn; Wed, 27 Mar 2024 15:53:39 +0800 (CST) Received: from bj03382pcu01.spreadtrum.com (10.0.73.40) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 27 Mar 2024 15:55:20 +0800 From: "zhaoyang.huang" To: Andrew Morton , Matthew Wilcox , Christoph Hellwig , , , Zhaoyang Huang , Subject: [PATCH] mm: get the folio's refcnt before clear PG_lru in folio_isolate_lru Date: Wed, 27 Mar 2024 15:55:16 +0800 Message-ID: <20240327075516.1367097-1-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL:SHSQR01.spreadtrum.com 42R7tMMt081647 From: Zhaoyang Huang Bellowing race happens when the caller of folio_isolate_lru rely on the refcnt of page cache. Moving folio_get ahead of folio_test_clear_lru to make it more robust. 0. Thread_isolate calls folio_isolate_lru by holding one refcnt of page cache and get preempted before folio_get. folio_isolate_lru VM_BUG_ON(!folio->refcnt) if (folio_test_clear_lru(folio)) folio_get() 1. Thread_release calls release_pages and meet the scenario of the folio get its refcnt of page cache removed before folio_put_testzero release_pages folio_put_testzero(folio) == true if(folio_test_clear_lru(folio)) lruvec_del_folio(folio) list_add(folio, pages_to_free); Signed-off-by: Zhaoyang Huang --- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 3ef654addd44..42f15ca06e09 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1731,10 +1731,10 @@ bool folio_isolate_lru(struct folio *folio) VM_BUG_ON_FOLIO(!folio_ref_count(folio), folio); + folio_get(folio); if (folio_test_clear_lru(folio)) { struct lruvec *lruvec; - folio_get(folio); lruvec = folio_lruvec_lock_irq(folio); lruvec_del_folio(lruvec, folio); unlock_page_lruvec_irq(lruvec); -- 2.25.1