]> git.baikalelectronics.ru Git - kernel.git/commit
x86/fpu: Add kernel_fpu_begin_mask() to selectively initialize state
authorAndy Lutomirski <luto@kernel.org>
Thu, 21 Jan 2021 05:09:48 +0000 (21:09 -0800)
committerBorislav Petkov <bp@suse.de>
Thu, 21 Jan 2021 11:07:28 +0000 (12:07 +0100)
commitfe1a800006673e87534aa518d6be061f876cb1ad
tree881341f1bc988ab97448b9a76f55121e13970252
parent6fd082c9cf4e384739641a55341e6e77f8f416ed
x86/fpu: Add kernel_fpu_begin_mask() to selectively initialize state

Currently, requesting kernel FPU access doesn't distinguish which parts of
the extended ("FPU") state are needed.  This is nice for simplicity, but
there are a few cases in which it's suboptimal:

 - The vast majority of in-kernel FPU users want XMM/YMM/ZMM state but do
   not use legacy 387 state.  These users want MXCSR initialized but don't
   care about the FPU control word.  Skipping FNINIT would save time.
   (Empirically, FNINIT is several times slower than LDMXCSR.)

 - Code that wants MMX doesn't want or need MXCSR initialized.
   _mmx_memcpy(), for example, can run before CR4.OSFXSR gets set, and
   initializing MXCSR will fail because LDMXCSR generates an #UD when the
   aforementioned CR4 bit is not set.

 - Any future in-kernel users of XFD (eXtended Feature Disable)-capable
   dynamic states will need special handling.

Add a more specific API that allows callers to specify exactly what they
want.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Tested-by: Krzysztof Piotr Olędzki <ole@ans.pl>
Link: https://lkml.kernel.org/r/aff1cac8b8fc7ee900cf73e8f2369966621b053f.1611205691.git.luto@kernel.org
arch/x86/include/asm/fpu/api.h
arch/x86/kernel/fpu/core.c