Skip to content

Commit f23d1f4

Browse files
Zhang YanfeiGleb Natapov
authored andcommitted
x86/kexec: VMCLEAR VMCSs loaded on all cpus if necessary
This patch provides a way to VMCLEAR VMCSs related to guests on all cpus before executing the VMXOFF when doing kdump. This is used to ensure the VMCSs in the vmcore updated and non-corrupted. Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> Acked-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Gleb Natapov <gleb@redhat.com>
1 parent c219346 commit f23d1f4

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎arch/x86/include/asm/kexec.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ struct kimage_arch {
163163
};
164164
#endif
165165

166+
extern void (*crash_vmclear_loaded_vmcss)(void);
167+
166168
#endif /* __ASSEMBLY__ */
167169

168170
#endif /* _ASM_X86_KEXEC_H */

‎arch/x86/kernel/crash.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/delay.h>
1717
#include <linux/elf.h>
1818
#include <linux/elfcore.h>
19+
#include <linux/module.h>
1920

2021
#include <asm/processor.h>
2122
#include <asm/hardirq.h>
@@ -30,6 +31,27 @@
3031

3132
int in_crash_kexec;
3233

34+
/*
35+
* This is used to VMCLEAR all VMCSs loaded on the
36+
* processor. And when loading kvm_intel module, the
37+
* callback function pointer will be assigned.
38+
*
39+
* protected by rcu.
40+
*/
41+
void (*crash_vmclear_loaded_vmcss)(void) = NULL;
42+
EXPORT_SYMBOL_GPL(crash_vmclear_loaded_vmcss);
43+
44+
static inline void cpu_crash_vmclear_loaded_vmcss(void)
45+
{
46+
void (*do_vmclear_operation)(void) = NULL;
47+
48+
rcu_read_lock();
49+
do_vmclear_operation = rcu_dereference(crash_vmclear_loaded_vmcss);
50+
if (do_vmclear_operation)
51+
do_vmclear_operation();
52+
rcu_read_unlock();
53+
}
54+
3355
#if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
3456

3557
static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
@@ -46,6 +68,11 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
4668
#endif
4769
crash_save_cpu(regs, cpu);
4870

71+
/*
72+
* VMCLEAR VMCSs loaded on all cpus if needed.
73+
*/
74+
cpu_crash_vmclear_loaded_vmcss();
75+
4976
/* Disable VMX or SVM if needed.
5077
*
5178
* We need to disable virtualization on all CPUs.
@@ -88,6 +115,11 @@ void native_machine_crash_shutdown(struct pt_regs *regs)
88115

89116
kdump_nmi_shootdown_cpus();
90117

118+
/*
119+
* VMCLEAR VMCSs loaded on this cpu if needed.
120+
*/
121+
cpu_crash_vmclear_loaded_vmcss();
122+
91123
/* Booting kdump kernel with VMX or SVM enabled won't work,
92124
* because (among other limitations) we can't disable paging
93125
* with the virt flags.

0 commit comments

Comments
 (0)