Skip to contentSkip to conversation

lib: sbi_domain_context: Flush TLB after SATP mode switch

PATCH Applied Zishun Yi 2 participants 2 messages Apr 29 – Jun 9

lore
Share & tools
lore

Zishun Yi

author
#0 lore raw

PATCH 1/1 lib: sbi_domain_context: Flush TLB after SATP mode switch

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.

---
 lib/sbi/sbi_domain_context.c | 2 ++
 1 file changed, 2 insertions(+)
lib/sbi/sbi_domain_context.c +2 -0
index 158f4990432e..f47875e48230 100644
@@ -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)
Signature · 7 lines
2.51.2


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Reviewed-by on v1 1/1 Applied
#1 lore raw
Quoted 7 lines · Zishun Yi

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.

Quoted 5 lines

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.

The hart protection re-configuration will anyway perform full sfence / hfence so instead of adding yet another sfence over here it will be better to move the hart protection re-configuration after the CSR+FP+Vector context switch.

I will update the commit description and do the required code movement at the time of merging this patch.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi