Skip to contentSkip to conversation

kvm: log available guest crash parameters

PATCH Superseded Denis V. Lunev 2 participants 4 messages Jan 31, 2017 – Feb 1, 2017

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: log available guest crash parameters

From: Anton Nefedov <[email protected]>

Windows reports BSOD parameters through Hyper-V crash MSRs. This information is very useful for initial crash analysis and thus it would be nice to see it in the QEMU log file. There is suitable log mask for the purpose.

Linux guest does not provide this information, but still it would be nice to log that we have crashed.

CC Paolo Bonzini <[email protected]>
CC Marcelo Tosatti <[email protected]>
CC Richard Henderson <[email protected]>
CC Eduardo Habkost <[email protected]>
---
 hw/misc/pvpanic.c    |  1 +
 include/sysemu/kvm.h |  2 ++
 kvm-all.c            |  1 +
 stubs/Makefile.objs  |  1 +
 stubs/kvm-crash.c    |  8 ++++++++
 target/i386/kvm.c    | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 64 insertions(+)
 create mode 100644 stubs/kvm-crash.c
hw/misc/pvpanic.c +1 -0
index 0ac1e6a..221aa4e 100644
@@ -42,6 +42,7 @@ static void handle_event(int event)
     }
 
     if (event & PVPANIC_PANICKED) {
+        qemu_log_mask(LOG_GUEST_ERROR, "Guest panicked\n");
         qemu_system_guest_panicked();
         return;
     }
include/sysemu/kvm.h +2 -0
index 3045ee7..70cab9d 100644
@@ -527,4 +527,6 @@ int kvm_set_one_reg(CPUState *cs, uint64_t id, void *source);
  */
 int kvm_get_one_reg(CPUState *cs, uint64_t id, void *target);
 int kvm_get_max_memslots(void);
+
+void kvm_arch_log_crash(CPUState *cpu);
 #endif
kvm-all.c +1 -0
index 330219e..5f83389 100644
@@ -2000,6 +2000,7 @@ int kvm_cpu_exec(CPUState *cpu)
                 ret = EXCP_INTERRUPT;
                 break;
             case KVM_SYSTEM_EVENT_CRASH:
+                kvm_arch_log_crash(cpu);
                 qemu_mutex_lock_iothread();
                 qemu_system_guest_panicked();
                 qemu_mutex_unlock_iothread();
stubs/Makefile.objs +1 -0
index a187295..3b1632a 100644
@@ -35,3 +35,4 @@ stub-obj-y += qmp_pc_dimm_device_list.o
 stub-obj-y += target-monitor-defs.o
 stub-obj-y += target-get-monitor-def.o
 stub-obj-y += pc_madt_cpu_entry.o
+stub-obj-y += kvm-crash.o
stubs/kvm-crash.c new file +8 -0
new file mode 100644
index 0000000..36ab7f0
@@ -0,0 +1,8 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "sysemu/kvm.h"
+
+void kvm_arch_log_crash(CPUState *cs)
+{
+    return;
+}
target/i386/kvm.c +51 -0

63 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw
Quoted 9 lines · Denis V. Lunev

From: Anton Nefedov <[email protected]>

Windows reports BSOD parameters through Hyper-V crash MSRs. This information is very useful for initial crash analysis and thus it would be nice to see it in the QEMU log file. There is suitable log mask for the purpose.

Linux guest does not provide this information, but still it would be nice to log that we have crashed.

We tell libvirt that the guest crashed through a QMP event, so I think this should be passed as arguments of the QMP event. You could add:

- a QAPI type GuestPanicInformation

{'union': 'GuestPanicInformation',
'data': { 'hyper-v': 'GuestPanicInformationHyperV' } }

{'struct': 'GuestPanicInformationHyperV',
'data': { 'arg1': 'uint64',

           'arg2': 'uint64',
           'arg3': 'uint64',
           'arg4': 'uint64' } }

- a QOM property on the CPU object, crash-information, whose getter returns an error unless cpu->crash_occurred = true

