[RFC PATCH v3 4/6] lib: sbi: Preserve S/VS indirect CSR selectors

Theodorus Wensan Februanto theodoruswensanfebruanto025 at gmail.com
Wed Nov 4 20:43:37 PST 2026


Preserve siselect when either Sscsrind or Smaia is available.

When H is implemented, also preserve vsiselect.

This change preserves the selectors only. It does not save
the indirectly selected backing state or IMSIC files.

Link: https://github.com/riscv-software-src/opensbi/issues/433

Signed-off-by: Theodorus Wensan Februanto <theodoruswensanfebruanto025 at gmail.com>
---
 lib/sbi/sbi_domain_context.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
index 89fd1647..fe7d98af 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -96,6 +96,10 @@ struct hart_context {
 	struct hart_context_sstc sstc;
 	/** Supervisor counter inhibit configuration */
 	unsigned long scountinhibit;
+	/** Supervisor indirect CSR selector */
+	unsigned long siselect;
+	/** Virtual supervisor indirect CSR selector */
+	unsigned long vsiselect;
 
 	/** Float context state */
 	struct sbi_fp_context fp_ctx;
@@ -277,6 +281,13 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
 	    (csr_read64(CSR_MENVCFG) & ENVCFG_CDE))
 		ctx->scountinhibit = csr_swap(CSR_SCOUNTINHIBIT,
 						 dom_ctx->scountinhibit);
+	if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCSRIND) ||
+	    sbi_hart_has_extension(scratch, SBI_HART_EXT_SMAIA)) {
+		ctx->siselect = csr_swap(CSR_SISELECT, dom_ctx->siselect);
+		if (misa_extension('H'))
+			ctx->vsiselect = csr_swap(CSR_VSISELECT,
+						 dom_ctx->vsiselect);
+	}
 
 	/* Eager context switch for float */
 	if (sbi_hart_has_extension(scratch, SBI_HART_EXT_F) ||
-- 
2.43.0




More information about the opensbi mailing list