Skip to contentSkip to conversation

hvm/svm: Implement Debug events

PATCH Superseded Alexandru Isaila 3 participants 6 messages Mar 21, 2018

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 hvm/svm: Implement Debug events

At this moment the Debug events for the AMD architecture are not forwarded to the monitor layer.

This patch adds the Debug event to the common capabilities, adds the VMEXIT_ICEBP then forwards the event to the monitor layer.

Chapter 2: SVM Processor and Platform Extensions: "Note: A vector 1 exception generated by the single byte INT1
instruction (also known as ICEBP) does not trigger the #DB intercept. Software should use the dedicated ICEBP intercept to intercept ICEBP"

---
Changes since V2:
- Moved INSTR_ICEBP entry in opc_tab
- Added mechanism to enable/disable icebp interception
- Changed trap_type to unsigned int
- Replaced svm_propagate_intr with hvm_inject_exception

---
 xen/arch/x86/hvm/svm/emulate.c        |  1 +
 xen/arch/x86/hvm/svm/svm.c            | 71 +++++++++++++++++++++++++++--------
 xen/arch/x86/monitor.c                |  6 +++
 xen/include/asm-x86/hvm/hvm.h         | 36 ++++++++++++++++++
 xen/include/asm-x86/hvm/svm/emulate.h |  1 +
 xen/include/asm-x86/monitor.h         |  4 +-
 6 files changed, 101 insertions(+), 18 deletions(-)
