From: "Jan Beulich" Subject: [PATCH 4/5] x86/emulate: add support for {, v}movq xmm, xmm/m64 Date: Thu, 08 Sep 2016 07:45:19 -0600 Message-ID: <57D1878F020000780010D270@prv-mh.provo.novell.com> References: <57D18589020000780010D251@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartFACC717F.2__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhzgk-0005aL-JA for xen-devel@lists.xenproject.org; Thu, 08 Sep 2016 13:48:22 +0000 In-Reply-To: <57D18589020000780010D251@prv-mh.provo.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel Cc: Andrew Cooper , Mihai Dontu List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartFACC717F.2__= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Disposition: inline From: Mihai Donțu Signed-off-by: Mihai Donțu Signed-off-by: Jan Beulich --- v4: Re-base on decoding changes. Address my own review comments (where still applicable). #UD when vex.l is set. Various adjustments to the test tool change. --- a/tools/tests/x86_emulator/test_x86_emulator.c +++ b/tools/tests/x86_emulator/test_x86_emulator.c @@ -713,6 +713,54 @@ int main(int argc, char **argv) else printf("skipped\n"); + printf("%-40s", "Testing movq %%xmm0,32(%%ecx)..."); + if ( stack_exec && cpu_has_sse2 ) + { + decl_insn(movq_to_mem2); + + asm volatile ( "pcmpgtb %%xmm0, %%xmm0\n" + put_insn(movq_to_mem2, "movq %%xmm0, 32(%0)") + :: "c" (NULL) ); + + memset(res, 0xbd, 64); + set_insn(movq_to_mem2); + regs.ecx = (unsigned long)res; + regs.edx = 0; + rc = x86_emulate(&ctxt, &emulops); + if ( rc != X86EMUL_OKAY || !check_eip(movq_to_mem2) || + *((uint64_t *)res + 4) || + memcmp(res, res + 10, 24) || + memcmp(res, res + 6, 8) ) + goto fail; + printf("okay\n"); + } + else + printf("skipped\n"); + + printf("%-40s", "Testing vmovq %%xmm1,32(%%edx)..."); + if ( stack_exec && cpu_has_avx ) + { + decl_insn(vmovq_to_mem); + + asm volatile ( "pcmpgtb %%xmm1, %%xmm1\n" + put_insn(vmovq_to_mem, "vmovq %%xmm1, 32(%0)") + :: "d" (NULL) ); + + memset(res, 0xdb, 64); + set_insn(vmovq_to_mem); + regs.ecx = 0; + regs.edx = (unsigned long)res; + rc = x86_emulate(&ctxt, &emulops); + if ( rc != X86EMUL_OKAY || !check_eip(vmovq_to_mem) || + *((uint64_t *)res + 4) || + memcmp(res, res + 10, 24) || + memcmp(res, res + 6, 8) ) + goto fail; + printf("okay\n"); + } + else + printf("skipped\n"); + printf("%-40s", "Testing movdqu %xmm2,(%ecx)..."); if ( stack_exec && cpu_has_sse2 ) { --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -269,7 +269,7 @@ static const opcode_desc_t twobyte_table ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, /* 0xD0 - 0xDF */ - ModRM, ModRM, ModRM, ModRM, ModRM, ModRM, ModRM, ModRM, + ModRM, ModRM, ModRM, ModRM, ModRM, ModRM, ImplicitOps|ModRM, ModRM, ModRM, ModRM, ModRM, ModRM, ModRM, ModRM, ModRM, ModRM, /* 0xE0 - 0xEF */ ModRM, ModRM, ModRM, ModRM, ModRM, ModRM, ModRM, ImplicitOps|ModRM, @@ -4779,6 +4779,8 @@ x86_emulate( case X86EMUL_OPC_F3(0x0f, 0x7f): /* movdqu xmm,xmm/m128 */ case X86EMUL_OPC_VEX_F3(0x0f, 0x7f): /* vmovdqu xmm,xmm/m128 */ /* vmovdqu ymm,ymm/m256 */ + case X86EMUL_OPC_66(0x0f, 0xd6): /* movq xmm,xmm/m64 */ + case X86EMUL_OPC_VEX_66(0x0f, 0xd6): /* vmovq xmm,xmm/m64 */ { uint8_t *buf = get_stub(stub); struct fpu_insn_ctxt fic = { .insn_bytes = 5 }; @@ -4796,7 +4798,8 @@ x86_emulate( case vex_66: case vex_f3: host_and_vcpu_must_have(sse2); - buf[0] = 0x66; /* movdqa */ + /* Converting movdqu to movdqa here: Our buffer is aligned. */ + buf[0] = 0x66; get_fpu(X86EMUL_FPU_xmm, &fic); ea.bytes = 16; break; @@ -4819,6 +4822,11 @@ x86_emulate( get_fpu(X86EMUL_FPU_ymm, &fic); ea.bytes = 16 << vex.l; } + if ( b == 0xd6 ) + { + generate_exception_if(vex.l, EXC_UD, -1); + ea.bytes = 8; + } if ( ea.type == OP_MEM ) { generate_exception_if((vex.pfx == vex_66) && --=__PartFACC717F.2__= Content-Type: text/plain; name="x86emul-vmovq.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86emul-vmovq.patch" x86/emulate: add support for {,v}movq xmm,xmm/m64=0A=0AFrom: Mihai = Don=C8=9Bu =0A=0ASigned-off-by: Mihai Don=C8=9Bu = =0ASigned-off-by: Jan Beulich = =0A---=0Av4: Re-base on decoding changes. Address my own review comments = (where=0A still applicable). #UD when vex.l is set. Various adjustments = to=0A the test tool change.=0A=0A--- a/tools/tests/x86_emulator/test_x86= _emulator.c=0A+++ b/tools/tests/x86_emulator/test_x86_emulator.c=0A@@ = -713,6 +713,54 @@ int main(int argc, char **argv)=0A else=0A = printf("skipped\n");=0A =0A+ printf("%-40s", "Testing movq %%xmm0,32(%%e= cx)...");=0A+ if ( stack_exec && cpu_has_sse2 )=0A+ {=0A+ = decl_insn(movq_to_mem2);=0A+=0A+ asm volatile ( "pcmpgtb %%xmm0, = %%xmm0\n"=0A+ put_insn(movq_to_mem2, "movq %%xmm0, = 32(%0)")=0A+ :: "c" (NULL) );=0A+=0A+ = memset(res, 0xbd, 64);=0A+ set_insn(movq_to_mem2);=0A+ = regs.ecx =3D (unsigned long)res;=0A+ regs.edx =3D 0;=0A+ rc = =3D x86_emulate(&ctxt, &emulops);=0A+ if ( rc !=3D X86EMUL_OKAY || = !check_eip(movq_to_mem2) ||=0A+ *((uint64_t *)res + 4) ||=0A+ = memcmp(res, res + 10, 24) ||=0A+ memcmp(res, res + = 6, 8) )=0A+ goto fail;=0A+ printf("okay\n");=0A+ = }=0A+ else=0A+ printf("skipped\n");=0A+=0A+ printf("%-40s", = "Testing vmovq %%xmm1,32(%%edx)...");=0A+ if ( stack_exec && cpu_has_avx= )=0A+ {=0A+ decl_insn(vmovq_to_mem);=0A+=0A+ asm = volatile ( "pcmpgtb %%xmm1, %%xmm1\n"=0A+ put_insn(vm= ovq_to_mem, "vmovq %%xmm1, 32(%0)")=0A+ :: "d" = (NULL) );=0A+=0A+ memset(res, 0xdb, 64);=0A+ set_insn(vmovq_t= o_mem);=0A+ regs.ecx =3D 0;=0A+ regs.edx =3D (unsigned = long)res;=0A+ rc =3D x86_emulate(&ctxt, &emulops);=0A+ if ( = rc !=3D X86EMUL_OKAY || !check_eip(vmovq_to_mem) ||=0A+ = *((uint64_t *)res + 4) ||=0A+ memcmp(res, res + 10, 24) ||=0A+ = memcmp(res, res + 6, 8) )=0A+ goto fail;=0A+ = printf("okay\n");=0A+ }=0A+ else=0A+ printf("skipped\n");=0A+= =0A printf("%-40s", "Testing movdqu %xmm2,(%ecx)...");=0A if ( = stack_exec && cpu_has_sse2 )=0A {=0A--- a/xen/arch/x86/x86_emulate/x86_= emulate.c=0A+++ b/xen/arch/x86/x86_emulate/x86_emulate.c=0A@@ -269,7 = +269,7 @@ static const opcode_desc_t twobyte_table=0A ImplicitOps, = ImplicitOps, ImplicitOps, ImplicitOps,=0A ImplicitOps, ImplicitOps, = ImplicitOps, ImplicitOps,=0A /* 0xD0 - 0xDF */=0A- ModRM, ModRM, = ModRM, ModRM, ModRM, ModRM, ModRM, ModRM,=0A+ ModRM, ModRM, ModRM, = ModRM, ModRM, ModRM, ImplicitOps|ModRM, ModRM,=0A ModRM, ModRM, ModRM, = ModRM, ModRM, ModRM, ModRM, ModRM,=0A /* 0xE0 - 0xEF */=0A ModRM, = ModRM, ModRM, ModRM, ModRM, ModRM, ModRM, ImplicitOps|ModRM,=0A@@ -4779,6 = +4779,8 @@ x86_emulate(=0A case X86EMUL_OPC_F3(0x0f, 0x7f): /* = movdqu xmm,xmm/m128 */=0A case X86EMUL_OPC_VEX_F3(0x0f, 0x7f): /* = vmovdqu xmm,xmm/m128 */=0A /* = vmovdqu ymm,ymm/m256 */=0A+ case X86EMUL_OPC_66(0x0f, 0xd6): /* = movq xmm,xmm/m64 */=0A+ case X86EMUL_OPC_VEX_66(0x0f, 0xd6): /* vmovq = xmm,xmm/m64 */=0A {=0A uint8_t *buf =3D get_stub(stub);=0A = struct fpu_insn_ctxt fic =3D { .insn_bytes =3D 5 };=0A@@ -4796,7 = +4798,8 @@ x86_emulate(=0A case vex_66:=0A case = vex_f3:=0A host_and_vcpu_must_have(sse2);=0A- = buf[0] =3D 0x66; /* movdqa */=0A+ /* Converting movdqu to = movdqa here: Our buffer is aligned. */=0A+ buf[0] =3D = 0x66;=0A get_fpu(X86EMUL_FPU_xmm, &fic);=0A = ea.bytes =3D 16;=0A break;=0A@@ -4819,6 +4822,11 @@ = x86_emulate(=0A get_fpu(X86EMUL_FPU_ymm, &fic);=0A = ea.bytes =3D 16 << vex.l;=0A }=0A+ if ( b =3D=3D 0xd6 )=0A+ = {=0A+ generate_exception_if(vex.l, EXC_UD, -1);=0A+ = ea.bytes =3D 8;=0A+ }=0A if ( ea.type =3D=3D OP_MEM = )=0A {=0A generate_exception_if((vex.pfx =3D=3D = vex_66) &&=0A --=__PartFACC717F.2__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --=__PartFACC717F.2__=--