selftests/x86/amx: Add test cases for AMX state management
authorChang S. Bae <chang.seok.bae@intel.com>
Tue, 26 Oct 2021 12:25:24 +0000 (05:25 -0700)
committerBorislav Petkov <bp@suse.de>
Thu, 28 Oct 2021 12:35:27 +0000 (14:35 +0200)
commit6a3e0651b4a00daa314c59d6e4228dfa7a986983
treee76af3abe0f57c4d9dc67be5d07a2d8a3dd4e45f
parent2308ee57d93d896618dd65c996429c9d3e469fe0
selftests/x86/amx: Add test cases for AMX state management

AMX TILEDATA is a very large XSAVE feature.  It could have caused
nasty XSAVE buffer space waste in two places:

 * Signal stacks
 * Kernel task_struct->fpu buffers

To avoid this waste, neither of these buffers have AMX state by
default.  The non-default features are called "dynamic" features.

There is an arch_prctl(ARCH_REQ_XCOMP_PERM) which allows a task
to declare that it wants to use AMX or other "dynamic" XSAVE
features.  This arch_prctl() ensures that sufficient sigaltstack
space is available before it will succeed.  It also expands the
task_struct buffer.

Functions of this test:
 * Test arch_prctl(ARCH_REQ_XCOMP_PERM).  Ensure that it checks for
   proper sigaltstack sizing and that the sizing is enforced for
   future sigaltstack calls.
 * Ensure that ARCH_REQ_XCOMP_PERM is inherited across fork()
 * Ensure that TILEDATA use before the prctl() is fatal
 * Ensure that TILEDATA is cleared across fork()

Note: Generally, compiler support is needed to do something with
AMX.  Instead, directly load AMX state from userspace with a
plain XSAVE.  Do not depend on the compiler.

 [ dhansen: bunches of cleanups ]

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20211026122524.7BEDAA95@davehans-spike.ostc.intel.com
tools/testing/selftests/x86/Makefile
tools/testing/selftests/x86/amx.c [new file with mode: 0644]