xen/arch/x86/hvm/svm/emulate.c +1 -0
index e1a1581..535674e 100644
@@ -65,6 +65,7 @@ static const struct {
 } opc_tab[INSTR_MAX_COUNT] = {
     [INSTR_PAUSE]   = { X86EMUL_OPC_F3(0, 0x90) },
     [INSTR_INT3]    = { X86EMUL_OPC(   0, 0xcc) },
+    [INSTR_ICEBP]   = { X86EMUL_OPC(   0, 0xf1) },
     [INSTR_HLT]     = { X86EMUL_OPC(   0, 0xf4) },
     [INSTR_XSETBV]  = { X86EMUL_OPC(0x0f, 0x01), MODRM(3, 2, 1) },
     [INSTR_VMRUN]   = { X86EMUL_OPC(0x0f, 0x01), MODRM(3, 3, 0) },
xen/arch/x86/hvm/svm/svm.c +55 -16

109 lines not on this page · raw message

xen/arch/x86/monitor.c +6 -0
index 4317658..3b3af4b 100644
@@ -288,6 +288,12 @@ int arch_monitor_domctl_event(struct domain *d,
         ad->monitor.debug_exception_sync = requested_status ?
                                             mop->u.debug_exception.sync :
                                             0;
+
+        if ( requested_status )
+            hvm_enable_icebp_interception(d);
+        else
+            hvm_disable_icebp_interception(d);
+
         domain_unpause(d);
         break;
     }
xen/include/asm-x86/hvm/hvm.h +36 -0
index 2376ed6..8d8c325 100644
@@ -209,6 +209,8 @@ struct hvm_function_table {
                                 bool_t access_w, bool_t access_x);
 
     void (*enable_msr_interception)(struct domain *d, uint32_t msr);
+    void (*enable_icebp_interception)(struct domain *d);
+    void (*disable_icebp_interception)(struct domain *d);
     bool_t (*is_singlestep_supported)(void);
 
     /* Alternate p2m */
@@ -407,6 +409,20 @@ void hvm_migrate_pirqs(struct vcpu *v);
 
 void hvm_inject_event(const struct x86_event *event);
 
+static inline void hvm_inject_exception(
+    unsigned int vector, unsigned int type,
+    unsigned int insn_len,int error_code)
+{
+    struct x86_event event = {
+        .vector = vector,
+        .type = type,
+        .insn_len = insn_len,
+        .error_code = error_code,
+    };
+
+    hvm_inject_event(&event);
+}
+
 static inline void hvm_inject_hw_exception(unsigned int vector, int errcode)
 {
     struct x86_event event = {
@@ -581,6 +597,26 @@ static inline bool_t hvm_enable_msr_interception(struct domain *d, uint32_t msr)
     return 0;
 }
 
+static inline bool_t hvm_enable_icebp_interception(struct domain *d)
+{
+    if( hvm_funcs.enable_icebp_interception )
+    {
+        hvm_funcs.enable_icebp_interception(d);
+        return 1;
+    }
+    return 0;
+}
+
+static inline bool_t hvm_disable_icebp_interception(struct domain *d)
+{
+    if( hvm_funcs.disable_icebp_interception )
+    {
+        hvm_funcs.disable_icebp_interception(d);
+        return 1;
+    }
+    return 0;
+}
+
 static inline bool_t hvm_is_singlestep_supported(void)
 {
     return (hvm_funcs.is_singlestep_supported &&
xen/include/asm-x86/hvm/svm/emulate.h +1 -0
index 7c1dcd1..3de8236 100644
@@ -38,6 +38,7 @@ enum instruction_index {
     INSTR_STGI,
     INSTR_CLGI,
     INSTR_INVLPGA,
+    INSTR_ICEBP,
     INSTR_MAX_COUNT /* Must be last - Number of instructions supported */
 };
 
xen/include/asm-x86/monitor.h +2 -2
index 99ed4b87..c5a86d1 100644
@@ -82,12 +82,12 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
                     (1U << XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) |
+                    (1U << XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) |
                     (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG));
 
     if ( cpu_has_vmx )
     {
-        capabilities |= ((1U << XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) |
-                         (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED));
+        capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED);
 
         /* Since we know this is on VMX, we can just call the hvm func */
         if ( hvm_is_singlestep_supported() )
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 14 lines · Alexandru Isaila
xen/include/asm-x86/hvm/hvm.h +2 -0
index 2376ed6..8d8c325 100644
@@ -209,6 +209,8 @@ struct hvm_function_table {
                                 bool_t access_w, bool_t access_x);
 
     void (*enable_msr_interception)(struct domain *d, uint32_t msr);
+    void (*enable_icebp_interception)(struct domain *d);
+    void (*disable_icebp_interception)(struct domain *d);
     bool_t (*is_singlestep_supported)(void);
 
     /* Alternate p2m */

xen/include/asm-x86/hvm/hvm.h void hvm_migrate_pirqs(struct vcpu *v); · line 414

Quoted 6 lines
xen/include/asm-x86/hvm/hvm.h +3 -0
@@ -407,6 +409,20 @@ void hvm_migrate_pirqs(struct vcpu *v);
 
 void hvm_inject_event(const struct x86_event *event);
 
+static inline void hvm_inject_exception(
+    unsigned int vector, unsigned int type,
+    unsigned int insn_len,int error_code)

Space after comma.

Quoted 15 lines
xen/include/asm-x86/hvm/hvm.h +11 -0
+{
+    struct x86_event event = {
+        .vector = vector,
+        .type = type,
+        .insn_len = insn_len,
+        .error_code = error_code,
+    };
+
+    hvm_inject_event(&event);
+}
+
 static inline void hvm_inject_hw_exception(unsigned int vector, int errcode)
 {
     struct x86_event event = {

xen/include/asm-x86/hvm/hvm.h static inline bool_t hvm_enable_msr_interception(struct domain *d, uint32_t msr) · line 600

Quoted 4 lines
xen/include/asm-x86/hvm/hvm.h +1 -0
@@ -581,6 +597,26 @@ static inline bool_t hvm_enable_msr_interception(struct domain *d, uint32_t msr)
     return 0;
 }
 
+static inline bool_t hvm_enable_icebp_interception(struct domain *d)

bool.

Both can be fixed on commit, and everything else looks ok, so

I've got a plan which will remove these enable/disable hooks, but we need a bit more infrastructure from my CPUID series before they can go.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
In reply to Alexandru Isaila

xen/include/asm-x86/hvm/hvm.h struct hvm_function_table { · line 213

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 15:47, <[email protected]> wrote:
xen/include/asm-x86/hvm/hvm.h +2 -0
@@ -209,6 +209,8 @@ struct hvm_function_table {
                                 bool_t access_w, bool_t access_x);
 
     void (*enable_msr_interception)(struct domain *d, uint32_t msr);
+    void (*enable_icebp_interception)(struct domain *d);
+    void (*disable_icebp_interception)(struct domain *d);

Why two new hooks when one (with a boolean parameter) would do?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines · On 21.03.18 at 15:47, <[email protected]> wrote:
xen/include/asm-x86/hvm/hvm.h +0 -0
@@ -209,6 +209,8 @@ struct hvm_function_table {
                                 bool_t access_w, bool_t access_x);
 
Quoted 9 lines

xen/include/asm-x86/hvm/hvm.h struct hvm_function_table { · line 213

Quoted 4 lines
xen/include/asm-x86/hvm/hvm.h +2 -0
     void (*enable_msr_interception)(struct domain *d, uint32_t
 msr);
+    void (*enable_icebp_interception)(struct domain *d);
+    void (*disable_icebp_interception)(struct domain *d);

Why two new hooks when one (with a boolean parameter) would do?

Jan

I'll merge them in one with a bool parameter

Alex

________________________
This email was scanned by Bitdefender
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
In reply to Jan Beulich
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines · On 21.03.18 at 15:47, <[email protected]> wrote:
xen/include/asm-x86/hvm/hvm.h +0 -0
@@ -209,6 +209,8 @@ struct hvm_function_table {
                                 bool_t access_w, bool_t access_x);
 
Quoted 10 lines

xen/include/asm-x86/hvm/hvm.h struct hvm_function_table { · line 213

Quoted 4 lines
xen/include/asm-x86/hvm/hvm.h +2 -0
     void (*enable_msr_interception)(struct domain *d, uint32_t
 msr);
+    void (*enable_icebp_interception)(struct domain *d);
+    void (*disable_icebp_interception)(struct domain *d);

Why two new hooks when one (with a boolean parameter) would do?

Jan

Would update_icebp_interception() be a suitable name for the hook?

Thanks,
Alex

________________________
This email was scanned by Bitdefender
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 21.03.18 at 17:00, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines · On 21.03.18 at 15:47, <[email protected]> wrote:
xen/include/asm-x86/hvm/hvm.h +0 -0
@@ -209,6 +209,8 @@ struct hvm_function_table {
                                 bool_t access_w, bool_t access_x);
 
Quoted 8 lines
Quoted 7 lines

xen/include/asm-x86/hvm/hvm.h struct hvm_function_table { · line 213

Quoted 4 lines
xen/include/asm-x86/hvm/hvm.h +2 -0
     void (*enable_msr_interception)(struct domain *d, uint32_t
 msr);
+    void (*enable_icebp_interception)(struct domain *d);
+    void (*disable_icebp_interception)(struct domain *d);

Why two new hooks when one (with a boolean parameter) would do?

Would update_icebp_interception() be a suitable name for the hook?

"update" or "set" would both seem fine to me.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel