Skip to contentSkip to conversation

xen/vm_event: Clean up control-register-write vm_events

PATCH Superseded Razvan Cojocaru 3 participants 9 messages May 12, 2015 – May 13, 2015

v1 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/vm_event: Clean up control-register-write vm_events

As suggested by Andrew Cooper, this patch attempts to remove some redundancy and allow for an easier time when adding vm_events for new control registers in the future, by having a single VM_EVENT_REASON_MOV_TO_CR vm_event type, meant to serve CR0, CR3 and CR4. The actual control register will be deduced by the new .index field in vm_event_write_ctrlreg (renamed from vm_event_mov_to_cr). The patch has also modified the xen-access.c test - it is now able to log CR3 events.

---
 tools/libxc/include/xenctrl.h       |    8 ++---
 tools/libxc/xc_monitor.c            |   39 +++--------------------
 tools/tests/xen-access/xen-access.c |   30 ++++++++++++++++--
 xen/arch/x86/hvm/event.c            |   50 +++++++----------------------
 xen/arch/x86/hvm/hvm.c              |    6 ++--
 xen/arch/x86/hvm/vmx/vmx.c          |    4 +--
 xen/arch/x86/monitor.c              |   60 ++++++++++++-----------------------
 xen/include/asm-x86/domain.h        |   20 ++++--------
 xen/include/asm-x86/hvm/event.h     |    4 +--
 xen/include/public/domctl.h         |   12 +++----
 xen/include/public/vm_event.h       |   27 +++++++++-------
 11 files changed, 100 insertions(+), 160 deletions(-)
tools/libxc/include/xenctrl.h +2 -6
index a689caf..7025027 100644
@@ -2355,12 +2355,8 @@ int xc_mem_access_disable_emulate(xc_interface *xch, domid_t domain_id);
 void *xc_monitor_enable(xc_interface *xch, domid_t domain_id, uint32_t *port);
 int xc_monitor_disable(xc_interface *xch, domid_t domain_id);
 int xc_monitor_resume(xc_interface *xch, domid_t domain_id);
-int xc_monitor_mov_to_cr0(xc_interface *xch, domid_t domain_id, bool enable,
-                          bool sync, bool onchangeonly);
-int xc_monitor_mov_to_cr3(xc_interface *xch, domid_t domain_id, bool enable,
-                          bool sync, bool onchangeonly);
-int xc_monitor_mov_to_cr4(xc_interface *xch, domid_t domain_id, bool enable,
-                          bool sync, bool onchangeonly);
+int xc_monitor_mov_to_cr(xc_interface *xch, domid_t domain_id, uint16_t index,
+                         bool enable, bool sync, bool onchangeonly);
 int xc_monitor_mov_to_msr(xc_interface *xch, domid_t domain_id, bool enable,
                           bool extended_capture);
 int xc_monitor_singlestep(xc_interface *xch, domid_t domain_id, bool enable);
tools/libxc/xc_monitor.c +4 -35
index 87ad968..8aba93f 100644
@@ -45,8 +45,8 @@ int xc_monitor_resume(xc_interface *xch, domid_t domain_id)
                                NULL);
 }
 
-int xc_monitor_mov_to_cr0(xc_interface *xch, domid_t domain_id, bool enable,
-                          bool sync, bool onchangeonly)
+int xc_monitor_mov_to_cr(xc_interface *xch, domid_t domain_id, uint16_t index,
+                         bool enable, bool sync, bool onchangeonly)
 {
     DECLARE_DOMCTL;
 
@@ -54,39 +54,8 @@ int xc_monitor_mov_to_cr0(xc_interface *xch, domid_t domain_id, bool enable,
     domctl.domain = domain_id;
     domctl.u.monitor_op.op = enable ? XEN_DOMCTL_MONITOR_OP_ENABLE
                                     : XEN_DOMCTL_MONITOR_OP_DISABLE;
-    domctl.u.monitor_op.event = XEN_DOMCTL_MONITOR_EVENT_MOV_TO_CR0;
-    domctl.u.monitor_op.u.mov_to_cr.sync = sync;
-    domctl.u.monitor_op.u.mov_to_cr.onchangeonly = onchangeonly;
-
-    return do_domctl(xch, &domctl);
-}
-
-int xc_monitor_mov_to_cr3(xc_interface *xch, domid_t domain_id, bool enable,
-                          bool sync, bool onchangeonly)
-{
-    DECLARE_DOMCTL;
-
-    domctl.cmd = XEN_DOMCTL_monitor_op;
-    domctl.domain = domain_id;
-    domctl.u.monitor_op.op = enable ? XEN_DOMCTL_MONITOR_OP_ENABLE
-                                    : XEN_DOMCTL_MONITOR_OP_DISABLE;
-    domctl.u.monitor_op.event = XEN_DOMCTL_MONITOR_EVENT_MOV_TO_CR3;
-    domctl.u.monitor_op.u.mov_to_cr.sync = sync;
-    domctl.u.monitor_op.u.mov_to_cr.onchangeonly = onchangeonly;
-
-    return do_domctl(xch, &domctl);
-}
-
-int xc_monitor_mov_to_cr4(xc_interface *xch, domid_t domain_id, bool enable,
-                          bool sync, bool onchangeonly)
-{
-    DECLARE_DOMCTL;
-
-    domctl.cmd = XEN_DOMCTL_monitor_op;
-    domctl.domain = domain_id;
-    domctl.u.monitor_op.op = enable ? XEN_DOMCTL_MONITOR_OP_ENABLE
-                                    : XEN_DOMCTL_MONITOR_OP_DISABLE;
-    domctl.u.monitor_op.event = XEN_DOMCTL_MONITOR_EVENT_MOV_TO_CR4;
+    domctl.u.monitor_op.event = XEN_DOMCTL_MONITOR_EVENT_MOV_TO_CR;
+    domctl.u.monitor_op.u.mov_to_cr.index = index;
     domctl.u.monitor_op.u.mov_to_cr.sync = sync;
     domctl.u.monitor_op.u.mov_to_cr.onchangeonly = onchangeonly;
 
tools/tests/xen-access/xen-access.c +28 -2
index 12ab921..c0b474b 100644
@@ -318,9 +318,9 @@ static void put_response(vm_event_t *vm_event, vm_event_response_t *rsp)
 void usage(char* progname)
 {
     fprintf(stderr,
-            "Usage: %s [-m] <domain_id> write|exec|breakpoint\n"
+            "Usage: %s [-m] <domain_id> write|exec|breakpoint|cr3\n"
             "\n"
-            "Logs first page writes, execs, or breakpoint traps that occur on the domain.\n"
+            "Logs first page writes, execs, CR3 writes or breakpoint traps that occur on the domain.\n"
             "\n"
             "-m requires this program to run, or else the domain may pause\n",
             progname);
@@ -341,6 +341,7 @@ int main(int argc, char *argv[])
     int required = 0;
     int breakpoint = 0;
     int shutting_down = 0;
+    int cr3 = 0;
 
     char* progname = argv[0];
     argv++;
@@ -383,6 +384,10 @@ int main(int argc, char *argv[])
     {
         breakpoint = 1;
     }
+    else if ( !strcmp(argv[0], "cr3") )
+    {
+        cr3 = 1;
+    }
     else
     {
         usage(argv[0]);
@@ -443,6 +448,16 @@ int main(int argc, char *argv[])
         }
     }
 
+    if ( cr3 )
+    {
+        rc = xc_monitor_mov_to_cr(xch, domain_id, X86_CR3, 1, 1, 1);
+        if ( rc < 0 )
+        {
+            ERROR("Error %d requesting CR3 monitoring with vm_event\n", rc);
+            goto exit;
+        }
+    }
+
     /* Wait for access */
     for (;;)
     {
@@ -455,6 +470,7 @@ int main(int argc, char *argv[])
             rc = xc_set_mem_access(xch, domain_id, XENMEM_access_rwx, START_PFN,
                                    (xenaccess->max_gpfn - START_PFN) );
             rc = xc_monitor_software_breakpoint(xch, domain_id, 0);
+            rc = xc_monitor_mov_to_cr(xch, domain_id, X86_CR3, 0, 0, 0);
 
             shutting_down = 1;
         }
@@ -546,6 +562,16 @@ int main(int argc, char *argv[])
                 }
 
                 break;
+            case VM_EVENT_REASON_MOV_TO_CR:
+                if ( req.u.write_ctrlreg.index == X86_CR3 )
+                    printf("CR3: old 0x%016lx new 0x%016lx\n",
+                        req.u.write_ctrlreg.new_value,
+                        req.u.write_ctrlreg.old_value);
+                else
+                    printf("Non-CR3 control register write event: 0x%08lx\n",
+                        req.u.write_ctrlreg.index);
+
+                break;
             default:
                 fprintf(stderr, "UNKNOWN REASON CODE %d\n", req.reason);
             }
