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

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