[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] x86emul: check alignment of SSE and AVX memory operands



commit 6dc9ac9f52b8651b5700e24567fadd5b2b61786d
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Fri Sep 2 14:20:23 2016 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Fri Sep 2 14:20:23 2016 +0200

    x86emul: check alignment of SSE and AVX memory operands
    
    It only now occurred to me that there's no new hook needed to do so.
    Eliminate the two work item comments.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 xen/arch/x86/x86_emulate/x86_emulate.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c 
b/xen/arch/x86/x86_emulate/x86_emulate.c
index f27c6d5..197e56a 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -1419,6 +1419,25 @@ decode_segment(uint8_t modrm_reg)
     return decode_segment_failed;
 }
 
+static bool is_aligned(enum x86_segment seg, unsigned long offs,
+                       unsigned int size, struct x86_emulate_ctxt *ctxt,
+                       const struct x86_emulate_ops *ops)
+{
+    struct segment_register reg;
+
+    /* Expecting powers of two only. */
+    ASSERT(!(size & (size - 1)));
+
+    /* No alignment checking when we have no way to read segment data. */
+    if ( !ops->read_segment )
+        return true;
+
+    if ( ops->read_segment(seg, &reg, ctxt) != X86EMUL_OKAY )
+        return false;
+
+    return !((reg.base + offs) & (size - 1));
+}
+
 /* Inject a software interrupt/exception, emulating if needed. */
 static int inject_swint(enum x86_swint_type type,
                         uint8_t vector, uint8_t insn_len,
@@ -4178,10 +4197,10 @@ x86_emulate(
             ea.bytes = vex.pfx & VEX_PREFIX_DOUBLE_MASK ? 8 : 4;
         if ( ea.type == OP_MEM )
         {
-            /* XXX enable once there is ops->ea() or equivalent
             generate_exception_if((b >= 0x28) &&
-                                  (ops->ea(ea.mem.seg, ea.mem.off)
-                                   & (ea.bytes - 1)), EXC_GP, 0); */
+                                  !is_aligned(ea.mem.seg, ea.mem.off, ea.bytes,
+                                              ctxt, ops),
+                                  EXC_GP, 0);
             if ( !(b & 1) )
                 rc = ops->read(ea.mem.seg, ea.mem.off+0, mmvalp,
                                ea.bytes, ctxt);
@@ -4432,10 +4451,10 @@ x86_emulate(
         }
         if ( ea.type == OP_MEM )
         {
-            /* XXX enable once there is ops->ea() or equivalent
             generate_exception_if((vex.pfx == vex_66) &&
-                                  (ops->ea(ea.mem.seg, ea.mem.off)
-                                   & (ea.bytes - 1)), EXC_GP, 0); */
+                                  !is_aligned(ea.mem.seg, ea.mem.off, ea.bytes,
+                                              ctxt, ops),
+                                  EXC_GP, 0);
             if ( b == 0x6f )
                 rc = ops->read(ea.mem.seg, ea.mem.off+0, mmvalp,
                                ea.bytes, ctxt);
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.