Skip to contentSkip to conversation

xen: Disable emulate.c REP optimization if introspection is active

PATCH Superseded Razvan Cojocaru 2 participants 2 messages Nov 3, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: Disable emulate.c REP optimization if introspection is active

Emulation for REP instructions is optimized to perform a single write for all repeats in the current page if possible. However, this interferes with a memory introspection application's ability to detect suspect behaviour, since it will cause only one mem_event to be sent per page touched.
This patch disables the optimization, gated on introspection being active for the domain.

---
 xen/arch/x86/hvm/emulate.c |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/emulate.c +10 -6
index c0f47d2..e53f390 100644
@@ -395,6 +395,7 @@ static int hvmemul_virtual_to_linear(
 {
     struct segment_register *reg;
     int okay;
+    struct domain *currd = current->domain;
 
     if ( seg == x86_seg_none )
     {
@@ -402,12 +403,15 @@ static int hvmemul_virtual_to_linear(
         return X86EMUL_OKAY;
     }
 
-    /*
-     * Clip repetitions to avoid overflow when multiplying by @bytes_per_rep.
-     * The chosen maximum is very conservative but it's what we use in
-     * hvmemul_linear_to_phys() so there is no point in using a larger value.
-     */
-    *reps = min_t(unsigned long, *reps, 4096);
+    if ( currd->arch.hvm_domain.introspection_enabled )
+        *reps = 1;
+    else
+        /*
+         * Clip repetitions to avoid overflow when multiplying by @bytes_per_rep.
+         * The chosen maximum is very conservative but it's what we use in
+         * hvmemul_linear_to_phys() so there is no point in using a larger value.
+         */
+        *reps = min_t(unsigned long, *reps, 4096);
 
     reg = hvmemul_get_seg_reg(seg, hvmemul_ctxt);
 
Signature · 1 line
1.7.9.5
#1 lore raw

xen/arch/x86/hvm/emulate.c static int hvmemul_virtual_to_linear( · line 398

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 03.11.14 at 10:39, <[email protected]> wrote:
xen/arch/x86/hvm/emulate.c +1 -0
@@ -395,6 +395,7 @@ static int hvmemul_virtual_to_linear(
 {
     struct segment_register *reg;
     int okay;
+    struct domain *currd = current->domain;

This is being used just once and hence not really worthwhile.

Quoted 9 lines
xen/arch/x86/hvm/emulate.c +0 -5
@@ -402,12 +403,15 @@ static int hvmemul_virtual_to_linear(
         return X86EMUL_OKAY;
     }
 
-    /*
-     * Clip repetitions to avoid overflow when multiplying by @bytes_per_rep.
-     * The chosen maximum is very conservative but it's what we use in
-     * hvmemul_linear_to_phys() so there is no point in using a larger value.
-     */

xen/arch/x86/hvm/emulate.c static int hvmemul_virtual_to_linear( · line 414

Quoted 10 lines
xen/arch/x86/hvm/emulate.c +9 -1
-    *reps = min_t(unsigned long, *reps, 4096);
+    if ( currd->arch.hvm_domain.introspection_enabled )
+        *reps = 1;
+    else
+        /*
+         * Clip repetitions to avoid overflow when multiplying by @bytes_per_rep.
+         * The chosen maximum is very conservative but it's what we use in
+         * hvmemul_linear_to_phys() so there is no point in using a larger value.
+         */
+        *reps = min_t(unsigned long, *reps, 4096);

With introspection_enabled supposedly being the unusual case (at least for the majority of current users), a likely()/unlikely() annotation should be used here. Further, with it being unclear (at least from patch description and context alone) whether *reps could legally be zero when getting here, I'd prefer

    *reps = min_t(unsigned long, *reps,
                  unlikely(current->domain->arch.hvm_domain.introspection_enabled)
                           ? 1 : 4096);

Perhaps with an adjustment to the comment explaining why.

Jan