Skip to content

Commit 8f536b7

Browse files
Zhang YanfeiGleb Natapov
authored andcommitted
KVM: VMX: provide the vmclear function and a bitmap to support VMCLEAR in kdump
The vmclear function will be assigned to the callback function pointer when loading kvm-intel module. And the bitmap indicates whether we should do VMCLEAR operation in kdump. The bits in the bitmap are set/unset according to different conditions. 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 f23d1f4 commit 8f536b7

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

‎arch/x86/kvm/vmx.c‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <asm/i387.h>
4343
#include <asm/xcr.h>
4444
#include <asm/perf_event.h>
45+
#include <asm/kexec.h>
4546

4647
#include "trace.h"
4748

@@ -987,6 +988,46 @@ static void vmcs_load(struct vmcs *vmcs)
987988
vmcs, phys_addr);
988989
}
989990

991+
#ifdef CONFIG_KEXEC
992+
/*
993+
* This bitmap is used to indicate whether the vmclear
994+
* operation is enabled on all cpus. All disabled by
995+
* default.
996+
*/
997+
static cpumask_t crash_vmclear_enabled_bitmap = CPU_MASK_NONE;
998+
999+
static inline void crash_enable_local_vmclear(int cpu)
1000+
{
1001+
cpumask_set_cpu(cpu, &crash_vmclear_enabled_bitmap);
1002+
}
1003+
1004+
static inline void crash_disable_local_vmclear(int cpu)
1005+
{
1006+
cpumask_clear_cpu(cpu, &crash_vmclear_enabled_bitmap);
1007+
}
1008+
1009+
static inline int crash_local_vmclear_enabled(int cpu)
1010+
{
1011+
return cpumask_test_cpu(cpu, &crash_vmclear_enabled_bitmap);
1012+
}
1013+
1014+
static void crash_vmclear_local_loaded_vmcss(void)
1015+
{
1016+
int cpu = raw_smp_processor_id();
1017+
struct loaded_vmcs *v;
1018+
1019+
if (!crash_local_vmclear_enabled(cpu))
1020+
return;
1021+
1022+
list_for_each_entry(v, &per_cpu(loaded_vmcss_on_cpu, cpu),
1023+
loaded_vmcss_on_cpu_link)
1024+
vmcs_clear(v->vmcs);
1025+
}
1026+
#else
1027+
static inline void crash_enable_local_vmclear(int cpu) { }
1028+
static inline void crash_disable_local_vmclear(int cpu) { }
1029+
#endif /* CONFIG_KEXEC */
1030+
9901031
static void __loaded_vmcs_clear(void *arg)
9911032
{
9921033
struct loaded_vmcs *loaded_vmcs = arg;
@@ -996,6 +1037,7 @@ static void __loaded_vmcs_clear(void *arg)
9961037
return; /* vcpu migration can race with cpu offline */
9971038
if (per_cpu(current_vmcs, cpu) == loaded_vmcs->vmcs)
9981039
per_cpu(current_vmcs, cpu) = NULL;
1040+
crash_disable_local_vmclear(cpu);
9991041
list_del(&loaded_vmcs->loaded_vmcss_on_cpu_link);
10001042

10011043
/*
@@ -1007,6 +1049,7 @@ static void __loaded_vmcs_clear(void *arg)
10071049
smp_wmb();
10081050

10091051
loaded_vmcs_init(loaded_vmcs);
1052+
crash_enable_local_vmclear(cpu);
10101053
}
10111054

10121055
static void loaded_vmcs_clear(struct loaded_vmcs *loaded_vmcs)
@@ -1530,6 +1573,7 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
15301573

15311574
kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
15321575
local_irq_disable();
1576+
crash_disable_local_vmclear(cpu);
15331577

15341578
/*
15351579
* Read loaded_vmcs->cpu should be before fetching
@@ -1540,6 +1584,7 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
15401584

15411585
list_add(&vmx->loaded_vmcs->loaded_vmcss_on_cpu_link,
15421586
&per_cpu(loaded_vmcss_on_cpu, cpu));
1587+
crash_enable_local_vmclear(cpu);
15431588
local_irq_enable();
15441589

15451590
/*
@@ -2353,6 +2398,18 @@ static int hardware_enable(void *garbage)
23532398
return -EBUSY;
23542399

23552400
INIT_LIST_HEAD(&per_cpu(loaded_vmcss_on_cpu, cpu));
2401+
2402+
/*
2403+
* Now we can enable the vmclear operation in kdump
2404+
* since the loaded_vmcss_on_cpu list on this cpu
2405+
* has been initialized.
2406+
*
2407+
* Though the cpu is not in VMX operation now, there
2408+
* is no problem to enable the vmclear operation
2409+
* for the loaded_vmcss_on_cpu list is empty!
2410+
*/
2411+
crash_enable_local_vmclear(cpu);
2412+
23562413
rdmsrl(MSR_IA32_FEATURE_CONTROL, old);
23572414

23582415
test_bits = FEATURE_CONTROL_LOCKED;
@@ -7383,6 +7440,11 @@ static int __init vmx_init(void)
73837440
if (r)
73847441
goto out3;
73857442

7443+
#ifdef CONFIG_KEXEC
7444+
rcu_assign_pointer(crash_vmclear_loaded_vmcss,
7445+
crash_vmclear_local_loaded_vmcss);
7446+
#endif
7447+
73867448
vmx_disable_intercept_for_msr(MSR_FS_BASE, false);
73877449
vmx_disable_intercept_for_msr(MSR_GS_BASE, false);
73887450
vmx_disable_intercept_for_msr(MSR_KERNEL_GS_BASE, true);
@@ -7420,6 +7482,11 @@ static void __exit vmx_exit(void)
74207482
free_page((unsigned long)vmx_io_bitmap_b);
74217483
free_page((unsigned long)vmx_io_bitmap_a);
74227484

7485+
#ifdef CONFIG_KEXEC
7486+
rcu_assign_pointer(crash_vmclear_loaded_vmcss, NULL);
7487+
synchronize_rcu();
7488+
#endif
7489+
74237490
kvm_exit();
74247491
}
74257492

0 commit comments

Comments
 (0)