From f84bdb98772b44d20bddb1ccae65ee40ac36991b Mon Sep 17 00:00:00 2001 From: Nia Su Date: Mon, 14 Sep 2026 01:39:33 -0700 Subject: [PATCH] firmware: Clear scratch->trap_context on warm boot sbi_trap_handler() links tcntx->prev_context on entry and restores scratch->trap_context on exit, forming a stack that unwinds through the same path it was pushed from. Non-retentive suspend/resume breaks that unwind: the SBI call requesting suspend jumps straight to warm boot (jump_warmboot()) instead of returning through the normal exit path, leaving scratch->trap_context stale. Since each hart's scratch space sits at a fixed address, the next trap taken after warm boot resume reads that same stale scratch->trap_context as its prev_context, which sbi_trap_error() then walks to print trap diagnostics -- producing a broken trap dump. Clear trap_context in the scratch space on warm boot entry. Fixes: 60ffc154c84d ("include: sbi: Add trap_context pointer in struct sbi_scratch") Signed-off-by: Nia Su Reviewed-by: Evgeny Voevodin Reviewed-by: Anup Patel Link: https://lore.kernel.org/r/20260914-trap-context-fix-v2-1-3a6bedc6fcf0@sifive.com Signed-off-by: Anup Patel --- firmware/fw_base.S | 3 +++ 1 file changed, 3 insertions(+) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index a76ddc1b..f1752d5c 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -458,6 +458,9 @@ _start_warm: /* update the mscratch */ csrw CSR_MSCRATCH, tp + /* Clear trap_context in scratch space */ + REG_S zero, SBI_SCRATCH_TRAP_CONTEXT_OFFSET(tp) + /* Setup stack */ add sp, tp, zero