From patchwork Mon Jun 22 21:47:57 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 31875 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n5MLiPLv020577 for ; Mon, 22 Jun 2009 21:44:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751364AbZFVVoV (ORCPT ); Mon, 22 Jun 2009 17:44:21 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751347AbZFVVoU (ORCPT ); Mon, 22 Jun 2009 17:44:20 -0400 Received: from outbound-dub.frontbridge.com ([213.199.154.16]:33123 "EHLO IE1EHSOBE002.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751228AbZFVVoT (ORCPT ); Mon, 22 Jun 2009 17:44:19 -0400 Received: from mail88-dub-R.bigfish.com (10.5.252.3) by IE1EHSOBE002.bigfish.com (10.5.252.22) with Microsoft SMTP Server id 8.1.340.0; Mon, 22 Jun 2009 21:44:21 +0000 Received: from mail88-dub (localhost.localdomain [127.0.0.1]) by mail88-dub-R.bigfish.com (Postfix) with ESMTP id A612016083EA; Mon, 22 Jun 2009 21:44:21 +0000 (UTC) X-SpamScore: 1 X-BigFish: VPS1(zzzz1202hzzz32i17ch61h) X-Spam-TCS-SCL: 0:0 Received: by mail88-dub (MessageSwitch) id 1245707060696426_12159; Mon, 22 Jun 2009 21:44:20 +0000 (UCT) Received: from ausb3extmailp02.amd.com (ausb3extmailp02.amd.com [163.181.251.22]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail88-dub.bigfish.com (Postfix) with ESMTP id 589FE1780051; Mon, 22 Jun 2009 21:44:20 +0000 (UTC) Received: from ausb3twp02.amd.com ([163.181.250.38]) by ausb3extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id n5MLiFdG017558; Mon, 22 Jun 2009 16:44:18 -0500 X-WSS-ID: 0KLNTPF-02-VEB-01 Received: from sausexbh1.amd.com (sausexbh1.amd.com [163.181.22.101]) by ausb3twp02.amd.com (Tumbleweed MailGate 3.5.1) with ESMTP id 2B4A31234029; Mon, 22 Jun 2009 16:44:02 -0500 (CDT) Received: from sausexmb1.amd.com ([163.181.3.156]) by sausexbh1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 22 Jun 2009 16:44:15 -0500 Received: from SDRSEXMB1.amd.com ([172.20.3.116]) by sausexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 22 Jun 2009 16:44:14 -0500 Received: from localhost.localdomain ([165.204.15.42]) by SDRSEXMB1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 22 Jun 2009 23:44:10 +0200 From: Andre Przywara To: aliguori@us.ibm.com CC: avi@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, Andre Przywara Subject: [PATCH 2/2] introduce -cpu host target Date: Mon, 22 Jun 2009 23:47:57 +0200 Message-ID: <1245707277-769-1-git-send-email-andre.przywara@amd.com> X-Mailer: git-send-email 1.6.1.3 X-OriginalArrivalTime: 22 Jun 2009 21:44:10.0107 (UTC) FILETIME=[936704B0:01C9F382] MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Although the guest's CPUID bits can be controlled in a fine grained way in QEMU, a simple way to inject the host CPU is missing. This is handy for KVM desktop virtualization, where one wants the guest to support the full host feature set. Introduce another CPU type called 'host', which will propagate the host's CPUID bits to the guest. Problematic bits can still be turned off by using the existing syntax (-cpu host,-skinit) Signed-off-by: Andre Przywara --- target-i386/helper.c | 65 +++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 59 insertions(+), 6 deletions(-) I know that this has some more implications, currently it does not boot Linux kernels on AMD K8 and Fam10h boxes with KVM. I will send out patches for KVM to fix these issues (unhandled MSRs) later. Should we ignore unhandled MSRs like QEMU or Xen do? Also I want to hear your opinions on disabling CPUID bits afterwards (like ibs, skinit and other things we don't virtualize yet). Thanks and Regards, Andre. diff --git a/target-i386/helper.c b/target-i386/helper.c index 529f962..80b5621 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -273,9 +273,9 @@ static x86_def_t x86_defs[] = { { .name = "athlon", .level = 2, - .vendor1 = 0x68747541, /* "Auth" */ - .vendor2 = 0x69746e65, /* "enti" */ - .vendor3 = 0x444d4163, /* "cAMD" */ + .vendor1 = CPUID_VENDOR_AMD_1, + .vendor2 = CPUID_VENDOR_AMD_2, + .vendor3 = CPUID_VENDOR_AMD_3, .family = 6, .model = 2, .stepping = 3, @@ -308,6 +308,54 @@ static x86_def_t x86_defs[] = { }, }; +static void host_cpuid(uint32_t function, uint32_t count, uint32_t *eax, + uint32_t *ebx, uint32_t *ecx, uint32_t *edx); + +static int cpu_x86_fill_model_id(char *str) +{ + uint32_t eax, ebx, ecx, edx; + int i; + + for (i = 0; i < 3; i++) { + host_cpuid(0x80000002 + i, 0, &eax, &ebx, &ecx, &edx); + memcpy(str + i * 16 + 0, &eax, 4); + memcpy(str + i * 16 + 4, &ebx, 4); + memcpy(str + i * 16 + 8, &ecx, 4); + memcpy(str + i * 16 + 12, &edx, 4); + } + return 0; +} + +static int cpu_x86_fill_host(x86_def_t *x86_cpu_def) +{ + uint32_t eax, ebx, ecx, edx; + + x86_cpu_def->name = "host"; + host_cpuid(0x0, 0, &eax, &ebx, &ecx, &edx); + x86_cpu_def->level = eax; + x86_cpu_def->vendor1 = ebx; + x86_cpu_def->vendor2 = edx; + x86_cpu_def->vendor3 = ecx; + + host_cpuid(0x1, 0, &eax, &ebx, &ecx, &edx); + x86_cpu_def->family = ((eax >> 8) & 0x0F) + ((eax >> 20) & 0xFF); + x86_cpu_def->model = ((eax >> 4) & 0x0F) | ((eax & 0xF0000) >> 12); + x86_cpu_def->stepping = eax & 0x0F; + x86_cpu_def->ext_features = ecx; + x86_cpu_def->features = edx; + + host_cpuid(0x80000000, 0, &eax, &ebx, &ecx, &edx); + x86_cpu_def->xlevel = eax; + + host_cpuid(0x80000001, 0, &eax, &ebx, &ecx, &edx); + 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; + + return 0; +} + static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) { unsigned int i; @@ -326,9 +374,14 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) break; } } - if (!def) - goto error; - memcpy(x86_cpu_def, def, sizeof(*def)); + if (!def) { + if (strcmp(name, "host") != 0) { + goto error; + } + cpu_x86_fill_host(x86_cpu_def); + } else { + memcpy(x86_cpu_def, def, sizeof(*def)); + } if (kvm_enabled()) { add_flagname_to_bitmaps("hypervisor", &plus_features,