public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] RE: ia32 emulation on Intel CPU
@ 2007-03-25 18:54 Kiselev, Sergey
       [not found] ` <C07C4589BE74A34981C3C3525EE1F80101AB02CD-t8eeqVGEwHVP9JyJpTNKArfspsVTdybXVpNB7YpNyf8@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Kiselev, Sergey @ 2007-03-25 18:54 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

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

Following patch adds back this functionality:
 
Signed-off-by: Sergey Kiselev <sergey.kiselev-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>

--- kvm-18.orig/qemu/qemu-kvm.c	2007-03-21 17:55:11.000000000 +0200
+++ kvm-18/qemu/qemu-kvm.c	2007-03-25 20:42:53.000000000 +0200
@@ -693,6 +693,37 @@
 	if ((h_edx & 0x00100000) == 0)
 	    e->edx &= ~0x00100000u;
     }
+    // sysenter isn't supported on compatibility mode on AMD.  and
syscall
+    // isn't supported in compatibility mode on Intel.  so advertise
the
+    // actuall cpu, and say goodbye to migration between different
vendors
+    // is you use compatibility mode.
+    if (function == 0) {
+	uint32_t bcd[3];
+	asm (
+#ifdef __x86_64__
+	     "push %%rax; push %%rbx; push %%rcx; push %%rdx \n\t"
+	     "mov $0, %%eax \n\t"
+	     "cpuid \n\t"
+	     "mov (%%rsp), %%rax \n\t"
+	     "mov %%ebx, (%%rax) \n\t"
+	     "mov %%ecx, 4(%%rax) \n\t"
+	     "mov %%edx, 8(%%rax) \n\t"
+	     "pop %%rdx; pop %%rcx; pop %%rbx; pop %%rax"
+#else
+	     "push %%eax; push %%ebx; push %%ecx; push %%edx \n\t"
+	     "mov $0, %%eax \n\t"
+	     "cpuid \n\t"
+	     "mov (%%esp), %%eax \n\t"
+	     "mov %%ebx, (%%eax) \n\t"
+	     "mov %%ecx, 4(%%eax) \n\t"
+	     "mov %%edx, 8(%%eax) \n\t"
+	     "pop %%edx; pop %%ecx; pop %%ebx; pop %%eax"
+#endif
+	     : : "d"(bcd) : "memory");
+	e->ebx = bcd[0];
+	e->ecx = bcd[1];
+	e->edx = bcd[2];
+    }
 }
 
 int kvm_qemu_init_env(CPUState *cenv)



________________________________

From: Kiselev, Sergey 
Sent: 25 March 2007 20:28
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: ia32 emulation on Intel CPU


Hi,
 
In kvm-18 code that returned actual CPU vendor string was removed from
qemu-kvm.c (so kvm-18 running on Intel's CPU will return "AuthenticAMD"
vendor string).
Linux uses boot_cpu_data.x86_vendor (derived from vendor string) to
determine whenever to use syscall or sysenter instruction. It seems that
when running under kvm it will always try to use sysenter, which causes
invalid instruction trap...
 
Thanks,
Sergey

[-- Attachment #2: kvm-18-vendor_id.patch --]
[-- Type: application/octet-stream, Size: 1363 bytes --]

Signed-off-by: Sergey Kiselev <sergey.kiselev@intel.com>

--- kvm-18.orig/qemu/qemu-kvm.c	2007-03-21 17:55:11.000000000 +0200
+++ kvm-18/qemu/qemu-kvm.c	2007-03-25 20:42:53.000000000 +0200
@@ -693,6 +693,37 @@
 	if ((h_edx & 0x00100000) == 0)
 	    e->edx &= ~0x00100000u;
     }
+    // sysenter isn't supported on compatibility mode on AMD.  and syscall
+    // isn't supported in compatibility mode on Intel.  so advertise the
+    // actuall cpu, and say goodbye to migration between different vendors
+    // is you use compatibility mode.
+    if (function == 0) {
+	uint32_t bcd[3];
+	asm (
+#ifdef __x86_64__
+	     "push %%rax; push %%rbx; push %%rcx; push %%rdx \n\t"
+	     "mov $0, %%eax \n\t"
+	     "cpuid \n\t"
+	     "mov (%%rsp), %%rax \n\t"
+	     "mov %%ebx, (%%rax) \n\t"
+	     "mov %%ecx, 4(%%rax) \n\t"
+	     "mov %%edx, 8(%%rax) \n\t"
+	     "pop %%rdx; pop %%rcx; pop %%rbx; pop %%rax"
+#else
+	     "push %%eax; push %%ebx; push %%ecx; push %%edx \n\t"
+	     "mov $0, %%eax \n\t"
+	     "cpuid \n\t"
+	     "mov (%%esp), %%eax \n\t"
+	     "mov %%ebx, (%%eax) \n\t"
+	     "mov %%ecx, 4(%%eax) \n\t"
+	     "mov %%edx, 8(%%eax) \n\t"
+	     "pop %%edx; pop %%ecx; pop %%ebx; pop %%eax"
+#endif
+	     : : "d"(bcd) : "memory");
+	e->ebx = bcd[0];
+	e->ecx = bcd[1];
+	e->edx = bcd[2];
+    }
 }
 
 int kvm_qemu_init_env(CPUState *cenv)

[-- Attachment #3: Type: text/plain, Size: 345 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] RE: ia32 emulation on Intel CPU
       [not found] ` <C07C4589BE74A34981C3C3525EE1F80101AB02CD-t8eeqVGEwHVP9JyJpTNKArfspsVTdybXVpNB7YpNyf8@public.gmane.org>
@ 2007-03-26  9:25   ` Avi Kivity
  0 siblings, 0 replies; 2+ messages in thread
From: Avi Kivity @ 2007-03-26  9:25 UTC (permalink / raw)
  To: Kiselev, Sergey; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Kiselev, Sergey wrote:
> Following patch adds back this functionality:
>  
> Signed-off-by: Sergey Kiselev <sergey.kiselev-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>   

Applied, thanks.

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


-------------------------------------------------------------------------
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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-03-26  9:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-25 18:54 [PATCH] RE: ia32 emulation on Intel CPU Kiselev, Sergey
     [not found] ` <C07C4589BE74A34981C3C3525EE1F80101AB02CD-t8eeqVGEwHVP9JyJpTNKArfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-03-26  9:25   ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox