All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/11] HyperV equivalent of pvpanic driver
@ 2015-06-22 16:04 ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:04 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Andrey Smetanin, Denis V. Lunev, Gleb Natapov,
	Paolo Bonzini

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

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Gleb Natapov <gleb@kernel.org>
CC: Paolo Bonzini <pbonzini@redhat.com>

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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH v2 0/11] HyperV equivalent of pvpanic driver
@ 2015-06-22 16:04 ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:04 UTC (permalink / raw)
  Cc: kvm, Gleb Natapov, qemu-devel, Paolo Bonzini, Andrey Smetanin,
	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 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

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Gleb Natapov <gleb@kernel.org>
CC: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [PATCH 01/11] kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file
  2015-06-22 16:04 ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:04   ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:04 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Andrey Smetanin, Denis V. Lunev, Paolo Bonzini,
	Gleb Natapov

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 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

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index f4a555b..717a03c 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -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;
diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
index 16e8f96..944c8c8 100644
--- a/arch/x86/kvm/Makefile
+++ b/arch/x86/kvm/Makefile
@@ -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
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
new file mode 100644
index 0000000..0d24d9a
--- /dev/null
+++ b/arch/x86/kvm/hyperv.c
@@ -0,0 +1,303 @@
+/*
+ * 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 <asmetanin@virtuozzo.com>
+ *
+ * Authors:
+ *   Avi Kivity   <avi@qumranet.com>
+ *   Yaniv Kamay  <yaniv@qumranet.com>
+ *   Amit Shah    <amit.shah@qumranet.com>
+ *   Ben-Ami Yassour <benami@il.ibm.com>
+ *   Andrey Smetanin <asmetanin@virtuozzo.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "x86.h"
+#include "lapic.h"
+#include "hyperv.h"
+
+#include <linux/kvm_host.h>
+#include <trace/events/kvm.h>
+
+#include "trace.h"
+
+static bool kvm_hv_msr_partition_wide(u32 msr)
+{
+	bool r = false;
+
+	switch (msr) {
+	case HV_X64_MSR_GUEST_OS_ID:
+	case HV_X64_MSR_HYPERCALL:
+	case HV_X64_MSR_REFERENCE_TSC:
+	case HV_X64_MSR_TIME_REF_COUNT:
+		r = true;
+		break;
+	}
+
+	return r;
+}
+
+static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+{
+	struct kvm *kvm = vcpu->kvm;
+	struct kvm_arch_hyperv *hv = &kvm->arch.hyperv;
+
+	switch (msr) {
+	case HV_X64_MSR_GUEST_OS_ID:
+		hv->hv_guest_os_id = data;
+		/* setting guest os id to zero disables hypercall page */
+		if (!hv->hv_guest_os_id)
+			hv->hv_hypercall &= ~HV_X64_MSR_HYPERCALL_ENABLE;
+		break;
+	case HV_X64_MSR_HYPERCALL: {
+		u64 gfn;
+		unsigned long addr;
+		u8 instructions[4];
+
+		/* if guest os id is not set hypercall should remain disabled */
+		if (!hv->hv_guest_os_id)
+			break;
+		if (!(data & HV_X64_MSR_HYPERCALL_ENABLE)) {
+			hv->hv_hypercall = data;
+			break;
+		}
+		gfn = data >> HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
+		addr = gfn_to_hva(kvm, gfn);
+		if (kvm_is_error_hva(addr))
+			return 1;
+		kvm_x86_ops->patch_hypercall(vcpu, instructions);
+		((unsigned char *)instructions)[3] = 0xc3; /* ret */
+		if (__copy_to_user((void __user *)addr, instructions, 4))
+			return 1;
+		hv->hv_hypercall = data;
+		mark_page_dirty(kvm, gfn);
+		break;
+	}
+	case HV_X64_MSR_REFERENCE_TSC: {
+		u64 gfn;
+		HV_REFERENCE_TSC_PAGE tsc_ref;
+
+		memset(&tsc_ref, 0, sizeof(tsc_ref));
+		hv->hv_tsc_page = data;
+		if (!(data & HV_X64_MSR_TSC_REFERENCE_ENABLE))
+			break;
+		gfn = data >> HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT;
+		if (kvm_write_guest(kvm,
+			gfn << HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT,
+			&tsc_ref, sizeof(tsc_ref)))
+			return 1;
+		mark_page_dirty(kvm, gfn);
+		break;
+	}
+	default:
+		vcpu_unimpl(vcpu, "Hyper-V unimpl wrmsr: 0x%x data 0x%llx\n",
+				  msr, data);
+		return 1;
+	}
+	return 0;
+}
+
+static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+{
+	struct kvm_vcpu_arch_hyperv *hv = &vcpu->arch.hyperv;
+
+	switch (msr) {
+	case HV_X64_MSR_APIC_ASSIST_PAGE: {
+		u64 gfn;
+		unsigned long addr;
+
+		if (!(data & HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE)) {
+			hv->hv_vapic = data;
+			if (kvm_lapic_enable_pv_eoi(vcpu, 0))
+				return 1;
+			break;
+		}
+		gfn = data >> HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT;
+		addr = gfn_to_hva(vcpu->kvm, gfn);
+		if (kvm_is_error_hva(addr))
+			return 1;
+		if (__clear_user((void __user *)addr, PAGE_SIZE))
+			return 1;
+		hv->hv_vapic = data;
+		mark_page_dirty(vcpu->kvm, gfn);
+		if (kvm_lapic_enable_pv_eoi(vcpu,
+					    gfn_to_gpa(gfn) | KVM_MSR_ENABLED))
+			return 1;
+		break;
+	}
+	case HV_X64_MSR_EOI:
+		return kvm_hv_vapic_msr_write(vcpu, APIC_EOI, data);
+	case HV_X64_MSR_ICR:
+		return kvm_hv_vapic_msr_write(vcpu, APIC_ICR, data);
+	case HV_X64_MSR_TPR:
+		return kvm_hv_vapic_msr_write(vcpu, APIC_TASKPRI, data);
+	default:
+		vcpu_unimpl(vcpu, "Hyper-V unimpl wrmsr: 0x%x data 0x%llx\n",
+				  msr, data);
+		return 1;
+	}
+
+	return 0;
+}
+
+static int kvm_hv_get_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
+{
+	u64 data = 0;
+	struct kvm *kvm = vcpu->kvm;
+	struct kvm_arch_hyperv *hv = &kvm->arch.hyperv;
+
+	switch (msr) {
+	case HV_X64_MSR_GUEST_OS_ID:
+		data = hv->hv_guest_os_id;
+		break;
+	case HV_X64_MSR_HYPERCALL:
+		data = hv->hv_hypercall;
+		break;
+	case HV_X64_MSR_TIME_REF_COUNT: {
+		data =
+		     div_u64(get_kernel_ns() + kvm->arch.kvmclock_offset, 100);
+		break;
+	}
+	case HV_X64_MSR_REFERENCE_TSC:
+		data = hv->hv_tsc_page;
+		break;
+	default:
+		vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
+		return 1;
+	}
+
+	*pdata = data;
+	return 0;
+}
+
+static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
+{
+	u64 data = 0;
+
+	switch (msr) {
+	case HV_X64_MSR_VP_INDEX: {
+		int r;
+		struct kvm_vcpu *v;
+
+		kvm_for_each_vcpu(r, v, vcpu->kvm) {
+			if (v == vcpu) {
+				data = r;
+				break;
+			}
+		}
+		break;
+	}
+	case HV_X64_MSR_EOI:
+		return kvm_hv_vapic_msr_read(vcpu, APIC_EOI, pdata);
+	case HV_X64_MSR_ICR:
+		return kvm_hv_vapic_msr_read(vcpu, APIC_ICR, pdata);
+	case HV_X64_MSR_TPR:
+		return kvm_hv_vapic_msr_read(vcpu, APIC_TASKPRI, pdata);
+	case HV_X64_MSR_APIC_ASSIST_PAGE:
+		data = vcpu->arch.hyperv.hv_vapic;
+		break;
+	default:
+		vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
+		return 1;
+	}
+	*pdata = data;
+	return 0;
+}
+
+int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+{
+	if (kvm_hv_msr_partition_wide(msr)) {
+		int r;
+
+		mutex_lock(&vcpu->kvm->lock);
+		r = kvm_hv_set_msr_pw(vcpu, msr, data);
+		mutex_unlock(&vcpu->kvm->lock);
+		return r;
+	} else
+		return kvm_hv_set_msr(vcpu, msr, data);
+}
+
+int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
+{
+	if (kvm_hv_msr_partition_wide(msr)) {
+		int r;
+
+		mutex_lock(&vcpu->kvm->lock);
+		r = kvm_hv_get_msr_pw(vcpu, msr, pdata);
+		mutex_unlock(&vcpu->kvm->lock);
+		return r;
+	} else
+		return kvm_hv_get_msr(vcpu, msr, pdata);
+}
+
+bool kvm_hv_hypercall_enabled(struct kvm *kvm)
+{
+	return kvm->arch.hyperv.hv_hypercall & HV_X64_MSR_HYPERCALL_ENABLE;
+}
+
+int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
+{
+	u64 param, ingpa, outgpa, ret;
+	uint16_t code, rep_idx, rep_cnt, res = HV_STATUS_SUCCESS, rep_done = 0;
+	bool fast, longmode;
+
+	/*
+	 * hypercall generates UD from non zero cpl and real mode
+	 * per HYPER-V spec
+	 */
+	if (kvm_x86_ops->get_cpl(vcpu) != 0 || !is_protmode(vcpu)) {
+		kvm_queue_exception(vcpu, UD_VECTOR);
+		return 0;
+	}
+
+	longmode = is_64_bit_mode(vcpu);
+
+	if (!longmode) {
+		param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) |
+			(kvm_register_read(vcpu, VCPU_REGS_RAX) & 0xffffffff);
+		ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
+			(kvm_register_read(vcpu, VCPU_REGS_RCX) & 0xffffffff);
+		outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
+			(kvm_register_read(vcpu, VCPU_REGS_RSI) & 0xffffffff);
+	}
+#ifdef CONFIG_X86_64
+	else {
+		param = kvm_register_read(vcpu, VCPU_REGS_RCX);
+		ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
+		outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
+	}
+#endif
+
+	code = param & 0xffff;
+	fast = (param >> 16) & 0x1;
+	rep_cnt = (param >> 32) & 0xfff;
+	rep_idx = (param >> 48) & 0xfff;
+
+	trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa);
+
+	switch (code) {
+	case HV_X64_HV_NOTIFY_LONG_SPIN_WAIT:
+		kvm_vcpu_on_spin(vcpu);
+		break;
+	default:
+		res = HV_STATUS_INVALID_HYPERCALL_CODE;
+		break;
+	}
+
+	ret = res | (((u64)rep_done & 0xfff) << 32);
+	if (longmode) {
+		kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
+	} else {
+		kvm_register_write(vcpu, VCPU_REGS_RDX, ret >> 32);
+		kvm_register_write(vcpu, VCPU_REGS_RAX, ret & 0xffffffff);
+	}
+
+	return 1;
+}
diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
new file mode 100644
index 0000000..39aee93
--- /dev/null
+++ b/arch/x86/kvm/hyperv.h
@@ -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 <asmetanin@virtuozzo.com>
+ *
+ * Authors:
+ *   Avi Kivity   <avi@qumranet.com>
+ *   Yaniv Kamay  <yaniv@qumranet.com>
+ *   Amit Shah    <amit.shah@qumranet.com>
+ *   Ben-Ami Yassour <benami@il.ibm.com>
+ *   Andrey Smetanin <asmetanin@virtuozzo.com>
+ *
+ * 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
diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index 9d28383..2891d2e 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -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);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index ea306ad..2755c37 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -28,6 +28,7 @@
 #include "x86.h"
 #include "cpuid.h"
 #include "assigned-dev.h"
