[PATCH] lib: sbi: Preserve hcounteren and htimedelta across domain switches
whensun
theodoruswensanfebruanto025 at gmail.com
Thu Oct 22 17:02:41 PDT 2026
Save and restore hcounteren and htimedelta when switching between
domains on harts supporting the Hypervisor extension.
Without this preservation, a resumed domain can observe the register
values left by another domain.
Link: https://github.com/riscv-software-src/opensbi/issues/433
Signed-off-by: whensun <theodoruswensanfebruanto025 at gmail.com>
---
lib/sbi/sbi_domain_context.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
index 0861d541..31fa5afc 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -50,6 +50,8 @@ struct hart_context {
unsigned long senvcfg;
/** Supervisor resource management configuration register */
unsigned long srmcfg;
+ unsigned long hcounteren;
+ u64 htimedelta;
/** Float context state */
struct sbi_fp_context fp_ctx;
@@ -145,6 +147,10 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
ctx->srmcfg = csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
+ if (misa_extension('H')) {
+ ctx->hcounteren = csr_swap(CSR_HCOUNTEREN, dom_ctx->hcounteren);
+ ctx->htimedelta = csr_swap64(CSR_HTIMEDELTA, dom_ctx->htimedelta);
+ }
/* 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