Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mobzs-0007vF-AS for qemu-devel@nongnu.org; Fri, 18 Sep 2009 07:51:28 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mobzm-0007sn-Do for qemu-devel@nongnu.org; Fri, 18 Sep 2009 07:51:27 -0400 Received: from [199.232.76.173] (port=38468 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mobzl-0007sN-In for qemu-devel@nongnu.org; Fri, 18 Sep 2009 07:51:21 -0400 Received: from va3ehsobe005.messaging.microsoft.com ([216.32.180.15]:7328 helo=VA3EHSOBE005.bigfish.com) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_MD5:16) (Exim 4.60) (envelope-from ) id 1Mobzl-0003Mh-5y for qemu-devel@nongnu.org; Fri, 18 Sep 2009 07:51:21 -0400 Received: from mail92-va3 (localhost.localdomain [127.0.0.1]) by mail92-va3-R.bigfish.com (Postfix) with ESMTP id 988A4518344 for ; Fri, 18 Sep 2009 11:51:20 +0000 (UTC) Received: from svlb1extmailp01.amd.com (unknown [139.95.251.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail92-va3.bigfish.com (Postfix) with ESMTP id B05EA5C8056 for ; Fri, 18 Sep 2009 11:51:18 +0000 (UTC) Received: from svlb1twp02.amd.com ([139.95.250.35]) by svlb1extmailp01.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id n8IBpDnB025612 for ; Fri, 18 Sep 2009 04:51:16 -0700 Received: from SSVLEXBH2.amd.com (ssvlexbh2.amd.com [139.95.53.183]) by svlb1twp02.amd.com (Tumbleweed MailGate 3.7.0) with ESMTP id 2B02A1B10295 for ; Fri, 18 Sep 2009 04:51:09 -0700 (PDT) From: Andre Przywara Date: Fri, 18 Sep 2009 13:48:05 +0200 Message-ID: <1253274494-13244-13-git-send-email-andre.przywara@amd.com> In-Reply-To: <1253274494-13244-1-git-send-email-andre.przywara@amd.com> References: <1253274494-13244-1-git-send-email-andre.przywara@amd.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v2 12/21] cpuid: Fix multicore setup on Intel List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Andre Przywara The multicore CPUID code detects whether the guest is an Intel or an AMD CPU, because the Linux kernel is picky about the CmpLegacy bit. KVM by default passes through the host's vendor, which was not catched by the code. So fork out the vendor determining bits into a separate function to be used from both places and always get the real vendor. This fixes KVM's multicore setup on Intel CPUs. Signed-off-by: Andre Przywara Reported-by: Dietmar Maurer --- target-i386/cpuid.c | 49 +++++++++++++++++++++++++++++++------------------ 1 files changed, 31 insertions(+), 18 deletions(-) diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c index 4f2b359..e76457c 100644 --- a/target-i386/cpuid.c +++ b/target-i386/cpuid.c @@ -615,6 +615,24 @@ int cpu_x86_register (CPUX86State *env, const char *cpu_model) return 0; } +static void get_cpuid_vendor(CPUX86State *env, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) +{ + *ebx = env->cpuid_vendor1; + *edx = env->cpuid_vendor2; + *ecx = env->cpuid_vendor3; + + /* sysenter isn't supported on compatibility mode on AMD, syscall + * isn't supported in compatibility mode on Intel. + * Normally we advertise the actual cpu vendor, but you can override + * this if you want to use KVM's sysenter/syscall emulation + * in compatibility mode and when doing cross vendor migration + */ + if (kvm_enabled() && + (env->cpuid_flags & CPUID_FLAGS_VENDOR_OVERRIDE) == 0) + host_cpuid(0, 0, NULL, ebx, ecx, edx); +} + #define CPUID_LEAF_PROPAGATE ((1 << 0x02) | (1 << 0x04) | (1 << 0x05) |\ (1 << 0x0D)) #define CPUID_LEAF_PROPAGATE_EXTENDED ((1 << 0x05) | (1 << 0x06) |\ @@ -646,19 +664,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, switch(index) { case 0: *eax = env->cpuid_level; - *ebx = env->cpuid_vendor1; - *edx = env->cpuid_vendor2; - *ecx = env->cpuid_vendor3; - - /* sysenter isn't supported on compatibility mode on AMD, syscall - * isn't supported in compatibility mode on Intel. - * Normally we advertise the actual cpu vendor, but you can override - * this if you want to use KVM's sysenter/syscall emulation - * in compatibility mode and when doing cross vendor migration - */ - if (kvm_enabled() && - (env->cpuid_flags & CPUID_FLAGS_VENDOR_OVERRIDE) == 0) - host_cpuid(0, 0, NULL, ebx, ecx, edx); + get_cpuid_vendor(env, ebx, ecx, edx); break; case 1: *eax = env->cpuid_version; @@ -755,11 +761,18 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, *ecx = env->cpuid_ext3_features; *edx = env->cpuid_ext2_features; - if (env->nr_cores * env->nr_threads > 1 && - env->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && - env->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && - env->cpuid_vendor3 == CPUID_VENDOR_AMD_3) { - *ecx |= 1 << 1; /* CmpLegacy bit */ + /* The Linux kernel checks for the CMPLegacy bit and + * discards multiple thread information if it is set. + * So dont set it here for Intel to make Linux guests happy. + */ + if (env->nr_cores * env->nr_threads > 1) { + uint32_t tebx, tecx, tedx; + get_cpuid_vendor(env, &tebx, &tecx, &tedx); + if (tebx != CPUID_VENDOR_INTEL_1 || + tedx != CPUID_VENDOR_INTEL_2 || + tecx != CPUID_VENDOR_INTEL_3) { + *ecx |= 1 << 1; /* CmpLegacy bit */ + } } if (kvm_enabled()) { -- 1.6.1.3