Skip to contentSkip to conversation

HyperV equivalent of pvpanic driver

PATCH In review Denis V. Lunev 3 participants 22 messages Jul 3, 2015 – Sep 2, 2015

Subsystems (5)
Documentation x86 KVM KVM x86 +1 more subsystems
lore
Share & tools
lore
#0 lore raw

v6 cover HyperV equivalent of pvpanic driver

Windows 2012 guests can notify hypervisor about occurred guest crash (Windows bugcheck(BSOD)) by writing specific Hyper-V msrs. This patch does handling of this MSR's by KVM and sending notification to user space that allows to gather Windows guest crash dump by QEMU/LIBVIRT.

The idea is to provide functionality equal to pvpanic device without QEMU guest agent for Windows.

The idea is borrowed from Linux HyperV bus driver and validated against Windows 2k12.

Changes from v5:
* added hyperv crash msrs into supported/emulated list
* qemu: reset CPUState::crash_occurred at cpu reset
* qemu: userspace checks kernel support of hyperv crash msrs by kvm_get_supported_msrs

Changes from v4:
* fixed typo in email of Andreas Färber <[email protected]> my vim strangely behaves on lines with extended Deutch chars

Changes from v3:
* remove unused HV_X64_MSR_CRASH_CTL_NOTIFY
* added documentation section about KVM_SYSTEM_EVENT_CRASH
* allow only supported values inside crash ctl msr
* qemu: split patch into generic crash handling patches and hyperv specific
* qemu: skip migration of crash ctl msr value

Changes from v2:
* forbid modification crash ctl msr by guest
* qemu_system_guest_panicked usage in pvpanic and s390x
* hyper-v crash handler move from generic kvm to i386
* hyper-v crash handler: skip fetching crash msrs just mark crash occurred
* sync with linux-next 20150629
* patch 11 squashed to patch 10
* patch 9 squashed to patch 7

Changes from v1:
* hyperv code move to hyperv.c
* added read handlers of crash data msrs
* added per vm and per cpu hyperv context structures
* added saving crash msrs inside qemu cpu state
* added qemu fetch and update of crash msrs
* added qemu crash msrs store in cpu state and it's migration

#1 lore raw

PATCH v6 1/12 kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file

From: Andrey Smetanin <[email protected]>

This patch introduce Hyper-V related source code file - hyperv.c and per vm and per vcpu hyperv context structures.
All Hyper-V MSR's and hypercall code moved into hyperv.c. All Hyper-V kvm/vcpu fields moved into appropriate hyperv context structures. Copyrights and authors information copied from x86.c to hyperv.c.

---
 arch/x86/include/asm/kvm_host.h |  20 ++-
 arch/x86/kvm/Makefile           |   4 +-
 arch/x86/kvm/hyperv.c           | 307 ++++++++++++++++++++++++++++++++++++++++
 arch/x86/kvm/hyperv.h           |  32 +++++
 arch/x86/kvm/lapic.h            |   2 +-
 arch/x86/kvm/x86.c              | 265 +---------------------------------
 arch/x86/kvm/x86.h              |   5 +
 7 files changed, 366 insertions(+), 269 deletions(-)
 create mode 100644 arch/x86/kvm/hyperv.c
 create mode 100644 arch/x86/kvm/hyperv.h
arch/x86/include/asm/kvm_host.h +14 -6
index c7fa57b..78616aa 100644
@@ -358,6 +358,11 @@ struct kvm_mtrr {
 	struct list_head head;
 };
 
+/* Hyper-V per vcpu emulation context */
+struct kvm_vcpu_hv {
+	u64 hv_vapic;
+};
+
 struct kvm_vcpu_arch {
 	/*
 	 * rip and regs accesses must go through
@@ -514,8 +519,7 @@ struct kvm_vcpu_arch {
 	/* used for guest single stepping over the given code position */
 	unsigned long singlestep_rip;
 
-	/* fields used by HYPER-V emulation */
-	u64 hv_vapic;
+	struct kvm_vcpu_hv hyperv;
 
 	cpumask_var_t wbinvd_dirty_mask;
 
@@ -586,6 +590,13 @@ struct kvm_apic_map {
 	struct kvm_lapic *logical_map[16][16];
 };
 
+/* Hyper-V emulation context */
+struct kvm_hv {
+	u64 hv_guest_os_id;
+	u64 hv_hypercall;
+	u64 hv_tsc_page;
+};
+
 struct kvm_arch {
 	unsigned int n_used_mmu_pages;
 	unsigned int n_requested_mmu_pages;
@@ -643,10 +654,7 @@ struct kvm_arch {
 	/* reads protected by irq_srcu, writes by irq_lock */
 	struct hlist_head mask_notifier_list;
 
-	/* fields used by HYPER-V emulation */
-	u64 hv_guest_os_id;
-	u64 hv_hypercall;
-	u64 hv_tsc_page;
+	struct kvm_hv hyperv;
 
 	#ifdef CONFIG_KVM_MMU_AUDIT
 	int audit_point;
arch/x86/kvm/Makefile +3 -1
index 67d215c..a1ff508 100644
@@ -12,7 +12,9 @@ kvm-y			+= $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o \
 kvm-$(CONFIG_KVM_ASYNC_PF)	+= $(KVM)/async_pf.o
 
 kvm-y			+= x86.o mmu.o emulate.o i8259.o irq.o lapic.o \
-			   i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o
+			   i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o \
+			   hyperv.o
+
 kvm-$(CONFIG_KVM_DEVICE_ASSIGNMENT)	+= assigned-dev.o iommu.o
 kvm-intel-y		+= vmx.o pmu_intel.o
 kvm-amd-y		+= svm.o pmu_amd.o
arch/x86/kvm/hyperv.c new file +307 -0

307 lines not on this page · raw message

arch/x86/kvm/hyperv.h new file +32 -0
new file mode 100644
index 0000000..115c738
@@ -0,0 +1,32 @@
+/*
+ * KVM Microsoft Hyper-V emulation
+ *
+ * derived from arch/x86/kvm/x86.c
+ *
+ * Copyright (C) 2006 Qumranet, Inc.
+ * Copyright (C) 2008 Qumranet, Inc.
+ * Copyright IBM Corporation, 2008
+ * Copyright 2010 Red Hat, Inc. and/or its affiliates.
+ * Copyright (C) 2015 Andrey Smetanin <[email protected]>
+ *
+ * Authors:
+ *   Avi Kivity   <[email protected]>
+ *   Yaniv Kamay  <[email protected]>
+ *   Amit Shah    <[email protected]>
+ *   Ben-Ami Yassour <[email protected]>
+ *   Andrey Smetanin <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef __ARCH_X86_KVM_HYPERV_H__
+#define __ARCH_X86_KVM_HYPERV_H__
+
+int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data);
+int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
+bool kvm_hv_hypercall_enabled(struct kvm *kvm);
+int kvm_hv_hypercall(struct kvm_vcpu *vcpu);
+
+#endif
arch/x86/kvm/lapic.h +1 -1
index f2f4e10..26f7817 100644
@@ -90,7 +90,7 @@ int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
 
 static inline bool kvm_hv_vapic_assist_page_enabled(struct kvm_vcpu *vcpu)
 {
-	return vcpu->arch.hv_vapic & HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE;
+	return vcpu->arch.hyperv.hv_vapic & HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE;
 }
 
 int kvm_lapic_enable_pv_eoi(struct kvm_vcpu *vcpu, u64 data);
arch/x86/kvm/x86.c +4 -261

307 lines not on this page · raw message

arch/x86/kvm/x86.h +5 -0
index edc8cdc..c04b56b 100644
@@ -147,6 +147,11 @@ static inline void kvm_register_writel(struct kvm_vcpu *vcpu,
 	return kvm_register_write(vcpu, reg, val);
 }
 
+static inline u64 get_kernel_ns(void)
+{
+	return ktime_get_boot_ns();
+}
+
 void kvm_before_handle_nmi(struct kvm_vcpu *vcpu);
 void kvm_after_handle_nmi(struct kvm_vcpu *vcpu);
 void kvm_set_pending_timer(struct kvm_vcpu *vcpu);
Signature · 1 line
2.1.4
#2 lore raw

PATCH v6 2/12 kvm: introduce vcpu_debug = kvm_debug + vcpu context

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

vcpu_debug is useful macro like kvm_debug but additionally includes vcpu context inside output.

---
 include/linux/kvm_host.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/kvm_host.h +3 -0
index 9564fd7..2b2edf1 100644
@@ -424,6 +424,9 @@ struct kvm {
 #define vcpu_unimpl(vcpu, fmt, ...)					\
 	kvm_pr_unimpl("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__)
 
+#define vcpu_debug(vcpu, fmt, ...)					\
+	kvm_debug("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__)
+
 static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
 {
 	smp_rmb();
Signature · 1 line
2.1.4
#3 lore raw

PATCH v6 3/12 kvm: add hyper-v crash msrs values

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

Added Hyper-V crash msrs values - HV_X64_MSR_CRASH*.

---
 arch/x86/include/uapi/asm/hyperv.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/x86/include/uapi/asm/hyperv.h +11 -0
index ce6068d..8fba544 100644
@@ -199,6 +199,17 @@
 #define HV_X64_MSR_STIMER3_CONFIG		0x400000B6
 #define HV_X64_MSR_STIMER3_COUNT		0x400000B7
 
+/* Hyper-V guest crash notification MSR's */
+#define HV_X64_MSR_CRASH_P0			0x40000100
+#define HV_X64_MSR_CRASH_P1			0x40000101
+#define HV_X64_MSR_CRASH_P2			0x40000102
+#define HV_X64_MSR_CRASH_P3			0x40000103
+#define HV_X64_MSR_CRASH_P4			0x40000104
+#define HV_X64_MSR_CRASH_CTL			0x40000105
+#define HV_X64_MSR_CRASH_CTL_NOTIFY		(1ULL << 63)
+#define HV_X64_MSR_CRASH_PARAMS		\
+		(1 + (HV_X64_MSR_CRASH_P4 - HV_X64_MSR_CRASH_P0))
+
 #define HV_X64_MSR_HYPERCALL_ENABLE		0x00000001
 #define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT	12
 #define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK	\
Signature · 1 line
2.1.4
#4 lore raw

PATCH v6 4/12 kvm/x86: added hyper-v crash msrs into kvm hyperv context

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

Added kvm Hyper-V context hv crash variables as storage of Hyper-V crash msrs.

---
 arch/x86/include/asm/kvm_host.h | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/include/asm/kvm_host.h +4 -0
index 78616aa..697c1f3 100644
@@ -595,6 +595,10 @@ struct kvm_hv {
 	u64 hv_guest_os_id;
 	u64 hv_hypercall;
 	u64 hv_tsc_page;
+
+	/* Hyper-v based guest crash (NT kernel bugcheck) parameters */
+	u64 hv_crash_param[HV_X64_MSR_CRASH_PARAMS];
+	u64 hv_crash_ctl;
 };
 
 struct kvm_arch {
Signature · 1 line
2.1.4
#5 lore raw

PATCH v6 5/12 kvm: added KVM_REQ_HV_CRASH value to notify qemu about hyper-v crash

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

Added KVM_REQ_HV_CRASH - vcpu request used for notify user space(QEMU) about Hyper-V crash.

---
 include/linux/kvm_host.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/kvm_host.h +1 -0
index 2b2edf1..a377e00 100644
@@ -139,6 +139,7 @@ static inline bool is_error_page(struct page *page)
 #define KVM_REQ_DISABLE_IBS       24
 #define KVM_REQ_APIC_PAGE_RELOAD  25
 #define KVM_REQ_SMI               26
+#define KVM_REQ_HV_CRASH          27
 
 #define KVM_USERSPACE_IRQ_SOURCE_ID		0
 #define KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID	1
Signature · 1 line
2.1.4
#6 lore raw

PATCH v6 6/12 kvm/x86: mark hyper-v crash msrs as partition wide

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

Hyper-V crash msr's are per vm, aren't per vcpu, so mark them as partition wide.

---
 arch/x86/kvm/hyperv.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kvm/hyperv.c +2 -0
index 2b49f10..af83c96 100644
@@ -39,6 +39,8 @@ static bool kvm_hv_msr_partition_wide(u32 msr)
 	case HV_X64_MSR_HYPERCALL:
 	case HV_X64_MSR_REFERENCE_TSC:
 	case HV_X64_MSR_TIME_REF_COUNT:
+	case HV_X64_MSR_CRASH_CTL:
+	case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
 		r = true;
 		break;
 	}
Signature · 1 line
2.1.4
#7 lore raw

PATCH v6 7/12 kvm/x86: added hyper-v crash data and ctl msr's get/set'ers

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

Added hyper-v crash msr's(HV_X64_MSR_CRASH*) data and control geters and setters. Userspace should check that such msr's available by check of KVM_CAP_HYPERV_MSR_CRASH capability.

User space allowed to setup Hyper-V crash ctl msr.
This msr should be setup to HV_X64_MSR_CRASH_CTL_NOTIFY value so Hyper-V guest knows it can send crash data to host. But Hyper-V guest notifies about crash event by writing the same HV_X64_MSR_CRASH_CTL_NOTIFY value into crash ctl msr. So both user space and guest writes inside ctl msr the same value and this patch distingiush the moment of actual guest crash by checking host initiated value from msr info. Also patch prevents modification of crash ctl msr by guest.

---
 arch/x86/kvm/hyperv.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++---
 arch/x86/kvm/hyperv.h |  2 +-
 arch/x86/kvm/x86.c    |  9 ++++++-
 3 files changed, 80 insertions(+), 5 deletions(-)
arch/x86/kvm/hyperv.c +71 -3
index af83c96..a8160d2 100644
@@ -48,7 +48,63 @@ static bool kvm_hv_msr_partition_wide(u32 msr)
 	return r;
 }
 
-static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+static int kvm_hv_msr_get_crash_data(struct kvm_vcpu *vcpu,
+				     u32 index, u64 *pdata)
+{
+	struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
+
+	if (WARN_ON_ONCE(index >= ARRAY_SIZE(hv->hv_crash_param)))
+		return -EINVAL;
+
+	*pdata = hv->hv_crash_param[index];
+	return 0;
+}
+
+static int kvm_hv_msr_get_crash_ctl(struct kvm_vcpu *vcpu, u64 *pdata)
+{
+	struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
+
+	*pdata = hv->hv_crash_ctl;
+	return 0;
+}
+
+static int kvm_hv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u64 data, bool host)
+{
+	struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
+
+	if (host)
+		hv->hv_crash_ctl = data & HV_X64_MSR_CRASH_CTL_NOTIFY;
+
+	if (!host && (data & HV_X64_MSR_CRASH_CTL_NOTIFY)) {
+
+		vcpu_debug(vcpu, "hv crash (0x%llx 0x%llx 0x%llx 0x%llx 0x%llx)\n",
+			  hv->hv_crash_param[0],
+			  hv->hv_crash_param[1],
+			  hv->hv_crash_param[2],
+			  hv->hv_crash_param[3],
+			  hv->hv_crash_param[4]);
+
+		/* Send notification about crash to user space */
+		kvm_make_request(KVM_REQ_HV_CRASH, vcpu);
+	}
+
+	return 0;
+}
+
+static int kvm_hv_msr_set_crash_data(struct kvm_vcpu *vcpu,
+				     u32 index, u64 data)
+{
+	struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
+
+	if (WARN_ON_ONCE(index >= ARRAY_SIZE(hv->hv_crash_param)))
+		return -EINVAL;
+
+	hv->hv_crash_param[index] = data;
+	return 0;
+}
+
+static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data,
+			     bool host)
 {
 	struct kvm *kvm = vcpu->kvm;
 	struct kvm_hv *hv = &kvm->arch.hyperv;
@@ -101,6 +157,12 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 		mark_page_dirty(kvm, gfn);
 		break;
 	}
