Skip to content

Commit 0f99022

Browse files
Haiwei Libonzini
authored andcommitted
KVM: Check the allocation of pv cpu mask
check the allocation of per-cpu __pv_cpu_mask. Initialize ops only when successful. Signed-off-by: Haiwei Li <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 43fea4e commit 0f99022

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

arch/x86/kernel/kvm.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,6 @@ static void __init kvm_guest_init(void)
654654
}
655655

656656
if (pv_tlb_flush_supported()) {
657-
pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others;
658657
pv_ops.mmu.tlb_remove_table = tlb_remove_table;
659658
pr_info("KVM setup pv remote TLB flush\n");
660659
}
@@ -767,6 +766,14 @@ static __init int activate_jump_labels(void)
767766
}
768767
arch_initcall(activate_jump_labels);
769768

769+
static void kvm_free_pv_cpu_mask(void)
770+
{
771+
unsigned int cpu;
772+
773+
for_each_possible_cpu(cpu)
774+
free_cpumask_var(per_cpu(__pv_cpu_mask, cpu));
775+
}
776+
770777
static __init int kvm_alloc_cpumask(void)
771778
{
772779
int cpu;
@@ -785,11 +792,20 @@ static __init int kvm_alloc_cpumask(void)
785792

786793
if (alloc)
787794
for_each_possible_cpu(cpu) {
788-
zalloc_cpumask_var_node(per_cpu_ptr(&__pv_cpu_mask, cpu),
789-
GFP_KERNEL, cpu_to_node(cpu));
795+
if (!zalloc_cpumask_var_node(
796+
per_cpu_ptr(&__pv_cpu_mask, cpu),
797+
GFP_KERNEL, cpu_to_node(cpu))) {
798+
goto zalloc_cpumask_fail;
799+
}
790800
}
791801

802+
apic->send_IPI_mask_allbutself = kvm_send_ipi_mask_allbutself;
803+
pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others;
792804
return 0;
805+
806+
zalloc_cpumask_fail:
807+
kvm_free_pv_cpu_mask();
808+
return -ENOMEM;
793809
}
794810
arch_initcall(kvm_alloc_cpumask);
795811

0 commit comments

Comments
 (0)