From patchwork Tue Jun 1 02:39:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 103350 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o512eIeN004138 for ; Tue, 1 Jun 2010 02:40:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753260Ab0FACkQ (ORCPT ); Mon, 31 May 2010 22:40:16 -0400 Received: from mga03.intel.com ([143.182.124.21]:15545 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753186Ab0FACkO (ORCPT ); Mon, 31 May 2010 22:40:14 -0400 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 31 May 2010 19:40:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.53,337,1272870000"; d="scan'208";a="283402301" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.36.64]) by azsmga001.ch.intel.com with ESMTP; 31 May 2010 19:40:12 -0700 Received: from yasker by syang10-desktop with local (Exim 4.71) (envelope-from ) id 1OJHOM-0000L0-FU; Tue, 01 Jun 2010 10:39:46 +0800 From: Sheng Yang To: Avi Kivity , Marcelo Tosatti Cc: Anthony Liguori , kvm@vger.kernel.org, Sheng Yang Subject: [PATCH 1/2] qemu: kvm: Extend kvm_arch_get_supported_cpuid() to support index Date: Tue, 1 Jun 2010 10:39:44 +0800 Message-Id: <1275359985-1273-1-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.7.0.4 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 01 Jun 2010 02:40:18 +0000 (UTC) diff --git a/kvm.h b/kvm.h index aab5118..16b06a4 100644 --- a/kvm.h +++ b/kvm.h @@ -152,7 +152,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, - int reg); + uint32_t index, int reg); void kvm_cpu_synchronize_state(CPUState *env); void kvm_cpu_synchronize_post_reset(CPUState *env); void kvm_cpu_synchronize_post_init(CPUState *env); diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index 95b7aa5..1eb8768 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -1188,18 +1188,18 @@ int kvm_arch_init_vcpu(CPUState *cenv) #endif kvm_trim_features(&cenv->cpuid_features, - kvm_arch_get_supported_cpuid(cenv, 1, R_EDX)); + kvm_arch_get_supported_cpuid(cenv, 1, 0, R_EDX)); /* prevent the hypervisor bit from being cleared by the kernel */ i = cenv->cpuid_ext_features & CPUID_EXT_HYPERVISOR; kvm_trim_features(&cenv->cpuid_ext_features, - kvm_arch_get_supported_cpuid(cenv, 1, R_ECX)); + kvm_arch_get_supported_cpuid(cenv, 1, 0, R_ECX)); cenv->cpuid_ext_features |= i; kvm_trim_features(&cenv->cpuid_ext2_features, - kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_EDX)); + kvm_arch_get_supported_cpuid(cenv, 0x80000001, 0, R_EDX)); kvm_trim_features(&cenv->cpuid_ext3_features, - kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_ECX)); + kvm_arch_get_supported_cpuid(cenv, 0x80000001, 0, R_ECX)); copy = *cenv; diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 87c1133..626cac6 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -71,7 +71,8 @@ static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int max) return cpuid; } -uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int reg) +uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, + uint32_t index, int reg) { struct kvm_cpuid2 *cpuid; int i, max; @@ -88,7 +89,8 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int reg) } for (i = 0; i < cpuid->nent; ++i) { - if (cpuid->entries[i].function == function) { + if (cpuid->entries[i].function == function && + cpuid->entries[i].index == index) { switch (reg) { case R_EAX: ret = cpuid->entries[i].eax; @@ -110,7 +112,7 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int reg) /* 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, R_EDX); + cpuid_1_edx = kvm_arch_get_supported_cpuid(env, 1, 0, R_EDX); ret |= cpuid_1_edx & 0x183f7ff; break; } @@ -126,7 +128,8 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int reg) #else -uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int reg) +uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, + uint32_t index, int reg) { return -1U; } @@ -180,16 +183,16 @@ int kvm_arch_init_vcpu(CPUState *env) env->mp_state = KVM_MP_STATE_RUNNABLE; - env->cpuid_features &= kvm_arch_get_supported_cpuid(env, 1, R_EDX); + env->cpuid_features &= kvm_arch_get_supported_cpuid(env, 1, 0, R_EDX); i = env->cpuid_ext_features & CPUID_EXT_HYPERVISOR; - env->cpuid_ext_features &= kvm_arch_get_supported_cpuid(env, 1, R_ECX); + env->cpuid_ext_features &= kvm_arch_get_supported_cpuid(env, 1, 0, R_ECX); env->cpuid_ext_features |= i; env->cpuid_ext2_features &= kvm_arch_get_supported_cpuid(env, 0x80000001, - R_EDX); + 0, R_EDX); env->cpuid_ext3_features &= kvm_arch_get_supported_cpuid(env, 0x80000001, - R_ECX); + 0, R_ECX); cpuid_i = 0;