+	case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
+		return kvm_hv_msr_set_crash_data(vcpu,
+						 msr - HV_X64_MSR_CRASH_P0,
+						 data);
+	case HV_X64_MSR_CRASH_CTL:
+		return kvm_hv_msr_set_crash_ctl(vcpu, data, host);
 	default:
 		vcpu_unimpl(vcpu, "Hyper-V uhandled wrmsr: 0x%x data 0x%llx\n",
 			    msr, data);
@@ -173,6 +235,12 @@ static int kvm_hv_get_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
 	case HV_X64_MSR_REFERENCE_TSC:
 		data = hv->hv_tsc_page;
 		break;
+	case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
+		return kvm_hv_msr_get_crash_data(vcpu,
+						 msr - HV_X64_MSR_CRASH_P0,
+						 pdata);
+	case HV_X64_MSR_CRASH_CTL:
+		return kvm_hv_msr_get_crash_ctl(vcpu, pdata);
 	default:
 		vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
 		return 1;
@@ -217,13 +285,13 @@ static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
 	return 0;
 }
 
-int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 {
 	if (kvm_hv_msr_partition_wide(msr)) {
 		int r;
 
 		mutex_lock(&vcpu->kvm->lock);
-		r = kvm_hv_set_msr_pw(vcpu, msr, data);
+		r = kvm_hv_set_msr_pw(vcpu, msr, data, host);
 		mutex_unlock(&vcpu->kvm->lock);
 		return r;
 	} else
arch/x86/kvm/hyperv.h +1 -1
index 115c738..c7bce55 100644
@@ -24,7 +24,7 @@
 #ifndef __ARCH_X86_KVM_HYPERV_H__
 #define __ARCH_X86_KVM_HYPERV_H__
 
-int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data);
+int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host);
 int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
 bool kvm_hv_hypercall_enabled(struct kvm *kvm);
 int kvm_hv_hypercall(struct kvm_vcpu *vcpu);
