Skip to content

Commit 99c8431

Browse files
musamaanjumIngo Molnar
authored andcommitted
x86/selftests: Skip the tests if prerequisites aren't fulfilled
Skip instead of failing when prerequisite conditions aren't fulfilled, such as invalid xstate values etc. Make the tests show as 'SKIP' when run: make -C tools/testing/selftests/ TARGETS=x86 run_tests ... # timeout set to 45 # selftests: x86: amx_64 # # xstate cpuid: invalid tile data size/offset: 0/0 ok 42 selftests: x86: amx_64 # SKIP # timeout set to 45 # selftests: x86: lam_64 # # Unsupported LAM feature! ok 43 selftests: x86: lam_64 # SKIP ... In the AMX test, Move away from check_cpuid_xsave() and start using arch_prctl() to find out if AMX support is present or not. In the kernels where AMX isn't present, arch_prctl() returns -EINVAL, hence it is backward compatible. Signed-off-by: Muhammad Usama Anjum <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Chang S. Bae <[email protected]> Reviewed-by: Binbin Wu <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent cd2236c commit 99c8431

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

tools/testing/selftests/x86/amx.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,6 @@ static void clearhandler(int sig)
103103

104104
#define CPUID_LEAF1_ECX_XSAVE_MASK (1 << 26)
105105
#define CPUID_LEAF1_ECX_OSXSAVE_MASK (1 << 27)
106-
static inline void check_cpuid_xsave(void)
107-
{
108-
uint32_t eax, ebx, ecx, edx;
109-
110-
/*
111-
* CPUID.1:ECX.XSAVE[bit 26] enumerates general
112-
* support for the XSAVE feature set, including
113-
* XGETBV.
114-
*/
115-
__cpuid_count(1, 0, eax, ebx, ecx, edx);
116-
if (!(ecx & CPUID_LEAF1_ECX_XSAVE_MASK))
117-
fatal_error("cpuid: no CPU xsave support");
118-
if (!(ecx & CPUID_LEAF1_ECX_OSXSAVE_MASK))
119-
fatal_error("cpuid: no OS xsave support");
120-
}
121106

122107
static uint32_t xbuf_size;
123108

@@ -350,6 +335,7 @@ enum expected_result { FAIL_EXPECTED, SUCCESS_EXPECTED };
350335

351336
/* arch_prctl() and sigaltstack() test */
352337

338+
#define ARCH_GET_XCOMP_SUPP 0x1021
353339
#define ARCH_GET_XCOMP_PERM 0x1022
354340
#define ARCH_REQ_XCOMP_PERM 0x1023
355341

@@ -928,8 +914,15 @@ static void test_ptrace(void)
928914

929915
int main(void)
930916
{
931-
/* Check hardware availability at first */
932-
check_cpuid_xsave();
917+
unsigned long features;
918+
long rc;
919+
920+
rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features);
921+
if (rc || (features & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE) {
922+
ksft_print_msg("no AMX support\n");
923+
return KSFT_SKIP;
924+
}
925+
933926
check_cpuid_xtiledata();
934927

935928
init_stashed_xsave();

tools/testing/selftests/x86/lam.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ int main(int argc, char **argv)
11831183

11841184
if (!cpu_has_lam()) {
11851185
ksft_print_msg("Unsupported LAM feature!\n");
1186-
return -1;
1186+
return KSFT_SKIP;
11871187
}
11881188

11891189
while ((c = getopt(argc, argv, "ht:")) != -1) {

0 commit comments

Comments
 (0)