Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1225895 > unrolled thread

[PATCH v5 1/2] KVM: nVMX: enhance allocate/free_vpid to handle shadow vpid

Started byWanpeng Li <wanpeng.li@hotmail.com>
First post2015-09-16 11:40 +0200
Last post2015-09-16 12:20 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v5 1/2] KVM: nVMX: enhance allocate/free_vpid to handle shadow vpid Wanpeng Li <wanpeng.li@hotmail.com> - 2015-09-16 11:40 +0200
    Re: [PATCH v5 1/2] KVM: nVMX: enhance allocate/free_vpid to handle  shadow vpid Paolo Bonzini <pbonzini@redhat.com> - 2015-09-16 12:10 +0200
      Re: [PATCH v5 1/2] KVM: nVMX: enhance allocate/free_vpid to handle  shadow vpid Wanpeng Li <wanpeng.li@hotmail.com> - 2015-09-16 12:20 +0200

#1225895 — [PATCH v5 1/2] KVM: nVMX: enhance allocate/free_vpid to handle shadow vpid

FromWanpeng Li <wanpeng.li@hotmail.com>
Date2015-09-16 11:40 +0200
Subject[PATCH v5 1/2] KVM: nVMX: enhance allocate/free_vpid to handle shadow vpid
Message-ID<q9hm4-uy-31@gated-at.bofh.it>
Enhance allocate/free_vid to handle shadow vpid.

Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
 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);
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1225911 — Re: [PATCH v5 1/2] KVM: nVMX: enhance allocate/free_vpid to handle shadow vpid

FromPaolo Bonzini <pbonzini@redhat.com>
Date2015-09-16 12:10 +0200
SubjectRe: [PATCH v5 1/2] KVM: nVMX: enhance allocate/free_vpid to handle shadow vpid
Message-ID<q9hP4-1id-13@gated-at.bofh.it>
In reply to#1225895

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 <wanpeng.li@hotmail.com>
> ---
>  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);
>  }
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1225926 — Re: [PATCH v5 1/2] KVM: nVMX: enhance allocate/free_vpid to handle shadow vpid

FromWanpeng Li <wanpeng.li@hotmail.com>
Date2015-09-16 12:20 +0200
SubjectRe: [PATCH v5 1/2] KVM: nVMX: enhance allocate/free_vpid to handle shadow vpid
Message-ID<q9hYK-1tT-1@gated-at.bofh.it>
In reply to#1225911
On 9/16/15 6:04 PM, Paolo Bonzini wrote:
>
> 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.

Cool, always thanks for your help, Paolo! :-)

Regards,
Wanpeng Li

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web