x86/fpu/xsave: Handle compacted offsets correctly with supervisor states
authorThomas Gleixner <tglx@linutronix.de>
Thu, 24 Mar 2022 13:47:13 +0000 (14:47 +0100)
committerBorislav Petkov <bp@suse.de>
Wed, 30 Mar 2022 09:20:36 +0000 (11:20 +0200)
commit7aa5128b5fea26cf224766303ea3b8df343f9a87
tree9eccf1ad56132fdf3808af0514650a2bedf31712
parent6afbb58cc2251c1d83472ca3005638206e73b6b8
x86/fpu/xsave: Handle compacted offsets correctly with supervisor states

So far the cached fixed compacted offsets worked, but with (re-)enabling
of ENQCMD this does no longer work with KVM fpstate.

KVM does not have supervisor features enabled for the guest FPU, which
means that KVM has then a different XSAVE area layout than the host FPU
state. This in turn breaks the copy from/to UABI functions when invoked for
a guest state.

Remove the pre-calculated compacted offsets and calculate the offset
of each component at runtime based on the XCOMP_BV field in the XSAVE
header.

The runtime overhead is not interesting because these copy from/to UABI
functions are not used in critical fast paths. KVM uses them to save and
restore FPU state during migration. The host uses them for ptrace and for
the slow path of 32bit signal handling.

Fixes: 7c1ef59145f1 ("x86/cpufeatures: Re-enable ENQCMD")
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/r/20220324134623.627636809@linutronix.de
arch/x86/kernel/fpu/xstate.c