[PATCH] lib: sbi_domain_context: Flush TLB after SATP mode switch
Zishun Yi
vulab at iscas.ac.cn
Wed Apr 29 11:17:47 PDT 2026
When switching between domains with different satp.MODE values (e.g.
Sv39 to Sv48), the RISC-V ISA permits hardware to use cached
translations from the old virtual-address width if no SFENCE.VMA
intervenes. This constrained-unpredictable behavior is clarified in
riscv-isa-manual PR #2219.
Add __sbi_sfence_vma_all() after the csr_swap(CSR_SATP, ...) in
switch_to_next_domain_context() to ensure translations from the new
domain's address width are used.
Link: https://github.com/riscv/riscv-isa-manual/pull/2219
Signed-off-by: Zishun Yi <vulab at iscas.ac.cn>
---
lib/sbi/sbi_domain_context.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
index 158f4990432e..f47875e48230 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -18,6 +18,7 @@
#include <sbi/sbi_domain_context.h>
#include <sbi/sbi_platform.h>
#include <sbi/sbi_trap.h>
+#include <sbi/sbi_tlb.h>
/** Context representation for a hart within a domain */
struct hart_context {
@@ -136,6 +137,7 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
ctx->stval = csr_swap(CSR_STVAL, dom_ctx->stval);
ctx->sip = csr_swap(CSR_SIP, dom_ctx->sip);
ctx->satp = csr_swap(CSR_SATP, dom_ctx->satp);
+ __sbi_sfence_vma_all();
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12)
--
2.51.2
More information about the opensbi
mailing list