xen/arch/x86/hvm/event.c +12 -38

67 lines not on this page · raw message

xen/arch/x86/hvm/hvm.c +3 -3
index 689e402..f1f20bc 100644
@@ -3267,7 +3267,7 @@ int hvm_set_cr0(unsigned long value)
         hvm_funcs.handle_cd(v, value);
 
     hvm_update_cr(v, 0, value);
-    hvm_event_cr0(value, old_value);
+    hvm_event_cr(X86_CR0, value, old_value);
 
     if ( (value ^ old_value) & X86_CR0_PG ) {
         if ( !nestedhvm_vmswitch_in_progress(v) && nestedhvm_vcpu_in_guestmode(v) )
@@ -3308,7 +3308,7 @@ int hvm_set_cr3(unsigned long value)
     old=v->arch.hvm_vcpu.guest_cr[3];
     v->arch.hvm_vcpu.guest_cr[3] = value;
     paging_update_cr3(v);
-    hvm_event_cr3(value, old);
+    hvm_event_cr(X86_CR3, value, old);
     return X86EMUL_OKAY;
 
  bad_cr3:
@@ -3349,7 +3349,7 @@ int hvm_set_cr4(unsigned long value)
     }
 
     hvm_update_cr(v, 4, value);
-    hvm_event_cr4(value, old_cr);
+    hvm_event_cr(X86_CR4, value, old_cr);
 
     /*
      * Modifying CR4.{PSE,PAE,PGE,SMEP}, or clearing CR4.PCIDE
xen/arch/x86/hvm/vmx/vmx.c +2 -2
index 74f563f..56651ce 100644
@@ -1262,7 +1262,7 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
                 v->arch.hvm_vmx.exec_control |= cr3_ctls;
 
             /* Trap CR3 updates if CR3 memory events are enabled. */
-            if ( v->domain->arch.monitor.mov_to_cr3_enabled )
+            if ( v->domain->arch.monitor.write_ctrlreg_enabled & X86_CR3 )
                 v->arch.hvm_vmx.exec_control |= CPU_BASED_CR3_LOAD_EXITING;
 
             vmx_update_cpu_exec_control(v);
@@ -2010,7 +2010,7 @@ static int vmx_cr_access(unsigned long exit_qualification)
         unsigned long old = curr->arch.hvm_vcpu.guest_cr[0];
         curr->arch.hvm_vcpu.guest_cr[0] &= ~X86_CR0_TS;
         vmx_update_guest_cr(curr, 0);
-        hvm_event_cr0(curr->arch.hvm_vcpu.guest_cr[0], old);
+        hvm_event_cr(X86_CR0, curr->arch.hvm_vcpu.guest_cr[0], old);
         HVMTRACE_0D(CLTS);
         break;
     }
xen/arch/x86/monitor.c +20 -40

79 lines not on this page · raw message

