public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: akpm-3NddpPZAyC0@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 31/38] KVM: Make vcpu creation and destruction arch operations
Date: Mon, 27 Nov 2006 12:41:38 -0000	[thread overview]
Message-ID: <20061127124138.BA36825015E@cleopatra.q> (raw)
In-Reply-To: <456AD5C6.1090406-atKUWr5tajBWk0Htik3J/w@public.gmane.org>

Signed-off-by: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>

Index: linux-2.6/drivers/kvm/kvm.h
===================================================================
--- linux-2.6.orig/drivers/kvm/kvm.h
+++ linux-2.6/drivers/kvm/kvm.h
@@ -260,6 +260,9 @@ struct kvm_arch_ops {
 	int (*hardware_setup)(void);               /* __init */
 	void (*hardware_unsetup)(void);            /* __exit */
 
+	int (*vcpu_create)(struct kvm_vcpu *vcpu);
+	void (*vcpu_free)(struct kvm_vcpu *vcpu);
+
 	struct kvm_vcpu *(*vcpu_load)(struct kvm_vcpu *vcpu);
 	void (*vcpu_put)(struct kvm_vcpu *vcpu);
 
@@ -299,8 +302,6 @@ struct kvm_arch_ops {
 	void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);
 };
 
-void __vcpu_clear(void *arg); /* temporary hack */
-
 extern struct kvm_stat kvm_stat;
 extern struct kvm_arch_ops *kvm_arch_ops;
 
Index: linux-2.6/drivers/kvm/kvm_main.c
===================================================================
--- linux-2.6.orig/drivers/kvm/kvm_main.c
+++ linux-2.6/drivers/kvm/kvm_main.c
@@ -219,31 +219,6 @@ int kvm_write_guest(struct kvm_vcpu *vcp
 }
 EXPORT_SYMBOL_GPL(kvm_write_guest);
 
