Skip to contentSkip to conversation

HyperV equivalent of pvpanic driver

PATCH Superseded Denis V. Lunev 4 participants 31 messages Jun 22, 2015 – Jun 25, 2015

Subsystems (4)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 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 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 v2 1/11 kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file

From: Andrey Smetanin <[email protected]>

This patch introduces 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           |   2 +-
 arch/x86/kvm/hyperv.c           | 303 ++++++++++++++++++++++++++++++++++++++++
 arch/x86/kvm/hyperv.h           |  31 ++++
 arch/x86/kvm/lapic.h            |   2 +-
 arch/x86/kvm/x86.c              | 263 +---------------------------------
 arch/x86/kvm/x86.h              |   5 +
 7 files changed, 358 insertions(+), 268 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 f4a555b..717a03c 100644
@@ -344,6 +344,11 @@ enum {
 	KVM_DEBUGREG_RELOAD = 4,
 };
 
+/* Hyper-V per vcpu emulation context */
+struct kvm_vcpu_arch_hyperv {
+	u64 hv_vapic;
+};
+
 struct kvm_vcpu_arch {
 	/*
 	 * rip and regs accesses must go through
@@ -498,8 +503,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_arch_hyperv hyperv;
 
 	cpumask_var_t wbinvd_dirty_mask;
 
@@ -570,6 +574,13 @@ struct kvm_apic_map {
 	struct kvm_lapic *logical_map[16][16];
 };
 
+/* Hyper-V emulation context */
+struct kvm_arch_hyperv {
+	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;
@@ -627,10 +638,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_arch_hyperv hyperv;
 
 	#ifdef CONFIG_KVM_MMU_AUDIT
 	int audit_point;
arch/x86/kvm/Makefile +1 -1
index 16e8f96..944c8c8 100644
@@ -12,7 +12,7 @@ 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
+			   i8254.o ioapic.o irq_comm.o cpuid.o pmu.o hyperv.o
 kvm-$(CONFIG_KVM_DEVICE_ASSIGNMENT)	+= assigned-dev.o iommu.o
 kvm-intel-y		+= vmx.o
 kvm-amd-y		+= svm.o
arch/x86/kvm/hyperv.c new file +303 -0

303 lines not on this page · raw message

arch/x86/kvm/hyperv.h new file +31 -0
new file mode 100644
index 0000000..39aee93
@@ -0,0 +1,31 @@
+/*
+ * KVM Microsoft Hyper-V emulation
+ *
+ * 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 9d28383..2891d2e 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 +3 -260

305 lines not on this page · raw message

arch/x86/kvm/x86.h +5 -0
index f5fef18..1cb1179 100644
@@ -145,6 +145,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
1.9.1
#2 lore raw

Re: [PATCH 01/11] kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file

Quoted 9 lines · Denis V. Lunev

From: Andrey Smetanin <[email protected]>

This patch introduces 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.

Quoted 4 lines

Paolo, Gleb,

we are very sensitive on the first patch. Could you suggest which tree we should be based on? For now I think that we should use

https://git.kernel.org/cgit/virt/kvm/kvm.git/

but the branch here could also matters.

Den

maintainer
#3 lore raw

Re: [PATCH 01/11] kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file

Quoted 10 lines · Denis V. Lunev

Paolo, Gleb,

we are very sensitive on the first patch. Could you suggest which tree we should be based on? For now I think that we should use

https://git.kernel.org/cgit/virt/kvm/kvm.git/

but the branch here could also matters.

You can use Linus's tree right now, but in general you should use branch "next" in that tree.

Paolo

#4 lore raw

PATCH v2 2/11 kvm: introduce vcpu_debug = kvm_debug + vcpu context

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

vcpu_debug is a useful macro like kvm_debug and additionally includes vcpu context into output.

---
 include/linux/kvm_host.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/kvm_host.h +3 -0
index ad45054..7ee3a90 100644
@@ -411,6 +411,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
1.9.1
#5 lore raw

PATCH v2 3/11 kvm: add hyper-v crash msrs constants

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

Added Hyper-V crash msrs HV_X64_MSR_CRASH* constants.

---
 arch/x86/include/uapi/asm/hyperv.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/x86/include/uapi/asm/hyperv.h +15 -0
index ce6068d..a1be4ba 100644
@@ -199,6 +199,21 @@
 #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_CTL_CONTENTS	\
+		(HV_X64_MSR_CRASH_CTL_NOTIFY)
+
+#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
1.9.1
#6 lore raw

PATCH v2 4/11 kvm/x86: added hyper-v crash msrs into kvm hyperv context

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

Added kvm hyperv 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 717a03c..578816a 100644
@@ -579,6 +579,10 @@ struct kvm_arch_hyperv {
 	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
1.9.1
#7 lore raw

PATCH v2 5/11 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 7ee3a90..f1a3977b 100644
@@ -134,6 +134,7 @@ static inline bool is_error_page(struct page *page)
 #define KVM_REQ_ENABLE_IBS        23
 #define KVM_REQ_DISABLE_IBS       24
 #define KVM_REQ_APIC_PAGE_RELOAD  25
+#define KVM_REQ_HV_CRASH          26
 
 #define KVM_USERSPACE_IRQ_SOURCE_ID		0
 #define KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID	1
Signature · 1 line
1.9.1
#8 lore raw

PATCH v2 6/11 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 a per VM, not 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 0d24d9a..f65fb622 100644
@@ -37,6 +37,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
1.9.1
#9 lore raw

PATCH v2 7/11 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.

---
 arch/x86/kvm/hyperv.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/kvm/x86.c    |  4 ++++
 2 files changed, 70 insertions(+)
arch/x86/kvm/hyperv.c +65 -0
index f65fb622..0a7d373 100644
@@ -46,6 +46,59 @@ static bool kvm_hv_msr_partition_wide(u32 msr)
 	return r;
 }
 
+static int kvm_hv_msr_get_crash_ctl(struct kvm_vcpu *vcpu, u64 *pdata)
+{
+	struct kvm_arch_hyperv *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)
+{
+	struct kvm_arch_hyperv *hv = &vcpu->kvm->arch.hyperv;
+
+	hv->hv_crash_ctl = data;
+	if ((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;
+	}
+
+	return 0;
+}
+
+static int kvm_hv_msr_set_crash_data(struct kvm_vcpu *vcpu,
+				     u32 index, u64 data)
+{
+	struct kvm_arch_hyperv *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_msr_get_crash_data(struct kvm_vcpu *vcpu,
+				     u32 index, u64 *pdata)
+{
+	struct kvm_arch_hyperv *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_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 {
 	struct kvm *kvm = vcpu->kvm;
@@ -98,6 +152,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);
 	default:
 		vcpu_unimpl(vcpu, "Hyper-V unimpl wrmsr: 0x%x data 0x%llx\n",
 				  msr, data);
@@ -170,6 +230,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;
arch/x86/kvm/x86.c +4 -0
index 2755c37..2046b78 100644
@@ -2208,6 +2208,8 @@ 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:
+	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);
 		break;
 	case MSR_IA32_BBL_CR_CTL3:
@@ -2451,6 +2453,8 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
 		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, pdata);
 		break;
 	case MSR_IA32_BBL_CR_CTL3:
Signature · 1 line
1.9.1
#10 lore raw

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

Quoted 19 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.

---
 arch/x86/kvm/hyperv.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/kvm/x86.c    |  4 ++++
 2 files changed, 70 insertions(+)
arch/x86/kvm/hyperv.c +0 -0
index f65fb622..0a7d373 100644

arch/x86/kvm/hyperv.c static bool kvm_hv_msr_partition_wide(u32 msr) · line 53

Quoted 8 lines
arch/x86/kvm/hyperv.c +5 -0
@@ -46,6 +46,59 @@ static bool kvm_hv_msr_partition_wide(u32 msr)
        return r;
 }
 
+static int kvm_hv_msr_get_crash_ctl(struct kvm_vcpu *vcpu, u64 *pdata)
+{
+       struct kvm_arch_hyperv *hv = &vcpu->kvm->arch.hyperv;
+
+       *pdata = hv->hv_crash_ctl;

I see that this is implemented so that userspace controls the Hyper-V crash capabilities that are enabled - userspace must set HV_X64_MSR_CRASH_CTL_NOTIFY before the guest reads HV_X64_MSR_CRASH_CTL. I just want to check that you considered an
alternative: a simpler implementation would have the crash capabilities statically defined by kvm, and HV_X64_MSR_CRASH_CTL_CONTENTS could just be returned here (and hv_crash_ctl could be removed from struct kvm_arch_hyperv).

The current implementation is potentially more flexible but makes the MSR handling a little more awkward since the host_initiated bool needs to be passed around (patch 09). I guess either approach seems ok to me.

Also, if this patchset is used then it looks like
HV_X64_MSR_CRASH_CTL_CONTENTS can be removed.

Quoted 9 lines
arch/x86/kvm/hyperv.c +9 -0
+       return 0;
+}
+
+static int kvm_hv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u64 data)
+{
+       struct kvm_arch_hyperv *hv = &vcpu->kvm->arch.hyperv;
+
+       hv->hv_crash_ctl = data;
+       if ((data & HV_X64_MSR_CRASH_CTL_NOTIFY)) {

arch/x86/kvm/hyperv.c static bool kvm_hv_msr_partition_wide(u32 msr) · line 72

Quoted 10 lines
arch/x86/kvm/hyperv.c +10 -0
+               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;

Returning from here seems unnecessary - if more crash capabilities are added in the future, the guest might want to invoke multiple capabilities at once, so we'd want to check for those here too.

Quoted 83 lines
arch/x86/kvm/hyperv.c +41 -0
+       }
+
+       return 0;
+}
+
+static int kvm_hv_msr_set_crash_data(struct kvm_vcpu *vcpu,
+                                    u32 index, u64 data)
+{
+       struct kvm_arch_hyperv *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_msr_get_crash_data(struct kvm_vcpu *vcpu,
+                                    u32 index, u64 *pdata)
+{
+       struct kvm_arch_hyperv *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_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 {
        struct kvm *kvm = vcpu->kvm;
@@ -98,6 +152,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);
        default:
                vcpu_unimpl(vcpu, "Hyper-V unimpl wrmsr: 0x%x data 0x%llx\n",
                                  msr, data);
@@ -170,6 +230,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;
arch/x86/kvm/x86.c +4 -1
index 2755c37..2046b78 100644
@@ -2208,6 +2208,8 @@ 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:
+       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);
                break;
        case MSR_IA32_BBL_CR_CTL3:
@@ -2451,6 +2453,8 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
                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, pdata);
                break;
        case MSR_IA32_BBL_CR_CTL3:
--

1.9.1

Quoted 2 lines

--
To unsubscribe from this list: send the line "unsubscribe kvm" in

--
To unsubscribe from this list: send the line "unsubscribe kvm" in

#11 lore raw

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

Quoted 37 lines · Peter Hornyack
Quoted 19 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.

---
  arch/x86/kvm/hyperv.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
  arch/x86/kvm/x86.c    |  4 ++++
  2 files changed, 70 insertions(+)
arch/x86/kvm/hyperv.c +0 -0
index f65fb622..0a7d373 100644

arch/x86/kvm/hyperv.c static bool kvm_hv_msr_partition_wide(u32 msr) · line 53

Quoted 8 lines
arch/x86/kvm/hyperv.c +5 -0
@@ -46,6 +46,59 @@ static bool kvm_hv_msr_partition_wide(u32 msr)
         return r;
  }
 
+static int kvm_hv_msr_get_crash_ctl(struct kvm_vcpu *vcpu, u64 *pdata)
+{
+       struct kvm_arch_hyperv *hv = &vcpu->kvm->arch.hyperv;
+
+       *pdata = hv->hv_crash_ctl;

I see that this is implemented so that userspace controls the Hyper-V crash capabilities that are enabled - userspace must set HV_X64_MSR_CRASH_CTL_NOTIFY before the guest reads HV_X64_MSR_CRASH_CTL. I just want to check that you considered an
alternative: a simpler implementation would have the crash capabilities statically defined by kvm, and HV_X64_MSR_CRASH_CTL_CONTENTS could just be returned here (and hv_crash_ctl could be removed from struct kvm_arch_hyperv).

Quoted 7 lines

The current implementation is potentially more flexible but makes the MSR handling a little more awkward since the host_initiated bool needs to be passed around (patch 09). I guess either approach seems ok to me.

Also, if this patchset is used then it looks like
HV_X64_MSR_CRASH_CTL_CONTENTS can be removed.

Paolo,

do you have any opinion on this? I prefer
configurable way but there is no problem
to enable it by default dropping 'hv_panic'
property.

Regards,
Den

Quoted 108 lines
Quoted 9 lines
arch/x86/kvm/hyperv.c +9 -0
+       return 0;
+}
+
+static int kvm_hv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u64 data)
+{
+       struct kvm_arch_hyperv *hv = &vcpu->kvm->arch.hyperv;
+
+       hv->hv_crash_ctl = data;
+       if ((data & HV_X64_MSR_CRASH_CTL_NOTIFY)) {

arch/x86/kvm/hyperv.c static bool kvm_hv_msr_partition_wide(u32 msr) · line 72

Quoted 10 lines
arch/x86/kvm/hyperv.c +10 -0
+               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;

Returning from here seems unnecessary - if more crash capabilities are added in the future, the guest might want to invoke multiple capabilities at once, so we'd want to check for those here too.

Quoted 85 lines
arch/x86/kvm/hyperv.c +41 -0
+       }
+
+       return 0;
+}
+
+static int kvm_hv_msr_set_crash_data(struct kvm_vcpu *vcpu,
+                                    u32 index, u64 data)
+{
+       struct kvm_arch_hyperv *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_msr_get_crash_data(struct kvm_vcpu *vcpu,
+                                    u32 index, u64 *pdata)
+{
+       struct kvm_arch_hyperv *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_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
  {
         struct kvm *kvm = vcpu->kvm;
@@ -98,6 +152,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);
         default:
                 vcpu_unimpl(vcpu, "Hyper-V unimpl wrmsr: 0x%x data 0x%llx\n",
                                   msr, data);
@@ -170,6 +230,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;
arch/x86/kvm/x86.c +4 -1
index 2755c37..2046b78 100644
@@ -2208,6 +2208,8 @@ 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:
+       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);
                 break;
         case MSR_IA32_BBL_CR_CTL3:
@@ -2451,6 +2453,8 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
                 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, pdata);
                 break;
         case MSR_IA32_BBL_CR_CTL3:
--

1.9.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in

maintainer
#12 lore raw

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

Quoted 9 lines · Denis V. Lunev
Quoted 8 lines

The current implementation is potentially more flexible but makes the MSR handling a little more awkward since the host_initiated bool needs to be passed around (patch 09). I guess either approach seems ok to me.

Also, if this patchset is used then it looks like
HV_X64_MSR_CRASH_CTL_CONTENTS can be removed.

Quoted 6 lines

Paolo,

do you have any opinion on this? I prefer
configurable way but there is no problem
to enable it by default dropping 'hv_panic'
property.

I also prefer the configurable way. Would hv_panic prevent reboot-on-BSOD from rebooting the VM?

Paolo

#13 lore raw

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

Quoted 11 lines · Paolo Bonzini
Quoted 9 lines · Denis V. Lunev
Quoted 7 lines

The current implementation is potentially more flexible but makes the MSR handling a little more awkward since the host_initiated bool needs to be passed around (patch 09). I guess either approach seems ok to me.

Also, if this patchset is used then it looks like
HV_X64_MSR_CRASH_CTL_CONTENTS can be removed.

Paolo,

Quoted 8 lines
Quoted 4 lines

do you have any opinion on this? I prefer
configurable way but there is no problem
to enable it by default dropping 'hv_panic'
property.

I also prefer the configurable way. Would hv_panic prevent reboot-on-BSOD from rebooting the VM?

Paolo

the behavior becomes controlled by libvirt, which has appropriate event configuration, specified here
https://libvirt.org/formatdomain.html
namely
<on_crash>restart</on_crash>

Thus it looks like without libvirt help the guest will stuck in RUN_STATE_GUEST_PANICKED state.

Den

maintainer
#14 lore raw

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

Quoted 8 lines · Denis V. Lunev

the behavior becomes controlled by libvirt, which has appropriate event configuration, specified here
https://libvirt.org/formatdomain.html
namely
<on_crash>restart</on_crash>

Thus it looks like without libvirt help the guest will stuck in RUN_STATE_GUEST_PANICKED state.

Yes, exactly. So it's better to keep it user-configurable. We already made the same mistake with pvpanic.

Paolo

#15 lore raw

PATCH v2 8/11 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 set for vcpu. kvm_run structure will contain system_event with type equals to KVM_SYSTEM_EVENT_CRASH and flag KVM_SYSTEM_EVENT_FL_HV_CRASH to clarify that the crash occures inside Hyper-V based guest.

---
 arch/x86/kvm/x86.c       | 8 ++++++++
 include/uapi/linux/kvm.h | 2 ++
 2 files changed, 10 insertions(+)
arch/x86/kvm/x86.c +8 -0
index 2046b78..111fa83 100644
@@ -6027,6 +6027,14 @@ 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;
+			vcpu->run->system_event.flags =
+						KVM_SYSTEM_EVENT_FL_HV_CRASH;
+			r = 0;
+			goto out;
+		}
 	}
 
 	if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win) {
include/uapi/linux/kvm.h +2 -0
index 4b60056..22b6cca 100644
@@ -317,6 +317,8 @@ struct kvm_run {
 		struct {
 #define KVM_SYSTEM_EVENT_SHUTDOWN       1
 #define KVM_SYSTEM_EVENT_RESET          2
+#define KVM_SYSTEM_EVENT_CRASH          3
+#define KVM_SYSTEM_EVENT_FL_HV_CRASH    (1ULL << 0)
 			__u32 type;
 			__u64 flags;
 		} system_event;
Signature · 1 line
1.9.1
#16 lore raw

PATCH v2 9/11 kvm/x86: distingiush hyper-v guest crash notification

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

Previous patches allowes userspace to setup Hyper-V crash ctl msr. This msr should expose HV_X64_MSR_CRASH_CTL_NOTIFY value to Hyper-V guest to allow to send crash data. Unfortunately Hyper-V guest notifies hardware about crash by writing the same HV_X64_MSR_CRASH_CTL_NOTIFY value into crash ctl msr. Thus 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.

---
 arch/x86/kvm/hyperv.c | 17 +++++++++--------
 arch/x86/kvm/hyperv.h |  2 +-
 arch/x86/kvm/x86.c    |  3 ++-
 3 files changed, 12 insertions(+), 10 deletions(-)
arch/x86/kvm/hyperv.c +9 -8
index 6b18015..f49502a 100644
@@ -54,12 +54,12 @@ static int kvm_hv_msr_get_crash_ctl(struct kvm_vcpu *vcpu, u64 *pdata)
 	return 0;
 }
 
-static int kvm_hv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u64 data)
+static int kvm_hv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u64 data, bool host)
 {
 	struct kvm_arch_hyperv *hv = &vcpu->kvm->arch.hyperv;
 
 	hv->hv_crash_ctl = data;
-	if ((data & HV_X64_MSR_CRASH_CTL_NOTIFY)) {
+	if ((data & HV_X64_MSR_CRASH_CTL_NOTIFY) && !host) {
 		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],
@@ -99,7 +99,8 @@ static int kvm_hv_msr_get_crash_data(struct kvm_vcpu *vcpu,
 	return 0;
 }
 
-static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu,
+			     u32 msr, u64 data, bool host)
 {
 	struct kvm *kvm = vcpu->kvm;
 	struct kvm_arch_hyperv *hv = &kvm->arch.hyperv;
@@ -156,7 +157,7 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 						 msr - HV_X64_MSR_CRASH_P0,
 						 data);
 	case HV_X64_MSR_CRASH_CTL:
-		return kvm_hv_msr_set_crash_ctl(vcpu, data);
+		return kvm_hv_msr_set_crash_ctl(vcpu, data, host);
 	default:
 		vcpu_unimpl(vcpu, "Hyper-V unimpl wrmsr: 0x%x data 0x%llx\n",
 				  msr, data);
@@ -165,7 +166,7 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 	return 0;
 }
 
-static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 {
 	struct kvm_vcpu_arch_hyperv *hv = &vcpu->arch.hyperv;
 
@@ -278,17 +279,17 @@ 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
-		return kvm_hv_set_msr(vcpu, msr, data);
+		return kvm_hv_set_msr(vcpu, msr, data, host);
 }
 
 int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
arch/x86/kvm/hyperv.h +1 -1
index 39aee93..dc49527 100644
@@ -22,7 +22,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);
arch/x86/kvm/x86.c +2 -1
index 111fa83..db4eecb 100644
@@ -2210,7 +2210,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 	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_set_msr_common(vcpu, msr, data);
+		return kvm_hv_set_msr_common(vcpu, msr, data,
+					     msr_info->host_initiated);
 		break;
 	case MSR_IA32_BBL_CR_CTL3:
 		/* Drop writes to this legacy MSR -- see rdmsr
Signature · 1 line
1.9.1
maintainer
#17 lore raw

Re: [PATCH 09/11] kvm/x86: distingiush hyper-v guest crash notification

Quoted 107 lines · Denis V. Lunev

From: Andrey Smetanin <[email protected]>

Previous patches allowes userspace to setup Hyper-V crash ctl msr. This msr should expose HV_X64_MSR_CRASH_CTL_NOTIFY value to Hyper-V guest to allow to send crash data. Unfortunately Hyper-V guest notifies hardware about crash by writing the same HV_X64_MSR_CRASH_CTL_NOTIFY value into crash ctl msr. Thus 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.

---
 arch/x86/kvm/hyperv.c | 17 +++++++++--------
 arch/x86/kvm/hyperv.h |  2 +-
 arch/x86/kvm/x86.c    |  3 ++-
 3 files changed, 12 insertions(+), 10 deletions(-)
arch/x86/kvm/hyperv.c +9 -8
index 6b18015..f49502a 100644
@@ -54,12 +54,12 @@ static int kvm_hv_msr_get_crash_ctl(struct kvm_vcpu *vcpu, u64 *pdata)
 	return 0;
 }
 
-static int kvm_hv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u64 data)
+static int kvm_hv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u64 data, bool host)
 {
 	struct kvm_arch_hyperv *hv = &vcpu->kvm->arch.hyperv;
 
 	hv->hv_crash_ctl = data;
-	if ((data & HV_X64_MSR_CRASH_CTL_NOTIFY)) {
+	if ((data & HV_X64_MSR_CRASH_CTL_NOTIFY) && !host) {
 		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],
@@ -99,7 +99,8 @@ static int kvm_hv_msr_get_crash_data(struct kvm_vcpu *vcpu,
 	return 0;
 }
 
-static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu,
+			     u32 msr, u64 data, bool host)
 {
 	struct kvm *kvm = vcpu->kvm;
 	struct kvm_arch_hyperv *hv = &kvm->arch.hyperv;
@@ -156,7 +157,7 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 						 msr - HV_X64_MSR_CRASH_P0,
 						 data);
 	case HV_X64_MSR_CRASH_CTL:
-		return kvm_hv_msr_set_crash_ctl(vcpu, data);
+		return kvm_hv_msr_set_crash_ctl(vcpu, data, host);
 	default:
 		vcpu_unimpl(vcpu, "Hyper-V unimpl wrmsr: 0x%x data 0x%llx\n",
 				  msr, data);
@@ -165,7 +166,7 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 	return 0;
 }
 
-static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 {
 	struct kvm_vcpu_arch_hyperv *hv = &vcpu->arch.hyperv;
 
@@ -278,17 +279,17 @@ 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
-		return kvm_hv_set_msr(vcpu, msr, data);
+		return kvm_hv_set_msr(vcpu, msr, data, host);
 }
 
 int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
arch/x86/kvm/hyperv.h +1 -1
index 39aee93..dc49527 100644
@@ -22,7 +22,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);
arch/x86/kvm/x86.c +0 -0
index 111fa83..db4eecb 100644

arch/x86/kvm/x86.c int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) · line 2217

Quoted 9 lines
arch/x86/kvm/x86.c +2 -1
@@ -2210,7 +2210,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 	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_set_msr_common(vcpu, msr, data);
+		return kvm_hv_set_msr_common(vcpu, msr, data,
+					     msr_info->host_initiated);
 		break;
 	case MSR_IA32_BBL_CR_CTL3:
 		/* Drop writes to this legacy MSR -- see rdmsr

This has to be squashed into patch 7. The patches looked good so far, so I can do this myself, but I'm dropping a note here in case I find something on a second read and you need to do a v3.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in

#18 lore raw

Re: [PATCH 09/11] kvm/x86: distingiush hyper-v guest crash notification

In reply to Denis V. Lunev
Quoted 25 lines · Denis V. Lunev

From: Andrey Smetanin <[email protected]>

Previous patches allowes userspace to setup Hyper-V crash ctl msr. This msr should expose HV_X64_MSR_CRASH_CTL_NOTIFY value to Hyper-V guest to allow to send crash data. Unfortunately Hyper-V guest notifies hardware about crash by writing the same HV_X64_MSR_CRASH_CTL_NOTIFY value into crash ctl msr. Thus 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.

---
 arch/x86/kvm/hyperv.c | 17 +++++++++--------
 arch/x86/kvm/hyperv.h |  2 +-
 arch/x86/kvm/x86.c    |  3 ++-
 3 files changed, 12 insertions(+), 10 deletions(-)
arch/x86/kvm/hyperv.c +0 -0
index 6b18015..f49502a 100644

arch/x86/kvm/hyperv.c static int kvm_hv_msr_get_crash_ctl(struct kvm_vcpu *vcpu, u64 *pdata) · line 61

Quoted 9 lines
arch/x86/kvm/hyperv.c +1 -1
@@ -54,12 +54,12 @@ static int kvm_hv_msr_get_crash_ctl(struct kvm_vcpu *vcpu, u64 *pdata)
        return 0;
 }
 
-static int kvm_hv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u64 data)
+static int kvm_hv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u64 data, bool host)
 {
        struct kvm_arch_hyperv *hv = &vcpu->kvm->arch.hyperv;
 
        hv->hv_crash_ctl = data;

Should we allow hv_crash_ctl to be set if !host? It's a small detail, but it doesn't seem like the guest should be able to disable crash actions that userspace has enabled in hv_crash_ctl.

Quoted 84 lines
arch/x86/kvm/hyperv.c +8 -7
-       if ((data & HV_X64_MSR_CRASH_CTL_NOTIFY)) {
+       if ((data & HV_X64_MSR_CRASH_CTL_NOTIFY) && !host) {
                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],
@@ -99,7 +99,8 @@ static int kvm_hv_msr_get_crash_data(struct kvm_vcpu *vcpu,
        return 0;
 }
 
-static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu,
+                            u32 msr, u64 data, bool host)
 {
        struct kvm *kvm = vcpu->kvm;
        struct kvm_arch_hyperv *hv = &kvm->arch.hyperv;
@@ -156,7 +157,7 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
                                                 msr - HV_X64_MSR_CRASH_P0,
                                                 data);
        case HV_X64_MSR_CRASH_CTL:
-               return kvm_hv_msr_set_crash_ctl(vcpu, data);
+               return kvm_hv_msr_set_crash_ctl(vcpu, data, host);
        default:
                vcpu_unimpl(vcpu, "Hyper-V unimpl wrmsr: 0x%x data 0x%llx\n",
                                  msr, data);
@@ -165,7 +166,7 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
        return 0;
 }
 
-static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 {
        struct kvm_vcpu_arch_hyperv *hv = &vcpu->arch.hyperv;
 
@@ -278,17 +279,17 @@ 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
-               return kvm_hv_set_msr(vcpu, msr, data);
+               return kvm_hv_set_msr(vcpu, msr, data, host);
 }
 
 int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
arch/x86/kvm/hyperv.h +1 -1
index 39aee93..dc49527 100644
@@ -22,7 +22,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);
arch/x86/kvm/x86.c +2 -2
index 111fa83..db4eecb 100644
@@ -2210,7 +2210,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
        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_set_msr_common(vcpu, msr, data);
+               return kvm_hv_set_msr_common(vcpu, msr, data,
+                                            msr_info->host_initiated);
                break;
        case MSR_IA32_BBL_CR_CTL3:
                /* Drop writes to this legacy MSR -- see rdmsr
--

1.9.1

Quoted 2 lines

--
To unsubscribe from this list: send the line "unsubscribe kvm" in

--
To unsubscribe from this list: send the line "unsubscribe kvm" in

maintainer
#19 lore raw

Re: [PATCH 09/11] kvm/x86: distingiush hyper-v guest crash notification

Quoted 9 lines · Peter Hornyack
Quoted 6 lines

arch/x86/kvm/hyperv.c static int kvm_hv_msr_get_crash_ctl(struct kvm_vcpu *vcpu, u64 *pdata) · line 61

Quoted 6 lines
arch/x86/kvm/hyperv.c +1 -1
-static int kvm_hv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u64 data)
+static int kvm_hv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u64 data, bool host)
 {
        struct kvm_arch_hyperv *hv = &vcpu->kvm->arch.hyperv;
 
        hv->hv_crash_ctl = data;

Should we allow hv_crash_ctl to be set if !host? It's a small detail, but it doesn't seem like the guest should be able to disable crash actions that userspace has enabled in hv_crash_ctl.

No, the MSR contents shouldn't be writable.

Paolo

#20 lore raw

PATCH v2 10/11 qemu/kvm: kvm hyper-v based guest crash event handling

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

KVM Hyper-V based guests can notify hypervisor about occurred guest crash. This patch does handling of KVM crash event by sending to libvirt guest panic event that allows to gather guest crash dump by QEMU/LIBVIRT. Add support of HV_X64_MSR_CRASH_P0-P4, HV_X64_MSR_CRASH_CTL msrs.

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.

---
 include/sysemu/kvm.h           |  2 ++
 include/sysemu/sysemu.h        |  1 +
 kvm-all.c                      |  7 ++++
 linux-headers/asm-x86/hyperv.h | 16 +++++++++
 linux-headers/linux/kvm.h      |  2 ++
 target-arm/kvm.c               |  5 +++
 target-i386/cpu-qom.h          |  1 +
 target-i386/cpu.c              |  1 +
 target-i386/cpu.h              |  3 ++
 target-i386/kvm.c              | 80 ++++++++++++++++++++++++++++++++++++++++++
 target-i386/machine.c          | 23 ++++++++++++
 target-mips/kvm.c              |  5 +++
 target-ppc/kvm.c               |  5 +++
 target-s390x/kvm.c             |  5 +++
 vl.c                           |  6 ++++
 15 files changed, 162 insertions(+)
include/sysemu/kvm.h +2 -0
index f459fbd..3c0fa02 100644
@@ -257,6 +257,8 @@ extern const KVMCapabilityInfo kvm_arch_required_capabilities[];
 void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run);
 MemTxAttrs kvm_arch_post_run(CPUState *cpu, struct kvm_run *run);
 
+int kvm_arch_handle_hv_crash(CPUState *cpu);
+
 int kvm_arch_handle_exit(CPUState *cpu, struct kvm_run *run);
 
 int kvm_arch_process_async_events(CPUState *cpu);
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);
kvm-all.c +7 -0
index 53e01d4..1528fb5 100644
@@ -1844,6 +1844,13 @@ int kvm_cpu_exec(CPUState *cpu)
                 qemu_system_reset_request();
                 ret = EXCP_INTERRUPT;
                 break;
+            case KVM_SYSTEM_EVENT_CRASH:
+                if (run->system_event.flags & KVM_SYSTEM_EVENT_FL_HV_CRASH) {
+                    kvm_arch_handle_hv_crash(cpu);
+                }
+                qemu_system_guest_panicked();
+                ret = 0;
+                break;
             default:
                 DPRINTF("kvm_arch_handle_exit\n");
                 ret = kvm_arch_handle_exit(cpu, run);
linux-headers/asm-x86/hyperv.h +16 -0
index ce6068d..aec7d27 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,20 @@
 #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_CTL_CONTENTS	\
+		(HV_X64_MSR_CRASH_CTL_NOTIFY)
+
+#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	\
linux-headers/linux/kvm.h +2 -0
index fad9e5c..46cb7e0 100644
@@ -317,6 +317,8 @@ struct kvm_run {
 		struct {
 #define KVM_SYSTEM_EVENT_SHUTDOWN       1
 #define KVM_SYSTEM_EVENT_RESET          2
+#define KVM_SYSTEM_EVENT_CRASH          3
+#define KVM_SYSTEM_EVENT_FL_HV_CRASH    (1ULL << 0)
 			__u32 type;
 			__u64 flags;
 		} system_event;
target-arm/kvm.c +5 -0
index 548bfd7..c19899e 100644
@@ -512,6 +512,11 @@ MemTxAttrs kvm_arch_post_run(CPUState *cs, struct kvm_run *run)
     return MEMTXATTRS_UNSPECIFIED;
 }
 
+int kvm_arch_handle_hv_crash(CPUState *cs)
+{
+    return 0;
+}
+
 int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 {
     return 0;
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 4e7cdaa..af0552a 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 +3 -0
index 603aaf0..474a93e 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,8 @@ 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];
+    uint64_t msr_hv_crash_ctl;
 
     /* exception/interrupt handling */
     int error_code;
target-i386/kvm.c +80 -0

122 lines not on this page · raw message

target-i386/machine.c +23 -0
index a0df64b..15b3f31 100644
@@ -661,6 +661,28 @@ static const VMStateDescription vmstate_msr_hyperv_time = {
     }
 };
 
+static bool hyperv_crash_enable_needed(void *opaque)
+{
+    X86CPU *cpu = opaque;
+    CPUX86State *env = &cpu->env;
+
+    return (env->msr_hv_crash_ctl & HV_X64_MSR_CRASH_CTL_CONTENTS) ?
+            true : 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(env.msr_hv_crash_ctl, X86CPU),
+        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 +864,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
target-mips/kvm.c +5 -0
index 948619f..1ac7732 100644
@@ -122,6 +122,11 @@ int kvm_arch_process_async_events(CPUState *cs)
     return cs->halted;
 }
 
+int kvm_arch_handle_hv_crash(CPUState *cs)
+{
+    return 0;
+}
+
 int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 {
     int ret;
target-ppc/kvm.c +5 -0
index afb4696..af34198 100644
@@ -1564,6 +1564,11 @@ static int kvm_handle_debug(PowerPCCPU *cpu, struct kvm_run *run)
     return handle;
 }
 
+int kvm_arch_handle_hv_crash(CPUState *cs)
+{
+    return 0;
+}
+
 int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 {
     PowerPCCPU *cpu = POWERPC_CPU(cs);
target-s390x/kvm.c +5 -0
index b02ff8d..07d0914 100644
@@ -2002,6 +2002,11 @@ static int kvm_arch_handle_debug_exit(S390CPU *cpu)
     return ret;
 }
 
+int kvm_arch_handle_hv_crash(CPUState *cs)
+{
+    return 0;
+}
+
 int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 {
     S390CPU *cpu = S390_CPU(cs);
vl.c +6 -0
index 1a920e6..9b60f95 100644
@@ -1725,6 +1725,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
1.9.1
maintainer
#21 lore raw

Re: [PATCH 10/11] qemu/kvm: kvm hyper-v based guest crash event handling

vl.c void qemu_system_reset(bool report) · line 1733

Quoted 6 lines · Denis V. Lunev
vl.c +6 -0
+void qemu_system_guest_panicked(void)
+{
+    qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE, &error_abort);
+    vm_stop(RUN_STATE_GUEST_PANICKED);
+}
+

Please call this in pvpanic.c and target-s390x/kvm.c (replacing the guest_panicked function in that file there) as well.

Quoted 41 lines
target-i386/kvm.c +37 -0
@@ -2540,6 +2573,53 @@ static bool host_supports_vmx(void)
     return ecx & CPUID_EXT_VMX;
 }
 
