[PATCH] KVM: Initialize kvm_arch_ops on unload

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.$B!!(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>

authored by Yoshimi Ichiyanagi and committed by Linus Torvalds 09db28b8 a9058ecd

+6
+6
drivers/kvm/kvm_main.c
··· 1865 1865 { 1866 1866 int r; 1867 1867 1868 + if (kvm_arch_ops) { 1869 + printk(KERN_ERR "kvm: already loaded the other module\n"); 1870 + return -EEXIST; 1871 + } 1872 + 1868 1873 kvm_arch_ops = ops; 1869 1874 1870 1875 if (!kvm_arch_ops->cpu_has_kvm_support()) { ··· 1912 1907 unregister_reboot_notifier(&kvm_reboot_notifier); 1913 1908 on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1); 1914 1909 kvm_arch_ops->hardware_unsetup(); 1910 + kvm_arch_ops = NULL; 1915 1911 } 1916 1912 1917 1913 static __init int kvm_init(void)