From: Jeremy Katz <katzj-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: [PATCH] Match virtual machine processor vendor to that of the host
Date: Wed, 20 Dec 2006 23:34:05 -0500 [thread overview]
Message-ID: <1166675645.10717.99.camel@aglarond.local> (raw)
[-- Attachment #1: Type: text/plain, Size: 558 bytes --]
Currently, kvm ends up just using the standard qemu cpu initialization.
This means that all x86_64 virtual machines appear to have an
AuthenticAMD (AMD64) processor. This ends up causing a problem when
booting some x86_64 Linux kernels as they attempt to do AMD64 specific
initialization for things like performance counters. Since those MSRs
aren't supported on the Intel host, the virtual machine is halted.
The attached patch makes it so that we check the actual cpu type of the
host and then provide the same cpu type for the virtual machine.
Jeremy
[-- Attachment #2: kvm-cputype.patch --]
[-- Type: text/x-patch, Size: 2294 bytes --]
Index: qemu/exec-all.h
===================================================================
--- qemu/exec-all.h (revision 4142)
+++ qemu/exec-all.h (working copy)
@@ -603,3 +603,7 @@
}
#endif
+
+#ifdef USE_KVM
+#include "qemu-kvm.h"
+#endif
--- qemu/target-i386/helper2.c (revision 4142)
+++ qemu/target-i386/helper2.c (working copy)
@@ -141,6 +141,9 @@
#ifdef USE_KQEMU
kqemu_init(env);
#endif
+#ifdef USE_KVM
+ kvm_cpu_init(env);
+#endif
return env;
}
--- qemu/qemu-kvm.c (revision 4142)
+++ qemu/qemu-kvm.c (working copy)
@@ -590,6 +590,56 @@
.io_window = kvm_io_window,
};
+static inline unsigned int cpuid_ebx(unsigned int op)
+{
+ unsigned int eax, ebx;
+ __asm__ volatile
+ ("movl %%ebx, %%esi\n\t"
+ "cpuid\n\t"
+ "xchgl %%ebx, %%esi"
+ : "=a" (eax), "=S" (ebx)
+ : "0" (op));
+ return ebx;
+}
+
+static void kvm_update_cpuid(CPUState *env)
+{
+ int family, model, stepping;
+
+ /* we need to differentiate intel vs amd processors here.
+ * FIXME: should match more cpuid capabilities here */
+ switch (cpuid_ebx(0)) {
+ case 0x756e6547: /* Intel */
+ env->cpuid_vendor1 = 0x756e6547; /* "Genu" */
+ env->cpuid_vendor2 = 0x49656e69; /* "ineI" */
+ env->cpuid_vendor3 = 0x6c65746e; /* "ntel" */
+ family = 6;
+ model = 15;
+ stepping = 3;
+ break;
+ case 0x68747541: /* AMD */
+ env->cpuid_vendor1 = 0x68747541; /* "Auth" */
+ env->cpuid_vendor2 = 0x69746e65; /* "enti" */
+ env->cpuid_vendor3 = 0x444d4163; /* "cAMD" */
+ family = 6;
+ model = 2;
+ stepping = 3;
+ break;
+ default:
+ /* we don't know what it is, just return */
+ return;
+ break;
+ }
+
+ env->cpuid_version = (family << 8) | (model << 4) | stepping;
+}
+
+int kvm_cpu_init(CPUState *env)
+{
+ kvm_update_cpuid(env);
+ return 0;
+}
+
int kvm_qemu_init()
{
/* Try to initialize kvm */
Index: qemu/qemu-kvm.h
===================================================================
--- qemu/qemu-kvm.h (revision 4142)
+++ qemu/qemu-kvm.h (working copy)
@@ -10,4 +10,6 @@
int kvm_cpu_exec(CPUState *env);
int kvm_update_debugger(CPUState *env);
+int kvm_cpu_init(CPUState *env);
+
#endif
[-- Attachment #3: Type: text/plain, Size: 347 bytes --]
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
[-- Attachment #4: Type: text/plain, Size: 186 bytes --]
_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel
next reply other threads:[~2006-12-21 4:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-21 4:34 Jeremy Katz [this message]
[not found] ` <1166675645.10717.99.camel-T9xAYgMuJli44ywRPIzf9A@public.gmane.org>
2006-12-21 9:20 ` [PATCH] Match virtual machine processor vendor to that of the host Avi Kivity
[not found] ` <458A51C0.6020506-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2006-12-21 9:49 ` Michael Riepe
2006-12-21 14:01 ` Jeremy Katz
[not found] ` <1166709696.10717.113.camel-T9xAYgMuJli44ywRPIzf9A@public.gmane.org>
2006-12-21 14:26 ` Avi Kivity
[not found] ` <458A99AB.30701-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2006-12-21 15:49 ` Jeremy Katz
[not found] ` <1166716174.10717.145.camel-T9xAYgMuJli44ywRPIzf9A@public.gmane.org>
2006-12-21 16:16 ` Avi Kivity
[not found] ` <458AB35A.3060402-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2006-12-24 10:54 ` Avi Kivity
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=1166675645.10717.99.camel@aglarond.local \
--to=katzj-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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