x86/fpu/xsave: Support XSAVEC in the kernel
authorThomas Gleixner <tglx@linutronix.de>
Mon, 4 Apr 2022 12:11:25 +0000 (14:11 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Mon, 25 Apr 2022 13:05:37 +0000 (15:05 +0200)
commit8ad7e8f696951f192c6629a0cbda9ac94c773159
tree4031df2db6fbb38b765b6b42a79533ef96c4d85c
parentaf2d861d4cd2a4da5137f795ee3509e6f944a25b
x86/fpu/xsave: Support XSAVEC in the kernel

XSAVEC is the user space counterpart of XSAVES which cannot save supervisor
state. In virtualization scenarios the hypervisor does not expose XSAVES
but XSAVEC to the guest, though the kernel does not make use of it.

That's unfortunate because XSAVEC uses the compacted format of saving the
XSTATE. This is more efficient in terms of storage space vs. XSAVE[OPT] as
it does not create holes for XSTATE components which are not supported or
enabled by the kernel but are available in hardware. There is room for
further optimizations when XSAVEC/S and XGETBV1 are supported.

In order to support XSAVEC:

 - Define the XSAVEC ASM macro as it's not yet supported by the required
   minimal toolchain.

 - Create a software defined X86_FEATURE_XCOMPACTED to select the compacted
   XSTATE buffer format for both XSAVEC and XSAVES.

 - Make XSAVEC an option in the 'XSAVE' ASM alternatives

Requested-by: Andrew Cooper <Andrew.Cooper3@citrix.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20220404104820.598704095@linutronix.de
arch/x86/include/asm/cpufeatures.h
arch/x86/kernel/fpu/xstate.c
arch/x86/kernel/fpu/xstate.h