+int kvm_arch_handle_hv_crash(CPUState *cs)
+{
+    X86CPU *cpu = X86_CPU(cs);
+    CPUX86State *env = &cpu->env;
+    struct {
+        struct kvm_msrs info;
+        struct kvm_msr_entry entries[HV_X64_MSR_CRASH_PARAMS + 1];
+    } msr_data;
+    struct kvm_msr_entry *msrs = msr_data.entries;
+    int ret, n, i;
+
+    if (!has_msr_hv_crash) {
+        return -EINVAL;
+    }
+
+    for (n = 0; n < HV_X64_MSR_CRASH_PARAMS; n++) {
+        msrs[n].index = HV_X64_MSR_CRASH_P0 + n;
+    }
+
+    msrs[n++].index = HV_X64_MSR_CRASH_CTL;
+    msr_data.info = (struct kvm_msrs) {
+        .nmsrs = n,
+    };
+
+    ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, &msr_data);
+    if (ret < 0) {
+        return ret;
+    }
+
+    for (i = 0; i < ret; i++) {
+        uint32_t index = msrs[i].index;
+
+        switch (index) {
+        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 HV_X64_MSR_CRASH_CTL:

target-i386/kvm.c static bool host_supports_vmx(void) · line 2622

Quoted 10 lines
target-i386/kvm.c +10 -0
+            env->msr_hv_crash_ctl = msrs[i].data;
+            break;
+        default:
+            break;
+        }
+    }
+
+    return 0;
+}
+

