|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v4 10/28] x86emul: support {LD,ST}TILECFG
While ver 043 of the ISA extensions doc also specifies
xcr0_supports_palette() returning false as one of the #GP(0) reasons for
LDTILECFG, the earlier #UD / #GP conditions look to make this fully
dead.
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
v4: Prevent double read for LDTILECFG. Use X86_EXC_*. Re-base.
v3: Rebase over struct x86_tilecfg introduction.
v2: New.
---
SDE: -spr or -gnr
--- a/tools/tests/x86_emulator/predicates.c
+++ b/tools/tests/x86_emulator/predicates.c
@@ -1343,6 +1343,8 @@ static const struct vex {
{ { 0x45 }, 2, T, R, pfx_66, Wn, Ln }, /* vpsrlv{d,q} */
{ { 0x46 }, 2, T, R, pfx_66, W0, Ln }, /* vpsravd */
{ { 0x47 }, 2, T, R, pfx_66, Wn, Ln }, /* vpsllv{d,q} */
+ { { 0x49, 0x00 }, 2, F, R, pfx_no, W0, L0 }, /* ldtilecfg */
+ { { 0x49, 0x00 }, 2, F, W, pfx_66, W0, L0 }, /* sttilecfg */
{ { 0x49, 0xc0 }, 2, F, N, pfx_no, W0, L0 }, /* tilerelease */
{ { 0x50 }, 2, T, R, pfx_no, W0, Ln }, /* vpdpbuud */
{ { 0x50 }, 2, T, R, pfx_66, W0, Ln }, /* vpdpbusd */
--- a/tools/tests/x86_emulator/test_x86_emulator.c
+++ b/tools/tests/x86_emulator/test_x86_emulator.c
@@ -1139,6 +1139,11 @@ int main(int argc, char **argv)
#ifdef __x86_64__
unsigned int vendor_native;
bool nci_ndd_nf;
+ static const struct x86_tilecfg tilecfg = {
+ .palette = 1,
+ .colsb = { 2, 4, 5, 3 },
+ .rows = { 2, 4, 3, 5 },
+ };
#else
# define nci_ndd_nf false
unsigned int bcdres_native, bcdres_emul;
@@ -6040,6 +6045,74 @@ int main(int argc, char **argv)
printf("skipped\n");
#ifdef __x86_64__
+ printf("%-40s", "Testing tilerelease;sttilecfg 4(%rcx)...");
+ if ( stack_exec && cpu_has_amx_tile )
+ {
+ decl_insn(tilerelease);
+
+ asm volatile ( put_insn(tilerelease,
+ /* tilerelease */
+ ".byte 0xC4, 0xE2, 0x78, 0x49, 0xC0;"
+ /* sttilecfg 4(%0) */
+ ".byte 0xC4, 0xE2, 0x79, 0x49, 0x41, 0x04")
+ :: "c" (NULL) );
+
+ memset(res, ~0, 72);
+ set_insn(tilerelease);
+ regs.ecx = (unsigned long)res;
+ rc = x86_emulate(&ctxt, &emulops);
+ if ( rc == X86EMUL_OKAY )
+ rc = x86_emulate(&ctxt, &emulops);
+ if ( rc != X86EMUL_OKAY || !check_eip(tilerelease) ||
+ ~res[0] || ~res[17] || memchr_inv(res + 1, 0, 64) )
+ goto fail;
+ printf("okay\n");
+ }
+ else
+ printf("skipped\n");
+
+ printf("%-40s", "Testing ldtilecfg (%rdx)...");
+ if ( stack_exec && cpu_has_amx_tile )
+ {
+ decl_insn(ldtilecfg);
+
+ asm volatile ( put_insn(ldtilecfg,
+ /* ldtilecfg (%0) */
+ ".byte 0xC4, 0xE2, 0x78, 0x49, 0x02")
+ :: "d" (NULL) );
+
+ set_insn(ldtilecfg);
+ regs.edx = (unsigned long)&tilecfg;
+ rc = x86_emulate(&ctxt, &emulops);
+ if ( rc != X86EMUL_OKAY || !check_eip(ldtilecfg) )
+ goto fail;
+ printf("pending\n");
+ }
+ else
+ printf("skipped\n");
+
+ printf("%-40s", "Testing sttilecfg -4(%rcx)...");
+ if ( stack_exec && cpu_has_amx_tile )
+ {
+ decl_insn(sttilecfg);
+
+ asm volatile ( put_insn(sttilecfg,
+ /* sttilecfg -4(%0) */
+ ".byte 0xC4, 0xE2, 0x79, 0x49, 0x41, 0xFC")
+ :: "c" (NULL) );
+
+ memset(res, ~0, 72);
+ set_insn(sttilecfg);
+ regs.ecx = (unsigned long)(res + 2);
+ rc = x86_emulate(&ctxt, &emulops);
+ if ( rc != X86EMUL_OKAY || !check_eip(sttilecfg) ||
+ ~res[0] || ~res[17] || memcmp(res + 1, &tilecfg, 64) )
+ goto fail;
+ printf("okay\n");
+ }
+ else
+ printf("skipped\n");
+
printf("%-40s", "Testing vzeroupper (compat)...");
if ( cpu_has_avx )
{
--- a/tools/tests/x86_emulator/x86-emulate.h
+++ b/tools/tests/x86_emulator/x86-emulate.h
@@ -83,6 +83,17 @@
#define is_canonical_address(x) (((int64_t)(x) >> 47) == ((int64_t)(x) >> 63))
+static inline void *memchr_inv(const void *s, int c, size_t n)
+{
+ const unsigned char *p = s;
+
+ while ( n-- )
+ if ( (unsigned char)c != *p++ )
+ return (void *)(p - 1);
+
+ return NULL;
+}
+
static inline void *place_ret(void *ptr)
{
*(uint8_t *)ptr = 0xc3;
@@ -210,6 +221,9 @@ void wrpkru(unsigned int val);
#define cpu_has_serialize cpu_policy.feat.serialize
#define cpu_has_avx512_fp16 (cpu_policy.feat.avx512_fp16 && \
xcr0_mask(0xe6))
+#define cpu_has_amx_tile (cpu_policy.feat.amx_tile && \
+ xcr0_mask(X86_XCR0_TILE_CFG | \
+ X86_XCR0_TILE_DATA))
#define cpu_has_sha512 (cpu_policy.feat.sha512 && xcr0_mask(6))
#define cpu_has_sm3 (cpu_policy.feat.sm3 && xcr0_mask(6))
#define cpu_has_sm4 (cpu_policy.feat.sm4 && xcr0_mask(6))
--- a/xen/arch/x86/include/asm/x86-types.h
+++ b/xen/arch/x86/include/asm/x86-types.h
@@ -74,4 +74,14 @@ struct segment_register {
uint64_t base;
};
+/*
+ * TILECFG register
+ */
+struct x86_tilecfg {
+ uint8_t palette, start_row;
+ uint8_t res[14];
+ uint16_t colsb[16];
+ uint8_t rows[16];
+};
+
#endif /* X86_X86_TYPES_H */
--- a/xen/arch/x86/x86_emulate/decode.c
+++ b/xen/arch/x86/x86_emulate/decode.c
@@ -1267,6 +1267,10 @@ decode_0f38(struct x86_emulate_state *s,
s->simd_size = simd_packed_fp;
break;
+ case X86EMUL_OPC_VEX_66(0, 0x49): /* sttilecfg */
+ s->desc = DstMem | SrcImplicit | Mov;
+ break;
+
case X86EMUL_OPC_EVEX_66(0, 0x7a): /* vpbroadcastb */
case X86EMUL_OPC_EVEX_66(0, 0x7b): /* vpbroadcastw */
case X86EMUL_OPC_EVEX_66(0, 0x7c): /* vpbroadcast{d,q} */
--- a/xen/arch/x86/x86_emulate/private.h
+++ b/xen/arch/x86/x86_emulate/private.h
@@ -18,6 +18,7 @@
# include <asm/endbr.h>
# include <asm/msr-index.h>
# include <asm/stubs.h>
+# include <asm/x86-types.h>
# include <asm/x86-vendors.h>
# include <asm/x86_emulate.h>
@@ -372,6 +373,7 @@ typedef union {
uint64_t __attribute__ ((aligned(16))) xmm[2];
uint64_t __attribute__ ((aligned(32))) ymm[4];
uint64_t __attribute__ ((aligned(64))) zmm[8];
+ struct x86_tilecfg tilecfg;
uint32_t data32[16];
} mmval_t;
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -97,6 +97,8 @@ static const uint16_t _3dnow_ext_table[1
/* Shift values between src and dst sizes of pmov{s,z}x{b,w,d}{w,d,q}. */
static const uint8_t pmov_convert_delta[] = { 1, 2, 3, 1, 2, 1 };
+#define PALETTE_AMX 1
+
#endif /* !X86EMUL_NO_SIMD */
static const uint8_t sse_prefix[] = { 0x66, 0xf3, 0xf2 };
@@ -6564,7 +6566,79 @@ x86_emulate(
goto unrecognized_insn;
}
}
- goto unimplemented_insn;
+
+ switch ( modrm_reg & 7 )
+ {
+ case 0: /* ldtilecfg mem */
+ generate_exception_if(vex.reg != 0xf, X86_EXC_UD);
+ vcpu_must_have(amx_tile);
+ get_fpu(X86EMUL_FPU_tilecfg);
+ rc = ops->read(ea.mem.seg, ea.mem.off, mmvalp, 64, ctxt);
+ if ( rc != X86EMUL_OKAY )
+ goto done;
+ generate_exception_if((mmvalp->tilecfg.palette >
+ cp->tile.max_palette),
+ X86_EXC_GP, 0);
+ switch ( mmvalp->tilecfg.palette )
+ {
+ case 0: /* init */
+ break;
+
+ case PALETTE_AMX:
+ {
+ const typeof(cp->tile.palette1) *palette = &cp->tile.palette1;
+
+ generate_exception_if(memchr_inv(mmvalp->tilecfg.res, 0,
+ sizeof(mmvalp->tilecfg.res)),
+ X86_EXC_GP, 0);
+
+ /*
+ * Parameters for valid registers must be within bounds, or
+ * both be zero at the same time.
+ */
+ for ( i = 0; i < palette->num_regs; ++i )
+ generate_exception_if(((mmvalp->tilecfg.colsb[i] >
+ palette->bytes_per_row) ||
+ (mmvalp->tilecfg.rows[i] >
+ palette->max_rows) ||
+ (!mmvalp->tilecfg.colsb[i] !=
+ !mmvalp->tilecfg.rows[i])),
+ X86_EXC_GP, 0);
+
+ /* All remaining entries must be zero. */
+ for ( ; i < 16; ++i )
+ generate_exception_if((mmvalp->tilecfg.colsb[i] ||
+ mmvalp->tilecfg.rows[i]),
+ X86_EXC_GP, 0);
+
+ break;
+ }
+
+ default:
+ generate_exception(X86_EXC_GP, 0);
+ }
+
+ op_bytes = 64;
+ /* Fake for the common SIMD code below. */
+ d = (d & ~SrcMask) | SrcMem16;
+ goto simd_0f_common;
+ }
+ goto unrecognized_insn;
+
+ case X86EMUL_OPC_VEX_66(0x0f38, 0x49):
+ generate_exception_if(!mode_64bit() || vex.l || vex.w, X86_EXC_UD);
+ if ( ea.type == OP_REG )
+ goto unrecognized_insn;
+
+ switch ( modrm_reg & 7 )
+ {
+ case 0: /* sttilecfg mem */
+ vcpu_must_have(amx_tile);
+ get_fpu(X86EMUL_FPU_tilecfg);
+ op_bytes = 64;
+ goto simd_0f_common;
+ }
+ goto unrecognized_insn;
case X86EMUL_OPC_VEX (0x0f38, 0x50): /* vpdpbuud
[xy]mm/mem,[xy]mm,[xy]mm */
case X86EMUL_OPC_VEX_F3(0x0f38, 0x50): /* vpdpbsud
[xy]mm/mem,[xy]mm,[xy]mm */
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |