public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm-12 userland guest reboot fix
@ 2007-01-24 13:05 Joerg Roedel
       [not found] ` <20070124130534.GA19732-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Joerg Roedel @ 2007-01-24 13:05 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

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

From: Markus Rechberger <markus.rechberger-5C7GfCeVMHo@public.gmane.org>
From: Joerg Roedel <joerg.roedel-5C7GfCeVMHo@public.gmane.org>

This patch fixes the initialization of the segment registers which
solves the triple fault and keyboard controller reset problems in
kvm/qemu guests as well as the slow grub menu interaction. This works
for SVM now, it is not tested on kvm/vmx.

Signed-off-by: Markus Rechberger <Markus.Rechberger-5C7GfCeVMHo@public.gmane.org>
Signed-off-by: Joerg Roedel <joerg.roedel-5C7GfCeVMHo@public.gmane.org>

-- 
Joerg Roedel
Operating System Research Center
AMD Saxony LLC & Co. KG

[-- Attachment #2: kvm-12-qemu-reboot.patch --]
[-- Type: text/plain, Size: 4080 bytes --]

diff -ur kvm-12-old/qemu/qemu-kvm.c kvm-12/qemu/qemu-kvm.c
--- kvm-12-old/qemu/qemu-kvm.c	2007-01-23 11:40:46.000000000 +0100
+++ kvm-12/qemu/qemu-kvm.c	2007-01-24 13:27:00.000000000 +0100
@@ -582,6 +582,12 @@
 
     return 1;
 }
+
+static int kvm_shutdown(void *opaque, int vcpu)
+{
+    qemu_system_reset_request();
+    return 1;
+}
  
 static struct kvm_callbacks qemu_kvm_ops = {
     .cpuid = kvm_cpuid,
@@ -601,6 +607,7 @@
     .writel = kvm_writel,
     .writeq = kvm_writeq,
     .halt  = kvm_halt,
+    .shutdown = kvm_shutdown,
     .io_window = kvm_io_window,
     .try_push_interrupts = try_push_interrupts,
     .post_kvm_run = post_kvm_run,
diff -ur kvm-12-old/qemu/qemu-kvm.h kvm-12/qemu/qemu-kvm.h
--- kvm-12-old/qemu/qemu-kvm.h	2006-12-31 14:31:38.000000000 +0100
+++ kvm-12/qemu/qemu-kvm.h	2007-01-24 12:21:29.000000000 +0100
@@ -10,5 +10,6 @@
 void kvm_save_registers(CPUState *env);
 int kvm_cpu_exec(CPUState *env);
 int kvm_update_debugger(CPUState *env);
+extern void qemu_system_reset_request(void);
 
 #endif
diff -ur kvm-12-old/qemu/target-i386/helper2.c kvm-12/qemu/target-i386/helper2.c
--- kvm-12-old/qemu/target-i386/helper2.c	2006-12-31 14:31:38.000000000 +0100
+++ kvm-12/qemu/target-i386/helper2.c	2007-01-24 12:20:46.000000000 +0100
@@ -151,6 +151,9 @@
 void cpu_reset(CPUX86State *env)
 {
     int i;
+    unsigned int flags = DESC_P_MASK |
+                         DESC_S_MASK |
+                         (2 << DESC_TYPE_SHIFT);
 
     memset(env, 0, offsetof(CPUX86State, breakpoints));
 
@@ -173,9 +176,9 @@
     env->tr.flags = DESC_P_MASK;
     
     cpu_x86_load_seg_cache(env, R_CS, 0xf000, 0xffff0000, 0xffff, 0); 
-    cpu_x86_load_seg_cache(env, R_DS, 0, 0, 0xffff, 0);
-    cpu_x86_load_seg_cache(env, R_ES, 0, 0, 0xffff, 0);
-    cpu_x86_load_seg_cache(env, R_SS, 0, 0, 0xffff, 0);
+    cpu_x86_load_seg_cache(env, R_DS, 0, 0, 0xffff, flags);
+    cpu_x86_load_seg_cache(env, R_ES, 0, 0, 0xffff, flags);
+    cpu_x86_load_seg_cache(env, R_SS, 0, 0, 0xffff, flags);
     cpu_x86_load_seg_cache(env, R_FS, 0, 0, 0xffff, 0);
     cpu_x86_load_seg_cache(env, R_GS, 0, 0, 0xffff, 0);
     
diff -ur kvm-12-old/qemu/vl.c kvm-12/qemu/vl.c
--- kvm-12-old/qemu/vl.c	2007-01-07 13:58:54.000000000 +0100
+++ kvm-12/qemu/vl.c	2007-01-24 13:41:24.000000000 +0100
@@ -5248,6 +5248,13 @@
     CPUState *env;
 
     cur_cpu = first_cpu;
+
+    /* initialize first cpu */
+#ifdef USE_KVM
+    if (kvm_allowed)
+	    kvm_load_registers(cur_cpu);
+#endif
+
     for(;;) {
         if (vm_running) {
 
@@ -5281,6 +5288,10 @@
             if (reset_requested) {
                 reset_requested = 0;
                 qemu_system_reset();
+#ifdef USE_KVM
+		if (kvm_allowed)
+			kvm_load_registers(env);
+#endif
                 ret = EXCP_INTERRUPT;
             }
             if (powerdown_requested) {
diff -ur kvm-12-old/user/kvmctl.c kvm-12/user/kvmctl.c
--- kvm-12-old/user/kvmctl.c	2006-12-31 14:31:38.000000000 +0100
+++ kvm-12/user/kvmctl.c	2007-01-24 12:20:46.000000000 +0100
@@ -522,6 +522,11 @@
 	return kvm->callbacks->halt(kvm->opaque, kvm_run->vcpu);
 }
 
+static int handle_shutdown(kvm_context_t kvm, struct kvm_run *kvm_run)
+{
+	return kvm->callbacks->shutdown(kvm->opaque, kvm_run->vcpu);
+}
+
 int try_push_interrupts(kvm_context_t kvm)
 {
 	return kvm->callbacks->try_push_interrupts(kvm->opaque);
@@ -594,6 +599,9 @@
 			break;
 		case KVM_EXIT_IRQ_WINDOW_OPEN:
 			break;
+		case KVM_EXIT_SHUTDOWN:
+			r = handle_shutdown(kvm, &kvm_run);
+			break;
 		default:
 			fprintf(stderr, "unhandled vm exit: 0x%x\n", kvm_run.exit_reason);
 			kvm_show_regs(kvm, vcpu);
diff -ur kvm-12-old/user/kvmctl.h kvm-12/user/kvmctl.h
--- kvm-12-old/user/kvmctl.h	2006-12-31 14:31:38.000000000 +0100
+++ kvm-12/user/kvmctl.h	2007-01-24 12:20:46.000000000 +0100
@@ -59,6 +59,7 @@
 	 * on the host CPU.
 	 */
     int (*halt)(void *opaque, int vcpu);
+    int (*shutdown)(void *opaque, int vcpu);
     int (*io_window)(void *opaque);
     int (*try_push_interrupts)(void *opaque);
     void (*post_kvm_run)(void *opaque, struct kvm_run *kvm_run);

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

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

* Re: [PATCH] kvm-12 userland guest reboot fix
       [not found] ` <20070124130534.GA19732-5C7GfCeVMHo@public.gmane.org>
@ 2007-01-24 13:47   ` Avi Kivity
       [not found]     ` <45B7638E.300-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Avi Kivity @ 2007-01-24 13:47 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Joerg Roedel wrote:
> From: Markus Rechberger <markus.rechberger-5C7GfCeVMHo@public.gmane.org>
> From: Joerg Roedel <joerg.roedel-5C7GfCeVMHo@public.gmane.org>
>
> This patch fixes the initialization of the segment registers which
> solves the triple fault and keyboard controller reset problems in
> kvm/qemu guests as well as the slow grub menu interaction. This works
> for SVM now, it is not tested on kvm/vmx.
>
>   

The patch fails to boot on Intel hosts.  Most likely the segment changes 
are illegal for vm86 mode, which we use on Intel to simulate real mode.

I tried to change flags in cpu_reset() so that type == 3 and dpl == 3, 
as required by 22.3.1.2, but it didn't help.


-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
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] 4+ messages in thread

* Re: [PATCH] kvm-12 userland guest reboot fix
       [not found]     ` <45B7638E.300-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
@ 2007-01-24 14:39       ` Joerg Roedel
       [not found]         ` <20070124143902.GB19730-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Joerg Roedel @ 2007-01-24 14:39 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

On Wed, Jan 24, 2007 at 03:47:58PM +0200, Avi Kivity wrote:
> Joerg Roedel wrote:
> >From: Markus Rechberger <markus.rechberger-5C7GfCeVMHo@public.gmane.org>
> >From: Joerg Roedel <joerg.roedel-5C7GfCeVMHo@public.gmane.org>
> >
> >This patch fixes the initialization of the segment registers which
> >solves the triple fault and keyboard controller reset problems in
> >kvm/qemu guests as well as the slow grub menu interaction. This works
> >for SVM now, it is not tested on kvm/vmx.
> >
> >  
> 
> The patch fails to boot on Intel hosts.  Most likely the segment
> changes are illegal for vm86 mode, which we use on Intel to simulate
> real mode.
> 
> I tried to change flags in cpu_reset() so that type == 3 and dpl == 3,
> as required by 22.3.1.2, but it didn't help.

Hmm, I am not aware of the VMX and realmode emulation implementation. Is
it hard to simply hide those flags to the vm86 mode?

-- 
Joerg Roedel
Operating System Research Center
AMD Saxony LLC & Co. KG



-------------------------------------------------------------------------
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] 4+ messages in thread

* Re: [PATCH] kvm-12 userland guest reboot fix
       [not found]         ` <20070124143902.GB19730-5C7GfCeVMHo@public.gmane.org>
@ 2007-01-24 15:14           ` Avi Kivity
  0 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2007-01-24 15:14 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Joerg Roedel wrote:
> On Wed, Jan 24, 2007 at 03:47:58PM +0200, Avi Kivity wrote:
>   
>> Joerg Roedel wrote:
>>     
>>> From: Markus Rechberger <markus.rechberger-5C7GfCeVMHo@public.gmane.org>
>>> From: Joerg Roedel <joerg.roedel-5C7GfCeVMHo@public.gmane.org>
>>>
>>> This patch fixes the initialization of the segment registers which
>>> solves the triple fault and keyboard controller reset problems in
>>> kvm/qemu guests as well as the slow grub menu interaction. This works
>>> for SVM now, it is not tested on kvm/vmx.
>>>
>>>  
>>>       
>> The patch fails to boot on Intel hosts.  Most likely the segment
>> changes are illegal for vm86 mode, which we use on Intel to simulate
>> real mode.
>>
>> I tried to change flags in cpu_reset() so that type == 3 and dpl == 3,
>> as required by 22.3.1.2, but it didn't help.
>>     
>
> Hmm, I am not aware of the VMX and realmode emulation implementation. Is
> it hard to simply hide those flags to the vm86 mode?
>
>   

It is supposed to be hidden (see fix_rmode_seg(), called from 
enter_rmode()), but somehow that path fails.

It's been a while since I hacked on that code.


-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
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] 4+ messages in thread

end of thread, other threads:[~2007-01-24 15:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-24 13:05 [PATCH] kvm-12 userland guest reboot fix Joerg Roedel
     [not found] ` <20070124130534.GA19732-5C7GfCeVMHo@public.gmane.org>
2007-01-24 13:47   ` Avi Kivity
     [not found]     ` <45B7638E.300-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-01-24 14:39       ` Joerg Roedel
     [not found]         ` <20070124143902.GB19730-5C7GfCeVMHo@public.gmane.org>
2007-01-24 15:14           ` Avi Kivity

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