From patchwork Thu Mar 11 13:39:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 47320 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E8049B6EFF for ; Fri, 12 Mar 2010 00:46:42 +1100 (EST) Received: from localhost ([127.0.0.1]:51299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Npiil-0007PR-V9 for incoming@patchwork.ozlabs.org; Thu, 11 Mar 2010 08:46:39 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Npibp-0005Wi-2f for qemu-devel@nongnu.org; Thu, 11 Mar 2010 08:39:29 -0500 Received: from [199.232.76.173] (port=45884 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Npibn-0005W0-Ps for qemu-devel@nongnu.org; Thu, 11 Mar 2010 08:39:27 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Npibl-0001R5-Mk for qemu-devel@nongnu.org; Thu, 11 Mar 2010 08:39:27 -0500 Received: from va3ehsobe001.messaging.microsoft.com ([216.32.180.11]:44515 helo=VA3EHSOBE001.bigfish.com) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_MD5:16) (Exim 4.60) (envelope-from ) id 1Npibl-0001Qy-Dn for qemu-devel@nongnu.org; Thu, 11 Mar 2010 08:39:25 -0500 Received: from mail153-va3-R.bigfish.com (10.7.14.240) by VA3EHSOBE001.bigfish.com (10.7.40.21) with Microsoft SMTP Server id 8.1.340.0; Thu, 11 Mar 2010 13:39:24 +0000 Received: from mail153-va3 (localhost [127.0.0.1]) by mail153-va3-R.bigfish.com (Postfix) with ESMTP id A02C38F8225; Thu, 11 Mar 2010 13:39:24 +0000 (UTC) X-SpamScore: -4 X-BigFish: VPS-4(zz936eMab9bhzz1202hzzz32i6bh2a8h61h) X-FB-SS: 5, Received: from mail153-va3 (localhost.localdomain [127.0.0.1]) by mail153-va3 (MessageSwitch) id 1268314762832541_7523; Thu, 11 Mar 2010 13:39:22 +0000 (UTC) Received: from VA3EHSMHS018.bigfish.com (unknown [10.7.14.249]) by mail153-va3.bigfish.com (Postfix) with ESMTP id C079D4F8012; Thu, 11 Mar 2010 13:39:22 +0000 (UTC) Received: from ausb3extmailp02.amd.com (163.181.251.22) by VA3EHSMHS018.bigfish.com (10.7.99.28) with Microsoft SMTP Server (TLS) id 14.0.482.39; Thu, 11 Mar 2010 13:39:19 +0000 Received: from ausb3twp01.amd.com (ausb3twp01.amd.com [163.181.250.37]) by ausb3extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with SMTP id o2BDh6ub031427; Thu, 11 Mar 2010 07:43:09 -0600 X-WSS-ID: 0KZ4DXC-01-7MJ-02 X-M-MSG: Received: from sausexhtp02.amd.com (sausexhtp02.amd.com [163.181.3.152]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by ausb3twp01.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 2C6ED10288B0; Thu, 11 Mar 2010 07:39:12 -0600 (CST) Received: from storexhtp02.amd.com (172.24.4.4) by sausexhtp02.amd.com (163.181.3.152) with Microsoft SMTP Server (TLS) id 8.2.234.1; Thu, 11 Mar 2010 07:39:15 -0600 Received: from storexbh1.amd.com (10.1.1.17) by storexhtp02.amd.com (172.24.4.4) with Microsoft SMTP Server id 8.2.234.1; Thu, 11 Mar 2010 08:39:14 -0500 Received: from sausexmb1.amd.com ([163.181.3.156]) by storexbh1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 11 Mar 2010 08:39:14 -0500 Received: from seurexmb1.amd.com ([165.204.9.130]) by sausexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 11 Mar 2010 07:39:03 -0600 Received: from gwo.osrc.amd.com ([165.204.16.204]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 11 Mar 2010 14:38:55 +0100 Received: from localhost.localdomain (tronje.osrc.amd.com [165.204.15.48]) by gwo.osrc.amd.com (Postfix) with ESMTP id BB2BC49C228; Thu, 11 Mar 2010 13:38:55 +0000 (GMT) From: Andre Przywara To: anthony@codemonkey.ws Date: Thu, 11 Mar 2010 14:39:02 +0100 Message-ID: <1268314747-11111-9-git-send-email-andre.przywara@amd.com> X-Mailer: git-send-email 1.6.4 In-Reply-To: <1268314747-11111-1-git-send-email-andre.przywara@amd.com> References: <1268314747-11111-1-git-send-email-andre.przywara@amd.com> X-OriginalArrivalTime: 11 Mar 2010 13:38:56.0012 (UTC) FILETIME=[32472CC0:01CAC120] MIME-Version: 1.0 X-Reverse-DNS: ausb3extmailp02.amd.com X-detected-operating-system: by monty-python.gnu.org: Windows 2000 SP4, XP SP1+ Cc: Andre Przywara , qemu-devel@nongnu.org, aurelien@aurel32.net Subject: [Qemu-devel] [PATCH 08/13] x86/cpuid: propagate further CPUID leafs when -cpu host X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org -cpu host currently only propagates the CPU's family/model/stepping, the brand name and the feature bits. Add a whitelist of safe CPUID leafs to let the guest see the actual CPU's cache details and other things. Signed-off-by: Andre Przywara --- target-i386/cpu.h | 6 +++++- target-i386/cpuid.c | 32 ++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/target-i386/cpu.h b/target-i386/cpu.h index c540213..72addd7 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -581,6 +581,10 @@ typedef struct { #define NB_MMU_MODES 2 +#define CPUID_FLAGS_BUILTIN (1 << 0) +#define CPUID_FLAGS_VENDOR_OVERRIDE (1 << 1) +#define CPUID_FLAGS_HOST (1 << 2) + typedef struct CPUX86State { /* standard registers */ target_ulong regs[CPU_NB_REGS]; @@ -685,7 +689,7 @@ typedef struct CPUX86State { uint32_t cpuid_ext2_features; uint32_t cpuid_ext3_features; uint32_t cpuid_apic_id; - int cpuid_vendor_override; + uint32_t cpuid_flags; /* MTRRs */ uint64_t mtrr_fixed[11]; diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c index 1e1c25b..14a10e9 100644 --- a/target-i386/cpuid.c +++ b/target-i386/cpuid.c @@ -213,7 +213,6 @@ typedef struct x86_def_t { uint32_t features, ext_features, ext2_features, ext3_features, kvm_features; uint32_t xlevel; char model_id[48]; - int vendor_override; uint32_t flags; } x86_def_t; @@ -481,7 +480,7 @@ static int cpu_x86_fill_host(x86_def_t *x86_cpu_def) x86_cpu_def->ext2_features = edx; x86_cpu_def->ext3_features = ecx; cpu_x86_fill_model_id(x86_cpu_def->model_id); - x86_cpu_def->vendor_override = 0; + x86_cpu_def->flags = CPUID_FLAGS_HOST; return 0; } @@ -625,7 +624,7 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) x86_cpu_def->vendor2 |= ((uint8_t)val[i + 4]) << (8 * i); x86_cpu_def->vendor3 |= ((uint8_t)val[i + 8]) << (8 * i); } - x86_cpu_def->vendor_override = 1; + x86_cpu_def->flags |= CPUID_FLAGS_VENDOR_OVERRIDE; } else if (!strcmp(featurestr, "model_id")) { pstrcpy(x86_cpu_def->model_id, sizeof(x86_cpu_def->model_id), val); @@ -723,7 +722,8 @@ void x86_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...), return; } for (def = x86_defs; def; def = def->next) { - snprintf(buf, sizeof (buf), def->flags ? "[%s]": "%s", def->name); + snprintf(buf, sizeof (buf), + def->flags & CPUID_FLAGS_BUILTIN ? "[%s]": "%s", def->name); if (model || dump) { (*cpu_fprintf)(f, "x86 %16s %-48s\n", buf, def->model_id); } else { @@ -777,7 +777,7 @@ int cpu_x86_register (CPUX86State *env, const char *cpu_model) env->cpuid_vendor2 = CPUID_VENDOR_INTEL_2; env->cpuid_vendor3 = CPUID_VENDOR_INTEL_3; } - env->cpuid_vendor_override = def->vendor_override; + env->cpuid_flags = def->flags; env->cpuid_level = def->level; if (def->family > 0x0f) env->cpuid_version = 0xf00 | ((def->family - 0x0f) << 20); @@ -923,7 +923,7 @@ void x86_cpudef_setup(void) for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); ++i) { builtin_x86_defs[i].next = x86_defs; - builtin_x86_defs[i].flags = 1; + builtin_x86_defs[i].flags |= CPUID_FLAGS_BUILTIN; x86_defs = &builtin_x86_defs[i]; } #if !defined(CONFIG_USER_ONLY) @@ -944,22 +944,38 @@ static void get_cpuid_vendor(CPUX86State *env, uint32_t *ebx, * 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_vendor_override) { + if (kvm_enabled() && env->cpuid_flags & CPUID_FLAGS_VENDOR_OVERRIDE) { host_cpuid(0, 0, NULL, ebx, ecx, edx); } } +/* safe CPUID leafs to propagate to guest if -cpu host is specified */ +#define CPUID_LEAF_PROPAGATE ((1 << 0x02) | (1 << 0x04) | (1 << 0x05) |\ + (1 << 0x0D)) +#define CPUID_LEAF_PROPAGATE_EXTENDED ((1 << 0x05) | (1 << 0x06) |\ + (1 << 0x08) | (1 << 0x19) | (1 << 0x1A)) + void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { - /* test if maximum index reached */ if (index & 0x80000000) { + /* test if maximum index reached */ if (index > env->cpuid_xlevel) index = env->cpuid_level; + if ((env->cpuid_flags & CPUID_FLAGS_HOST) && + ((1 << (index - 0x80000000)) & CPUID_LEAF_PROPAGATE_EXTENDED)) { + host_cpuid(index, count, eax, ebx, ecx, edx); + return; + } } else { if (index > env->cpuid_level) index = env->cpuid_level; + if ((env->cpuid_flags & CPUID_FLAGS_HOST) && + ((1 << index) & CPUID_LEAF_PROPAGATE)) { + host_cpuid(index, count, eax, ebx, ecx, edx); + return; + } } switch(index) {