OSDN Git Service

x86/fpu/xstate: Add fpstate_realloc()/free()
authorChang S. Bae <chang.seok.bae@intel.com>
Thu, 21 Oct 2021 22:55:22 +0000 (15:55 -0700)
committerBorislav Petkov <bp@suse.de>
Tue, 26 Oct 2021 08:53:02 +0000 (10:53 +0200)
commit500afbf645a040a39e1af0dba2fdf6ebf224bd47
tree31a57a92d06da8df3b4198090d1d1440d37c7184
parent783e87b404956f8958657aed8a6a72aa98d5b7e1
x86/fpu/xstate: Add fpstate_realloc()/free()

The fpstate embedded in struct fpu is the default state for storing the FPU
registers. It's sized so that the default supported features can be stored.
For dynamically enabled features the register buffer is too small.

The #NM handler detects first use of a feature which is disabled in the
XFD MSR. After handling permission checks it recalculates the size for
kernel space and user space state and invokes fpstate_realloc() which
tries to reallocate fpstate and install it.

Provide the allocator function which checks whether the current buffer size
is sufficient and if not allocates one. If allocation is successful the new
fpstate is initialized with the new features and sizes and the now enabled
features is removed from the task's XFD mask.

realloc_fpstate() uses vzalloc(). If use of this mechanism grows to
re-allocate buffers larger than 64KB, a more sophisticated allocation
scheme that includes purpose-built reclaim capability might be justified.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/r/20211021225527.10184-19-chang.seok.bae@intel.com
arch/x86/include/asm/fpu/api.h
arch/x86/kernel/fpu/xstate.c
arch/x86/kernel/process.c