diff mbox series

[v2,1/2] firmware: Clear scratch->trap_context on warm boot

Message ID 20260914-trap-context-fix-v2-1-3a6bedc6fcf0@sifive.com
State New
Headers show
Series lib: sbi: Fix stale trap_context/prev_context linking | expand

Commit Message

Nia Su Sept. 14, 2026, 8:39 a.m. UTC
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 <nia.su@sifive.com>
Reviewed-by: Evgeny Voevodin <evvoevod@tenstorrent.com>
---
 firmware/fw_base.S | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/firmware/fw_base.S b/firmware/fw_base.S
index 0c5c65c10e5cf38d1cc6d0b3a66ffac661e7bacf..8ccca5e91c09f9c4cfcbab9c31c7e77afe7a96ab 100644
--- a/firmware/fw_base.S
+++ b/firmware/fw_base.S
@@ -364,6 +364,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