diff --git a/arch/x86/kvm/vac.c b/arch/x86/kvm/vac.c index 3977279a84f43d..365d8e24296429 100644 --- a/arch/x86/kvm/vac.c +++ b/arch/x86/kvm/vac.c @@ -9,7 +9,6 @@ u32 __read_mostly kvm_uret_msrs_list[KVM_MAX_NR_USER_RETURN_MSRS]; EXPORT_SYMBOL(kvm_uret_msrs_list); struct kvm_user_return_msrs __percpu *user_return_msrs; -EXPORT_SYMBOL(user_return_msrs); u32 __read_mostly kvm_nr_uret_msrs; EXPORT_SYMBOL(kvm_nr_uret_msrs); @@ -160,6 +159,13 @@ void kvm_arch_hardware_disable(void) int __init vac_init(void) { + user_return_msrs = alloc_percpu(struct kvm_user_return_msrs); + if (!user_return_msrs) { + pr_err("failed to allocate percpu kvm_user_return_msrs\n"); + return -ENOMEM; + } + kvm_nr_uret_msrs = 0; + #ifdef CONFIG_KVM_INTEL if (cpu_has_vmx()) return vac_vmx_init(); @@ -172,6 +178,12 @@ int __init vac_init(void) } module_init(vac_init); +void __exit vac_exit(void) +{ + free_percpu(user_return_msrs); +} +module_exit(vac_exit); + /* * Handle a fault on a hardware virtualization (VMX or SVM) instruction. * diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 8217d9447bfda5..b5ce36f1446c65 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9244,14 +9244,6 @@ static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) return -ENOMEM; } - user_return_msrs = alloc_percpu(struct kvm_user_return_msrs); - if (!user_return_msrs) { - pr_err("failed to allocate percpu kvm_user_return_msrs\n"); - r = -ENOMEM; - goto out_free_x86_emulator_cache; - } - kvm_nr_uret_msrs = 0; - r = kvm_mmu_vendor_module_init(); if (r) goto out_free_percpu; @@ -9325,8 +9317,6 @@ static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) out_mmu_exit: kvm_mmu_vendor_module_exit(); out_free_percpu: - free_percpu(user_return_msrs); -out_free_x86_emulator_cache: kmem_cache_destroy(x86_emulator_cache); return r; } @@ -9364,7 +9354,6 @@ void kvm_x86_vendor_exit(void) #endif static_call(kvm_x86_hardware_unsetup)(); kvm_mmu_vendor_module_exit(); - free_percpu(user_return_msrs); kmem_cache_destroy(x86_emulator_cache); #ifdef CONFIG_KVM_XEN static_key_deferred_flush(&kvm_xen_enabled);