arch/x86/kvm/x86.c +8 -1
index 301ee01..ceec9bf 100644
@@ -950,6 +950,8 @@ static u32 emulated_msrs[] = {
 	MSR_KVM_SYSTEM_TIME_NEW, MSR_KVM_WALL_CLOCK_NEW,
 	HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
 	HV_X64_MSR_TIME_REF_COUNT, HV_X64_MSR_REFERENCE_TSC,
+	HV_X64_MSR_CRASH_P0, HV_X64_MSR_CRASH_P1, HV_X64_MSR_CRASH_P2,
+	HV_X64_MSR_CRASH_P3, HV_X64_MSR_CRASH_P4, HV_X64_MSR_CRASH_CTL,
 	HV_X64_MSR_APIC_ASSIST_PAGE, MSR_KVM_ASYNC_PF_EN, MSR_KVM_STEAL_TIME,
 	MSR_KVM_PV_EOI_EN,
 
@@ -2103,7 +2105,10 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 		 */
 		break;
 	case HV_X64_MSR_GUEST_OS_ID ... HV_X64_MSR_SINT15:
-		return kvm_hv_set_msr_common(vcpu, msr, data);
+	case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
+	case HV_X64_MSR_CRASH_CTL:
+		return kvm_hv_set_msr_common(vcpu, msr, data,
+					     msr_info->host_initiated);
 	case MSR_IA32_BBL_CR_CTL3:
 		/* Drop writes to this legacy MSR -- see rdmsr
 		 * counterpart for further detail.
@@ -2304,6 +2309,8 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 		msr_info->data = 0x20000000;
 		break;
 	case HV_X64_MSR_GUEST_OS_ID ... HV_X64_MSR_SINT15:
+	case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
+	case HV_X64_MSR_CRASH_CTL:
 		return kvm_hv_get_msr_common(vcpu,
 					     msr_info->index, &msr_info->data);
 		break;
Signature · 1 line
2.1.4
#8 lore raw

Re: [PATCH 7/12] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers

Quoted 5 lines · Denis V. Lunev

From: Andrey Smetanin <[email protected]>

Added hyper-v crash msr's(HV_X64_MSR_CRASH*) data and control geters and setters. Userspace should check that such msr's available by check of KVM_CAP_HYPERV_MSR_CRASH capability.

I didn't see the KVM_CAP_HYPERV_MSR_CRASH in this patchset. :(

Regards,
Wanpeng Li

#9 lore raw

Re: [PATCH 7/12] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers

Quoted 11 lines · Wanpeng Li
Quoted 5 lines · Denis V. Lunev

From: Andrey Smetanin <[email protected]>

Added hyper-v crash msr's(HV_X64_MSR_CRASH*) data and control geters and setters. Userspace should check that such msr's available by check of KVM_CAP_HYPERV_MSR_CRASH capability.

I didn't see the KVM_CAP_HYPERV_MSR_CRASH in this patchset. :(

Regards,
Wanpeng Li

aaaa, actually I have not updated the comment. Sorry. This cap was gone since previous revision, the check of the presense of this feature in KVM is performed by MSR availability.

Den

#10 lore raw

PATCH v6 8/12 kvm/x86: add sending hyper-v crash notification to user space

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

Sending of notification is done by exiting vcpu to user space if KVM_REQ_HV_CRASH is enabled for vcpu. At exit to user space the kvm_run structure contains system_event with type KVM_SYSTEM_EVENT_CRASH to notify about guest crash occurred.

---
 Documentation/virtual/kvm/api.txt | 5 +++++
 arch/x86/kvm/x86.c                | 6 ++++++
 include/uapi/linux/kvm.h          | 1 +
 3 files changed, 12 insertions(+)
Documentation/virtual/kvm/api.txt +5 -0
index a7926a9..a4ebcb7 100644
@@ -3277,6 +3277,7 @@ should put the acknowledged interrupt vector into the 'epr' field.
 		struct {
 #define KVM_SYSTEM_EVENT_SHUTDOWN       1
 #define KVM_SYSTEM_EVENT_RESET          2
+#define KVM_SYSTEM_EVENT_CRASH          3
 			__u32 type;
 			__u64 flags;
 		} system_event;
@@ -3296,6 +3297,10 @@ Valid values for 'type' are:
   KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM.
    As with SHUTDOWN, userspace can choose to ignore the request, or
    to schedule the reset to occur in the future and may call KVM_RUN again.
+  KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest
+   has requested a crash condition maintenance. Userspace can choose
+   to ignore the request, or to gather VM memory core dump and/or
+   reset/shutdown of the VM.
 
 		/* Fix the size of the union. */
 		char padding[256];
arch/x86/kvm/x86.c +6 -0
index ceec9bf..4d71b8f 100644
@@ -6266,6 +6266,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 			vcpu_scan_ioapic(vcpu);
 		if (kvm_check_request(KVM_REQ_APIC_PAGE_RELOAD, vcpu))
 			kvm_vcpu_reload_apic_access_page(vcpu);
+		if (kvm_check_request(KVM_REQ_HV_CRASH, vcpu)) {
+			vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
+			vcpu->run->system_event.type = KVM_SYSTEM_EVENT_CRASH;
+			r = 0;
+			goto out;
+		}
 	}
 
 	if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win) {
include/uapi/linux/kvm.h +1 -0
index 716ad4a..9ef19eb 100644
@@ -317,6 +317,7 @@ struct kvm_run {
 		struct {
 #define KVM_SYSTEM_EVENT_SHUTDOWN       1
 #define KVM_SYSTEM_EVENT_RESET          2
+#define KVM_SYSTEM_EVENT_CRASH          3
 			__u32 type;
 			__u64 flags;
 		} system_event;
Signature · 1 line
2.1.4
#11 lore raw

PATCH v6 9/12 Added generic panic handler qemu_system_guest_panicked()

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

There are pieces of guest panic handling code that can be shared in one generic function. These code replaced by call qemu_system_guest_panicked().

---
 hw/misc/pvpanic.c       |  3 +--
 include/sysemu/sysemu.h |  1 +
 target-s390x/kvm.c      | 11 ++---------
 vl.c                    |  6 ++++++
 4 files changed, 10 insertions(+), 11 deletions(-)
hw/misc/pvpanic.c +1 -2
index 994f8af..3709488 100644
@@ -41,8 +41,7 @@ static void handle_event(int event)
     }
 
     if (event & PVPANIC_PANICKED) {
-        qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE, &error_abort);
-        vm_stop(RUN_STATE_GUEST_PANICKED);
+        qemu_system_guest_panicked();
         return;
     }
 }
include/sysemu/sysemu.h +1 -0
index df80951..70164c9 100644
@@ -68,6 +68,7 @@ int qemu_reset_requested_get(void);
 void qemu_system_killed(int signal, pid_t pid);
 void qemu_devices_reset(void);
 void qemu_system_reset(bool report);
