KVM: Add VT-x machine check support
PATCH 1/1 KVM: Add VT-x machine check support
From: Andi Kleen <[email protected]>
VT-x needs an explicit MC vector intercept to handle machine checks in the hyper visor.
It also has a special option to catch machine checks that happen during VT entry.
Do these interceptions and forward them to the Linux machine check handler. Make it always look like user space is interrupted because the machine check handler treats kernel/user space differently.
Thanks to Jiang Yunhong for help and testing.
v3: Rebased on kvm.git
v2: Handle machine checks still in interrupt off context to avoid problems on preemptible kernels.
--- arch/x86/include/asm/kvm_host.h | 2 + arch/x86/include/asm/vmx.h | 1 arch/x86/kernel/cpu/mcheck/mce_64.c | 1 arch/x86/kvm/vmx.c | 41 +++++++++++++++++++++++++++++++++--- 4 files changed, 42 insertions(+), 3 deletions(-)
arch/x86/include/asm/vmx.h +1 -0
@@ -247,6 +247,7 @@ enum vmcs_field {#define EXIT_REASON_MSR_READ 31#define EXIT_REASON_MSR_WRITE 32#define EXIT_REASON_MWAIT_INSTRUCTION 36 +#define EXIT_REASON_MCE_DURING_VMENTRY 41#define EXIT_REASON_TPR_BELOW_THRESHOLD 43#define EXIT_REASON_APIC_ACCESS 44#define EXIT_REASON_EPT_VIOLATION 48
arch/x86/kvm/vmx.c +38 -3
89 lines not on this page · raw message
arch/x86/include/asm/kvm_host.h +2 -0
@@ -382,6 +382,8 @@ struct kvm_vcpu_arch {u64 mcg_status;u64 mcg_ctl;u64 *mce_banks; + +u32 exit_reason; };struct kvm_mem_alias {
arch/x86/kernel/cpu/mcheck/mce_64.c +1 -0
@@ -420,6 +420,7 @@ void do_machine_check(struct pt_regs * r out2:atomic_dec (&mce_entry); } +EXPORT_SYMBOL_GPL (do_machine_check);#ifdef CONFIG_X86_MCE_INTEL /***
Quoted 4 lines · Huang Ying
From: Andi Kleen <[email protected]>
VT-x needs an explicit MC vector intercept to handle machine checks in the hyper visor.
Quoted 10 lines
It also has a special option to catch machine checks that happen during VT entry.
Do these interceptions and forward them to the Linux machine check handler. Make it always look like user space is interrupted because the machine check handler treats kernel/user space differently.
Thanks to Jiang Yunhong for help and testing.
Noticed an additional problem. See below.
arch/x86/kvm/vmx.c static int handle_exception(struct kvm_v · line 2647
Quoted 12 lines
static int
handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run){arch/x86/kvm/vmx.c +4
-0struct vcpu_vmx *vmx =to_vmx (vcpu);@@ -2616,6 +2640,10 @@ static int handle_exception(struct kvm_v vect_info = vmx->idt_vectoring_info; intr_info =vmcs_read32 (VM_EXIT_INTR_INFO ); + ex_no = intr_info &INTR_INFO_VECTOR_MASK ; +if (ex_no ==MC_VECTOR ) +return handle_machine_check (vcpu, kvm_run); +
It isn't sufficient to check the vector number; you also need to check the interrupt type. See for example is_page_fault() and is_no_device().
I suggest you add an is_machine_check() along similar lines. Later we can collapse all those functions to use a single helper.
arch/x86/include/asm/kvm_host.h struct kvm_vcpu_arch { · line 388
Quoted 10 lines
arch/x86/include/asm/kvm_host.h +2
-0@@ -382,6 +382,8 @@ struct kvm_vcpu_arch {u64 mcg_status;u64 mcg_ctl;u64 *mce_banks; + +u32 exit_reason; };
Please move this into struct vcpu_vmx.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 35 lines · Avi Kivity
Quoted 5 lines · Huang Ying
From: Andi Kleen <[email protected]>
VT-x needs an explicit MC vector intercept to handle machine checks in the hyper visor.
Quoted 10 lines
It also has a special option to catch machine checks that happen during VT entry.
Do these interceptions and forward them to the Linux machine check handler. Make it always look like user space is interrupted because the machine check handler treats kernel/user space differently.
Thanks to Jiang Yunhong for help and testing.
Noticed an additional problem. See below.
arch/x86/kvm/vmx.c static int handle_exception(struct kvm_v · line 2647
Quoted 12 lines
static int
handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run){arch/x86/kvm/vmx.c +4
-0struct vcpu_vmx *vmx =to_vmx (vcpu);@@ -2616,6 +2640,10 @@ static int handle_exception(struct kvm_v vect_info = vmx->idt_vectoring_info; intr_info =vmcs_read32 (VM_EXIT_INTR_INFO ); + ex_no = intr_info &INTR_INFO_VECTOR_MASK ; +if (ex_no ==MC_VECTOR ) +return handle_machine_check (vcpu, kvm_run); +It isn't sufficient to check the vector number; you also need to check the interrupt type. See for example
is_page_fault()andis_no_device().
Quoted 2 lines
I suggest you add an
is_machine_check()along similar lines. Later we can collapse all those functions to use a single helper.
OK. I will do this.
Quoted 4 lines
Quoted 4 lines
arch/x86/include/asm/kvm_host.h +0
-0@@ -382,6 +382,8 @@ struct kvm_vcpu_arch {u64 mcg_status;
Quoted 8 lines
arch/x86/include/asm/kvm_host.h struct kvm_vcpu_arch { · line 388
Quoted 6 lines
arch/x86/include/asm/kvm_host.h +2
-0u64 mcg_ctl;u64 *mce_banks; + +u32 exit_reason; };Please move this into struct
vcpu_vmx.
OK.
Best Regards,
Huang Ying