From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751556AbeA2Kbd (ORCPT ); Mon, 29 Jan 2018 05:31:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43678 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751204AbeA2Kbc (ORCPT ); Mon, 29 Jan 2018 05:31:32 -0500 Subject: Re: [PATCH v2 2/3] KVM: VMX: introduce alloc_loaded_vmcs To: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , David Woodhouse , KarimAllah Ahmed References: <1517043027-7655-1-git-send-email-pbonzini@redhat.com> <1517043027-7655-3-git-send-email-pbonzini@redhat.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <6caf105b-7e5c-b7ed-4f27-91b82b19396a@redhat.com> Date: Mon, 29 Jan 2018 11:31:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <1517043027-7655-3-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 27.01.2018 09:50, Paolo Bonzini wrote: > Group together the calls to alloc_vmcs and loaded_vmcs_init. Soon we'll also > allocate an MSR bitmap there. > > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/vmx.c | 36 ++++++++++++++++++++++-------------- > 1 file changed, 22 insertions(+), 14 deletions(-) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index ad6a883b7a32..ab4b9bc99a52 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -3829,11 +3829,6 @@ static struct vmcs *alloc_vmcs_cpu(int cpu) > return vmcs; > } > > -static struct vmcs *alloc_vmcs(void) > -{ > - return alloc_vmcs_cpu(raw_smp_processor_id()); > -} > - > static void free_vmcs(struct vmcs *vmcs) > { > free_pages((unsigned long)vmcs, vmcs_config.order); > @@ -3852,6 +3847,22 @@ static void free_loaded_vmcs(struct loaded_vmcs *loaded_vmcs) > WARN_ON(loaded_vmcs->shadow_vmcs != NULL); > } > > +static struct vmcs *alloc_vmcs(void) > +{ > + return alloc_vmcs_cpu(raw_smp_processor_id()); > +} > + > +static int alloc_loaded_vmcs(struct loaded_vmcs *loaded_vmcs) > +{ > + loaded_vmcs->vmcs = alloc_vmcs(); > + if (!loaded_vmcs->vmcs) > + return -ENOMEM; > + > + loaded_vmcs->shadow_vmcs = NULL; > + loaded_vmcs_init(loaded_vmcs); > + return 0; > +} > + > static void free_kvm_area(void) > { > int cpu; > @@ -7145,12 +7156,11 @@ static int enter_vmx_operation(struct kvm_vcpu *vcpu) > { > struct vcpu_vmx *vmx = to_vmx(vcpu); > struct vmcs *shadow_vmcs; > + int r; > > - vmx->nested.vmcs02.vmcs = alloc_vmcs(); > - vmx->nested.vmcs02.shadow_vmcs = NULL; > - if (!vmx->nested.vmcs02.vmcs) > + r = alloc_loaded_vmcs(&vmx->nested.vmcs02); > + if (r < 0) > goto out_vmcs02; > - loaded_vmcs_init(&vmx->nested.vmcs02); > > if (cpu_has_vmx_msr_bitmap()) { > vmx->nested.msr_bitmap = > @@ -9545,13 +9555,11 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) > if (!vmx->guest_msrs) > goto free_pml; > > - vmx->loaded_vmcs = &vmx->vmcs01; > - vmx->loaded_vmcs->vmcs = alloc_vmcs(); > - vmx->loaded_vmcs->shadow_vmcs = NULL; > - if (!vmx->loaded_vmcs->vmcs) > + err = alloc_loaded_vmcs(&vmx->vmcs01); > + if (err < 0) > goto free_msrs; > - loaded_vmcs_init(vmx->loaded_vmcs); > > + vmx->loaded_vmcs = &vmx->vmcs01; > cpu = get_cpu(); > vmx_vcpu_load(&vmx->vcpu, cpu); > vmx->vcpu.cpu = cpu; > Reviewed-by: David Hildenbrand -- Thanks, David / dhildenb