Is this necessary? The call to cpu_synchronize_all_states in qemu_savevm_state_complete should be enough. If necessary, you can call it from qemu_system_guest_panicked instead of special casing the crash MSRs here.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in

maintainer
#22 lore raw

Re: [PATCH 10/11] qemu/kvm: kvm hyper-v based guest crash event handling

In reply to Denis V. Lunev

Another one...

kvm-all.c int kvm_cpu_exec(CPUState *cpu) · line 1851

Quoted 5 lines · Denis V. Lunev
kvm-all.c +5 -0
+            case KVM_SYSTEM_EVENT_CRASH:
+                if (run->system_event.flags & KVM_SYSTEM_EVENT_FL_HV_CRASH) {
+                    kvm_arch_handle_hv_crash(cpu);
+                }
+                qemu_system_guest_panicked();

Please call

	kvm_arch_handle_crash(cpu);
	qemu_system_guest_panicked();

here, and check the HV_CRASH flag inside x86 specific code.

Paolo

kvm-all.c int kvm_cpu_exec(CPUState *cpu) · line 1853

Quoted 2 lines
kvm-all.c +2 -0
+                ret = 0;
+                break;

--
To unsubscribe from this list: send the line "unsubscribe kvm" in

#23 lore raw

PATCH v2 11/11 qemu/kvm: mark in cpu state that hyper-v crash occured

