Blame SOURCES/kvm-i386-kvm-advertise-Hyper-V-frequency-MSRs.patch

4a2fec
From 8225804259b165300d2d1cc1c4bdbad32fadf6da Mon Sep 17 00:00:00 2001
4a2fec
From: Ladi Prosek <lprosek@redhat.com>
4a2fec
Date: Tue, 10 Oct 2017 14:02:51 +0200
4a2fec
Subject: [PATCH 13/69] i386/kvm: advertise Hyper-V frequency MSRs
4a2fec
4a2fec
RH-Author: Ladi Prosek <lprosek@redhat.com>
4a2fec
Message-id: <20171010140251.23801-5-lprosek@redhat.com>
4a2fec
Patchwork-id: 77063
4a2fec
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 4/4] i386/kvm: advertise Hyper-V frequency MSRs
4a2fec
Bugzilla: 1500347
4a2fec
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
RH-Acked-by: David Hildenbrand <david@redhat.com>
4a2fec
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
4a2fec
4a2fec
As of kernel commit eb82feea59d6 ("KVM: hyperv: support HV_X64_MSR_TSC_FREQUENCY
4a2fec
and HV_X64_MSR_APIC_FREQUENCY"), KVM supports two new MSRs which are required
4a2fec
for nested Hyper-V to read timestamps with RDTSC + TSC page.
4a2fec
4a2fec
This commit makes QEMU advertise the MSRs with CPUID.40000003H:EAX[11] and
4a2fec
CPUID.40000003H:EDX[8] as specified in the Hyper-V TLFS and experimentally
4a2fec
verified on a Hyper-V host. The feature is enabled with the existing hv-time CPU
4a2fec
flag, and only if the TSC frequency is stable across migrations and known.
4a2fec
4a2fec
Signed-off-by: Ladi Prosek <lprosek@redhat.com>
4a2fec
Reviewed-by: David Hildenbrand <david@redhat.com>
4a2fec
Message-Id: <20170807085703.32267-5-lprosek@redhat.com>
4a2fec
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
(cherry picked from commit d72bc7f6f8a397790abee4a25ba1b8c35dd2b841)
4a2fec
Signed-off-by: Ladi Prosek <lprosek@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 target/i386/kvm.c | 12 +++++++++++-
4a2fec
 1 file changed, 11 insertions(+), 1 deletion(-)
4a2fec
4a2fec
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
4a2fec
index 2dc01c9..739334a 100644
4a2fec
--- a/target/i386/kvm.c
4a2fec
+++ b/target/i386/kvm.c
4a2fec
@@ -89,6 +89,7 @@ static bool has_msr_hv_vpindex;
4a2fec
 static bool has_msr_hv_runtime;
4a2fec
 static bool has_msr_hv_synic;
4a2fec
 static bool has_msr_hv_stimer;
4a2fec
+static bool has_msr_hv_frequencies;
4a2fec
 static bool has_msr_xss;
4a2fec
 
4a2fec
 static bool has_msr_architectural_pmu;
4a2fec
@@ -640,7 +641,13 @@ static int hyperv_handle_properties(CPUState *cs)
4a2fec
     if (cpu->hyperv_time) {
4a2fec
         env->features[FEAT_HYPERV_EAX] |= HV_X64_MSR_HYPERCALL_AVAILABLE;
4a2fec
         env->features[FEAT_HYPERV_EAX] |= HV_X64_MSR_TIME_REF_COUNT_AVAILABLE;
4a2fec
-        env->features[FEAT_HYPERV_EAX] |= 0x200;
4a2fec
+        env->features[FEAT_HYPERV_EAX] |= HV_X64_MSR_REFERENCE_TSC_AVAILABLE;
4a2fec
+
4a2fec
+        if (has_msr_hv_frequencies && tsc_is_stable_and_known(env)) {
4a2fec
+            env->features[FEAT_HYPERV_EAX] |= HV_X64_ACCESS_FREQUENCY_MSRS;
4a2fec
+            env->features[FEAT_HYPERV_EDX] |=
4a2fec
+                HV_FEATURE_FREQUENCY_MSRS_AVAILABLE;
4a2fec
+        }
4a2fec
     }
4a2fec
     if (cpu->hyperv_crash && has_msr_hv_crash) {
4a2fec
         env->features[FEAT_HYPERV_EDX] |= HV_X64_GUEST_CRASH_MSR_AVAILABLE;
4a2fec
@@ -1134,6 +1141,9 @@ static int kvm_get_supported_msrs(KVMState *s)
4a2fec
                 case HV_X64_MSR_STIMER0_CONFIG:
4a2fec
                     has_msr_hv_stimer = true;
4a2fec
                     break;
4a2fec
+                case HV_X64_MSR_TSC_FREQUENCY:
4a2fec
+                    has_msr_hv_frequencies = true;
4a2fec
+                    break;
4a2fec
                 }
4a2fec
             }
4a2fec
         }
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec