HyperV equivalent of pvpanic driver
Subsystems (5)
v5 cover HyperV equivalent of pvpanic driver
Windows 2012 guests can notify hypervisor about occurred guest crash (Windows bugcheck(BSOD)) by writing specific Hyper-V msrs. This patch does handling of this MSR's by KVM and sending notification to user space that allows to gather Windows guest crash dump by QEMU/LIBVIRT.
The idea is to provide functionality equal to pvpanic device without QEMU guest agent for Windows.
The idea is borrowed from Linux HyperV bus driver and validated against Windows 2k12.
Changes from v4:
* fixed typo in email of Andreas Färber <[email protected]> my vim strangely behaves on lines with extended Deutch chars
Changes from v3:
* remove unused HV_X64_MSR_CRASH_CTL_NOTIFY
* added documentation section about KVM_SYSTEM_EVENT_CRASH
* allow only supported values inside crash ctl msr
* qemu: split patch into generic crash handling patches and hyperv specific
* qemu: skip migration of crash ctl msr value
Changes from v2:
* forbid modification crash ctl msr by guest
* qemu_system_guest_panicked usage in pvpanic and s390x
* hyper-v crash handler move from generic kvm to i386
* hyper-v crash handler: skip fetching crash msrs just mark crash occured
* sync with linux-next 20150629
* patch 11 squashed to patch 10
* patch 9 squashed to patch 7
Changes from v1:
* hyperv code move to hyperv.c
* added read handlers of crash data msrs
* added per vm and per cpu hyperv context structures
* added saving crash msrs inside qemu cpu state
* added qemu fetch and update of crash msrs
* added qemu crash msrs store in cpu state and it's migration
PATCH v5 1/12 kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file
From: Andrey Smetanin <[email protected]>
This patch introduce Hyper-V related source code file - hyperv.c and per vm and per vcpu hyperv context structures.
All Hyper-V MSR's and hypercall code moved into hyperv.c. All Hyper-V kvm/vcpu fields moved into appropriate hyperv context structures. Copyrights and authors information copied from x86.c to hyperv.c.
--- arch/x86/include/asm/kvm_host.h | 20 ++- arch/x86/kvm/Makefile | 4 +- arch/x86/kvm/hyperv.c | 307 ++++++++++++++++++++++++++++++++++++++++ arch/x86/kvm/hyperv.h | 32 +++++ arch/x86/kvm/lapic.h | 2 +- arch/x86/kvm/x86.c | 265 +--------------------------------- arch/x86/kvm/x86.h | 5 + 7 files changed, 366 insertions(+), 269 deletions(-) create mode 100644 arch/x86/kvm/hyperv.c create mode 100644 arch/x86/kvm/hyperv.h
arch/x86/include/asm/kvm_host.h +14 -6
@@ -358,6 +358,11 @@ struct kvm_mtrr {struct list_head head; }; +/* Hyper-V per vcpu emulation context */ +struct kvm_vcpu_hv { +u64 hv_vapic; +}; +struct kvm_vcpu_arch {/* * rip and regs accesses must go through
@@ -514,8 +519,7 @@ struct kvm_vcpu_arch {/* used for guest single stepping over the given code position */ unsigned long singlestep_rip; -/* fields used by HYPER-V emulation */ -u64 hv_vapic; +struct kvm_vcpu_hv hyperv;cpumask_var_t wbinvd_dirty_mask;
@@ -586,6 +590,13 @@ struct kvm_apic_map {struct kvm_lapic *logical_map[16 ][16 ]; }; +/* Hyper-V emulation context */ +struct kvm_hv { +u64 hv_guest_os_id; +u64 hv_hypercall; +u64 hv_tsc_page; +}; +struct kvm_arch {unsigned int n_used_mmu_pages;unsigned int n_requested_mmu_pages;
@@ -643,10 +654,7 @@ struct kvm_arch {/* reads protected by irq_srcu, writes by irq_lock */ struct hlist_head mask_notifier_list; -/* fields used by HYPER-V emulation */ -u64 hv_guest_os_id; -u64 hv_hypercall; -u64 hv_tsc_page; +struct kvm_hv hyperv;#ifdef CONFIG_KVM_MMU_AUDIT int audit_point;
arch/x86/kvm/Makefile +3 -1
@@ -12,7 +12,9 @@ kvm-y += $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o \ kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o kvm-y += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \ - i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o + i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o \ + hyperv.o + kvm-$(CONFIG_KVM_DEVICE_ASSIGNMENT) += assigned-dev.o iommu.o kvm-intel-y += vmx.o pmu_intel.o kvm-amd-y += svm.o pmu_amd.o
arch/x86/kvm/hyperv.c new file +307 -0
307 lines not on this page · raw message
arch/x86/kvm/hyperv.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* KVM Microsoft Hyper-V emulation +* +* derived from arch/x86/kvm/x86.c +* +* Copyright (C) 2006 Qumranet, Inc. +* Copyright (C) 2008 Qumranet, Inc. +* Copyright IBM Corporation, 2008 +* Copyright 2010 Red Hat, Inc. and/or its affiliates. +* Copyright (C) 2015 Andrey Smetanin <[email protected]> +* +* Authors: +* Avi Kivity <[email protected]> +* Yaniv Kamay <[email protected]> +* Amit Shah <[email protected]> +* Ben-Ami Yassour <[email protected]> +* Andrey Smetanin <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +*/ + +#ifndef __ARCH_X86_KVM_HYPERV_H__ +#define __ARCH_X86_KVM_HYPERV_H__ + +int kvm_hv_set_msr_common (struct kvm_vcpu *vcpu,u32 msr,u64 data); +int kvm_hv_get_msr_common (struct kvm_vcpu *vcpu,u32 msr,u64 *pdata); +bool kvm_hv_hypercall_enabled (struct kvm *kvm); +int kvm_hv_hypercall (struct kvm_vcpu *vcpu); + +#endif
arch/x86/kvm/lapic.h +1 -1
@@ -90,7 +90,7 @@ int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);static inline bool kvm_hv_vapic_assist_page_enabled (struct kvm_vcpu *vcpu) { -return vcpu->arch.hv_vapic &HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE ; +return vcpu->arch.hyperv.hv_vapic &HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE ; }int kvm_lapic_enable_pv_eoi (struct kvm_vcpu *vcpu,u64 data);
arch/x86/kvm/x86.c +4 -261
307 lines not on this page · raw message
arch/x86/kvm/x86.h +5 -0
@@ -147,6 +147,11 @@ static inline void kvm_register_writel(struct kvm_vcpu *vcpu,return kvm_register_write (vcpu, reg, val); } +static inline u64 get_kernel_ns (void ) +{ +return ktime_get_boot_ns (); +} +void kvm_before_handle_nmi (struct kvm_vcpu *vcpu);void kvm_after_handle_nmi (struct kvm_vcpu *vcpu);void kvm_set_pending_timer (struct kvm_vcpu *vcpu);
Signature · 1 line
2.1.4
PATCH v5 2/12 kvm: introduce vcpu_debug = kvm_debug + vcpu context
In reply to Denis V. LunevFrom: Andrey Smetanin <[email protected]>
vcpu_debug is useful macro like kvm_debug but additionally includes vcpu context inside output.
--- include/linux/kvm_host.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/kvm_host.h +3 -0
@@ -424,6 +424,9 @@ struct kvm {#define vcpu_unimpl (vcpu, fmt, ...) \ kvm_pr_unimpl("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__) +#define vcpu_debug (vcpu, fmt, ...) \ + kvm_debug("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__) +static inline struct kvm_vcpu *kvm_get_vcpu (struct kvm *kvm,int i) {smp_rmb ();
Signature · 1 line
2.1.4
PATCH v5 3/12 kvm: add hyper-v crash msrs values
In reply to Denis V. LunevFrom: Andrey Smetanin <[email protected]>
Added Hyper-V crash msrs values - HV_X64_MSR_CRASH*.
--- arch/x86/include/uapi/asm/hyperv.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/x86/include/uapi/asm/hyperv.h +11 -0
@@ -199,6 +199,17 @@#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6#define HV_X64_MSR_STIMER3_COUNT 0x400000B7 +/* Hyper-V guest crash notification MSR's */ +#define HV_X64_MSR_CRASH_P0 0x40000100 +#define HV_X64_MSR_CRASH_P1 0x40000101 +#define HV_X64_MSR_CRASH_P2 0x40000102 +#define HV_X64_MSR_CRASH_P3 0x40000103 +#define HV_X64_MSR_CRASH_P4 0x40000104 +#define HV_X64_MSR_CRASH_CTL 0x40000105 +#define HV_X64_MSR_CRASH_CTL_NOTIFY (1ULL << 63) +#define HV_X64_MSR_CRASH_PARAMS \ + (1 + (HV_X64_MSR_CRASH_P4 - HV_X64_MSR_CRASH_P0)) +#define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK \
Signature · 1 line
2.1.4
PATCH v5 4/12 kvm/x86: added hyper-v crash msrs into kvm hyperv context
In reply to Denis V. LunevFrom: Andrey Smetanin <[email protected]>
Added kvm Hyper-V context hv crash variables as storage of Hyper-V crash msrs.
--- arch/x86/include/asm/kvm_host.h | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/include/asm/kvm_host.h +4 -0
@@ -595,6 +595,10 @@ struct kvm_hv {u64 hv_guest_os_id;u64 hv_hypercall;u64 hv_tsc_page; + +/* Hyper-v based guest crash (NT kernel bugcheck) parameters */ +u64 hv_crash_param[HV_X64_MSR_CRASH_PARAMS ]; +u64 hv_crash_ctl; };struct kvm_arch {
Signature · 1 line
2.1.4
PATCH v5 5/12 kvm: added KVM_REQ_HV_CRASH value to notify qemu about hyper-v crash
In reply to Denis V. LunevFrom: Andrey Smetanin <[email protected]>
Added KVM_REQ_HV_CRASH - vcpu request used for notify user space(QEMU) about Hyper-V crash.
--- include/linux/kvm_host.h | 1 + 1 file changed, 1 insertion(+)
include/linux/kvm_host.h +1 -0
@@ -139,6 +139,7 @@ static inline bool is_error_page(struct page *page)#define KVM_REQ_DISABLE_IBS 24#define KVM_REQ_APIC_PAGE_RELOAD 25#define KVM_REQ_SMI 26 +#define KVM_REQ_HV_CRASH 27#define KVM_USERSPACE_IRQ_SOURCE_ID 0#define KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID 1
Signature · 1 line
2.1.4
PATCH v5 6/12 kvm/x86: mark hyper-v crash msrs as partition wide
In reply to Denis V. LunevFrom: Andrey Smetanin <[email protected]>
Hyper-V crash msr's are per vm, aren't per vcpu, so mark them as partition wide.
--- arch/x86/kvm/hyperv.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/kvm/hyperv.c +2 -0
@@ -39,6 +39,8 @@ static bool kvm_hv_msr_partition_wide(u32 msr)case HV_X64_MSR_HYPERCALL :case HV_X64_MSR_REFERENCE_TSC :case HV_X64_MSR_TIME_REF_COUNT : +case HV_X64_MSR_CRASH_CTL : + case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4: r = true;break ; }
Signature · 1 line
2.1.4
PATCH v5 7/12 kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
In reply to Denis V. LunevFrom: Andrey Smetanin <[email protected]>
Added hyper-v crash msr's(HV_X64_MSR_CRASH*) data and control geters and setters. Userspace should check that such msr's available by check of KVM_CAP_HYPERV_MSR_CRASH capability.
User space allowed to setup Hyper-V crash ctl msr.
This msr should be setup to HV_X64_MSR_CRASH_CTL_NOTIFY value so Hyper-V guest knows it can send crash data to host. But Hyper-V guest notifies about crash event by writing the same HV_X64_MSR_CRASH_CTL_NOTIFY value into crash ctl msr. So both user space and guest writes inside ctl msr the same value and this patch distingiush the moment of actual guest crash by checking host initiated value from msr info. Also patch prevents modification of crash ctl msr by guest.
--- arch/x86/kvm/hyperv.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++-- arch/x86/kvm/hyperv.h | 2 +- arch/x86/kvm/x86.c | 8 +++++- include/uapi/linux/kvm.h | 1 + 4 files changed, 80 insertions(+), 5 deletions(-)
arch/x86/kvm/hyperv.c +71 -3
@@ -48,7 +48,63 @@ static bool kvm_hv_msr_partition_wide(u32 msr)return r; } -static int kvm_hv_set_msr_pw (struct kvm_vcpu *vcpu,u32 msr,u64 data) +static int kvm_hv_msr_get_crash_data (struct kvm_vcpu *vcpu, +u32 index,u64 *pdata) +{ +struct kvm_hv *hv = &vcpu->kvm->arch.hyperv; + +if (WARN_ON_ONCE (index >=ARRAY_SIZE (hv->hv_crash_param))) +return -EINVAL ; + + *pdata = hv->hv_crash_param[index]; +return 0 ; +} + +static int kvm_hv_msr_get_crash_ctl (struct kvm_vcpu *vcpu,u64 *pdata) +{ +struct kvm_hv *hv = &vcpu->kvm->arch.hyperv; + + *pdata = hv->hv_crash_ctl; +return 0 ; +} + +static int kvm_hv_msr_set_crash_ctl (struct kvm_vcpu *vcpu,u64 data,bool host) +{ +struct kvm_hv *hv = &vcpu->kvm->arch.hyperv; + +if (host) + hv->hv_crash_ctl = data &HV_X64_MSR_CRASH_CTL_NOTIFY ; + +if (!host && (data &HV_X64_MSR_CRASH_CTL_NOTIFY )) { + +vcpu_debug (vcpu,"hv crash (0x%llx 0x%llx 0x%llx 0x%llx 0x%llx)\n" , + hv->hv_crash_param[0 ], + hv->hv_crash_param[1 ], + hv->hv_crash_param[2 ], + hv->hv_crash_param[3 ], + hv->hv_crash_param[4 ]); + +/* Send notification about crash to user space */ +kvm_make_request (KVM_REQ_HV_CRASH , vcpu); + } + +return 0 ; +} + +static int kvm_hv_msr_set_crash_data (struct kvm_vcpu *vcpu, +u32 index,u64 data) +{ +struct kvm_hv *hv = &vcpu->kvm->arch.hyperv; + +if (WARN_ON_ONCE (index >=ARRAY_SIZE (hv->hv_crash_param))) +return -EINVAL ; + + hv->hv_crash_param[index] = data; +return 0 ; +} + +static int kvm_hv_set_msr_pw (struct kvm_vcpu *vcpu,u32 msr,u64 data, +bool host) {struct kvm *kvm = vcpu->kvm;struct kvm_hv *hv = &kvm->arch.hyperv;
@@ -101,6 +157,12 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)mark_page_dirty (kvm, gfn);break ; } + case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4: +return kvm_hv_msr_set_crash_data (vcpu, + msr -HV_X64_MSR_CRASH_P0 , + data); +case HV_X64_MSR_CRASH_CTL : +return kvm_hv_msr_set_crash_ctl (vcpu, data, host);default :vcpu_unimpl (vcpu,"Hyper-V uhandled wrmsr: 0x%x data 0x%llx\n" , msr, data);
@@ -173,6 +235,12 @@ static int kvm_hv_get_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)case HV_X64_MSR_REFERENCE_TSC : data = hv->hv_tsc_page;break ; + case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4: +return kvm_hv_msr_get_crash_data (vcpu, + msr -HV_X64_MSR_CRASH_P0 , + pdata); +case HV_X64_MSR_CRASH_CTL : +return kvm_hv_msr_get_crash_ctl (vcpu, pdata);default :vcpu_unimpl (vcpu,"Hyper-V unhandled rdmsr: 0x%x\n" , msr);return 1 ;
@@ -217,13 +285,13 @@ static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)return 0 ; } -int kvm_hv_set_msr_common (struct kvm_vcpu *vcpu,u32 msr,u64 data) +int kvm_hv_set_msr_common (struct kvm_vcpu *vcpu,u32 msr,u64 data,bool host) {if (kvm_hv_msr_partition_wide (msr)) {int r;mutex_lock (&vcpu->kvm->lock); - r =kvm_hv_set_msr_pw (vcpu, msr, data); + r =kvm_hv_set_msr_pw (vcpu, msr, data, host);mutex_unlock (&vcpu->kvm->lock);return r; }else
arch/x86/kvm/hyperv.h +1 -1
@@ -24,7 +24,7 @@#ifndef __ARCH_X86_KVM_HYPERV_H__#define __ARCH_X86_KVM_HYPERV_H__ -int kvm_hv_set_msr_common (struct kvm_vcpu *vcpu,u32 msr,u64 data); +int kvm_hv_set_msr_common (struct kvm_vcpu *vcpu,u32 msr,u64 data,bool host);int kvm_hv_get_msr_common (struct kvm_vcpu *vcpu,u32 msr,u64 *pdata);bool kvm_hv_hypercall_enabled (struct kvm *kvm);int kvm_hv_hypercall (struct kvm_vcpu *vcpu);
arch/x86/kvm/x86.c +7 -1
@@ -2103,7 +2103,10 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)*/ break ; case HV_X64_MSR_GUEST_OS_ID ... HV_X64_MSR_SINT15: -return kvm_hv_set_msr_common (vcpu, msr, data); + case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4: +case HV_X64_MSR_CRASH_CTL : +return kvm_hv_set_msr_common (vcpu, msr, data, + msr_info->host_initiated);case MSR_IA32_BBL_CR_CTL3 :/* Drop writes to this legacy MSR -- see rdmsr * counterpart for further detail.
@@ -2304,6 +2307,8 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) msr_info->data =0x20000000 ;break ; case HV_X64_MSR_GUEST_OS_ID ... HV_X64_MSR_SINT15: + case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4: +case HV_X64_MSR_CRASH_CTL :return kvm_hv_get_msr_common (vcpu, msr_info->index, &msr_info->data);break ;
@@ -2456,6 +2461,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_TSC_DEADLINE_TIMER :case KVM_CAP_ENABLE_CAP_VM :case KVM_CAP_DISABLE_QUIRKS : +case KVM_CAP_HYPERV_MSR_CRASH :#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT case KVM_CAP_ASSIGN_DEV_IRQ :case KVM_CAP_PCI_2_3 :
include/uapi/linux/kvm.h +1 -0
@@ -817,6 +817,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_DISABLE_QUIRKS 116#define KVM_CAP_X86_SMM 117#define KVM_CAP_MULTI_ADDRESS_SPACE 118 +#define KVM_CAP_HYPERV_MSR_CRASH 119#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
2.1.4
Paolo Bonzini
maintainerRe: [PATCH 07/12] kvm/x86: added hyper-v crash data and ctl msr's get/set'ers
Quoted 5 lines · Denis V. Lunev
From: Andrey Smetanin <[email protected]>
Added hyper-v crash msr's(HV_X64_MSR_CRASH*) data and control geters and setters. Userspace should check that such msr's available by check of
KVM_CAP_HYPERV_MSR_CRASHcapability.
It should use the existing KVM_GET_SUPPORTED_MSRS infrastructure. See emulated_msrs where other Hyper-V MSRs are listed.
Paolo
PATCH v5 8/12 kvm/x86: add sending hyper-v crash notification to user space
In reply to Denis V. LunevFrom: Andrey Smetanin <[email protected]>
Sending of notification is done by exiting vcpu to user space if KVM_REQ_HV_CRASH is enabled for vcpu. At exit to user space the kvm_run structure contains system_event with type KVM_SYSTEM_EVENT_CRASH to notify about guest crash occured.
--- Documentation/virtual/kvm/api.txt | 5 +++++ arch/x86/kvm/x86.c | 6 ++++++ include/uapi/linux/kvm.h | 1 + 3 files changed, 12 insertions(+)
Documentation/virtual/kvm/api.txt +5 -0
@@ -3277,6 +3277,7 @@ should put the acknowledged interrupt vector into the 'epr' field. struct { #define KVM_SYSTEM_EVENT_SHUTDOWN 1 #define KVM_SYSTEM_EVENT_RESET 2 +#define KVM_SYSTEM_EVENT_CRASH 3 __u32 type; __u64 flags; } system_event;
@@ -3296,6 +3297,10 @@ Valid values for 'type' are: KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM. As with SHUTDOWN, userspace can choose to ignore the request, or to schedule the reset to occur in the future and may call KVM_RUN again. + KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest + has requested a crash condition maintenance. Userspace can choose + to ignore the request, or to gather VM memory core dump and/or + reset/shutdown of the VM. /* Fix the size of the union. */ char padding[256];
arch/x86/kvm/x86.c +6 -0
@@ -6265,6 +6265,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)vcpu_scan_ioapic (vcpu);if (kvm_check_request (KVM_REQ_APIC_PAGE_RELOAD , vcpu))kvm_vcpu_reload_apic_access_page (vcpu); +if (kvm_check_request (KVM_REQ_HV_CRASH , vcpu)) { + vcpu->run->exit_reason =KVM_EXIT_SYSTEM_EVENT ; + vcpu->run->system_event.type =KVM_SYSTEM_EVENT_CRASH ; + r =0 ; + goto out; + } }if (kvm_check_request (KVM_REQ_EVENT , vcpu) || req_int_win) {
include/uapi/linux/kvm.h +1 -0
@@ -317,6 +317,7 @@ struct kvm_run {struct {#define KVM_SYSTEM_EVENT_SHUTDOWN 1#define KVM_SYSTEM_EVENT_RESET 2 +#define KVM_SYSTEM_EVENT_CRASH 3__u32 type;__u64 flags; } system_event;
Signature · 1 line
2.1.4
PATCH v5 9/12 qemu: added qemu_system_guest_panicked() - generic guest panic handler
In reply to Denis V. LunevFrom: Andrey Smetanin <[email protected]>
There are pieces of guest panic handling code that can be shared in one generic function.
--- hw/misc/pvpanic.c | 3 +-- include/sysemu/sysemu.h | 1 + target-s390x/kvm.c | 11 ++--------- vl.c | 6 ++++++ 4 files changed, 10 insertions(+), 11 deletions(-)
hw/misc/pvpanic.c +1 -2
@@ -41,8 +41,7 @@ static void handle_event(int event) }if (event &PVPANIC_PANICKED ) { -qapi_event_send_guest_panicked (GUEST_PANIC_ACTION_PAUSE , &error_abort); -vm_stop (RUN_STATE_GUEST_PANICKED ); +qemu_system_guest_panicked ();return ; } }
include/sysemu/sysemu.h +1 -0
@@ -68,6 +68,7 @@ int qemu_reset_requested_get(void);void qemu_system_killed (int signal,pid_t pid);void qemu_devices_reset (void );void qemu_system_reset (bool report); +void qemu_system_guest_panicked (void );void qemu_add_exit_notifier (Notifier *notify);void qemu_remove_exit_notifier (Notifier *notify);
target-s390x/kvm.c +2 -9
@@ -1796,13 +1796,6 @@ static bool is_special_wait_psw(CPUState *cs)return cs->kvm_run->psw_addr ==0xfffUL ; } -static void guest_panicked (void ) -{ -qapi_event_send_guest_panicked (GUEST_PANIC_ACTION_PAUSE , - &error_abort); -vm_stop (RUN_STATE_GUEST_PANICKED ); -} -static void unmanageable_intercept (S390CPU *cpu,const char *str,int pswoffset) {CPUState *cs =CPU (cpu);
@@ -1811,7 +1804,7 @@ static void unmanageable_intercept(S390CPU *cpu, const char *str, int pswoffset) str, cs->cpu_index,ldq_phys (cs->as, cpu->env.psa + pswoffset), ldq_phys(cs->as, cpu->env.psa + pswoffset + 8));s390_cpu_halt (cpu); -guest_panicked (); +qemu_system_guest_panicked (); }static int handle_intercept (S390CPU *cpu)
@@ -1844,7 +1837,7 @@ static int handle_intercept(S390CPU *cpu)if (is_special_wait_psw (cs)) {qemu_system_shutdown_request (); }else { -guest_panicked (); +qemu_system_guest_panicked (); } } r =EXCP_HALTED ;
vl.c +6 -0
@@ -1721,6 +1721,12 @@ void qemu_system_reset(bool report)cpu_synchronize_all_post_reset (); } +void qemu_system_guest_panicked (void ) +{ +qapi_event_send_guest_panicked (GUEST_PANIC_ACTION_PAUSE , &error_abort); +vm_stop (RUN_STATE_GUEST_PANICKED ); +} +void qemu_system_reset_request (void ) {if (no_reboot) {
Signature · 1 line
2.1.4
PATCH v5 10/12 qemu/kvm: added kvm system event crash handler
In reply to Denis V. LunevFrom: Andrey Smetanin <[email protected]>
KVM kernel can receive guest crash events. Patch code calls appropriate handler for kernel guest crash event. Guest crash event recognized by KVM_SYSTEM_EVENT_CRASH type of system event.
--- kvm-all.c | 4 ++++ linux-headers/linux/kvm.h | 1 + 2 files changed, 5 insertions(+)
kvm-all.c +4 -0
@@ -1844,6 +1844,10 @@ int kvm_cpu_exec(CPUState *cpu)qemu_system_reset_request (); ret =EXCP_INTERRUPT ;break ; +case KVM_SYSTEM_EVENT_CRASH : +qemu_system_guest_panicked (); + ret =0 ; +break ;default :DPRINTF ("kvm_arch_handle_exit\n" ); ret =kvm_arch_handle_exit (cpu, run);
linux-headers/linux/kvm.h +1 -0
@@ -317,6 +317,7 @@ struct kvm_run {struct {#define KVM_SYSTEM_EVENT_SHUTDOWN 1#define KVM_SYSTEM_EVENT_RESET 2 +#define KVM_SYSTEM_EVENT_CRASH 3__u32 type;__u64 flags; } system_event;
Signature · 1 line
2.1.4
PATCH v5 11/12 qemu: add crash_occurred flag into CPUState
In reply to Denis V. LunevFrom: Andrey Smetanin <[email protected]>
CPUState->crash_occurred value inside CPUState marks that guest crash occurred. This value added into cpu common migration subsection.
--- exec.c | 19 +++++++++++++++++++ include/qom/cpu.h | 1 + vl.c | 3 +++ 3 files changed, 23 insertions(+)
exec.c +19 -0
@@ -465,6 +465,24 @@ static const VMStateDescription vmstate_cpu_common_exception_index = { } }; +static bool cpu_common_crash_occurred_needed (void *opaque) +{ +CPUState *cpu = opaque; + +return cpu->crash_occurred !=0 ; +} + +static const VMStateDescription vmstate_cpu_common_crash_occurred = { + .name ="cpu_common/crash_occurred" , + .version_id =1 , + .minimum_version_id =1 , + .needed = cpu_common_crash_occurred_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32 (crash_occurred, CPUState), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_cpu_common = { .name ="cpu_common" , .version_id =1 ,
@@ -478,6 +496,7 @@ const VMStateDescription vmstate_cpu_common = { }, .subsections = (const VMStateDescription*[]) { &vmstate_cpu_common_exception_index, + &vmstate_cpu_common_crash_occurred,NULL } };
include/qom/cpu.h +1 -0
@@ -263,6 +263,7 @@ struct CPUState {bool created;bool stop;bool stopped; +uint32_t crash_occurred;volatile sig_atomic_t exit_request;uint32_t interrupt_request;int singlestep_enabled;
vl.c +3 -0
@@ -1723,6 +1723,9 @@ void qemu_system_reset(bool report)void qemu_system_guest_panicked (void ) { +if (current_cpu) { + current_cpu->crash_occurred =1 ; + }qapi_event_send_guest_panicked (GUEST_PANIC_ACTION_PAUSE , &error_abort);vm_stop (RUN_STATE_GUEST_PANICKED ); }
Signature · 1 line
2.1.4
Re: [PATCH 11/12] qemu: add crash_occurred flag into CPUState
Hi,
This patch is clearly against QEMU, please name it "cpu: Add crash_...". (You may want to take a second look at the non-CPU patches, too.)
Am 02.07.2015 um 18:07 schrieb Denis V. Lunev:
Quoted 3 lines
From: Andrey Smetanin <[email protected]>
CPUState->crash_occurredvalue inside CPUState marks
"CPUState::crash_occurred field inside ..."
Quoted 1 line
that guest crash occurred. This value added into cpu common
"value is added"
Quoted 54 lines
migration subsection.
Signed-off-by Andrey Smetanin <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Paolo Bonzini <[email protected]>CC Andreas Färber <[email protected]>--- exec.c | 19 +++++++++++++++++++ include/qom/cpu.h | 1 + vl.c | 3 +++ 3 files changed, 23 insertions(+)exec.c +19
-0@@ -465,6 +465,24 @@ static const VMStateDescription vmstate_cpu_common_exception_index = { } }; +static bool cpu_common_crash_occurred_needed (void *opaque) +{ +CPUState *cpu = opaque; + +return cpu->crash_occurred !=0 ; +} + +static const VMStateDescription vmstate_cpu_common_crash_occurred = { + .name ="cpu_common/crash_occurred" , + .version_id =1 , + .minimum_version_id =1 , + .needed = cpu_common_crash_occurred_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32 (crash_occurred, CPUState), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_cpu_common = { .name ="cpu_common" , .version_id =1 ,@@ -478,6 +496,7 @@ const VMStateDescription vmstate_cpu_common = { }, .subsections = (const VMStateDescription*[]) { &vmstate_cpu_common_exception_index, + &vmstate_cpu_common_crash_occurred,NULL } };include/qom/cpu.h +0
-0
include/qom/cpu.h struct CPUState { · line 269
Quoted 7 lines
include/qom/cpu.h +1
-0@@ -263,6 +263,7 @@ struct CPUState {bool created;bool stop;bool stopped; +uint32_t crash_occurred;volatile sig_atomic_t exit_request;uint32_t interrupt_request;int singlestep_enabled;
If you add this field to CPUState, you'll also need to reset it in qom/cpu.c. Or is it intentionally persistent?
Looks good otherwise.
Regards,
Andreas
Quoted 14 lines
vl.c +3
-0@@ -1723,6 +1723,9 @@ void qemu_system_reset(bool report)void qemu_system_guest_panicked (void ) { +if (current_cpu) { + current_cpu->crash_occurred =1 ; + }qapi_event_send_guest_panicked (GUEST_PANIC_ACTION_PAUSE , &error_abort);vm_stop (RUN_STATE_GUEST_PANICKED ); }
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB 21284 (AG Nürnberg)
Paolo Bonzini
maintainerRe: [PATCH 11/12] qemu: add crash_occurred flag into CPUState
Quoted 6 lines · Andreas Färber
Quoted 4 lines
Quoted 4 lines
+ uint32_t crash_occurred; volatile sig_atomic_t exit_request; uint32_t interrupt_request; int singlestep_enabled;If you add this field to CPUState, you'll also need to reset it in
qom/cpu.c. Or is it intentionally persistent?
And since you are at it, you can make it a bool.
Paolo
PATCH v5 12/12 qemu/kvm/x86: hyper-v crash msrs set/get'ers and migration
In reply to Denis V. LunevFrom: Andrey Smetanin <[email protected]>
KVM Hyper-V based guests can notify hypervisor about occurred guest crash by writing into Hyper-V crash MSR's. This patch does handling and migration of HV_X64_MSR_CRASH_P0-P4, HV_X64_MSR_CRASH_CTL msrs. User can enable these MSR's by 'hv-crash' option.
--- linux-headers/asm-x86/hyperv.h | 13 +++++++++++++ linux-headers/linux/kvm.h | 1 + target-i386/cpu-qom.h | 1 + target-i386/cpu.c | 1 + target-i386/cpu.h | 2 ++ target-i386/kvm.c | 27 +++++++++++++++++++++++++++ target-i386/machine.c | 26 ++++++++++++++++++++++++++ 7 files changed, 71 insertions(+)
linux-headers/asm-x86/hyperv.h +13 -0
@@ -108,6 +108,8 @@#define HV_X64_HYPERCALL_PARAMS_XMM_AVAILABLE (1 << 4)/* Support for a virtual guest idle state is available */ #define HV_X64_GUEST_IDLE_STATE_AVAILABLE (1 << 5) +/* Guest crash data handler available */ +#define HV_X64_GUEST_CRASH_MSR_AVAILABLE (1 << 10)/* * Implementation recommendations. Indicates which behaviors the hypervisor
@@ -199,6 +201,17 @@#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6#define HV_X64_MSR_STIMER3_COUNT 0x400000B7 +/* Hypev-V guest crash notification MSR's */ +#define HV_X64_MSR_CRASH_P0 0x40000100 +#define HV_X64_MSR_CRASH_P1 0x40000101 +#define HV_X64_MSR_CRASH_P2 0x40000102 +#define HV_X64_MSR_CRASH_P3 0x40000103 +#define HV_X64_MSR_CRASH_P4 0x40000104 +#define HV_X64_MSR_CRASH_CTL 0x40000105 +#define HV_X64_MSR_CRASH_CTL_NOTIFY (1ULL << 63) +#define HV_X64_MSR_CRASH_PARAMS \ + (1 + (HV_X64_MSR_CRASH_P4 - HV_X64_MSR_CRASH_P0)) +#define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK \
linux-headers/linux/kvm.h +1 -0
@@ -818,6 +818,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_DISABLE_QUIRKS 116#define KVM_CAP_X86_SMM 117#define KVM_CAP_MULTI_ADDRESS_SPACE 118 +#define KVM_CAP_HYPERV_MSR_CRASH 119#ifdef KVM_CAP_IRQ_ROUTING
target-i386/cpu-qom.h +1 -0
@@ -89,6 +89,7 @@ typedef struct X86CPU {bool hyperv_relaxed_timing;int hyperv_spinlock_attempts;bool hyperv_time; +bool hyperv_crash;bool check_cpuid;bool enforce_cpuid;bool expose_kvm;
target-i386/cpu.c +1 -0
@@ -3117,6 +3117,7 @@ static Property x86_cpu_properties[] = {DEFINE_PROP_BOOL ("hv-relaxed" ,X86CPU , hyperv_relaxed_timing, false),DEFINE_PROP_BOOL ("hv-vapic" ,X86CPU , hyperv_vapic, false),DEFINE_PROP_BOOL ("hv-time" ,X86CPU , hyperv_time, false), +DEFINE_PROP_BOOL ("hv-crash" ,X86CPU , hyperv_crash, false),DEFINE_PROP_BOOL ("check" ,X86CPU , check_cpuid, false),DEFINE_PROP_BOOL ("enforce" ,X86CPU , enforce_cpuid, false), DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true),
target-i386/cpu.h +2 -0
@@ -21,6 +21,7 @@#include "config.h" #include "qemu-common.h" +#include <asm/hyperv.h> #ifdef TARGET_X86_64 #define TARGET_LONG_BITS 64
@@ -904,6 +905,7 @@ typedef struct CPUX86State {uint64_t msr_hv_guest_os_id;uint64_t msr_hv_vapic;uint64_t msr_hv_tsc; +uint64_t msr_hv_crash_prm[HV_X64_MSR_CRASH_PARAMS ];/* exception/interrupt handling */ int error_code;
target-i386/kvm.c +27 -0
@@ -79,6 +79,7 @@ static int lm_capable_kernel;static bool has_msr_hv_hypercall;static bool has_msr_hv_vapic;static bool has_msr_hv_tsc; +static bool has_msr_hv_crash;static bool has_msr_mtrr;static bool has_msr_xss;
@@ -515,6 +516,12 @@ int kvm_arch_init_vcpu(CPUState *cs) c->eax |=0x200 ; has_msr_hv_tsc = true; } +if (cpu->hyperv_crash && +kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV_MSR_CRASH ) >0 ) { + 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) {
@@ -1321,6 +1328,16 @@ static int kvm_put_msrs(X86CPU *cpu, int level)kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_REFERENCE_TSC , env->msr_hv_tsc); } +if (has_msr_hv_crash) { +int j; + +for (j =0 ; j <HV_X64_MSR_CRASH_PARAMS ; j++) +kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_CRASH_P0 + j, + env->msr_hv_crash_prm[j]); + +kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_CRASH_CTL , +HV_X64_MSR_CRASH_CTL_NOTIFY ); + }if (has_msr_mtrr) {kvm_msr_entry_set (&msrs[n++], MSR_MTRRdefType, env->mtrr_deftype); kvm_msr_entry_set(&msrs[n++],
@@ -1673,6 +1690,13 @@ static int kvm_get_msrs(X86CPU *cpu)if (has_msr_hv_tsc) { msrs[n++].index =HV_X64_MSR_REFERENCE_TSC ; } +if (has_msr_hv_crash) { +int j; + +for (j =0 ; j <HV_X64_MSR_CRASH_PARAMS ; j++) { + msrs[n++].index =HV_X64_MSR_CRASH_P0 + j; + } + }if (has_msr_mtrr) { msrs[n++].index = MSR_MTRRdefType; msrs[n++].index = MSR_MTRRfix64K_00000;
@@ -1817,6 +1841,9 @@ static int kvm_get_msrs(X86CPU *cpu)case HV_X64_MSR_REFERENCE_TSC : env->msr_hv_tsc = msrs[i].data;break ; + case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4: + env->msr_hv_crash_prm[index -HV_X64_MSR_CRASH_P0 ] = msrs[i].data; +break ;case MSR_MTRRdefType: env->mtrr_deftype = msrs[i].data;break ;
target-i386/machine.c +26 -0
@@ -661,6 +661,31 @@ static const VMStateDescription vmstate_msr_hyperv_time = { } }; +static bool hyperv_crash_enable_needed (void *opaque) +{ +X86CPU *cpu = opaque; +CPUX86State *env = &cpu->env; +int i; +for (i =0 ; i <HV_X64_MSR_CRASH_PARAMS ; i++) { +if (env->msr_hv_crash_prm[i]) { +return true; + } + } +return false; +} + +static const VMStateDescription vmstate_msr_hyperv_crash = { + .name ="cpu/msr_hyperv_crash" , + .version_id =1 , + .minimum_version_id =1 , + .needed = hyperv_crash_enable_needed, + .fields = (VMStateField []) { +VMSTATE_UINT64_ARRAY (env.msr_hv_crash_prm, +X86CPU ,HV_X64_MSR_CRASH_PARAMS ), +VMSTATE_END_OF_LIST () + } +}; +static bool avx512_needed (void *opaque) {X86CPU *cpu = opaque;
@@ -842,6 +867,7 @@ VMStateDescription vmstate_x86_cpu = { &vmstate_msr_hypercall_hypercall, &vmstate_msr_hyperv_vapic, &vmstate_msr_hyperv_time, + &vmstate_msr_hyperv_crash, &vmstate_avx512, &vmstate_xss,NULL
Signature · 1 line
2.1.4
Paolo Bonzini
maintainerRe: [PATCH 12/12] qemu/kvm/x86: hyper-v crash msrs set/get'ers and migration
target-i386/kvm.c int kvm_arch_init_vcpu(CPUState *cs) · line 524
Quoted 6 lines · Denis V. Lunev
target-i386/kvm.c +6
-0+if (cpu->hyperv_crash && +kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV_MSR_CRASH ) >0 ) { + c->edx |=HV_X64_GUEST_CRASH_MSR_AVAILABLE ; + has_msr_hv_crash = true; + } +
Please patch kvm_get_supported_msrs instead of adding a capability. The QEMU parts are otherwise okay.
Paolo