[RFC PATCH 4/5] lib: sbi: Preserve supervisor count inhibit configuration
whensun
theodoruswensanfebruanto025 at gmail.com
Thu Oct 22 19:43:44 PDT 2026
From: Theodorus Wensan Februanto <theodoruswensanfebruanto025 at gmail.com>
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 32ff365b..0541bf8e 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -71,6 +71,8 @@ struct hart_context {
unsigned long srmcfg;
/** Supervisor timer comparison register */
u64 stimecmp;
+ /** Supervisor counter inhibit configuration */
+ unsigned long scountinhibit;
/** Float context state */
struct sbi_fp_context fp_ctx;
@@ -201,6 +203,10 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
ctx->srmcfg = csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSTC))
ctx->stimecmp = csr_swap64(CSR_STIMECMP, dom_ctx->stimecmp);
+ 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