All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Teddy Astie" <teddy.astie@vates.tech>,
	"Roger Pau Monné" <roger@xenproject.org>
Subject: [PATCH 20/30] x86emul: support APX+AVX512 insns
Date: Wed, 11 Nov 2026 15:28:42 +0100	[thread overview]
Message-ID: <6843916f-7fa0-40ea-a5e1-a90a5aefbb7d@suse.com> (raw)
In-Reply-To: <17d56a5d-41f2-4691-aea7-d6dfdde5ad32@suse.com>

It's KMOV{B,W,D,Q} which gain straight EVEX-encoded counterparts. Like
the VEX forms require special treatment, so do the EVEX ones. Respective
code is being cloned, with mode_64bit() conditionals dropped.

While adjusting the testharness'es Makefile, drop -Os from the non-APX
opmask test as well - for an assembly source that option is meaningless.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
The spec says EVEX.B4 is ignored for opcode 0x93. While that matches
the fact that EVEX.B3 is also ignored, other similar statments in spec
version 005 (especially as to EVEX.R4 vs EVEX.R3) aren't consistent.
Hence this may need adjustment.

The checking of the 4th EVEX byte is going to re-appear for a number of
further insns. It may therefore want folding into a wrapper macro. Just
that I don't seem to be able to think of a good name for such a macro.

Is simply forcing EVEX encodings (without also involving eGPR-s) enough
of a testing approach?