+void qemu_system_guest_panicked(void);
 
 void qemu_add_exit_notifier(Notifier *notify);
 void qemu_remove_exit_notifier(Notifier *notify);
target-s390x/kvm.c +2 -9
index 135111a..e5bd3ef 100644
@@ -1796,13 +1796,6 @@ static bool is_special_wait_psw(CPUState *cs)
     return cs->kvm_run->psw_addr == 0xfffUL;
 }
 
-static void guest_panicked(void)
-{
-    qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE,
-                                   &error_abort);
-    vm_stop(RUN_STATE_GUEST_PANICKED);
-}
-
 static void unmanageable_intercept(S390CPU *cpu, const char *str, int pswoffset)
 {
     CPUState *cs = CPU(cpu);
@@ -1811,7 +1804,7 @@ static void unmanageable_intercept(S390CPU *cpu, const char *str, int pswoffset)
                  str, cs->cpu_index, ldq_phys(cs->as, cpu->env.psa + pswoffset),
                  ldq_phys(cs->as, cpu->env.psa + pswoffset + 8));
     s390_cpu_halt(cpu);
-    guest_panicked();
+    qemu_system_guest_panicked();
 }
 
 static int handle_intercept(S390CPU *cpu)
@@ -1844,7 +1837,7 @@ static int handle_intercept(S390CPU *cpu)
                 if (is_special_wait_psw(cs)) {
                     qemu_system_shutdown_request();
                 } else {
-                    guest_panicked();
+                    qemu_system_guest_panicked();
                 }
             }
             r = EXCP_HALTED;
vl.c +6 -0
index 69ad90c..38eee1f 100644
@@ -1721,6 +1721,12 @@ void qemu_system_reset(bool report)
     cpu_synchronize_all_post_reset();
 }
 
