From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Subject: [Qemu-devel] [PULL 24/30] i386/kvm: add support for Hyper-V reenlightenment MSRs
Date: Wed, 9 May 2018 00:14:41 +0200 [thread overview]
Message-ID: <1525817687-34620-25-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1525817687-34620-1-git-send-email-pbonzini@redhat.com>
From: Vitaly Kuznetsov <vkuznets@redhat.com>
KVM recently gained support for Hyper-V Reenlightenment MSRs which are
required to make KVM-on-Hyper-V enable TSC page clocksource to its guests
when INVTSC is not passed to it (and it is not passed by default in Qemu
as it effectively blocks migration).
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Message-Id: <20180411115036.31832-2-vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/cpu.c | 4 +++-
target/i386/cpu.h | 4 ++++
target/i386/hyperv-proto.h | 9 ++++++++-
target/i386/kvm.c | 39 ++++++++++++++++++++++++++++++++++++++-
target/i386/machine.c | 24 ++++++++++++++++++++++++
5 files changed, 77 insertions(+), 3 deletions(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index a20fe26..b0a1c62 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -416,7 +416,8 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
NULL /* hv_vpindex_access */, NULL /* hv_msr_reset_access */,
NULL /* hv_msr_stats_access */, NULL /* hv_reftsc_access */,
NULL /* hv_msr_idle_access */, NULL /* hv_msr_frequency_access */,
- NULL, NULL, NULL, NULL,
+ NULL /* hv_msr_debug_access */, NULL /* hv_msr_reenlightenment_access */,
+ NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
@@ -4770,6 +4771,7 @@ static Property x86_cpu_properties[] = {
DEFINE_PROP_BOOL("hv-synic", X86CPU, hyperv_synic, false),
DEFINE_PROP_BOOL("hv-stimer", X86CPU, hyperv_stimer, false),
DEFINE_PROP_BOOL("hv-frequencies", X86CPU, hyperv_frequencies, false),
+ DEFINE_PROP_BOOL("hv-reenlightenment", X86CPU, hyperv_reenlightenment, false),
DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true),
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 1b219fa..b58b779 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1174,6 +1174,9 @@ typedef struct CPUX86State {
uint64_t msr_hv_synic_sint[HV_SINT_COUNT];
uint64_t msr_hv_stimer_config[HV_STIMER_COUNT];
uint64_t msr_hv_stimer_count[HV_STIMER_COUNT];
+ uint64_t msr_hv_reenlightenment_control;
+ uint64_t msr_hv_tsc_emulation_control;
+ uint64_t msr_hv_tsc_emulation_status;
uint64_t msr_rtit_ctrl;
uint64_t msr_rtit_status;
@@ -1297,6 +1300,7 @@ struct X86CPU {
bool hyperv_synic;
bool hyperv_stimer;
bool hyperv_frequencies;
+ bool hyperv_reenlightenment;
bool check_cpuid;
bool enforce_cpuid;
bool expose_kvm;
diff --git a/target/i386/hyperv-proto.h b/target/i386/hyperv-proto.h
index cb4d7f2..93352eb 100644
--- a/target/i386/hyperv-proto.h
+++ b/target/i386/hyperv-proto.h
@@ -35,7 +35,7 @@
#define HV_RESET_AVAILABLE (1u << 7)
#define HV_REFERENCE_TSC_AVAILABLE (1u << 9)
#define HV_ACCESS_FREQUENCY_MSRS (1u << 11)
-
+#define HV_ACCESS_REENLIGHTENMENTS_CONTROL (1u << 13)
/*
* HV_CPUID_FEATURES.EDX bits
@@ -130,6 +130,13 @@
#define HV_CRASH_CTL_NOTIFY (1ull << 63)
/*
+ * Reenlightenment notification MSRs
+ */
+#define HV_X64_MSR_REENLIGHTENMENT_CONTROL 0x40000106
+#define HV_X64_MSR_TSC_EMULATION_CONTROL 0x40000107
+#define HV_X64_MSR_TSC_EMULATION_STATUS 0x40000108
+
+/*
* Hypercall status code
*/
#define HV_STATUS_SUCCESS 0
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 6c49954..d6666a4 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -90,6 +90,7 @@ static bool has_msr_hv_runtime;
static bool has_msr_hv_synic;
static bool has_msr_hv_stimer;
static bool has_msr_hv_frequencies;
+static bool has_msr_hv_reenlightenment;
static bool has_msr_xss;
static bool has_msr_spec_ctrl;
static bool has_msr_smi_count;
@@ -583,7 +584,8 @@ static bool hyperv_enabled(X86CPU *cpu)
cpu->hyperv_vpindex ||
cpu->hyperv_runtime ||
cpu->hyperv_synic ||
- cpu->hyperv_stimer);
+ cpu->hyperv_stimer ||
+ cpu->hyperv_reenlightenment);
}
static int kvm_arch_set_tsc_khz(CPUState *cs)
@@ -669,6 +671,16 @@ static int hyperv_handle_properties(CPUState *cs)
}
env->features[FEAT_HYPERV_EDX] |= HV_GUEST_CRASH_MSR_AVAILABLE;
}
+ if (cpu->hyperv_reenlightenment) {
+ if (!has_msr_hv_reenlightenment) {
+ fprintf(stderr,
+ "Hyper-V Reenlightenment MSRs "
+ "(requested by 'hv-reenlightenment' cpu flag) "
+ "are not supported by kernel\n");
+ return -ENOSYS;
+ }
+ env->features[FEAT_HYPERV_EAX] |= HV_ACCESS_REENLIGHTENMENTS_CONTROL;
+ }
env->features[FEAT_HYPERV_EDX] |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE;
if (cpu->hyperv_reset) {
if (!has_msr_hv_reset) {
@@ -1215,6 +1227,9 @@ static int kvm_get_supported_msrs(KVMState *s)
case HV_X64_MSR_TSC_FREQUENCY:
has_msr_hv_frequencies = true;
break;
+ case HV_X64_MSR_REENLIGHTENMENT_CONTROL:
+ has_msr_hv_reenlightenment = true;
+ break;
case MSR_IA32_SPEC_CTRL:
has_msr_spec_ctrl = true;
break;
@@ -1778,6 +1793,14 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
kvm_msr_entry_add(cpu, HV_X64_MSR_REFERENCE_TSC,
env->msr_hv_tsc);
}
+ if (cpu->hyperv_reenlightenment) {
+ kvm_msr_entry_add(cpu, HV_X64_MSR_REENLIGHTENMENT_CONTROL,
+ env->msr_hv_reenlightenment_control);
+ kvm_msr_entry_add(cpu, HV_X64_MSR_TSC_EMULATION_CONTROL,
+ env->msr_hv_tsc_emulation_control);
+ kvm_msr_entry_add(cpu, HV_X64_MSR_TSC_EMULATION_STATUS,
+ env->msr_hv_tsc_emulation_status);
+ }
}
if (cpu->hyperv_vapic) {
kvm_msr_entry_add(cpu, HV_X64_MSR_APIC_ASSIST_PAGE,
@@ -2140,6 +2163,11 @@ static int kvm_get_msrs(X86CPU *cpu)
if (cpu->hyperv_time) {
kvm_msr_entry_add(cpu, HV_X64_MSR_REFERENCE_TSC, 0);
}
+ if (cpu->hyperv_reenlightenment) {
+ kvm_msr_entry_add(cpu, HV_X64_MSR_REENLIGHTENMENT_CONTROL, 0);
+ kvm_msr_entry_add(cpu, HV_X64_MSR_TSC_EMULATION_CONTROL, 0);
+ kvm_msr_entry_add(cpu, HV_X64_MSR_TSC_EMULATION_STATUS, 0);
+ }
if (has_msr_hv_crash) {
int j;
@@ -2397,6 +2425,15 @@ static int kvm_get_msrs(X86CPU *cpu)
env->msr_hv_stimer_count[(index - HV_X64_MSR_STIMER0_COUNT)/2] =
msrs[i].data;
break;
+ case HV_X64_MSR_REENLIGHTENMENT_CONTROL:
+ env->msr_hv_reenlightenment_control = msrs[i].data;
+ break;
+ case HV_X64_MSR_TSC_EMULATION_CONTROL:
+ env->msr_hv_tsc_emulation_control = msrs[i].data;
+ break;
+ case HV_X64_MSR_TSC_EMULATION_STATUS:
+ env->msr_hv_tsc_emulation_status = 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 bd2d82e..fd99c0b 100644
--- a/target/i386/machine.c
+++ b/target/i386/machine.c
@@ -713,6 +713,29 @@ static const VMStateDescription vmstate_msr_hyperv_stimer = {
}
};
+static bool hyperv_reenlightenment_enable_needed(void *opaque)
+{
+ X86CPU *cpu = opaque;
+ CPUX86State *env = &cpu->env;
+
+ return env->msr_hv_reenlightenment_control != 0 ||
+ env->msr_hv_tsc_emulation_control != 0 ||
+ env->msr_hv_tsc_emulation_status != 0;
+}
+
+static const VMStateDescription vmstate_msr_hyperv_reenlightenment = {
+ .name = "cpu/msr_hyperv_reenlightenment",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .needed = hyperv_reenlightenment_enable_needed,
+ .fields = (VMStateField[]) {
+ VMSTATE_UINT64(env.msr_hv_reenlightenment_control, X86CPU),
+ VMSTATE_UINT64(env.msr_hv_tsc_emulation_control, X86CPU),
+ VMSTATE_UINT64(env.msr_hv_tsc_emulation_status, X86CPU),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
static bool avx512_needed(void *opaque)
{
X86CPU *cpu = opaque;
@@ -1005,6 +1028,7 @@ VMStateDescription vmstate_x86_cpu = {
&vmstate_msr_hyperv_runtime,
&vmstate_msr_hyperv_synic,
&vmstate_msr_hyperv_stimer,
+ &vmstate_msr_hyperv_reenlightenment,
&vmstate_avx512,
&vmstate_xss,
&vmstate_tsc_khz,
--
1.8.3.1
next prev parent reply other threads:[~2018-05-08 22:15 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-08 22:14 [Qemu-devel] [PULL 00/30] Misc patches for 2018-05-09 Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 01/30] configure: recognize more rpmbuild macros Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 02/30] cpus: Fix event order on resume of stopped guest Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 03/30] cpus: tcg: fix never exiting loop on unplug Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 04/30] checkpatch.pl: add common glib defines to typelist Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 05/30] qom: allow object_get_canonical_path_component without parent Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 06/30] memdev: remove "id" property Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 07/30] exec: move memory access declarations to a common header, inline *_phys functions Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 08/30] exec: small changes to flatview_do_translate Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 09/30] exec: extract address_space_translate_iommu, fix page_mask corner case Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 10/30] exec: reintroduce MemoryRegion caching Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 11/30] qemu-thread: always keep the posix wrapper layer Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 12/30] update-linux-headers: drop hyperv.h Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 13/30] accel: use g_strsplit for parsing accelerator names Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 14/30] opts: don't silently truncate long parameter keys Paolo Bonzini
2018-05-09 5:46 ` Thomas Huth
2018-05-08 22:14 ` [Qemu-devel] [PULL 15/30] opts: don't silently truncate long option values Paolo Bonzini
2018-05-14 16:19 ` Peter Maydell
2018-05-14 16:23 ` Daniel P. Berrangé
2018-05-08 22:14 ` [Qemu-devel] [PULL 16/30] target/i386: sev: fix memory leaks Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 17/30] qemu-options: Mark -virtioconsole as deprecated Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 18/30] qemu-options: Remove remainders of the -tdf option Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 19/30] qemu-options: Bail out on unsupported options instead of silently ignoring them Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 20/30] qemu-options: Remove deprecated -no-kvm-pit-reinjection Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 21/30] qemu-options: Remove deprecated -no-kvm-irqchip Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 22/30] qemu-doc: provide details of supported build platforms Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 23/30] glib: bump min required glib library version to 2.42 Paolo Bonzini
2018-05-08 22:14 ` Paolo Bonzini [this message]
2018-05-08 22:14 ` [Qemu-devel] [PULL 25/30] configure: Really use local libfdt if the system one is too old Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 26/30] configure: Display if libfdt is from system or git Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 27/30] shippable: Remove Debian 8 libfdt kludge Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 28/30] build: Silence dtc directory creation Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 29/30] pc-dimm: fix error messages if no slots were defined Paolo Bonzini
2018-05-08 22:14 ` [Qemu-devel] [PULL 30/30] rename included C files to foo.inc.c, remove osdep.h Paolo Bonzini
2018-05-11 12:19 ` [Qemu-devel] [PULL 00/30] Misc patches for 2018-05-09 Peter Maydell
2018-05-11 12:33 ` Paolo Bonzini
2018-05-11 12:39 ` Peter Maydell
2018-05-11 12:42 ` Daniel P. Berrangé
2018-05-11 12:50 ` Peter Maydell
2018-05-11 12:54 ` Daniel P. Berrangé
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=1525817687-34620-25-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vkuznets@redhat.com \
/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).