From patchwork Mon Aug 1 23:19:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Mihai_Don=C8=9Bu?= X-Patchwork-Id: 9254941 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 320FF6077C for ; Mon, 1 Aug 2016 23:21:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B45027F17 for ; Mon, 1 Aug 2016 23:21:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F9B3284D5; Mon, 1 Aug 2016 23:21:50 +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 6A56827F17 for ; Mon, 1 Aug 2016 23:21:49 +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 1bUMUZ-0006U6-GC; Mon, 01 Aug 2016 23:19:27 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bUMUY-0006Tx-0A for xen-devel@lists.xen.org; Mon, 01 Aug 2016 23:19:26 +0000 Received: from [193.109.254.147] by server-3.bemta-14.messagelabs.com id 2F/95-29440-DF8DF975; Mon, 01 Aug 2016 23:19:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPIsWRWlGSWpSXmKPExsUSfTxjoe6fG/P DDdZPk7JY8nExiwOjx9Hdv5kCGKNYM/OS8isSWDPe/ZzBXPBZtmLRswMsDYy3RLoYOTmEBNwl +tZOYuxi5AKy1zBKHHr0gA0icY1R4tUPHgjbTeLgtjvsEEXTGSX+HF8PVsQioCIx484vVhCbT cBS4syGw0wgtoiAskTvr98sIDYzUPOljXPAbGGBGImuxhVg9bwCphKXt85lBLE5Bewl7s+aA9 TLAbQgT2LHeUcQk19AUmLZOkGIakGJkzOfsICEmQXUJdbPE4IYri2xbOFrZhBbQiBH4tLrF6w gJRICUhL/W5VADpYQ6GWRuPzqGTtEjYzEo4k32SYwis5CMnUWwtRZSKYuYGRexahRnFpUllqk a2Sml1SUmZ5RkpuYmaNraGiil5taXJyYnpqTmFSsl5yfu4kRGBH1DAyMOxj7L/sdYpTkYFIS5 fVsmh8uxJeUn1KZkVicEV9UmpNafIhRhoNDSYL30nWgnGBRanpqRVpmDjA2YdISHDxKIrw/QN K8xQWJucWZ6RCpU4yKUuK8i0ASAiCJjNI8uDZYOrjEKCslzMvIwMAgxFOQWpSbWYIq/4pRnIN RSZj3JcgUnsy8Erjpr4AWMwEtTrSfA7K4JBEhJdXAWN9r1LA2z+quybGpl2ctd9MJ9gj9IvYm VLrqC/PyLYsDy9t8PDY/4ovb4FHidiDAxTOHM2Va5BKzZarrfD93Pj0Qvr6BNXlC4wWpRWYrb rjeTKkQkxK4c4XXfa5hcJa56coDfOaTF9hO3BG05Nuu+reiik2zRNeHJvcfkDz8o8Bmx8rl6T W1SizFGYmGWsxFxYkAkuxdEwIDAAA= X-Env-Sender: mdontu@bitdefender.com X-Msg-Ref: server-15.tower-27.messagelabs.com!1470093563!1985922!1 X-Originating-IP: [91.199.104.161] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6638 invoked from network); 1 Aug 2016 23:19:24 -0000 Received: from mx01.bbu.dsd.mx.bitdefender.com (HELO mx01.bbu.dsd.mx.bitdefender.com) (91.199.104.161) by server-15.tower-27.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 1 Aug 2016 23:19:24 -0000 Received: (qmail 20890 invoked from network); 2 Aug 2016 02:19:22 +0300 Received: from unknown (HELO mx-sr.buh.bitdefender.com) (10.17.80.103) by mx01.bbu.dsd.mx.bitdefender.com with AES256-GCM-SHA384 encrypted SMTP; 2 Aug 2016 02:19:22 +0300 Received: from smtp02.buh.bitdefender.net (smtp.bitdefender.biz [10.17.80.76]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id 3C8A77FBFB for ; Tue, 2 Aug 2016 02:19:21 +0300 (EEST) Received: (qmail 3381 invoked from network); 2 Aug 2016 02:19:21 +0300 Received: from unknown (HELO bitdefender.com) (mdontu@bitdefender.com@10.20.65.13) by smtp02.buh.bitdefender.net with SMTP; 2 Aug 2016 02:19:21 +0300 Date: Tue, 2 Aug 2016 02:19:20 +0300 From: Mihai =?UTF-8?B?RG9uyJt1?= To: Jan Beulich Message-ID: <20160802021920.3772b070@bitdefender.com> In-Reply-To: <579F689802000078001014EC@prv-mh.provo.novell.com> References: <20160801025231.7211-1-mdontu@bitdefender.com> <579F689802000078001014EC@prv-mh.provo.novell.com> Organization: Bitdefender MIME-Version: 1.0 X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.6 on smtp02.buh.bitdefender.net, sigver: 7.66626 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.6.911, Dats: 429617, Stamp: 3], Multi: [Enabled, t: (0.000020, 0.003964)], BW: [Enabled, t: (0.000008,0.000004)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.003456), Flags: 85D2ED72; NN_LEGIT_VALID_REPLY; NN_LEGIT_SUMM_400_WORDS; NN_NO_LINK_NMD; NN_LEGIT_BITDEFENDER; NN_LEGIT_S_SQARE_BRACKETS], SGN: [Enabled, t: (0.023570)], URL: [Enabled, t: (0.000005)], RTDA: [Enabled, t: (0.012961), Hit: No, Details: v2.3.10; Id: 2m1ghk0.1aofv2j7u.17b2h], total: 0(775) X-BitDefender-CF-Stamp: none Cc: Andrew Cooper , xen-devel@lists.xen.org Subject: Re: [Xen-devel] [PATCH v3 1/3] x86/emulate: add support for {, v}movq xmm, xmm/m64 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 On Monday 01 August 2016 07:19:51 Jan Beulich wrote: > >>> On 01.08.16 at 04:52, wrote: > > @@ -4412,6 +4412,7 @@ x86_emulate( > > case 0x7f: /* movq mm,mm/m64 */ > > /* {,v}movdq{a,u} xmm,xmm/m128 */ > > /* vmovdq{a,u} ymm,ymm/m256 */ > > + case 0xd6: /* {,v}movq xmm,xmm/m64 */ > > { > > uint8_t *buf = get_stub(stub); > > struct fpu_insn_ctxt fic = { .insn_bytes = 5 }; > > @@ -4429,9 +4430,9 @@ x86_emulate( > > case vex_66: > > case vex_f3: > > host_and_vcpu_must_have(sse2); > > - buf[0] = 0x66; /* movdqa */ > > + buf[0] = 0x66; /* SSE */ > > The comment change here indicates a problem: So far it was indicating > that despite the possible F3 prefix (movdqu) we encode a 66 one > (movdqa). Opcode D6 prefixed with F3, however, is movq2dq, which > you then either don't emulate correctly, or if it happens to be > emulated correctly you should include in the comment accompanying > the case label. And its AVX counterpart should then produce #UD. I fiddled with this for a while and the attached patch (adjusted) appears to be doing the right thing: ie. movq2dq gets emulated correctly too. copy_REX_VEX() does not work OK with movq2dq, but it looked easy to single out this case. All tests pass, including for {,v}movq xmm/m64 and movq2dq. There does not appear to be an AVX variant for the latter, or I'm not reading the Intel SDM right (or binutils' as is lying to me). diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c index fe594ba..d6c199b 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -245,7 +245,7 @@ static uint8_t twobyte_table[256] = { ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, /* 0xD0 - 0xDF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, ImplicitOps|ModRM, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xE0 - 0xEF */ 0, 0, 0, 0, 0, 0, 0, ImplicitOps|ModRM, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xF0 - 0xFF */ @@ -4412,6 +4412,8 @@ x86_emulate( case 0x7f: /* movq mm,mm/m64 */ /* {,v}movdq{a,u} xmm,xmm/m128 */ /* vmovdq{a,u} ymm,ymm/m256 */ + case 0xd6: /* {,v}movq xmm,xmm/m64 */ + /* movq2dq mm,xmm */ { uint8_t *buf = get_stub(stub); struct fpu_insn_ctxt fic = { .insn_bytes = 5 }; @@ -4431,7 +4433,7 @@ x86_emulate( host_and_vcpu_must_have(sse2); buf[0] = 0x66; /* movdqa */ get_fpu(X86EMUL_FPU_xmm, &fic); - ea.bytes = 16; + ea.bytes = (b == 0xd6 ? 8 : 16); break; case vex_none: if ( b != 0xe7 ) @@ -4451,7 +4453,7 @@ x86_emulate( ((vex.pfx != vex_66) && (vex.pfx != vex_f3))); host_and_vcpu_must_have(avx); get_fpu(X86EMUL_FPU_ymm, &fic); - ea.bytes = 16 << vex.l; + ea.bytes = (b == 0xd6 ? 8 : (16 << vex.l)); } if ( ea.type == OP_MEM ) { @@ -4469,7 +4471,11 @@ x86_emulate( } if ( !rc ) { - copy_REX_VEX(buf, rex_prefix, vex); + /* try to preserve the mandatory prefix for movq2dq */ + if ( !rex_prefix && vex.opcx == vex_none && vex.pfx == vex_f3 ) + buf[0] = 0xf3; + else + copy_REX_VEX(buf, rex_prefix, vex); asm volatile ( "call *%0" : : "r" (stub.func), "a" (mmvalp) : "memory" ); }