[RFC PATCH v3 3/6] lib: sbi: Preserve supervisor count inhibit configuration
Theodorus Wensan Februanto
theodoruswensanfebruanto025 at gmail.com
Wed Nov 4 20:43:36 PST 2026
Preserve the delegated counter inhibit configuration across domain
switches when Ssccfg is available and menvcfg.CDE is enabled.
The extra CDE guard avoids accessing scountinhibit while counter
delegation is disabled. scountinhibit aliases delegated parts of
mcountinhibit, so this is not a complete PMU state virtualization fix.
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 | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
index d2490483..89fd1647 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -94,6 +94,8 @@ struct hart_context {
/** Supervisor resource management configuration register */
unsigned long srmcfg;
struct hart_context_sstc sstc;
+ /** Supervisor counter inhibit configuration */
+ unsigned long scountinhibit;
/** Float context state */
struct sbi_fp_context fp_ctx;
@@ -271,6 +273,10 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
ctx->sstc.vstimecmp = csr_swap64(CSR_VSTIMECMP,
dom_ctx->sstc.vstimecmp);
}
+ if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCCFG) &&
+ (csr_read64(CSR_MENVCFG) & ENVCFG_CDE))
+ ctx->scountinhibit = csr_swap(CSR_SCOUNTINHIBIT,
+ dom_ctx->scountinhibit);
/* 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