xen/include/asm-x86/domain.h +7 -13
index 45b5283..1dd49dd 100644
@@ -341,19 +341,13 @@ struct arch_domain
 
     /* Monitor options */
     struct {
-        uint16_t mov_to_cr0_enabled          : 1;
-        uint16_t mov_to_cr0_sync             : 1;
-        uint16_t mov_to_cr0_onchangeonly     : 1;
-        uint16_t mov_to_cr3_enabled          : 1;
-        uint16_t mov_to_cr3_sync             : 1;
-        uint16_t mov_to_cr3_onchangeonly     : 1;
-        uint16_t mov_to_cr4_enabled          : 1;
-        uint16_t mov_to_cr4_sync             : 1;
-        uint16_t mov_to_cr4_onchangeonly     : 1;
-        uint16_t mov_to_msr_enabled          : 1;
-        uint16_t mov_to_msr_extended         : 1;
-        uint16_t singlestep_enabled          : 1;
-        uint16_t software_breakpoint_enabled : 1;
+        uint32_t write_ctrlreg_enabled       : 8;
+        uint32_t write_ctrlreg_sync          : 8;
+        uint32_t write_ctrlreg_onchangeonly  : 8;
+        uint32_t mov_to_msr_enabled          : 1;
+        uint32_t mov_to_msr_extended         : 1;
+        uint32_t singlestep_enabled          : 1;
+        uint32_t software_breakpoint_enabled : 1;
     } monitor;
 
     /* Mem_access emulation control */
xen/include/asm-x86/hvm/event.h +1 -3
index bb757a1..7d327f4 100644
@@ -19,9 +19,7 @@
 #define __ASM_X86_HVM_EVENT_H__
 
 /* Called for current VCPU on crX/MSR changes by guest */
-void hvm_event_cr0(unsigned long value, unsigned long old);
-void hvm_event_cr3(unsigned long value, unsigned long old);
-void hvm_event_cr4(unsigned long value, unsigned long old);
+void hvm_event_cr(unsigned short index, unsigned long value, unsigned long old);
 void hvm_event_msr(unsigned int msr, uint64_t value);
 /* Called for current VCPU: returns -1 if no listener */
 int hvm_event_int3(unsigned long gla);
xen/include/public/domctl.h +6 -6
index 0c0ea4a..5bdc56f 100644
@@ -1034,12 +1034,10 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_psr_cmt_op_t);
 #define XEN_DOMCTL_MONITOR_OP_ENABLE   0
 #define XEN_DOMCTL_MONITOR_OP_DISABLE  1
 
-#define XEN_DOMCTL_MONITOR_EVENT_MOV_TO_CR0            0
-#define XEN_DOMCTL_MONITOR_EVENT_MOV_TO_CR3            1
-#define XEN_DOMCTL_MONITOR_EVENT_MOV_TO_CR4            2
-#define XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR            3
-#define XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP            4
-#define XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT   5
+#define XEN_DOMCTL_MONITOR_EVENT_MOV_TO_CR             0
+#define XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR            1
+#define XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP            2
+#define XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT   3
 
 struct xen_domctl_monitor_op {
     uint32_t op; /* XEN_DOMCTL_MONITOR_OP_* */
@@ -1050,6 +1048,8 @@ struct xen_domctl_monitor_op {
      */
     union {
         struct {
+            /* Which control register */
+            uint8_t index;
             /* Pause vCPU until response */
             uint8_t sync;
             /* Send event only on a change of value */
xen/include/public/vm_event.h +15 -12
index c7426de..3ae59be 100644
@@ -60,22 +60,24 @@
 #define VM_EVENT_REASON_MEM_SHARING             2
 /* Memory paging event */
 #define VM_EVENT_REASON_MEM_PAGING              3
-/* CR0 was updated */
-#define VM_EVENT_REASON_MOV_TO_CR0              4
-/* CR3 was updated */
-#define VM_EVENT_REASON_MOV_TO_CR3              5
-/* CR4 was updated */
-#define VM_EVENT_REASON_MOV_TO_CR4              6
+/* A control register was updated */
+#define VM_EVENT_REASON_MOV_TO_CR               4
 /* An MSR was updated. */
-#define VM_EVENT_REASON_MOV_TO_MSR              7
+#define VM_EVENT_REASON_MOV_TO_MSR              5
 /* Debug operation executed (e.g. int3) */
-#define VM_EVENT_REASON_SOFTWARE_BREAKPOINT     8
+#define VM_EVENT_REASON_SOFTWARE_BREAKPOINT     6
 /* Single-step (e.g. MTF) */
-#define VM_EVENT_REASON_SINGLESTEP              9
+#define VM_EVENT_REASON_SINGLESTEP              7
+
+/* Supported values for the vm_event_write_ctrlreg index. */
+#define X86_CR0     (1 << 0)
+#define X86_CR3     (1 << 1)
+#define X86_CR4     (1 << 2)
+#define X86_XCR0    (1 << 3)
 
 /*
  * Using a custom struct (not hvm_hw_cpu) so as to not fill
- * the mem_event ring buffer too quickly.
+ * the vm_event ring buffer too quickly.
  */
 struct vm_event_regs_x86 {
     uint64_t rax;
@@ -156,7 +158,8 @@ struct vm_event_mem_access {
     uint32_t _pad;
 };
 
-struct vm_event_mov_to_cr {
+struct vm_event_write_ctrlreg {
+    uint64_t index;
     uint64_t new_value;
     uint64_t old_value;
 };
@@ -196,7 +199,7 @@ typedef struct vm_event_st {
         struct vm_event_paging                mem_paging;
         struct vm_event_sharing               mem_sharing;
         struct vm_event_mem_access            mem_access;
-        struct vm_event_mov_to_cr             mov_to_cr;
+        struct vm_event_write_ctrlreg         write_ctrlreg;
         struct vm_event_mov_to_msr            mov_to_msr;
         struct vm_event_debug                 software_breakpoint;
         struct vm_event_debug                 singlestep;
Signature · 1 line
1.7.9.5
#1 lore raw

xen/include/public/vm_event.h line 76

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 12.05.15 at 16:58, <[email protected]> wrote:
xen/include/public/vm_event.h +5 -0
+/* Supported values for the vm_event_write_ctrlreg index. */
+#define X86_CR0     (1 << 0)
+#define X86_CR3     (1 << 1)
+#define X86_CR4     (1 << 2)
+#define X86_XCR0    (1 << 3)

These names, being put in the public interface, are way too generic.

Jan

#2 lore raw
Quoted 8 lines · Jan Beulich

xen/include/public/vm_event.h line 76

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 12.05.15 at 16:58, <[email protected]> wrote:
xen/include/public/vm_event.h +5 -0
+/* Supported values for the vm_event_write_ctrlreg index. */
+#define X86_CR0     (1 << 0)
+#define X86_CR3     (1 << 1)
+#define X86_CR4     (1 << 2)
+#define X86_XCR0    (1 << 3)

These names, being put in the public interface, are way too generic.

I've copied them from Andrew Cooper's suggestion in the previous thread, hopefully he'll chime in. I'm happy to rename / move them if so desired.

Thanks,
Razvan

#3 lore raw
Quoted 10 lines · Razvan Cojocaru
Quoted 7 lines · Jan Beulich

xen/include/public/vm_event.h line 76

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 12.05.15 at 16:58, <[email protected]> wrote:
xen/include/public/vm_event.h +5 -0
+/* Supported values for the vm_event_write_ctrlreg index. */
+#define X86_CR0     (1 << 0)
+#define X86_CR3     (1 << 1)
+#define X86_CR4     (1 << 2)
+#define X86_XCR0    (1 << 3)

These names, being put in the public interface, are way too generic.

I've copied them from Andrew Cooper's suggestion in the previous thread, hopefully he'll chime in. I'm happy to rename / move them if so desired.

I intended something like VM_EVENT_ARCH_X86_CR0 etc.

~Andrew

#4 lore raw
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Razvan Cojocaru
Quoted 7 lines · Jan Beulich

xen/include/public/vm_event.h line 76

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 12.05.15 at 16:58, <[email protected]> wrote:
xen/include/public/vm_event.h +5 -0
+/* Supported values for the vm_event_write_ctrlreg index. */
+#define X86_CR0     (1 << 0)
+#define X86_CR3     (1 << 1)
+#define X86_CR4     (1 << 2)
+#define X86_XCR0    (1 << 3)

These names, being put in the public interface, are way too generic.

Quoted 3 lines
Quoted 2 lines

I've copied them from Andrew Cooper's suggestion in the previous thread, hopefully he'll chime in. I'm happy to rename / move them if so desired.

I intended something like VM_EVENT_ARCH_X86_CR0 etc.

or perhaps slightly more specific to ctrl_reg read/write.

~Andrew

#5 lore raw
Quoted 10 lines · Andrew Cooper
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Razvan Cojocaru
Quoted 7 lines · Jan Beulich

xen/include/public/vm_event.h line 76

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 12.05.15 at 16:58, <[email protected]> wrote:
xen/include/public/vm_event.h +5 -0
+/* Supported values for the vm_event_write_ctrlreg index. */
+#define X86_CR0     (1 << 0)
+#define X86_CR3     (1 << 1)
+#define X86_CR4     (1 << 2)
+#define X86_XCR0    (1 << 3)

These names, being put in the public interface, are way too generic.

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

I've copied them from Andrew Cooper's suggestion in the previous thread, hopefully he'll chime in. I'm happy to rename / move them if so desired.

I intended something like VM_EVENT_ARCH_X86_CR0 etc.

or perhaps slightly more specific to ctrl_reg read/write.

VM_EVENT_ARCH_X86_MOV_TO_CR0? Or maybe VM_EVENT_WRITE_ARCH_X86_CR0?

There's something else that should also be clarified: I've renamed the vm_event.h struct to vm_event_write_ctrlreg, and changed monitor.mov_to_cr* to monitor.write_ctrlreg*, but left xc_monitor_mov_to_cr() in libxc, and mov_to_cr in the domctl part (I thought it fit with mov_to_msr(), etc.). Should I change that to write_ctrlreg as well? On the one hand, mov_to_cr seems to be consistent with the previous interface, and on the other it's not consistent with the name changes the patch has made.

Thanks,
Razvan

#6 lore raw
Quoted 11 lines · Razvan Cojocaru
Quoted 10 lines · Andrew Cooper
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Razvan Cojocaru
Quoted 7 lines · Jan Beulich

xen/include/public/vm_event.h line 76

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 12.05.15 at 16:58, <[email protected]> wrote:
xen/include/public/vm_event.h +5 -0
+/* Supported values for the vm_event_write_ctrlreg index. */
+#define X86_CR0     (1 << 0)
+#define X86_CR3     (1 << 1)
+#define X86_CR4     (1 << 2)
+#define X86_XCR0    (1 << 3)

These names, being put in the public interface, are way too generic.

Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

I've copied them from Andrew Cooper's suggestion in the previous thread, hopefully he'll chime in. I'm happy to rename / move them if so desired.

I intended something like VM_EVENT_ARCH_X86_CR0 etc.

or perhaps slightly more specific to ctrl_reg read/write.

VM_EVENT_ARCH_X86_MOV_TO_CR0? Or maybe VM_EVENT_WRITE_ARCH_X86_CR0?

Are there any other events which could plausibly use the same indicies? Monitoring ctrl_reg reads perhaps ?

Quoted 9 lines

There's something else that should also be clarified: I've renamed the vm_event.h struct to vm_event_write_ctrlreg, and changed monitor.mov_to_cr* to monitor.write_ctrlreg*, but left xc_monitor_mov_to_cr() in libxc, and mov_to_cr in the domctl part (I thought it fit with mov_to_msr(), etc.). Should I change that to write_ctrlreg as well? On the one hand, mov_to_cr seems to be consistent with the previous interface, and on the other it's not consistent with the name changes the patch has made.

Any API/ABI changes in this area are fine until 4.6 is released, and a consistent interface is much preferred.

~Andrew

#7 lore raw
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Razvan Cojocaru
Quoted 10 lines · Andrew Cooper
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Razvan Cojocaru
Quoted 7 lines · Jan Beulich

Review

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 12.05.15 at 16:58, <[email protected]> wrote:
(quoted diff) +5 -0
+/* Supported values for the vm_event_write_ctrlreg index. */
+#define X86_CR0     (1 << 0)
+#define X86_CR3     (1 << 1)
+#define X86_CR4     (1 << 2)
+#define X86_XCR0    (1 << 3)

These names, being put in the public interface, are way too generic.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

I've copied them from Andrew Cooper's suggestion in the previous thread, hopefully he'll chime in. I'm happy to rename / move them if so desired.

I intended something like VM_EVENT_ARCH_X86_CR0 etc.

or perhaps slightly more specific to ctrl_reg read/write.

VM_EVENT_ARCH_X86_MOV_TO_CR0? Or maybe VM_EVENT_WRITE_ARCH_X86_CR0?

Are there any other events which could plausibly use the same indicies? Monitoring ctrl_reg reads perhaps ?

I see what you mean, those could be reused for reads and result in less verbosity in the vm_event.h header.

I'll stick to VM_EVENT_ARCH_X86_CR0 and so on (unless requested otherwise), I don't have a better naming convention (I guess if we need to emphasize that something is being done to said control register we could call them VM_EVENT_ACCESS_ARCH_X86_CR0, but that's more verbose and IMHO not much better).

Quoted 11 lines
Quoted 8 lines

There's something else that should also be clarified: I've renamed the vm_event.h struct to vm_event_write_ctrlreg, and changed monitor.mov_to_cr* to monitor.write_ctrlreg*, but left xc_monitor_mov_to_cr() in libxc, and mov_to_cr in the domctl part (I thought it fit with mov_to_msr(), etc.). Should I change that to write_ctrlreg as well? On the one hand, mov_to_cr seems to be consistent with the previous interface, and on the other it's not consistent with the name changes the patch has made.

Any API/ABI changes in this area are fine until 4.6 is released, and a consistent interface is much preferred.

Understood. Then I'll rename xc_monitor_mov_to_cr() to xc_monitor_write_ctrlreg(), since vm_event_write_ctrlreg has been previously requested. I'll also rename XEN_DOMCTL_MONITOR_EVENT_MOV_TO_CR to XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG, and VM_EVENT_REASON_MOV_TO_CR to VM_EVENT_REASON_WRITE_CTRLREG.

I'm reading your reply to mean that I should also rename xc_monitor_mov_to_msr() to xc_monitor_write_msr(), and do similar things to the respective vm_event struct, VM_EVENT_REASON_MOV_TO_MSR and so on. Is that correct?

Thanks,
Razvan

#8 lore raw
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 12.05.15 at 20:38, <[email protected]> wrote:
Quoted 18 lines · Andrew Cooper
Quoted 16 lines · Razvan Cojocaru
Quoted 10 lines · Andrew Cooper
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Razvan Cojocaru
Quoted 7 lines · Jan Beulich

Review

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 12.05.15 at 16:58, <[email protected]> wrote:
(quoted diff) +5 -0
+/* Supported values for the vm_event_write_ctrlreg index. */
+#define X86_CR0     (1 << 0)
+#define X86_CR3     (1 << 1)
+#define X86_CR4     (1 << 2)
+#define X86_XCR0    (1 << 3)

These names, being put in the public interface, are way too generic.

Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

I've copied them from Andrew Cooper's suggestion in the previous thread, hopefully he'll chime in. I'm happy to rename / move them if so desired.

I intended something like VM_EVENT_ARCH_X86_CR0 etc.

or perhaps slightly more specific to ctrl_reg read/write.

VM_EVENT_ARCH_X86_MOV_TO_CR0? Or maybe VM_EVENT_WRITE_ARCH_X86_CR0?

Quoted 8 lines
Quoted 2 lines

Are there any other events which could plausibly use the same indicies? Monitoring ctrl_reg reads perhaps ?

I see what you mean, those could be reused for reads and result in less verbosity in the vm_event.h header.

I'll stick to VM_EVENT_ARCH_X86_CR0 and so on (unless requested otherwise),

Yes - I'd say this one, or even with the _ARCH part dropped.

Jan