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 679B9383981 for ; Wed, 24 Jun 2026 21:01:05 +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=1782334866; cv=none; b=mvAt29Kk7D/cmo3qxpeFXZNpjKnhyijMrBDv2hnh9zDphBHKHfllT/t4Ty3fZsFn0VjMXYoC+ERR4uhjeJezeq+4DjflgUxfbmiQQrAhHhIwc5Lnu/TBMb5KecRhggE0modTqJvns2aIaS65pf2UgGolkDY+/UkfAyJ70FwOHm0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782334866; c=relaxed/simple; bh=7uJm0TyoiLg/LphRzmZXpcEnXhGn7A6iM731zzikoys=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=Aq2TARj7onaOTMTeSDai6PjytQWoRmASdVrSF5ncgd31OUjLL25hm94eIXMProui2CyKfmW7YOS4iLTZ/a2pFayqqwKNfb5AdqtkGQeffDT5XGOUu1UZTUSAddOBB4zxmZvYVLEPC8/v1Z3/8g/k+WfnXxv8qEotZAxQT1rudVs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=X1YzewiD; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="X1YzewiD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F4DF1F00A3D; Wed, 24 Jun 2026 21:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1782334865; bh=T6AiIW0qUO5FLu24Zy/LeQ2RfXKyse0PDrwQy1AWVx8=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=X1YzewiDkAcUK6Xvk3Rc4GL9vilaLtIncvcdSLTtHu5K5LmqLWBEUmhcM4L06iEoF t4S0Bqti94qLIRNJE/PTaC4GoA4/Q5GRJAwctP6sgpNHQl/dwBWcujkEkk4Nmy5vGm b5HkAKJee4gITSHmJw748m1J8MpYtmUzPX0/KajU= Date: Wed, 24 Jun 2026 14:01:04 -0700 From: Andrew Morton To: Hui Zhu Cc: David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hui Zhu Subject: Re: [PATCH v2] mm: avoid KCSAN false positive in memdesc_nid() Message-Id: <20260624140104.eacc15e291eec123bc7b3349@linux-foundation.org> In-Reply-To: <20260623084432.701120-1-hui.zhu@linux.dev> References: <20260623084432.701120-1-hui.zhu@linux.dev> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 23 Jun 2026 16:44:32 +0800 Hui Zhu wrote: > 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. > > ... > > --- 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 It seems weird to be doing this against a local variable within a random function, seemingly unrelated to the problematic functions which you've identified. Seems that it fooled Sashiko: https://sashiko.dev/#/patchset/20260623084432.701120-1-hui.zhu@linux.dev I'm wondering what the heck is going on here?