[PATCH] KVM: Initialize kvm_arch_ops on unload
authorYoshimi Ichiyanagi <ichiyanagi.yoshimi@lab.ntt.co.jp>
Sat, 30 Dec 2006 00:49:41 +0000 (16:49 -0800)
committerLinus Torvalds <torvalds@woody.osdl.org>
Sat, 30 Dec 2006 18:56:44 +0000 (10:56 -0800)
The latest version of kvm doesn't initialize kvm_arch_ops in kvm_init(), which
causes an error with the following sequence.

1. Load the supported arch's module.
2. Load the unsupported arch's module.\e$B!!\e(B(loading error)
3. Unload the unsupported arch's module.

You'll get the following error message after step 3.  "BUG: unable to handle
to handle kernel paging request at virtual address xxxxxxxx"

The problem here is that the unsupported arch's module overwrites kvm_arch_ops
of the supported arch's module at step 2.

This patch initializes kvm_arch_ops upon loading architecture specific kvm
module, and prevents overwriting kvm_arch_ops when kvm_arch_ops is already set
correctly.

Signed-off-by: Avi Kivity <avi@qumranet.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/kvm/kvm_main.c

index 38375e2..0631407 100644 (file)
@@ -1865,6 +1865,11 @@ int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module)
 {
        int r;
 
+       if (kvm_arch_ops) {
+               printk(KERN_ERR "kvm: already loaded the other module\n");
+               return -EEXIST;
+       }
+
        kvm_arch_ops = ops;
 
        if (!kvm_arch_ops->cpu_has_kvm_support()) {
@@ -1907,6 +1912,7 @@ void kvm_exit_arch(void)
        unregister_reboot_notifier(&kvm_reboot_notifier);
        on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1);
        kvm_arch_ops->hardware_unsetup();
+       kvm_arch_ops = NULL;
 }
 
 static __init int kvm_init(void)