KVM: Allow internal errors reported to userspace to carry extra data
authorAvi Kivity <avi@redhat.com>
Wed, 4 Nov 2009 09:54:59 +0000 (11:54 +0200)
committerAvi Kivity <avi@redhat.com>
Thu, 3 Dec 2009 07:32:24 +0000 (09:32 +0200)
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.

Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/kvm/mmu.c
arch/x86/kvm/vmx.c
include/linux/kvm.h
virt/kvm/kvm_main.c

index a9024797b21f03ccf9b106ae48052b96501fce2a..4c3e5b2314cb1c8ca94ff13909af2061b702466d 100644 (file)
@@ -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();
index c9cc9596e1a6510a0f3d1219c9aa989613901299..c0e66dd58a47b26a3177da9f34998a38c78a1734 100644 (file)
@@ -3352,6 +3352,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;
                }
index ca62b8e056f9b0180167ddc1f89bd0d8d9cd3cd8..172639e94392c0dd5a4c671caa9a0b42be9308e0 100644 (file)
@@ -251,6 +251,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];
@@ -484,6 +487,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
 
index bd44fb48ac43bd1f860ba8797d982f39cacbb93b..f92ba138007ace7a7669492d9852055322e69b64 100644 (file)
@@ -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: