Skip to content

Commit

Permalink
selftests/x86/xstate: Enumerate and name xstate components
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Chang S. Bae authored and Ingo Molnar committed Feb 26, 2025
1 parent 0f6d91a commit 3fcb4d6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
2 changes: 0 additions & 2 deletions tools/testing/selftests/x86/amx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
60 changes: 60 additions & 0 deletions tools/testing/selftests/x86/xstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down

0 comments on commit 3fcb4d6

Please sign in to comment.