mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: bsd@redhat.com, Wanpeng Li <wanpeng.li@hotmail.com>
Subject: [FYI PATCH 16/20] KVM: VMX: adjust interface to allocate/free_vpid
Date: Mon, 28 Sep 2015 12:39:01 +0200	[thread overview]
Message-ID: <1443436745-38086-17-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1443436745-38086-1-git-send-email-pbonzini@redhat.com>

From: Wanpeng Li <wanpeng.li@hotmail.com>

Adjust allocate/free_vid so that they can be reused for the nested vpid.

Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.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 b2d619ab3d07..656074153f49 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);
 }
 
@@ -8483,7 +8482,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);
@@ -8502,7 +8501,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)
@@ -8578,7 +8577,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.8.3.1



  parent reply	other threads:[~2015-09-28 10:39 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-28 10:38 [FYI PATCH 00/20] kvm/queue will be merged soon to kvm/next Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 01/20] KVM: x86: set TMR when the interrupt is accepted Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 02/20] KVM: x86: store IOAPIC-handled vectors in each VCPU Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 03/20] KVM: x86: replace vm_has_apicv hook with cpu_uses_apicv Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 04/20] KVM: x86: introduce lapic_in_kernel Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 05/20] KVM: x86: unify handling of interrupt window Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 06/20] KVM: x86: Split the APIC from the rest of IRQCHIP Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 07/20] KVM: x86: Add KVM exit for IOAPIC EOIs Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 08/20] KVM: x86: Add EOI exit bitmap inference Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 09/20] KVM: x86: Add support for local interrupt requests from userspace Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 10/20] kvm: use kmalloc() instead of kzalloc() during iodev register/unregister Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 11/20] kvm: add tracepoint for fast mmio Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 12/20] kvm: add capability for any-length ioeventfds Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 13/20] kvm/x86: Hyper-V HV_X64_MSR_RESET msr Paolo Bonzini
2015-09-28 10:38 ` [FYI PATCH 14/20] kvm/x86: Hyper-V HV_X64_MSR_VP_INDEX export for QEMU Paolo Bonzini
2015-09-28 10:39 ` [FYI PATCH 15/20] kvm/x86: Hyper-V HV_X64_MSR_VP_RUNTIME support Paolo Bonzini
2015-09-28 10:39 ` Paolo Bonzini [this message]
2015-09-28 10:39 ` [FYI PATCH 17/20] KVM: VMX: introduce __vmx_flush_tlb to handle specific vpid Paolo Bonzini
2015-09-28 10:39 ` [FYI PATCH 18/20] KVM: nVMX: emulate the INVVPID instruction Paolo Bonzini
2015-09-28 10:39 ` [FYI PATCH 19/20] KVM: nVMX: nested VPID emulation Paolo Bonzini
2015-09-28 10:39 ` [FYI PATCH 20/20] KVM: vmx: disable posted interrupts if no local APIC Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443436745-38086-17-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=bsd@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wanpeng.li@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®