From patchwork Tue Jan 13 05:23:02 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 2068 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 n0D5Ivus028124 for ; Mon, 12 Jan 2009 21:18:57 -0800 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750912AbZAMFWy (ORCPT ); Tue, 13 Jan 2009 00:22:54 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751279AbZAMFWy (ORCPT ); Tue, 13 Jan 2009 00:22:54 -0500 Received: from mx2.redhat.com ([66.187.237.31]:58470 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750912AbZAMFWx (ORCPT ); Tue, 13 Jan 2009 00:22:53 -0500 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n0D5Mpd4020779; Tue, 13 Jan 2009 00:22:52 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n0D5Mp82012681; Tue, 13 Jan 2009 00:22:51 -0500 Received: from localhost (vpn-10-29.str.redhat.com [10.32.10.29]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n0D5Mlra012769; Tue, 13 Jan 2009 00:22:50 -0500 Date: Tue, 13 Jan 2009 10:53:02 +0530 From: Amit Shah To: Muli Ben-Yehuda Cc: avi@redhat.com, kvm@vger.kernel.org Subject: Re: [PATCH] KVM: x86: Store multiple cpuid entries for a single function Message-ID: <20090113052302.GA3542@amit-x200.pnq.redhat.com> References: <1231757365-15717-1-git-send-email-amit.shah@redhat.com> <1231757365-15717-2-git-send-email-amit.shah@redhat.com> <1231757365-15717-3-git-send-email-amit.shah@redhat.com> <20090112203931.GC13839@il.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20090112203931.GC13839@il.ibm.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Mon, Jan 12, 2009 at 10:39:31PM +0200, Muli Ben-Yehuda wrote: > On Mon, Jan 12, 2009 at 10:49:25AM +0000, Amit Shah wrote: > > + case 0xd: > > + vcpu->arch.cpuid_entries[i].index = count++; > > Isn't this using count uninitialized? Oops, that's right. Here's the refreshed patch. Thanks, Amit. From 0708401594924e2d8ca7bcc1512624a8a0a6e79d Mon Sep 17 00:00:00 2001 From: Amit Shah Date: Mon, 12 Jan 2009 15:59:37 +0530 Subject: [PATCH] KVM: x86: Store multiple cpuid entries for a single function CPUID functions 4, 0xb and 0xd behave differently for different values of ECX. Store these values if userspace passes them. Signed-off-by: Amit Shah --- arch/x86/kvm/x86.c | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 06b44fb..4d731fd 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1126,7 +1126,7 @@ static int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid *cpuid, struct kvm_cpuid_entry __user *entries) { - int r, i; + int r, i, count; struct kvm_cpuid_entry *cpuid_entries; r = -E2BIG; @@ -1140,14 +1140,27 @@ static int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu, if (copy_from_user(cpuid_entries, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry))) goto out_free; + count = 0; for (i = 0; i < cpuid->nent; i++) { vcpu->arch.cpuid_entries[i].function = cpuid_entries[i].function; vcpu->arch.cpuid_entries[i].eax = cpuid_entries[i].eax; vcpu->arch.cpuid_entries[i].ebx = cpuid_entries[i].ebx; vcpu->arch.cpuid_entries[i].ecx = cpuid_entries[i].ecx; vcpu->arch.cpuid_entries[i].edx = cpuid_entries[i].edx; - vcpu->arch.cpuid_entries[i].index = 0; - vcpu->arch.cpuid_entries[i].flags = 0; + switch (cpuid_entries[i].function) { + case 4: + case 0xb: + case 0xd: + vcpu->arch.cpuid_entries[i].index = count++; + vcpu->arch.cpuid_entries[i].flags = + KVM_CPUID_FLAG_SIGNIFICANT_INDEX; + break; + default: + vcpu->arch.cpuid_entries[i].index = 0; + vcpu->arch.cpuid_entries[i].flags = 0; + } + if (cpuid_entries[i].function != cpuid_entries[i+1].function) + count = 0; vcpu->arch.cpuid_entries[i].padding[0] = 0; vcpu->arch.cpuid_entries[i].padding[1] = 0; vcpu->arch.cpuid_entries[i].padding[2] = 0;