Skip to contentSkip to conversation

x86/reboot: Add support for restart handlers

PATCH New sushrut 1 participant 1 message Oct 14, 2025 x86

lore
Share & tools
lore

sushrut

author
#0 lore raw

PATCH 1/1 x86/reboot: Add support for restart handlers

From: Sushrut Shirole <[email protected]>

Other architectures (ARM, PowerPC, MIPS, RISC-V) support restart handlers via register_restart_handler(), allowing drivers to perform direct hardware resets. x86 lacks this mechanism, creating an architectural inconsistency.

This is particularly problematic for high-availability x86 systems in the networking and embedded appliance space. These systems rely on hardware watchdogs as the final defense against catastrophic software hangs. When recovering from a true kernel lockup, the complex, multi-step machine_restart() path (ACPI, UEFI, keyboard controller) cannot be relied upon to execute, rendering watchdog recovery non-deterministic.

Add a call to do_kernel_restart() at the beginning of native_machine_restart(). This executes registered restart handlers to perform a direct hardware reset.

If a handler succeeds, the system restarts immediately. If no handlers are registered, or if all handlers fail, the function returns and the standard x86 reboot sequence proceeds.

This provides a deterministic recovery path for systems with the necessary watchdog hardware while having negligible impact on general-purpose systems.

Rename the parameter from '__unused' to 'cmd' to pass the restart command string to handlers, enabling command-specific behavior (e.g., "recovery", "bootloader").

Tested on x86_64 with a custom watchdog driver that registers a restart handler for direct hardware reset. Verified that handlers execute before machine_shutdown(), the normal reboot path remains unchanged when no handlers are registered, and the restart command is properly passed to handlers.

---
 arch/x86/kernel/reboot.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/reboot.c +2 -1
index 964f6b0a3d68..0d26ccd9274a 100644
@@ -772,10 +772,11 @@ static void __machine_emergency_restart(int emergency)
 	machine_ops.emergency_restart();
 }
 
-static void native_machine_restart(char *__unused)
+static void native_machine_restart(char *cmd)
 {
 	pr_notice("machine restart\n");
 
+	do_kernel_restart(cmd);
 	if (!reboot_force)
 		machine_shutdown();
 	__machine_emergency_restart(0);
Signature · 1 line
2.51.0