Skip to contentSkip to conversation

x86/hvm: Fix the unknown nested vmexit reason 80000021 bug

PATCH In review Liang Li 5 participants 6 messages Apr 7, 2015 – Apr 14, 2015

lore
Share & tools
lore

Liang Li

author
#0 lore raw

PATCH 1/1 x86/hvm: Fix the unknown nested vmexit reason 80000021 bug

This bug will be trigged when NMI happen in the L2 guest. The current code handles the NMI incorrectly. According to Intel SDM 31.7.1.2 (Resuming Guest Software after Handling an Exception), If bit 31 of the IDT-vectoring information fields is set, and the virtual NMIs VM-execution control is 1, while bits 10:8 in the IDT-vectoring information field is 2, bit 3 in the interruptibility-state field should be cleared to avoid the next VM entry fail.

---
 xen/arch/x86/hvm/vmx/vmx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +3 -3
index e1c55ce..b1f2df8 100644
@@ -2621,7 +2621,8 @@ static void vmx_idtv_reinject(unsigned long idtv_info)
          * Clear NMI-blocking interruptibility info if an NMI delivery faulted.
          * Re-delivery will re-set it (see SDM 3B 25.7.1.2).
          */
-        if ( (idtv_info & INTR_INFO_INTR_TYPE_MASK) == (X86_EVENTTYPE_NMI<<8) )
+        if ( cpu_has_vmx_vnmi && ((idtv_info & INTR_INFO_INTR_TYPE_MASK) ==
+                                 (X86_EVENTTYPE_NMI<<8)) )
         {
             unsigned long intr_info;
 
@@ -2772,8 +2773,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
     hvm_maybe_deassert_evtchn_irq();
 
     __vmread(IDT_VECTORING_INFO, &idtv_info);
-    if ( !nestedhvm_vcpu_in_guestmode(v) && 
-         exit_reason != EXIT_REASON_TASK_SWITCH )
+    if ( exit_reason != EXIT_REASON_TASK_SWITCH )
         vmx_idtv_reinject(idtv_info);
 
     switch ( exit_reason )
Signature · 1 line
1.9.1
#1 lore raw
Quoted 18 lines · Liang Li

This bug will be trigged when NMI happen in the L2 guest. The current code handles the NMI incorrectly. According to Intel SDM 31.7.1.2 (Resuming Guest Software after Handling an Exception), If bit 31 of the IDT-vectoring information fields is set, and the virtual NMIs VM-execution control is 1, while bits 10:8 in the IDT-vectoring information field is 2, bit 3 in the interruptibility-state field should be cleared to avoid the next VM entry fail.

---
 xen/arch/x86/hvm/vmx/vmx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +0 -0
index e1c55ce..b1f2df8 100644

xen/arch/x86/hvm/vmx/vmx.c static void vmx_idtv_reinject(unsigned long idtv_info) · line 2625

Quoted 6 lines
xen/arch/x86/hvm/vmx/vmx.c +2 -1
@@ -2621,7 +2621,8 @@ static void vmx_idtv_reinject(unsigned long idtv_info)
          * Clear NMI-blocking interruptibility info if an NMI delivery faulted.
          * Re-delivery will re-set it (see SDM 3B 25.7.1.2).
          */
-        if ( (idtv_info & INTR_INFO_INTR_TYPE_MASK) == (X86_EVENTTYPE_NMI<<8) )
+        if ( cpu_has_vmx_vnmi && ((idtv_info & INTR_INFO_INTR_TYPE_MASK) ==
+                                 (X86_EVENTTYPE_NMI<<8)) )

This would be easier to read as

if ( cpu_has_vmx_vnmi &&

     (idtv_info & INTR_INFO_INTR_TYPE_MASK) == (X86_EVENTTYPE_NMI<<8)) )

~Andrew

Quoted 13 lines
xen/arch/x86/hvm/vmx/vmx.c +1 -2
         {
             unsigned long intr_info;
 
@@ -2772,8 +2773,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
     hvm_maybe_deassert_evtchn_irq();
 
     __vmread(IDT_VECTORING_INFO, &idtv_info);
-    if ( !nestedhvm_vcpu_in_guestmode(v) && 
-         exit_reason != EXIT_REASON_TASK_SWITCH )
+    if ( exit_reason != EXIT_REASON_TASK_SWITCH )
         vmx_idtv_reinject(idtv_info);
 
     switch ( exit_reason )
#2 lore raw
Quoted 28 lines · Andrew Cooper
Quoted 18 lines · Liang Li

This bug will be trigged when NMI happen in the L2 guest. The current code handles the NMI incorrectly. According to Intel SDM 31.7.1.2 (Resuming Guest Software after Handling an Exception), If bit 31 of the IDT-vectoring information fields is set, and the virtual NMIs VM-execution control is 1, while bits 10:8 in the IDT-vectoring information field is 2, bit 3 in the interruptibility-state field should be cleared to avoid the next VM entry fail.

---
 xen/arch/x86/hvm/vmx/vmx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +0 -0
index e1c55ce..b1f2df8 100644

xen/arch/x86/hvm/vmx/vmx.c static void vmx_idtv_reinject(unsigned long idtv_info) · line 2625

Quoted 6 lines
xen/arch/x86/hvm/vmx/vmx.c +2 -1
@@ -2621,7 +2621,8 @@ static void vmx_idtv_reinject(unsigned long idtv_info)
          * Clear NMI-blocking interruptibility info if an NMI delivery faulted.
          * Re-delivery will re-set it (see SDM 3B 25.7.1.2).
          */
-        if ( (idtv_info & INTR_INFO_INTR_TYPE_MASK) == (X86_EVENTTYPE_NMI<<8) )
+        if ( cpu_has_vmx_vnmi && ((idtv_info & INTR_INFO_INTR_TYPE_MASK) ==
+                                 (X86_EVENTTYPE_NMI<<8)) )

This would be easier to read as

Quoted 2 lines

if ( cpu_has_vmx_vnmi &&

     (idtv_info & INTR_INFO_INTR_TYPE_MASK) == (X86_EVENTTYPE_NMI<<8)) )

