From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5WIt-00028T-DD for qemu-devel@nongnu.org; Tue, 21 Jan 2014 03:03:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W5WIn-0003Ws-AN for qemu-devel@nongnu.org; Tue, 21 Jan 2014 03:03:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:25948) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5WIn-0003Wc-2P for qemu-devel@nongnu.org; Tue, 21 Jan 2014 03:03:17 -0500 From: Vadim Rozenfeld Date: Tue, 21 Jan 2014 19:02:45 +1100 Message-Id: <1390291367-21958-2-git-send-email-vrozenfe@redhat.com> In-Reply-To: <1390291367-21958-1-git-send-email-vrozenfe@redhat.com> References: <1390291367-21958-1-git-send-email-vrozenfe@redhat.com> Subject: [Qemu-devel] [PATCH 1/3] cleanup hyper-v interface initialization List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, mtosatti@redhat.com, pl@dlhnet.de, Vadim Rozenfeld , aliguori@amazon.com Signed-off-by: Vadim Rozenfeld --- target-i386/kvm.c | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 7522e98..768ca1d 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -71,6 +71,8 @@ static bool has_msr_pv_eoi_en; static bool has_msr_misc_enable; static bool has_msr_kvm_steal_time; static int lm_capable_kernel; +static bool has_msr_hv_hypercall; +static bool has_msr_hv_vapic; static bool has_msr_architectural_pmu; static uint32_t num_architectural_pmu_counters; @@ -463,13 +465,7 @@ int kvm_arch_init_vcpu(CPUState *cs) /* Paravirtualization CPUIDs */ c = &cpuid_data.entries[cpuid_i++]; c->function = KVM_CPUID_SIGNATURE; - if (!hyperv_enabled(cpu)) { - memcpy(signature, "KVMKVMKVM\0\0\0", 12); - c->eax = 0; - } else { - memcpy(signature, "Microsoft Hv", 12); - c->eax = HYPERV_CPUID_MIN; - } + memcpy(signature, "KVMKVMKVM\0\0\0", 12); c->ebx = signature[0]; c->ecx = signature[1]; c->edx = signature[2]; @@ -478,23 +474,23 @@ int kvm_arch_init_vcpu(CPUState *cs) c->function = KVM_CPUID_FEATURES; c->eax = env->features[FEAT_KVM]; - if (hyperv_enabled(cpu)) { + if (hyperv_enabled(cpu) && + kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0) { + has_msr_hv_hypercall = true; + memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12); c->eax = signature[0]; c = &cpuid_data.entries[cpuid_i++]; - c->function = HYPERV_CPUID_VERSION; - c->eax = 0x00001bbc; - c->ebx = 0x00060001; - - c = &cpuid_data.entries[cpuid_i++]; c->function = HYPERV_CPUID_FEATURES; if (cpu->hyperv_relaxed_timing) { c->eax |= HV_X64_MSR_HYPERCALL_AVAILABLE; } - if (cpu->hyperv_vapic) { + if (cpu->hyperv_vapic && + kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_VAPIC) > 0) { c->eax |= HV_X64_MSR_HYPERCALL_AVAILABLE; c->eax |= HV_X64_MSR_APIC_ACCESS_AVAILABLE; + has_msr_hv_vapic = true; } c = &cpuid_data.entries[cpuid_i++]; @@ -502,23 +498,15 @@ int kvm_arch_init_vcpu(CPUState *cs) if (cpu->hyperv_relaxed_timing) { c->eax |= HV_X64_RELAXED_TIMING_RECOMMENDED; } - if (cpu->hyperv_vapic) { + if (has_msr_hv_vapic) { c->eax |= HV_X64_APIC_ACCESS_RECOMMENDED; } - c->ebx = cpu->hyperv_spinlock_attempts; - - c = &cpuid_data.entries[cpuid_i++]; - c->function = HYPERV_CPUID_IMPLEMENT_LIMITS; - c->eax = 0x40; - c->ebx = 0x40; - - c = &cpuid_data.entries[cpuid_i++]; - c->function = KVM_CPUID_SIGNATURE_NEXT; - memcpy(signature, "KVMKVMKVM\0\0\0", 12); - c->eax = 0; - c->ebx = signature[0]; - c->ecx = signature[1]; - c->edx = signature[2]; + if (cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY && + kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_SPIN) > 0) { + c->ebx = cpu->hyperv_spinlock_attempts; + } else { + c->ebx = HYPERV_SPINLOCK_NEVER_RETRY; + } } has_msr_async_pf_en = c->eax & (1 << KVM_FEATURE_ASYNC_PF); -- 1.8.3.1