9ae3a8
From 4e424b837ade87f4d44cbd51e8994e4ac8f36515 Mon Sep 17 00:00:00 2001
9ae3a8
From: Vadim Rozenfeld <vrozenfe@redhat.com>
9ae3a8
Date: Mon, 3 Mar 2014 12:09:16 +0100
9ae3a8
Subject: [PATCH 04/12] kvm: make availability of Hyper-V enlightenments dependent on KVM_CAP_HYPERV
9ae3a8
9ae3a8
RH-Author: Vadim Rozenfeld <vrozenfe@redhat.com>
9ae3a8
Message-id: <1393848564-10511-5-git-send-email-vrozenfe@redhat.com>
9ae3a8
Patchwork-id: 57960
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm v4 PATCH 04/12] kvm: make availability of Hyper-V enlightenments dependent on KVM_CAP_HYPERV
9ae3a8
Bugzilla: 1004773
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
9ae3a8
RH-Acked-by: Juan Quintela <quintela@redhat.com>
9ae3a8
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
9ae3a8
9ae3a8
From: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
9ae3a8
The MS docs specify HV_X64_MSR_HYPERCALL as a mandatory interface,
9ae3a8
thus we must provide the MSRs even if the user only specified
9ae3a8
features that, like relaxed timing, in principle don't require them.
9ae3a8
And the MSRs are only there if the hypervisor has KVM_CAP_HYPERV.
9ae3a8
9ae3a8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
(cherry picked from commit 7bc3d711b45d6feacab96eda410c5655f4ddafcf)
9ae3a8
---
9ae3a8
 target-i386/kvm.c | 16 +++++++++++-----
9ae3a8
 1 file changed, 11 insertions(+), 5 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 target-i386/kvm.c |   16 +++++++++++-----
9ae3a8
 1 files changed, 11 insertions(+), 5 deletions(-)
9ae3a8
9ae3a8
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
9ae3a8
index 3688371..495021b 100644
9ae3a8
--- a/target-i386/kvm.c
9ae3a8
+++ b/target-i386/kvm.c
9ae3a8
@@ -70,6 +70,8 @@ static bool has_msr_pv_eoi_en;
9ae3a8
 static bool has_msr_misc_enable;
9ae3a8
 static bool has_msr_kvm_steal_time;
9ae3a8
 static int lm_capable_kernel;
9ae3a8
+static bool has_msr_hv_hypercall;
9ae3a8
+static bool has_msr_hv_vapic;
9ae3a8
 
9ae3a8
 static bool has_msr_architectural_pmu;
9ae3a8
 static uint32_t num_architectural_pmu_counters;
9ae3a8
@@ -433,8 +435,10 @@ static bool hyperv_hypercall_available(X86CPU *cpu)
9ae3a8
 
9ae3a8
 static bool hyperv_enabled(X86CPU *cpu)
9ae3a8
 {
9ae3a8
-    return hyperv_hypercall_available(cpu) ||
9ae3a8
-           cpu->hyperv_relaxed_timing;
9ae3a8
+    CPUState *cs = CPU(cpu);
9ae3a8
+    return kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0 &&
9ae3a8
+           (hyperv_hypercall_available(cpu) ||
9ae3a8
+            cpu->hyperv_relaxed_timing);
9ae3a8
 }
9ae3a8
 
9ae3a8
 #define KVM_MAX_CPUID_ENTRIES  100
9ae3a8
@@ -489,6 +493,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
9ae3a8
         if (cpu->hyperv_vapic) {
9ae3a8
             c->eax |= HV_X64_MSR_HYPERCALL_AVAILABLE;
9ae3a8
             c->eax |= HV_X64_MSR_APIC_ACCESS_AVAILABLE;
9ae3a8
+            has_msr_hv_vapic = true;
9ae3a8
         }
9ae3a8
 
9ae3a8
         c = &cpuid_data.entries[cpuid_i++];
9ae3a8
@@ -496,7 +501,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
9ae3a8
         if (cpu->hyperv_relaxed_timing) {
9ae3a8
             c->eax |= HV_X64_RELAXED_TIMING_RECOMMENDED;
9ae3a8
         }
9ae3a8
-        if (cpu->hyperv_vapic) {
9ae3a8
+        if (has_msr_hv_vapic) {
9ae3a8
             c->eax |= HV_X64_APIC_ACCESS_RECOMMENDED;
9ae3a8
         }
9ae3a8
         c->ebx = cpu->hyperv_spinlock_attempts;
9ae3a8
@@ -507,6 +512,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
9ae3a8
         c->ebx = 0x40;
9ae3a8
 
9ae3a8
         kvm_base = KVM_CPUID_SIGNATURE_NEXT;
9ae3a8
+        has_msr_hv_hypercall = true;
9ae3a8
     }
9ae3a8
 
9ae3a8
     memcpy(signature, "KVMKVMKVM\0\0\0", 12);
9ae3a8
@@ -1191,11 +1197,11 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
9ae3a8
             kvm_msr_entry_set(&msrs[n++], MSR_CORE_PERF_GLOBAL_CTRL,
9ae3a8
                               env->msr_global_ctrl);
9ae3a8
         }
9ae3a8
-        if (hyperv_hypercall_available(cpu)) {
9ae3a8
+        if (has_msr_hv_hypercall) {
9ae3a8
             kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_GUEST_OS_ID, 0);
9ae3a8
             kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_HYPERCALL, 0);
9ae3a8
         }
9ae3a8
-        if (cpu->hyperv_vapic) {
9ae3a8
+        if (has_msr_hv_vapic) {
9ae3a8
             kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE, 0);
9ae3a8
         }
9ae3a8
     }
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8