--- a/tools/tests/x86_emulator/Makefile
+++ b/tools/tests/x86_emulator/Makefile
@@ -172,7 +172,8 @@ $(1)-cflags := $(foreach vec,$($(1:-gf=)
 	         "-D_$(vec) -mgfni -m$(1:-gf=) $(call non-sse,$(1)) -Os -DVEC_SIZE=$(vec)")
 endef
 define opmask-defs
-$(1)-opmask-cflags := $(foreach vec,$($(1)-opmask-vecs), "-D_$(vec) -m$(1) -Os -DSIZE=$(vec)")
+$(1)-opmask-cflags := $(foreach vec,$($(1)-opmask-vecs), "-D_$(vec) -m$(1) -DSIZE=$(vec)")
+$(1)-opmask-cflags-x86_64 := $(foreach vec,$($(1)-opmask-vecs), "-D_$(vec) -mapxf -m$(1) -DSIZE=$(vec)")
 endef
 
 $(foreach flavor,$(SIMD) $(FMA),$(eval $(call simd-defs,$(flavor))))
@@ -214,6 +215,9 @@ $(addsuffix -opmask.h,$(OPMASK)): %.h: o
 	    for cflags in $($*-cflags) $($*-cflags-$(arch)); do \
 		$(MAKE) -f testcase.mk TESTCASE=$* XEN_TARGET_ARCH=$(arch) $*-cflags="$$cflags" all; \
 		prefix=$(shell echo $(subst -,_,$*) | sed -e 's,^\([0-9]\),_\1,'); \
+		if [ "$$cflags" != "$${cflags%apx*}" ]; then \
+			prefix=$${prefix%opmask}apx; \
+		fi; \
 		flavor=$$(echo $${cflags} | sed -e 's, .*,,' -e 'y,-=,__,') ; \
 		(echo 'static const unsigned int __attribute__((section(".test, \"ax\", @progbits #")))' \
 		      "$${prefix}_$(arch)$${flavor}[] = {"; \
--- a/tools/tests/x86_emulator/evex-disp8.c
+++ b/tools/tests/x86_emulator/evex-disp8.c
@@ -1103,6 +1103,29 @@ static const struct test adx[] = {
     INSN(adox,      f3, map4, 66,    el,   dq, no),
 };
 
+static const struct test avx512bw[] = {
+//       kmov,      f2,   0f, 92,          dq
+//       kmov,      f2,   0f, 93,          dq
+    INSN(kmovd,     66,   0f, 90,    el,    d, no),
+    INSN(kmovd,     66,   0f, 91,    el,    d, no),
+    INSN(kmovq,       ,   0f, 90,    el,    q, no),
+    INSN(kmovq,       ,   0f, 91,    el,    q, no),
+};
+
+static const struct test avx512dq[] = {
+    INSN(kmovb,     66,   0f, 90,    el,    b, no),
+    INSN(kmovb,     66,   0f, 91,    el,    b, no),
+//       kmovb,     66,   0f, 92,           b
+//       kmovb,     66,   0f, 93,           b
+};
+
+static const struct test avx512f[] = {
+    INSN(kmovw,       ,   0f, 90,    el,    w, no),
+    INSN(kmovw,       ,   0f, 91,    el,    w, no),
+//       kmovw,       ,   0f, 92,           w
+//       kmovw,       ,   0f, 93,           w
+};
+
 static const unsigned char vl_all[] = { VL_512, VL_128, VL_256 };
 static const unsigned char vl_128[] = { VL_128 };
 static const unsigned char vl_no128[] = { VL_512, VL_256 };
@@ -1261,7 +1284,17 @@ static void test_one(const struct test *
         evex.w = 1;
         /* fall through */
 #endif
-    case ESZ_d: case ESZ_d_nb:
+    case ESZ_d:
+#ifdef __x86_64__
+        /*
+         * KMOVD don't follow the general pattern: They have EVEX.W set despite
+         * having a DWORD operand.
+         */
+        if ( test->spc == SPC_0f && (test->opc | 1) == 0x91 )
+            evex.w = 1;
+        /* fall through */
+#endif
+    case ESZ_d_nb:
         esz = 4;
         break;
 
@@ -1678,6 +1711,9 @@ void evex_disp8_test(void *instr, struct
     } while ( false )
 
         RUN(adx);
+        RUN(avx512f);
+        RUN(avx512dq);
+        RUN(avx512bw);
 
 #undef RUN
 
--- a/tools/tests/x86_emulator/opmask.S
+++ b/tools/tests/x86_emulator/opmask.S
@@ -8,6 +8,12 @@
 #  define R(x) e##x
 # endif
 # define DATA(x) x(%rip)
+# ifdef __APX_F__
+#  define kmovb {evex} kmovb
+#  define kmovd {evex} kmovd
+#  define kmovq {evex} kmovq
+#  define kmovw {evex} kmovw
+# endif
 #endif
 
 #if SIZE == 1
--- a/tools/tests/x86_emulator/predicates.c
+++ b/tools/tests/x86_emulator/predicates.c
@@ -1787,6 +1787,18 @@ static const struct evex {
     { { 0x7f }, 2, T, W, pfx_66, Wn, Ln }, /* vmovdqa{32,64} */
     { { 0x7f }, 2, T, W, pfx_f3, Wn, Ln }, /* vmovdqu{32,64} */
     { { 0x7f }, 2, T, W, pfx_f2, Wn, Ln }, /* vmovdqu{8,16} */
+#ifdef __x86_64__
+    { { 0x90 }, 2, T, R, pfx_no, Wn, L0 }, /* kmov{w,q} */
+    { { 0x90 }, 2, T, R, pfx_66, Wn, L0 }, /* kmov{b,d} */
+    { { 0x91 }, 2, N, W, pfx_no, Wn, L0 }, /* kmov{w,q} */
+    { { 0x91 }, 2, N, W, pfx_66, Wn, L0 }, /* kmov{b,d} */
+    { { 0x92, 0xc0 }, 2, F, N, pfx_no, W0, L0 }, /* kmovw */
+    { { 0x92, 0xc0 }, 2, F, N, pfx_66, W0, L0 }, /* kmovb */
+    { { 0x92, 0xc0 }, 2, F, N, pfx_f2, Wn, L0 }, /* kmov{d,q} */
+    { { 0x93, 0xc0 }, 2, F, N, pfx_no, W0, L0 }, /* kmovw */
+    { { 0x93, 0xc0 }, 2, F, N, pfx_66, W0, L0 }, /* kmovb */
+    { { 0x93, 0xc0 }, 2, F, N, pfx_f2, Wn, L0 }, /* kmov{d,q} */
+#endif
     { { 0xc2 }, 3, T, R, pfx_no, W0, Ln }, /* vcmpps */
     { { 0xc2 }, 3, T, R, pfx_66, W1, Ln }, /* vcmppd */
     { { 0xc2 }, 3, T, R, pfx_f3, W0, LIG }, /* vcmpss */
--- a/tools/tests/x86_emulator/test_x86_emulator.c
+++ b/tools/tests/x86_emulator/test_x86_emulator.c
@@ -348,6 +348,23 @@ static bool simd_check_avx512fp16_vl(voi
            cpu_has_avx10;
 }
 
+#ifdef __x86_64__
+static bool simd_check_avx512f_apx(void)
+{
+    return simd_check_avx512f_opmask() && check_apx_f();
+}
+
+static bool simd_check_avx512bw_apx(void)
+{
+    return simd_check_avx512bw_opmask() && check_apx_f();
+}
+
+static bool simd_check_avx512dq_apx(void)
+{
+    return simd_check_avx512dq_opmask() && check_apx_f();
+}
+#endif /* __x86_64__ */
+
 static void simd_set_regs(struct cpu_user_regs *regs)
 {
     if ( cpu_has_mmx )
@@ -532,6 +549,13 @@ static const struct {
     SIMD(OPMASK+DQ/w, avx512dq_opmask,         2),
     SIMD(OPMASK+BW/d, avx512bw_opmask,         4),
     SIMD(OPMASK+BW/q, avx512bw_opmask,         8),
+#ifdef __x86_64__
+    SIMD_(64, OPMASK+APX/w,     avx512f_apx,   2),
+    SIMD_(64, OPMASK+DQ+APX/b, avx512dq_apx,   1),
+    SIMD_(64, OPMASK+DQ+APX/w, avx512dq_apx,   2),
+    SIMD_(64, OPMASK+BW+APX/d, avx512bw_apx,   4),
+    SIMD_(64, OPMASK+BW+APX/q, avx512bw_apx,   8),
+#endif
     SIMD(AVX512F f32 scalar,  avx512f,        f4),
     SIMD(AVX512F f32x16,      avx512f,      64f4),
     SIMD(AVX512F f64 scalar,  avx512f,        f8),
--- a/xen/arch/x86/x86_emulate/decode.c
+++ b/xen/arch/x86/x86_emulate/decode.c
@@ -1100,18 +1100,35 @@ decode_twobyte(struct x86_emulate_state
         }
         break;
 
+    case X86EMUL_OPC_EVEX(0, 0x90):    /* kmov{w,q} */
+    case X86EMUL_OPC_EVEX_66(0, 0x90): /* kmov{b,d} */
+        s->promoted_evex = true;
+        fallthrough;
     case X86EMUL_OPC_VEX(0, 0x90):    /* kmov{w,q} */
     case X86EMUL_OPC_VEX_66(0, 0x90): /* kmov{b,d} */
         s->desc = DstReg | SrcMem | Mov;
         s->simd_size = simd_other;
         break;
 
+    case X86EMUL_OPC_EVEX(0, 0x91):    /* kmov{w,q} */
+    case X86EMUL_OPC_EVEX_66(0, 0x91): /* kmov{b,d} */
+        s->promoted_evex = true;
+        fallthrough;
     case X86EMUL_OPC_VEX(0, 0x91):    /* kmov{w,q} */
     case X86EMUL_OPC_VEX_66(0, 0x91): /* kmov{b,d} */
         s->desc = DstMem | SrcReg | Mov;
         s->simd_size = simd_other;
         break;
 
+    case X86EMUL_OPC_EVEX(0, 0x92):    /* kmovw */
+    case X86EMUL_OPC_EVEX_66(0, 0x92): /* kmovb */
+    case X86EMUL_OPC_EVEX_F2(0, 0x92): /* kmov{d,q} */
+    case X86EMUL_OPC_EVEX(0, 0x93):    /* kmovw */
+    case X86EMUL_OPC_EVEX_66(0, 0x93): /* kmovb */
+    case X86EMUL_OPC_EVEX_F2(0, 0x93): /* kmov{d,q} */
+        s->promoted_evex = true;
+        break;
+
     case 0xae:
         ctxt->opcode |= MASK_INSR(s->vex.pfx, X86EMUL_OPC_PFX_MASK);
         /* fall through */
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -5316,6 +5316,16 @@ x86_emulate(
 
 #ifndef X86EMUL_NO_SIMD
 
+    case X86EMUL_OPC_EVEX(0x0f, 0x91):    /* kmov{w,q} k,mem */
+    case X86EMUL_OPC_EVEX_66(0x0f, 0x91): /* kmov{b,d} k,mem */
+        generate_exception_if(ea.type != OP_MEM, X86_EXC_UD);
+        fallthrough;
+    case X86EMUL_OPC_EVEX(0x0f, 0x90):    /* kmov{w,q} k/mem,k */
+    case X86EMUL_OPC_EVEX_66(0x0f, 0x90): /* kmov{b,d} k/mem,k */
+        generate_exception_if((evex.lr || evex.brs || evex.opmsk ||
+                               !evex.r3 || !evex.r4),
+                              X86_EXC_UD);
+        goto kmov;
     case X86EMUL_OPC_VEX(0x0f, 0x91):    /* kmov{w,q} k,mem */
     case X86EMUL_OPC_VEX_66(0x0f, 0x91): /* kmov{b,d} k,mem */
         generate_exception_if(ea.type != OP_MEM, X86_EXC_UD);
@@ -5323,6 +5333,7 @@ x86_emulate(
     case X86EMUL_OPC_VEX(0x0f, 0x90):    /* kmov{w,q} k/mem,k */
     case X86EMUL_OPC_VEX_66(0x0f, 0x90): /* kmov{b,d} k/mem,k */
         generate_exception_if(vex.l || !vex.r, X86_EXC_UD);
+    kmov:
         if ( vex.w )
         {
             visa_check(bw);
@@ -5353,6 +5364,13 @@ x86_emulate(
         insn_bytes = PFX_BYTES + 2;
         break;
 
+    case X86EMUL_OPC_EVEX(0x0f, 0x92):    /* kmovw r32,k */
+    case X86EMUL_OPC_EVEX_66(0x0f, 0x92): /* kmovb r32,k */
+    case X86EMUL_OPC_EVEX_F2(0x0f, 0x92): /* kmov{d,q} reg,k */
+        generate_exception_if((evex.lr || evex.brs || evex.opmsk ||
+                               !evex.r4 || !evex.RX),
+                              X86_EXC_UD);
+        fallthrough;
     case X86EMUL_OPC_VEX(0x0f, 0x92):    /* kmovw r32,k */
     case X86EMUL_OPC_VEX_66(0x0f, 0x92): /* kmovb r32,k */
     case X86EMUL_OPC_VEX_F2(0x0f, 0x92): /* kmov{d,q} reg,k */
@@ -5381,8 +5399,8 @@ x86_emulate(
         opc[1] = modrm & 0xf8;
         place_ret(&opc[2]);
 
-        copy_VEX(opc, vex, false);
-        ea.reg = decode_gpr(&_regs, NULL, modrm_rm);
+        copy_VEX(opc, vex, state->promoted_evex);
+        ea.reg = decode_gpr(&_regs, &state->egpr, modrm_rm);
         invoke_stub("", "", "=m" (dummy) : "a" (*ea.reg));
 
         put_stub(stub);
@@ -5391,13 +5409,19 @@ x86_emulate(
         dst.type = OP_NONE;
         break;
 
+    case X86EMUL_OPC_EVEX(0x0f, 0x93):    /* kmovw k,r32 */
+    case X86EMUL_OPC_EVEX_66(0x0f, 0x93): /* kmovb k,r32 */
+    case X86EMUL_OPC_EVEX_F2(0x0f, 0x93): /* kmov{d,q} k,reg */
+        generate_exception_if((evex.lr || evex.brs || evex.opmsk || !evex.RX),
+                              X86_EXC_UD);
+        fallthrough;
     case X86EMUL_OPC_VEX(0x0f, 0x93):    /* kmovw k,r32 */
     case X86EMUL_OPC_VEX_66(0x0f, 0x93): /* kmovb k,r32 */
     case X86EMUL_OPC_VEX_F2(0x0f, 0x93): /* kmov{d,q} k,reg */
         generate_exception_if(vex.l || vex.reg != 0xf || ea.type != OP_REG,
                               X86_EXC_UD);
         dst = ea;
-        dst.reg = decode_gpr(&_regs, NULL, modrm_reg);
+        dst.reg = decode_gpr(&_regs, &state->egpr, modrm_reg);
 
         if ( vex.pfx == vex_f2 )
         {
@@ -5425,7 +5449,7 @@ x86_emulate(
         opc[1] = modrm & 0xc7;
         place_ret(&opc[2]);
 
-        copy_VEX(opc, vex, false);
+        copy_VEX(opc, vex, state->promoted_evex);
         invoke_stub("", "", "=a" (dst.val) : [dummy] "i" (0));
 
         put_stub(stub);
@@ -8950,7 +8974,12 @@ x86_emulate(
         EXPECT(op_bytes);
         EXPECT(opc);
 
-        if ( evex_encoded() )
+        if ( state->promoted_evex )
+        {
+            place_ret(&opc[insn_bytes - PFX_BYTES]);
+            copy_VEX(opc, vex, true);
+        }
+        else if ( evex_encoded() )
         {
             place_ret(&opc[insn_bytes - EVEX_PFX_BYTES]);
             copy_EVEX(opc, evex);



  parent reply	other threads:[~2026-11-11 14:29 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 14:19 [PATCH 00/30] x86: permit guests to use APX Jan Beulich
2026-11-11 14:20 ` [PATCH 01/30] x86/CPUID: introduce APX_F Jan Beulich
2026-11-11 14:21 ` [PATCH 02/30] x86/CPUID: enable APX sub-leaf Jan Beulich
2026-11-11 14:21 ` [PATCH 03/30] x86/xstate: enable APX_F Jan Beulich
2026-11-11 14:22 ` [PATCH 04/30] x86emul: add eGPR parameter to decode_gpr() Jan Beulich
2026-11-11 14:22 ` [PATCH 05/30] x86emul: replace earlier relaxation of decode_gpr() Jan Beulich
2026-11-11 14:22 ` [PATCH 06/30] VMX: support APX Jan Beulich
2026-11-11 14:23 ` [PATCH 07/30] x86emul: latch XCR0 early during decode Jan Beulich
2026-11-11 14:23 ` [PATCH 08/30] x86emul: support REX2-prefixed insns Jan Beulich
2026-11-11 14:24 ` [PATCH 09/30] x86emul: APX_F REX2 testing Jan Beulich
2026-11-11 14:24 ` [PATCH 10/30] x86emul: support JMPABS Jan Beulich
2026-11-11 14:25 ` [PATCH 11/30] x86emul: switch to EVEX.R{3,4} nomenclature Jan Beulich
2026-11-11 14:25 ` [PATCH 12/30] x86emul: switch to EVEX.B{3,4} nomenclature Jan Beulich
2026-11-11 14:25 ` [PATCH 13/30] x86emul: switch to EVEX.X3 nomenclature Jan Beulich
2026-11-11 14:26 ` [PATCH 14/30] x86emul: support basic APX EVEX-encoded ALU insns Jan Beulich
2026-11-11 14:26 ` [PATCH 15/30] x86emul: support APX EVEX-encoded shift/rotate insns Jan Beulich
2026-11-11 14:27 ` [PATCH 16/30] x86emul: support remaining basic APX EVEX-Map4 insns Jan Beulich
2026-11-11 14:27 ` [PATCH 17/30] x86emul: support APX SCC insns Jan Beulich
2026-11-11 14:27 ` [PATCH 18/30] x86emul: support APX+ADX insns Jan Beulich
2026-11-11 14:28 ` [PATCH 19/30] x86emul: extend copy_VEX() for APX use Jan Beulich
2026-11-11 14:28 ` Jan Beulich [this message]
2026-11-11 14:29 ` [PATCH 21/30] x86emul: support APX+BMI1 insns Jan Beulich
2026-11-11 14:29 ` [PATCH 22/30] x86emul: support APX+BMI2 insns Jan Beulich
2026-11-11 14:29 ` [PATCH 23/30] x86emul: support APX+CMPccXADD insns Jan Beulich
2026-11-11 14:30 ` [PATCH 24/30] x86emul: support APX+{LZ,POP}CNT insns Jan Beulich
2026-11-11 14:30 ` [PATCH 25/30] x86emul: support APX+MOVBE insn Jan Beulich
2026-11-11 14:31 ` [PATCH 26/30] x86emul: support APX+MOVDIR/ENQCMD insns Jan Beulich
2026-11-11 14:31 ` [PATCH 27/30] x86emul: support APX+MOVRS insn Jan Beulich
2026-11-11 14:31 ` [PATCH 28/30] x86emul: support APX MSR access insns Jan Beulich
2026-11-11 14:32 ` [PATCH 29/30] x86: permit guests to use APX Jan Beulich
2026-11-11 14:33 ` [PATCH 30/30] x86emul: use latched XCR0 in x86emul_get_fpu() Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6843916f-7fa0-40ea-a5e1-a90a5aefbb7d@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=roger@xenproject.org \
    --cc=teddy.astie@vates.tech \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.