From patchwork Tue Jun 21 17:08:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 101318 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 87DAEB6F85 for ; Wed, 22 Jun 2011 03:12:53 +1000 (EST) Received: from localhost ([::1]:42684 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QZ4VN-00075N-NF for incoming@patchwork.ozlabs.org; Tue, 21 Jun 2011 13:12:49 -0400 Received: from eggs.gnu.org ([140.186.70.92]:56289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QZ4Rj-0006zq-HS for qemu-devel@nongnu.org; Tue, 21 Jun 2011 13:09:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QZ4Rf-0000wp-G8 for qemu-devel@nongnu.org; Tue, 21 Jun 2011 13:09:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35364) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QZ4Rf-0000wM-2x for qemu-devel@nongnu.org; Tue, 21 Jun 2011 13:08:59 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5LH8whe001425 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 21 Jun 2011 13:08:58 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p5LH8vhi014756; Tue, 21 Jun 2011 13:08:57 -0400 Received: from amt.cnet (vpn-9-196.rdu.redhat.com [10.11.9.196]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p5LH8u5n020367; Tue, 21 Jun 2011 13:08:56 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 438DE66E170; Tue, 21 Jun 2011 14:08:40 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.5/8.14.5/Submit) id p5LH8cN4006989; Tue, 21 Jun 2011 14:08:38 -0300 From: Marcelo Tosatti To: Anthony Liguori Date: Tue, 21 Jun 2011 14:08:01 -0300 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Jan Kiszka , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org, Eduardo Habkost Subject: [Qemu-devel] [PATCH 12/15] kvm: x86: Pass KVMState to kvm_arch_get_supported_cpuid X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jan Kiszka kvm_arch_get_supported_cpuid checks for global cpuid restrictions, it does not require any CPUState reference. Changing its interface allows to call it before any VCPU is initialized. CC: Eduardo Habkost Signed-off-by: Jan Kiszka Signed-off-by: Marcelo Tosatti --- kvm.h | 2 +- target-i386/cpuid.c | 20 ++++++++++++-------- target-i386/kvm.c | 30 +++++++++++++++--------------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/kvm.h b/kvm.h index d565dba..243b063 100644 --- a/kvm.h +++ b/kvm.h @@ -157,7 +157,7 @@ bool kvm_arch_stop_on_emulation_error(CPUState *env); int kvm_check_extension(KVMState *s, unsigned int extension); -uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, +uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function, uint32_t index, int reg); void kvm_cpu_synchronize_state(CPUState *env); void kvm_cpu_synchronize_post_reset(CPUState *env); diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c index 79e7580..e1ae3af 100644 --- a/target-i386/cpuid.c +++ b/target-i386/cpuid.c @@ -1144,10 +1144,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, break; case 7: if (kvm_enabled()) { - *eax = kvm_arch_get_supported_cpuid(env, 0x7, count, R_EAX); - *ebx = kvm_arch_get_supported_cpuid(env, 0x7, count, R_EBX); - *ecx = kvm_arch_get_supported_cpuid(env, 0x7, count, R_ECX); - *edx = kvm_arch_get_supported_cpuid(env, 0x7, count, R_EDX); + KVMState *s = env->kvm_state; + + *eax = kvm_arch_get_supported_cpuid(s, 0x7, count, R_EAX); + *ebx = kvm_arch_get_supported_cpuid(s, 0x7, count, R_EBX); + *ecx = kvm_arch_get_supported_cpuid(s, 0x7, count, R_ECX); + *edx = kvm_arch_get_supported_cpuid(s, 0x7, count, R_EDX); } else { *eax = 0; *ebx = 0; @@ -1179,10 +1181,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, break; } if (kvm_enabled()) { - *eax = kvm_arch_get_supported_cpuid(env, 0xd, count, R_EAX); - *ebx = kvm_arch_get_supported_cpuid(env, 0xd, count, R_EBX); - *ecx = kvm_arch_get_supported_cpuid(env, 0xd, count, R_ECX); - *edx = kvm_arch_get_supported_cpuid(env, 0xd, count, R_EDX); + KVMState *s = env->kvm_state; + + *eax = kvm_arch_get_supported_cpuid(s, 0xd, count, R_EAX); + *ebx = kvm_arch_get_supported_cpuid(s, 0xd, count, R_EBX); + *ecx = kvm_arch_get_supported_cpuid(s, 0xd, count, R_ECX); + *edx = kvm_arch_get_supported_cpuid(s, 0xd, count, R_EDX); } else { *eax = 0; *ebx = 0; diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 5db33ea..938e0a3 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -98,12 +98,12 @@ struct kvm_para_features { { -1, -1 } }; -static int get_para_features(CPUState *env) +static int get_para_features(KVMState *s) { int i, features = 0; for (i = 0; i < ARRAY_SIZE(para_features) - 1; i++) { - if (kvm_check_extension(env->kvm_state, para_features[i].cap)) { + if (kvm_check_extension(s, para_features[i].cap)) { features |= (1 << para_features[i].feature); } } @@ -112,7 +112,7 @@ static int get_para_features(CPUState *env) } -uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, +uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, uint32_t index, int reg) { struct kvm_cpuid2 *cpuid; @@ -122,7 +122,7 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int has_kvm_features = 0; max = 1; - while ((cpuid = try_get_cpuid(env->kvm_state, max)) == NULL) { + while ((cpuid = try_get_cpuid(s, max)) == NULL) { max *= 2; } @@ -153,7 +153,7 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, /* On Intel, kvm returns cpuid according to the Intel spec, * so add missing bits according to the AMD spec: */ - cpuid_1_edx = kvm_arch_get_supported_cpuid(env, 1, 0, R_EDX); + cpuid_1_edx = kvm_arch_get_supported_cpuid(s, 1, 0, R_EDX); ret |= cpuid_1_edx & 0x183f7ff; break; } @@ -166,7 +166,7 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, /* fallback for older kernels */ if (!has_kvm_features && (function == KVM_CPUID_FEATURES)) { - ret = get_para_features(env); + ret = get_para_features(s); } return ret; @@ -349,25 +349,25 @@ int kvm_arch_init_vcpu(CPUState *env) struct kvm_cpuid2 cpuid; struct kvm_cpuid_entry2 entries[100]; } __attribute__((packed)) cpuid_data; + KVMState *s = env->kvm_state; uint32_t limit, i, j, cpuid_i; uint32_t unused; struct kvm_cpuid_entry2 *c; uint32_t signature[3]; - env->cpuid_features &= kvm_arch_get_supported_cpuid(env, 1, 0, R_EDX); + env->cpuid_features &= kvm_arch_get_supported_cpuid(s, 1, 0, R_EDX); i = env->cpuid_ext_features & CPUID_EXT_HYPERVISOR; - env->cpuid_ext_features &= kvm_arch_get_supported_cpuid(env, 1, 0, R_ECX); + env->cpuid_ext_features &= kvm_arch_get_supported_cpuid(s, 1, 0, R_ECX); env->cpuid_ext_features |= i; - env->cpuid_ext2_features &= kvm_arch_get_supported_cpuid(env, 0x80000001, + env->cpuid_ext2_features &= kvm_arch_get_supported_cpuid(s, 0x80000001, 0, R_EDX); - env->cpuid_ext3_features &= kvm_arch_get_supported_cpuid(env, 0x80000001, + env->cpuid_ext3_features &= kvm_arch_get_supported_cpuid(s, 0x80000001, 0, R_ECX); - env->cpuid_svm_features &= kvm_arch_get_supported_cpuid(env, 0x8000000A, + env->cpuid_svm_features &= kvm_arch_get_supported_cpuid(s, 0x8000000A, 0, R_EDX); - cpuid_i = 0; /* Paravirtualization CPUIDs */ @@ -383,8 +383,8 @@ int kvm_arch_init_vcpu(CPUState *env) c = &cpuid_data.entries[cpuid_i++]; memset(c, 0, sizeof(*c)); c->function = KVM_CPUID_FEATURES; - c->eax = env->cpuid_kvm_features & kvm_arch_get_supported_cpuid(env, - KVM_CPUID_FEATURES, 0, R_EAX); + c->eax = env->cpuid_kvm_features & + kvm_arch_get_supported_cpuid(s, KVM_CPUID_FEATURES, 0, R_EAX); has_msr_async_pf_en = c->eax & (1 << KVM_FEATURE_ASYNC_PF); @@ -453,7 +453,7 @@ int kvm_arch_init_vcpu(CPUState *env) /* Call Centaur's CPUID instructions they are supported. */ if (env->cpuid_xlevel2 > 0) { env->cpuid_ext4_features &= - kvm_arch_get_supported_cpuid(env, 0xC0000001, 0, R_EDX); + kvm_arch_get_supported_cpuid(s, 0xC0000001, 0, R_EDX); cpu_x86_cpuid(env, 0xC0000000, 0, &limit, &unused, &unused, &unused); for (i = 0xC0000000; i <= limit; i++) {