In reply to Denis V. Lunev

From: Andrey Smetanin <[email protected]>

It's usually impossible to understand from Hyper-V crash msr's that crash happened because ctl msr always contains the same value HV_X64_MSR_CRASH_CTL_NOTIFY. To solve it add a particalar value hv_crash_occurred inside CPU state and migrate this value with crash msr's.

---
 target-i386/cpu.h     | 1 +
 target-i386/kvm.c     | 1 +
 target-i386/machine.c | 1 +
 3 files changed, 3 insertions(+)
target-i386/cpu.h +1 -0
index 474a93e..2958cdc 100644
@@ -907,6 +907,7 @@ typedef struct CPUX86State {
     uint64_t msr_hv_tsc;
     uint64_t msr_hv_crash_prm[HV_X64_MSR_CRASH_PARAMS];
     uint64_t msr_hv_crash_ctl;
+    uint8_t hv_crash_occurred;
 
     /* exception/interrupt handling */
     int error_code;
target-i386/kvm.c +1 -0
index 690677b..2c8d00f 100644
@@ -2616,6 +2616,7 @@ int kvm_arch_handle_hv_crash(CPUState *cs)
             break;
         }
     }
+    env->hv_crash_occurred = 1;
 
     return 0;
 }
target-i386/machine.c +1 -0
index 15b3f31..4f72ba8 100644
@@ -679,6 +679,7 @@ static const VMStateDescription vmstate_msr_hyperv_crash = {
         VMSTATE_UINT64(env.msr_hv_crash_ctl, X86CPU),
         VMSTATE_UINT64_ARRAY(env.msr_hv_crash_prm,
                              X86CPU, HV_X64_MSR_CRASH_PARAMS),
+        VMSTATE_UINT8(env.hv_crash_occurred, X86CPU),
         VMSTATE_END_OF_LIST()
     }
 };
