diff mbox

[3/5] x86emul: simplify IRET logic

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

Commit Message

Jan Beulich Feb. 17, 2016, 4:36 p.m. UTC
Since we only handle real mode, we need to consider neither non-ring0
nor IOPL. Also for POPF the mode_iopl() check can really be inside the
not-ring-0 body.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
x86emul: simplify IRET logic

Since we only handle real mode, we need to consider neither non-ring0
nor IOPL. Also for POPF the mode_iopl() check can really be inside the
not-ring-0 body.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -2490,9 +2490,11 @@ x86_emulate(
     case 0x9d: /* popf */ {
         uint32_t mask = EFLG_VIP | EFLG_VIF | EFLG_VM;
         if ( !mode_ring0() )
+        {
             mask |= EFLG_IOPL;
-        if ( !mode_iopl() )
-            mask |= EFLG_IF;
+            if ( !mode_iopl() )
+                mask |= EFLG_IF;
+        }
         /* 64-bit mode: POP defaults to a 64-bit operand. */
         if ( mode_64bit() && (op_bytes == 4) )
             op_bytes = 8;
@@ -2814,10 +2816,7 @@ x86_emulate(
     case 0xcf: /* iret */ {
         unsigned long sel, eip, eflags;
         uint32_t mask = EFLG_VIP | EFLG_VIF | EFLG_VM;
-        if ( !mode_ring0() )
-            mask |= EFLG_IOPL;
-        if ( !mode_iopl() )
-            mask |= EFLG_IF;
+
         fail_if(!in_realmode(ctxt, ops));
         if ( (rc = read_ulong(x86_seg_ss, sp_post_inc(op_bytes),
                               &eip, op_bytes, ctxt, ops)) ||
@@ -2830,7 +2829,7 @@ x86_emulate(
             eflags = (uint16_t)eflags | (_regs.eflags & 0xffff0000u);
         eflags &= 0x257fd5;
         _regs.eflags &= mask;
-        _regs.eflags |= (uint32_t)(eflags & ~mask) | 0x02;
+        _regs.eflags |= (eflags & ~mask) | 0x02;
         _regs.eip = eip;
         if ( (rc = load_seg(x86_seg_cs, sel, 1, &cs, ctxt, ops)) ||
              (rc = commit_far_branch(&cs, eip)) )

Comments

Andrew Cooper Feb. 17, 2016, 6:03 p.m. UTC | #1
On 17/02/16 16:36, Jan Beulich wrote:
> Since we only handle real mode, we need to consider neither non-ring0
> nor IOPL. Also for POPF the mode_iopl() check can really be inside the
> not-ring-0 body.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
diff mbox

Patch

--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -2490,9 +2490,11 @@  x86_emulate(
     case 0x9d: /* popf */ {
         uint32_t mask = EFLG_VIP | EFLG_VIF | EFLG_VM;
         if ( !mode_ring0() )
+        {
             mask |= EFLG_IOPL;
-        if ( !mode_iopl() )
-            mask |= EFLG_IF;
+            if ( !mode_iopl() )
+                mask |= EFLG_IF;
+        }
         /* 64-bit mode: POP defaults to a 64-bit operand. */
         if ( mode_64bit() && (op_bytes == 4) )
             op_bytes = 8;
@@ -2814,10 +2816,7 @@  x86_emulate(
     case 0xcf: /* iret */ {
         unsigned long sel, eip, eflags;
         uint32_t mask = EFLG_VIP | EFLG_VIF | EFLG_VM;
-        if ( !mode_ring0() )
-            mask |= EFLG_IOPL;
-        if ( !mode_iopl() )
-            mask |= EFLG_IF;
+
         fail_if(!in_realmode(ctxt, ops));
         if ( (rc = read_ulong(x86_seg_ss, sp_post_inc(op_bytes),
                               &eip, op_bytes, ctxt, ops)) ||
@@ -2830,7 +2829,7 @@  x86_emulate(
             eflags = (uint16_t)eflags | (_regs.eflags & 0xffff0000u);
         eflags &= 0x257fd5;
         _regs.eflags &= mask;
-        _regs.eflags |= (uint32_t)(eflags & ~mask) | 0x02;
+        _regs.eflags |= (eflags & ~mask) | 0x02;
         _regs.eip = eip;
         if ( (rc = load_seg(x86_seg_cs, sel, 1, &cs, ctxt, ops)) ||
              (rc = commit_far_branch(&cs, eip)) )