diff mbox series

[RFC,v3,3/6] lib: sbi: Preserve supervisor count inhibit configuration

Message ID 20261105044339.435711-4-theodoruswensanfebruanto025@gmail.com
State New
Headers show
Series Preserve more architectural state across domain switches | expand

Commit Message

Theodorus Wensan Februanto Nov. 5, 2026, 4:43 a.m. UTC
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@gmail.com>
---
 lib/sbi/sbi_domain_context.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

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) ||