Skip to content

Commit dbef280

Browse files
vittyvkbonzini
authored andcommitted
KVM: VMX: fix crash cleanup when KVM wasn't used
If KVM wasn't used at all before we crash the cleanup procedure fails with BUG: unable to handle page fault for address: ffffffffffffffc8 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 23215067 P4D 23215067 PUD 23217067 PMD 0 Oops: 0000 [#8] SMP PTI CPU: 0 PID: 3542 Comm: bash Kdump: loaded Tainted: G D 5.6.0-rc2+ #823 RIP: 0010:crash_vmclear_local_loaded_vmcss.cold+0x19/0x51 [kvm_intel] The root cause is that loaded_vmcss_on_cpu list is not yet initialized, we initialize it in hardware_enable() but this only happens when we start a VM. Previously, we used to have a bitmap with enabled CPUs and that was preventing [masking] the issue. Initialized loaded_vmcss_on_cpu list earlier, right before we assign crash_vmclear_loaded_vmcss pointer. blocked_vcpu_on_cpu list and blocked_vcpu_on_cpu_lock are moved altogether for consistency. Fixes: 31603d4 ("KVM: VMX: Always VMCLEAR in-use VMCSes during crash with kexec support") Signed-off-by: Vitaly Kuznetsov <[email protected]> Message-Id: <[email protected]> Reviewed-by: Sean Christopherson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 4064a4c commit dbef280

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,10 +2261,6 @@ static int hardware_enable(void)
22612261
!hv_get_vp_assist_page(cpu))
22622262
return -EFAULT;
22632263

2264-
INIT_LIST_HEAD(&per_cpu(loaded_vmcss_on_cpu, cpu));
2265-
INIT_LIST_HEAD(&per_cpu(blocked_vcpu_on_cpu, cpu));
2266-
spin_lock_init(&per_cpu(blocked_vcpu_on_cpu_lock, cpu));
2267-
22682264
r = kvm_cpu_vmxon(phys_addr);
22692265
if (r)
22702266
return r;
@@ -8044,7 +8040,7 @@ module_exit(vmx_exit);
80448040

80458041
static int __init vmx_init(void)
80468042
{
8047-
int r;
8043+
int r, cpu;
80488044

80498045
#if IS_ENABLED(CONFIG_HYPERV)
80508046
/*
@@ -8098,6 +8094,12 @@ static int __init vmx_init(void)
80988094
return r;
80998095
}
81008096

8097+
for_each_possible_cpu(cpu) {
8098+
INIT_LIST_HEAD(&per_cpu(loaded_vmcss_on_cpu, cpu));
8099+
INIT_LIST_HEAD(&per_cpu(blocked_vcpu_on_cpu, cpu));
8100+
spin_lock_init(&per_cpu(blocked_vcpu_on_cpu_lock, cpu));
8101+
}
8102+
81018103
#ifdef CONFIG_KEXEC_CORE
81028104
rcu_assign_pointer(crash_vmclear_loaded_vmcss,
81038105
crash_vmclear_local_loaded_vmcss);

0 commit comments

Comments
 (0)