From patchwork Tue Jun 1 12:33:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 103530 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 o51CY1bV008578 for ; Tue, 1 Jun 2010 12:34:02 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756415Ab0FAMd6 (ORCPT ); Tue, 1 Jun 2010 08:33:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24386 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752791Ab0FAMdv (ORCPT ); Tue, 1 Jun 2010 08:33:51 -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.13.8/8.13.8) with ESMTP id o51CXpo4006792 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 1 Jun 2010 08:33:51 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o51CXnkS014649 for ; Tue, 1 Jun 2010 08:33:50 -0400 Received: from file.tlv.redhat.com (file.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 20912250ADC; Tue, 1 Jun 2010 15:33:48 +0300 (IDT) From: Avi Kivity To: Marcelo Tosatti , Glauber Costa Cc: kvm@vger.kernel.org Subject: [PATCH 5/5] Use upstream's kvm_arch_init_vcpu()'s cpuid bits Date: Tue, 1 Jun 2010 15:33:47 +0300 Message-Id: <1275395627-2321-6-git-send-email-avi@redhat.com> In-Reply-To: <1275395627-2321-1-git-send-email-avi@redhat.com> References: <1275395627-2321-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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 12:34:02 +0000 (UTC) diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index 853d50e..3c33e64 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -1101,114 +1101,10 @@ void kvm_arch_save_regs(CPUState *env) kvm_get_debugregs(env); } -static void do_cpuid_ent(struct kvm_cpuid_entry2 *e, uint32_t function, - uint32_t count, CPUState *env) -{ - env->regs[R_EAX] = function; - env->regs[R_ECX] = count; - qemu_kvm_cpuid_on_env(env); - e->function = function; - e->flags = 0; - e->index = 0; - e->eax = env->regs[R_EAX]; - e->ebx = env->regs[R_EBX]; - e->ecx = env->regs[R_ECX]; - e->edx = env->regs[R_EDX]; -} - -static void kvm_trim_features(uint32_t *features, uint32_t supported) -{ - int i; - uint32_t mask; - - for (i = 0; i < 32; ++i) { - mask = 1U << i; - if ((*features & mask) && !(supported & mask)) { - *features &= ~mask; - } - } -} - static int _kvm_arch_init_vcpu(CPUState *env) { - struct kvm_cpuid_entry2 cpuid_ent[100]; -#ifdef KVM_CPUID_SIGNATURE - struct kvm_cpuid_entry2 *pv_ent; - uint32_t signature[3]; -#endif - int cpuid_nent = 0; - CPUState copy; - uint32_t i, j, limit; - kvm_arch_reset_vcpu(env); -#ifdef KVM_CPUID_SIGNATURE - /* Paravirtualization CPUIDs */ - memcpy(signature, "KVMKVMKVM\0\0\0", 12); - pv_ent = &cpuid_ent[cpuid_nent++]; - memset(pv_ent, 0, sizeof(*pv_ent)); - pv_ent->function = KVM_CPUID_SIGNATURE; - pv_ent->eax = 0; - pv_ent->ebx = signature[0]; - pv_ent->ecx = signature[1]; - pv_ent->edx = signature[2]; - - pv_ent = &cpuid_ent[cpuid_nent++]; - memset(pv_ent, 0, sizeof(*pv_ent)); - pv_ent->function = KVM_CPUID_FEATURES; - pv_ent->eax = get_para_features(env); -#endif - - kvm_trim_features(&env->cpuid_features, - kvm_arch_get_supported_cpuid(env, 1, R_EDX)); - - /* prevent the hypervisor bit from being cleared by the kernel */ - i = env->cpuid_ext_features & CPUID_EXT_HYPERVISOR; - kvm_trim_features(&env->cpuid_ext_features, - kvm_arch_get_supported_cpuid(env, 1, R_ECX)); - env->cpuid_ext_features |= i; - - kvm_trim_features(&env->cpuid_ext2_features, - kvm_arch_get_supported_cpuid(env, 0x80000001, R_EDX)); - kvm_trim_features(&env->cpuid_ext3_features, - kvm_arch_get_supported_cpuid(env, 0x80000001, R_ECX)); - - copy = *env; - - copy.regs[R_EAX] = 0; - qemu_kvm_cpuid_on_env(©); - limit = copy.regs[R_EAX]; - - for (i = 0; i <= limit; ++i) { - if (i == 4 || i == 0xb || i == 0xd) { - for (j = 0; ; ++j) { - do_cpuid_ent(&cpuid_ent[cpuid_nent], i, j, ©); - - cpuid_ent[cpuid_nent].flags = KVM_CPUID_FLAG_SIGNIFCANT_INDEX; - cpuid_ent[cpuid_nent].index = j; - - cpuid_nent++; - - if (i == 4 && copy.regs[R_EAX] == 0) - break; - if (i == 0xb && !(copy.regs[R_ECX] & 0xff00)) - break; - if (i == 0xd && copy.regs[R_EAX] == 0) - break; - } - } else - do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, 0, ©); - } - - copy.regs[R_EAX] = 0x80000000; - qemu_kvm_cpuid_on_env(©); - limit = copy.regs[R_EAX]; - - for (i = 0x80000000; i <= limit; ++i) - do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, 0, ©); - - kvm_setup_cpuid2(env, cpuid_nent, cpuid_ent); - #ifdef KVM_CAP_MCE if (((env->cpuid_version >> 8)&0xF) >= 6 && (env->cpuid_features&(CPUID_MCE|CPUID_MCA)) == (CPUID_MCE|CPUID_MCA) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 8db6d54..9cb9cf4 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -168,8 +168,6 @@ static int _kvm_arch_init_vcpu(CPUState *env); int kvm_arch_init_vcpu(CPUState *env) { int r; -#ifdef KVM_UPSTREAM - struct { struct kvm_cpuid2 cpuid; struct kvm_cpuid_entry2 entries[100]; @@ -181,8 +179,6 @@ int kvm_arch_init_vcpu(CPUState *env) uint32_t signature[3]; #endif -#endif - r = _kvm_arch_init_vcpu(env); if (r < 0) { return r; @@ -192,6 +188,8 @@ int kvm_arch_init_vcpu(CPUState *env) env->mp_state = KVM_MP_STATE_RUNNABLE; +#endif + env->cpuid_features &= kvm_arch_get_supported_cpuid(env, 1, R_EDX); i = env->cpuid_ext_features & CPUID_EXT_HYPERVISOR; @@ -285,8 +283,6 @@ int kvm_arch_init_vcpu(CPUState *env) cpuid_data.cpuid.nent = cpuid_i; return kvm_vcpu_ioctl(env, KVM_SET_CPUID2, &cpuid_data); -#endif - return 0; } void kvm_arch_reset_vcpu(CPUState *env)