mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: kvm-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org, akpm@osdl.org
Subject: [PATCH 4/38] KVM: Make the per-cpu enable/disable functions arch operations
Date: Mon, 27 Nov 2006 12:14:37 -0000	[thread overview]
Message-ID: <20061127121437.187B125015E@cleopatra.q> (raw)
In-Reply-To: <456AD5C6.1090406@qumranet.com>

Signed-off-by: Avi Kivity <avi@qumranet.com>

Index: linux-2.6/drivers/kvm/kvm.h
===================================================================
--- linux-2.6.orig/drivers/kvm/kvm.h
+++ linux-2.6/drivers/kvm/kvm.h
@@ -238,6 +238,8 @@ struct kvm_stat {
 struct kvm_arch_ops {
 	int (*cpu_has_kvm_support)(void);          /* __init */
 	int (*disabled_by_bios)(void);             /* __init */
+	void (*hardware_enable)(void *dummy);      /* __init */
+	void (*hardware_disable)(void *dummy);
 };
 
 extern struct kvm_stat kvm_stat;
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
@@ -135,7 +135,6 @@ static const u32 vmx_msr_index[] = {
 #define CR0_RESEVED_BITS 0xffffffff1ffaffc0ULL
 #define LMSW_GUEST_MASK 0x0eULL
 #define CR4_RESEVED_BITS (~((1ULL << 11) - 1))
-#define CR4_VMXE 0x2000
 #define CR8_RESEVED_BITS (~0x0fULL)
 #define EFER_RESERVED_BITS 0xfffffffffffff2fe
 
@@ -300,7 +299,8 @@ static void reload_tss(void)
 #endif
 }
 
-static DEFINE_PER_CPU(struct vmcs *, vmxarea);
+DEFINE_PER_CPU(struct vmcs *, vmxarea);
+EXPORT_SYMBOL_GPL(per_cpu__vmxarea); /* temporary hack */
 static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
 
 static struct vmcs_descriptor {
@@ -553,26 +553,6 @@ static __init int alloc_kvm_area(void)
 	return 0;
 }
 
-static __init void kvm_enable(void *garbage)
-{
-	int cpu = raw_smp_processor_id();
-	u64 phys_addr = __pa(per_cpu(vmxarea, cpu));
-	u64 old;
-
-	rdmsrl(MSR_IA32_FEATURE_CONTROL, old);
-	if ((old & 5) == 0)
-		/* enable and lock */
-		wrmsrl(MSR_IA32_FEATURE_CONTROL, old | 5);
-	write_cr4(read_cr4() | CR4_VMXE); /* FIXME: not cpu hotplug safe */
-	asm volatile (ASM_VMX_VMXON_RAX : : "a"(&phys_addr), "m"(phys_addr)
-		      : "memory", "cc");
-}
-
-static void kvm_disable(void *garbage)
-{
-	asm volatile (ASM_VMX_VMXOFF : : : "cc");
-}
-
 static int kvm_dev_open(struct inode *inode, struct file *filp)
 {
 	struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
@@ -3565,8 +3545,8 @@ static int kvm_reboot(struct notifier_bl
 		 * Some (well, at least mine) BIOSes hang on reboot if
 		 * in vmx root mode.
 		 */
-		printk(KERN_INFO "kvm: exiting vmx mode\n");
-		on_each_cpu(kvm_disable, 0, 0, 1);
+		printk(KERN_INFO "kvm: exiting hardware virtualization\n");
+		on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1);
 	}
 	return NOTIFY_OK;
 }
@@ -3612,6 +3592,9 @@ int kvm_init_arch(struct kvm_arch_ops *o
 		return -EOPNOTSUPP;
 	}
 
+	on_each_cpu(kvm_arch_ops->hardware_enable, 0, 0, 1);
+	register_reboot_notifier(&kvm_reboot_notifier);
+
 	kvm_chardev_ops.owner = module;
 
 	r = misc_register(&kvm_dev);
@@ -3627,6 +3610,9 @@ out_free:
 void kvm_exit_arch(void)
 {
 	misc_deregister(&kvm_dev);
+
+	unregister_reboot_notifier(&kvm_reboot_notifier);
+	on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1);
 }
 
 static __init int kvm_init(void)
