From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: VMX and save/restore guest in virtual-8086 mode Date: Wed, 7 Apr 2010 17:24:00 -0300 Message-ID: <20100407202400.GA29595@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Avi Kivity , Jan Kiszka , Gleb Natapov To: kvm Return-path: Received: from mx1.redhat.com ([209.132.183.28]:30817 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751871Ab0DGUYN (ORCPT ); Wed, 7 Apr 2010 16:24:13 -0400 Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: During initialization, WinXP.32 switches to virtual-8086 mode, with paging enabled, to use VGABIOS functions. Since enter_pmode unconditionally clears IOPL and VM bits in RFLAGS flags = vmcs_readl(GUEST_RFLAGS); flags &= ~(X86_EFLAGS_IOPL | X86_EFLAGS_VM); flags |= (vmx->rmode.save_iopl << IOPL_SHIFT); vmcs_writel(GUEST_RFLAGS, flags); And the order of loading state is set_regs (rflags) followed by set_sregs (cr0), these bits are lost across save/restore: savevm 1 kvm_arch_save_regs EIP=7a04 cr0=8001003b eflags=33286 system_reset loadvm 1 kvm_arch_save_regs EIP=7a04 cr0=8001003b eflags=10286 cont kvm: unhandled exit 80000021 kvm_run returned -22 The following patch fixes it, but it has some drawbacks: - cpu_synchronize_state+writeback is noticeably slow with tpr patching, this makes it slower. - Should be conditional on VMX !unrestricted guest. - Its a fugly workaround. Any better ideas? diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index 748ff69..9821653 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -956,6 +956,7 @@ void kvm_arch_load_regs(CPUState *env, int level) sregs.efer = env->efer; kvm_set_sregs(env, &sregs); + kvm_set_regs(env, ®s); /* msrs */ n = 0;