[PATCH v2 1/2] rust: add a wrapper for the `num_possible_cpus` C function

From: Andreas Hindborg

Date: Fri Jun 05 2026 - 09:00:28 EST


This function returns the maximum number of CPUs that can be online.

The wrapper is needed by the Rust null block driver.

Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
rust/helpers/helpers.c | 1 +
rust/helpers/num_cpus.c | 8 ++++++++
rust/kernel/cpu.rs | 7 +++++++
3 files changed, 16 insertions(+)

diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 625921e27dfb..bb250648e0a9 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -70,6 +70,7 @@
#include "maple_tree.c"
#include "mm.c"
#include "mutex.c"
+#include "num_cpus.c"
#include "of.c"
#include "page.c"
#include "pci.c"
diff --git a/rust/helpers/num_cpus.c b/rust/helpers/num_cpus.c
new file mode 100644
index 000000000000..54e8bacb46c3
--- /dev/null
+++ b/rust/helpers/num_cpus.c
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/cpumask.h>
+
+__rust_helper unsigned int rust_helper_num_possible_cpus(void)
+{
+ return num_possible_cpus();
+}
diff --git a/rust/kernel/cpu.rs b/rust/kernel/cpu.rs
index cb6c0338ef5a..b38b6914b12e 100644
--- a/rust/kernel/cpu.rs
+++ b/rust/kernel/cpu.rs
@@ -6,6 +6,13 @@

use crate::{bindings, device::Device, error::Result, prelude::ENODEV};

+/// Returns the maximum number of CPUs that may be online on the system.
+#[inline]
+pub fn num_possible_cpus() -> u32 {
+ // SAFETY: FFI call with no additional requirements.
+ unsafe { bindings::num_possible_cpus() }
+}
+
/// Returns the maximum number of possible CPUs in the current system configuration.
#[inline]
pub fn nr_cpu_ids() -> u32 {

--
2.51.2