Skip to content

Commit

Permalink
KVM: VAC: VMX: Move allocation of vmxon area into init
Browse files Browse the repository at this point in the history
Removes requirement for GFP_ATOMIC mallocation.

Suggested-by: Sean <[email protected]>
Signed-off-by: Venkatesh Srinivas <[email protected]>
  • Loading branch information
vsrinivas committed Aug 2, 2023
1 parent c4b15ef commit 24f1b26
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions arch/x86/kvm/svm/vac.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,7 @@ int __init vac_svm_init(void)
{
return 0;
}

void vac_svm_exit(void)
{
}
7 changes: 7 additions & 0 deletions arch/x86/kvm/vac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 14 additions & 8 deletions arch/x86/kvm/vmx/vac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 24f1b26

Please sign in to comment.