From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [PULL 5/6] target-i386: Move hyperv_* static globals to X86CPU Date: Fri, 16 Aug 2013 18:56:42 +0200 Message-ID: <1376672203-31191-6-git-send-email-afaerber@suse.de> References: <1376672203-31191-1-git-send-email-afaerber@suse.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Gleb Natapov , Marcelo Tosatti , Paolo Bonzini , kvm@vger.kernel.org (open list:X86) To: qemu-devel@nongnu.org Return-path: Received: from cantor2.suse.de ([195.135.220.15]:55470 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753708Ab3HPQ5C (ORCPT ); Fri, 16 Aug 2013 12:57:02 -0400 In-Reply-To: <1376672203-31191-1-git-send-email-afaerber@suse.de> Sender: kvm-owner@vger.kernel.org List-ID: =46rom: Igor Mammedov - since hyperv_* helper functions are used only in target-i386/kvm.c move them there as static helpers Requested-by: Eduardo Habkost Signed-off-by: Igor Mammedov Signed-off-by: Andreas F=C3=A4rber --- target-i386/Makefile.objs | 2 +- target-i386/cpu-qom.h | 4 +++ target-i386/cpu.c | 16 ++++++++---- target-i386/cpu.h | 4 +++ target-i386/hyperv.c | 64 ---------------------------------------= -------- target-i386/hyperv.h | 45 --------------------------------- target-i386/kvm.c | 36 ++++++++++++++++++-------- 7 files changed, 46 insertions(+), 125 deletions(-) delete mode 100644 target-i386/hyperv.c delete mode 100644 target-i386/hyperv.h diff --git a/target-i386/Makefile.objs b/target-i386/Makefile.objs index 3b629d4d..da1fc40 100644 --- a/target-i386/Makefile.objs +++ b/target-i386/Makefile.objs @@ -3,7 +3,7 @@ obj-y +=3D excp_helper.o fpu_helper.o cc_helper.o int_h= elper.o svm_helper.o obj-y +=3D smm_helper.o misc_helper.o mem_helper.o seg_helper.o obj-y +=3D gdbstub.o obj-$(CONFIG_SOFTMMU) +=3D machine.o arch_memory_mapping.o arch_dump.o -obj-$(CONFIG_KVM) +=3D kvm.o hyperv.o +obj-$(CONFIG_KVM) +=3D kvm.o obj-$(CONFIG_NO_KVM) +=3D kvm-stub.o obj-$(CONFIG_LINUX_USER) +=3D ioport-user.o obj-$(CONFIG_BSD_USER) +=3D ioport-user.o diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h index 53b4c34..c4447c2 100644 --- a/target-i386/cpu-qom.h +++ b/target-i386/cpu-qom.h @@ -66,6 +66,10 @@ typedef struct X86CPU { =20 CPUX86State env; =20 + bool hyperv_vapic; + bool hyperv_relaxed_timing; + int hyperv_spinlock_attempts; + /* Features that were filtered out because of missing host capabil= ities */ uint32_t filtered_features[FEATURE_WORDS]; =20 diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 2efbeca..6e38252 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -35,8 +35,6 @@ #include "qapi/visitor.h" #include "sysemu/arch_init.h" =20 -#include "hyperv.h" - #include "hw/hw.h" #if defined(CONFIG_KVM) #include @@ -1591,12 +1589,19 @@ static void cpu_x86_parse_featurestr(X86CPU *cp= u, char *features, Error **errp) object_property_parse(OBJECT(cpu), num, "tsc-frequency= ", errp); } else if (!strcmp(featurestr, "hv-spinlocks")) { char *err; + const int min =3D 0xFFF; numvalue =3D strtoul(val, &err, 0); if (!*val || *err) { error_setg(errp, "bad numerical value %s", val); goto out; } - hyperv_set_spinlock_retries(numvalue); + if (numvalue < min) { + fprintf(stderr, "hv-spinlocks value shall always b= e >=3D 0x%x" + ", fixup will be removed in future version= s\n", + min); + numvalue =3D min; + } + cpu->hyperv_spinlock_attempts =3D numvalue; } else { error_setg(errp, "unrecognized feature %s", featurestr= ); goto out; @@ -1606,9 +1611,9 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu,= char *features, Error **errp) } else if (!strcmp(featurestr, "enforce")) { check_cpuid =3D enforce_cpuid =3D 1; } else if (!strcmp(featurestr, "hv_relaxed")) { - hyperv_enable_relaxed_timing(true); + cpu->hyperv_relaxed_timing =3D true; } else if (!strcmp(featurestr, "hv_vapic")) { - hyperv_enable_vapic_recommended(true); + cpu->hyperv_vapic =3D true; } else { error_setg(errp, "feature string `%s' not in format (+feat= ure|" "-feature|feature=3Dxyz)", featurestr); @@ -2489,6 +2494,7 @@ static void x86_cpu_initfn(Object *obj) x86_cpu_get_feature_words, NULL, NULL, (void *)cpu->filtered_features, NU= LL); =20 + cpu->hyperv_spinlock_attempts =3D HYPERV_SPINLOCK_NEVER_RETRY; env->cpuid_apic_id =3D x86_cpu_apic_id_from_index(cs->cpu_index); =20 /* init various static tables used in TCG mode */ diff --git a/target-i386/cpu.h b/target-i386/cpu.h index cedefdc..8a3d0fd 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -549,6 +549,10 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; #define CPUID_MWAIT_IBE (1 << 1) /* Interrupts can exit capability= */ #define CPUID_MWAIT_EMX (1 << 0) /* enumeration supported */ =20 +#ifndef HYPERV_SPINLOCK_NEVER_RETRY +#define HYPERV_SPINLOCK_NEVER_RETRY 0xFFFFFFFF +#endif + #define EXCP00_DIVZ 0 #define EXCP01_DB 1 #define EXCP02_NMI 2 diff --git a/target-i386/hyperv.c b/target-i386/hyperv.c deleted file mode 100644 index f284e99..0000000 --- a/target-i386/hyperv.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * QEMU Hyper-V support - * - * Copyright Red Hat, Inc. 2011 - * - * Author: Vadim Rozenfeld - * - * This work is licensed under the terms of the GNU GPL, version 2 or = later. - * See the COPYING file in the top-level directory. - * - */ - -#include "hyperv.h" - -static bool hyperv_vapic; -static bool hyperv_relaxed_timing; -static int hyperv_spinlock_attempts =3D HYPERV_SPINLOCK_NEVER_RETRY; - -void hyperv_enable_vapic_recommended(bool val) -{ - hyperv_vapic =3D val; -} - -void hyperv_enable_relaxed_timing(bool val) -{ - hyperv_relaxed_timing =3D val; -} - -void hyperv_set_spinlock_retries(int val) -{ - hyperv_spinlock_attempts =3D val; - if (hyperv_spinlock_attempts < 0xFFF) { - hyperv_spinlock_attempts =3D 0xFFF; - } -} - -bool hyperv_enabled(void) -{ - return hyperv_hypercall_available() || hyperv_relaxed_timing_enabl= ed(); -} - -bool hyperv_hypercall_available(void) -{ - if (hyperv_vapic || - (hyperv_spinlock_attempts !=3D HYPERV_SPINLOCK_NEVER_RETRY)) { - return true; - } - return false; -} - -bool hyperv_vapic_recommended(void) -{ - return hyperv_vapic; -} - -bool hyperv_relaxed_timing_enabled(void) -{ - return hyperv_relaxed_timing; -} - -int hyperv_get_spinlock_retries(void) -{ - return hyperv_spinlock_attempts; -} diff --git a/target-i386/hyperv.h b/target-i386/hyperv.h deleted file mode 100644 index bacb1d4..0000000 --- a/target-i386/hyperv.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * QEMU Hyper-V support - * - * Copyright Red Hat, Inc. 2011 - * - * Author: Vadim Rozenfeld - * - * This work is licensed under the terms of the GNU GPL, version 2 or = later. - * See the COPYING file in the top-level directory. - * - */ - -#ifndef QEMU_HW_HYPERV_H -#define QEMU_HW_HYPERV_H 1 - -#include "qemu-common.h" -#ifdef CONFIG_KVM -#include -#endif - -#ifndef HYPERV_SPINLOCK_NEVER_RETRY -#define HYPERV_SPINLOCK_NEVER_RETRY 0xFFFFFFFF -#endif - -#ifndef KVM_CPUID_SIGNATURE_NEXT -#define KVM_CPUID_SIGNATURE_NEXT 0x40000100 -#endif - -#if !defined(CONFIG_USER_ONLY) && defined(CONFIG_KVM) -void hyperv_enable_vapic_recommended(bool val); -void hyperv_enable_relaxed_timing(bool val); -void hyperv_set_spinlock_retries(int val); -#else -static inline void hyperv_enable_vapic_recommended(bool val) { } -static inline void hyperv_enable_relaxed_timing(bool val) { } -static inline void hyperv_set_spinlock_retries(int val) { } -#endif - -bool hyperv_enabled(void); -bool hyperv_hypercall_available(void); -bool hyperv_vapic_recommended(void); -bool hyperv_relaxed_timing_enabled(void); -int hyperv_get_spinlock_retries(void); - -#endif /* QEMU_HW_HYPERV_H */ diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 376fc70..0b6eb01 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -31,7 +31,7 @@ #include "hw/i386/pc.h" #include "hw/i386/apic.h" #include "exec/ioport.h" -#include "hyperv.h" +#include #include "hw/pci/pci.h" =20 //#define DEBUG_KVM @@ -420,6 +420,22 @@ unsigned long kvm_arch_vcpu_id(CPUState *cs) return cpu->env.cpuid_apic_id; } =20 +#ifndef KVM_CPUID_SIGNATURE_NEXT +#define KVM_CPUID_SIGNATURE_NEXT 0x40000100 +#endif + +static bool hyperv_hypercall_available(X86CPU *cpu) +{ + return cpu->hyperv_vapic || + (cpu->hyperv_spinlock_attempts !=3D HYPERV_SPINLOCK_NEVER_R= ETRY); +} + +static bool hyperv_enabled(X86CPU *cpu) +{ + return hyperv_hypercall_available(cpu) || + cpu->hyperv_relaxed_timing; +} + #define KVM_MAX_CPUID_ENTRIES 100 =20 int kvm_arch_init_vcpu(CPUState *cs) @@ -442,7 +458,7 @@ int kvm_arch_init_vcpu(CPUState *cs) c =3D &cpuid_data.entries[cpuid_i++]; memset(c, 0, sizeof(*c)); c->function =3D KVM_CPUID_SIGNATURE; - if (!hyperv_enabled()) { + if (!hyperv_enabled(cpu)) { memcpy(signature, "KVMKVMKVM\0\0\0", 12); c->eax =3D 0; } else { @@ -458,7 +474,7 @@ int kvm_arch_init_vcpu(CPUState *cs) c->function =3D KVM_CPUID_FEATURES; c->eax =3D env->features[FEAT_KVM]; =20 - if (hyperv_enabled()) { + if (hyperv_enabled(cpu)) { memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12); c->eax =3D signature[0]; =20 @@ -471,10 +487,10 @@ int kvm_arch_init_vcpu(CPUState *cs) c =3D &cpuid_data.entries[cpuid_i++]; memset(c, 0, sizeof(*c)); c->function =3D HYPERV_CPUID_FEATURES; - if (hyperv_relaxed_timing_enabled()) { + if (cpu->hyperv_relaxed_timing) { c->eax |=3D HV_X64_MSR_HYPERCALL_AVAILABLE; } - if (hyperv_vapic_recommended()) { + if (cpu->hyperv_vapic) { c->eax |=3D HV_X64_MSR_HYPERCALL_AVAILABLE; c->eax |=3D HV_X64_MSR_APIC_ACCESS_AVAILABLE; } @@ -482,13 +498,13 @@ int kvm_arch_init_vcpu(CPUState *cs) c =3D &cpuid_data.entries[cpuid_i++]; memset(c, 0, sizeof(*c)); c->function =3D HYPERV_CPUID_ENLIGHTMENT_INFO; - if (hyperv_relaxed_timing_enabled()) { + if (cpu->hyperv_relaxed_timing) { c->eax |=3D HV_X64_RELAXED_TIMING_RECOMMENDED; } - if (hyperv_vapic_recommended()) { + if (cpu->hyperv_vapic) { c->eax |=3D HV_X64_APIC_ACCESS_RECOMMENDED; } - c->ebx =3D hyperv_get_spinlock_retries(); + c->ebx =3D cpu->hyperv_spinlock_attempts; =20 c =3D &cpuid_data.entries[cpuid_i++]; memset(c, 0, sizeof(*c)); @@ -1114,11 +1130,11 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_set(&msrs[n++], MSR_KVM_STEAL_TIME, env->steal_time_msr); } - if (hyperv_hypercall_available()) { + if (hyperv_hypercall_available(cpu)) { kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_GUEST_OS_ID, 0); kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_HYPERCALL, 0); } - if (hyperv_vapic_recommended()) { + if (cpu->hyperv_vapic) { kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE,= 0); } } --=20 1.8.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VANKs-0002hu-D7 for qemu-devel@nongnu.org; Fri, 16 Aug 2013 12:57:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VANKg-0000da-DP for qemu-devel@nongnu.org; Fri, 16 Aug 2013 12:57:14 -0400 Received: from cantor2.suse.de ([195.135.220.15]:55468 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VANKf-0000co-Vi for qemu-devel@nongnu.org; Fri, 16 Aug 2013 12:57:02 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Fri, 16 Aug 2013 18:56:42 +0200 Message-Id: <1376672203-31191-6-git-send-email-afaerber@suse.de> In-Reply-To: <1376672203-31191-1-git-send-email-afaerber@suse.de> References: <1376672203-31191-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 5/6] target-i386: Move hyperv_* static globals to X86CPU List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gleb Natapov , "open list:X86" , Marcelo Tosatti , Paolo Bonzini , Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Igor Mammedov - since hyperv_* helper functions are used only in target-i386/kvm.c move them there as static helpers Requested-by: Eduardo Habkost Signed-off-by: Igor Mammedov Signed-off-by: Andreas F=C3=A4rber --- target-i386/Makefile.objs | 2 +- target-i386/cpu-qom.h | 4 +++ target-i386/cpu.c | 16 ++++++++---- target-i386/cpu.h | 4 +++ target-i386/hyperv.c | 64 -----------------------------------------= ------ target-i386/hyperv.h | 45 --------------------------------- target-i386/kvm.c | 36 ++++++++++++++++++-------- 7 files changed, 46 insertions(+), 125 deletions(-) delete mode 100644 target-i386/hyperv.c delete mode 100644 target-i386/hyperv.h diff --git a/target-i386/Makefile.objs b/target-i386/Makefile.objs index 3b629d4d..da1fc40 100644 --- a/target-i386/Makefile.objs +++ b/target-i386/Makefile.objs @@ -3,7 +3,7 @@ obj-y +=3D excp_helper.o fpu_helper.o cc_helper.o int_hel= per.o svm_helper.o obj-y +=3D smm_helper.o misc_helper.o mem_helper.o seg_helper.o obj-y +=3D gdbstub.o obj-$(CONFIG_SOFTMMU) +=3D machine.o arch_memory_mapping.o arch_dump.o -obj-$(CONFIG_KVM) +=3D kvm.o hyperv.o +obj-$(CONFIG_KVM) +=3D kvm.o obj-$(CONFIG_NO_KVM) +=3D kvm-stub.o obj-$(CONFIG_LINUX_USER) +=3D ioport-user.o obj-$(CONFIG_BSD_USER) +=3D ioport-user.o diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h index 53b4c34..c4447c2 100644 --- a/target-i386/cpu-qom.h +++ b/target-i386/cpu-qom.h @@ -66,6 +66,10 @@ typedef struct X86CPU { =20 CPUX86State env; =20 + bool hyperv_vapic; + bool hyperv_relaxed_timing; + int hyperv_spinlock_attempts; + /* Features that were filtered out because of missing host capabilit= ies */ uint32_t filtered_features[FEATURE_WORDS]; =20 diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 2efbeca..6e38252 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -35,8 +35,6 @@ #include "qapi/visitor.h" #include "sysemu/arch_init.h" =20 -#include "hyperv.h" - #include "hw/hw.h" #if defined(CONFIG_KVM) #include @@ -1591,12 +1589,19 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu,= char *features, Error **errp) object_property_parse(OBJECT(cpu), num, "tsc-frequency",= errp); } else if (!strcmp(featurestr, "hv-spinlocks")) { char *err; + const int min =3D 0xFFF; numvalue =3D strtoul(val, &err, 0); if (!*val || *err) { error_setg(errp, "bad numerical value %s", val); goto out; } - hyperv_set_spinlock_retries(numvalue); + if (numvalue < min) { + fprintf(stderr, "hv-spinlocks value shall always be = >=3D 0x%x" + ", fixup will be removed in future versions\= n", + min); + numvalue =3D min; + } + cpu->hyperv_spinlock_attempts =3D numvalue; } else { error_setg(errp, "unrecognized feature %s", featurestr); goto out; @@ -1606,9 +1611,9 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, c= har *features, Error **errp) } else if (!strcmp(featurestr, "enforce")) { check_cpuid =3D enforce_cpuid =3D 1; } else if (!strcmp(featurestr, "hv_relaxed")) { - hyperv_enable_relaxed_timing(true); + cpu->hyperv_relaxed_timing =3D true; } else if (!strcmp(featurestr, "hv_vapic")) { - hyperv_enable_vapic_recommended(true); + cpu->hyperv_vapic =3D true; } else { error_setg(errp, "feature string `%s' not in format (+featur= e|" "-feature|feature=3Dxyz)", featurestr); @@ -2489,6 +2494,7 @@ static void x86_cpu_initfn(Object *obj) x86_cpu_get_feature_words, NULL, NULL, (void *)cpu->filtered_features, NULL= ); =20 + cpu->hyperv_spinlock_attempts =3D HYPERV_SPINLOCK_NEVER_RETRY; env->cpuid_apic_id =3D x86_cpu_apic_id_from_index(cs->cpu_index); =20 /* init various static tables used in TCG mode */ diff --git a/target-i386/cpu.h b/target-i386/cpu.h index cedefdc..8a3d0fd 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -549,6 +549,10 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; #define CPUID_MWAIT_IBE (1 << 1) /* Interrupts can exit capability *= / #define CPUID_MWAIT_EMX (1 << 0) /* enumeration supported */ =20 +#ifndef HYPERV_SPINLOCK_NEVER_RETRY +#define HYPERV_SPINLOCK_NEVER_RETRY 0xFFFFFFFF +#endif + #define EXCP00_DIVZ 0 #define EXCP01_DB 1 #define EXCP02_NMI 2 diff --git a/target-i386/hyperv.c b/target-i386/hyperv.c deleted file mode 100644 index f284e99..0000000 --- a/target-i386/hyperv.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * QEMU Hyper-V support - * - * Copyright Red Hat, Inc. 2011 - * - * Author: Vadim Rozenfeld - * - * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. - * See the COPYING file in the top-level directory. - * - */ - -#include "hyperv.h" - -static bool hyperv_vapic; -static bool hyperv_relaxed_timing; -static int hyperv_spinlock_attempts =3D HYPERV_SPINLOCK_NEVER_RETRY; - -void hyperv_enable_vapic_recommended(bool val) -{ - hyperv_vapic =3D val; -} - -void hyperv_enable_relaxed_timing(bool val) -{ - hyperv_relaxed_timing =3D val; -} - -void hyperv_set_spinlock_retries(int val) -{ - hyperv_spinlock_attempts =3D val; - if (hyperv_spinlock_attempts < 0xFFF) { - hyperv_spinlock_attempts =3D 0xFFF; - } -} - -bool hyperv_enabled(void) -{ - return hyperv_hypercall_available() || hyperv_relaxed_timing_enabled= (); -} - -bool hyperv_hypercall_available(void) -{ - if (hyperv_vapic || - (hyperv_spinlock_attempts !=3D HYPERV_SPINLOCK_NEVER_RETRY)) { - return true; - } - return false; -} - -bool hyperv_vapic_recommended(void) -{ - return hyperv_vapic; -} - -bool hyperv_relaxed_timing_enabled(void) -{ - return hyperv_relaxed_timing; -} - -int hyperv_get_spinlock_retries(void) -{ - return hyperv_spinlock_attempts; -} diff --git a/target-i386/hyperv.h b/target-i386/hyperv.h deleted file mode 100644 index bacb1d4..0000000 --- a/target-i386/hyperv.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * QEMU Hyper-V support - * - * Copyright Red Hat, Inc. 2011 - * - * Author: Vadim Rozenfeld - * - * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. - * See the COPYING file in the top-level directory. - * - */ - -#ifndef QEMU_HW_HYPERV_H -#define QEMU_HW_HYPERV_H 1 - -#include "qemu-common.h" -#ifdef CONFIG_KVM -#include -#endif - -#ifndef HYPERV_SPINLOCK_NEVER_RETRY -#define HYPERV_SPINLOCK_NEVER_RETRY 0xFFFFFFFF -#endif - -#ifndef KVM_CPUID_SIGNATURE_NEXT -#define KVM_CPUID_SIGNATURE_NEXT 0x40000100 -#endif - -#if !defined(CONFIG_USER_ONLY) && defined(CONFIG_KVM) -void hyperv_enable_vapic_recommended(bool val); -void hyperv_enable_relaxed_timing(bool val); -void hyperv_set_spinlock_retries(int val); -#else -static inline void hyperv_enable_vapic_recommended(bool val) { } -static inline void hyperv_enable_relaxed_timing(bool val) { } -static inline void hyperv_set_spinlock_retries(int val) { } -#endif - -bool hyperv_enabled(void); -bool hyperv_hypercall_available(void); -bool hyperv_vapic_recommended(void); -bool hyperv_relaxed_timing_enabled(void); -int hyperv_get_spinlock_retries(void); - -#endif /* QEMU_HW_HYPERV_H */ diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 376fc70..0b6eb01 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -31,7 +31,7 @@ #include "hw/i386/pc.h" #include "hw/i386/apic.h" #include "exec/ioport.h" -#include "hyperv.h" +#include #include "hw/pci/pci.h" =20 //#define DEBUG_KVM @@ -420,6 +420,22 @@ unsigned long kvm_arch_vcpu_id(CPUState *cs) return cpu->env.cpuid_apic_id; } =20 +#ifndef KVM_CPUID_SIGNATURE_NEXT +#define KVM_CPUID_SIGNATURE_NEXT 0x40000100 +#endif + +static bool hyperv_hypercall_available(X86CPU *cpu) +{ + return cpu->hyperv_vapic || + (cpu->hyperv_spinlock_attempts !=3D HYPERV_SPINLOCK_NEVER_RET= RY); +} + +static bool hyperv_enabled(X86CPU *cpu) +{ + return hyperv_hypercall_available(cpu) || + cpu->hyperv_relaxed_timing; +} + #define KVM_MAX_CPUID_ENTRIES 100 =20 int kvm_arch_init_vcpu(CPUState *cs) @@ -442,7 +458,7 @@ int kvm_arch_init_vcpu(CPUState *cs) c =3D &cpuid_data.entries[cpuid_i++]; memset(c, 0, sizeof(*c)); c->function =3D KVM_CPUID_SIGNATURE; - if (!hyperv_enabled()) { + if (!hyperv_enabled(cpu)) { memcpy(signature, "KVMKVMKVM\0\0\0", 12); c->eax =3D 0; } else { @@ -458,7 +474,7 @@ int kvm_arch_init_vcpu(CPUState *cs) c->function =3D KVM_CPUID_FEATURES; c->eax =3D env->features[FEAT_KVM]; =20 - if (hyperv_enabled()) { + if (hyperv_enabled(cpu)) { memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12); c->eax =3D signature[0]; =20 @@ -471,10 +487,10 @@ int kvm_arch_init_vcpu(CPUState *cs) c =3D &cpuid_data.entries[cpuid_i++]; memset(c, 0, sizeof(*c)); c->function =3D HYPERV_CPUID_FEATURES; - if (hyperv_relaxed_timing_enabled()) { + if (cpu->hyperv_relaxed_timing) { c->eax |=3D HV_X64_MSR_HYPERCALL_AVAILABLE; } - if (hyperv_vapic_recommended()) { + if (cpu->hyperv_vapic) { c->eax |=3D HV_X64_MSR_HYPERCALL_AVAILABLE; c->eax |=3D HV_X64_MSR_APIC_ACCESS_AVAILABLE; } @@ -482,13 +498,13 @@ int kvm_arch_init_vcpu(CPUState *cs) c =3D &cpuid_data.entries[cpuid_i++]; memset(c, 0, sizeof(*c)); c->function =3D HYPERV_CPUID_ENLIGHTMENT_INFO; - if (hyperv_relaxed_timing_enabled()) { + if (cpu->hyperv_relaxed_timing) { c->eax |=3D HV_X64_RELAXED_TIMING_RECOMMENDED; } - if (hyperv_vapic_recommended()) { + if (cpu->hyperv_vapic) { c->eax |=3D HV_X64_APIC_ACCESS_RECOMMENDED; } - c->ebx =3D hyperv_get_spinlock_retries(); + c->ebx =3D cpu->hyperv_spinlock_attempts; =20 c =3D &cpuid_data.entries[cpuid_i++]; memset(c, 0, sizeof(*c)); @@ -1114,11 +1130,11 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_set(&msrs[n++], MSR_KVM_STEAL_TIME, env->steal_time_msr); } - if (hyperv_hypercall_available()) { + if (hyperv_hypercall_available(cpu)) { kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_GUEST_OS_ID, 0); kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_HYPERCALL, 0); } - if (hyperv_vapic_recommended()) { + if (cpu->hyperv_vapic) { kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE, 0= ); } } --=20 1.8.1.4