+void qemu_system_guest_panicked(void)
+{
+    qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE, &error_abort);
+    vm_stop(RUN_STATE_GUEST_PANICKED);
+}
+
 void qemu_system_reset_request(void)
 {
     if (no_reboot) {
Signature · 1 line
2.1.4
#12 lore raw

PATCH v6 10/12 kvm: Add kvm system event crash handler

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

KVM kernel can send guest crash events into userspace. Appropriate guest crash handler is called when kernel guest crash event received. Guest crash event recognized by a KVM_SYSTEM_EVENT_CRASH type of system event.

---
 kvm-all.c                 | 4 ++++
 linux-headers/linux/kvm.h | 1 +
 2 files changed, 5 insertions(+)
kvm-all.c +4 -0
index 53e01d4..7a959b6 100644
@@ -1844,6 +1844,10 @@ int kvm_cpu_exec(CPUState *cpu)
                 qemu_system_reset_request();
                 ret = EXCP_INTERRUPT;
                 break;
+            case KVM_SYSTEM_EVENT_CRASH:
+                qemu_system_guest_panicked();
+                ret = 0;
+                break;
             default:
                 DPRINTF("kvm_arch_handle_exit\n");
                 ret = kvm_arch_handle_exit(cpu, run);
linux-headers/linux/kvm.h +1 -0
index fad9e5c..409be37 100644
@@ -317,6 +317,7 @@ struct kvm_run {
 		struct {
 #define KVM_SYSTEM_EVENT_SHUTDOWN       1
 #define KVM_SYSTEM_EVENT_RESET          2
+#define KVM_SYSTEM_EVENT_CRASH          3
 			__u32 type;
 			__u64 flags;
 		} system_event;
Signature · 1 line
2.1.4
#13 lore raw

PATCH v6 11/12 cpu: Add crash_occurred flag into CPUState

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

CPUState::crash_occurred field inside CPUState marks that guest crash occurred. This value is added into cpu common migration subsection.

---
 exec.c            | 19 +++++++++++++++++++
 include/qom/cpu.h |  1 +
 qom/cpu.c         |  1 +
 vl.c              |  3 +++
 4 files changed, 24 insertions(+)
exec.c +19 -0
index f7883d2..15c9a29 100644
@@ -465,6 +465,24 @@ static const VMStateDescription vmstate_cpu_common_exception_index = {
     }
 };
 
+static bool cpu_common_crash_occurred_needed(void *opaque)
+{
+    CPUState *cpu = opaque;
+
+    return cpu->crash_occurred;
+}
+
+static const VMStateDescription vmstate_cpu_common_crash_occurred = {
+    .name = "cpu_common/crash_occurred",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .needed = cpu_common_crash_occurred_needed,
+    .fields = (VMStateField[]) {
+        VMSTATE_BOOL(crash_occurred, CPUState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 const VMStateDescription vmstate_cpu_common = {
     .name = "cpu_common",
     .version_id = 1,
@@ -478,6 +496,7 @@ const VMStateDescription vmstate_cpu_common = {
     },
     .subsections = (const VMStateDescription*[]) {
         &vmstate_cpu_common_exception_index,
+        &vmstate_cpu_common_crash_occurred,
         NULL
     }
 };
include/qom/cpu.h +1 -0
index 39f0f19..aae05fd 100644
@@ -263,6 +263,7 @@ struct CPUState {
     bool created;
     bool stop;
     bool stopped;
+    bool crash_occurred;
     volatile sig_atomic_t exit_request;
     uint32_t interrupt_request;
     int singlestep_enabled;
qom/cpu.c +1 -0
index 108bfa2..c3c4674 100644
@@ -249,6 +249,7 @@ static void cpu_common_reset(CPUState *cpu)
     cpu->icount_decr.u32 = 0;
     cpu->can_do_io = 0;
     cpu->exception_index = -1;
+    cpu->crash_occurred = false;
     memset(cpu->tb_jmp_cache, 0, TB_JMP_CACHE_SIZE * sizeof(void *));
 }
 
vl.c +3 -0
index 38eee1f..62bab42 100644
@@ -1723,6 +1723,9 @@ void qemu_system_reset(bool report)
 
 void qemu_system_guest_panicked(void)
 {
+    if (current_cpu) {
+        current_cpu->crash_occurred = true;
+    }
     qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE, &error_abort);
     vm_stop(RUN_STATE_GUEST_PANICKED);
 }
Signature · 1 line
2.1.4
maintainer
#14 lore raw

Re: [PATCH 11/12] cpu: Add crash_occurred flag into CPUState

Quoted 10 lines · Denis V. Lunev

From: Andrey Smetanin <[email protected]>

CPUState::crash_occurred field inside CPUState marks that guest crash occurred. This value is added into cpu common migration subsection.

Since there's been no answer for two months, I'll send a pull request for this patch when I'm back.

Paolo

Quoted 83 lines
---
 exec.c            | 19 +++++++++++++++++++
 include/qom/cpu.h |  1 +
 qom/cpu.c         |  1 +
 vl.c              |  3 +++
 4 files changed, 24 insertions(+)
exec.c +19 -0
index f7883d2..15c9a29 100644
@@ -465,6 +465,24 @@ static const VMStateDescription vmstate_cpu_common_exception_index = {
     }
 };
 
+static bool cpu_common_crash_occurred_needed(void *opaque)
+{
+    CPUState *cpu = opaque;
+
+    return cpu->crash_occurred;
+}
+
+static const VMStateDescription vmstate_cpu_common_crash_occurred = {
+    .name = "cpu_common/crash_occurred",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .needed = cpu_common_crash_occurred_needed,
+    .fields = (VMStateField[]) {
+        VMSTATE_BOOL(crash_occurred, CPUState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 const VMStateDescription vmstate_cpu_common = {
     .name = "cpu_common",
     .version_id = 1,
@@ -478,6 +496,7 @@ const VMStateDescription vmstate_cpu_common = {
     },
     .subsections = (const VMStateDescription*[]) {
         &vmstate_cpu_common_exception_index,
+        &vmstate_cpu_common_crash_occurred,
         NULL
     }
 };
include/qom/cpu.h +1 -0
index 39f0f19..aae05fd 100644
@@ -263,6 +263,7 @@ struct CPUState {
     bool created;
     bool stop;
     bool stopped;
+    bool crash_occurred;
     volatile sig_atomic_t exit_request;
     uint32_t interrupt_request;
     int singlestep_enabled;
qom/cpu.c +1 -0
index 108bfa2..c3c4674 100644
@@ -249,6 +249,7 @@ static void cpu_common_reset(CPUState *cpu)
     cpu->icount_decr.u32 = 0;
     cpu->can_do_io = 0;
     cpu->exception_index = -1;
+    cpu->crash_occurred = false;
     memset(cpu->tb_jmp_cache, 0, TB_JMP_CACHE_SIZE * sizeof(void *));
 }
 
vl.c +3 -0
index 38eee1f..62bab42 100644
@@ -1723,6 +1723,9 @@ void qemu_system_reset(bool report)
 
 void qemu_system_guest_panicked(void)
 {
+    if (current_cpu) {
+        current_cpu->crash_occurred = true;
+    }
     qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE, &error_abort);
     vm_stop(RUN_STATE_GUEST_PANICKED);
 }
#15 lore raw

PATCH v6 12/12 i386/kvm: Hyper-v crash msrs set/get'ers and migration

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

KVM Hyper-V based guests can notify hypervisor about occurred guest crash by writing into Hyper-V crash MSR's. This patch does handling and migration of HV_X64_MSR_CRASH_P0-P4, HV_X64_MSR_CRASH_CTL msrs. User can enable these MSR's by 'hv-crash' option.

---
 linux-headers/asm-x86/hyperv.h | 13 +++++++++++++
 target-i386/cpu-qom.h          |  1 +
 target-i386/cpu.c              |  1 +
 target-i386/cpu.h              |  2 ++
 target-i386/kvm.c              | 32 +++++++++++++++++++++++++++++++-
 target-i386/machine.c          | 27 +++++++++++++++++++++++++++
 6 files changed, 75 insertions(+), 1 deletion(-)
linux-headers/asm-x86/hyperv.h +13 -0
index ce6068d..5f88dc7 100644
@@ -108,6 +108,8 @@
 #define HV_X64_HYPERCALL_PARAMS_XMM_AVAILABLE		(1 << 4)
 /* Support for a virtual guest idle state is available */
 #define HV_X64_GUEST_IDLE_STATE_AVAILABLE		(1 << 5)
+/* Guest crash data handler available */
+#define HV_X64_GUEST_CRASH_MSR_AVAILABLE		(1 << 10)
 
 /*
  * Implementation recommendations. Indicates which behaviors the hypervisor
@@ -199,6 +201,17 @@
 #define HV_X64_MSR_STIMER3_CONFIG		0x400000B6
 #define HV_X64_MSR_STIMER3_COUNT		0x400000B7
 
+/* Hypev-V guest crash notification MSR's */
+#define HV_X64_MSR_CRASH_P0			0x40000100
+#define HV_X64_MSR_CRASH_P1			0x40000101
+#define HV_X64_MSR_CRASH_P2			0x40000102
+#define HV_X64_MSR_CRASH_P3			0x40000103
+#define HV_X64_MSR_CRASH_P4			0x40000104
+#define HV_X64_MSR_CRASH_CTL			0x40000105
+#define HV_X64_MSR_CRASH_CTL_NOTIFY		(1ULL << 63)
+#define HV_X64_MSR_CRASH_PARAMS	\
+		(1 + (HV_X64_MSR_CRASH_P4 - HV_X64_MSR_CRASH_P0))
+
 #define HV_X64_MSR_HYPERCALL_ENABLE		0x00000001
 #define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT	12
 #define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK	\
target-i386/cpu-qom.h +1 -0
index 7a4fddd..c35b624 100644
@@ -89,6 +89,7 @@ typedef struct X86CPU {
     bool hyperv_relaxed_timing;
     int hyperv_spinlock_attempts;
     bool hyperv_time;
+    bool hyperv_crash;
     bool check_cpuid;
     bool enforce_cpuid;
     bool expose_kvm;
target-i386/cpu.c +1 -0
index 36b07f9..04a8408 100644
@@ -3117,6 +3117,7 @@ static Property x86_cpu_properties[] = {
     DEFINE_PROP_BOOL("hv-relaxed", X86CPU, hyperv_relaxed_timing, false),
     DEFINE_PROP_BOOL("hv-vapic", X86CPU, hyperv_vapic, false),
     DEFINE_PROP_BOOL("hv-time", X86CPU, hyperv_time, false),
+    DEFINE_PROP_BOOL("hv-crash", X86CPU, hyperv_crash, false),
     DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, false),
     DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false),
     DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true),
target-i386/cpu.h +2 -0
index 603aaf0..6c2352a 100644
@@ -21,6 +21,7 @@
 
 #include "config.h"
 #include "qemu-common.h"
+#include <asm/hyperv.h>
 
 #ifdef TARGET_X86_64
 #define TARGET_LONG_BITS 64
@@ -904,6 +905,7 @@ typedef struct CPUX86State {
     uint64_t msr_hv_guest_os_id;
     uint64_t msr_hv_vapic;
     uint64_t msr_hv_tsc;
+    uint64_t msr_hv_crash_prm[HV_X64_MSR_CRASH_PARAMS];
 
     /* exception/interrupt handling */
     int error_code;
target-i386/kvm.c +31 -1
index daced5c..3d1fca5 100644
@@ -79,6 +79,7 @@ static int lm_capable_kernel;
 static bool has_msr_hv_hypercall;
 static bool has_msr_hv_vapic;
 static bool has_msr_hv_tsc;
+static bool has_msr_hv_crash;
 static bool has_msr_mtrr;
 static bool has_msr_xss;
 
@@ -449,7 +450,8 @@ static bool hyperv_enabled(X86CPU *cpu)
     return kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0 &&
            (hyperv_hypercall_available(cpu) ||
             cpu->hyperv_time  ||
-            cpu->hyperv_relaxed_timing);
+            cpu->hyperv_relaxed_timing ||
+            cpu->hyperv_crash);
 }
 
 static Error *invtsc_mig_blocker;
@@ -515,6 +517,10 @@ int kvm_arch_init_vcpu(CPUState *cs)
             c->eax |= 0x200;
             has_msr_hv_tsc = true;
         }
+        if (cpu->hyperv_crash && has_msr_hv_crash) {
+            c->edx |= HV_X64_GUEST_CRASH_MSR_AVAILABLE;
+        }
+
         c = &cpuid_data.entries[cpuid_i++];
         c->function = HYPERV_CPUID_ENLIGHTMENT_INFO;
         if (cpu->hyperv_relaxed_timing) {
@@ -831,6 +837,10 @@ static int kvm_get_supported_msrs(KVMState *s)
                     has_msr_xss = true;
                     continue;
                 }
+                if (kvm_msr_list->indices[i] == HV_X64_MSR_CRASH_CTL) {
+                    has_msr_hv_crash = true;
+                    continue;
+                }
             }
         }
 
