diff mbox

KVM: x86: Store multiple cpuid entries for a single function

Message ID 20090113052302.GA3542@amit-x200.pnq.redhat.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Amit Shah Jan. 13, 2009, 5:23 a.m. UTC
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 <amit.shah@redhat.com>
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 <amit.shah@redhat.com>
---
 arch/x86/kvm/x86.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
diff mbox

Patch

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;