I was going to say something similar, but I think in the past Jan has said that Liang's original is more in line with the coding style.

But I'll let him comment.

-George

#3 lore raw
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 08.04.15 at 11:20, <[email protected]> wrote:
Quoted 14 lines · Andrew Cooper
Quoted 13 lines · Liang Li

This bug will be trigged when NMI happen in the L2 guest. The current code handles the NMI incorrectly. According to Intel SDM 31.7.1.2 (Resuming Guest Software after Handling an Exception), If bit 31 of the IDT-vectoring information fields is set, and the virtual NMIs VM-execution control is 1, while bits 10:8 in the IDT-vectoring information field is 2, bit 3 in the interruptibility-state field should be cleared to avoid the next VM entry fail.

---
 xen/arch/x86/hvm/vmx/vmx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 6 lines

xen/arch/x86/hvm/vmx/vmx.c static void vmx_idtv_reinject(unsigned long idtv_info) · line 2621

Quoted 6 lines
xen/arch/x86/hvm/vmx/vmx.c +0 -0
index e1c55ce..b1f2df8 100644
@@ -2621,7 +2621,8 @@ static void vmx_idtv_reinject(unsigned long idtv_info)
          * Clear NMI-blocking interruptibility info if an NMI delivery 

faulted.

Quoted 6 lines
Quoted 5 lines
xen/arch/x86/hvm/vmx/vmx.c +2 -1
          * Re-delivery will re-set it (see SDM 3B 25.7.1.2).
          */
-        if ( (idtv_info & INTR_INFO_INTR_TYPE_MASK) == (X86_EVENTTYPE_NMI<<8) )
+        if ( cpu_has_vmx_vnmi && ((idtv_info & INTR_INFO_INTR_TYPE_MASK) ==
+                                 (X86_EVENTTYPE_NMI<<8)) )
Quoted 7 lines
Quoted 4 lines

This would be easier to read as

if ( cpu_has_vmx_vnmi &&

     (idtv_info & INTR_INFO_INTR_TYPE_MASK) == (X86_EVENTTYPE_NMI<<8)) )

I was going to say something similar, but I think in the past Jan has said that Liang's original is more in line with the coding style.

No, my complaint here wouldn't be about coding style, but about the hard-coded 8 - it's not been that long ago that I replaced may of them, and I'd really like to see it replaced here too. Liang - can you please submit an incremental change (as the original one got committed already)? There should be several examples in VMX code on how the 8 can be avoided.

Jan

#4 lore raw
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

This would be easier to read as

if ( cpu_has_vmx_vnmi &&

     (idtv_info & INTR_INFO_INTR_TYPE_MASK) ==

(X86_EVENTTYPE_NMI<<8)) )

I was going to say something similar, but I think in the past Jan has said that Liang's original is more in line with the coding style.

Quoted 7 lines

No, my complaint here wouldn't be about coding style, but about the hard- coded 8 - it's not been that long ago that I replaced may of them, and I'd really like to see it replaced here too. Liang - can you please submit an incremental change (as the original one got committed already)? There should be several examples in VMX code on how the 8 can be avoided.

Jan

Of course, with pleasure.

Liang

Acked-by on v1 1/1
#5 lore raw
In reply to Liang Li
Quoted 11 lines

From: Li, Liang Z
Sent: Tuesday, April 07, 2015 9:27 PM

This bug will be trigged when NMI happen in the L2 guest. The current code handles the NMI incorrectly. According to Intel SDM 31.7.1.2 (Resuming Guest Software after Handling an Exception), If bit 31 of the IDT-vectoring information fields is set, and the virtual NMIs VM-execution control is 1, while bits 10:8 in the IDT-vectoring information field is 2, bit 3 in the interruptibility-state field should be cleared to avoid the next VM entry fail.

Quoted 1 line
Quoted 35 lines
---
 xen/arch/x86/hvm/vmx/vmx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +0 -0
index e1c55ce..b1f2df8 100644
@@ -2621,7 +2621,8 @@ static void vmx_idtv_reinject(unsigned long
 idtv_info)
          * Clear NMI-blocking interruptibility info if an NMI delivery

faulted.
* Re-delivery will re-set it (see SDM 3B 25.7.1.2). */
- if ( (idtv_info & INTR_INFO_INTR_TYPE_MASK) ==
(X86_EVENTTYPE_NMI<<8) )
+ if ( cpu_has_vmx_vnmi && ((idtv_info &
INTR_INFO_INTR_TYPE_MASK) ==

xen/arch/x86/hvm/vmx/vmx.c +2 -2
+                                 (X86_EVENTTYPE_NMI<<8)) )
         {
             unsigned long intr_info;
@@ -2772,8 +2773,7 @@ void vmx_vmexit_handler(struct cpu_user_regs
 *regs)
     hvm_maybe_deassert_evtchn_irq();
 
     __vmread(IDT_VECTORING_INFO, &idtv_info);
-    if ( !nestedhvm_vcpu_in_guestmode(v) &&
-         exit_reason != EXIT_REASON_TASK_SWITCH )
+    if ( exit_reason != EXIT_REASON_TASK_SWITCH )
         vmx_idtv_reinject(idtv_info);
 

switch ( exit_reason )
--
1.9.1