public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* VMX and save/restore guest in virtual-8086 mode
@ 2010-04-07 20:24 Marcelo Tosatti
  2010-04-07 20:46 ` Avi Kivity
  0 siblings, 1 reply; 10+ messages in thread
From: Marcelo Tosatti @ 2010-04-07 20:24 UTC (permalink / raw)
  To: kvm; +Cc: Avi Kivity, Jan Kiszka, Gleb Natapov


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, &regs);
 
     /* msrs */
     n = 0;





^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-04-08 14:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox