[PATCH v2 2/3] rust: reboot: add emergency_restart() wrapper
Artem Lytkin <[email protected]> Thu, 23 Jul 2026 19:15:28 +0300
| Newsgroups | org.kernel.vger.linux-watchdog,org.kernel.vger.linux-kernel,org.kernel.vger.rust-for-linux |
|---|---|
| Message-ID | <[email protected]> |
Add a minimal reboot module wrapping emergency_restart(), which restarts the machine immediately without syncing or unmounting filesystems. This is needed by watchdog drivers that must restart the system when the watchdog expires, such as the Rust software watchdog added in a subsequent patch. emergency_restart() is safe to call from any context, including the interrupt context of an expiring timer. Signed-off-by: Artem Lytkin <[email protected]> --- rust/bindings/bindings_helper.h | 1 + rust/kernel/lib.rs | 1 + rust/kernel/reboot.rs | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 rust/kernel/reboot.rs diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index e692d142c8608..89f0e1f65f6d7 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -81,6 +81,7 @@ #include <linux/property.h> #include <linux/pwm.h> #include <linux/random.h> +#include <linux/reboot.h> #include <linux/refcount.h> #include <linux/regulator/consumer.h> #include <linux/sched.h> diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index a1130c4b82881..e603c07dc53dd 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -113,6 +113,7 @@ #[cfg(CONFIG_RUST_PWM_ABSTRACTIONS)] pub mod pwm; pub mod rbtree; +pub mod reboot; pub mod regulator; pub mod revocable; pub mod safety; diff --git a/rust/kernel/reboot.rs b/rust/kernel/reboot.rs new file mode 100644 index 0000000000000..f98a85d19f85d --- /dev/null +++ b/rust/kernel/reboot.rs @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Reboot support. +//! +//! C header: [`include/linux/reboot.h`](srctree/include/linux/reboot.h). + +use crate::bindings; + +/// Restarts the machine immediately, without syncing or unmounting +/// filesystems and without going through the reboot notifier chains. +/// +/// This is intended for situations where the system is in a state where an +/// orderly shutdown is no longer possible, for example when a watchdog +/// expires. It can be called from any context, including interrupt context. +pub fn emergency_restart() { + // SAFETY: `emergency_restart` has no preconditions and is documented as + // safe to call from any context. + unsafe { bindings::emergency_restart() } +} -- 2.43.0