From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Andrey Smetanin" <asmetanin@virtuozzo.com>,
"Denis V. Lunev" <den@openvz.org>,
"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [PULL 07/24] i386/kvm: Hyper-v crash msrs set/get'ers and migration
Date: Wed, 16 Sep 2015 14:29:38 +0200 [thread overview]
Message-ID: <1442406595-14296-8-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1442406595-14296-1-git-send-email-pbonzini@redhat.com>
From: Andrey Smetanin <asmetanin@virtuozzo.com>
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.
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>
Message-Id: <1435924905-8926-13-git-send-email-den@openvz.org>
[Folks, stop abrviating variable names!!! Also fix compilation on
non-Linux/x86. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target-i386/cpu-qom.h | 1 +
target-i386/cpu.c | 1 +
target-i386/cpu.h | 2 ++
target-i386/kvm.c | 32 +++++++++++++++++++++++++++++++-
target-i386/machine.c | 27 +++++++++++++++++++++++++++
5 files changed, 62 insertions(+), 1 deletion(-)
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 cfb8aa7..7c52714 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -3121,6 +3121,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 af97772..5d515f6 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -21,6 +21,7 @@
#include "config.h"
#include "qemu-common.h"
+#include "standard-headers/asm-x86/hyperv.h"
#ifdef TARGET_X86_64
#define TARGET_LONG_BITS 64
@@ -908,6 +909,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_params[HV_X64_MSR_CRASH_PARAMS];
/* exception/interrupt handling */
int error_code;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index d8a11be..7b0ba17 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;
@@ -457,7 +458,8 @@ static bool hyperv_enabled(X86CPU *cpu)
return kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0 &&
(hyperv_hypercall_available(cpu) ||
cpu->hyperv_time ||
- cpu->hyperv_relaxed_timing);
+ cpu->hyperv_relaxed_timing ||
+ cpu->hyperv_crash);
}
static Error *invtsc_mig_blocker;
@@ -523,6 +525,10 @@ int kvm_arch_init_vcpu(CPUState *cs)
c->eax |= 0x200;
has_msr_hv_tsc = true;
}
+ if (cpu->hyperv_crash && has_msr_hv_crash) {
+ c->edx |= HV_X64_GUEST_CRASH_MSR_AVAILABLE;
+ }
+
c = &cpuid_data.entries[cpuid_i++];
c->function = HYPERV_CPUID_ENLIGHTMENT_INFO;
if (cpu->hyperv_relaxed_timing) {
@@ -843,6 +849,10 @@ static int kvm_get_supported_msrs(KVMState *s)
has_msr_xss = true;
continue;
}
+ if (kvm_msr_list->indices[i] == HV_X64_MSR_CRASH_CTL) {
+ has_msr_hv_crash = true;
+ continue;
+ }
}
}
@@ -1375,6 +1385,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_params[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++],
@@ -1730,6 +1750,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;
@@ -1877,6 +1904,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_params[index - HV_X64_MSR_CRASH_P0] = msrs[i].data;
+ break;
case MSR_MTRRdefType:
env->mtrr_deftype = msrs[i].data;
break;
diff --git a/target-i386/machine.c b/target-i386/machine.c
index a0df64b..9fa0563 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -661,6 +661,32 @@ static const VMStateDescription vmstate_msr_hyperv_time = {
}
};
+static bool hyperv_crash_enable_needed(void *opaque)
+{
+ X86CPU *cpu = opaque;
+ CPUX86State *env = &cpu->env;
+ int i;
+
+ for (i = 0; i < HV_X64_MSR_CRASH_PARAMS; i++) {
+ if (env->msr_hv_crash_params[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_params,
+ X86CPU, HV_X64_MSR_CRASH_PARAMS),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
static bool avx512_needed(void *opaque)
{
X86CPU *cpu = opaque;
@@ -842,6 +868,7 @@ VMStateDescription vmstate_x86_cpu = {
&vmstate_msr_hypercall_hypercall,
&vmstate_msr_hyperv_vapic,
&vmstate_msr_hyperv_time,
+ &vmstate_msr_hyperv_crash,
&vmstate_avx512,
&vmstate_xss,
NULL
--
2.5.0
next prev parent reply other threads:[~2015-09-16 12:30 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-16 12:29 [Qemu-devel] [PULL 00/24] Misc patches for 2015-09-16 Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 01/24] pci: remove Link Training error from AER error list Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 02/24] update Linux headers to 4.3-rc1 Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 03/24] update-linux-headers: copy standard-headers files one by one Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 04/24] target-i386: move asm-x86/hyperv.h to standard-headers Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 05/24] cpu: Add crash_occurred flag into CPUState Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 06/24] kvm: Add kvm system event crash handler Paolo Bonzini
2015-09-16 12:29 ` Paolo Bonzini [this message]
2015-09-16 12:29 ` [Qemu-devel] [PULL 08/24] hmp-commands-info: move info_cmds content out of monitor.c Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 09/24] monitor: remove target-specific code from monitor.c Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 10/24] hmp-commands.hx: fix end of table info Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 11/24] monitor: added generation of documentation for hmp-commands-info.hx Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 12/24] qemu-char: Use g_new() & friends where that makes obvious sense Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 13/24] cpu-exec: Migrate some generic fns to cpu-exec-common Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 14/24] translate-all: Move tcg_handle_interrupt() to -common Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 15/24] tcg: split tcg_op_defs " Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 16/24] tcg: Move tci_tb_ptr " Paolo Bonzini
2015-09-16 17:50 ` Stefan Weil
2015-09-16 19:14 ` Peter Crosthwaite
2015-09-16 19:58 ` Stefan Weil
2015-09-17 1:04 ` Peter Crosthwaite
2015-09-16 12:29 ` [Qemu-devel] [PULL 17/24] translate: move real_host_page setting " Paolo Bonzini
2015-09-18 18:52 ` Dr. David Alan Gilbert
2015-09-18 20:38 ` Peter Crosthwaite
2015-09-16 12:29 ` [Qemu-devel] [PULL 18/24] cputlb: move CPU_LOOP() for tlb_reset() to exec.c Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 19/24] cputlb: Change tlb_set_dirty() arg to cpu Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 20/24] include/exec: Move cputlb exec.c defs out Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 21/24] monitor: uninclude cpu_ldst Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 22/24] checkpatch: Escape left braces in regex Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 23/24] nbd: release exp->blk after all clients are closed Paolo Bonzini
2015-09-16 12:29 ` [Qemu-devel] [PULL 24/24] Revert "rcu: init rcu_registry_lock after fork" Paolo Bonzini
2015-09-16 14:28 ` [Qemu-devel] [PULL 00/24] Misc patches for 2015-09-16 Eric Blake
2015-09-16 15:08 ` Peter Maydell
2015-09-16 15:41 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1442406595-14296-8-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=afaerber@suse.de \
--cc=asmetanin@virtuozzo.com \
--cc=den@openvz.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).