From patchwork Tue Jan 13 10:47:54 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 2129 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 n0DAiDE2022687 for ; Tue, 13 Jan 2009 02:44:13 -0800 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752538AbZAMKsM (ORCPT ); Tue, 13 Jan 2009 05:48:12 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751311AbZAMKsM (ORCPT ); Tue, 13 Jan 2009 05:48:12 -0500 Received: from hera.kernel.org ([140.211.167.34]:33957 "EHLO hera.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752538AbZAMKsI (ORCPT ); Tue, 13 Jan 2009 05:48:08 -0500 Received: from hera.kernel.org (IDENT:U2FsdGVkX19TeUyoH7VUMNGTi07322LaQdKh4WlcSAk@localhost [127.0.0.1]) by hera.kernel.org (8.14.2/8.14.2) with ESMTP id n0DAm0j9012109 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 13 Jan 2009 10:48:00 GMT Received: (from amit@localhost) by hera.kernel.org (8.14.2/8.13.1/Submit) id n0DAlxjm012108; Tue, 13 Jan 2009 10:47:59 GMT From: Amit Shah To: avi@redhat.com Cc: kvm@vger.kernel.org, Amit Shah Subject: [PATCH 2/2] KVM: userspace: Fetch sub-leaf cpuid values for functions 4, 0xb, 0xd. Date: Tue, 13 Jan 2009 10:47:54 +0000 Message-Id: <1231843674-11333-4-git-send-email-amit.shah@redhat.com> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1231843674-11333-3-git-send-email-amit.shah@redhat.com> References: <1231843674-11333-1-git-send-email-amit.shah@redhat.com> <1231843674-11333-2-git-send-email-amit.shah@redhat.com> <1231843674-11333-3-git-send-email-amit.shah@redhat.com> X-Virus-Scanned: ClamAV 0.93.3/8857/Tue Jan 13 07:35:27 2009 on hera.kernel.org X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on hera.kernel.org X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (hera.kernel.org [127.0.0.1]); Tue, 13 Jan 2009 10:48:01 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org CPUID functions 4, 0xb and 0xd have sub-leaf values which depend on the input value of ECX. Fetch these cpuid values and pass them on to the kernel. We also switch to the kvm_set_cpuid2() ioctl for this; kvm_set_cpuid() can't handle the extra parameters we need to support sub-leaves. Signed-off-by: Amit Shah --- qemu/qemu-kvm-x86.c | 37 ++++++++++++++++++++++++++++--------- 1 files changed, 28 insertions(+), 9 deletions(-) diff --git a/qemu/qemu-kvm-x86.c b/qemu/qemu-kvm-x86.c index 4fad2af..d9736b4 100644 --- a/qemu/qemu-kvm-x86.c +++ b/qemu/qemu-kvm-x86.c @@ -462,10 +462,11 @@ void kvm_arch_save_regs(CPUState *env) } } -static void do_cpuid_ent(struct kvm_cpuid_entry *e, uint32_t function, - CPUState *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->eax = env->regs[R_EAX]; @@ -507,14 +508,14 @@ static int get_para_features(kvm_context_t kvm_context) int kvm_arch_qemu_init_env(CPUState *cenv) { - struct kvm_cpuid_entry cpuid_ent[100]; + struct kvm_cpuid_entry2 cpuid_ent[100]; #ifdef KVM_CPUID_SIGNATURE - struct kvm_cpuid_entry *pv_ent; + struct kvm_cpuid_entry2 *pv_ent; uint32_t signature[3]; #endif int cpuid_nent = 0; CPUState copy; - uint32_t i, limit; + uint32_t i, j, limit; copy = *cenv; @@ -539,17 +540,35 @@ int kvm_arch_qemu_init_env(CPUState *cenv) qemu_kvm_cpuid_on_env(©); limit = copy.regs[R_EAX]; - for (i = 0; i <= limit; ++i) - do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, ©); + 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_SIGNIFICANT_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, ©); + do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, 0, ©); - kvm_setup_cpuid(kvm_context, cenv->cpu_index, cpuid_nent, cpuid_ent); + kvm_setup_cpuid2(kvm_context, cenv->cpu_index, cpuid_nent, cpuid_ent); return 0; }