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 43F2E38B7D7 for ; Thu, 25 Jun 2026 03:09:49 +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=1782356991; cv=none; b=UE1xBVgshbRPD1KgJpvZ66gETw124ZF51fqUTvUV37qE1D8K/e7N1zQx90sgj4FBXhIPiz14eYBBqek7bn3WZxePPkhQF6LF1k6umga2cqChYh5N5qdQ91A4HHGa9P95zDw3aNnCUk9pWUA8VEl4fVS10Bk+e09Bv/u1FytNwKY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782356991; c=relaxed/simple; bh=IAt+BgD3j8cxkOn2Xs6n3YyTFHK5vlYpUWx9/O32jbA=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=XNEI5+5AIDw1Nxsmi7b2hjxidmUUBUY3vz9rTaiuP9IgP6VYm/ciTDLrXWsl3HdB8Pa6Iu2hYQxJgX/zYJvgmuPv7GX3DY2pwDpQOXMNmrFJK6C0kD7NlfXxSBUOoBXcrgIqk01IPicnrbxHRjqXSqT54hE5C/eaJOujQ5gYDFw= 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=GHLdobnr; 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="GHLdobnr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 030CC1F000E9; Thu, 25 Jun 2026 03:09:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1782356989; bh=l0veS0g5fF+whbLGepad1n2C9+nnzZ0GFYK9TZo8pw8=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=GHLdobnrwqEOu9mc/isAREnl7jRAbh5wy+vtnmCxEZJtPqlEdTfp25iqb9geOaHyQ TJvrO7dvB4c7xAjQ0V18KgLjpQUWJvTk+CLLPUM3iL/h0NJVG3iY4DQM28F1v2+0fb yONKAIo9ZFObi3fzZXkfmrLsv2wMIBgfIqgauCB8= Date: Wed, 24 Jun 2026 20:09:48 -0700 From: Andrew Morton To: Hui Zhu Cc: David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hui Zhu Subject: Re: [PATCH v3] mm: assert exclusive nid/zonenum bits at the page/folio access sites Message-Id: <20260624200948.d4d09c02540db0099e260c00@linux-foundation.org> In-Reply-To: <20260625024019.838786-1-hui.zhu@linux.dev> References: <20260625024019.838786-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 Thu, 25 Jun 2026 10:40:19 +0800 Hui Zhu wrote: > KCSAN reports a data race between page_to_nid()/folio_pgdat() 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 and zone id occupy fixed bit-ranges of page->flags that > are set once at page init and never modified afterwards, so they can > never overlap with the low PG_locked/PG_waiters bits touched by the > folio lock path. > > ASSERT_EXCLUSIVE_BITS(mdf.f, ...) inside memdesc_nid()/memdesc_zonenum() > checks a by-value copy of the flags word, not the actual shared > page->flags/folio->flags being modified concurrently, so it doesn't > reliably assert anything about the real race. Move the assertion to > page_to_nid(), folio_nid(), page_zonenum() and folio_zonenum(), where > flags is dereferenced directly from the page/folio. Thanks. Sashiko is worried about CONFIG_NUMA=n: https://sashiko.dev/#/patchset/20260625024019.838786-1-hui.zhu@linux.dev I'm a bit surprised that these functions even exist on NUMA=n. That we don't have simply #else static inline int folio_nid(const struct folio *folio) { return 0; } #endif