From patchwork Wed Feb 17 16:36:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 8340991 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 033A49F38B for ; Wed, 17 Feb 2016 16:38:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 15048202EB for ; Wed, 17 Feb 2016 16:38:48 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1DFDB203C0 for ; Wed, 17 Feb 2016 16:38:46 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aW55f-0005en-Kc; Wed, 17 Feb 2016 16:36:35 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aW55d-0005eJ-IX for xen-devel@lists.xenproject.org; Wed, 17 Feb 2016 16:36:33 +0000 Received: from [193.109.254.147] by server-11.bemta-14.messagelabs.com id 97/32-28228-091A4C65; Wed, 17 Feb 2016 16:36:32 +0000 X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-6.tower-27.messagelabs.com!1455726990!24662390!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 8091 invoked from network); 17 Feb 2016 16:36:31 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-6.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 17 Feb 2016 16:36:31 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Wed, 17 Feb 2016 09:36:29 -0700 Message-Id: <56C4AF9D02000078000D3494@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Wed, 17 Feb 2016 09:36:29 -0700 From: "Jan Beulich" To: "xen-devel" References: <56C4AC2802000078000D3473@prv-mh.provo.novell.com> In-Reply-To: <56C4AC2802000078000D3473@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper , Keir Fraser Subject: [Xen-devel] [PATCH 3/5] x86emul: simplify IRET logic X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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 --- 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)) ) Reviewed-by: Andrew Cooper --- 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)) )