All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nitin A Kamble <nitin.a.kamble@intel.com>
To: avi@redhat.com
Cc: kvm@vger.kernel.org
Subject: [kernel patch] exposing host cpuids to guest
Date: Thu, 29 Jan 2009 17:12:56 -0800	[thread overview]
Message-ID: <1233277976.28605.9.camel@mukti.sc.intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 379 bytes --]

Avi,
  I reworked the earlier patch for exposing the host cpuid bits to
guests. Attached is the patch for your kvm.git tree. With this new code
in the kernel both the old and new qemu binaries are working.

  There are also changes for the kvm-userspace.git tree. I will be
sending out those changes too.

  Please apply or give feedback for this patch.

Thanks & Regards,
Nitin

[-- Attachment #2: expose_host_cpuids_2_guest_kernel_patch.diff --]
[-- Type: text/x-patch, Size: 2588 bytes --]

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 55fd4c5..b450a69 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -87,7 +87,7 @@
 #define KVM_NUM_MMU_PAGES (1 << KVM_MMU_HASH_SHIFT)
 #define KVM_MIN_FREE_MMU_PAGES 5
 #define KVM_REFILL_PAGES 25
-#define KVM_MAX_CPUID_ENTRIES 40
+#define KVM_MAX_CPUID_ENTRIES 100
 #define KVM_NR_FIXED_MTRR_REGION 88
 #define KVM_NR_VAR_MTRR 8
 
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index e96edda..4d5124b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1060,19 +1060,25 @@ long kvm_arch_dev_ioctl(struct file *filp,
 	case KVM_GET_SUPPORTED_CPUID: {
 		struct kvm_cpuid2 __user *cpuid_arg = argp;
 		struct kvm_cpuid2 cpuid;
+		int retry = 0;
 
 		r = -EFAULT;
 		if (copy_from_user(&cpuid, cpuid_arg, sizeof cpuid))
 			goto out;
 		r = kvm_dev_ioctl_get_supported_cpuid(&cpuid,
 						      cpuid_arg->entries);
-		if (r)
+		if (r == -EAGAIN)
+			retry = 1;
+		else if (r)
 			goto out;
 
 		r = -EFAULT;
 		if (copy_to_user(cpuid_arg, &cpuid, sizeof cpuid))
 			goto out;
-		r = 0;
+		if (retry)
+			r = -EAGAIN;
+		else
+			r = 0;
 		break;
 	}
 	default:
@@ -1325,10 +1331,14 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
 {
 	struct kvm_cpuid_entry2 *cpuid_entries;
 	int limit, nent = 0, r = -E2BIG;
+	int sizer = 0;
 	u32 func;
 
-	if (cpuid->nent < 1)
-		goto out;
+	if (cpuid->nent == 0) {
+		sizer = 1;
+		cpuid->nent = KVM_MAX_CPUID_ENTRIES;
+	}
+
 	r = -ENOMEM;
 	cpuid_entries = vmalloc(sizeof(struct kvm_cpuid_entry2) * cpuid->nent);
 	if (!cpuid_entries)
@@ -1339,6 +1349,7 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
 	for (func = 1; func <= limit && nent < cpuid->nent; ++func)
 		do_cpuid_ent(&cpuid_entries[nent], func, 0,
 			     &nent, cpuid->nent);
+
 	r = -E2BIG;
 	if (nent >= cpuid->nent)
 		goto out_free;
@@ -1348,16 +1359,21 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
 	for (func = 0x80000001; func <= limit && nent < cpuid->nent; ++func)
 		do_cpuid_ent(&cpuid_entries[nent], func, 0,
 			     &nent, cpuid->nent);
-	r = -EFAULT;
-	if (copy_to_user(entries, cpuid_entries,
-			 nent * sizeof(struct kvm_cpuid_entry2)))
-		goto out_free;
-	cpuid->nent = nent;
-	r = 0;
+
+	if (sizer)
+		r = -EAGAIN;
+	else {
+		r = -EFAULT;
+		if (copy_to_user(entries, cpuid_entries,
+				 nent * sizeof(struct kvm_cpuid_entry2)))
+			goto out_free;
+		r = 0;
+	}
 
 out_free:
 	vfree(cpuid_entries);
 out:
+	cpuid->nent = nent;
 	return r;
 }
 

             reply	other threads:[~2009-01-30  1:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-30  1:12 Nitin A Kamble [this message]
2009-01-30  1:54 ` [userspace patch] exposing host cpuids to guest Nitin A Kamble
2009-01-30 10:57   ` Amit Shah
2009-01-30 19:40     ` Nitin A Kamble
2009-01-30 11:25 ` [kernel " Amit Shah
2009-01-30 19:36   ` Nitin A Kamble

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1233277976.28605.9.camel@mukti.sc.intel.com \
    --to=nitin.a.kamble@intel.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.