fine grained control of REP emulation optimizations
authorRazvan Cojocaru <rcojocaru@bitdefender.com>
Mon, 28 Sep 2015 15:29:45 +0000 (17:29 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 28 Sep 2015 15:29:45 +0000 (17:29 +0200)
Previously, if vm_event emulation support was enabled, then REP
optimizations were disabled when emulating REP-compatible
instructions. This patch allows fine-tuning of this behaviour by
providing a dedicated libxc helper function.

Signed-off-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
tools/libxc/include/xenctrl.h
tools/libxc/xc_monitor.c
xen/arch/x86/hvm/emulate.c
xen/arch/x86/monitor.c
xen/arch/x86/vm_event.c
xen/include/asm-x86/domain.h
xen/include/public/domctl.h

index 34825443d89d3aabb6e5f3a08506d665433b8759..3bfa00b5540df1aaa5a4f3a642290f01dc4f8f70 100644 (file)
@@ -2428,6 +2428,18 @@ int xc_monitor_software_breakpoint(xc_interface *xch, domid_t domain_id,
 int xc_monitor_guest_request(xc_interface *xch, domid_t domain_id,
                              bool enable, bool sync);
 
+/**
+ * This function enables / disables emulation for each REP for a
+ * REP-compatible instruction.
+ *
+ * @parm xch a handle to an open hypervisor interface.
+ * @parm domain_id the domain id one wants to get the node affinity of.
+ * @parm enable if 0 optimize when possible, else emulate each REP.
+ * @return 0 on success, -1 on failure.
+ */
+int xc_monitor_emulate_each_rep(xc_interface *xch, domid_t domain_id,
+                                bool enable);
+
 /***
  * Memory sharing operations.
  *
index 065669cbbb3c137e896854f39f40c15424447de5..b1705ddfd1dfb16b8ab7ba95088462aa71902eb9 100644 (file)
@@ -143,3 +143,16 @@ int xc_monitor_guest_request(xc_interface *xch, domid_t domain_id, bool enable,
 
     return do_domctl(xch, &domctl);
 }
+
+int xc_monitor_emulate_each_rep(xc_interface *xch, domid_t domain_id,
+                                bool enable)
+{
+    DECLARE_DOMCTL;
+
+    domctl.cmd = XEN_DOMCTL_monitor_op;
+    domctl.domain = domain_id;
+    domctl.u.monitor_op.op = XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP;
+    domctl.u.monitor_op.event = enable;
+
+    return do_domctl(xch, &domctl);
+}
index 5934c72e656d28aa3cc79adabadaceacc6506f0f..39774b77163b01f2842c69f99d3ba858a4bb9d83 100644 (file)
@@ -514,7 +514,7 @@ static int hvmemul_virtual_to_linear(
      * being triggered for repeated writes to a whole page.
      */
     *reps = min_t(unsigned long, *reps,
-                  unlikely(current->domain->arch.mem_access_emulate_enabled)
+                  unlikely(current->domain->arch.mem_access_emulate_each_rep)
                            ? 1 : 4096);
 
     reg = hvmemul_get_seg_reg(seg, hvmemul_ctxt);
index 3d521352d716366c25bfc8435c0b97e138a0ff5a..7611f7b9150a69c7e6d9348c023dadb883b16c80 100644 (file)
@@ -73,10 +73,15 @@ int monitor_domctl(struct domain *d, struct xen_domctl_monitor_op *mop)
     if ( rc )
         return rc;
 
-    if ( mop->op == XEN_DOMCTL_MONITOR_OP_GET_CAPABILITIES )
+    switch ( mop->op )
     {
+    case XEN_DOMCTL_MONITOR_OP_GET_CAPABILITIES:
         mop->event = capabilities;
         return 0;
+
+    case XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP:
+        d->arch.mem_access_emulate_each_rep = !!mop->event;
+        return 0;
     }
 
     /*
index e4e0aa4365ac1f08f2fcae9af85c9c98cc7adab0..c38d37b45d886aee50df525755f2a8b4ffcf2983 100644 (file)
@@ -54,6 +54,8 @@ void vm_event_cleanup_domain(struct domain *d)
         xfree(v->arch.vm_event);
         v->arch.vm_event = NULL;
     }
+
+    d->arch.mem_access_emulate_each_rep = 0;
 }
 
 void vm_event_toggle_singlestep(struct domain *d, struct vcpu *v)
index f0aeade198c1f24a11d505aa5d4e203dcad92f96..f1d7ed61e4650bd809da4709cd7ae99e4778f2e2 100644 (file)
@@ -386,6 +386,7 @@ struct arch_domain
 
     /* Mem_access emulation control */
     bool_t mem_access_emulate_enabled;
+    bool_t mem_access_emulate_each_rep;
 } __cacheline_aligned;
 
 #define has_arch_pdevs(d)    (!list_empty(&(d)->arch.pdev_list))
index 794d4d53f048380ed0f3910cdf110d5caccbf9e0..ae241f2597aeb15cc8c4ddbbd06ae0512c04fed9 100644 (file)
@@ -1007,6 +1007,7 @@ 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_OP_GET_CAPABILITIES  2
+#define XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP  3
 
 #define XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG         0
 #define XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR            1