[PATCH v5 3/8] rust: percpu: Add C bindings for per-CPU variable API

Mitchell Levy
2026-04-10T21:36:23Z

Add bindings necessary to implement a Rust per-CPU variable API,
specifically per-CPU variable allocation and management of CPU
preemption.

Signed-off-by: Mitchell Levy <levymitchell0@gmail.com>
---
rust/helpers/helpers.c | 2 ++
rust/helpers/percpu.c | 9 +++++++++
rust/helpers/preempt.c | 15 +++++++++++++++
3 files changed, 26 insertions(+)

diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index e05c6e7e4abb..af661bb9be34 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -70,9 +70,11 @@
#include "of.c"
#include "page.c"
#include "pci.c"
+#include "percpu.c"
#include "pid_namespace.c"
#include "platform.c"
#include "poll.c"
+#include "preempt.c"
#include "processor.c"
#include "property.c"
#include "pwm.c"
diff --git a/rust/helpers/percpu.c b/rust/helpers/percpu.c
new file mode 100644
index 000000000000..463186b8af9d
--- /dev/null
+++ b/rust/helpers/percpu.c
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/percpu.h>
+
+__rust_helper
+void __percpu *rust_helper_alloc_percpu(size_t sz, size_t align)
+{
+ return __alloc_percpu(sz, align);
+}
diff --git a/rust/helpers/preempt.c b/rust/helpers/preempt.c
new file mode 100644
index 000000000000..77dd5f10d8dc
--- /dev/null
+++ b/rust/helpers/preempt.c
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/preempt.h>
+
+__rust_helper
+void rust_helper_preempt_disable(void)
+{
+ preempt_disable();
+}
+
+__rust_helper
+void rust_helper_preempt_enable(void)
+{
+ preempt_enable();
+}

--
2.34.1