[RFC PATCH v2 4/8] lib: sbi: Preserve supervisor count inhibit configuration
Theodorus Wensan Februanto
theodoruswensanfebruanto025 at gmail.com
Fri Oct 23 00:09:21 PDT 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 33c19d04..9b4a4f5a 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -89,6 +89,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;
@@ -243,6 +245,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