Skip to content

Commit bfc98db

Browse files
ChangSeokBaeIngo Molnar
authored andcommitted
selftests/x86/avx: Add AVX tests
Add xstate testing specifically for those vector register states, validating kernel's context switching and ensuring ABI compliance. Use the established xstate testing framework. Alternatively, this invocation could be placed directly in xstate.c::main(). However, the current test file naming convention, which clearly specifies the tested area, seems reasonable. Adding avx.c considerably aligns with that convention. The test output should be like this for ZMM_Hi256 as an example: $ avx_64 ... [RUN] AVX-512 ZMM_Hi256: check context switches, 10 iterations, 5 threads. [OK] No incorrect case was found. [RUN] AVX-512 ZMM_Hi256: inject xstate via ptrace(). [OK] 'xfeatures' in SW reserved area was correctly written [OK] xstate was correctly updated. [RUN] AVX-512 ZMM_Hi256: load xstate and raise SIGUSR1 [OK] 'magic1' is valid [OK] 'xfeatures' in SW reserved area is valid [OK] 'xfeatures' in XSAVE header is valid [OK] xstate delivery was successful [OK] 'magic2' is valid [RUN] AVX-512 ZMM_Hi256: load new xstate from sighandler and check it after sigreturn [OK] xstate was restored correctly But systems without AVX-512 will look like: ... The kernel does not support feature number: 5 The kernel does not support feature number: 6 The kernel does not support feature number: 7 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-10-chang.seok.bae@intel.com
1 parent fa826c1 commit bfc98db

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

tools/testing/selftests/x86/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ TARGETS_C_32BIT_ONLY := entry_from_vm86 test_syscall_vdso unwind_vdso \
1919
test_FCMOV test_FCOMI test_FISTTP \
2020
vdso_restorer
2121
TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip syscall_numbering \
22-
corrupt_xstate_header amx lam test_shadow_stack
22+
corrupt_xstate_header amx lam test_shadow_stack avx
2323
# Some selftests require 32bit support enabled also on 64bit systems
2424
TARGETS_C_32BIT_NEEDED := ldt_gdt ptrace_syscall
2525

@@ -133,4 +133,6 @@ $(OUTPUT)/check_initial_reg_state_64: CFLAGS += -Wl,-ereal_start -static
133133
$(OUTPUT)/nx_stack_32: CFLAGS += -Wl,-z,noexecstack
134134
$(OUTPUT)/nx_stack_64: CFLAGS += -Wl,-z,noexecstack
135135

136+
$(OUTPUT)/avx_64: CFLAGS += -mno-avx -mno-avx512f
136137
$(OUTPUT)/amx_64: EXTRA_FILES += xstate.c
138+
$(OUTPUT)/avx_64: EXTRA_FILES += xstate.c

tools/testing/selftests/x86/avx.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#define _GNU_SOURCE /* Required for inline xstate helpers */
4+
#include "xstate.h"
5+
6+
int main(void)
7+
{
8+
test_xstate(XFEATURE_YMM);
9+
test_xstate(XFEATURE_OPMASK);
10+
test_xstate(XFEATURE_ZMM_Hi256);
11+
test_xstate(XFEATURE_Hi16_ZMM);
12+
}

0 commit comments

Comments
 (0)