[PATCH 2/2] kvm: disable virtualization when halting CPUs on crash

Eduardo Habkost ehabkost at redhat.com
Mon Oct 20 11:01:34 EDT 2008


Use the emergency_halt_notifier interface to disable virtualization
on all the CPUs on machine_crash_shutdown().

Signed-off-by: Eduardo Habkost <ehabkost at redhat.com>
---
 arch/x86/kvm/x86.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 5d29c50..17e2df1 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -40,6 +40,7 @@
 #include <asm/msr.h>
 #include <asm/desc.h>
 #include <asm/mtrr.h>
+#include <asm/reboot.h>
 
 #define MAX_IO_MSRS 256
 #define CR0_RESERVED_BITS						\
@@ -2583,6 +2584,18 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
 }
 EXPORT_SYMBOL_GPL(kvm_emulate_pio_string);
 
+static int kvm_emergency_halt(struct notifier_block *notifier,
+			      unsigned long val, void *v)
+{
+	/* We are crashing. Do the very least */
+	kvm_arch_hardware_disable(NULL);
+	return NOTIFY_OK;
+}
+
+static struct notifier_block kvm_emergency_halt_notifier = {
+	.notifier_call = kvm_emergency_halt,
+};
+
 int kvm_arch_init(void *opaque)
 {
 	int r;
@@ -2605,10 +2618,14 @@ int kvm_arch_init(void *opaque)
 		goto out;
 	}
 
-	r = kvm_mmu_module_init();
+	r = register_emergency_halt_notifier(&kvm_emergency_halt_notifier);
 	if (r)
 		goto out;
 
+	r = kvm_mmu_module_init();
+	if (r)
+		goto out_unregister;
+
 	kvm_init_msr_list();
 
 	kvm_x86_ops = ops;
@@ -2618,6 +2635,8 @@ int kvm_arch_init(void *opaque)
 			PT_DIRTY_MASK, PT64_NX_MASK, 0, 0);
 	return 0;
 
+out_unregister:
+	unregister_emergency_halt_notifier(&kvm_emergency_halt_notifier);
 out:
 	return r;
 }
@@ -2626,6 +2645,7 @@ void kvm_arch_exit(void)
 {
 	kvm_x86_ops = NULL;
 	kvm_mmu_module_exit();
+	unregister_emergency_halt_notifier(&kvm_emergency_halt_notifier);
 }
 
 int kvm_emulate_halt(struct kvm_vcpu *vcpu)
-- 
1.5.5.GIT




More information about the kexec mailing list