fpu_kern_enter(FPU_KERN_NOCTX) loaded the complete initial FPU state
with XRSTOR, to give the section a known state to start from. That
is the most expensive part of a section which is supposed to be short:
on an Atom C1110 an enter and leave pair takes 984 cycles, of which
more than 700 are the XRSTOR.
The consumers of FPU_KERN_NOCTX are SSE and AVX code, for which the
only control state that matters is MXCSR. Load the default MXCSR and
leave the data registers alone, the same as for a function called
according to the ABI. The upper halves of the %ymm registers are
cleared with VZEROUPPER, so that code using legacy SSE encodings does
not pay the SSE/AVX transition penalty for what the previous user of
the FPU left there. The pair takes 255 cycles then.
The x87 state is not initialized. The only consumer that depends on
it is the EFI runtime, where the calling convention requires the
default x87 control word. Do FNINIT in efi_arch_enter().
Register content left by another thread is visible only to the kernel
code in the section. A thread which takes the ownership of the FPU
afterwards always gets its complete state loaded with XRSTOR. For the
same reason the XSAVEOPT tracking, which the removed comment was about,
is not affected: nothing is saved while fpcurthread is NULL.
PKRU is not involved, it is switched with the thread.
Sponsored by: Rubicon Communications, LLC ("Netgate")