xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Xudong Hao <xudong.hao@intel.com>
To: JBeulich@suse.com, keir.xen@gmail.com
Cc: aravindh@virtuata.com, eddie.dong@intel.com,
	xen-devel@lists.xen.org, Xudong Hao <xudong.hao@intel.com>,
	Ian.Jackson@eu.citrix.com,
	Xiantao Zhang <xiantao.zhang@intel.com>
Subject: [PATCH v2 2/4] VMX: Fix the mistake of exception execution
Date: Wed, 30 May 2012 10:35:46 +0800	[thread overview]
Message-ID: <1338345347-22433-3-git-send-email-xudong.hao@intel.com> (raw)
In-Reply-To: <1338345347-22433-1-git-send-email-xudong.hao@intel.com>

Fix the mistake for debug exception(#DB), overflow exception(#OF) and
INT3(#BP), INTn instruction emulation.

Add inslen field in struct hvm_trap. According to instruction length,
to distinguish INT3 is generated by opcode 'CC' or 'CD ib =3',
so do INTO and #DB(debug exception).

Note:
 * 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: Xudong Hao <xudong.hao@intel.com>
Signed-off-by: Eddie Dong <eddie.dong@intel.com>
Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
---
 xen/arch/x86/hvm/vmx/vmx.c    |   43 ++++++++++++++++++++++++++++++++++++++++-
 xen/include/asm-x86/hvm/hvm.h |    2 +
 2 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index c96d18b..cf08a11 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -1381,6 +1381,19 @@ void vmx_inject_nmi(void)
                            HVM_DELIVER_NO_ERROR_CODE);
 }
 
+/*
+ * Generate the virtual event to guest.
+ * NOTE:
+ *    This is for processor execution generated exceptions,
+ * and handle #DB hardware exception and all software 
+ * exception/interrupt, which include:
+ *  - INT 3(CC), INTO (CE) instruction emulation, which should
+ *    use X86_EVENTTYPE_SW_EXCEPTION;
+ *  - INT nn (CD nn) instruction emulation, which should use
+ *    X86_EVENTTYPE_SW_INTERRUPT as interrupt type;
+ *  - opcode 0xf1 generated #DB should use privileged software
+ *    exception.
+ */
 static void vmx_inject_trap(struct hvm_trap *trap)
 {
     unsigned long intr_info;
@@ -1399,6 +1412,12 @@ static void vmx_inject_trap(struct hvm_trap *trap)
     switch ( _trap.vector )
     {
     case TRAP_debug:
+        _trap.type = X86_EVENTTYPE_HW_EXCEPTION;
+        if ( _trap.inslen != 1 ) {
+            _trap.type = X86_EVENTTYPE_PRI_SW_EXCEPTION;  /* opcode 0xf1 */
+            __vmwrite(VM_ENTRY_INSTRUCTION_LEN, _trap.inslen);
+        }
+
         if ( guest_cpu_user_regs()->eflags & X86_EFLAGS_TF )
         {
             __restore_debug_registers(curr);
@@ -1414,6 +1433,27 @@ static void vmx_inject_trap(struct hvm_trap *trap)
             domain_pause_for_debugger();
             return;
         }
+        _trap.type = X86_EVENTTYPE_SW_EXCEPTION;  /* CC */
+        if ( _trap.inslen != 1 )
+            _trap.type = X86_EVENTTYPE_SW_INTERRUPT;  /* CD ib with ib=3 */
+        __vmwrite(VM_ENTRY_INSTRUCTION_LEN, _trap.inslen);
+        break;
+
+    case TRAP_overflow:
+        _trap.type = X86_EVENTTYPE_SW_EXCEPTION;  /* CE */
+        if ( _trap.inslen != 1 )
+            _trap.type = X86_EVENTTYPE_SW_INTERRUPT;  /* CD ib with ib=4 */
+        __vmwrite(VM_ENTRY_INSTRUCTION_LEN, _trap.inslen);
+        break;
+
+    default:
+        if ( _trap.vector > TRAP_last_reserved ) /* int imm8 */
+        {
+            _trap.type = X86_EVENTTYPE_SW_INTERRUPT;
+            __vmwrite(VM_ENTRY_INSTRUCTION_LEN, _trap.inslen);
+        }
+        break;
+
     }
 
     if ( unlikely(intr_info & INTR_INFO_VALID_MASK) &&
@@ -2424,7 +2464,8 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
                     struct hvm_trap trap = {
                         .vector = TRAP_int3,
                         .type = X86_EVENTTYPE_SW_EXCEPTION,
-                        .error_code = HVM_DELIVER_NO_ERROR_CODE
+                        .error_code = HVM_DELIVER_NO_ERROR_CODE,
+                        .inslen = __vmread(VM_EXIT_INSTRUCTION_LEN)
                     };
                     hvm_inject_trap(&trap);
                     break;
diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h
index 65f7e20..a3d8bf1 100644
--- a/xen/include/asm-x86/hvm/hvm.h
+++ b/xen/include/asm-x86/hvm/hvm.h
@@ -76,6 +76,7 @@ struct hvm_trap {
     unsigned int  type;         /* X86_EVENTTYPE_* */
     int           error_code;   /* HVM_DELIVER_NO_ERROR_CODE if n/a */
     unsigned long cr2;          /* Only for TRAP_page_fault h/w exception */
+    int           inslen;       /* Instruction length */ 
 };
 
 /*
@@ -375,6 +376,7 @@ static inline int hvm_do_pmu_interrupt(struct cpu_user_regs *regs)
 #define X86_EVENTTYPE_NMI                   2    /* NMI                */
 #define X86_EVENTTYPE_HW_EXCEPTION          3    /* hardware exception */
 #define X86_EVENTTYPE_SW_INTERRUPT          4    /* software interrupt */
+#define X86_EVENTTYPE_PRI_SW_EXCEPTION      5    /* privileged software exception */
 #define X86_EVENTTYPE_SW_EXCEPTION          6    /* software exception */
 
 int hvm_event_needs_reinjection(uint8_t type, uint8_t vector);
-- 
1.5.5

  parent reply	other threads:[~2012-05-30  2:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-30  2:35 [PATCH v2 0/4] XEN: fix vmx exception mistake Xudong Hao
2012-05-30  2:35 ` [PATCH v2 1/4] xen: Define new struct hvm_trap and cleanup vmx exception Xudong Hao
2012-05-30  2:35 ` Xudong Hao [this message]
2012-05-30  9:18   ` [PATCH v2 2/4] VMX: Fix the mistake of exception execution Jan Beulich
2012-05-30 11:24     ` Hao, Xudong
2012-05-30  2:35 ` [PATCH v2 3/4] xen: Add instruction length parameter in hypercall HVMOP_inject_trap Xudong Hao
2012-05-30  9:19   ` Jan Beulich
2012-05-30 10:40 ` [PATCH v2 0/4] XEN: fix vmx exception mistake Keir Fraser
2012-05-30 11:16   ` Hao, Xudong
2012-05-30 12:21     ` Keir Fraser
2012-05-31  2:00       ` Hao, Xudong
2012-05-31 23:21         ` Aravindh Puthiyaparambil
2012-06-01  0:46           ` Hao, Xudong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1338345347-22433-3-git-send-email-xudong.hao@intel.com \
    --to=xudong.hao@intel.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=JBeulich@suse.com \
    --cc=aravindh@virtuata.com \
    --cc=eddie.dong@intel.com \
    --cc=keir.xen@gmail.com \
    --cc=xen-devel@lists.xen.org \
    --cc=xiantao.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).