@@ -1321,6 +1331,16 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
             kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_REFERENCE_TSC,
                               env->msr_hv_tsc);
         }
+        if (has_msr_hv_crash) {
+            int j;
+
+            for (j = 0; j < HV_X64_MSR_CRASH_PARAMS; j++)
+                kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_CRASH_P0 + j,
+                                  env->msr_hv_crash_prm[j]);
+
+            kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_CRASH_CTL,
+                              HV_X64_MSR_CRASH_CTL_NOTIFY);
+        }
         if (has_msr_mtrr) {
             kvm_msr_entry_set(&msrs[n++], MSR_MTRRdefType, env->mtrr_deftype);
             kvm_msr_entry_set(&msrs[n++],
@@ -1673,6 +1693,13 @@ static int kvm_get_msrs(X86CPU *cpu)
     if (has_msr_hv_tsc) {
         msrs[n++].index = HV_X64_MSR_REFERENCE_TSC;
     }
+    if (has_msr_hv_crash) {
+        int j;
+
+        for (j = 0; j < HV_X64_MSR_CRASH_PARAMS; j++) {
+            msrs[n++].index = HV_X64_MSR_CRASH_P0 + j;
+        }
+    }
     if (has_msr_mtrr) {
         msrs[n++].index = MSR_MTRRdefType;
         msrs[n++].index = MSR_MTRRfix64K_00000;
@@ -1817,6 +1844,9 @@ static int kvm_get_msrs(X86CPU *cpu)
         case HV_X64_MSR_REFERENCE_TSC:
             env->msr_hv_tsc = msrs[i].data;
             break;
+        case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
+            env->msr_hv_crash_prm[index - HV_X64_MSR_CRASH_P0] = msrs[i].data;
+            break;
         case MSR_MTRRdefType:
             env->mtrr_deftype = msrs[i].data;
             break;
target-i386/machine.c +27 -0
index a0df64b..fc46881 100644
@@ -661,6 +661,32 @@ static const VMStateDescription vmstate_msr_hyperv_time = {
     }
 };
 
+static bool hyperv_crash_enable_needed(void *opaque)
+{
+    X86CPU *cpu = opaque;
+    CPUX86State *env = &cpu->env;
+    int i;
+
+    for (i = 0; i < HV_X64_MSR_CRASH_PARAMS; i++) {
+        if (env->msr_hv_crash_prm[i]) {
+            return true;
+        }
+    }
+    return false;
+}
+
+static const VMStateDescription vmstate_msr_hyperv_crash = {
+    .name = "cpu/msr_hyperv_crash",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .needed = hyperv_crash_enable_needed,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT64_ARRAY(env.msr_hv_crash_prm,
+                             X86CPU, HV_X64_MSR_CRASH_PARAMS),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static bool avx512_needed(void *opaque)
 {
     X86CPU *cpu = opaque;
@@ -842,6 +868,7 @@ VMStateDescription vmstate_x86_cpu = {
         &vmstate_msr_hypercall_hypercall,
         &vmstate_msr_hyperv_vapic,
         &vmstate_msr_hyperv_time,
+        &vmstate_msr_hyperv_crash,
         &vmstate_avx512,
         &vmstate_xss,
         NULL
Signature · 1 line
2.1.4
maintainer
#16 lore raw

Re: [PATCH 12/12] i386/kvm: Hyper-v crash msrs set/get'ers and migration

linux-headers/asm-x86/hyperv.h line 115

Quoted 13 lines · Denis V. Lunev
linux-headers/asm-x86/hyperv.h +2 -0
index ce6068d..5f88dc7 100644
@@ -108,6 +108,8 @@
 #define HV_X64_HYPERCALL_PARAMS_XMM_AVAILABLE		(1 << 4)
 /* Support for a virtual guest idle state is available */
 #define HV_X64_GUEST_IDLE_STATE_AVAILABLE		(1 << 5)
+/* Guest crash data handler available */
+#define HV_X64_GUEST_CRASH_MSR_AVAILABLE		(1 << 10)
 
 /*
  * Implementation recommendations. Indicates which behaviors the hypervisor

This hunk is not present in the kernel-side patches. I'll apply it to the kernel KVM tree.

Paolo

maintainer
#17 lore raw

Re: [PATCH 12/12] i386/kvm: Hyper-v crash msrs set/get'ers and migration

In reply to Denis V. Lunev

target-i386/cpu.h typedef struct CPUX86State { · line 908

Quoted 5 lines · Denis V. Lunev
target-i386/cpu.h +1 -0
@@ -904,6 +905,7 @@ typedef struct CPUX86State {
     uint64_t msr_hv_guest_os_id;
     uint64_t msr_hv_vapic;
     uint64_t msr_hv_tsc;
+    uint64_t msr_hv_crash_prm[HV_X64_MSR_CRASH_PARAMS];

Do not abbreviate variable names! The enum even says PARAMS, so use params in the array name as well.

I've done the change locally in all files.

Paolo

Quoted 2 lines
target-i386/cpu.h +0 -0
     /* exception/interrupt handling */
     int error_code;
maintainer
#18 lore raw
In reply to Denis V. Lunev
Quoted 45 lines · Denis V. Lunev

Windows 2012 guests can notify hypervisor about occurred guest crash (Windows bugcheck(BSOD)) by writing specific Hyper-V msrs. This patch does handling of this MSR's by KVM and sending notification to user space that allows to gather Windows guest crash dump by QEMU/LIBVIRT.

The idea is to provide functionality equal to pvpanic device without QEMU guest agent for Windows.

The idea is borrowed from Linux HyperV bus driver and validated against Windows 2k12.

Changes from v5:
* added hyperv crash msrs into supported/emulated list
* qemu: reset CPUState::crash_occurred at cpu reset
* qemu: userspace checks kernel support of hyperv crash msrs by kvm_get_supported_msrs

Changes from v4:
* fixed typo in email of Andreas Färber <[email protected]> my vim strangely behaves on lines with extended Deutch chars

Changes from v3:
* remove unused HV_X64_MSR_CRASH_CTL_NOTIFY
* added documentation section about KVM_SYSTEM_EVENT_CRASH
* allow only supported values inside crash ctl msr
* qemu: split patch into generic crash handling patches and hyperv specific
* qemu: skip migration of crash ctl msr value

Changes from v2:
* forbid modification crash ctl msr by guest
* qemu_system_guest_panicked usage in pvpanic and s390x
* hyper-v crash handler move from generic kvm to i386
* hyper-v crash handler: skip fetching crash msrs just mark crash occurred
* sync with linux-next 20150629
* patch 11 squashed to patch 10
* patch 9 squashed to patch 7

Changes from v1:
* hyperv code move to hyperv.c
* added read handlers of crash data msrs
* added per vm and per cpu hyperv context structures
* added saving crash msrs inside qemu cpu state
* added qemu fetch and update of crash msrs
* added qemu crash msrs store in cpu state and it's migration

Quoted 5 lines

I'm queuing patches 1-8 to the KVM tree. For patch 9-12, I've applied them locally but would like Eduardo or Andreas to ack 11 and 12.

Paolo

#19 lore raw
Quoted 52 lines · Paolo Bonzini
Quoted 45 lines · Denis V. Lunev

Windows 2012 guests can notify hypervisor about occurred guest crash (Windows bugcheck(BSOD)) by writing specific Hyper-V msrs. This patch does handling of this MSR's by KVM and sending notification to user space that allows to gather Windows guest crash dump by QEMU/LIBVIRT.

The idea is to provide functionality equal to pvpanic device without QEMU guest agent for Windows.

The idea is borrowed from Linux HyperV bus driver and validated against Windows 2k12.

Changes from v5:
* added hyperv crash msrs into supported/emulated list
* qemu: reset CPUState::crash_occurred at cpu reset
* qemu: userspace checks kernel support of hyperv crash msrs by kvm_get_supported_msrs

Changes from v4:
* fixed typo in email of Andreas Färber <[email protected]> my vim strangely behaves on lines with extended Deutch chars

Changes from v3:
* remove unused HV_X64_MSR_CRASH_CTL_NOTIFY
* added documentation section about KVM_SYSTEM_EVENT_CRASH
* allow only supported values inside crash ctl msr
* qemu: split patch into generic crash handling patches and hyperv specific
* qemu: skip migration of crash ctl msr value

Changes from v2:
* forbid modification crash ctl msr by guest
* qemu_system_guest_panicked usage in pvpanic and s390x
* hyper-v crash handler move from generic kvm to i386
* hyper-v crash handler: skip fetching crash msrs just mark crash occurred
* sync with linux-next 20150629
* patch 11 squashed to patch 10
* patch 9 squashed to patch 7

Changes from v1:
* hyperv code move to hyperv.c
* added read handlers of crash data msrs
* added per vm and per cpu hyperv context structures
* added saving crash msrs inside qemu cpu state
* added qemu fetch and update of crash msrs
* added qemu crash msrs store in cpu state and it's migration

Quoted 5 lines
Quoted 4 lines

I'm queuing patches 1-8 to the KVM tree. For patch 9-12, I've applied them locally but would like Eduardo or Andreas to ack 11 and 12.

Paolo

guys?

we are going to move forward with other HyperV bits.

Den

maintainer
#20 lore raw
Quoted 3 lines · Denis V. Lunev

guys?

we are going to move forward with other HyperV bits.

Wait a second, 2.4 was released only a few hours ago...

Paolo

#21 lore raw
Quoted 8 lines · Paolo Bonzini
Quoted 3 lines · Denis V. Lunev

guys?

we are going to move forward with other HyperV bits.

Wait a second, 2.4 was released only a few hours ago...

Paolo

sure :)