From patchwork Thu Sep 8 13:44:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9321415 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 5D5BE60752 for ; Thu, 8 Sep 2016 13:46:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F04A2980E for ; Thu, 8 Sep 2016 13:46:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43D8A2988B; Thu, 8 Sep 2016 13:46:06 +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 BAA2B2980E for ; Thu, 8 Sep 2016 13:46:05 +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 1bhzce-00052b-PL; Thu, 08 Sep 2016 13:44:08 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhzcd-00052F-CO for xen-devel@lists.xenproject.org; Thu, 08 Sep 2016 13:44:07 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id 4D/5E-11175-62B61D75; Thu, 08 Sep 2016 13:44:06 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrNIsWRWlGSWpSXmKPExsXS6fjDS1c1+2K 4wYydFhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8br9gvsBX/VKia0z2NqYJwr28XIySEkkCfR uPEbM4jNK2An0f7oAJgtIWAo8fT9dTYQm0VAVeJS52VWEJtNQF2i7dl2IJuDQ0TAQOLc0SQQk 1lAX2LbOhaQCmEBM4nvb7oYIabbSSxZcBgszilgLzFlyRNGkHJeAUGJvzuEQcLMQCVTu3awTG DkmYWQmYUkA2FrSTz8dQvK1pZYtvA18yywvdISy/9xQISNJE4+PYpFia3Egj67BYwcqxg1ilO LylKLdA2N9JKKMtMzSnITM3N0DQ3M9HJTi4sT01NzEpOK9ZLzczcxAgOVAQh2MF7eGHCIUZKD SUmU16f4QrgQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd4rmRfDhQSLUtNTK9Iyc4AxA5OW4OBRE uFlzAJK8xYXJOYWZ6ZDpE4xKkqJ8yqAJARAEhmleXBtsDi9xCgrJczLCHSIEE9BalFuZgmq/C tGcQ5GJWFeXZApPJl5JXDTXwEtZgJaLHTqPMjikkSElFQD4+HLEbu45q2yU2ddOPlRyZU++6n M2Ws+a864qmT+f9nCZdptG7bfWdCuvmvLRp0Ff2bpNYbdn60RdcHO7OUhvu5VCt2Ru/g2Fn2v lrjwQPtkyOn47qOmqzcKii1SLGfrianTuqmYlTmJwYa3Vzvw4aU1Gw9pXti63/y7gaLGuvvpR Z6z8p5tzFZiKc5INNRiLipOBABCTlv0zgIAAA== X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-8.tower-27.messagelabs.com!1473342244!47949778!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 42797 invoked from network); 8 Sep 2016 13:44:05 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-8.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 8 Sep 2016 13:44:05 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Thu, 08 Sep 2016 07:44:03 -0600 Message-Id: <57D18744020000780010D26C@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.1 Date: Thu, 08 Sep 2016 07:44:04 -0600 From: "Jan Beulich" To: "xen-devel" References: <57D18589020000780010D251@prv-mh.provo.novell.com> In-Reply-To: <57D18589020000780010D251@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper Subject: [Xen-devel] [PATCH 3/5] x86emul: support RTM instructions 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 Minimal emulation: XBEGIN aborts right away, hence - XABORT is just a no-op, - XEND always raises #GP, - XTEST always signals neither RTM nor HLE are active. Signed-off-by: Jan Beulich x86emul: support RTM instructions Minimal emulation: XBEGIN aborts right away, hence - XABORT is just a no-op, - XEND always raises #GP, - XTEST always signals neither RTM nor HLE are active. Signed-off-by: Jan Beulich --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -1172,6 +1172,8 @@ static bool_t vcpu_has( #define vcpu_has_clflush() vcpu_has( 1, EDX, 19, ctxt, ops) #define vcpu_has_lzcnt() vcpu_has(0x80000001, ECX, 5, ctxt, ops) #define vcpu_has_bmi1() vcpu_has(0x00000007, EBX, 3, ctxt, ops) +#define vcpu_has_hle() vcpu_has(0x00000007, EBX, 4, ctxt, ops) +#define vcpu_has_rtm() vcpu_has(0x00000007, EBX, 11, ctxt, ops) #define vcpu_must_have(leaf, reg, bit) \ generate_exception_if(!vcpu_has(leaf, reg, bit, ctxt, ops), EXC_UD, -1) @@ -2852,7 +2854,18 @@ x86_emulate( lock_prefix = 1; break; - case 0xc6 ... 0xc7: /* mov (sole member of Grp11) */ + case 0xc6: /* Grp11: mov / xabort */ + case 0xc7: /* Grp11: mov / xbegin */ + if ( modrm == 0xf8 && vcpu_has_rtm() ) + { + if ( b & 1 ) + { + jmp_rel((int32_t)src.val); + _regs.eax = 0; + } + dst.type = OP_NONE; + break; + } generate_exception_if((modrm_reg & 7) != 0, EXC_UD, -1); case 0x88 ... 0x8b: /* mov */ case 0xa0 ... 0xa1: /* mov mem.offs,{%al,%ax,%eax,%rax} */ @@ -4246,6 +4259,17 @@ x86_emulate( goto done; goto no_writeback; + case 0xd5: /* xend */ + generate_exception_if(vcpu_has_rtm() && !vex.pfx, EXC_GP, 0); + break; + + case 0xd6: /* xtest */ + if ( (!vcpu_has_rtm() && !vcpu_has_hle()) || vex.pfx ) + break; + /* Neither HLE nor RTM can be active when we get here. */ + _regs.eflags |= EFLG_ZF; + goto no_writeback; + case 0xdf: /* invlpga */ generate_exception_if(!in_protmode(ctxt, ops), EXC_UD, -1); generate_exception_if(!mode_ring0(), EXC_GP, 0); --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -1172,6 +1172,8 @@ static bool_t vcpu_has( #define vcpu_has_clflush() vcpu_has( 1, EDX, 19, ctxt, ops) #define vcpu_has_lzcnt() vcpu_has(0x80000001, ECX, 5, ctxt, ops) #define vcpu_has_bmi1() vcpu_has(0x00000007, EBX, 3, ctxt, ops) +#define vcpu_has_hle() vcpu_has(0x00000007, EBX, 4, ctxt, ops) +#define vcpu_has_rtm() vcpu_has(0x00000007, EBX, 11, ctxt, ops) #define vcpu_must_have(leaf, reg, bit) \ generate_exception_if(!vcpu_has(leaf, reg, bit, ctxt, ops), EXC_UD, -1) @@ -2852,7 +2854,18 @@ x86_emulate( lock_prefix = 1; break; - case 0xc6 ... 0xc7: /* mov (sole member of Grp11) */ + case 0xc6: /* Grp11: mov / xabort */ + case 0xc7: /* Grp11: mov / xbegin */ + if ( modrm == 0xf8 && vcpu_has_rtm() ) + { + if ( b & 1 ) + { + jmp_rel((int32_t)src.val); + _regs.eax = 0; + } + dst.type = OP_NONE; + break; + } generate_exception_if((modrm_reg & 7) != 0, EXC_UD, -1); case 0x88 ... 0x8b: /* mov */ case 0xa0 ... 0xa1: /* mov mem.offs,{%al,%ax,%eax,%rax} */ @@ -4246,6 +4259,17 @@ x86_emulate( goto done; goto no_writeback; + case 0xd5: /* xend */ + generate_exception_if(vcpu_has_rtm() && !vex.pfx, EXC_GP, 0); + break; + + case 0xd6: /* xtest */ + if ( (!vcpu_has_rtm() && !vcpu_has_hle()) || vex.pfx ) + break; + /* Neither HLE nor RTM can be active when we get here. */ + _regs.eflags |= EFLG_ZF; + goto no_writeback; + case 0xdf: /* invlpga */ generate_exception_if(!in_protmode(ctxt, ops), EXC_UD, -1); generate_exception_if(!mode_ring0(), EXC_GP, 0);