From 2a184f353cd7cb85e03b04e8296afb77d582389c Mon Sep 17 00:00:00 2001 From: Shiqing Gao Date: Fri, 24 Aug 2018 16:21:59 +0800 Subject: [PATCH] hv: code clean up regarding to guest_msrs Change guest_msrs in vcpu data structure from pointer to array, which could avoid the dynamic memory allocation. v1 -> v2: * Remove the unnecessary initialization for guest_msrs[] since vcpu is allocated by calloc. Tracked-On: #861 Signed-off-by: Shiqing Gao Acked-by: Anthony Xu --- hypervisor/arch/x86/guest/vcpu.c | 1 - hypervisor/arch/x86/guest/vmsr.c | 8 -------- hypervisor/include/arch/x86/guest/vcpu.h | 2 +- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index a0f401ffa..32ac6e1c6 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -385,7 +385,6 @@ void destroy_vcpu(struct vcpu *vcpu) vlapic_free(vcpu); free(vcpu->arch_vcpu.vmcs); - free(vcpu->guest_msrs); per_cpu(ever_run_vcpu, vcpu->pcpu_id) = NULL; free_pcpu(vcpu->pcpu_id); free(vcpu); diff --git a/hypervisor/arch/x86/guest/vmsr.c b/hypervisor/arch/x86/guest/vmsr.c index 57c7e8764..1494b5f5c 100644 --- a/hypervisor/arch/x86/guest/vmsr.c +++ b/hypervisor/arch/x86/guest/vmsr.c @@ -105,14 +105,6 @@ void init_msr_emulation(struct vcpu *vcpu) value64 = HVA2HPA(vcpu->vm->arch_vm.msr_bitmap); exec_vmwrite64(VMX_MSR_BITMAP_FULL, value64); pr_dbg("VMX_MSR_BITMAP: 0x%016llx ", value64); - - if (!vcpu->guest_msrs) { - vcpu->guest_msrs = - (uint64_t *)calloc(msrs_count, sizeof(uint64_t)); - } - - ASSERT(vcpu->guest_msrs != NULL, ""); - (void)memset(vcpu->guest_msrs, 0U, msrs_count * sizeof(uint64_t)); } int rdmsr_vmexit_handler(struct vcpu *vcpu) diff --git a/hypervisor/include/arch/x86/guest/vcpu.h b/hypervisor/include/arch/x86/guest/vcpu.h index 676749cdc..c230db4a8 100644 --- a/hypervisor/include/arch/x86/guest/vcpu.h +++ b/hypervisor/include/arch/x86/guest/vcpu.h @@ -240,7 +240,7 @@ struct vcpu { * code. */ uint64_t msr_tsc_aux_guest; - uint64_t *guest_msrs; + uint64_t guest_msrs[IDX_MAX_MSR]; #ifdef CONFIG_MTRR_ENABLED struct mtrr_state mtrr; #endif