Signature · 1 line
1.9.1
#24 lore raw

Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured

Am 22.06.2015 um 18:05 schrieb Denis V. Lunev:

Quoted 13 lines

From: Andrey Smetanin <[email protected]>

It's usually impossible to understand from Hyper-V crash msr's that crash happened because ctl msr always contains the same value HV_X64_MSR_CRASH_CTL_NOTIFY. To solve it add a particalar value hv_crash_occurred inside CPU state and migrate this value with crash msr's.

---

[...]

target-i386/machine.c static const VMStateDescription vmstate_msr_hyperv_crash = { · line 685

Quoted 12 lines
target-i386/machine.c +1 -0
index 15b3f31..4f72ba8 100644
@@ -679,6 +679,7 @@ static const VMStateDescription vmstate_msr_hyperv_crash = {
         VMSTATE_UINT64(env.msr_hv_crash_ctl, X86CPU),
         VMSTATE_UINT64_ARRAY(env.msr_hv_crash_prm,
                              X86CPU, HV_X64_MSR_CRASH_PARAMS),
+        VMSTATE_UINT8(env.hv_crash_occurred, X86CPU),
         VMSTATE_END_OF_LIST()
     }
 };

This looks like a migration format breakage. You probably need to squash it with the preceding patch so that the "cpu/msr_hyperv_crash" subsection does not change in size between commits. Just incrementing the version is not an option for subsections, I think?

