From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793387001; b=EwLD7hGEyuKIE9IAhfkWXF9w7MWIW67yCGzA13Xf9qWwqGIVV+cunexewrZ9zvXx505Q 0QODqja69BgtxoRcQUnOenLpHEvwtwwPDj5pTgrLs1ZT49LNZHbihP8Ssw7+BcE1C18ax EbFV1dOmTQeGB7Cgmga6CYBCyGgjLTUBPwJ0FFpP2mcEg0ZqjrsGRe3D5iy8sV/O1Uka7 vg9ffgjVd3zYkRdEVRlIArJLd4ubO0FxceUYbWlYe6CfiGSTu5HmXW5rI3Y7mMW9WLgO0 YqLGRNtJjU9vWg5S4F7s8ROR3No+0YzRmJpSSB4g2o+lFozUgSNn/TaNLfNjP5X/7xg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793387001; h=Received:DKIM-Signature:Received:Received:X-ME-Sender:X-ME-Received: X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=Ez6NwxCX3bhjDqnSlRsdUj2bvOIZ+33wXUFtZScIV1g=; b=eFexuT+7m9zMoih6UFQB+fhUbfwPJJJgomxXID3J9Gsh4wYgY04/boBIrr5rpcSlzqW0 /gRtaey/MeizbPsATud+z1cCCegmZqtQb1OIeYngOVmWpmTmJalCITgcWfZGrdBn2WYep y8iUyXfWYpOtXfUHEqTSX9Ua4670s4e9ej5jITuqYqmpLSxbimtFJa5Pdkx3tILaEdiop CvnI3yNnHA2+XxDIlualh4B0JRMF8UN9dATmd2osqZX9ziwr/Ag+FLH/FzWB4x6sD430X TTcxCDU+oMH3mKklONKcCVNUDr15PCzGjceqJQ/A80+4mXlYFwRrwbBi39hPCiT8YvQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jR83Kb9q; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C764606A324 for ; Fri, 30 Oct 2026 19:03:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jR83Kb9q Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63B801F0093A; Fri, 30 Oct 2026 19:03:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793387000; bh=Ez6NwxCX3bhjDqnSlRsdUj2bvOIZ+33wXUFtZScIV1g=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=jR83Kb9qrDLc0R4usVOoKB7Wfomia0GqfF81Td+WbSHwwVFRLIPdKI0/vKgHbGgWb P1USucvboR+nddAxF/OZRMK0Ew55gkfE1rvvVBGUVExEc2cV8sn1eu2xRsK9P1spXk yJ9adP/RhRcn4iySwKESga8MO710jC2KbtLMkP6FIVF8zKe1ggfp4QqKW4fMKAsQA/ Yv4GQKGycK1FLwZ7Iwocu8SdRhjktGPMiUryhwcZkZ+QdtHDmj2WqfBmBfEn7klP5i qUl34fTmuMFxpxGecnNqx2fq5PohsF6Onpef8NtsZOeWT9wJuU8MwdIbKZyq/QQpIj KkXBSPPmT9bDw== Received: from phl-compute-08.internal (phl-compute-08.internal [10.202.2.48]) by mailfauth.phl.internal (Postfix) with ESMTP id B9037F40068; Fri, 30 Oct 2026 15:03:18 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Fri, 30 Oct 2026 15:03:18 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFGOr8QamtD/idwG8XBnzFAf/Ml7EAwCH31rnH8844AjLaVjcYoNBFy7nItSr7/1R lKLHkptekXrYmhAKtgQ1Z+R7VAqLBCvvhIKid69nwHnmkXXVXREiZZ8oE4ml2ZXua7p2aW mQmAcy/zMr6ozkc6UBBgKuOc54G/Nq6wmDswdE2iZ0oNX0nyv77LixT1rJuAK86uLRkCrb zpq8drx/483k+MkNQIfPcPZt8SIm44QxOvs9tyx1C5HtY485ysmDgaVxenlJAEBQO1QXf2 BQP+bfx7YLCr4UXJwZyyw6DeHKCAymUkdVUdgSFkV8FTLEwqfnvsgNQ/CBKWOkZyfPJpAO Al4yqBIi7gDBRnRpWOZHTMHspW3NbHnz3tfkJ3uE049XnujAFSjZJFrNTUoDrSiUfhUocU kbq/qJbDFNqTeqiE6KWjoGMgjRVFA6SGNk/kf8Q+8QqSShsOA6RZdm4Dq19laUOOpJLUel nldBdI3ybTOTjroLAAHFHhnIR4AdGLgsir3ATgNlzUnP2589vKropgG7sOAuRtGqomh9XH E9AlB5DHJFs34LLa/aIuFUBU71dMXYbEzW3vHDtoFyV4WEL1UiyAwRUUUELS6S/jP3YuB/ cnPbmCCSGKyWLaYixZ+A7AgPcyZ9Wej6qrDumo8qHFJv74joRgAvSZRQfiNg X-ME-Proxy: Feedback-ID: i8dbe485b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Oct 2026 15:03:17 -0400 (EDT) Date: Fri, 30 Oct 2026 12:03:16 -0700 From: Boqun Feng To: Andreas Hindborg Cc: Miguel Ojeda , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , Onur =?iso-8859-1?Q?=D6zkan?= , Thomas Gleixner , Peter Zijlstra , Lorenzo Stoakes , Vlastimil Babka , "Liam R. Howlett" , Uladzislau Rezki , Yury Norov , Yury Norov , Andrew Morton , Rasmus Villemoes , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v4 1/2] rust: add a wrapper for the `nr_online_nodes` C function Message-ID: References: <20261030-cpu-helpers-v4-0-a8d840d34837@kernel.org> <20261030-cpu-helpers-v4-1-a8d840d34837@kernel.org> X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261030-cpu-helpers-v4-1-a8d840d34837@kernel.org> On Fri, Oct 30, 2026 at 05:08:03PM +0100, Andreas Hindborg wrote: > This function returns the number of online NUMA nodes. > > The wrapper is needed by the Rust null block driver. > > Reviewed-by: Gary Guo > Reviewed-by: Yury Norov > Assisted-by: LLM > Signed-off-by: Andreas Hindborg > --- > rust/kernel/lib.rs | 1 + > rust/kernel/numa.rs | 29 +++++++++++++++++++++++++++++ > 2 files changed, 30 insertions(+) > > diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs > index 4d5c96ddc49c..a7b1c9cf454f 100644 > --- a/rust/kernel/lib.rs > +++ b/rust/kernel/lib.rs > @@ -105,6 +105,7 @@ > #[cfg(CONFIG_NET)] > pub mod net; > pub mod num; > +pub mod numa; > pub mod of; > #[cfg(CONFIG_PM_OPP)] > pub mod opp; > diff --git a/rust/kernel/numa.rs b/rust/kernel/numa.rs > new file mode 100644 > index 000000000000..164e622d325f > --- /dev/null > +++ b/rust/kernel/numa.rs > @@ -0,0 +1,29 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +//! NUMA topology utilities. > +//! > +//! C header: [`include/linux/nodemask.h`](srctree/include/linux/nodemask.h) > + > +use crate::bindings; > +#[cfg(CONFIG_NUMA)] > +use crate::sync::atomic::{ > + Atomic, > + Relaxed, // > +}; > + > +/// Returns the number of online NUMA nodes. > +#[inline] > +pub fn num_online_nodes() -> u32 { > + #[cfg(CONFIG_NUMA)] > + { > + // SAFETY: `nr_online_nodes` is a global variable that is valid for the lifetime of the > + // kernel. The C side updates it with plain writes during node hotplug and reads it with > + // plain reads. A relaxed load is the Rust equivalent of `READ_ONCE()`, which is the best > + // we can do on the reader side. > + unsafe { Atomic::from_ptr(&raw mut bindings::nr_online_nodes) }.load(Relaxed) Just so you know you can use `atomic_load()`[1]: unsafe { atomic_load(&raw mut bindings::nr_online_nodes, Relaxed) } With or without this: Reviewed-by: Boqun Feng [1]: https://rust.docs.kernel.org/kernel/sync/atomic/fn.atomic_load.html Regards, Boqun > + } > + #[cfg(not(CONFIG_NUMA))] > + { > + bindings::nr_online_nodes > + } > +} > > -- > 2.54.0 > >