Skip to content

Commit 3fcb4d6

Browse files
ChangSeokBaeIngo Molnar
authored andcommitted
selftests/x86/xstate: Enumerate and name xstate components
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 <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0f6d91a commit 3fcb4d6

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

tools/testing/selftests/x86/amx.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
/* err() exits and will not return */
3030
#define fatal_error(msg, ...) err(1, "[FAIL]\t" msg, ##__VA_ARGS__)
3131

32-
#define XFEATURE_XTILECFG 17
33-
#define XFEATURE_XTILEDATA 18
3432
#define XFEATURE_MASK_XTILECFG (1 << XFEATURE_XTILECFG)
3533
#define XFEATURE_MASK_XTILEDATA (1 << XFEATURE_XTILEDATA)
3634
#define XFEATURE_MASK_XTILE (XFEATURE_MASK_XTILECFG | XFEATURE_MASK_XTILEDATA)

tools/testing/selftests/x86/xstate.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,59 @@
99
#define XSAVE_HDR_OFFSET 512
1010
#define XSAVE_HDR_SIZE 64
1111

12+
/*
13+
* List of XSAVE features Linux knows about. Copied from
14+
* arch/x86/include/asm/fpu/types.h
15+
*/
16+
enum xfeature {
17+
XFEATURE_FP,
18+
XFEATURE_SSE,
19+
XFEATURE_YMM,
20+
XFEATURE_BNDREGS,
21+
XFEATURE_BNDCSR,
22+
XFEATURE_OPMASK,
23+
XFEATURE_ZMM_Hi256,
24+
XFEATURE_Hi16_ZMM,
25+
XFEATURE_PT_UNIMPLEMENTED_SO_FAR,
26+
XFEATURE_PKRU,
27+
XFEATURE_PASID,
28+
XFEATURE_CET_USER,
29+
XFEATURE_CET_KERNEL_UNUSED,
30+
XFEATURE_RSRVD_COMP_13,
31+
XFEATURE_RSRVD_COMP_14,
32+
XFEATURE_LBR,
33+
XFEATURE_RSRVD_COMP_16,
34+
XFEATURE_XTILECFG,
35+
XFEATURE_XTILEDATA,
36+
37+
XFEATURE_MAX,
38+
};
39+
40+
/* Copied from arch/x86/kernel/fpu/xstate.c */
41+
static const char *xfeature_names[] =
42+
{
43+
"x87 floating point registers",
44+
"SSE registers",
45+
"AVX registers",
46+
"MPX bounds registers",
47+
"MPX CSR",
48+
"AVX-512 opmask",
49+
"AVX-512 Hi256",
50+
"AVX-512 ZMM_Hi256",
51+
"Processor Trace (unused)",
52+
"Protection Keys User registers",
53+
"PASID state",
54+
"Control-flow User registers",
55+
"Control-flow Kernel registers (unused)",
56+
"unknown xstate feature",
57+
"unknown xstate feature",
58+
"unknown xstate feature",
59+
"unknown xstate feature",
60+
"AMX Tile config",
61+
"AMX Tile data",
62+
"unknown xstate feature",
63+
};
64+
1265
struct xsave_buffer {
1366
union {
1467
struct {
@@ -58,6 +111,7 @@ static inline uint32_t get_xbuf_size(void)
58111
}
59112

60113
struct xstate_info {
114+
const char *name;
61115
uint32_t num;
62116
uint32_t mask;
63117
uint32_t xbuf_offset;
@@ -69,6 +123,12 @@ static inline struct xstate_info get_xstate_info(uint32_t xfeature_num)
69123
struct xstate_info xstate = { };
70124
uint32_t eax, ebx, ecx, edx;
71125

126+
if (xfeature_num >= XFEATURE_MAX) {
127+
ksft_print_msg("unknown state\n");
128+
return xstate;
129+
}
130+
131+
xstate.name = xfeature_names[xfeature_num];
72132
xstate.num = xfeature_num;
73133
xstate.mask = 1 << xfeature_num;
74134

0 commit comments

Comments
 (0)