public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Avi Kivity <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>, kvm <kvm@vger.kernel.org>,
	Gleb Natapov <gleb@redhat.com>
Subject: Re: VMX and save/restore guest in virtual-8086 mode
Date: Thu, 08 Apr 2010 09:22:59 +0200	[thread overview]
Message-ID: <4BBD8453.2030405@siemens.com> (raw)
In-Reply-To: <4BBCEF34.8000607@redhat.com>

Avi Kivity wrote:
> 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)?

Just like we manipulate the flags for guest debugging in the
set/get_rflags vendor handlers, the same should happen for IOPL and VM.
This is no business of enter_pmode/rmode.

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

It has to be - otherwise the decision to go for full sync and individual
get/set IOCTL would have been wrong. What happens during tpr patching?

> 
>> - Should be conditional on VMX !unrestricted guest.
>>    
> 
> Userspace should know nothing of this mess.
> 
>> - Its a fugly workaround.
>>    
> 
> True.
> 

Still likely the way to go for old kernels.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

  reply	other threads:[~2010-04-08  7:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-07 20:24 VMX and save/restore guest in virtual-8086 mode Marcelo Tosatti
2010-04-07 20:46 ` Avi Kivity
2010-04-08  7:22   ` Jan Kiszka [this message]
2010-04-08  7:29     ` Avi Kivity
2010-04-08  7:54       ` Jan Kiszka
2010-04-08  8:05         ` Avi Kivity
2010-04-08 14:16           ` Marcelo Tosatti
2010-04-08 14:47             ` Avi Kivity
2010-04-08 14:56             ` Jan Kiszka
2010-04-08 14:47         ` Marcelo Tosatti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BBD8453.2030405@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=avi@redhat.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox