xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] Fix the mistake of exception execution
@ 2012-05-14 10:41 Hao, Xudong
  2012-05-14 11:06 ` Jan Beulich
  0 siblings, 1 reply; 8+ messages in thread
From: Hao, Xudong @ 2012-05-14 10:41 UTC (permalink / raw)
  To: Jan Beulich (JBeulich@suse.com), Keir Fraser (keir.xen@gmail.com)
  Cc: Aravindh Puthiyaparambil, Dong, Eddie, Zhang, Xiantao,
	Nakajima, Jun, xen-devel	(xen-devel@lists.xen.org)

Fix the mistake for debug exception(#DB), overflow exception(#OF; generated by INTO) and int 3(#BP) instruction emulation.

For INTn (CD ib), it should use type 4 (software interrupt).

For INT3 (CC; NOT CD ib with ib=3) and INTO (CE; NOT CD ib with ib=4), it should use type 6 (software exception).

For other exceptions (#DE, #DB, #BR, #UD, #NM, #TS, #NP, #SS, #GP, #PF, #MF, #AC, #MC, and #XM), it should use type 3 (hardware exception).
 
In the unlikely event that you are emulating the undocumented opcode F1 (informally called INT1 or ICEBP), it would use type 5 (privileged software exception).

Signed-off-by: Eddie Dong<eddie.dong@intel.com>
Signed-off-by: Xudong Hao <xudong.hao@intel.com>

diff -r cd4dd23a831d xen/arch/x86/hvm/vmx/vmx.c
--- a/xen/arch/x86/hvm/vmx/vmx.c	Fri May 11 18:59:07 2012 +0100
+++ b/xen/arch/x86/hvm/vmx/vmx.c	Wed May 15 02:31:34 2013 +0800
@@ -1350,6 +1350,19 @@ static void __vmx_inject_exception(int t
         curr->arch.hvm_vmx.vmx_emulate = 1;
 }
 
+/*
+ * Generate the virtual event to guest.
+ * NOTE: 
+ *    This is for processor execution generated exceptions,
+ * and INT 3(CC), INTO (CE) instruction emulation. It is
+ * not intended for the delivery of event due to emulation 
+ * of INT nn (CD nn) instruction, which should use 
+ * X86_EVENTTYPE_SW_INTERRUPT as interrupt type; opcode
+ * 0xf1 generated #DB should use privileged software
+ * exception, which is not deliverd here either.
+ *    The caller of this function should set correct instruction
+ * length.
+ */
 void vmx_inject_hw_exception(int trap, int error_code)
 {
     unsigned long intr_info;
@@ -1365,7 +1378,6 @@ void vmx_inject_hw_exception(int trap, i
     switch ( trap )
     {
     case TRAP_debug:
-        type = X86_EVENTTYPE_SW_EXCEPTION;
         if ( guest_cpu_user_regs()->eflags & X86_EFLAGS_TF )
         {
             __restore_debug_registers(curr);
@@ -1383,16 +1395,14 @@ void vmx_inject_hw_exception(int trap, i
             return;
         }
 
-        type = X86_EVENTTYPE_SW_EXCEPTION;
-        __vmwrite(VM_ENTRY_INSTRUCTION_LEN, 1); /* int3 */
-        break;
-
+        type = X86_EVENTTYPE_SW_EXCEPTION; /* int3; CC */
+        break;
+
+    case TRAP_overflow:
+        type = X86_EVENTTYPE_SW_EXCEPTION;  /* into; CE */
+        break;
+	
     default:
-        if ( trap > TRAP_last_reserved )
-        {
-            type = X86_EVENTTYPE_SW_EXCEPTION;
-            __vmwrite(VM_ENTRY_INSTRUCTION_LEN, 2); /* int imm8 */
-        }
         break;
     }
 
@@ -2447,6 +2457,11 @@ void vmx_vmexit_handler(struct cpu_user_
                 if ( handled < 0 ) 
                 {
                     vmx_inject_exception(TRAP_int3, HVM_DELIVER_NO_ERROR_CODE, 0);
+                    /*
+                     * According to the vmx_inject_hw_exception() description,
+                     * it must set correct instruction length by caller itself.
+                     */
+                    __vmwrite(VM_ENTRY_INSTRUCTION_LEN, 1); /* int3, CC */
                     break;
                 }
                 else if ( handled )

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

end of thread, other threads:[~2012-05-15  8:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-14 10:41 [PATCH v3] Fix the mistake of exception execution Hao, Xudong
2012-05-14 11:06 ` Jan Beulich
2012-05-15  5:59   ` Hao, Xudong
2012-05-15  6:48     ` Jan Beulich
2012-05-15  7:22       ` Aravindh Puthiyaparambil
2012-05-15  7:32         ` Jan Beulich
2012-05-15  8:14         ` Hao, Xudong
2012-05-15  8:19           ` Aravindh Puthiyaparambil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).