@@ -3640,8 +3626,6 @@ static __init int kvm_init(void)
 	r = alloc_kvm_area();
 	if (r)
 		goto out;
-	on_each_cpu(kvm_enable, 0, 0, 1);
-	register_reboot_notifier(&kvm_reboot_notifier);
 
 	if ((bad_page = alloc_page(GFP_KERNEL)) == NULL) {
 		r = -ENOMEM;
@@ -3663,8 +3647,6 @@ out:
 static __exit void kvm_exit(void)
 {
 	kvm_exit_debug();
-	unregister_reboot_notifier(&kvm_reboot_notifier);
-	on_each_cpu(kvm_disable, 0, 0, 1);
 	free_kvm_area();
 	__free_page(pfn_to_page(bad_page_address >> PAGE_SHIFT));
 }
Index: linux-2.6/drivers/kvm/vmx.c
===================================================================
--- linux-2.6.orig/drivers/kvm/vmx.c
+++ linux-2.6/drivers/kvm/vmx.c
@@ -23,6 +23,8 @@
 MODULE_AUTHOR("Qumranet");
 MODULE_LICENSE("GPL");
 
+DECLARE_PER_CPU(struct vmcs *, vmxarea);
+
 static __init int cpu_has_kvm_support(void)
 {
 	unsigned long ecx = cpuid_ecx(1);
@@ -37,9 +39,31 @@ static __init int vmx_disabled_by_bios(v
 	return (msr & 5) == 1; /* locked but not enabled */
 }
 
+static __init void hardware_enable(void *garbage)
+{
+	int cpu = raw_smp_processor_id();
+	u64 phys_addr = __pa(per_cpu(vmxarea, cpu));
+	u64 old;
+
+	rdmsrl(MSR_IA32_FEATURE_CONTROL, old);
+	if ((old & 5) == 0)
+		/* enable and lock */
+		wrmsrl(MSR_IA32_FEATURE_CONTROL, old | 5);
+	write_cr4(read_cr4() | CR4_VMXE); /* FIXME: not cpu hotplug safe */
+	asm volatile (ASM_VMX_VMXON_RAX : : "a"(&phys_addr), "m"(phys_addr)
+		      : "memory", "cc");
+}
+
+static void hardware_disable(void *garbage)
+{
+	asm volatile (ASM_VMX_VMXOFF : : : "cc");
+}
+
 static struct kvm_arch_ops vmx_arch_ops = {
 	.cpu_has_kvm_support = cpu_has_kvm_support,
 	.disabled_by_bios = vmx_disabled_by_bios,
+	.hardware_enable = hardware_enable,
+	.hardware_disable = hardware_disable,
 };
 
 static int __init vmx_init(void)
Index: linux-2.6/drivers/kvm/vmx.h
===================================================================
--- linux-2.6.orig/drivers/kvm/vmx.h
+++ linux-2.6/drivers/kvm/vmx.h
@@ -284,4 +284,6 @@ enum vmcs_field {
 
 #define AR_RESERVD_MASK 0xfffe0f00
 
+#define CR4_VMXE 0x2000
+
 #endif

  parent reply	other threads:[~2006-11-27 12:14 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:11 ` [PATCH 1/38] KVM: Create kvm-intel.ko module Avi Kivity
2006-11-27 12:36   ` Ingo Molnar
2006-11-30 14:24     ` Christoph Hellwig
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 ` Avi Kivity [this message]
2006-11-27 12:15 ` [PATCH 5/38] KVM: Make the hardware setup operations (non-percpu) arch operations Avi Kivity
2006-11-27 12:16 ` [PATCH 6/38] KVM: Make the guest debugger an arch operation Avi Kivity
2006-11-27 12:17 ` [PATCH 7/38] KVM: Make msr accessors arch operations 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
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 ` [PATCH 31/38] KVM: Make vcpu creation and destruction " Avi Kivity
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=20061127121437.187B125015E@cleopatra.q \
    --to=avi@qumranet.com \
    --cc=akpm@osdl.org \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®