From 65930809ee27938f086eb8d87c68920058276a70 Mon Sep 17 00:00:00 2001 From: Mingqiang Chi Date: Wed, 5 Sep 2018 13:51:32 +0800 Subject: [PATCH] hv: Replace dynamic allocation with static memory for vmxon_region Remove vmxon_region_pa from structure per_cpu_region, and define vmxon_region inside per_cpu_region. Tracked-On: #861 Signed-off-by: Mingqiang Chi Reviewed-by: Junjie Mao Acked-by: Eddie Dong --- hypervisor/arch/x86/vmx.c | 48 ++++++++++----------------- hypervisor/include/arch/x86/per_cpu.h | 3 +- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/hypervisor/arch/x86/vmx.c b/hypervisor/arch/x86/vmx.c index 80296676b..82c60c29c 100644 --- a/hypervisor/arch/x86/vmx.c +++ b/hypervisor/arch/x86/vmx.c @@ -84,42 +84,28 @@ int exec_vmxon_instr(uint16_t pcpu_id) { uint64_t tmp64, vmcs_pa; uint32_t tmp32; - int ret = -ENOMEM; - void *vmxon_region_va; + int ret = 0; + void *vmxon_region_va = (void *)per_cpu(vmxon_region, pcpu_id); + uint64_t vmxon_region_pa; struct vcpu *vcpu = get_ever_run_vcpu(pcpu_id); - /* Allocate page aligned memory for VMXON region */ - if (per_cpu(vmxon_region_pa, pcpu_id) == 0UL) { - vmxon_region_va = alloc_page(); - } - else { - vmxon_region_va = HPA2HVA(per_cpu(vmxon_region_pa, pcpu_id)); - } + /* Initialize vmxon page with revision id from IA32 VMX BASIC MSR */ + tmp32 = (uint32_t)msr_read(MSR_IA32_VMX_BASIC); + (void)memcpy_s((uint32_t *) vmxon_region_va, 4U, (void *)&tmp32, 4U); - if (vmxon_region_va != NULL) { - /* Initialize vmxon page with revision id from IA32 VMX BASIC - * MSR - */ - tmp32 = (uint32_t)msr_read(MSR_IA32_VMX_BASIC); - (void)memcpy_s((uint32_t *) vmxon_region_va, 4U, (void *)&tmp32, 4U); + /* Turn on CR0.NE and CR4.VMXE */ + CPU_CR_READ(cr0, &tmp64); + CPU_CR_WRITE(cr0, tmp64 | CR0_NE); + CPU_CR_READ(cr4, &tmp64); + CPU_CR_WRITE(cr4, tmp64 | CR4_VMXE); - /* Turn on CR0.NE and CR4.VMXE */ - CPU_CR_READ(cr0, &tmp64); - CPU_CR_WRITE(cr0, tmp64 | CR0_NE); - CPU_CR_READ(cr4, &tmp64); - CPU_CR_WRITE(cr4, tmp64 | CR4_VMXE); + /* Turn ON VMX */ + vmxon_region_pa = HVA2HPA(vmxon_region_va); + ret = exec_vmxon(&vmxon_region_pa); - /* Turn ON VMX */ - per_cpu(vmxon_region_pa, pcpu_id) = HVA2HPA(vmxon_region_va); - ret = exec_vmxon(&per_cpu(vmxon_region_pa, pcpu_id)); - - if (vcpu != NULL) { - vmcs_pa = HVA2HPA(vcpu->arch_vcpu.vmcs); - ret = exec_vmptrld(&vmcs_pa); - } - } else { - pr_err("%s, alloc memory for VMXON region failed\n", - __func__); + if (vcpu != NULL) { + vmcs_pa = HVA2HPA(vcpu->arch_vcpu.vmcs); + ret = exec_vmptrld(&vmcs_pa); } return ret; diff --git a/hypervisor/include/arch/x86/per_cpu.h b/hypervisor/include/arch/x86/per_cpu.h index 605bd3ebf..55eb485e8 100644 --- a/hypervisor/include/arch/x86/per_cpu.h +++ b/hypervisor/include/arch/x86/per_cpu.h @@ -19,6 +19,8 @@ #include "arch/x86/guest/instr_emul.h" struct per_cpu_region { + /* vmxon_region MUST be 4KB-aligned */ + uint8_t vmxon_region[CPU_PAGE_SIZE]; #ifdef HV_DEBUG uint64_t *sbuf[ACRN_SBUF_ID_MAX]; uint64_t vmexit_cnt[64]; @@ -28,7 +30,6 @@ struct per_cpu_region { uint64_t irq_count[NR_IRQS]; uint64_t softirq_pending; uint64_t spurious; - uint64_t vmxon_region_pa; struct shared_buf *earlylog_sbuf; void *vcpu; void *ever_run_vcpu;