From patchwork Mon Dec 12 10:00:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9470333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3D9AE60476 for ; Mon, 12 Dec 2016 10:03:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3410228401 for ; Mon, 12 Dec 2016 10:03:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28CD928427; Mon, 12 Dec 2016 10:03:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9FD7928401 for ; Mon, 12 Dec 2016 10:03:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGNPn-0006OF-FZ; Mon, 12 Dec 2016 10:00:59 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGNPm-0006Nb-Hg for xen-devel@lists.xenproject.org; Mon, 12 Dec 2016 10:00:58 +0000 Received: from [85.158.139.211] by server-10.bemta-5.messagelabs.com id 95/8B-21400-9557E485; Mon, 12 Dec 2016 10:00:57 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrBIsWRWlGSWpSXmKPExsXS6fjDSzei1C/ CoHkuo8X3LZOZHBg9Dn+4whLAGMWamZeUX5HAmjFregdbwUm9ikfd75gaGE8pdjFycggJ5Ems u97ADmLzCthJXN3VD2ZLCBhKPH1/nQ3EZhFQlXixegIjiM0moC7R9mw7axcjB4eIgIHEuaNJI CazgL7EtnUsIBXCAhYS19e9YIGYbidxfv0NsE5OAXuJ332TWEDKeQUEJf7uEAYJMwOVvN56i3 0CI88shMwsJBkIW0vi4a9bLBC2tsSyha+ZZ4HtlZZY/o8DImwlsXjnTDZUJSC2q8SpsyfYFjB yrGLUKE4tKkst0jUy1ksqykzPKMlNzMzRNTQw1ctNLS5OTE/NSUwq1kvOz93ECAzVegYGxh2M O9r9DjFKcjApifL+8PaLEOJLyk+pzEgszogvKs1JLT7EqMHBIbBt1+oLjFIsefl5qUoSvFOKg eoEi1LTUyvSMnOA0QRTKsHBoyQCkeYtLkjMLc5Mh0idYlSUEue1KwFKCIAkMkrz4NpgEXyJUV ZKmJeRgYFBiKcgtSg3swRV/hWjOAejkjDvWpDxPJl5JXDTXwEtZgJa/HyfN8jikkSElFQDo43 gTquZ3rZXLhQaCntF3xC781p6rVFe+68iOX5b05KYpKV3O/JkZ4a7TPXNelCkcmf2+5uTf2x0 XTozie+lzFQZzSXV921Ll+no/Z++TqJjol24iee65GfXTBYL7bt7cxN3hgcP2/Q7GQeLj8fNO mvw5ND3c5tbtC/I+1ccfmZjJ3rs7o9HOUosxRmJhlrMRcWJAC1x3xLbAgAA X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-12.tower-206.messagelabs.com!1481536849!38608897!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 50664 invoked from network); 12 Dec 2016 10:00:52 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-12.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 12 Dec 2016 10:00:52 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Mon, 12 Dec 2016 03:00:52 -0700 Message-Id: <584E83600200007800127DD7@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.1 Date: Mon, 12 Dec 2016 03:00:48 -0700 From: "Jan Beulich" To: "xen-devel" References: <584E7E320200007800127D69@prv-mh.provo.novell.com> In-Reply-To: <584E7E320200007800127D69@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper Subject: [Xen-devel] [PATCH 3/3] x86emul: some REX related polishing X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP While there are a few cases where it seems better to open-code REX_* values, there's one where this clearly is a bad idea. And the SYSEXIT emulation has no need to look at REX at all, it can simply use op_bytes instead. Signed-off-by: Jan Beulich x86emul: some REX related polishing While there are a few cases where it seems better to open-code REX_* values, there's one where this clearly is a bad idea. And the SYSEXIT emulation has no need to look at REX at all, it can simply use op_bytes instead. Signed-off-by: Jan Beulich --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -3082,7 +3082,7 @@ x86_emulate( case 0x90: /* nop / xchg %%r8,%%rax */ case X86EMUL_OPC_F3(0, 0x90): /* pause / xchg %%r8,%%rax */ - if ( !(rex_prefix & 1) ) + if ( !(rex_prefix & REX_B) ) break; /* nop / pause */ /* fall through */ @@ -4897,7 +4897,6 @@ x86_emulate( case X86EMUL_OPC(0x0f, 0x35): /* sysexit */ { uint64_t msr_content; - bool user64 = rex_prefix & REX_W; generate_exception_if(!mode_ring0(), EXC_GP, 0); generate_exception_if(!in_protmode(ctxt, ops), EXC_GP, 0); @@ -4907,16 +4906,17 @@ x86_emulate( goto done; generate_exception_if(!(msr_content & 0xfffc), EXC_GP, 0); - generate_exception_if(user64 && (!is_canonical_address(_regs.edx) || - !is_canonical_address(_regs.ecx)), + generate_exception_if(op_bytes == 8 && + (!is_canonical_address(_regs.edx) || + !is_canonical_address(_regs.ecx)), EXC_GP, 0); cs.sel = (msr_content | 3) + /* SELECTOR_RPL_MASK */ - (user64 ? 32 : 16); + (op_bytes == 8 ? 32 : 16); cs.base = 0; /* flat segment */ cs.limit = ~0u; /* 4GB limit */ - cs.attr.bytes = user64 ? 0xafb /* L+DB+P+DPL3+S+Code */ - : 0xcfb; /* G+DB+P+DPL3+S+Code */ + cs.attr.bytes = op_bytes == 8 ? 0xafb /* L+DB+P+DPL3+S+Code */ + : 0xcfb; /* G+DB+P+DPL3+S+Code */ sreg.sel = cs.sel + 8; sreg.base = 0; /* flat segment */ @@ -4928,8 +4928,8 @@ x86_emulate( (rc = ops->write_segment(x86_seg_ss, &sreg, ctxt)) != 0 ) goto done; - _regs.eip = user64 ? _regs.edx : (uint32_t)_regs.edx; - _regs.esp = user64 ? _regs.ecx : (uint32_t)_regs.ecx; + _regs.eip = op_bytes == 8 ? _regs.edx : (uint32_t)_regs.edx; + _regs.esp = op_bytes == 8 ? _regs.ecx : (uint32_t)_regs.ecx; if ( _regs.eflags & EFLG_TF ) ctxt->retire.singlestep = true; Reviewed-by: Andrew Cooper --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -3082,7 +3082,7 @@ x86_emulate( case 0x90: /* nop / xchg %%r8,%%rax */ case X86EMUL_OPC_F3(0, 0x90): /* pause / xchg %%r8,%%rax */ - if ( !(rex_prefix & 1) ) + if ( !(rex_prefix & REX_B) ) break; /* nop / pause */ /* fall through */ @@ -4897,7 +4897,6 @@ x86_emulate( case X86EMUL_OPC(0x0f, 0x35): /* sysexit */ { uint64_t msr_content; - bool user64 = rex_prefix & REX_W; generate_exception_if(!mode_ring0(), EXC_GP, 0); generate_exception_if(!in_protmode(ctxt, ops), EXC_GP, 0); @@ -4907,16 +4906,17 @@ x86_emulate( goto done; generate_exception_if(!(msr_content & 0xfffc), EXC_GP, 0); - generate_exception_if(user64 && (!is_canonical_address(_regs.edx) || - !is_canonical_address(_regs.ecx)), + generate_exception_if(op_bytes == 8 && + (!is_canonical_address(_regs.edx) || + !is_canonical_address(_regs.ecx)), EXC_GP, 0); cs.sel = (msr_content | 3) + /* SELECTOR_RPL_MASK */ - (user64 ? 32 : 16); + (op_bytes == 8 ? 32 : 16); cs.base = 0; /* flat segment */ cs.limit = ~0u; /* 4GB limit */ - cs.attr.bytes = user64 ? 0xafb /* L+DB+P+DPL3+S+Code */ - : 0xcfb; /* G+DB+P+DPL3+S+Code */ + cs.attr.bytes = op_bytes == 8 ? 0xafb /* L+DB+P+DPL3+S+Code */ + : 0xcfb; /* G+DB+P+DPL3+S+Code */ sreg.sel = cs.sel + 8; sreg.base = 0; /* flat segment */ @@ -4928,8 +4928,8 @@ x86_emulate( (rc = ops->write_segment(x86_seg_ss, &sreg, ctxt)) != 0 ) goto done; - _regs.eip = user64 ? _regs.edx : (uint32_t)_regs.edx; - _regs.esp = user64 ? _regs.ecx : (uint32_t)_regs.ecx; + _regs.eip = op_bytes == 8 ? _regs.edx : (uint32_t)_regs.edx; + _regs.esp = op_bytes == 8 ? _regs.ecx : (uint32_t)_regs.ecx; if ( _regs.eflags & EFLG_TF ) ctxt->retire.singlestep = true;