Regards,
Andreas

Signature · 5 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
maintainer
#25 lore raw

Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured

Quoted 4 lines · Andreas Färber
Quoted 4 lines
Quoted 4 lines
target-i386/machine.c +0 -0
@@ -679,6 +679,7 @@ static const VMStateDescription vmstate_msr_hyperv_crash = {
         VMSTATE_UINT64(env.msr_hv_crash_ctl, X86CPU),
         VMSTATE_UINT64_ARRAY(env.msr_hv_crash_prm,
                              X86CPU, HV_X64_MSR_CRASH_PARAMS),
Quoted 8 lines
Quoted 4 lines

target-i386/machine.c static const VMStateDescription vmstate_msr_hyperv_crash = { · line 685

Quoted 4 lines
target-i386/machine.c +1 -0
+        VMSTATE_UINT8(env.hv_crash_occurred, X86CPU),
         VMSTATE_END_OF_LIST()
     }
 };

This looks like a migration format breakage. You probably need to squash it with the preceding patch so that the "cpu/msr_hyperv_crash" subsection does not change in size between commits. Just incrementing the version is not an option for subsections, I think?

We don't usually care about migration format within the same upstream release, but yes that would be better.

On the other hand, I wonder if current_cpu is available in qemu_system_guest_panicked. If so, you could add the field to the generic CPUState struct and migrate it as a subsection of vmstate_cpu_common.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in

