Skip to contentSkip to conversation

Nested VMX: prohabit virtual vmentry/vmexit during IO emulaiton

PATCH In review Yang Zhang 3 participants 5 messages Jan 17, 2014 – Jan 21, 2014

lore
Share & tools
lore

Yang Zhang

author
#0 lore raw

PATCH 1/1 Nested VMX: prohabit virtual vmentry/vmexit during IO emulaiton

From: Yang Zhang <[email protected]>

Sometimes, L0 need to decode the 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 in L1's context, but since we got a X86EMUL_RETRY just now and this means hyprevisor 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.

---
 xen/arch/x86/hvm/vmx/vvmx.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
xen/arch/x86/hvm/vmx/vvmx.c +8 -0
index 41db52b..27119d5 100644
@@ -1394,8 +1394,16 @@ void nvmx_switch_guest(void)
     struct vcpu *v = current;
     struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
     struct cpu_user_regs *regs = guest_cpu_user_regs();
+    ioreq_t *p = get_ioreq(v);
 
     /*
+     * 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 ( p->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,
      * a L1 virtual interrupt causes another virtual vmexit, we
Signature · 1 line
1.7.1
#1 lore raw
Quoted 17 lines
Quoted 1 line
Quoted 1 line · Yang Zhang

Sometimes, L0 need to decode the 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
in L1's context, but since we got a X86EMUL_RETRY just now and this means hyprevisor
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.

Quoted 3 lines
---
 xen/arch/x86/hvm/vmx/vvmx.c |    8 ++++++++

Didn't we agree earlier on to do this in common code?

Jan

#2 lore raw

Jan Beulich wrote on 2014-01-17:

Quoted 13 lines
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Yang Zhang

Sometimes, L0 need to decode the 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 in L1's context, but since we got a X86EMUL_RETRY just now and this means hyprevisor 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.

Quoted 6 lines
Quoted 3 lines
---
 xen/arch/x86/hvm/vmx/vvmx.c |    8 ++++++++

Didn't we agree earlier on to do this in common code?

I think you agree with this fixing. Let me have a double check: Do you mean move the check to nhvm_interrupt_block () as Christoph suggested or move to another place in common code? Christoph' s suggestion doesn't solve the issue as I said in previous thread. Also, since SVM and VMX handle the vmswitch totally independent, there is no proper point to put the check in common code to cover both.

Best regards,
Yang

#3 lore raw
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Yang Z

Jan Beulich wrote on 2014-01-17:

Quoted 13 lines
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Yang Zhang

Sometimes, L0 need to decode the 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 in L1's context, but since we got a X86EMUL_RETRY just now and this means hyprevisor 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.

Quoted 6 lines
Quoted 3 lines
---
 xen/arch/x86/hvm/vmx/vvmx.c |    8 ++++++++

Didn't we agree earlier on to do this in common code?

Quoted 6 lines

I think you agree with this fixing. Let me have a double check: Do you mean move the check to nhvm_interrupt_block () as Christoph suggested or move to another place in common code? Christoph' s suggestion doesn't solve the issue as I said in previous thread. Also, since SVM and VMX handle the vmswitch totally independent, there is no proper point to put the check in common code to cover both.

Okay, fine with me then as is. Awaiting a VMX maintainer ack then...

Jan

Acked-by
#4 lore raw
Quoted 22 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Yang Z

Jan Beulich wrote on 2014-01-17:

Quoted 19 lines
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Yang Zhang

Sometimes, L0 need to decode the 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 in L1's context, but since we got a X86EMUL_RETRY just now and this means hyprevisor 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.

Quoted 3 lines
---
 xen/arch/x86/hvm/vmx/vvmx.c |    8 ++++++++

Didn't we agree earlier on to do this in common code?

Quoted 8 lines
Quoted 6 lines

I think you agree with this fixing. Let me have a double check: Do you mean move the check to nhvm_interrupt_block () as Christoph suggested or move to another place in common code? Christoph' s suggestion doesn't solve the issue as I said in previous thread. Also, since SVM and VMX handle the vmswitch totally independent, there is no proper point to put the check in common code to cover both.

Okay, fine with me then as is. Awaiting a VMX maintainer ack then...

Quoted 3 lines

Jan

Signature · 2 lines
Jun
Intel Open Source Technology Center