+#include "hyperv.h"
 
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>
@@ -1193,11 +1194,6 @@ static void kvm_get_time_scale(uint32_t scaled_khz, uint32_t base_khz,
 		 __func__, base_khz, scaled_khz, shift, *pmultiplier);
 }
 
-static inline u64 get_kernel_ns(void)
-{
-	return ktime_get_boot_ns();
-}
-
 #ifdef CONFIG_X86_64
 static atomic_t kvm_guest_has_master_clock = ATOMIC_INIT(0);
 #endif
@@ -1956,123 +1952,6 @@ out:
 	return r;
 }
 
-static bool kvm_hv_hypercall_enabled(struct kvm *kvm)
-{
-	return kvm->arch.hv_hypercall & HV_X64_MSR_HYPERCALL_ENABLE;
-}
-
-static bool kvm_hv_msr_partition_wide(u32 msr)
-{
-	bool r = false;
-	switch (msr) {
-	case HV_X64_MSR_GUEST_OS_ID:
-	case HV_X64_MSR_HYPERCALL:
-	case HV_X64_MSR_REFERENCE_TSC:
-	case HV_X64_MSR_TIME_REF_COUNT:
-		r = true;
-		break;
-	}
-
-	return r;
-}
-
-static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
-{
-	struct kvm *kvm = vcpu->kvm;
-
-	switch (msr) {
-	case HV_X64_MSR_GUEST_OS_ID:
-		kvm->arch.hv_guest_os_id = data;
-		/* setting guest os id to zero disables hypercall page */
-		if (!kvm->arch.hv_guest_os_id)
-			kvm->arch.hv_hypercall &= ~HV_X64_MSR_HYPERCALL_ENABLE;
-		break;
-	case HV_X64_MSR_HYPERCALL: {
-		u64 gfn;
-		unsigned long addr;
-		u8 instructions[4];
-
-		/* if guest os id is not set hypercall should remain disabled */
-		if (!kvm->arch.hv_guest_os_id)
-			break;
-		if (!(data & HV_X64_MSR_HYPERCALL_ENABLE)) {
-			kvm->arch.hv_hypercall = data;
-			break;
-		}
-		gfn = data >> HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
-		addr = gfn_to_hva(kvm, gfn);
-		if (kvm_is_error_hva(addr))
-			return 1;
-		kvm_x86_ops->patch_hypercall(vcpu, instructions);
-		((unsigned char *)instructions)[3] = 0xc3; /* ret */
-		if (__copy_to_user((void __user *)addr, instructions, 4))
-			return 1;
-		kvm->arch.hv_hypercall = data;
-		mark_page_dirty(kvm, gfn);
-		break;
-	}
-	case HV_X64_MSR_REFERENCE_TSC: {
-		u64 gfn;
-		HV_REFERENCE_TSC_PAGE tsc_ref;
-		memset(&tsc_ref, 0, sizeof(tsc_ref));
-		kvm->arch.hv_tsc_page = data;
-		if (!(data & HV_X64_MSR_TSC_REFERENCE_ENABLE))
-			break;
-		gfn = data >> HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT;
-		if (kvm_write_guest(kvm, gfn << HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT,
-			&tsc_ref, sizeof(tsc_ref)))
-			return 1;
-		mark_page_dirty(kvm, gfn);
-		break;
-	}
-	default:
-		vcpu_unimpl(vcpu, "HYPER-V unimplemented wrmsr: 0x%x "
-			    "data 0x%llx\n", msr, data);
-		return 1;
-	}
-	return 0;
-}
-
-static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)
-{
-	switch (msr) {
-	case HV_X64_MSR_APIC_ASSIST_PAGE: {
-		u64 gfn;
-		unsigned long addr;
-
-		if (!(data & HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE)) {
-			vcpu->arch.hv_vapic = data;
-			if (kvm_lapic_enable_pv_eoi(vcpu, 0))
-				return 1;
-			break;
-		}
-		gfn = data >> HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT;
-		addr = gfn_to_hva(vcpu->kvm, gfn);
-		if (kvm_is_error_hva(addr))
-			return 1;
-		if (__clear_user((void __user *)addr, PAGE_SIZE))
-			return 1;
-		vcpu->arch.hv_vapic = data;
-		mark_page_dirty(vcpu->kvm, gfn);
-		if (kvm_lapic_enable_pv_eoi(vcpu, gfn_to_gpa(gfn) | KVM_MSR_ENABLED))
-			return 1;
-		break;
-	}
-	case HV_X64_MSR_EOI:
-		return kvm_hv_vapic_msr_write(vcpu, APIC_EOI, data);
-	case HV_X64_MSR_ICR:
-		return kvm_hv_vapic_msr_write(vcpu, APIC_ICR, data);
-	case HV_X64_MSR_TPR:
-		return kvm_hv_vapic_msr_write(vcpu, APIC_TASKPRI, data);
-	default:
-		vcpu_unimpl(vcpu, "HYPER-V unimplemented wrmsr: 0x%x "
-			    "data 0x%llx\n", msr, data);
-		return 1;
-	}
-
-	return 0;
-}
-
 static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
 {
 	gpa_t gpa = data & ~0x3f;
@@ -2329,14 +2208,7 @@ 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:
-		if (kvm_hv_msr_partition_wide(msr)) {
-			int r;
-			mutex_lock(&vcpu->kvm->lock);
-			r = set_msr_hyperv_pw(vcpu, msr, data);
-			mutex_unlock(&vcpu->kvm->lock);
-			return r;
-		} else
-			return set_msr_hyperv(vcpu, msr, data);
+		return kvm_hv_set_msr_common(vcpu, msr, data);
 		break;
 	case MSR_IA32_BBL_CR_CTL3:
 		/* Drop writes to this legacy MSR -- see rdmsr
@@ -2456,68 +2328,6 @@ static int get_msr_mce(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
 	return 0;
 }
 
-static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
-{
-	u64 data = 0;
-	struct kvm *kvm = vcpu->kvm;
-
-	switch (msr) {
-	case HV_X64_MSR_GUEST_OS_ID:
-		data = kvm->arch.hv_guest_os_id;
-		break;
-	case HV_X64_MSR_HYPERCALL:
-		data = kvm->arch.hv_hypercall;
-		break;
-	case HV_X64_MSR_TIME_REF_COUNT: {
-		data =
-		     div_u64(get_kernel_ns() + kvm->arch.kvmclock_offset, 100);
-		break;
-	}
-	case HV_X64_MSR_REFERENCE_TSC:
-		data = kvm->arch.hv_tsc_page;
-		break;
-	default:
-		vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
-		return 1;
-	}
-
-	*pdata = data;
-	return 0;
-}
-
-static int get_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
-{
-	u64 data = 0;
-
-	switch (msr) {
-	case HV_X64_MSR_VP_INDEX: {
-		int r;
-		struct kvm_vcpu *v;
-		kvm_for_each_vcpu(r, v, vcpu->kvm) {
-			if (v == vcpu) {
-				data = r;
-				break;
-			}
-		}
-		break;
-	}
-	case HV_X64_MSR_EOI:
-		return kvm_hv_vapic_msr_read(vcpu, APIC_EOI, pdata);
-	case HV_X64_MSR_ICR:
-		return kvm_hv_vapic_msr_read(vcpu, APIC_ICR, pdata);
-	case HV_X64_MSR_TPR:
-		return kvm_hv_vapic_msr_read(vcpu, APIC_TASKPRI, pdata);
-	case HV_X64_MSR_APIC_ASSIST_PAGE:
-		data = vcpu->arch.hv_vapic;
-		break;
-	default:
-		vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
-		return 1;
-	}
-	*pdata = data;
-	return 0;
-}
-
 int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
 {
 	u64 data;
@@ -2641,14 +2451,7 @@ 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:
-		if (kvm_hv_msr_partition_wide(msr)) {
-			int r;
-			mutex_lock(&vcpu->kvm->lock);
-			r = get_msr_hyperv_pw(vcpu, msr, pdata);
-			mutex_unlock(&vcpu->kvm->lock);
-			return r;
-		} else
-			return get_msr_hyperv(vcpu, msr, pdata);
+		return kvm_hv_get_msr_common(vcpu, msr, pdata);
 		break;
 	case MSR_IA32_BBL_CR_CTL3:
 		/* This legacy MSR exists but isn't fully documented in current
@@ -5880,66 +5683,6 @@ int kvm_emulate_halt(struct kvm_vcpu *vcpu)
 }
 EXPORT_SYMBOL_GPL(kvm_emulate_halt);
 
-int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
-{
-	u64 param, ingpa, outgpa, ret;
-	uint16_t code, rep_idx, rep_cnt, res = HV_STATUS_SUCCESS, rep_done = 0;
-	bool fast, longmode;
-
-	/*
-	 * hypercall generates UD from non zero cpl and real mode
-	 * per HYPER-V spec
-	 */
-	if (kvm_x86_ops->get_cpl(vcpu) != 0 || !is_protmode(vcpu)) {
-		kvm_queue_exception(vcpu, UD_VECTOR);
-		return 0;
-	}
-
-	longmode = is_64_bit_mode(vcpu);
-
-	if (!longmode) {
-		param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) |
-			(kvm_register_read(vcpu, VCPU_REGS_RAX) & 0xffffffff);
-		ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
-			(kvm_register_read(vcpu, VCPU_REGS_RCX) & 0xffffffff);
-		outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
-			(kvm_register_read(vcpu, VCPU_REGS_RSI) & 0xffffffff);
-	}
-#ifdef CONFIG_X86_64
-	else {
-		param = kvm_register_read(vcpu, VCPU_REGS_RCX);
-		ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
-		outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
-	}
-#endif
-
-	code = param & 0xffff;
-	fast = (param >> 16) & 0x1;
-	rep_cnt = (param >> 32) & 0xfff;
-	rep_idx = (param >> 48) & 0xfff;
-
-	trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa);
-
-	switch (code) {
-	case HV_X64_HV_NOTIFY_LONG_SPIN_WAIT:
-		kvm_vcpu_on_spin(vcpu);
-		break;
-	default:
-		res = HV_STATUS_INVALID_HYPERCALL_CODE;
-		break;
-	}
-
-	ret = res | (((u64)rep_done & 0xfff) << 32);
-	if (longmode) {
-		kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
-	} else {
-		kvm_register_write(vcpu, VCPU_REGS_RDX, ret >> 32);
-		kvm_register_write(vcpu, VCPU_REGS_RAX, ret & 0xffffffff);
-	}
-
-	return 1;
-}
-
 /*
  * kvm_pv_kick_cpu_op:  Kick a vcpu.
  *
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index f5fef18..1cb1179 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -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);
-- 
1.9.1

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

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 01/11] kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file
@ 2015-06-22 16:04   ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:04 UTC (permalink / raw)
  Cc: kvm, Gleb Natapov, qemu-devel, Paolo Bonzini, Andrey Smetanin,
	Denis V. Lunev

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 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

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index f4a555b..717a03c 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -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;
diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
index 16e8f96..944c8c8 100644
--- a/arch/x86/kvm/Makefile
+++ b/arch/x86/kvm/Makefile
@@ -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
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
new file mode 100644
index 0000000..0d24d9a
--- /dev/null
+++ b/arch/x86/kvm/hyperv.c
@@ -0,0 +1,303 @@
+/*
+ * 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 <asmetanin@virtuozzo.com>
+ *
+ * Authors:
+ *   Avi Kivity   <avi@qumranet.com>
+ *   Yaniv Kamay  <yaniv@qumranet.com>
+ *   Amit Shah    <amit.shah@qumranet.com>
+ *   Ben-Ami Yassour <benami@il.ibm.com>
+ *   Andrey Smetanin <asmetanin@virtuozzo.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "x86.h"
+#include "lapic.h"
+#include "hyperv.h"
+
+#include <linux/kvm_host.h>
+#include <trace/events/kvm.h>
+
+#include "trace.h"
+
+static bool kvm_hv_msr_partition_wide(u32 msr)
+{
+	bool r = false;
+
+	switch (msr) {
+	case HV_X64_MSR_GUEST_OS_ID:
+	case HV_X64_MSR_HYPERCALL:
+	case HV_X64_MSR_REFERENCE_TSC:
+	case HV_X64_MSR_TIME_REF_COUNT:
+		r = true;
+		break;
+	}
+
+	return r;
+}
+
+static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+{
+	struct kvm *kvm = vcpu->kvm;
+	struct kvm_arch_hyperv *hv = &kvm->arch.hyperv;
+
+	switch (msr) {
+	case HV_X64_MSR_GUEST_OS_ID:
+		hv->hv_guest_os_id = data;
+		/* setting guest os id to zero disables hypercall page */
+		if (!hv->hv_guest_os_id)
+			hv->hv_hypercall &= ~HV_X64_MSR_HYPERCALL_ENABLE;
+		break;
+	case HV_X64_MSR_HYPERCALL: {
+		u64 gfn;
+		unsigned long addr;
+		u8 instructions[4];
+
+		/* if guest os id is not set hypercall should remain disabled */
+		if (!hv->hv_guest_os_id)
+			break;
+		if (!(data & HV_X64_MSR_HYPERCALL_ENABLE)) {
+			hv->hv_hypercall = data;
+			break;
+		}
+		gfn = data >> HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
+		addr = gfn_to_hva(kvm, gfn);
+		if (kvm_is_error_hva(addr))
+			return 1;
+		kvm_x86_ops->patch_hypercall(vcpu, instructions);
+		((unsigned char *)instructions)[3] = 0xc3; /* ret */
+		if (__copy_to_user((void __user *)addr, instructions, 4))
+			return 1;
+		hv->hv_hypercall = data;
+		mark_page_dirty(kvm, gfn);
+		break;
+	}
+	case HV_X64_MSR_REFERENCE_TSC: {
+		u64 gfn;
+		HV_REFERENCE_TSC_PAGE tsc_ref;
+
+		memset(&tsc_ref, 0, sizeof(tsc_ref));
+		hv->hv_tsc_page = data;
+		if (!(data & HV_X64_MSR_TSC_REFERENCE_ENABLE))
+			break;
+		gfn = data >> HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT;
+		if (kvm_write_guest(kvm,
+			gfn << HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT,
+			&tsc_ref, sizeof(tsc_ref)))
+			return 1;
+		mark_page_dirty(kvm, gfn);
+		break;
+	}
+	default:
+		vcpu_unimpl(vcpu, "Hyper-V unimpl wrmsr: 0x%x data 0x%llx\n",
+				  msr, data);
+		return 1;
+	}
+	return 0;
+}
+
+static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+{
+	struct kvm_vcpu_arch_hyperv *hv = &vcpu->arch.hyperv;
+
+	switch (msr) {
+	case HV_X64_MSR_APIC_ASSIST_PAGE: {
+		u64 gfn;
+		unsigned long addr;
+
+		if (!(data & HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE)) {
+			hv->hv_vapic = data;
+			if (kvm_lapic_enable_pv_eoi(vcpu, 0))
+				return 1;
+			break;
+		}
+		gfn = data >> HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT;
+		addr = gfn_to_hva(vcpu->kvm, gfn);
+		if (kvm_is_error_hva(addr))
+			return 1;
+		if (__clear_user((void __user *)addr, PAGE_SIZE))
+			return 1;
+		hv->hv_vapic = data;
+		mark_page_dirty(vcpu->kvm, gfn);
+		if (kvm_lapic_enable_pv_eoi(vcpu,
+					    gfn_to_gpa(gfn) | KVM_MSR_ENABLED))
+			return 1;
+		break;
+	}
+	case HV_X64_MSR_EOI:
+		return kvm_hv_vapic_msr_write(vcpu, APIC_EOI, data);
+	case HV_X64_MSR_ICR:
+		return kvm_hv_vapic_msr_write(vcpu, APIC_ICR, data);
+	case HV_X64_MSR_TPR:
+		return kvm_hv_vapic_msr_write(vcpu, APIC_TASKPRI, data);
+	default:
+		vcpu_unimpl(vcpu, "Hyper-V unimpl wrmsr: 0x%x data 0x%llx\n",
+				  msr, data);
+		return 1;
+	}
+
+	return 0;
+}
+
+static int kvm_hv_get_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
+{
+	u64 data = 0;
+	struct kvm *kvm = vcpu->kvm;
+	struct kvm_arch_hyperv *hv = &kvm->arch.hyperv;
+
+	switch (msr) {
+	case HV_X64_MSR_GUEST_OS_ID:
+		data = hv->hv_guest_os_id;
+		break;
+	case HV_X64_MSR_HYPERCALL:
+		data = hv->hv_hypercall;
+		break;
+	case HV_X64_MSR_TIME_REF_COUNT: {
+		data =
+		     div_u64(get_kernel_ns() + kvm->arch.kvmclock_offset, 100);
+		break;
+	}
+	case HV_X64_MSR_REFERENCE_TSC:
+		data = hv->hv_tsc_page;
+		break;
+	default:
+		vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
+		return 1;
+	}
+
+	*pdata = data;
+	return 0;
+}
+
+static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
+{
+	u64 data = 0;
+
+	switch (msr) {
+	case HV_X64_MSR_VP_INDEX: {
+		int r;
+		struct kvm_vcpu *v;
+
+		kvm_for_each_vcpu(r, v, vcpu->kvm) {
+			if (v == vcpu) {
+				data = r;
+				break;
+			}
+		}
+		break;
+	}
+	case HV_X64_MSR_EOI:
+		return kvm_hv_vapic_msr_read(vcpu, APIC_EOI, pdata);
+	case HV_X64_MSR_ICR:
+		return kvm_hv_vapic_msr_read(vcpu, APIC_ICR, pdata);
+	case HV_X64_MSR_TPR:
+		return kvm_hv_vapic_msr_read(vcpu, APIC_TASKPRI, pdata);
+	case HV_X64_MSR_APIC_ASSIST_PAGE:
+		data = vcpu->arch.hyperv.hv_vapic;
+		break;
+	default:
+		vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
+		return 1;
+	}
+	*pdata = data;
+	return 0;
+}
+
+int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+{
+	if (kvm_hv_msr_partition_wide(msr)) {
+		int r;
+
+		mutex_lock(&vcpu->kvm->lock);
+		r = kvm_hv_set_msr_pw(vcpu, msr, data);
+		mutex_unlock(&vcpu->kvm->lock);
+		return r;
+	} else
+		return kvm_hv_set_msr(vcpu, msr, data);
+}
+
+int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
+{
+	if (kvm_hv_msr_partition_wide(msr)) {
+		int r;
+
+		mutex_lock(&vcpu->kvm->lock);
+		r = kvm_hv_get_msr_pw(vcpu, msr, pdata);
+		mutex_unlock(&vcpu->kvm->lock);
+		return r;
+	} else
+		return kvm_hv_get_msr(vcpu, msr, pdata);
+}
+
+bool kvm_hv_hypercall_enabled(struct kvm *kvm)
+{
+	return kvm->arch.hyperv.hv_hypercall & HV_X64_MSR_HYPERCALL_ENABLE;
+}
+
+int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
+{
+	u64 param, ingpa, outgpa, ret;
+	uint16_t code, rep_idx, rep_cnt, res = HV_STATUS_SUCCESS, rep_done = 0;
+	bool fast, longmode;
+
+	/*
+	 * hypercall generates UD from non zero cpl and real mode
+	 * per HYPER-V spec
+	 */
+	if (kvm_x86_ops->get_cpl(vcpu) != 0 || !is_protmode(vcpu)) {
+		kvm_queue_exception(vcpu, UD_VECTOR);
+		return 0;
+	}
+
+	longmode = is_64_bit_mode(vcpu);
+
+	if (!longmode) {
+		param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) |
+			(kvm_register_read(vcpu, VCPU_REGS_RAX) & 0xffffffff);
+		ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
+			(kvm_register_read(vcpu, VCPU_REGS_RCX) & 0xffffffff);
+		outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
+			(kvm_register_read(vcpu, VCPU_REGS_RSI) & 0xffffffff);
+	}
+#ifdef CONFIG_X86_64
+	else {
+		param = kvm_register_read(vcpu, VCPU_REGS_RCX);
+		ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
+		outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
+	}
+#endif
+
+	code = param & 0xffff;
+	fast = (param >> 16) & 0x1;
+	rep_cnt = (param >> 32) & 0xfff;
+	rep_idx = (param >> 48) & 0xfff;
+
+	trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa);
+
+	switch (code) {
+	case HV_X64_HV_NOTIFY_LONG_SPIN_WAIT:
+		kvm_vcpu_on_spin(vcpu);
+		break;
+	default:
+		res = HV_STATUS_INVALID_HYPERCALL_CODE;
+		break;
+	}
+
+	ret = res | (((u64)rep_done & 0xfff) << 32);
+	if (longmode) {
+		kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
+	} else {
+		kvm_register_write(vcpu, VCPU_REGS_RDX, ret >> 32);
+		kvm_register_write(vcpu, VCPU_REGS_RAX, ret & 0xffffffff);
+	}
+
+	return 1;
+}
diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
new file mode 100644
index 0000000..39aee93
--- /dev/null
+++ b/arch/x86/kvm/hyperv.h
@@ -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 <asmetanin@virtuozzo.com>
+ *
+ * Authors:
+ *   Avi Kivity   <avi@qumranet.com>
+ *   Yaniv Kamay  <yaniv@qumranet.com>
+ *   Amit Shah    <amit.shah@qumranet.com>
+ *   Ben-Ami Yassour <benami@il.ibm.com>
+ *   Andrey Smetanin <asmetanin@virtuozzo.com>
+ *
+ * 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
diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index 9d28383..2891d2e 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -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);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index ea306ad..2755c37 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -28,6 +28,7 @@
 #include "x86.h"
 #include "cpuid.h"
 #include "assigned-dev.h"
+#include "hyperv.h"
 
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>
@@ -1193,11 +1194,6 @@ static void kvm_get_time_scale(uint32_t scaled_khz, uint32_t base_khz,
 		 __func__, base_khz, scaled_khz, shift, *pmultiplier);
 }
 
-static inline u64 get_kernel_ns(void)
-{
-	return ktime_get_boot_ns();
-}
-
 #ifdef CONFIG_X86_64
 static atomic_t kvm_guest_has_master_clock = ATOMIC_INIT(0);
 #endif
@@ -1956,123 +1952,6 @@ out:
 	return r;
 }
 
-static bool kvm_hv_hypercall_enabled(struct kvm *kvm)
-{
-	return kvm->arch.hv_hypercall & HV_X64_MSR_HYPERCALL_ENABLE;
-}
-
-static bool kvm_hv_msr_partition_wide(u32 msr)
-{
-	bool r = false;
-	switch (msr) {
-	case HV_X64_MSR_GUEST_OS_ID:
-	case HV_X64_MSR_HYPERCALL:
-	case HV_X64_MSR_REFERENCE_TSC:
-	case HV_X64_MSR_TIME_REF_COUNT:
-		r = true;
-		break;
-	}
-
-	return r;
-}
-
-static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
-{
-	struct kvm *kvm = vcpu->kvm;
-
-	switch (msr) {
-	case HV_X64_MSR_GUEST_OS_ID:
-		kvm->arch.hv_guest_os_id = data;
-		/* setting guest os id to zero disables hypercall page */
-		if (!kvm->arch.hv_guest_os_id)
-			kvm->arch.hv_hypercall &= ~HV_X64_MSR_HYPERCALL_ENABLE;
-		break;
-	case HV_X64_MSR_HYPERCALL: {
-		u64 gfn;
-		unsigned long addr;
-		u8 instructions[4];
-
-		/* if guest os id is not set hypercall should remain disabled */
-		if (!kvm->arch.hv_guest_os_id)
-			break;
-		if (!(data & HV_X64_MSR_HYPERCALL_ENABLE)) {
-			kvm->arch.hv_hypercall = data;
-			break;
-		}
-		gfn = data >> HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
-		addr = gfn_to_hva(kvm, gfn);
-		if (kvm_is_error_hva(addr))
-			return 1;
-		kvm_x86_ops->patch_hypercall(vcpu, instructions);
-		((unsigned char *)instructions)[3] = 0xc3; /* ret */
-		if (__copy_to_user((void __user *)addr, instructions, 4))
-			return 1;
-		kvm->arch.hv_hypercall = data;
-		mark_page_dirty(kvm, gfn);
-		break;
-	}
-	case HV_X64_MSR_REFERENCE_TSC: {
-		u64 gfn;
-		HV_REFERENCE_TSC_PAGE tsc_ref;
-		memset(&tsc_ref, 0, sizeof(tsc_ref));
-		kvm->arch.hv_tsc_page = data;
-		if (!(data & HV_X64_MSR_TSC_REFERENCE_ENABLE))
-			break;
-		gfn = data >> HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT;
-		if (kvm_write_guest(kvm, gfn << HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT,
-			&tsc_ref, sizeof(tsc_ref)))
-			return 1;
-		mark_page_dirty(kvm, gfn);
-		break;
-	}
-	default:
-		vcpu_unimpl(vcpu, "HYPER-V unimplemented wrmsr: 0x%x "
-			    "data 0x%llx\n", msr, data);
-		return 1;
-	}
-	return 0;
-}
-
-static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)
-{
-	switch (msr) {
-	case HV_X64_MSR_APIC_ASSIST_PAGE: {
-		u64 gfn;
-		unsigned long addr;
-
-		if (!(data & HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE)) {
-			vcpu->arch.hv_vapic = data;
-			if (kvm_lapic_enable_pv_eoi(vcpu, 0))
-				return 1;
-			break;
-		}
-		gfn = data >> HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT;
-		addr = gfn_to_hva(vcpu->kvm, gfn);
-		if (kvm_is_error_hva(addr))
-			return 1;
-		if (__clear_user((void __user *)addr, PAGE_SIZE))
-			return 1;
-		vcpu->arch.hv_vapic = data;
-		mark_page_dirty(vcpu->kvm, gfn);
-		if (kvm_lapic_enable_pv_eoi(vcpu, gfn_to_gpa(gfn) | KVM_MSR_ENABLED))
-			return 1;
-		break;
-	}
-	case HV_X64_MSR_EOI:
-		return kvm_hv_vapic_msr_write(vcpu, APIC_EOI, data);
-	case HV_X64_MSR_ICR:
-		return kvm_hv_vapic_msr_write(vcpu, APIC_ICR, data);
-	case HV_X64_MSR_TPR:
-		return kvm_hv_vapic_msr_write(vcpu, APIC_TASKPRI, data);
-	default:
-		vcpu_unimpl(vcpu, "HYPER-V unimplemented wrmsr: 0x%x "
-			    "data 0x%llx\n", msr, data);
-		return 1;
-	}
-
-	return 0;
-}
-
 static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
 {
 	gpa_t gpa = data & ~0x3f;
@@ -2329,14 +2208,7 @@ 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:
-		if (kvm_hv_msr_partition_wide(msr)) {
-			int r;
-			mutex_lock(&vcpu->kvm->lock);
-			r = set_msr_hyperv_pw(vcpu, msr, data);
-			mutex_unlock(&vcpu->kvm->lock);
-			return r;
-		} else
-			return set_msr_hyperv(vcpu, msr, data);
+		return kvm_hv_set_msr_common(vcpu, msr, data);
 		break;
 	case MSR_IA32_BBL_CR_CTL3:
 		/* Drop writes to this legacy MSR -- see rdmsr
@@ -2456,68 +2328,6 @@ static int get_msr_mce(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
 	return 0;
 }
 
-static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
-{
-	u64 data = 0;
-	struct kvm *kvm = vcpu->kvm;
-
-	switch (msr) {
-	case HV_X64_MSR_GUEST_OS_ID:
-		data = kvm->arch.hv_guest_os_id;
-		break;
-	case HV_X64_MSR_HYPERCALL:
-		data = kvm->arch.hv_hypercall;
-		break;
-	case HV_X64_MSR_TIME_REF_COUNT: {
-		data =
-		     div_u64(get_kernel_ns() + kvm->arch.kvmclock_offset, 100);
-		break;
-	}
-	case HV_X64_MSR_REFERENCE_TSC:
-		data = kvm->arch.hv_tsc_page;
-		break;
-	default:
-		vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
-		return 1;
-	}
-
-	*pdata = data;
-	return 0;
-}
-
-static int get_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
-{
-	u64 data = 0;
-
-	switch (msr) {
-	case HV_X64_MSR_VP_INDEX: {
-		int r;
-		struct kvm_vcpu *v;
-		kvm_for_each_vcpu(r, v, vcpu->kvm) {
-			if (v == vcpu) {
-				data = r;
-				break;
-			}
-		}
-		break;
-	}
-	case HV_X64_MSR_EOI:
-		return kvm_hv_vapic_msr_read(vcpu, APIC_EOI, pdata);
-	case HV_X64_MSR_ICR:
-		return kvm_hv_vapic_msr_read(vcpu, APIC_ICR, pdata);
-	case HV_X64_MSR_TPR:
-		return kvm_hv_vapic_msr_read(vcpu, APIC_TASKPRI, pdata);
-	case HV_X64_MSR_APIC_ASSIST_PAGE:
-		data = vcpu->arch.hv_vapic;
-		break;
-	default:
-		vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
-		return 1;
-	}
-	*pdata = data;
-	return 0;
-}
-
 int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
 {
 	u64 data;
@@ -2641,14 +2451,7 @@ 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:
-		if (kvm_hv_msr_partition_wide(msr)) {
-			int r;
-			mutex_lock(&vcpu->kvm->lock);
-			r = get_msr_hyperv_pw(vcpu, msr, pdata);
-			mutex_unlock(&vcpu->kvm->lock);
-			return r;
-		} else
-			return get_msr_hyperv(vcpu, msr, pdata);
+		return kvm_hv_get_msr_common(vcpu, msr, pdata);
 		break;
 	case MSR_IA32_BBL_CR_CTL3:
 		/* This legacy MSR exists but isn't fully documented in current
@@ -5880,66 +5683,6 @@ int kvm_emulate_halt(struct kvm_vcpu *vcpu)
 }
 EXPORT_SYMBOL_GPL(kvm_emulate_halt);
 
-int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
-{
-	u64 param, ingpa, outgpa, ret;
-	uint16_t code, rep_idx, rep_cnt, res = HV_STATUS_SUCCESS, rep_done = 0;
-	bool fast, longmode;
-
-	/*
-	 * hypercall generates UD from non zero cpl and real mode
-	 * per HYPER-V spec
-	 */
-	if (kvm_x86_ops->get_cpl(vcpu) != 0 || !is_protmode(vcpu)) {
-		kvm_queue_exception(vcpu, UD_VECTOR);
-		return 0;
-	}
-
-	longmode = is_64_bit_mode(vcpu);
-
-	if (!longmode) {
-		param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) |
-			(kvm_register_read(vcpu, VCPU_REGS_RAX) & 0xffffffff);
-		ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
-			(kvm_register_read(vcpu, VCPU_REGS_RCX) & 0xffffffff);
-		outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
-			(kvm_register_read(vcpu, VCPU_REGS_RSI) & 0xffffffff);
-	}
-#ifdef CONFIG_X86_64
-	else {
-		param = kvm_register_read(vcpu, VCPU_REGS_RCX);
-		ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
-		outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
-	}
-#endif
-
-	code = param & 0xffff;
-	fast = (param >> 16) & 0x1;
-	rep_cnt = (param >> 32) & 0xfff;
-	rep_idx = (param >> 48) & 0xfff;
-
-	trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa);
-
-	switch (code) {
-	case HV_X64_HV_NOTIFY_LONG_SPIN_WAIT:
-		kvm_vcpu_on_spin(vcpu);
-		break;
-	default:
-		res = HV_STATUS_INVALID_HYPERCALL_CODE;
-		break;
-	}
-
-	ret = res | (((u64)rep_done & 0xfff) << 32);
-	if (longmode) {
-		kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
-	} else {
-		kvm_register_write(vcpu, VCPU_REGS_RDX, ret >> 32);
-		kvm_register_write(vcpu, VCPU_REGS_RAX, ret & 0xffffffff);
-	}
-
-	return 1;
-}
-
 /*
  * kvm_pv_kick_cpu_op:  Kick a vcpu.
  *
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index f5fef18..1cb1179 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -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);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH 02/11] kvm: introduce vcpu_debug = kvm_debug + vcpu context
  2015-06-22 16:04 ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:04   ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:04 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Andrey Smetanin, Denis V. Lunev, Paolo Bonzini,
	Gleb Natapov

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 include/linux/kvm_host.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index ad45054..7ee3a90 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -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();
-- 
1.9.1

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

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 02/11] kvm: introduce vcpu_debug = kvm_debug + vcpu context
@ 2015-06-22 16:04   ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:04 UTC (permalink / raw)
  Cc: kvm, Gleb Natapov, qemu-devel, Paolo Bonzini, Andrey Smetanin,
	Denis V. Lunev

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 include/linux/kvm_host.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index ad45054..7ee3a90 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -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();
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH 03/11] kvm: add hyper-v crash msrs constants
  2015-06-22 16:04 ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:05   ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Andrey Smetanin, Denis V. Lunev, Paolo Bonzini,
	Gleb Natapov

From: Andrey Smetanin <asmetanin@virtuozzo.com>

Added Hyper-V crash msrs HV_X64_MSR_CRASH* constants.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 arch/x86/include/uapi/asm/hyperv.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/arch/x86/include/uapi/asm/hyperv.h b/arch/x86/include/uapi/asm/hyperv.h
index ce6068d..a1be4ba 100644
--- a/arch/x86/include/uapi/asm/hyperv.h
+++ b/arch/x86/include/uapi/asm/hyperv.h
@@ -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	\
-- 
1.9.1

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

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 03/11] kvm: add hyper-v crash msrs constants
@ 2015-06-22 16:05   ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, Gleb Natapov, qemu-devel, Paolo Bonzini, Andrey Smetanin,
	Denis V. Lunev

From: Andrey Smetanin <asmetanin@virtuozzo.com>

Added Hyper-V crash msrs HV_X64_MSR_CRASH* constants.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 arch/x86/include/uapi/asm/hyperv.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/arch/x86/include/uapi/asm/hyperv.h b/arch/x86/include/uapi/asm/hyperv.h
index ce6068d..a1be4ba 100644
--- a/arch/x86/include/uapi/asm/hyperv.h
+++ b/arch/x86/include/uapi/asm/hyperv.h
@@ -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	\
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH 04/11] kvm/x86: added hyper-v crash msrs into kvm hyperv context
  2015-06-22 16:04 ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:05   ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Andrey Smetanin, Denis V. Lunev, Paolo Bonzini,
	Gleb Natapov

From: Andrey Smetanin <asmetanin@virtuozzo.com>

Added kvm hyperv context hv crash variables as storage
of hyper-v crash msrs.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 arch/x86/include/asm/kvm_host.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 717a03c..578816a 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -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 {
-- 
1.9.1

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

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 04/11] kvm/x86: added hyper-v crash msrs into kvm hyperv context
@ 2015-06-22 16:05   ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, Gleb Natapov, qemu-devel, Paolo Bonzini, Andrey Smetanin,
	Denis V. Lunev

From: Andrey Smetanin <asmetanin@virtuozzo.com>

Added kvm hyperv context hv crash variables as storage
of hyper-v crash msrs.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 arch/x86/include/asm/kvm_host.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 717a03c..578816a 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -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 {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH 05/11] kvm: added KVM_REQ_HV_CRASH value to notify qemu about Hyper-V crash
  2015-06-22 16:04 ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:05   ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Andrey Smetanin, Denis V. Lunev, Paolo Bonzini,
	Gleb Natapov

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 include/linux/kvm_host.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 7ee3a90..f1a3977b 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -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
-- 
1.9.1

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

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 05/11] kvm: added KVM_REQ_HV_CRASH value to notify qemu about Hyper-V crash
@ 2015-06-22 16:05   ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, Gleb Natapov, qemu-devel, Paolo Bonzini, Andrey Smetanin,
	Denis V. Lunev

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 include/linux/kvm_host.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 7ee3a90..f1a3977b 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -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
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH 06/11] kvm/x86: mark hyper-v crash msrs as partition wide
  2015-06-22 16:04 ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:05   ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Andrey Smetanin, Denis V. Lunev, Paolo Bonzini,
	Gleb Natapov

From: Andrey Smetanin <asmetanin@virtuozzo.com>

Hyper-V crash msr's a per VM, not per vcpu, so mark them
as partition wide.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 arch/x86/kvm/hyperv.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 0d24d9a..f65fb622 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -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;
 	}
-- 
1.9.1

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

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 06/11] kvm/x86: mark hyper-v crash msrs as partition wide
@ 2015-06-22 16:05   ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, Gleb Natapov, qemu-devel, Paolo Bonzini, Andrey Smetanin,
	Denis V. Lunev

From: Andrey Smetanin <asmetanin@virtuozzo.com>

Hyper-V crash msr's a per VM, not per vcpu, so mark them
as partition wide.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 arch/x86/kvm/hyperv.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 0d24d9a..f65fb622 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -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;
 	}
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH 07/11] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
  2015-06-22 16:04 ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:05   ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Andrey Smetanin, Denis V. Lunev, Paolo Bonzini,
	Gleb Natapov

From: Andrey Smetanin <asmetanin@virtuozzo.com>

Added hyper-v crash msr's(HV_X64_MSR_CRASH*) data and control
geters and setters.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 arch/x86/kvm/hyperv.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/kvm/x86.c    |  4 ++++
 2 files changed, 70 insertions(+)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index f65fb622..0a7d373 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -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;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2755c37..2046b78 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 07/11] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
@ 2015-06-22 16:05   ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, Gleb Natapov, qemu-devel, Paolo Bonzini, Andrey Smetanin,
	Denis V. Lunev

From: Andrey Smetanin <asmetanin@virtuozzo.com>

Added hyper-v crash msr's(HV_X64_MSR_CRASH*) data and control
geters and setters.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 arch/x86/kvm/hyperv.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/kvm/x86.c    |  4 ++++
 2 files changed, 70 insertions(+)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index f65fb622..0a7d373 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -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;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2755c37..2046b78 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH 08/11] kvm/x86: add sending hyper-v crash notification to user space
  2015-06-22 16:04 ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:05   ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Andrey Smetanin, Denis V. Lunev, Paolo Bonzini,
	Gleb Natapov

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 arch/x86/kvm/x86.c       | 8 ++++++++
 include/uapi/linux/kvm.h | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2046b78..111fa83 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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) {
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 4b60056..22b6cca 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -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;
-- 
1.9.1

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

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 08/11] kvm/x86: add sending hyper-v crash notification to user space
@ 2015-06-22 16:05   ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, Gleb Natapov, qemu-devel, Paolo Bonzini, Andrey Smetanin,
	Denis V. Lunev

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 arch/x86/kvm/x86.c       | 8 ++++++++
 include/uapi/linux/kvm.h | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2046b78..111fa83 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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) {
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 4b60056..22b6cca 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -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;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH 09/11] kvm/x86: distingiush hyper-v guest crash notification
  2015-06-22 16:04 ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:05   ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Andrey Smetanin, Denis V. Lunev, Paolo Bonzini,
	Gleb Natapov

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 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(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 6b18015..f49502a 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -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)
diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
index 39aee93..dc49527 100644
--- a/arch/x86/kvm/hyperv.h
+++ b/arch/x86/kvm/hyperv.h
@@ -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);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 111fa83..db4eecb 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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

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

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 09/11] kvm/x86: distingiush hyper-v guest crash notification
@ 2015-06-22 16:05   ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, Gleb Natapov, qemu-devel, Paolo Bonzini, Andrey Smetanin,
	Denis V. Lunev

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Gleb Natapov <gleb@kernel.org>
---
 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(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 6b18015..f49502a 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -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)
diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
index 39aee93..dc49527 100644
--- a/arch/x86/kvm/hyperv.h
+++ b/arch/x86/kvm/hyperv.h
@@ -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);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 111fa83..db4eecb 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH 10/11] qemu/kvm: kvm hyper-v based guest crash event handling
  2015-06-22 16:04 ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:05   ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Andrey Smetanin, Denis V. Lunev, Paolo Bonzini,
	Andreas Färber

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Andreas Färber <afaerber@suse.de>
---
 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(+)

diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index f459fbd..3c0fa02 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -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);
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index df80951..70164c9 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -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);
diff --git a/kvm-all.c b/kvm-all.c
index 53e01d4..1528fb5 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -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);
diff --git a/linux-headers/asm-x86/hyperv.h b/linux-headers/asm-x86/hyperv.h
index ce6068d..aec7d27 100644
--- a/linux-headers/asm-x86/hyperv.h
+++ b/linux-headers/asm-x86/hyperv.h
@@ -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	\
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index fad9e5c..46cb7e0 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -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;
diff --git a/target-arm/kvm.c b/target-arm/kvm.c
index 548bfd7..c19899e 100644
--- a/target-arm/kvm.c
+++ b/target-arm/kvm.c
@@ -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;
diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index 7a4fddd..c35b624 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -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;
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 4e7cdaa..af0552a 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -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),
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 603aaf0..474a93e 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -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;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 5a236e3..690677b 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -80,6 +80,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;
 
@@ -516,6 +517,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
             c->eax |= 0x200;
             has_msr_hv_tsc = true;
         }
+        if (cpu->hyperv_crash) {
+            c->edx |= HV_X64_GUEST_CRASH_MSR_AVAILABLE;
+            has_msr_hv_crash = true;
+        }
+
         c = &cpuid_data.entries[cpuid_i++];
         c->function = HYPERV_CPUID_ENLIGHTMENT_INFO;
         if (cpu->hyperv_relaxed_timing) {
@@ -762,6 +768,9 @@ void kvm_arch_reset_vcpu(X86CPU *cpu)
     } else {
         env->mp_state = KVM_MP_STATE_RUNNABLE;
     }
+    if (has_msr_hv_crash) {
+            env->msr_hv_crash_ctl = HV_X64_MSR_CRASH_CTL_CONTENTS;
+    }
 }
 
 void kvm_arch_do_init_vcpu(X86CPU *cpu)
@@ -1322,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,
+                              env->msr_hv_crash_ctl);
+        }
         if (has_msr_mtrr) {
             kvm_msr_entry_set(&msrs[n++], MSR_MTRRdefType, env->mtrr_deftype);
             kvm_msr_entry_set(&msrs[n++],
@@ -1674,6 +1693,14 @@ 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;
+        }
+        msrs[n++].index = HV_X64_MSR_CRASH_CTL;
+    }
     if (has_msr_mtrr) {
         msrs[n++].index = MSR_MTRRdefType;
         msrs[n++].index = MSR_MTRRfix64K_00000;
@@ -1818,6 +1845,12 @@ 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_CTL:
+            env->msr_hv_crash_ctl = 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;
@@ -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:
+            env->msr_hv_crash_ctl = msrs[i].data;
+            break;
+        default:
+            break;
+        }
+    }
+
+    return 0;
+}
+
 #define VMX_INVALID_GUEST_STATE 0x80000021
 
 int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
diff --git a/target-i386/machine.c b/target-i386/machine.c
index a0df64b..15b3f31 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -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
diff --git a/target-mips/kvm.c b/target-mips/kvm.c
index 948619f..1ac7732 100644
--- a/target-mips/kvm.c
+++ b/target-mips/kvm.c
@@ -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;
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index afb4696..af34198 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -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);
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index b02ff8d..07d0914 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -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);
diff --git a/vl.c b/vl.c
index 1a920e6..9b60f95 100644
--- a/vl.c
+++ b/vl.c
@@ -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) {
-- 
1.9.1

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

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 10/11] qemu/kvm: kvm hyper-v based guest crash event handling
@ 2015-06-22 16:05   ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Paolo Bonzini, Andrey Smetanin, Denis V. Lunev,
	Andreas Färber

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Andreas Färber <afaerber@suse.de>
---
 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(+)

diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index f459fbd..3c0fa02 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -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);
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index df80951..70164c9 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -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);
diff --git a/kvm-all.c b/kvm-all.c
index 53e01d4..1528fb5 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -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);
diff --git a/linux-headers/asm-x86/hyperv.h b/linux-headers/asm-x86/hyperv.h
index ce6068d..aec7d27 100644
--- a/linux-headers/asm-x86/hyperv.h
+++ b/linux-headers/asm-x86/hyperv.h
@@ -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	\
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index fad9e5c..46cb7e0 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -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;
diff --git a/target-arm/kvm.c b/target-arm/kvm.c
index 548bfd7..c19899e 100644
--- a/target-arm/kvm.c
+++ b/target-arm/kvm.c
@@ -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;
diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index 7a4fddd..c35b624 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -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;
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 4e7cdaa..af0552a 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -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),
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 603aaf0..474a93e 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -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;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 5a236e3..690677b 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -80,6 +80,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;
 
@@ -516,6 +517,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
             c->eax |= 0x200;
             has_msr_hv_tsc = true;
         }
+        if (cpu->hyperv_crash) {
+            c->edx |= HV_X64_GUEST_CRASH_MSR_AVAILABLE;
+            has_msr_hv_crash = true;
+        }
+
         c = &cpuid_data.entries[cpuid_i++];
         c->function = HYPERV_CPUID_ENLIGHTMENT_INFO;
         if (cpu->hyperv_relaxed_timing) {
@@ -762,6 +768,9 @@ void kvm_arch_reset_vcpu(X86CPU *cpu)
     } else {
         env->mp_state = KVM_MP_STATE_RUNNABLE;
     }
+    if (has_msr_hv_crash) {
+            env->msr_hv_crash_ctl = HV_X64_MSR_CRASH_CTL_CONTENTS;
+    }
 }
 
 void kvm_arch_do_init_vcpu(X86CPU *cpu)
@@ -1322,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,
+                              env->msr_hv_crash_ctl);
+        }
         if (has_msr_mtrr) {
             kvm_msr_entry_set(&msrs[n++], MSR_MTRRdefType, env->mtrr_deftype);
             kvm_msr_entry_set(&msrs[n++],
@@ -1674,6 +1693,14 @@ 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;
+        }
+        msrs[n++].index = HV_X64_MSR_CRASH_CTL;
+    }
     if (has_msr_mtrr) {
         msrs[n++].index = MSR_MTRRdefType;
         msrs[n++].index = MSR_MTRRfix64K_00000;
@@ -1818,6 +1845,12 @@ 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_CTL:
+            env->msr_hv_crash_ctl = 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;
@@ -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:
+            env->msr_hv_crash_ctl = msrs[i].data;
+            break;
+        default:
+            break;
+        }
+    }
+
+    return 0;
+}
+
 #define VMX_INVALID_GUEST_STATE 0x80000021
 
 int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
diff --git a/target-i386/machine.c b/target-i386/machine.c
index a0df64b..15b3f31 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -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
diff --git a/target-mips/kvm.c b/target-mips/kvm.c
index 948619f..1ac7732 100644
--- a/target-mips/kvm.c
+++ b/target-mips/kvm.c
@@ -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;
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index afb4696..af34198 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -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);
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index b02ff8d..07d0914 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -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);
diff --git a/vl.c b/vl.c
index 1a920e6..9b60f95 100644
--- a/vl.c
+++ b/vl.c
@@ -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) {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
  2015-06-22 16:04 ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:05   ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Andrey Smetanin, Denis V. Lunev, Paolo Bonzini,
	Andreas Färber

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Andreas Färber <afaerber@suse.de>
---
 target-i386/cpu.h     | 1 +
 target-i386/kvm.c     | 1 +
 target-i386/machine.c | 1 +
 3 files changed, 3 insertions(+)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 474a93e..2958cdc 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -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;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 690677b..2c8d00f 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -2616,6 +2616,7 @@ int kvm_arch_handle_hv_crash(CPUState *cs)
             break;
         }
     }
+    env->hv_crash_occurred = 1;
 
     return 0;
 }
diff --git a/target-i386/machine.c b/target-i386/machine.c
index 15b3f31..4f72ba8 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -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()
     }
 };
-- 
1.9.1

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

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [Qemu-devel] [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
@ 2015-06-22 16:05   ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:05 UTC (permalink / raw)
  Cc: kvm, qemu-devel, Paolo Bonzini, Andrey Smetanin, Denis V. Lunev,
	Andreas Färber

From: Andrey Smetanin <asmetanin@virtuozzo.com>

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.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Andreas Färber <afaerber@suse.de>
---
 target-i386/cpu.h     | 1 +
 target-i386/kvm.c     | 1 +
 target-i386/machine.c | 1 +
 3 files changed, 3 insertions(+)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 474a93e..2958cdc 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -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;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 690677b..2c8d00f 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -2616,6 +2616,7 @@ int kvm_arch_handle_hv_crash(CPUState *cs)
             break;
         }
     }
+    env->hv_crash_occurred = 1;
 
     return 0;
 }
diff --git a/target-i386/machine.c b/target-i386/machine.c
index 15b3f31..4f72ba8 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -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()
     }
 };
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* Re: [PATCH 09/11] kvm/x86: distingiush hyper-v guest crash notification
  2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:09     ` Paolo Bonzini
  -1 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-22 16:09 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: kvm, qemu-devel, Andrey Smetanin, Gleb Natapov



On 22/06/2015 18:05, Denis V. Lunev wrote:
> From: Andrey Smetanin <asmetanin@virtuozzo.com>
> 
> 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.
> 
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Gleb Natapov <gleb@kernel.org>
> ---
>  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(-)
> 
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index 6b18015..f49502a 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -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)
> diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
> index 39aee93..dc49527 100644
> --- a/arch/x86/kvm/hyperv.h
> +++ b/arch/x86/kvm/hyperv.h
> @@ -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);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 111fa83..db4eecb 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 09/11] kvm/x86: distingiush hyper-v guest crash notification
@ 2015-06-22 16:09     ` Paolo Bonzini
  0 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-22 16:09 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: Andrey Smetanin, Gleb Natapov, qemu-devel, kvm



On 22/06/2015 18:05, Denis V. Lunev wrote:
> From: Andrey Smetanin <asmetanin@virtuozzo.com>
> 
> 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.
> 
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Gleb Natapov <gleb@kernel.org>
> ---
>  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(-)
> 
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index 6b18015..f49502a 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -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)
> diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
> index 39aee93..dc49527 100644
> --- a/arch/x86/kvm/hyperv.h
> +++ b/arch/x86/kvm/hyperv.h
> @@ -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);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 111fa83..db4eecb 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 10/11] qemu/kvm: kvm hyper-v based guest crash event handling
  2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:15     ` Paolo Bonzini
  -1 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-22 16:15 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: kvm, qemu-devel, Andrey Smetanin, Andreas Färber



On 22/06/2015 18:05, Denis V. Lunev wrote:
> +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.

> @@ -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:
> +            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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 10/11] qemu/kvm: kvm hyper-v based guest crash event handling
@ 2015-06-22 16:15     ` Paolo Bonzini
  0 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-22 16:15 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: Andrey Smetanin, qemu-devel, kvm, Andreas Färber



On 22/06/2015 18:05, Denis V. Lunev wrote:
> +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.

> @@ -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:
> +            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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 10/11] qemu/kvm: kvm hyper-v based guest crash event handling
  2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:17     ` Paolo Bonzini
  -1 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-22 16:17 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: kvm, qemu-devel, Andrey Smetanin, Andreas Färber

Another one...

On 22/06/2015 18:05, Denis V. Lunev wrote:
> +            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

> +                ret = 0;
> +                break;
--
To unsubscribe from this list: send the line "unsubscribe kvm" in

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 10/11] qemu/kvm: kvm hyper-v based guest crash event handling
@ 2015-06-22 16:17     ` Paolo Bonzini
  0 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-22 16:17 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: Andrey Smetanin, qemu-devel, kvm, Andreas Färber

Another one...

On 22/06/2015 18:05, Denis V. Lunev wrote:
> +            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

> +                ret = 0;
> +                break;

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
  2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 16:23     ` Andreas Färber
  -1 siblings, 0 replies; 62+ messages in thread
From: Andreas Färber @ 2015-06-22 16:23 UTC (permalink / raw)
  To: Denis V. Lunev
  Cc: kvm, qemu-devel, Andrey Smetanin, Paolo Bonzini, Juan Quintela

Am 22.06.2015 um 18:05 schrieb Denis V. Lunev:
> From: Andrey Smetanin <asmetanin@virtuozzo.com>
> 
> 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.
> 
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Andreas Färber <afaerber@suse.de>
> ---
[...]
> diff --git a/target-i386/machine.c b/target-i386/machine.c
> index 15b3f31..4f72ba8 100644
> --- a/target-i386/machine.c
> +++ b/target-i386/machine.c
> @@ -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

-- 
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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
@ 2015-06-22 16:23     ` Andreas Färber
  0 siblings, 0 replies; 62+ messages in thread
From: Andreas Färber @ 2015-06-22 16:23 UTC (permalink / raw)
  To: Denis V. Lunev
  Cc: Andrey Smetanin, Paolo Bonzini, qemu-devel, kvm, Juan Quintela

Am 22.06.2015 um 18:05 schrieb Denis V. Lunev:
> From: Andrey Smetanin <asmetanin@virtuozzo.com>
> 
> 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.
> 
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Andreas Färber <afaerber@suse.de>
> ---
[...]
> diff --git a/target-i386/machine.c b/target-i386/machine.c
> index 15b3f31..4f72ba8 100644
> --- a/target-i386/machine.c
> +++ b/target-i386/machine.c
> @@ -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

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
  2015-06-22 16:23     ` [Qemu-devel] " Andreas Färber
@ 2015-06-22 16:27       ` Paolo Bonzini
  -1 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-22 16:27 UTC (permalink / raw)
  To: Andreas Färber, Denis V. Lunev
  Cc: kvm, qemu-devel, Andrey Smetanin, Juan Quintela



On 22/06/2015 18:23, Andreas Färber wrote:
>> > @@ -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?

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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
@ 2015-06-22 16:27       ` Paolo Bonzini
  0 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-22 16:27 UTC (permalink / raw)
  To: Andreas Färber, Denis V. Lunev
  Cc: Andrey Smetanin, qemu-devel, kvm, Juan Quintela



On 22/06/2015 18:23, Andreas Färber wrote:
>> > @@ -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?

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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
  2015-06-22 16:27       ` [Qemu-devel] " Paolo Bonzini
@ 2015-06-22 16:33         ` Andreas Färber
  -1 siblings, 0 replies; 62+ messages in thread
From: Andreas Färber @ 2015-06-22 16:33 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Denis V. Lunev, kvm, qemu-devel, Andrey Smetanin, Juan Quintela

Am 22.06.2015 um 18:27 schrieb Paolo Bonzini:
> 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

-- 
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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
@ 2015-06-22 16:33         ` Andreas Färber
  0 siblings, 0 replies; 62+ messages in thread
From: Andreas Färber @ 2015-06-22 16:33 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Andrey Smetanin, Denis V. Lunev, qemu-devel, kvm, Juan Quintela

Am 22.06.2015 um 18:27 schrieb Paolo Bonzini:
> 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

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
  2015-06-22 16:33         ` [Qemu-devel] " Andreas Färber
@ 2015-06-22 16:35           ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:35 UTC (permalink / raw)
  To: Andreas Färber, Paolo Bonzini
  Cc: kvm, qemu-devel, Andrey Smetanin, Juan Quintela

On 22/06/15 19:33, Andreas Färber wrote:
> Am 22.06.2015 um 18:27 schrieb Paolo Bonzini:
>> 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
>
we'd better squash to avoid troubles. Any other issues?
--
To unsubscribe from this list: send the line "unsubscribe kvm" in

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
@ 2015-06-22 16:35           ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-22 16:35 UTC (permalink / raw)
  To: Andreas Färber, Paolo Bonzini
  Cc: Andrey Smetanin, qemu-devel, kvm, Juan Quintela

On 22/06/15 19:33, Andreas Färber wrote:
> Am 22.06.2015 um 18:27 schrieb Paolo Bonzini:
>> 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
>
we'd better squash to avoid troubles. Any other issues?

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
  2015-06-22 16:33         ` [Qemu-devel] " Andreas Färber
@ 2015-06-22 16:36           ` Paolo Bonzini
  -1 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-22 16:36 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Andrey Smetanin, Denis V. Lunev, qemu-devel, kvm, Juan Quintela



On 22/06/2015 18:33, Andreas Färber wrote:
>> > 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...

> 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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
@ 2015-06-22 16:36           ` Paolo Bonzini
  0 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-22 16:36 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Andrey Smetanin, Denis V. Lunev, qemu-devel, kvm, Juan Quintela



On 22/06/2015 18:33, Andreas Färber wrote:
>> > 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...

> 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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
  2015-06-22 16:36           ` [Qemu-devel] " Paolo Bonzini
@ 2015-06-22 17:46             ` Andreas Färber
  -1 siblings, 0 replies; 62+ messages in thread
From: Andreas Färber @ 2015-06-22 17:46 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Andrey Smetanin, Denis V. Lunev, qemu-devel, kvm, Juan Quintela

Am 22.06.2015 um 18:36 schrieb Paolo Bonzini:
> On 22/06/2015 18:33, Andreas Färber wrote:
>>>> 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

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
@ 2015-06-22 17:46             ` Andreas Färber
  0 siblings, 0 replies; 62+ messages in thread
From: Andreas Färber @ 2015-06-22 17:46 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Andrey Smetanin, Denis V. Lunev, qemu-devel, kvm, Juan Quintela

Am 22.06.2015 um 18:36 schrieb Paolo Bonzini:
> On 22/06/2015 18:33, Andreas Färber wrote:
>>>> 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

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 07/11] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
  2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 23:52     ` Peter Hornyack
  -1 siblings, 0 replies; 62+ messages in thread
From: Peter Hornyack @ 2015-06-22 23:52 UTC (permalink / raw)
  To: Denis V. Lunev
  Cc: kvm, qemu-devel, Andrey Smetanin, Paolo Bonzini, Gleb Natapov

On Mon, Jun 22, 2015 at 9:05 AM, Denis V. Lunev <den@openvz.org> wrote:
> From: Andrey Smetanin <asmetanin@virtuozzo.com>
>
> Added hyper-v crash msr's(HV_X64_MSR_CRASH*) data and control
> geters and setters.
>
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Gleb Natapov <gleb@kernel.org>
> ---
>  arch/x86/kvm/hyperv.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  arch/x86/kvm/x86.c    |  4 ++++
>  2 files changed, 70 insertions(+)
>
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index f65fb622..0a7d373 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -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.

> +       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;

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.

> +       }
> +
> +       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;
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 2755c37..2046b78 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -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
--
To unsubscribe from this list: send the line "unsubscribe kvm" in

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 07/11] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
@ 2015-06-22 23:52     ` Peter Hornyack
  0 siblings, 0 replies; 62+ messages in thread
From: Peter Hornyack @ 2015-06-22 23:52 UTC (permalink / raw)
  To: Denis V. Lunev
  Cc: Andrey Smetanin, Paolo Bonzini, Gleb Natapov, qemu-devel, kvm

On Mon, Jun 22, 2015 at 9:05 AM, Denis V. Lunev <den@openvz.org> wrote:
> From: Andrey Smetanin <asmetanin@virtuozzo.com>
>
> Added hyper-v crash msr's(HV_X64_MSR_CRASH*) data and control
> geters and setters.
>
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Gleb Natapov <gleb@kernel.org>
> ---
>  arch/x86/kvm/hyperv.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  arch/x86/kvm/x86.c    |  4 ++++
>  2 files changed, 70 insertions(+)
>
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index f65fb622..0a7d373 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -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.

> +       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;

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.

> +       }
> +
> +       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;
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 2755c37..2046b78 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 09/11] kvm/x86: distingiush hyper-v guest crash notification
  2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-22 23:55     ` Peter Hornyack
  -1 siblings, 0 replies; 62+ messages in thread
From: Peter Hornyack @ 2015-06-22 23:55 UTC (permalink / raw)
  To: Denis V. Lunev
  Cc: kvm, qemu-devel, Andrey Smetanin, Paolo Bonzini, Gleb Natapov

On Mon, Jun 22, 2015 at 9:05 AM, Denis V. Lunev <den@openvz.org> wrote:
> From: Andrey Smetanin <asmetanin@virtuozzo.com>
>
> 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.
>
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Gleb Natapov <gleb@kernel.org>
> ---
>  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(-)
>
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index 6b18015..f49502a 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -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.

> -       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)
> diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
> index 39aee93..dc49527 100644
> --- a/arch/x86/kvm/hyperv.h
> +++ b/arch/x86/kvm/hyperv.h
> @@ -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);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 111fa83..db4eecb 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -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
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
--
To unsubscribe from this list: send the line "unsubscribe kvm" in

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 09/11] kvm/x86: distingiush hyper-v guest crash notification
@ 2015-06-22 23:55     ` Peter Hornyack
  0 siblings, 0 replies; 62+ messages in thread
From: Peter Hornyack @ 2015-06-22 23:55 UTC (permalink / raw)
  To: Denis V. Lunev
  Cc: Andrey Smetanin, Paolo Bonzini, Gleb Natapov, qemu-devel, kvm

On Mon, Jun 22, 2015 at 9:05 AM, Denis V. Lunev <den@openvz.org> wrote:
> From: Andrey Smetanin <asmetanin@virtuozzo.com>
>
> 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.
>
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Gleb Natapov <gleb@kernel.org>
> ---
>  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(-)
>
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index 6b18015..f49502a 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -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.

> -       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)
> diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
> index 39aee93..dc49527 100644
> --- a/arch/x86/kvm/hyperv.h
> +++ b/arch/x86/kvm/hyperv.h
> @@ -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);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 111fa83..db4eecb 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -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
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 07/11] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
  2015-06-22 23:52     ` [Qemu-devel] " Peter Hornyack
@ 2015-06-23  9:47       ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-23  9:47 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Peter Hornyack, kvm, qemu-devel, Andrey Smetanin, Gleb Natapov

On 23/06/15 02:52, Peter Hornyack wrote:
> On Mon, Jun 22, 2015 at 9:05 AM, Denis V. Lunev <den@openvz.org> wrote:
>> From: Andrey Smetanin <asmetanin@virtuozzo.com>
>>
>> Added hyper-v crash msr's(HV_X64_MSR_CRASH*) data and control
>> geters and setters.
>>
>> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>> CC: Paolo Bonzini <pbonzini@redhat.com>
>> CC: Gleb Natapov <gleb@kernel.org>
>> ---
>>   arch/x86/kvm/hyperv.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
>>   arch/x86/kvm/x86.c    |  4 ++++
>>   2 files changed, 70 insertions(+)
>>
>> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
>> index f65fb622..0a7d373 100644
>> --- a/arch/x86/kvm/hyperv.c
>> +++ b/arch/x86/kvm/hyperv.c
>> @@ -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.

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

>> +       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;
> 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.
>
>> +       }
>> +
>> +       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;
>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> index 2755c37..2046b78 100644
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
>> @@ -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


^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 07/11] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
@ 2015-06-23  9:47       ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-23  9:47 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Andrey Smetanin, Gleb Natapov, qemu-devel, kvm, Peter Hornyack

On 23/06/15 02:52, Peter Hornyack wrote:
> On Mon, Jun 22, 2015 at 9:05 AM, Denis V. Lunev <den@openvz.org> wrote:
>> From: Andrey Smetanin <asmetanin@virtuozzo.com>
>>
>> Added hyper-v crash msr's(HV_X64_MSR_CRASH*) data and control
>> geters and setters.
>>
>> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>> CC: Paolo Bonzini <pbonzini@redhat.com>
>> CC: Gleb Natapov <gleb@kernel.org>
>> ---
>>   arch/x86/kvm/hyperv.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
>>   arch/x86/kvm/x86.c    |  4 ++++
>>   2 files changed, 70 insertions(+)
>>
>> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
>> index f65fb622..0a7d373 100644
>> --- a/arch/x86/kvm/hyperv.c
>> +++ b/arch/x86/kvm/hyperv.c
>> @@ -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.

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

>> +       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;
> 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.
>
>> +       }
>> +
>> +       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;
>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> index 2755c37..2046b78 100644
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
>> @@ -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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 07/11] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
  2015-06-23  9:47       ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-23  9:51         ` Paolo Bonzini
  -1 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-23  9:51 UTC (permalink / raw)
  To: Denis V. Lunev
  Cc: Peter Hornyack, kvm, qemu-devel, Andrey Smetanin, Gleb Natapov



On 23/06/2015 11:47, Denis V. Lunev wrote:
>>
>> 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.

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

Paolo

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 07/11] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
@ 2015-06-23  9:51         ` Paolo Bonzini
  0 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-23  9:51 UTC (permalink / raw)
  To: Denis V. Lunev
  Cc: Andrey Smetanin, Gleb Natapov, qemu-devel, kvm, Peter Hornyack



On 23/06/2015 11:47, Denis V. Lunev wrote:
>>
>> 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.

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

Paolo

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 09/11] kvm/x86: distingiush hyper-v guest crash notification
  2015-06-22 23:55     ` [Qemu-devel] " Peter Hornyack
@ 2015-06-23  9:52       ` Paolo Bonzini
  -1 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-23  9:52 UTC (permalink / raw)
  To: Peter Hornyack, Denis V. Lunev
  Cc: kvm, qemu-devel, Andrey Smetanin, Gleb Natapov



On 23/06/2015 01:55, Peter Hornyack wrote:
>> > -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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 09/11] kvm/x86: distingiush hyper-v guest crash notification
@ 2015-06-23  9:52       ` Paolo Bonzini
  0 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-23  9:52 UTC (permalink / raw)
  To: Peter Hornyack, Denis V. Lunev
  Cc: Andrey Smetanin, Gleb Natapov, qemu-devel, kvm



On 23/06/2015 01:55, Peter Hornyack wrote:
>> > -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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
  2015-06-22 17:46             ` [Qemu-devel] " Andreas Färber
@ 2015-06-23  9:53               ` Paolo Bonzini
  -1 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-23  9:53 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Denis V. Lunev, kvm, qemu-devel, Andrey Smetanin, Juan Quintela



On 22/06/2015 19:46, Andreas Färber wrote:
>>>>> >>>> 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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured
@ 2015-06-23  9:53               ` Paolo Bonzini
  0 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-23  9:53 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Andrey Smetanin, Denis V. Lunev, qemu-devel, kvm, Juan Quintela



On 22/06/2015 19:46, Andreas Färber wrote:
>>>>> >>>> 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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 07/11] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
  2015-06-23  9:51         ` [Qemu-devel] " Paolo Bonzini
@ 2015-06-23 10:08           ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-23 10:08 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Peter Hornyack, kvm, qemu-devel, Andrey Smetanin, Gleb Natapov

On 23/06/15 12:51, Paolo Bonzini wrote:
>
> On 23/06/2015 11:47, Denis V. Lunev wrote:
>>> 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.
> 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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 07/11] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
@ 2015-06-23 10:08           ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-23 10:08 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Andrey Smetanin, Gleb Natapov, qemu-devel, kvm, Peter Hornyack

On 23/06/15 12:51, Paolo Bonzini wrote:
>
> On 23/06/2015 11:47, Denis V. Lunev wrote:
>>> 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.
> 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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 07/11] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
  2015-06-23 10:08           ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-23 10:30             ` Paolo Bonzini
  -1 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-23 10:30 UTC (permalink / raw)
  To: Denis V. Lunev
  Cc: Peter Hornyack, kvm, qemu-devel, Andrey Smetanin, Gleb Natapov



On 23/06/2015 12:08, Denis V. Lunev wrote:
> 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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 07/11] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
@ 2015-06-23 10:30             ` Paolo Bonzini
  0 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-23 10:30 UTC (permalink / raw)
  To: Denis V. Lunev
  Cc: Andrey Smetanin, Gleb Natapov, qemu-devel, kvm, Peter Hornyack



On 23/06/2015 12:08, Denis V. Lunev wrote:
> 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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 01/11] kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file
  2015-06-22 16:04   ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-25 10:25     ` Denis V. Lunev
  -1 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-25 10:25 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, qemu-devel, Andrey Smetanin, Gleb Natapov

On 22/06/15 19:04, Denis V. Lunev wrote:
> From: Andrey Smetanin <asmetanin@virtuozzo.com>
>
> 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.
>
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Gleb Natapov <gleb@kernel.org>

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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 01/11] kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file
@ 2015-06-25 10:25     ` Denis V. Lunev
  0 siblings, 0 replies; 62+ messages in thread
From: Denis V. Lunev @ 2015-06-25 10:25 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Andrey Smetanin, Gleb Natapov, qemu-devel, kvm

On 22/06/15 19:04, Denis V. Lunev wrote:
> From: Andrey Smetanin <asmetanin@virtuozzo.com>
>
> 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.
>
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Gleb Natapov <gleb@kernel.org>

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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCH 01/11] kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file
  2015-06-25 10:25     ` [Qemu-devel] " Denis V. Lunev
@ 2015-06-25 10:26       ` Paolo Bonzini
  -1 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-25 10:26 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: kvm, qemu-devel, Andrey Smetanin, Gleb Natapov



On 25/06/2015 12:25, Denis V. Lunev wrote:
> 
> 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

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [Qemu-devel] [PATCH 01/11] kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file
@ 2015-06-25 10:26       ` Paolo Bonzini
  0 siblings, 0 replies; 62+ messages in thread
From: Paolo Bonzini @ 2015-06-25 10:26 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: Andrey Smetanin, Gleb Natapov, qemu-devel, kvm



On 25/06/2015 12:25, Denis V. Lunev wrote:
> 
> 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

^ permalink raw reply	[flat|nested] 62+ messages in thread

end of thread, other threads:[~2015-06-25 10:26 UTC | newest]

Thread overview: 62+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-22 16:04 [PATCH v2 0/11] HyperV equivalent of pvpanic driver Denis V. Lunev
2015-06-22 16:04 ` [Qemu-devel] " Denis V. Lunev
2015-06-22 16:04 ` [PATCH 01/11] kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file Denis V. Lunev
2015-06-22 16:04   ` [Qemu-devel] " Denis V. Lunev
2015-06-25 10:25   ` Denis V. Lunev
2015-06-25 10:25     ` [Qemu-devel] " Denis V. Lunev
2015-06-25 10:26     ` Paolo Bonzini
2015-06-25 10:26       ` [Qemu-devel] " Paolo Bonzini
2015-06-22 16:04 ` [PATCH 02/11] kvm: introduce vcpu_debug = kvm_debug + vcpu context Denis V. Lunev
2015-06-22 16:04   ` [Qemu-devel] " Denis V. Lunev
2015-06-22 16:05 ` [PATCH 03/11] kvm: add hyper-v crash msrs constants Denis V. Lunev
2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
2015-06-22 16:05 ` [PATCH 04/11] kvm/x86: added hyper-v crash msrs into kvm hyperv context Denis V. Lunev
2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
2015-06-22 16:05 ` [PATCH 05/11] kvm: added KVM_REQ_HV_CRASH value to notify qemu about Hyper-V crash Denis V. Lunev
2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
2015-06-22 16:05 ` [PATCH 06/11] kvm/x86: mark hyper-v crash msrs as partition wide Denis V. Lunev
2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
2015-06-22 16:05 ` [PATCH 07/11] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers Denis V. Lunev
2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
2015-06-22 23:52   ` Peter Hornyack
2015-06-22 23:52     ` [Qemu-devel] " Peter Hornyack
2015-06-23  9:47     ` Denis V. Lunev
2015-06-23  9:47       ` [Qemu-devel] " Denis V. Lunev
2015-06-23  9:51       ` Paolo Bonzini
2015-06-23  9:51         ` [Qemu-devel] " Paolo Bonzini
2015-06-23 10:08         ` Denis V. Lunev
2015-06-23 10:08           ` [Qemu-devel] " Denis V. Lunev
2015-06-23 10:30           ` Paolo Bonzini
2015-06-23 10:30             ` [Qemu-devel] " Paolo Bonzini
2015-06-22 16:05 ` [PATCH 08/11] kvm/x86: add sending hyper-v crash notification to user space Denis V. Lunev
2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
2015-06-22 16:05 ` [PATCH 09/11] kvm/x86: distingiush hyper-v guest crash notification Denis V. Lunev
2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
2015-06-22 16:09   ` Paolo Bonzini
2015-06-22 16:09     ` [Qemu-devel] " Paolo Bonzini
2015-06-22 23:55   ` Peter Hornyack
2015-06-22 23:55     ` [Qemu-devel] " Peter Hornyack
2015-06-23  9:52     ` Paolo Bonzini
2015-06-23  9:52       ` [Qemu-devel] " Paolo Bonzini
2015-06-22 16:05 ` [PATCH 10/11] qemu/kvm: kvm hyper-v based guest crash event handling Denis V. Lunev
2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
2015-06-22 16:15   ` Paolo Bonzini
2015-06-22 16:15     ` [Qemu-devel] " Paolo Bonzini
2015-06-22 16:17   ` Paolo Bonzini
2015-06-22 16:17     ` [Qemu-devel] " Paolo Bonzini
2015-06-22 16:05 ` [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured Denis V. Lunev
2015-06-22 16:05   ` [Qemu-devel] " Denis V. Lunev
2015-06-22 16:23   ` Andreas Färber
2015-06-22 16:23     ` [Qemu-devel] " Andreas Färber
2015-06-22 16:27     ` Paolo Bonzini
2015-06-22 16:27       ` [Qemu-devel] " Paolo Bonzini
2015-06-22 16:33       ` Andreas Färber
2015-06-22 16:33         ` [Qemu-devel] " Andreas Färber
2015-06-22 16:35         ` Denis V. Lunev
2015-06-22 16:35           ` [Qemu-devel] " Denis V. Lunev
2015-06-22 16:36         ` Paolo Bonzini
2015-06-22 16:36           ` [Qemu-devel] " Paolo Bonzini
2015-06-22 17:46           ` Andreas Färber
2015-06-22 17:46             ` [Qemu-devel] " Andreas Färber
2015-06-23  9:53             ` Paolo Bonzini
2015-06-23  9:53               ` [Qemu-devel] " Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.