- an optional GuestPanicInformation argument to the GUEST_PANICKED event, which is passed if the QOM property returns a non-error value

Thanks,

Paolo

Quoted 144 lines
CC Paolo Bonzini <[email protected]>
CC Marcelo Tosatti <[email protected]>
CC Richard Henderson <[email protected]>
CC Eduardo Habkost <[email protected]>
---
 hw/misc/pvpanic.c    |  1 +
 include/sysemu/kvm.h |  2 ++
 kvm-all.c            |  1 +
 stubs/Makefile.objs  |  1 +
 stubs/kvm-crash.c    |  8 ++++++++
 target/i386/kvm.c    | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 64 insertions(+)
 create mode 100644 stubs/kvm-crash.c
hw/misc/pvpanic.c +1 -0
index 0ac1e6a..221aa4e 100644
@@ -42,6 +42,7 @@ static void handle_event(int event)
     }
 
     if (event & PVPANIC_PANICKED) {
+        qemu_log_mask(LOG_GUEST_ERROR, "Guest panicked\n");
         qemu_system_guest_panicked();
         return;
     }
include/sysemu/kvm.h +2 -0
index 3045ee7..70cab9d 100644
@@ -527,4 +527,6 @@ int kvm_set_one_reg(CPUState *cs, uint64_t id, void *source);
  */
 int kvm_get_one_reg(CPUState *cs, uint64_t id, void *target);
 int kvm_get_max_memslots(void);
+
+void kvm_arch_log_crash(CPUState *cpu);
 #endif
kvm-all.c +1 -0
index 330219e..5f83389 100644
@@ -2000,6 +2000,7 @@ int kvm_cpu_exec(CPUState *cpu)
                 ret = EXCP_INTERRUPT;
                 break;
             case KVM_SYSTEM_EVENT_CRASH:
+                kvm_arch_log_crash(cpu);
                 qemu_mutex_lock_iothread();
                 qemu_system_guest_panicked();
                 qemu_mutex_unlock_iothread();
stubs/Makefile.objs +1 -0
index a187295..3b1632a 100644
@@ -35,3 +35,4 @@ stub-obj-y += qmp_pc_dimm_device_list.o
 stub-obj-y += target-monitor-defs.o
 stub-obj-y += target-get-monitor-def.o
 stub-obj-y += pc_madt_cpu_entry.o
+stub-obj-y += kvm-crash.o
stubs/kvm-crash.c new file +8 -0
new file mode 100644
index 0000000..36ab7f0
@@ -0,0 +1,8 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "sysemu/kvm.h"
+
+void kvm_arch_log_crash(CPUState *cs)
+{
+    return;
+}
target/i386/kvm.c +51 -0
index 3b52821..899a83c 100644
@@ -2020,6 +2020,36 @@ static int kvm_get_sregs(X86CPU *cpu)
     return 0;
 }
 
+static int kvm_read_msr_hv_crash(X86CPU *cpu, uint64_t *buf)
+{
+    int i, ret;
+    struct {
+        struct kvm_msrs info;
+        struct kvm_msr_entry entries[HV_X64_MSR_CRASH_PARAMS];
+    } msr_data;
+
+    if (!has_msr_hv_crash) {
+        return -ENOSYS;
+    }
+
+    for (i = 0; i < HV_X64_MSR_CRASH_PARAMS; i++) {
+        msr_data.entries[i].index = HV_X64_MSR_CRASH_P0 + i;
+    }
+    msr_data.info.nmsrs = HV_X64_MSR_CRASH_PARAMS;
+
+    ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, &msr_data);
+    if (ret < 0) {
+        return ret;
+    }
+
+    for (i = 0; i < ret; i++) {
+        const struct kvm_msr_entry *msr = msr_data.entries + i;
+        buf[msr->index - HV_X64_MSR_CRASH_P0] = msr->data;
+    }
+
+    return 0;
+}
+
 static int kvm_get_msrs(X86CPU *cpu)
 {
     CPUX86State *env = &cpu->env;
@@ -2767,6 +2797,27 @@ int kvm_arch_get_registers(CPUState *cs)
     return ret;
 }
 
