From patchwork Thu Jun 25 13:12:03 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 32386 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 n5PD8j46004927 for ; Thu, 25 Jun 2009 13:08:46 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752023AbZFYNIk (ORCPT ); Thu, 25 Jun 2009 09:08:40 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751718AbZFYNIk (ORCPT ); Thu, 25 Jun 2009 09:08:40 -0400 Received: from outbound-dub.frontbridge.com ([213.199.154.16]:28490 "EHLO IE1EHSOBE003.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751818AbZFYNIj (ORCPT ); Thu, 25 Jun 2009 09:08:39 -0400 Received: from mail32-dub-R.bigfish.com (10.5.252.3) by IE1EHSOBE003.bigfish.com (10.5.252.23) with Microsoft SMTP Server id 8.1.340.0; Thu, 25 Jun 2009 13:08:41 +0000 Received: from mail32-dub (localhost.localdomain [127.0.0.1]) by mail32-dub-R.bigfish.com (Postfix) with ESMTP id 805F59B8180; Thu, 25 Jun 2009 13:08:41 +0000 (UTC) X-SpamScore: 3 X-BigFish: VPS3(zzzz1202hzzz32i17ch43j61h) X-Spam-TCS-SCL: 0:0 Received: by mail32-dub (MessageSwitch) id 1245935320755469_3940; Thu, 25 Jun 2009 13:08:40 +0000 (UCT) Received: from ausb3extmailp01.amd.com (unknown [163.181.251.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail32-dub.bigfish.com (Postfix) with ESMTP id 6073E1610001; Thu, 25 Jun 2009 13:08:40 +0000 (UTC) Received: from ausb3twp02.amd.com ([163.181.250.38]) by ausb3extmailp01.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id n5PD8XEh028047; Thu, 25 Jun 2009 08:08:36 -0500 X-WSS-ID: 0KLSPU3-02-038-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 200AE123402B; Thu, 25 Jun 2009 08:08:27 -0500 (CDT) Received: from sausexmb2.amd.com ([163.181.3.157]) by sausexbh1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 25 Jun 2009 08:08:34 -0500 Received: from SDRSEXMB1.amd.com ([172.20.3.116]) by sausexmb2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 25 Jun 2009 08:08:34 -0500 Received: from localhost.localdomain ([165.204.15.42]) by SDRSEXMB1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 25 Jun 2009 15:08:08 +0200 From: Andre Przywara To: avi@redhat.com CC: kvm@vger.kernel.org, Andre Przywara Subject: [PATCH] qemu-kvm: fix KVMs GET_SUPPORTED_CPUID feature usage Date: Thu, 25 Jun 2009 15:12:03 +0200 Message-ID: <1245935523-32604-1-git-send-email-andre.przywara@amd.com> X-Mailer: git-send-email 1.6.1.3 X-OriginalArrivalTime: 25 Jun 2009 13:08:08.0437 (UTC) FILETIME=[FC0C5A50:01C9F595] MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org If we want to trim the user provided CPUID bits for KVM to be not greater than that of the host, we should a) not remove the bits _after_ we sent them to the kernel and b) not do the bitmangling on the original values while sending a copy This fixes the masking of features that are not present on the host and helps to use -cpu host. Signed-off-by: Andre Przywara --- qemu-kvm-x86.c | 21 +++++++++++---------- 1 files changed, 11 insertions(+), 10 deletions(-) Hi, this is a port of patch 4/6 of my "-cpu host" series for QEMU. The bug is similar, although the fix is a different one (different files). Even without "-cpu host" features that the host does not support are currently _not_ disabled as intended, so I consider this a bugfix. Regards, Andre. diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index 66b2b19..f3e4b6b 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -1190,7 +1190,6 @@ int kvm_arch_qemu_init_env(CPUState *cenv) qemu_kvm_load_lapic(cenv); - copy = *cenv; #ifdef KVM_CPUID_SIGNATURE /* Paravirtualization CPUIDs */ @@ -1209,6 +1208,17 @@ int kvm_arch_qemu_init_env(CPUState *cenv) pv_ent->eax = get_para_features(kvm_context); #endif + kvm_trim_features(&cenv->cpuid_features, + kvm_arch_get_supported_cpuid(cenv, 1, R_EDX)); + kvm_trim_features(&cenv->cpuid_ext_features, + kvm_arch_get_supported_cpuid(cenv, 1, R_ECX)); + kvm_trim_features(&cenv->cpuid_ext2_features, + kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_EDX)); + kvm_trim_features(&cenv->cpuid_ext3_features, + kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_ECX)); + + copy = *cenv; + copy.regs[R_EAX] = 0; qemu_kvm_cpuid_on_env(©); limit = copy.regs[R_EAX]; @@ -1243,15 +1253,6 @@ int kvm_arch_qemu_init_env(CPUState *cenv) kvm_setup_cpuid2(cenv->kvm_cpu_state.vcpu_ctx, cpuid_nent, cpuid_ent); - kvm_trim_features(&cenv->cpuid_features, - kvm_arch_get_supported_cpuid(cenv, 1, R_EDX)); - kvm_trim_features(&cenv->cpuid_ext_features, - kvm_arch_get_supported_cpuid(cenv, 1, R_ECX)); - kvm_trim_features(&cenv->cpuid_ext2_features, - kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_EDX)); - kvm_trim_features(&cenv->cpuid_ext3_features, - kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_ECX)); - return 0; }