Improve reporting of simultaneous exception errors
cover Improve reporting of simultaneous exception errors
Currently if we hit an error processing simultaneous exceptions we mumble something in dmesg and continue. AFAIK this situation always deteriorates, so attempt to report it to userspace to give us a chance to debug it.
Avi Kivity (2):
KVM: Allow internal errors reported to userspace to carry extra data
KVM: VMX: Report unexpected simultaneous exceptions as internal
errors
arch/x86/kvm/mmu.c | 1 + arch/x86/kvm/vmx.c | 12 +++++++++--- include/linux/kvm.h | 5 +++++ virt/kvm/kvm_main.c | 1 + 4 files changed, 16 insertions(+), 3 deletions(-)
PATCH 1/2 KVM: Allow internal errors reported to userspace to carry extra data
Usually userspace will freeze the guest so we can inspect it, but some internal state is not available. Add extra data to internal error reporting so we can expose it to the debugger. Extra data is specific to the suberror.
--- arch/x86/kvm/mmu.c | 1 + arch/x86/kvm/vmx.c | 1 + include/linux/kvm.h | 4 ++++ virt/kvm/kvm_main.c | 1 + 4 files changed, 7 insertions(+), 0 deletions(-)
arch/x86/kvm/mmu.c +1 -0
@@ -2800,6 +2800,7 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u32 error_code)case EMULATE_FAIL : vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; vcpu->run->internal.suberror =KVM_INTERNAL_ERROR_EMULATION ; + vcpu->run->internal.ndata =0 ;return 0 ;default :BUG ();
arch/x86/kvm/vmx.c +1 -0
@@ -3346,6 +3346,7 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)kvm_report_emulation_failure (vcpu,"emulation failure" ); vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; vcpu->run->internal.suberror =KVM_INTERNAL_ERROR_EMULATION ; + vcpu->run->internal.ndata =0 ; ret =0 ; goto out; }
include/linux/kvm.h +4 -0
@@ -187,6 +187,9 @@ struct kvm_run { } dcr;struct {__u32 suberror; +/* Available with KVM_CAP_INTERNAL_ERROR_DATA: */ +__u32 ndata; +__u64 data[16 ]; } internal;/* Fix the size of the union. */ char padding[256 ];
@@ -440,6 +443,7 @@ struct kvm_ioeventfd {#define KVM_CAP_XEN_HVM 38#endif #define KVM_CAP_ADJUST_CLOCK 39 +#define KVM_CAP_INTERNAL_ERROR_DATA 40#ifdef KVM_CAP_IRQ_ROUTING
virt/kvm/kvm_main.c +1 -0
@@ -1653,6 +1653,7 @@ static long kvm_dev_ioctl_check_extension_generic(long arg)#ifdef CONFIG_KVM_APIC_ARCHITECTURE case KVM_CAP_SET_BOOT_CPU_ID :#endif +case KVM_CAP_INTERNAL_ERROR_DATA :return 1 ;#ifdef CONFIG_HAVE_KVM_IRQCHIP case KVM_CAP_IRQ_ROUTING :
Signature · 1 line
1.6.5.2
PATCH 2/2 KVM: VMX: Report unexpected simultaneous exceptions as internal errors
In reply to Avi KivityThese happen when we trap an exception when another exception is being delivered; we only expect these with MCEs and page faults. If something unexpected happens, things probably went south and we're better off reporting an internal error and freezing.
--- arch/x86/kvm/vmx.c | 11 ++++++++--- include/linux/kvm.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)
arch/x86/kvm/vmx.c +8 -3
@@ -2738,9 +2738,14 @@ static int handle_exception(struct kvm_vcpu *vcpu)return handle_machine_check (vcpu);if ((vect_info &VECTORING_INFO_VALID_MASK ) && - !is_page_fault (intr_info)) -printk (KERN_ERR "%s: unexpected, vectoring info 0x%x " -"intr info 0x%x\n" , __func__, vect_info, intr_info); + !is_page_fault (intr_info)) { + vcpu->run->exit_reason =KVM_EXIT_INTERNAL_ERROR ; + vcpu->run->internal.suberror =KVM_INTERNAL_ERROR_SIMUL_EX ; + vcpu->run->internal.ndata =2 ; + vcpu->run->internal.data[0 ] = vect_info; + vcpu->run->internal.data[1 ] = intr_info; +return 0 ; + }if ((intr_info &INTR_INFO_INTR_TYPE_MASK ) ==INTR_TYPE_NMI_INTR )return 1 ;/* already handled by vmx_vcpu_run() */
include/linux/kvm.h +1 -0
@@ -99,6 +99,7 @@ struct kvm_pit_config {/* For KVM_EXIT_INTERNAL_ERROR */ #define KVM_INTERNAL_ERROR_EMULATION 1 +#define KVM_INTERNAL_ERROR_SIMUL_EX 2/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */ struct kvm_run {
Signature · 1 line
1.6.5.2