From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (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 691CA224AF1 for ; Wed, 24 Jun 2026 01:33:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782264811; cv=none; b=TLEVif3bZI8WfsD+ARalzJUlMDp1uwUdxP52bbPvAUAw6FWPCVYdR049PXR0OztW3vkA5vvL9BlebegZS74g55aHvAkCd3pf2ifMLFOwH5ETiORljc5jBWaAo3ADygYnZ69l9jWVDZbanHofnPEti/XJVrGIv1gvvMQw/AZJKg8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782264811; c=relaxed/simple; bh=2VjBFiUPtaDDjZm5c5yGhhYBhciATSjGSWrlr8OFxJ8=; h=MIME-Version:Date:Content-Type:From:Message-ID:Subject:To:Cc: In-Reply-To:References; b=goB+uAPUqW0j1ZZfaOI1BNEv4Df0gkbHlY3NpBirniUwW88y+/6Ma7XwxYf8RCg03o989kXt1gy1TjzJ4fo+ntRJiK90ajSluv9dMhWe18IIeLu9fiaEALXfmwDtMD/fhWCAZtoXDtm3vAxs+ZhVcb90PW6TgB34Rm8Ca4467MY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=abwr/AD8; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="abwr/AD8" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1782264806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mOg8LkKs733xmlAKwFCLPd9WcpZag1FHz/doRiCKuQs=; b=abwr/AD8vQqSwbq2irwDX2GN/P3JNdPfgkgjBL9KjFbvMJECnelvvWbegzVFbt/XYO6T5B 3op63GPNqAcGng+pSEPtPkyb/b18jT3E4jbtRnfYg64C96kOKRcC5ly80bXbWuLOGIflZx 1iPQB14pcZR3tadYbDppjCD2+DMXBY8= Date: Wed, 24 Jun 2026 01:33:24 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: "Hui Zhu" Message-ID: <40a6017455ce039225fc331940be6cb27d13bc3e@linux.dev> TLS-Required: No Subject: Re: [PATCH] mm: avoid KCSAN false positive in page_to_nid() To: "Lorenzo Stoakes" , "David Hildenbrand (Arm)" Cc: "Andrew Morton" , "Liam R. Howlett" , "Vlastimil Babka" , "Mike Rapoport" , "Suren Baghdasaryan" , "Michal Hocko" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Hui Zhu" In-Reply-To: References: <20260623074157.578113-1-hui.zhu@linux.dev> <97f2c4ad-c302-424d-a7c8-fdfa0fc0d811@kernel.org> X-Migadu-Flow: FLOW_OUT >=20 >=20On Tue, Jun 23, 2026 at 09:59:45AM +0200, David Hildenbrand (Arm) wro= te: >=20 >=20>=20 >=20> On 6/23/26 09:41, Hui Zhu wrote: > > From: Hui Zhu > >=20 >=20> KCSAN reports a data race between page_to_nid() reading page->flag= s > > and folio_trylock()/folio_lock() doing test_and_set_bit_lock(PG_lock= ed, > > ...) on the same word from another CPU, e.g.: > >=20 >=20> BUG: KCSAN: data-race in __lruvec_stat_mod_folio / shmem_get_folio= _gfp > >=20 >=20> The node id occupies a fixed, high bit-range of page->flags that i= s > > set once when the page is initialized and never modified afterwards, > > so it can never overlap with the low PG_locked/PG_waiters bits touch= ed > > by the folio lock path. The race is therefore harmless: page_to_nid(= ) > > always returns a consistent value regardless of how the read > > interleaves with the lock bit ops. > >=20 >=20> Wrap the flags read with data_race() to tell KCSAN this race is > > intentional and benign, consistent with how page->page_type is > > already annotated for similar packed-field accesses. > >=20 >=20> Signed-off-by: Hui Zhu > >=20 >=20How did you discover this? >=20 >=20A syzbot report? If so please include Reported-by, Closes tags. This wasn't reported by syzbot - it was found by our internal fuzzing CI on a KCSAN-enabled build of our downstream tree (based on v6.6.121), triggered by a multi-threaded mlockall() fuzz testcase. There's no public bug id for it, so Reported-by/Closes don't apply here. Best, Hui >=20 >=20>=20 >=20> --- > > include/linux/mm.h | 9 ++++++++- > > 1 file changed, 8 insertions(+), 1 deletion(-) > >=20 >=20> diff --git a/include/linux/mm.h b/include/linux/mm.h > > index 485df9c2dbdd..122d3b39369f 100644 > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -2296,7 +2296,14 @@ static inline int memdesc_nid(memdesc_flags_t= mdf) > >=20 >=20> static inline int page_to_nid(const struct page *page) > > { > > - return memdesc_nid(PF_POISONED_CHECK(page)->flags); > > + /* > > + * The node id occupies a fixed high bit-range of page->flags > > + * that is set once at page init and never changed afterwards. > > + * It cannot overlap with the low PG_locked/PG_waiters bits > > + * that folio_lock()/folio_unlock() concurrently update, so > > + * this data race is benign. > > + */ > >=20 >=20> Do we really need this excessive comment? > >=20 >=20Agreed, just delete it. For a trivial benign data race it's a bit muc= h, and the > commit message can cover it off for those who are curious. >=20 >=20>=20 >=20> + return memdesc_nid(data_race(PF_POISONED_CHECK(page)->flags)); > >=20 >=20> In memdesc_zonenum() we use ASSERT_EXCLUSIVE_BITS. > >=20 >=20> Can we do the same here inside memdesc_nid? > >=20 >=20Also agreed >=20 >=20>=20 >=20> diff --git a/include/linux/mm.h b/include/linux/mm.h > > index 69daeeab7fe8f..76d3bb54be844 100644 > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -2290,6 +2290,7 @@ int memdesc_nid(memdesc_flags_t mdf); > > #else > > static inline int memdesc_nid(memdesc_flags_t mdf) > > { > > + ASSERT_EXCLUSIVE_BITS(mdf.f, NODES_MASK << NODES_PGSHIFT); > > return (mdf.f >> NODES_PGSHIFT) & NODES_MASK; > > } > > #endif > >=20 >=20> -- > > Cheers, > >=20 >=20> David > >=20 >=20Thanks, Lorenzo >