#26 lore raw

Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured

Am 22.06.2015 um 18:27 schrieb Paolo Bonzini:

Quoted 4 lines

On the other hand, I wonder if current_cpu is available in qemu_system_guest_panicked. If so, you could add the field to the generic CPUState struct and migrate it as a subsection of vmstate_cpu_common.

Hm, not sure whether it is.

Would that work with the two ways we use vmstate_cpu_common though? I.e., can a nested VMState struct (VMSTATE_CPU()) have subsections?

Regards,
Andreas

Signature · 5 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
#27 lore raw

Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured

Quoted 5 lines · Andreas Färber

Am 22.06.2015 um 18:27 schrieb Paolo Bonzini:

Quoted 4 lines

On the other hand, I wonder if current_cpu is available in qemu_system_guest_panicked. If so, you could add the field to the generic CPUState struct and migrate it as a subsection of vmstate_cpu_common.

Quoted 8 lines

Hm, not sure whether it is.

Would that work with the two ways we use vmstate_cpu_common though? I.e., can a nested VMState struct (VMSTATE_CPU()) have subsections?

Regards,
Andreas

we'd better squash to avoid troubles. Any other issues? --
To unsubscribe from this list: send the line "unsubscribe kvm" in

maintainer
#28 lore raw

Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured

In reply to Andreas Färber
Quoted 5 lines · Andreas Färber
Quoted 4 lines
Quoted 4 lines

