From 1b79f28efe9c4a2c28af54db2d143ca5f57a092f Mon Sep 17 00:00:00 2001 From: Qi Yadong Date: Mon, 18 Mar 2019 12:11:53 +0800 Subject: [PATCH] hv: update CR0/CR4 on demand in run_vcpu() Suppose run_ctx.cr0/cr4 are correct when do world switching, so call vcpu_set_cr0/cr4() to update cr0/cr4 directly before resume to guest. This design is only for trusty world switching. Tracked-On: #2773 Signed-off-by: Qi Yadong Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vcpu.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index 53fcdb1ee..3a2f22548 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -432,6 +432,19 @@ int32_t run_vcpu(struct acrn_vcpu *vcpu) if (bitmap_test_and_clear_lock(CPU_REG_RFLAGS, &vcpu->reg_updated)) exec_vmwrite(VMX_GUEST_RFLAGS, ctx->rflags); + /* + * Currently, updating CR0/CR4 here is only designed for world + * switching. There should no other module request updating + * CR0/CR4 here. + */ + if (bitmap_test_and_clear_lock(CPU_REG_CR0, &vcpu->reg_updated)) { + vcpu_set_cr0(vcpu, ctx->cr0); + } + + if (bitmap_test_and_clear_lock(CPU_REG_CR4, &vcpu->reg_updated)) { + vcpu_set_cr4(vcpu, ctx->cr4); + } + /* If this VCPU is not already launched, launch it */ if (!vcpu->launched) { pr_info("VM %d Starting VCPU %hu",