[PATCH] riscv: sbi: Pass system failure reset reason on panic

From: Joshua Yeong

Date: Mon Nov 30 2026 - 06:08:06 EST


A restart from panic() is sent to the SBI SRST extension with reset
reason NONE, the same as a normal reboot, so firmware cannot tell a
panic reboot apart from a requested one.

Pass SBI_SRST_RESET_REASON_SYS_FAILURE when the restart is requested
while a panic is in progress.

Signed-off-by: Joshua Yeong <joshua.yeong@xxxxxxxxxxxxxxxx>
---
arch/riscv/kernel/sbi.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
index af1ccea222f1d..e44f23c5ded8d 100644
--- a/arch/riscv/kernel/sbi.c
+++ b/arch/riscv/kernel/sbi.c
@@ -8,6 +8,7 @@
#include <linux/bits.h>
#include <linux/init.h>
#include <linux/mm.h>
+#include <linux/panic.h>
#include <linux/pm.h>
#include <linux/reboot.h>
#include <asm/sbi.h>
@@ -515,10 +516,16 @@ static void sbi_srst_reset(unsigned long type, unsigned long reason)
static int sbi_srst_reboot(struct notifier_block *this,
unsigned long mode, void *cmd)
{
+ unsigned long reason = SBI_SRST_RESET_REASON_NONE;
+
+ /* Restart requested from panic() */
+ if (panic_in_progress())
+ reason = SBI_SRST_RESET_REASON_SYS_FAILURE;
+
sbi_srst_reset((mode == REBOOT_WARM || mode == REBOOT_SOFT) ?
SBI_SRST_RESET_TYPE_WARM_REBOOT :
SBI_SRST_RESET_TYPE_COLD_REBOOT,
- SBI_SRST_RESET_REASON_NONE);
+ reason);
return NOTIFY_DONE;
}

--
2.43.0