From 24f1b265951541fa8a10e87aec0cc59a7bbb6133 Mon Sep 17 00:00:00 2001 From: Venkatesh Srinivas Date: Wed, 2 Aug 2023 19:36:41 +0000 Subject: [PATCH] KVM: VAC: VMX: Move allocation of vmxon area into init Removes requirement for GFP_ATOMIC mallocation. Suggested-by: Sean Signed-off-by: Venkatesh Srinivas --- arch/x86/kvm/svm/vac.c | 4 ++++ arch/x86/kvm/vac.c | 7 +++++++ arch/x86/kvm/vmx/vac.c | 22 ++++++++++++++-------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/svm/vac.c b/arch/x86/kvm/svm/vac.c index f36b09a0be3127..1e2e9fe22d668d 100644 --- a/arch/x86/kvm/svm/vac.c +++ b/arch/x86/kvm/svm/vac.c @@ -178,3 +178,7 @@ int __init vac_svm_init(void) { return 0; } + +void vac_svm_exit(void) +{ +} diff --git a/arch/x86/kvm/vac.c b/arch/x86/kvm/vac.c index 1673aaa4337aa1..169ae38df1761b 100644 --- a/arch/x86/kvm/vac.c +++ b/arch/x86/kvm/vac.c @@ -180,8 +180,15 @@ int __init vac_init(void) } module_init(vac_init); +extern void vac_vmx_exit(void); +extern void vac_svm_exit(void); void __exit vac_exit(void) { + if (cpu_has_vmx()) { + vac_vmx_exit(); + } else if (cpu_has_svm(NULL)) { + vac_svm_exit(); + } free_percpu(user_return_msrs); } module_exit(vac_exit); diff --git a/arch/x86/kvm/vmx/vac.c b/arch/x86/kvm/vmx/vac.c index 7d848241478078..c704cbb9477af2 100644 --- a/arch/x86/kvm/vmx/vac.c +++ b/arch/x86/kvm/vmx/vac.c @@ -160,7 +160,7 @@ static int alloc_kvm_area(int cpu) struct page *pages; u32 vmx_msr_low, vmx_msr_high; - pages = __alloc_pages_node(cpu_to_node(cpu), GFP_ATOMIC | __GFP_ZERO, 0); + pages = __alloc_pages_node(cpu_to_node(cpu), GFP_KERNEL | __GFP_ZERO, 0); if (!pages) return -ENOMEM; vmcs = page_address(pages); @@ -204,11 +204,6 @@ int vmx_hardware_enable(void) intel_pt_handle_vmx(1); - r = alloc_kvm_area(cpu); - if (r) { - intel_pt_handle_vmx(0); - return r; - } phys_addr = __pa(vac_get_vmxarea(cpu)); r = kvm_cpu_vmxon(phys_addr); if (r) { @@ -237,8 +232,6 @@ void vmx_hardware_disable(void) hv_reset_evmcs(); intel_pt_handle_vmx(0); - - free_kvm_area(raw_smp_processor_id()); } EXPORT_SYMBOL(vmx_hardware_disable); @@ -249,6 +242,10 @@ int __init vac_vmx_init(void) { int cpu; + for_each_possible_cpu(cpu) { + alloc_kvm_area(cpu); + } + for_each_possible_cpu(cpu) { INIT_LIST_HEAD(&per_cpu(loaded_vmcss_on_cpu, cpu)); //pi_init_cpu(cpu); @@ -260,6 +257,15 @@ int __init vac_vmx_init(void) return 0; } +void vac_vmx_exit(void) +{ + int cpu; + + for_each_possible_cpu(cpu) { + free_kvm_area(cpu); + } +} + int allocate_vpid(void) { int vpid;