On the other hand, I wonder if current_cpu is available in qemu_system_guest_panicked. If so, you could add the field to the generic CPUState struct and migrate it as a subsection of vmstate_cpu_common.

Hm, not sure whether it is.

It should be...

Quoted 2 lines

Would that work with the two ways we use vmstate_cpu_common though? I.e., can a nested VMState struct (VMSTATE_CPU()) have subsections?

Yes, it can.

Paolo

#29 lore raw

Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured

Am 22.06.2015 um 18:36 schrieb Paolo Bonzini:

Quoted 8 lines · Andreas Färber
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

On the other hand, I wonder if current_cpu is available in qemu_system_guest_panicked. If so, you could add the field to the generic CPUState struct and migrate it as a subsection of vmstate_cpu_common.

Hm, not sure whether it is.

It should be...

Obviously depends on the call site. :) At some point in cpu-exec.c, current_cpu gets set to NULL. So the function would at least deserve a comment on when (not to) use it.

Cheers,
Andreas

Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)
maintainer
#30 lore raw

Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured

Quoted 10 lines · Andreas Färber
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

On the other hand, I wonder if current_cpu is available in qemu_system_guest_panicked. If so, you could add the field to the generic CPUState struct and migrate it as a subsection of vmstate_cpu_common.

Hm, not sure whether it is.

It should be...

Obviously depends on the call site. :) At some point in cpu-exec.c, current_cpu gets set to NULL. So the function would at least deserve a comment on when (not to) use it.

I think it could be used anyway even if current_cpu. The difference would be whether the crash is attached to a CPU or not.

Paolo