diff mbox

[v2] x86emul: {L, S}{G, I}DT ignore operand size overrides in 64-bit mode

Message ID 581B4C61020000780011BF8D@prv-mh.provo.novell.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Beulich Nov. 3, 2016, 1:40 p.m. UTC
This affects not only the layout of the data (always 2+8 bytes), but
also the contents (no truncation to 24 bits occurs).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-acked-by: Wei Liu <wei.liu2@citrix.com>
x86emul: {L,S}{G,I}DT ignore operand size overrides in 64-bit mode

This affects not only the layout of the data (always 2+8 bytes), but
also the contents (no truncation to 24 bits occurs).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-acked-by: Wei Liu <wei.liu2@citrix.com>

--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -4424,12 +4424,17 @@ x86_emulate(
             fail_if(ops->read_segment == NULL);
             if ( (rc = ops->read_segment(seg, &sreg, ctxt)) )
                 goto done;
-            if ( op_bytes == 2 )
+            if ( mode_64bit() )
+                op_bytes = 8;
+            else if ( op_bytes == 2 )
+            {
                 sreg.base &= 0xffffff;
-            if ( (rc = ops->write(ea.mem.seg, ea.mem.off+0,
-                                  &sreg.limit, 2, ctxt)) ||
-                 (rc = ops->write(ea.mem.seg, ea.mem.off+2,
-                                  &sreg.base, mode_64bit() ? 8 : 4, ctxt)) )
+                op_bytes = 4;
+            }
+            if ( (rc = ops->write(ea.mem.seg, ea.mem.off, &sreg.limit,
+                                  2, ctxt)) != X86EMUL_OKAY ||
+                 (rc = ops->write(ea.mem.seg, ea.mem.off + 2, &sreg.base,
+                                  op_bytes, ctxt)) != X86EMUL_OKAY )
                 goto done;
             break;
         case 2: /* lgdt */
@@ -4446,7 +4451,7 @@ x86_emulate(
             generate_exception_if(!is_canonical_address(base), EXC_GP, 0);
             sreg.base = base;
             sreg.limit = limit;
-            if ( op_bytes == 2 )
+            if ( !mode_64bit() && op_bytes == 2 )
                 sreg.base &= 0xffffff;
             if ( (rc = ops->write_segment(seg, &sreg, ctxt)) )
                 goto done;
diff mbox

Patch

--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -4424,12 +4424,17 @@  x86_emulate(
             fail_if(ops->read_segment == NULL);
             if ( (rc = ops->read_segment(seg, &sreg, ctxt)) )
                 goto done;
-            if ( op_bytes == 2 )
+            if ( mode_64bit() )
+                op_bytes = 8;
+            else if ( op_bytes == 2 )
+            {
                 sreg.base &= 0xffffff;
-            if ( (rc = ops->write(ea.mem.seg, ea.mem.off+0,
-                                  &sreg.limit, 2, ctxt)) ||
-                 (rc = ops->write(ea.mem.seg, ea.mem.off+2,
-                                  &sreg.base, mode_64bit() ? 8 : 4, ctxt)) )
+                op_bytes = 4;
+            }
+            if ( (rc = ops->write(ea.mem.seg, ea.mem.off, &sreg.limit,
+                                  2, ctxt)) != X86EMUL_OKAY ||
+                 (rc = ops->write(ea.mem.seg, ea.mem.off + 2, &sreg.base,
+                                  op_bytes, ctxt)) != X86EMUL_OKAY )
                 goto done;
             break;
         case 2: /* lgdt */
@@ -4446,7 +4451,7 @@  x86_emulate(
             generate_exception_if(!is_canonical_address(base), EXC_GP, 0);
             sreg.base = base;
             sreg.limit = limit;
-            if ( op_bytes == 2 )
+            if ( !mode_64bit() && op_bytes == 2 )
                 sreg.base &= 0xffffff;
             if ( (rc = ops->write_segment(seg, &sreg, ctxt)) )
                 goto done;