From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (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 B56AD3CEB8D for ; Tue, 23 Jun 2026 08:44:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782204290; cv=none; b=ESko0+aiL5kNMiX0y5ANm8Ehq/eR14LhVlzYuLJryah2pPcSqSnYmn3kgqVgf2lhQhfxJRc3ZbnYXV7AHEPNLBG/3UcPNLurjN6ldccl9fpU4FOnYthac2fYBPOOafmMEeMcGFd3LKB34BWETbWtv+K9+EuiYQSZTCdyJGIwFLE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782204290; c=relaxed/simple; bh=cI76XxlX0V59nRyYRydAopGqIxC5j+zkxeidnv36gvg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dGC9Q22bLPOu7APJnn2v6ODG8+SwlMFsCI54mogHEdPrbOEZp+KJWKGHY92M6kM4Hq4F+s/Sk7EXvQuotLPHilvfvdakTs2CPVwXrbxPWsm6VLoyxrrAfTwZhsBbBhXc3Txz20/0K7XoRzT9P1z5SgGDa4apO+moSRNCKM0RDew= 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=ss6+ispI; arc=none smtp.client-ip=91.218.175.181 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="ss6+ispI" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1782204286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=j4RRLMzp7jvw4FEfdbqtvjVAOns1TW89DIh3rnn3vtw=; b=ss6+ispI3wUwQkyJs4NRV/XgD18FDFpn1thnXNNnhvdzZM2KeakKmeZKrL9Fzywgy5SNZF RqNbD++6cT9jQSweeTdmeGr2PMFyMT6gp9z0drr5ZaOe37rGT+HNZMb5gURSvz/uxywSTy GFCx3IllenquVlf8i/ca6iuCGgrNMjc= From: Hui Zhu To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hui Zhu Subject: [PATCH v2] mm: avoid KCSAN false positive in memdesc_nid() Date: Tue, 23 Jun 2026 16:44:32 +0800 Message-ID: <20260623084432.701120-1-hui.zhu@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: Hui Zhu KCSAN reports a data race between page_to_nid()/folio_nid() reading page->flags and folio_trylock()/folio_lock() concurrently doing test_and_set_bit_lock(PG_locked, ...) on the same word, e.g.: BUG: KCSAN: data-race in __lruvec_stat_mod_folio / shmem_get_folio_gfp The node id occupies a fixed bit-range of page->flags that is set once at page init and never modified afterwards, so it can never overlap with the low PG_locked/PG_waiters bits touched by the folio lock path. Use ASSERT_EXCLUSIVE_BITS() in memdesc_nid() to scope the exemption to just the node-id bits, consistent with how memdesc_zonenum() already handles the same class of race for the zone-id bits. Signed-off-by: Hui Zhu --- Changelog: v2: According to the comments of David, remove useless comments and use ASSERT_EXCLUSIVE_BITS() in memdesc_nid() instead of data_race() in page_to_nid(). include/linux/mm.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 485df9c2dbdd..7518d6364a00 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 -- 2.43.0