From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754014AbbIPKEi (ORCPT ); Wed, 16 Sep 2015 06:04:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41976 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753479AbbIPKEe (ORCPT ); Wed, 16 Sep 2015 06:04:34 -0400 Subject: Re: [PATCH v5 1/2] KVM: nVMX: enhance allocate/free_vpid to handle shadow vpid To: Wanpeng Li References: <1442395806-14040-1-git-send-email-wanpeng.li@hotmail.com> Cc: Jan Kiszka , Bandan Das , Wincy Van , kvm@vger.kernel.org, linux-kernel@vger.kernel.org From: Paolo Bonzini Message-ID: <55F93EAD.90702@redhat.com> Date: Wed, 16 Sep 2015 12:04:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/09/2015 11:30, Wanpeng Li wrote: > Enhance allocate/free_vid to handle shadow vpid. Adjusting the commit message: KVM: nVMX: adjust interface to allocate/free_vpid Adjust allocate/free_vid so that they can be reused for the nested vpid. and committing to kvm/queue. Paolo > Signed-off-by: Wanpeng Li > --- > arch/x86/kvm/vmx.c | 25 ++++++++++++------------- > 1 file changed, 12 insertions(+), 13 deletions(-) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 9ff6a3f..f8d704d 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -4155,29 +4155,28 @@ static int alloc_identity_pagetable(struct kvm *kvm) > return r; > } > > -static void allocate_vpid(struct vcpu_vmx *vmx) > +static int allocate_vpid(void) > { > int vpid; > > - vmx->vpid = 0; > if (!enable_vpid) > - return; > + return 0; > spin_lock(&vmx_vpid_lock); > vpid = find_first_zero_bit(vmx_vpid_bitmap, VMX_NR_VPIDS); > - if (vpid < VMX_NR_VPIDS) { > - vmx->vpid = vpid; > + if (vpid < VMX_NR_VPIDS) > __set_bit(vpid, vmx_vpid_bitmap); > - } > + else > + vpid = 0; > spin_unlock(&vmx_vpid_lock); > + return vpid; > } > > -static void free_vpid(struct vcpu_vmx *vmx) > +static void free_vpid(int vpid) > { > - if (!enable_vpid) > + if (!enable_vpid || vpid == 0) > return; > spin_lock(&vmx_vpid_lock); > - if (vmx->vpid != 0) > - __clear_bit(vmx->vpid, vmx_vpid_bitmap); > + __clear_bit(vpid, vmx_vpid_bitmap); > spin_unlock(&vmx_vpid_lock); > } > > @@ -8482,7 +8481,7 @@ static void vmx_free_vcpu(struct kvm_vcpu *vcpu) > > if (enable_pml) > vmx_disable_pml(vmx); > - free_vpid(vmx); > + free_vpid(vmx->vpid); > leave_guest_mode(vcpu); > vmx_load_vmcs01(vcpu); > free_nested(vmx); > @@ -8501,7 +8500,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) > if (!vmx) > return ERR_PTR(-ENOMEM); > > - allocate_vpid(vmx); > + vmx->vpid = allocate_vpid(); > > err = kvm_vcpu_init(&vmx->vcpu, kvm, id); > if (err) > @@ -8577,7 +8576,7 @@ free_msrs: > uninit_vcpu: > kvm_vcpu_uninit(&vmx->vcpu); > free_vcpu: > - free_vpid(vmx); > + free_vpid(vmx->vpid); > kmem_cache_free(kvm_vcpu_cache, vmx); > return ERR_PTR(err); > } >