From: Nia Su <nia.su@sifive.com>
To: opensbi@lists.infradead.org
Cc: Nia Su <nia.su@sifive.com>, Nylon Chen <nylon.chen@sifive.com>,
Nick Hu <nick.hu@sifive.com>, Zong Li <zong.li@sifive.com>,
Evgeny Voevodin <evvoevod@tenstorrent.com>
Subject: [PATCH 1/2] firmware: Clear scratch->trap_context on warm boot
Date: Fri, 04 Sep 2026 01:16:43 -0700 [thread overview]
Message-ID: <20260904-trap-context-fix-v1-1-6bf7fa45d5f1@sifive.com> (raw)
In-Reply-To: <20260904-trap-context-fix-v1-0-6bf7fa45d5f1@sifive.com>
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.
Clear trap_context in the scratch space on warm boot entry,
mirroring what cold boot's _scratch_init already does.
Signed-off-by: Nia Su <nia.su@sifive.com>
---
firmware/fw_base.S | 3 +++
1 file changed, 3 insertions(+)
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
--
2.43.7
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next prev parent reply other threads:[~2026-09-04 8:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 8:16 [PATCH 0/2] lib: sbi: Fix stale trap_context/prev_context linking Nia Su
2026-09-04 8:16 ` Nia Su [this message]
2026-09-04 8:16 ` [PATCH 2/2] lib: sbi: Fix stale prev_context in RNMI handler Nia Su
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260904-trap-context-fix-v1-1-6bf7fa45d5f1@sifive.com \
--to=nia.su@sifive.com \
--cc=evvoevod@tenstorrent.com \
--cc=nick.hu@sifive.com \
--cc=nylon.chen@sifive.com \
--cc=opensbi@lists.infradead.org \
--cc=zong.li@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox