aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/arch/x86/kernel/fpu/core.c
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2021-10-13 16:55:27 +0200
committerBorislav Petkov <bp@suse.de>2021-10-20 22:26:24 +0200
commit87d0e5be0fac322f4415128def9f16a71a267a40 (patch)
tree5d7e073a11499c4c65dab2e15e503a5123464e2e /arch/x86/kernel/fpu/core.c
parentx86/fpu: Replace KVMs home brewed FPU copy to user (diff)
downloadwireguard-linux-87d0e5be0fac322f4415128def9f16a71a267a40.tar.xz
wireguard-linux-87d0e5be0fac322f4415128def9f16a71a267a40.zip
x86/fpu: Provide struct fpstate
New xfeatures will not longer be automatically stored in the regular XSAVE buffer in thread_struct::fpu. The kernel will provide the default sized buffer for storing the regular features up to AVX512 in thread_struct::fpu and if a task requests to use one of the new features then the register storage has to be extended. The state will be accessed via a pointer in thread_struct::fpu which defaults to the builtin storage and can be switched when extended storage is required. To avoid conditionals all over the code, create a new container for the register storage which will gain other information, e.g. size, feature masks etc., later. For now it just contains the register storage, which gives it exactly the same layout as the exiting fpu::state. Stick fpu::state and the new fpu::__fpstate into an anonymous union and initialize the pointer. Add build time checks to validate that both are at the same place and have the same size. This allows step by step conversion of all users. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lkml.kernel.org/r/20211013145322.234458659@linutronix.de
Diffstat (limited to 'arch/x86/kernel/fpu/core.c')
-rw-r--r--arch/x86/kernel/fpu/core.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index ac540a7d410e..d7643115a7ee 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -337,10 +337,17 @@ void fpstate_init_user(union fpregs_state *state)
fpstate_init_fstate(&state->fsave);
}
+void fpstate_reset(struct fpu *fpu)
+{
+ /* Set the fpstate pointer to the default fpstate */
+ fpu->fpstate = &fpu->__fpstate;
+}
+
#if IS_ENABLED(CONFIG_KVM)
void fpu_init_fpstate_user(struct fpu *fpu)
{
- fpstate_init_user(&fpu->state);
+ fpstate_reset(fpu);
+ fpstate_init_user(&fpu->fpstate->regs);
}
EXPORT_SYMBOL_GPL(fpu_init_fpstate_user);
#endif
@@ -354,6 +361,8 @@ int fpu_clone(struct task_struct *dst)
/* The new task's FPU state cannot be valid in the hardware. */
dst_fpu->last_cpu = -1;
+ fpstate_reset(dst_fpu);
+
if (!cpu_feature_enabled(X86_FEATURE_FPU))
return 0;