-static void vmcs_clear(struct vmcs *vmcs)
-{
-	u64 phys_addr = __pa(vmcs);
-	u8 error;
-
-	asm volatile (ASM_VMX_VMCLEAR_RAX "; setna %0"
-		      : "=g"(error) : "a"(&phys_addr), "m"(phys_addr)
-		      : "cc", "memory");
-	if (error)
-		printk(KERN_ERR "kvm: vmclear fail: %p/%llx\n",
-		       vmcs, phys_addr);
-}
-
-void __vcpu_clear(void *arg)
-{
-	struct kvm_vcpu *vcpu = arg;
-	int cpu = smp_processor_id();
-
-	if (vcpu->cpu == cpu)
-		vmcs_clear(vcpu->vmcs);
-	if (per_cpu(current_vmcs, cpu) == vcpu->vmcs)
-		per_cpu(current_vmcs, cpu) = 0;
-}
-EXPORT_SYMBOL_GPL(__vcpu_clear);
-
 static int vcpu_slot(struct kvm_vcpu *vcpu)
 {
 	return vcpu - vcpu->kvm->vcpus;
@@ -271,33 +246,6 @@ static void vcpu_put(struct kvm_vcpu *vc
 	mutex_unlock(&vcpu->mutex);
 }
 
-struct vmcs *alloc_vmcs_cpu(int cpu)
-{
-	int node = cpu_to_node(cpu);
-	struct page *pages;
-	struct vmcs *vmcs;
-
-	pages = alloc_pages_node(node, GFP_KERNEL, vmcs_descriptor.order);
-	if (!pages)
-		return 0;
-	vmcs = page_address(pages);
-	memset(vmcs, 0, vmcs_descriptor.size);
-	vmcs->revision_id = vmcs_descriptor.revision_id; /* vmcs revision id */
-	return vmcs;
-}
-EXPORT_SYMBOL_GPL(alloc_vmcs_cpu);
-
-static struct vmcs *alloc_vmcs(void)
-{
-	return alloc_vmcs_cpu(smp_processor_id());
-}
-
-void free_vmcs(struct vmcs *vmcs)
-{
-	free_pages((unsigned long)vmcs, vmcs_descriptor.order);
-}
-EXPORT_SYMBOL_GPL(free_vmcs);
-
 static int kvm_dev_open(struct inode *inode, struct file *filp)
 {
 	struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
@@ -350,18 +298,9 @@ static void kvm_free_physmem(struct kvm 
 		kvm_free_physmem_slot(&kvm->memslots[i], 0);
 }
 
-static void kvm_free_vmcs(struct kvm_vcpu *vcpu)
-{
-	if (vcpu->vmcs) {
-		on_each_cpu(__vcpu_clear, vcpu, 0, 1);
-		free_vmcs(vcpu->vmcs);
-		vcpu->vmcs = 0;
-	}
-}
-
 static void kvm_free_vcpu(struct kvm_vcpu *vcpu)
 {
-	kvm_free_vmcs(vcpu);
+	kvm_arch_ops->vcpu_free(vcpu);
 	kvm_mmu_destroy(vcpu);
 }
 
@@ -613,7 +552,6 @@ static int kvm_dev_ioctl_create_vcpu(str
 {
 	int r;
 	struct kvm_vcpu *vcpu;
-	struct vmcs *vmcs;
 
 	r = -EINVAL;
 	if (n < 0 || n >= KVM_MAX_VCPUS)
@@ -634,14 +572,9 @@ static int kvm_dev_ioctl_create_vcpu(str
 
 	vcpu->cpu = -1;  /* First load will set up TR */
 	vcpu->kvm = kvm;
-	vmcs = alloc_vmcs();
-	if (!vmcs) {
-		mutex_unlock(&vcpu->mutex);
+	r = kvm_arch_ops->vcpu_create(vcpu);
+	if (r < 0)
 		goto out_free_vcpus;
-	}
-	vmcs_clear(vmcs);
-	vcpu->vmcs = vmcs;
-	vcpu->launched = 0;
 
 	kvm_arch_ops->vcpu_load(vcpu);
 
@@ -658,6 +591,7 @@ static int kvm_dev_ioctl_create_vcpu(str
 
 out_free_vcpus:
 	kvm_free_vcpu(vcpu);
+	mutex_unlock(&vcpu->mutex);
 out:
 	return r;
 }
Index: linux-2.6/drivers/kvm/vmx.c
===================================================================
--- linux-2.6.orig/drivers/kvm/vmx.c
+++ linux-2.6/drivers/kvm/vmx.c
@@ -77,6 +77,30 @@ static const u32 vmx_msr_index[] = {
 
 struct vmx_msr_entry *find_msr_entry(struct kvm_vcpu *vcpu, u32 msr);
 
+static void vmcs_clear(struct vmcs *vmcs)
+{
+	u64 phys_addr = __pa(vmcs);
+	u8 error;
+
+	asm volatile (ASM_VMX_VMCLEAR_RAX "; setna %0"
+		      : "=g"(error) : "a"(&phys_addr), "m"(phys_addr)
+		      : "cc", "memory");
+	if (error)
+		printk(KERN_ERR "kvm: vmclear fail: %p/%llx\n",
+		       vmcs, phys_addr);
+}
+
+static void __vcpu_clear(void *arg)
+{
+	struct kvm_vcpu *vcpu = arg;
+	int cpu = smp_processor_id();
+
+	if (vcpu->cpu == cpu)
+		vmcs_clear(vcpu->vmcs);
+	if (per_cpu(current_vmcs, cpu) == vcpu->vmcs)
+		per_cpu(current_vmcs, cpu) = 0;
+}
+
 /*
  * Switches to specified vcpu, until a matching vcpu_put(), but assumes
  * vcpu mutex is already taken.
@@ -449,7 +473,30 @@ static __init void setup_vmcs_descriptor
 	vmcs_descriptor.revision_id = vmx_msr_low;
 };
 
-void free_vmcs(struct vmcs *vmcs);
+static struct vmcs *alloc_vmcs_cpu(int cpu)
+{
+	int node = cpu_to_node(cpu);
+	struct page *pages;
+	struct vmcs *vmcs;
+
+	pages = alloc_pages_node(node, GFP_KERNEL, vmcs_descriptor.order);
+	if (!pages)
+		return 0;
+	vmcs = page_address(pages);
+	memset(vmcs, 0, vmcs_descriptor.size);
+	vmcs->revision_id = vmcs_descriptor.revision_id; /* vmcs revision id */
+	return vmcs;
+}
+
+static struct vmcs *alloc_vmcs(void)
+{
+	return alloc_vmcs_cpu(smp_processor_id());
+}
+
+static void free_vmcs(struct vmcs *vmcs)
+{
+	free_pages((unsigned long)vmcs, vmcs_descriptor.order);
+}
 
 static __exit void free_kvm_area(void)
 {
@@ -1790,6 +1837,33 @@ static void vmx_inject_page_fault(struct
 
 }
 
+static void vmx_free_vmcs(struct kvm_vcpu *vcpu)
+{
+	if (vcpu->vmcs) {
+		on_each_cpu(__vcpu_clear, vcpu, 0, 1);
+		free_vmcs(vcpu->vmcs);
+		vcpu->vmcs = 0;
+	}
+}
+
+static void vmx_free_vcpu(struct kvm_vcpu *vcpu)
+{
+	vmx_free_vmcs(vcpu);
+}
+
+static int vmx_create_vcpu(struct kvm_vcpu *vcpu)
+{
+	struct vmcs *vmcs;
+
+	vmcs = alloc_vmcs();
+	if (!vmcs)
+		return -ENOMEM;
+	vmcs_clear(vmcs);
+	vcpu->vmcs = vmcs;
+	vcpu->launched = 0;
+	return 0;
+}
+
 static struct kvm_arch_ops vmx_arch_ops = {
 	.cpu_has_kvm_support = cpu_has_kvm_support,
 	.disabled_by_bios = vmx_disabled_by_bios,
@@ -1798,6 +1872,9 @@ static struct kvm_arch_ops vmx_arch_ops 
 	.hardware_enable = hardware_enable,
 	.hardware_disable = hardware_disable,
 
+	.vcpu_create = vmx_create_vcpu,
+	.vcpu_free = vmx_free_vcpu,
+
 	.vcpu_load = vmx_vcpu_load,
 	.vcpu_put = vmx_vcpu_put,
 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

  parent reply	other threads:[~2006-11-27 12:41 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-27 12:10 [PATCH 0/38] KVM: Decouple Intel VT implementation from base kvm Avi Kivity
2006-11-27 12:16 ` [PATCH 6/38] KVM: Make the guest debugger an arch operation Avi Kivity
     [not found] ` <456AD5C6.1090406-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2006-11-27 12:11   ` [PATCH 1/38] KVM: Create kvm-intel.ko module Avi Kivity
2006-11-27 12:36     ` Ingo Molnar
     [not found]       ` <20061127123606.GA11825-X9Un+BFzKDI@public.gmane.org>
2006-11-30 14:24         ` Christoph Hellwig
     [not found]           ` <20061130142435.GA13372-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2006-11-30 15:44             ` Ingo Molnar
2006-11-30 19:59               ` Andrew Morton
2006-11-30 20:19                 ` Ingo Molnar
2006-11-30 20:24                   ` Christoph Hellwig
2006-11-30 20:31                     ` Ingo Molnar
2006-11-27 12:12   ` [PATCH 2/38] KVM: Make /dev/registration happen when the arch specific module is loaded Avi Kivity
2006-11-27 12:13   ` [PATCH 0/38] KVM: Decouple Intel VT implementation from base kvm Avi Kivity
2006-11-27 12:13   ` [PATCH 3/38] KV: Make hardware detection an arch operation Avi Kivity
2006-11-27 12:14   ` [PATCH 4/38] KVM: Make the per-cpu enable/disable functions arch operations Avi Kivity
2006-11-27 12:15   ` [PATCH 5/38] KVM: Make the hardware setup operations (non-percpu) " Avi Kivity
2006-11-27 12:17   ` [PATCH 7/38] KVM: Make msr accessors " Avi Kivity
2006-11-27 12:18   ` [PATCH 8/38] KVM: Make the segment " Avi Kivity
2006-11-27 12:19   ` [PATCH 9/38] KVM: Cache guest cr4 in vcpu structure Avi Kivity
2006-11-27 12:20   ` [PATCH 10/38] KVM: Cache guest cr0 " Avi Kivity
2006-11-27 12:21   ` [PATCH 11/38] KVM: Add get_segment_base() arch accessor Avi Kivity
2006-11-27 12:22   ` [PATCH 12/38] KVM: Add idt and gdt descriptor accessors Avi Kivity
2006-11-27 12:23   ` [PATCH 13/38] KVM: Make syncing the register file to the vcpu structure an arch operation Avi Kivity
2006-11-27 12:24   ` [PATCH 14/38] KVM: Make the vcpu execution loop " Avi Kivity
2006-11-27 12:25   ` [PATCH 15/38] KVM: Move the vmx exit handlers to vmx.c Avi Kivity
2006-11-27 12:26   ` [PATCH 16/38] KVM: Make vcpu_setup() an arch operation Avi Kivity
2006-11-27 12:27   ` [PATCH 17/38] KVM: Make __set_cr0() (and dependencies) arch operations Avi Kivity
2006-11-27 12:28   ` [PATCH 18/38] KVM: Make __set_cr4() an arch operation Avi Kivity
2006-11-27 12:29   ` [PATCH 19/38] KVM: Make __set_efer() " Avi Kivity
2006-11-27 13:39     ` Christoph Hellwig
     [not found]       ` <20061127133944.GA4155-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2006-11-27 13:46         ` Avi Kivity
2006-11-27 12:30   ` [PATCH 20/38] KVM: Make set_cr3() and tlb flushing arch operations Avi Kivity
2006-11-27 12:31   ` [PATCH 21/38] KVM: Make inject_page_fault() an arch operation Avi Kivity
2006-11-27 12:32   ` [PATCH 22/38] KVM: Make inject_gp() " Avi Kivity
2006-11-27 12:33   ` [PATCH 23/38] KVM: Use the idt and gdt accessors in realmode emulation Avi Kivity
2006-11-27 12:34   ` [PATCH 24/38] KVM: Use the general purpose register accessors rather than direct access Avi Kivity
2006-11-27 12:35   ` [PATCH 25/38] KVM: Move the vmx tsc accessors to vmx.c Avi Kivity
2006-11-27 12:36   ` [PATCH 26/38] KVM: Access rflags through an arch operation Avi Kivity
2006-11-27 12:37   ` [PATCH 27/38] KVM: Move the vmx segment field definitions to vmx.c Avi Kivity
2006-11-27 12:38   ` [PATCH 28/38] KVM: Add an arch accessor for cs d/b and l bits Avi Kivity
2006-11-27 12:39   ` [PATCH 29/38] KVM: Add a set_cr0_no_modeswitch() arch accessor Avi Kivity
2006-11-27 12:40   ` [PATCH 30/38] KVM: Make vcpu_load() and vcpu_put() arch operations Avi Kivity
2006-11-27 12:41   ` Avi Kivity [this message]
2006-11-27 12:42   ` [PATCH 32/38] KVM: Move vmcs static variables to vmx.c Avi Kivity
2006-11-27 12:43   ` [PATCH 33/38] KVM: Make is_long_mode() an arch operation Avi Kivity
2006-11-27 12:44   ` [PATCH 34/38] KVM: Use the tlb flush arch operation instead of an inline Avi Kivity
2006-11-27 12:45   ` [PATCH 35/38] KVM: Remove guest_cpl() Avi Kivity
2006-11-27 12:46   ` [PATCH 36/38] KVM: Move vmcs accessors to vmx.c Avi Kivity
2006-11-27 12:47   ` [PATCH 37/38] KVM: Move vmx helper inlines " Avi Kivity
2006-11-27 12:48   ` [PATCH 38/38] KVM: Remove vmx includes from arch independent code Avi Kivity

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=20061127124138.BA36825015E@cleopatra.q \
    --to=avi-atkuwr5tajbwk0htik3j/w@public.gmane.org \
    --cc=akpm-3NddpPZAyC0@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /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