From b7e9a68923c34993445999e7585446320a944cc0 Mon Sep 17 00:00:00 2001 From: Zide Chen Date: Fri, 20 Aug 2021 19:12:41 -0700 Subject: [PATCH] hv: code cleanup in run_vcpu() - wrap a new function exec_vmentry() to reduce code duplication. - remove exec_vmread(VMX_GUEST_RSP) since ACRN doesn't need to know guest RSP in run time. Tracked-On: #6289 Signed-off-by: Zide Chen Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vcpu.c | 37 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index e40f1be72..1ae5ef2e6 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -602,6 +602,21 @@ int32_t create_vcpu(uint16_t pcpu_id, struct acrn_vm *vm, struct acrn_vcpu **rtn return ret; } +/** + * @pre ctx != NULL + */ +static inline int32_t exec_vmentry(struct run_context *ctx, int32_t launch_type, int32_t ibrs_type) +{ +#ifdef CONFIG_L1D_FLUSH_VMENTRY_ENABLED + cpu_l1d_flush(); +#endif + + /* Mitigation for MDS vulnerability, overwrite CPU internal buffers */ + cpu_internal_buffers_clear(); + + return vmx_vmrun(ctx, launch_type, ibrs_type); +} + /* * @pre vcpu != NULL */ @@ -689,15 +704,8 @@ int32_t run_vcpu(struct acrn_vcpu *vcpu) msr_write(MSR_IA32_PRED_CMD, PRED_SET_IBPB); } -#ifdef CONFIG_L1D_FLUSH_VMENTRY_ENABLED - cpu_l1d_flush(); -#endif - - /*Mitigation for MDS vulnerability, overwrite CPU internal buffers */ - cpu_internal_buffers_clear(); - /* Launch the VM */ - status = vmx_vmrun(ctx, VM_LAUNCH, ibrs_type); + status = exec_vmentry(ctx, VM_LAUNCH, ibrs_type); /* See if VM launched successfully */ if (status == 0) { @@ -712,17 +720,10 @@ int32_t run_vcpu(struct acrn_vcpu *vcpu) */ instlen = vcpu->arch.inst_len; rip = vcpu_get_rip(vcpu); - exec_vmwrite(VMX_GUEST_RIP, ((rip+(uint64_t)instlen) & - 0xFFFFFFFFFFFFFFFFUL)); -#ifdef CONFIG_L1D_FLUSH_VMENTRY_ENABLED - cpu_l1d_flush(); -#endif - - /* Mitigation for MDS vulnerability, overwrite CPU internal buffers */ - cpu_internal_buffers_clear(); + exec_vmwrite(VMX_GUEST_RIP, rip + instlen); /* Resume the VM */ - status = vmx_vmrun(ctx, VM_RESUME, ibrs_type); + status = exec_vmentry(ctx, VM_RESUME, ibrs_type); } vcpu->reg_cached = 0UL; @@ -738,8 +739,6 @@ int32_t run_vcpu(struct acrn_vcpu *vcpu) ia32_efer = vcpu_get_efer(vcpu); cr0 = vcpu_get_cr0(vcpu); set_vcpu_mode(vcpu, cs_attr, ia32_efer, cr0); - - ctx->cpu_regs.regs.rsp = exec_vmread(VMX_GUEST_RSP); } /* Obtain current VCPU instruction length */