+void kvm_arch_log_crash(CPUState *cs)
+{
+    uint64_t msrs[HV_X64_MSR_CRASH_PARAMS];
+    int ret;
+    X86CPU *cpu = X86_CPU(cs);
+
+    qemu_log_mask(LOG_GUEST_ERROR, "Guest crashed\n");
+    if (!has_msr_hv_crash) {
+        return;
+    }
+
+    ret = kvm_read_msr_hv_crash(cpu, msrs);
+    if (ret < 0) {
+        qemu_log_mask(LOG_GUEST_ERROR, "Failed to get HV crash parameters\n");
+        return;
+    }
+    qemu_log_mask(LOG_GUEST_ERROR, "HV crash parameters: (%#"PRIx64
+                  " %#"PRIx64" %#"PRIx64" %#"PRIx64" %#"PRIx64")\n",
+                  msrs[0], msrs[1], msrs[2], msrs[3], msrs[4]);
+}
+
 void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run)
 {
     X86CPU *x86_cpu = X86_CPU(cpu);
#3 lore raw
In reply to Denis V. Lunev
Quoted 26 lines · Denis V. Lunev
Quoted 25 lines · Paolo Bonzini
Quoted 9 lines · Denis V. Lunev

From: Anton Nefedov <[email protected]>

Windows reports BSOD parameters through Hyper-V crash MSRs. This information is very useful for initial crash analysis and thus it would be nice to see it in the QEMU log file. There is suitable log mask for the purpose.

Linux guest does not provide this information, but still it would be nice to log that we have crashed.

We tell libvirt that the guest crashed through a QMP event, so I think this should be passed as arguments of the QMP event. You could add:

- a QAPI type GuestPanicInformation

{'union': 'GuestPanicInformation',
'data': { 'hyper-v': 'GuestPanicInformationHyperV' } }

{'struct': 'GuestPanicInformationHyperV',
'data': { 'arg1': 'uint64',

           'arg2': 'uint64',
           'arg3': 'uint64',
           'arg4': 'uint64' } }
Quoted 7 lines
Quoted 5 lines

- a QOM property on the CPU object, crash-information, whose getter returns an error unless cpu->crash_occurred = true

- an optional GuestPanicInformation argument to the GUEST_PANICKED event, which is passed if the QOM property returns a non-error value

I like the idea of the event but also want to have the log message. LOG_GUEST_ERROR level fits well to the idea at my opinion.

Sure, you can do that anyway. It's just that a log message would go unnoticed, while QMP events can be passed up to management. Seeing bugcheck information in the GUI can be cool (e.g. to find immediately if you have an INACCESSIBLE_BOOT_DEVICE bugcheck). :)

Paolo

#2 lore raw
In reply to Paolo Bonzini
Quoted 25 lines · Paolo Bonzini
Quoted 9 lines · Denis V. Lunev

From: Anton Nefedov <[email protected]>

Windows reports BSOD parameters through Hyper-V crash MSRs. This information is very useful for initial crash analysis and thus it would be nice to see it in the QEMU log file. There is suitable log mask for the purpose.

Linux guest does not provide this information, but still it would be nice to log that we have crashed.

We tell libvirt that the guest crashed through a QMP event, so I think this should be passed as arguments of the QMP event. You could add:

- a QAPI type GuestPanicInformation

{'union': 'GuestPanicInformation',
'data': { 'hyper-v': 'GuestPanicInformationHyperV' } }

{'struct': 'GuestPanicInformationHyperV',
'data': { 'arg1': 'uint64',

           'arg2': 'uint64',
           'arg3': 'uint64',
           'arg4': 'uint64' } }
Quoted 5 lines

- a QOM property on the CPU object, crash-information, whose getter returns an error unless cpu->crash_occurred = true

- an optional GuestPanicInformation argument to the GUEST_PANICKED event, which is passed if the QOM property returns a non-error value

I like the idea of the event but also want to have the log message. LOG_GUEST_ERROR level fits well to the idea at my opinion.

Thank you for the idea :)

Den