From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: VMX and save/restore guest in virtual-8086 mode Date: Wed, 07 Apr 2010 23:46:44 +0300 Message-ID: <4BBCEF34.8000607@redhat.com> References: <20100407202400.GA29595@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm , Jan Kiszka , Gleb Natapov To: Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:33404 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751947Ab0DGUqu (ORCPT ); Wed, 7 Apr 2010 16:46:50 -0400 In-Reply-To: <20100407202400.GA29595@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: On 04/07/2010 11:24 PM, Marcelo Tosatti wrote: > 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); > > Looks like KVM_SET_REGS should write rmode.save_iopl (and a new save_vm)? I think we have a small related bug in realmode emulation - we run the guest with iopl=3. This means the guest can use pushfl and see the host iopl instead of the guest iopl. We should run with iopl=0, which causes pushfl/popfl to #GP, where we can emulate the flags correctly (by updating rmode.save_iopl and rmode.save_vm). That has lots of implications however... > 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. > Isn't it a very rare event? > - Should be conditional on VMX !unrestricted guest. > Userspace should know nothing of this mess. > - Its a fugly workaround. > True. -- I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.