]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/x86/xstate: Enumerate and name xstate components
authorChang S. Bae <chang.seok.bae@intel.com>
Wed, 26 Feb 2025 01:07:23 +0000 (17:07 -0800)
committerIngo Molnar <mingo@kernel.org>
Wed, 26 Feb 2025 12:05:28 +0000 (13:05 +0100)
After moving essential helpers from amx.c, the code remains neutral
regarding which xstate components it handles. However, explicitly listing
known components helps users identify which features are ready for
testing.

Enumerate xstate components to facilitate identification. Extend struct
xstate_info to include a name field, providing a human-readable
identifier.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20250226010731.2456-4-chang.seok.bae@intel.com
tools/testing/selftests/x86/amx.c
tools/testing/selftests/x86/xstate.h

index 366cfec221e482db0c58eefdbc8c9a136ea45bf9..cde22f303905622959bbcdf9a6ed04329deb4294 100644 (file)
@@ -29,8 +29,6 @@
 /* err() exits and will not return */
 #define fatal_error(msg, ...)  err(1, "[FAIL]\t" msg, ##__VA_ARGS__)
 
-#define XFEATURE_XTILECFG      17
-#define XFEATURE_XTILEDATA     18
 #define XFEATURE_MASK_XTILECFG (1 << XFEATURE_XTILECFG)
 #define XFEATURE_MASK_XTILEDATA        (1 << XFEATURE_XTILEDATA)
 #define XFEATURE_MASK_XTILE    (XFEATURE_MASK_XTILECFG | XFEATURE_MASK_XTILEDATA)
index 6729ffde6cc49c5a80939477a7db5283d8c48ee0..d3461c4384614538ab63d30a8ae4e30cbe4d3287 100644 (file)
@@ -9,6 +9,59 @@
 #define XSAVE_HDR_OFFSET       512
 #define XSAVE_HDR_SIZE         64
 
+/*
+ * List of XSAVE features Linux knows about. Copied from
+ * arch/x86/include/asm/fpu/types.h
+ */
+enum xfeature {
+       XFEATURE_FP,
+       XFEATURE_SSE,
+       XFEATURE_YMM,
+       XFEATURE_BNDREGS,
+       XFEATURE_BNDCSR,
+       XFEATURE_OPMASK,
+       XFEATURE_ZMM_Hi256,
+       XFEATURE_Hi16_ZMM,
+       XFEATURE_PT_UNIMPLEMENTED_SO_FAR,
+       XFEATURE_PKRU,
+       XFEATURE_PASID,
+       XFEATURE_CET_USER,
+       XFEATURE_CET_KERNEL_UNUSED,
+       XFEATURE_RSRVD_COMP_13,
+       XFEATURE_RSRVD_COMP_14,
+       XFEATURE_LBR,
+       XFEATURE_RSRVD_COMP_16,
+       XFEATURE_XTILECFG,
+       XFEATURE_XTILEDATA,
+
+       XFEATURE_MAX,
+};
+
+/* Copied from arch/x86/kernel/fpu/xstate.c */
+static const char *xfeature_names[] =
+{
+       "x87 floating point registers",
+       "SSE registers",
+       "AVX registers",
+       "MPX bounds registers",
+       "MPX CSR",
+       "AVX-512 opmask",
+       "AVX-512 Hi256",
+       "AVX-512 ZMM_Hi256",
+       "Processor Trace (unused)",
+       "Protection Keys User registers",
+       "PASID state",
+       "Control-flow User registers",
+       "Control-flow Kernel registers (unused)",
+       "unknown xstate feature",
+       "unknown xstate feature",
+       "unknown xstate feature",
+       "unknown xstate feature",
+       "AMX Tile config",
+       "AMX Tile data",
+       "unknown xstate feature",
+};
+
 struct xsave_buffer {
        union {
                struct {
@@ -58,6 +111,7 @@ static inline uint32_t get_xbuf_size(void)
 }
 
 struct xstate_info {
+       const char *name;
        uint32_t num;
        uint32_t mask;
        uint32_t xbuf_offset;
@@ -69,6 +123,12 @@ static inline struct xstate_info get_xstate_info(uint32_t xfeature_num)
        struct xstate_info xstate = { };
        uint32_t eax, ebx, ecx, edx;
 
+       if (xfeature_num >= XFEATURE_MAX) {
+               ksft_print_msg("unknown state\n");
+               return xstate;
+       }
+
+       xstate.name = xfeature_names[xfeature_num];
        xstate.num  = xfeature_num;
        xstate.mask = 1 << xfeature_num;