Skip to contentSkip to conversation

vmx: Restore debug registers when injecting #DB traps

PATCH Superseded Ross Lagerwall 2 participants 2 messages Mar 11, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vmx: Restore debug registers when injecting #DB traps

Commit a929bee0e652 ("x86/vmx: Fix injection of #DB traps following XSA-156") prevents an infinite loop in certain #DB traps. However, it changed the behavior to not call hvm_hw_inject_trap() for #DB and #AC traps which which means that the debug registers are not restored correctly and nullified commit b56ae5b48c38 ("VMX: fix/adjust trap injection").

To fix this, restore the original code path through hvm_inject_trap(), but ensure that the struct hvm_trap is populated with all the required data.

---
 xen/arch/x86/hvm/vmx/vmx.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +12 -13
index 9c5a388..1eddba5 100644
@@ -3091,24 +3091,23 @@ static int vmx_handle_eoi_write(void)
  * It is the callers responsibility to ensure that this function is only used
  * in the context of an appropriate vmexit.
  */
-static void vmx_propagate_intr(void)
+static void vmx_propagate_intr(unsigned long intr)
 {
-    unsigned long intr, tmp;
-
-    __vmread(VM_EXIT_INTR_INFO, &intr);
-
-    ASSERT(intr & INTR_INFO_VALID_MASK);
-
-    __vmwrite(VM_ENTRY_INTR_INFO, intr);
+    struct hvm_trap trap = {
+        .vector = intr & INTR_INFO_VECTOR_MASK,
+        .type = MASK_EXTR(intr, INTR_INFO_INTR_TYPE_MASK) };
+    unsigned long tmp;
 
     if ( intr & INTR_INFO_DELIVER_CODE_MASK )
     {
         __vmread(VM_EXIT_INTR_ERROR_CODE, &tmp);
-        __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, tmp);
+        trap.error_code = tmp;
     }
-
+    else
+        trap.error_code = HVM_DELIVER_NO_ERROR_CODE;
     __vmread(VM_EXIT_INSTRUCTION_LEN, &tmp);
-    __vmwrite(VM_ENTRY_INSTRUCTION_LEN, tmp);
+    trap.insn_len = tmp;
+    hvm_inject_trap(&trap);
 }
 
 static void vmx_idtv_reinject(unsigned long idtv_info)
@@ -3366,7 +3365,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
             HVMTRACE_1D(TRAP_DEBUG, exit_qualification);
             write_debugreg(6, exit_qualification | DR_STATUS_RESERVED_ONE);
             if ( !v->domain->debugger_attached )
-                vmx_propagate_intr();
+                vmx_propagate_intr(intr_info);
             else
                 domain_pause_for_debugger();
             break;
@@ -3437,7 +3436,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
             break;
         case TRAP_alignment_check:
             HVMTRACE_1D(TRAP, vector);
-            vmx_propagate_intr();
+            vmx_propagate_intr(intr_info);
             break;
         case TRAP_nmi:
             if ( MASK_EXTR(intr_info, INTR_INFO_INTR_TYPE_MASK) !=
Signature · 7 lines
2.4.3


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 11.03.16 at 15:51, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -3091,24 +3091,23 @@ static int vmx_handle_eoi_write(void)
  * It is the callers responsibility to ensure that this function is only used
  * in the context of an appropriate vmexit.
  */
-static void vmx_propagate_intr(void)
+static void vmx_propagate_intr(unsigned long intr)
 {

xen/arch/x86/hvm/vmx/vmx.c static int vmx_handle_eoi_write(void) · line 3098

Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -7
-    unsigned long intr, tmp;
-
-    __vmread(VM_EXIT_INTR_INFO, &intr);
-
-    ASSERT(intr & INTR_INFO_VALID_MASK);
-
-    __vmwrite(VM_ENTRY_INTR_INFO, intr);
+    struct hvm_trap trap = {
+        .vector = intr & INTR_INFO_VECTOR_MASK,
+        .type = MASK_EXTR(intr, INTR_INFO_INTR_TYPE_MASK) };

Please use MASK_EXTR() for both. Also the closing brace would better go on the next line.

Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +1 -0
+    unsigned long tmp;
 
     if ( intr & INTR_INFO_DELIVER_CODE_MASK )
     {

xen/arch/x86/hvm/vmx/vmx.c static int vmx_handle_eoi_write(void) · line 3109

Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +4 -3
         __vmread(VM_EXIT_INTR_ERROR_CODE, &tmp);
-        __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, tmp);
+        trap.error_code = tmp;
     }
-
+    else
+        trap.error_code = HVM_DELIVER_NO_ERROR_CODE;
     __vmread(VM_EXIT_INSTRUCTION_LEN, &tmp);
-    __vmwrite(VM_ENTRY_INSTRUCTION_LEN, tmp);
+    trap.insn_len = tmp;

For this one I was unsure already for the original change (but it had gone in already by the time I got to see it): The VM-exit instruction length field is undefined (i.e. not necessarily zero) for the #AC intercept case, and also for some (most) of the #DB ones. I therefore think this needs some qualification, with zero getting used otherwise.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel