From nobody Mon Jun 8 05:24:53 2026 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 A10E643E4AC; Fri, 5 Jun 2026 12:55:55 +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=1780664156; cv=none; b=dZSzE7OqO/wqGgxdGcCAolD0+LpHLSU/yzh1J2NrpZycch8fBIrChTQ4iYQ8DxBAY9mZRukwqgU0mu1biEYYc5CgsBsaDcaOw5K1+kF0Z3GedSaoiVtBb+fjitO4UUC1r+fpGa3G+DeLP3ftPU+bjETmYr7dV7zcw2//tqT0EYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780664156; c=relaxed/simple; bh=EVHRWI4wLcxgsMGjOMuez0caR65z0HmvxgL20kjWfts=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JKPk+1MZBDCshcIjMOVLVk2uZdGbnBc+n1BMIJBLMZLW0ECbbqL+WXGva90unUV9xvXZJpEMiGSarv/CVihLEDiJszxudVzTtV7aXewZ0Rh1ODZILxGg2n9/7jTPHJusH7sgcuSCq+EmwjqQm/oA7dsuI/MQXTCO54IFtG8ZJgE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C1sJZ9gr; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="C1sJZ9gr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5775F1F00893; Fri, 5 Jun 2026 12:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780664155; bh=IwQpixxMVMJ3JD+dIOM53Jnt444b2ZjbzOZe9CVJMvc=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=C1sJZ9grjh+M2NTdSc+GfqFkjNoH/Eokg7U7zRTQiTi1HqP7sLW8mHDHqZGnMT/IN AF2PCsXyL8q1DC8GxhsFJj3mMelor+9y9/Uw1akMySU22yUovo7svGUq99Ykip02xr 6mYm/WsugWTicArgAdWKKAz6icSdezY5o4FFIZhBHkKG9kY/vAsM1TlGwJOUgP99WW o3x5F49Hkz6AbCced9m4XcgmTTDwlZCZDuAJ3Pc8QpBImA3qOCEqftxAew/buqyVk+ sBBxcz8jkQ8tjw9T3NgtOEDSfUYakJKx+KnWB/JE3e8ugluNRSAb47lgDfSK1RkEgb +ayIokiO7U4dg== From: Andreas Hindborg Date: Fri, 05 Jun 2026 14:54:56 +0200 Subject: [PATCH v2 1/2] rust: add a wrapper for the `num_possible_cpus` C function 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260605-cpu-helpers-v2-1-0ad227f0d91b@kernel.org> References: <20260605-cpu-helpers-v2-0-0ad227f0d91b@kernel.org> In-Reply-To: <20260605-cpu-helpers-v2-0-0ad227f0d91b@kernel.org> To: Miguel Ojeda , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Boqun Feng , Thomas Gleixner , Peter Zijlstra , Boqun Feng Cc: Dirk Behme , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1652; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=EVHRWI4wLcxgsMGjOMuez0caR65z0HmvxgL20kjWfts=; b=owEBbQKS/ZANAwAKAfpQKQiqxb3QAcsmYgBqIscimV27hmSRG4hMcIyIgc+XWFSIROD+j82kq z46pPEYM5GJAjMEAAEKAB0WIQRXitnI2WZ2JirAaob6UCkIqsW90AUCaiLHIgAKCRD6UCkIqsW9 0N29D/0TYYkOBeSazoIsd1aKUiboF4HeCeHyVSswT6l2QGGw48ABfgzKNEaWfy+0JW6g3erP0Uq ir7PE+QeUotM+nubWKYEqfCEHQ7M262X6jGZ3wOlxACCAv5LrCYk1Q4LIImVqhUBhBHz0LbQWVZ MReIs6fUXt2dbxWf/NBCRB4QNP6JyPLUpu0M/jxz67VX++r+Kn+PSw/DDUIWTNgSAiDkefSl1xd xY0hSsm+gd4wX+3LBwN37c9J29kSWVSLGQb/IIGfzBPpMECtbBnMjw/y6EsIuzfyrPQG3Xqowox K7tO2GEou1mpcoNoq7ILftr4GVFPof+RlXJ+YNsQOQ/2gWErKTCHnH47kgkaQ/vqDPUph+9Az9g 6dYo9Nct/XKXE+uVkbVGBzke5mj5orvvnWMVKPfNHY9hxcP6mdHb2wuHlIyXgLaHZqD2elxvPdX XCZiK1usqfkteanIei5lfJ7+f44ayAunhsZXxXP8LWjmMkv23eKwbmWIRsHGs5+62iVV2eRjAqQ NjY7KmV6Hbz/ZRkjTiSx+xX8kcIbRbRp6p22eL/OOKDVq8rhyQMmhtTKbszWqZfg9WfDyF9x/Lm BQ6fXfzfkm56WLjs2XrFWzmKNPr8geDS4uHEaW9v3quV5K6ovgun/rVqIxgYgQVS0/ZoOUUpFgw NV1GM4TepIpr6XA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 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 --- 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 + +__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 @@ =20 use crate::{bindings, device::Device, error::Result, prelude::ENODEV}; =20 +/// 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 conf= iguration. #[inline] pub fn nr_cpu_ids() -> u32 { --=20 2.51.2 From nobody Mon Jun 8 05:24:53 2026 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 9CD373EF646; Fri, 5 Jun 2026 12:55:47 +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=1780664150; cv=none; b=WUbH1mWIAOwucOpv7TQTxLNizvSXRAfYmIBguGJ8NGmOIYY9SYTEOcUB5CZ2hYazUd0bWSRKRy0B0ibOYlVtSLjhSV/wju2lbJu+HMx+90Y9hUCqvCKnCc75wNRZx4isOCV+zhDwKp9g8XwBXxmFSGyofdLcbvS/9gFtN9ub1rs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780664150; c=relaxed/simple; bh=I3A/42ZAmqrZ51rafH9puHVqWjheNB+U+swntfsrAT0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=A3fgTdtf14q3IZSr23ulgp7PxQFtccGHCf9yUF7jVUlxdofhBg+I8W39clK1dIJZZRXrm65ENP/c2s5baF6kTqaz6fV2CztBUfUjK8ldPOA/Xt5wqDHsZAEwDMPKNMlI+u7h2BGOSxNEu4WiOOMrG8SRvL2LyifvH56YvP98mA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IsNwixmA; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IsNwixmA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8536B1F00893; Fri, 5 Jun 2026 12:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780664147; bh=80FKHxqCUDBJNZ51JKquyShmsELFWoEJpeApQ4LAXGM=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=IsNwixmAwKjoYPBK9Na/UOQ/q3826BQlKDYTFTqPvqrFJRKG5yo0l6ey0PSUuDIrH ihLGw2Nky4iOkV/dfzE50dhULXAKZ7A0Xc1oJIIYTNdbgymY7fH7omi5ooY+D7bHPf 43Mh0nkSsSDijNadyeY1bzQtwSjBYsnrhnnCDkYGw9bVtlOOp0XOtjZ0S9JTaiVtCf sHW0Q4vYxfmjUDdCnSx50LRmKy/SBHNXZn+KqiEuURszvCubfbBrPCCOkcYCx8E2pK Mu4NvF7nIKF2rdLaeBDMdXhA/8zG8NrjNVaw0xV8XXVQ1Agoz/yfxfAV4q41o7NhX/ K2oGPKKJrL3qA== From: Andreas Hindborg Date: Fri, 05 Jun 2026 14:54:57 +0200 Subject: [PATCH v2 2/2] rust: add a wrapper for the `nr_online_nodes` C function 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260605-cpu-helpers-v2-2-0ad227f0d91b@kernel.org> References: <20260605-cpu-helpers-v2-0-0ad227f0d91b@kernel.org> In-Reply-To: <20260605-cpu-helpers-v2-0-0ad227f0d91b@kernel.org> To: Miguel Ojeda , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Boqun Feng , Thomas Gleixner , Peter Zijlstra , Boqun Feng Cc: Dirk Behme , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1365; i=a.hindborg@kernel.org; h=from:subject:message-id; bh=I3A/42ZAmqrZ51rafH9puHVqWjheNB+U+swntfsrAT0=; b=owEBbQKS/ZANAwAKAfpQKQiqxb3QAcsmYgBqIscjiINiYgW2sRapjkkpGt+AEI2u8hL3vxywg 59XpOtNYe2JAjMEAAEKAB0WIQRXitnI2WZ2JirAaob6UCkIqsW90AUCaiLHIwAKCRD6UCkIqsW9 0K02EACZy70aO5iC+vEyVZrU4rbJT7FkXtUI65UW86khct/g3NglG/OuSjRIMxWxGa63kjk2P82 v+hEXFDIpwDVgN85h3jiN7vT0+H+O93sUIzT6Y3QHZ6M0gBW/+oV20uNcgxjrDlz9X0WpSLCNiE A/24lzHlR7O9589B7NIi+zvYPc8KH77SuuNhSp72rhCLNA20B4BRUuXGSSprnRtnljIwntY0i9G AaDH4rTq2Pj9yL1F7n9HbOa+3txiy/nozWDG3xD7CZS/3+01GF6miS4InPvc8JlGJejDdFUUAX4 TsgZscaSvOmhlnhS923TzPaLTkmE5VwkrQq9eFVRpEFGzxjN/JU9mzu3KZLJkWpD/Y6td4IIJv+ HPbAkRdN3jKFxjqId1q2RKCU2uF/2PrtfZg9RRb+LNT06J9Hivdrlb5sOndD7hPgJC8wRW7QQlV ukNEWvfN0XAS2vWi9UebxPE9sOe6c/MdowZEaPQ8nQaOuboK505Oh2jYuK1nL4NHqHS8ARhByFY k0BJsFGxlRuxYBWnRS+8af1kIMMy87yaLsE34s7knszGaZzgxBA49vbPA8FGy5gSd+v2RhaXPUM 4/nP+4Y/1xP9q0zFPt2z4A8TDAdrsQPdbQghQgcg4958LTGKkmn7yk1IM4qh/P3wp660/o8NP1z EnCWgv5U1sKmwCA== X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 This function returns the number of online NUMA nodes. The wrapper is needed by the Rust null block driver. Signed-off-by: Andreas Hindborg --- 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 d= o as C and just read it, + // even though it might race. + #[allow(unused_unsafe)] + unsafe { + bindings::nr_online_nodes + } +} --=20 2.51.2