From a557105e71d3bee750ed896d71f92f212de88397 Mon Sep 17 00:00:00 2001 From: Qian Wang Date: Tue, 27 Oct 2020 15:16:56 +0800 Subject: [PATCH] hv: ept: set EPT cache attribute to WB for pSRAM pSRAM memory should be cachable. However, it's not a RAM or a normal MMIO, so we can't use the an exist API to do the EPT mapping and set the EPT cache attribute to WB for it. Now we assume that SOS must assign the PSRAM area as a whole and as a separate memory region whose base address is PSRAM_BASE_HPA. If the hpa of the EPT mapping region is equal to PSRAM_BASE_HPA, we think this EPT mapping is for pSRAM, we change the EPT mapping cache attribute to WB. And fix a minor bug when SOS trap out to emulate wbinvd when pSRAM is enabled. Tracked-On: #5330 Signed-off-by: Qian Wang Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vmexit.c | 2 +- hypervisor/common/hypercall.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hypervisor/arch/x86/guest/vmexit.c b/hypervisor/arch/x86/guest/vmexit.c index 9f35941b6..9917c2ece 100644 --- a/hypervisor/arch/x86/guest/vmexit.c +++ b/hypervisor/arch/x86/guest/vmexit.c @@ -384,7 +384,7 @@ static int32_t wbinvd_vmexit_handler(struct acrn_vcpu *vcpu) struct acrn_vcpu *other; /* GUEST_FLAG_RT has not set in post-launched RTVM before it has been created */ - if ((is_psram_initialized) || (has_rt_vm() == false)) { + if ((!is_psram_initialized) && (has_rt_vm() == false)) { cache_flush_invalidate_all(); } else { if (is_rt_vm(vcpu->vm)) { diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index e2bc08cb8..ed3f90647 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -22,6 +22,7 @@ #include #include #include +#include #define DBG_LEVEL_HYCALL 6U @@ -577,6 +578,16 @@ static int32_t add_vm_memory_region(struct acrn_vm *vm, struct acrn_vm *target_v } else { prot |= EPT_UNCACHED; } + /* If pSRAM is initialized, and HV received a request to map pSRAM area to guest, + * we should add EPT_WB flag to make pSRAM effective. + * Assumption: SOS must assign the PSRAM area as a whole and as a separate memory + * region whose base address is PSRAM_BASE_HPA + * TODO: We can enforce WB for any region has overlap with pSRAM, for simplicity, + * and leave it to SOS to make sure it won't violate. + */ + if (hpa == PSRAM_BASE_HPA && is_psram_initialized == true) { + prot |= EPT_WB; + } /* create gpa to hpa EPT mapping */ ept_add_mr(target_vm, pml4_page, hpa, region->gpa, region->size, prot);