mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Andreas Hindborg" <a.hindborg@kernel.org>,
	"Gary Guo" <gary@garyguo.net>, "Miguel Ojeda" <ojeda@kernel.org>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>
Cc: "Dirk Behme" <dirk.behme@de.bosch.com>,
	<linux-kernel@vger.kernel.org>, <rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] rust: add a wrapper for the `nr_online_nodes` C function
Date: Mon, 08 Jun 2026 12:57:58 +0100	[thread overview]
Message-ID: <DJ3NEPPY3VBW.18SDYBTB63K7A@garyguo.net> (raw)
In-Reply-To: <87wlw9gsg2.fsf@kernel.org>

On Mon Jun 8, 2026 at 12:52 PM BST, Andreas Hindborg wrote:
> "Gary Guo" <gary@garyguo.net> writes:
>
>> On Fri Jun 5, 2026 at 1:54 PM BST, Andreas Hindborg wrote:
>>> This function returns the number of online NUMA nodes.
>>>
>>> The wrapper is needed by the Rust null block driver.
>>>
>>> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
>>> ---
>>>  rust/kernel/lib.rs  |  1 +
>>>  rust/kernel/numa.rs | 19 +++++++++++++++++++
>>>  2 files changed, 20 insertions(+)
>>>
>>> diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
>>> index b72b2fbe046d..00713b2adcac 100644
>>> --- a/rust/kernel/lib.rs
>>> +++ b/rust/kernel/lib.rs
>>> @@ -97,6 +97,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..760db072a6c1
>>> --- /dev/null
>>> +++ b/rust/kernel/numa.rs
>>> @@ -0,0 +1,19 @@
>>> +// SPDX-License-Identifier: GPL-2.0
>>> +
>>> +//! NUMA topology utilities.
>>> +//!
>>> +//! C header: [`include/linux/nodemask.h`](srctree/include/linux/nodemask.h)
>>> +
>>> +use crate::bindings;
>>> +
>>> +/// Returns the number of online NUMA nodes.
>>> +#[inline]
>>> +pub fn num_online_nodes() -> u32 {
>>> +    // NOTE: In some configurations, we can read this variable without an unsafe block.
>>> +    // SAFETY: When NUMA is enabled, this is a global mutable static. We do as C and just read it,
>>> +    // even though it might race.
>>
>> Can we do better and do a relaxed load instead?
>
> Yes, that sounds reasonable.
>
> But what are the semantics of a relaxed load when other writers are not
> using atomic primitives? Does it make a difference?

This is the whole CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC again.

Technically not okay, but this happens common in C code that people can choose
to ignore it :)

But let's not advocate for that in Rust code.

Best,
Gary

      reply	other threads:[~2026-06-08 11:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-05 12:54 [PATCH v2 0/2] rust: add a few helpers Andreas Hindborg
2026-06-05 12:54 ` [PATCH v2 1/2] rust: add a wrapper for the `num_possible_cpus` C function Andreas Hindborg
2026-06-08  7:28   ` Alice Ryhl
2026-06-08 11:06   ` Gary Guo
2026-06-05 12:54 ` [PATCH v2 2/2] rust: add a wrapper for the `nr_online_nodes` " Andreas Hindborg
2026-06-08  7:28   ` Alice Ryhl
2026-06-08 11:05   ` Gary Guo
2026-06-08 11:52     ` Andreas Hindborg
2026-06-08 11:57       ` Gary Guo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DJ3NEPPY3VBW.18SDYBTB63K7A@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=dirk.behme@de.bosch.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tglx@kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®