Nested VMX: prohibit virtual vmentry/vmexit during IO emulation
authorYang Zhang <yang.z.zhang@Intel.com>
Thu, 23 Jan 2014 09:27:34 +0000 (10:27 +0100)
committerJan Beulich <jbeulich@suse.com>
Thu, 23 Jan 2014 09:27:34 +0000 (10:27 +0100)
Sometimes, L0 needs to decode L2's instruction to handle IO access directly.
And L0 may get X86EMUL_RETRY when handling this IO request. At same time, if
there is a virtual vmexit pending (for example, an interrupt pending to inject
to L1) and hypervisor will switch the VCPU context from L2 to L1. Now we
already are in L1's context, but since we got a X86EMUL_RETRY just now and
this means hypervisor will retry to handle the IO request later and
unfortunately, the retry will happen in L1's context. And it will cause the
problem. The fixing is that if there is a pending IO request, no virtual
vmexit/vmentry is allowed.

Signed-off-by: Yang Zhang <yang.z.zhang@Intel.com>
Acked-by: Jun Nakajima <jun.nakajima@intel.com>
xen/arch/x86/hvm/vmx/vvmx.c

index 41db52be44495ce46fdc58e53ad4d4430ba3799d..d2ba435471d0835d200414b9cdb6a43a2f96479a 100644 (file)
@@ -1395,6 +1395,13 @@ void nvmx_switch_guest(void)
     struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
     struct cpu_user_regs *regs = guest_cpu_user_regs();
 
+    /*
+     * a pending IO emualtion may still no finished. In this case,
+     * no virtual vmswith is allowed. Or else, the following IO
+     * emulation will handled in a wrong VCPU context.
+     */
+    if ( get_ioreq(v)->state != STATE_IOREQ_NONE )
+        return;
     /*
      * a softirq may interrupt us between a virtual vmentry is
      * just handled and the true vmentry. If during this window,