From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 BF4351C861D for ; Thu, 23 Jul 2026 00:48:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784767738; cv=none; b=Ygl3R5EIyO8jrlbVVW/xl6p57aZg6+pUy3p82QOt8/jNG3PqYgidnw4Ms4dFDzSMol+DVZTi68vPx5mMGVMec1NVqZdDXCd638pRjr9Fr2s1yR74VYfbAtbXaO42tJAM2FVnboxkILCoo/tF6tAnbnloz6eBlmYXTQi7dDzqFUQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784767738; c=relaxed/simple; bh=51SnewrnPOpt6uqysSFSf1Qzu8ZD67OvKcXlrbS1zlQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z2zvGJK6MREUpTo4/0YcydAgTmsllTsuoHwztAkMUD25+wZ76Qofn13L4Fq5lwjN9nNygJzYql2gxXwODWNau3doECIK2sI5rKkKeBhneCUCrPlCznz/aIhynEXtxn/7McWxhdGte1waqD3xSKWKlm0ZsVROjND3+S+2NGfrcyo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=axS+J2fn; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="axS+J2fn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 024D81F000E9; Thu, 23 Jul 2026 00:48:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784767737; bh=9S7H+h7uAEU0vg/ILZ1013Z2srwGSoOGwHV8pM1o8wA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=axS+J2fn0q6OUHYYBUR8QBF/o85AgmGpa3mcDkITAQXHidSXSNWQhJnUJfL3REJHM nP9FIUKhKCtX7ampRb/ViFylqR7+uVybbW/dDVsKIX5JBl4N8w9J2OfWiZauvm9YZA 1ckL+pvo60D0eXRjEU8Yj4pSCQUOib3wRgxJ/2tW5JZjFCVP8pgf2O0qMeEPcK30nZ Ntt/9W5NcLijHY9abSf/9p1b4uG4YDdHwuEVUkuLFCY+cONDwzWu1uTzRQ3PKDcWkP llmMOUgfHLcKME2qQprR3V/0qMSu4q1ww2GaARAqoqYv3yQYs0lcraZIQxXVD5qGd5 cUfwCLDeJZRNA== From: SJ Park To: "Lorenzo Stoakes (ARM)" Cc: SJ Park , Jiale Yao , Andrew Morton , David Hildenbrand , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/page_idle: call folio_test_lru() after folio_get() Date: Wed, 22 Jul 2026 17:48:47 -0700 Message-ID: <20260723004848.96647-1-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Wed, 22 Jul 2026 10:56:13 +0100 "Lorenzo Stoakes (ARM)" wrote: > On Wed, Jul 22, 2026 at 05:26:42PM +0800, Jiale Yao wrote: > > page_idle_get_folio() speculatively calls folio_test_lru() before > > folio_try_get(). The folio can get freed and reallocated to a tail page > > in the meantime. In that case, VM_BUG_ON_PGFLAGS() in > > const_folio_flags() can be triggered. Remove the speculative call. > > > > Also mark the folio_test_lru() check right after folio_try_get() success > > as no more unlikely. > > Slightly strange wording but not sure why you're doing that? It is > generally unlikely a given folio will be !LRU right? > > > > > This is a sibling-path bug: damon_get_folio() was copied from this > > function with the same flawed pattern. Commit d6b8b02a27b3 > > ("mm/damon/ops-common: call folio_test_lru() after folio_get()") fixed > > damon_get_folio(), but page_idle_get_folio() was left unfixed. KCSAN > > (strict mode) confirms the data race on the folio flags: > > > > BUG: KCSAN: data-race in ... / percpu_counter_add_batch > > page_idle_get_folio+0x7a/0x2d0 > > page_idle_bitmap_read+0xc9/0x220 > > > > Signed-off-by: Jiale Yao > > Yeah generally this seems obviously correct (TM), if we can't be sure a > folio is kept around any other way to the extent we're doing > folio_try_get() we should gate any actual interactions with the folio on > succeeding the get first...! > > With the unlikely thing changed, LGTM so: > > Reviewed-by: Lorenzo Stoakes (ARM) > > > --- > > mm/page_idle.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/mm/page_idle.c b/mm/page_idle.c > > index 9c67cbac2965..29ee18f0e8ce 100644 > > --- a/mm/page_idle.c > > +++ b/mm/page_idle.c > > @@ -40,9 +40,9 @@ static struct folio *page_idle_get_folio(unsigned long pfn) > > return NULL; > > > > folio = page_folio(page); > > - if (!folio_test_lru(folio) || !folio_try_get(folio)) > > I guess this was meant as a racey check... > > > + if (!folio_try_get(folio)) > > return NULL; > > - if (unlikely(page_folio(page) != folio || !folio_test_lru(folio))) { > > + if (unlikely(page_folio(page) != folio) || !folio_test_lru(folio)) { > > As above, not sure why you're changing this? Seems unrelated, I'd just keep > it as it was. Maybe Jiale followed the pattern in DAMON side fix (commit d6b8b02a27b3). I was making a similar change for the below reason. The second test_lru() was unlikely because it is the second test. Now it became the first test, so it is "less" unlikely than before. I don't expect this makes some real change, though. Keeping this as is looks fine to me. Thanks, SJ [...]