public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Glauber Costa <glommer@redhat.com>
To: kvm@vger.kernel.org
Cc: avi@redhat.com
Subject: [PATCH 5/5] use upstream cpuid code
Date: Wed, 15 Jul 2009 12:31:43 -0400	[thread overview]
Message-ID: <1247675503-7106-6-git-send-email-glommer@redhat.com> (raw)
In-Reply-To: <1247675503-7106-5-git-send-email-glommer@redhat.com>

use cpuid code from upstream. By doing that, we lose the following snippet
in kvm_get_supported_cpuid():

    ret |= 1 << 12; /* MTRR */
    ret |= 1 << 16; /* PAT */
    ret |= 1 << 7;  /* MCE */
    ret |= 1 << 14; /* MCA */

A quick search in mailing lists says this code is not really necessary, and we're
keeping it just for backwards compatibility. This is not that important, because
we'd lose it anyway in the golden day in which we totally merge with qemu.
Anyway, if it do _is_ important, we can send a patch to qemu with it.

Signed-off-by: Glauber Costa <glommer@redhat.com>
---
 qemu-kvm-x86.c    |  121 -----------------------------------------------------
 target-i386/kvm.c |    2 +
 2 files changed, 2 insertions(+), 121 deletions(-)

diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index 128a792..8d6a6a8 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -608,108 +608,6 @@ int kvm_disable_tpr_access_reporting(kvm_vcpu_context_t vcpu)
 
 #endif
 
-#ifdef KVM_CAP_EXT_CPUID
-
-static struct kvm_cpuid2 *try_get_cpuid(kvm_context_t kvm, int max)
-{
-	struct kvm_cpuid2 *cpuid;
-	int r, size;
-
-	size = sizeof(*cpuid) + max * sizeof(*cpuid->entries);
-	cpuid = qemu_malloc(size);
-	cpuid->nent = max;
-	r = kvm_ioctl(kvm_state, KVM_GET_SUPPORTED_CPUID, cpuid);
-	if (r == -1)
-		r = -errno;
-	else if (r == 0 && cpuid->nent >= max)
-		r = -E2BIG;
-	if (r < 0) {
-		if (r == -E2BIG) {
-			free(cpuid);
-			return NULL;
-		} else {
-			fprintf(stderr, "KVM_GET_SUPPORTED_CPUID failed: %s\n",
-				strerror(-r));
-			exit(1);
-		}
-	}
-	return cpuid;
-}
-
-#define R_EAX 0
-#define R_ECX 1
-#define R_EDX 2
-#define R_EBX 3
-#define R_ESP 4
-#define R_EBP 5
-#define R_ESI 6
-#define R_EDI 7
-
-uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg)
-{
-	struct kvm_cpuid2 *cpuid;
-	int i, max;
-	uint32_t ret = 0;
-	uint32_t cpuid_1_edx;
-
-	if (!kvm_check_extension(kvm_state, KVM_CAP_EXT_CPUID)) {
-		return -1U;
-	}
-
-	max = 1;
-	while ((cpuid = try_get_cpuid(kvm, max)) == NULL) {
-		max *= 2;
-	}
-
-	for (i = 0; i < cpuid->nent; ++i) {
-		if (cpuid->entries[i].function == function) {
-			switch (reg) {
-			case R_EAX:
-				ret = cpuid->entries[i].eax;
-				break;
-			case R_EBX:
-				ret = cpuid->entries[i].ebx;
-				break;
-			case R_ECX:
-				ret = cpuid->entries[i].ecx;
-				break;
-			case R_EDX:
-				ret = cpuid->entries[i].edx;
-                                if (function == 1) {
-                                    /* kvm misreports the following features
-                                     */
-                                    ret |= 1 << 12; /* MTRR */
-                                    ret |= 1 << 16; /* PAT */
-                                    ret |= 1 << 7;  /* MCE */
-                                    ret |= 1 << 14; /* MCA */
-                                }
-
-				/* On Intel, kvm returns cpuid according to
-				 * the Intel spec, so add missing bits
-				 * according to the AMD spec:
-				 */
-				if (function == 0x80000001) {
-					cpuid_1_edx = kvm_get_supported_cpuid(kvm, 1, R_EDX);
-					ret |= cpuid_1_edx & 0xdfeff7ff;
-				}
-				break;
-			}
-		}
-	}
-
-	free(cpuid);
-
-	return ret;
-}
-
-#else
-
-uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg)
-{
-	return -1U;
-}
-
-#endif
 int kvm_qemu_create_memory_alias(uint64_t phys_start,
                                  uint64_t len,
                                  uint64_t target_phys)
@@ -1191,19 +1089,6 @@ static int get_para_features(kvm_context_t kvm_context)
 	return features;
 }
 
-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;
-        }
-    }
-}
-
 int kvm_arch_qemu_init_env(CPUState *cenv)
 {
     struct kvm_cpuid_entry2 cpuid_ent[100];
@@ -1599,12 +1484,6 @@ int kvm_arch_init_irq_routing(void)
     return 0;
 }
 
-uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function,
-                                      int reg)
-{
-    return kvm_get_supported_cpuid(kvm_context, function, reg);
-}
-
 void kvm_arch_process_irqchip_events(CPUState *env)
 {
     kvm_arch_save_regs(env);
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index cfa5b80..359d27d 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -35,6 +35,7 @@
     do { } while (0)
 #endif
 
+#endif
 #ifdef KVM_CAP_EXT_CPUID
 
 static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int max)
@@ -130,6 +131,7 @@ static void kvm_trim_features(uint32_t *features, uint32_t supported)
         }
     }
 }
+#ifdef KVM_UPSTREAM
 
 int kvm_arch_init_vcpu(CPUState *env)
 {
-- 
1.6.2.2


  reply	other threads:[~2009-07-15 16:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-15 16:31 [PATCH 0/5] Further cleanups Glauber Costa
2009-07-15 16:31 ` [PATCH 1/5] remove kvm types from handle unhandled Glauber Costa
2009-07-15 16:31   ` [PATCH 2/5] reuse kvm_vm_ioctl Glauber Costa
2009-07-15 16:31     ` [PATCH 3/5] reuse kvm_ioctl Glauber Costa
2009-07-15 16:31       ` [PATCH 4/5] check extension Glauber Costa
2009-07-15 16:31         ` Glauber Costa [this message]
2009-07-17 13:35     ` [PATCH 2/5] reuse kvm_vm_ioctl Marcelo Tosatti
2009-07-17 14:21       ` Glauber Costa
2009-07-17 15:39     ` Marcelo Tosatti
2009-07-17 15:49       ` Glauber Costa
2009-07-17 15:46         ` Marcelo Tosatti
2009-07-17 15:57           ` Marcelo Tosatti
2009-07-17 16:48             ` Glauber Costa

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=1247675503-7106-6-git-send-email-glommer@redhat.com \
    --to=glommer@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox