Skip to contentSkip to conversation

kvm-12 userland guest reboot fix

PATCH In review Joerg Roedel 2 participants 4 messages Jan 24, 2007 3 messages not in the archive KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm-12 userland guest reboot fix

From: Markus Rechberger <[email protected]>
From: Joerg Roedel <[email protected]>

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.

Signature · 3 lines
Joerg Roedel
Operating System Research Center
AMD Saxony LLC & Co. KG
qemu/qemu-kvm.c +7 -0
diff -ur kvm-12-old/qemu/qemu-kvm.c kvm-12/qemu/qemu-kvm.c
@@ -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,
qemu/qemu-kvm.h +1 -0
diff -ur kvm-12-old/qemu/qemu-kvm.h kvm-12/qemu/qemu-kvm.h
@@ -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
qemu/target-i386/helper2.c +6 -3
diff -ur kvm-12-old/qemu/target-i386/helper2.c kvm-12/qemu/target-i386/helper2.c
@@ -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);
     
qemu/vl.c +11 -0
diff -ur kvm-12-old/qemu/vl.c kvm-12/qemu/vl.c
@@ -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) {
user/kvmctl.c +8 -0
diff -ur kvm-12-old/user/kvmctl.c kvm-12/user/kvmctl.c
@@ -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);
user/kvmctl.h +1 -0
diff -ur kvm-12-old/user/kvmctl.h kvm-12/user/kvmctl.h
@@ -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);

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

_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 9 lines · Joerg Roedel

From: Markus Rechberger <[email protected]>
From: Joerg Roedel <[email protected]>

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.

Signature · 8 lines
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

A message that is not in the archive (sent off-list or not yet received): 45B7638E.300-atKUWr5tajBWk0Htik3J/[email protected]

#4 lore raw
Quoted 11 lines · Avi Kivity
Quoted 9 lines · Joerg Roedel

From: Markus Rechberger <[email protected]>
From: Joerg Roedel <[email protected]>

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.

Quoted 6 lines

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?

Signature · 11 lines
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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw
Quoted 18 lines · Joerg Roedel
Quoted 16 lines · Avi Kivity
Quoted 10 lines · Joerg Roedel

From: Markus Rechberger <[email protected]>
From: Joerg Roedel <[email protected]>

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.

Quoted 8 lines
Quoted 3 lines

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.

Signature · 8 lines
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