From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Joerg Roedel" Subject: [PATCH try #2] kvm-12 userland guest reboot fix Date: Wed, 31 Jan 2007 17:58:30 +0100 Message-ID: <20070131165830.GB8491@amd.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=b5gNqxB1S1yM7hjW To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Return-path: Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org --b5gNqxB1S1yM7hjW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: 7bit From: Markus Rechberger From: Joerg Roedel 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. The patch should also work on Intel VMX now. Signed-off-by: Markus Rechberger Signed-off-by: Joerg Roedel -- Joerg Roedel Operating System Research Center AMD Saxony LLC & Co. KG --b5gNqxB1S1yM7hjW Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=kvm-12-reboot-fix2.patch Content-Transfer-Encoding: 7bit diff -upr kvm-12/kernel/vmx.c kvm-12-reboot-fixed/kernel/vmx.c --- kvm-12/kernel/vmx.c 2007-01-23 11:40:46.000000000 +0100 +++ kvm-12-reboot-fixed/kernel/vmx.c 2007-01-29 15:09:02.620662000 +0100 @@ -781,6 +781,9 @@ static void vmx_set_cr0(struct kvm_vcpu */ static void vmx_set_cr0_no_modeswitch(struct kvm_vcpu *vcpu, unsigned long cr0) { + if (!vcpu->rmode.active && !(cr0 & CR0_PE_MASK)) + enter_rmode(vcpu); + vcpu->rmode.active = ((cr0 & CR0_PE_MASK) == 0); update_exception_bitmap(vcpu); vmcs_writel(CR0_READ_SHADOW, cr0); diff -upr kvm-12/qemu/qemu-kvm.c kvm-12-reboot-fixed/qemu/qemu-kvm.c --- kvm-12/qemu/qemu-kvm.c 2007-01-23 11:40:46.000000000 +0100 +++ kvm-12-reboot-fixed/qemu/qemu-kvm.c 2007-01-23 20:32:35.556600000 +0100 @@ -582,6 +582,12 @@ static int kvm_halt(void *opaque, int vc 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 @@ static struct kvm_callbacks qemu_kvm_ops .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 -upr kvm-12/qemu/target-i386/helper2.c kvm-12-reboot-fixed/qemu/target-i386/helper2.c --- kvm-12/qemu/target-i386/helper2.c 2006-12-31 14:31:38.000000000 +0100 +++ kvm-12-reboot-fixed/qemu/target-i386/helper2.c 2007-01-23 20:24:42.265987000 +0100 @@ -151,6 +151,9 @@ CPUX86State *cpu_x86_init(void) 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 @@ void cpu_reset(CPUX86State *env) 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 -upr kvm-12/qemu/vl.c kvm-12-reboot-fixed/qemu/vl.c --- kvm-12/qemu/vl.c 2007-01-07 13:58:54.000000000 +0100 +++ kvm-12-reboot-fixed/qemu/vl.c 2007-01-23 20:11:53.772182000 +0100 @@ -5281,6 +5281,10 @@ int main_loop(void) 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) { Only in kvm-12-reboot-fixed/qemu: x86_64-softmmu diff -upr kvm-12/user/kvmctl.c kvm-12-reboot-fixed/user/kvmctl.c --- kvm-12/user/kvmctl.c 2006-12-31 14:31:38.000000000 +0100 +++ kvm-12-reboot-fixed/user/kvmctl.c 2007-01-23 19:48:18.111267000 +0100 @@ -522,6 +522,11 @@ static int handle_halt(kvm_context_t kvm 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 @@ again: 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 -upr kvm-12/user/kvmctl.h kvm-12-reboot-fixed/user/kvmctl.h --- kvm-12/user/kvmctl.h 2006-12-31 14:31:38.000000000 +0100 +++ kvm-12-reboot-fixed/user/kvmctl.h 2007-01-23 18:25:32.758594000 +0100 @@ -59,6 +59,7 @@ struct kvm_callbacks { * 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); --b5gNqxB1S1yM7hjW Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- 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 --b5gNqxB1S1yM7hjW Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kvm-devel mailing list kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/kvm-devel --b5gNqxB1S1yM7hjW--