Commit b2681e79 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Borislav Petkov

x86/fpu: Rename and sanitize fpu__save/copy()

Both function names are a misnomer.

fpu__save() is actually about synchronizing the hardware register state
into the task's memory state so that either coredump or a math exception
handler can inspect the state at the time where the problem happens.

The function guarantees to preserve the register state, while "save" is a
common terminology for saving the current state so it can be modified and
restored later. This is clearly not the case here.

Rename it to fpu_sync_fpstate().

fpu__copy() is used to clone the current task's FPU state when duplicating
task_struct. While the register state is a copy the rest of the FPU state
is not.

Name it accordingly and remove the really pointless @src argument along
with the warning which comes along with it.

Nothing can ever copy the FPU state of a non-current task. It's clearly
just a consequence of arch_dup_task_struct(), but it makes no sense to
proliferate that further.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Reviewed-by: default avatarBorislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210623121455.196727450@linutronix.de
parent 784a4661
...@@ -26,14 +26,16 @@ ...@@ -26,14 +26,16 @@
/* /*
* High level FPU state handling functions: * High level FPU state handling functions:
*/ */
extern void fpu__save(struct fpu *fpu);
extern int fpu__restore_sig(void __user *buf, int ia32_frame); extern int fpu__restore_sig(void __user *buf, int ia32_frame);
extern void fpu__drop(struct fpu *fpu); extern void fpu__drop(struct fpu *fpu);
extern int fpu__copy(struct task_struct *dst, struct task_struct *src);
extern void fpu__clear_user_states(struct fpu *fpu); extern void fpu__clear_user_states(struct fpu *fpu);
extern void fpu__clear_all(struct fpu *fpu); extern void fpu__clear_all(struct fpu *fpu);
extern int fpu__exception_code(struct fpu *fpu, int trap_nr); extern int fpu__exception_code(struct fpu *fpu, int trap_nr);
extern void fpu_sync_fpstate(struct fpu *fpu);
extern int fpu_clone(struct task_struct *dst);
/* /*
* Boot time FPU initialization functions: * Boot time FPU initialization functions:
*/ */
......
...@@ -159,11 +159,10 @@ void kernel_fpu_end(void) ...@@ -159,11 +159,10 @@ void kernel_fpu_end(void)
EXPORT_SYMBOL_GPL(kernel_fpu_end); EXPORT_SYMBOL_GPL(kernel_fpu_end);
/* /*
* Save the FPU state (mark it for reload if necessary): * Sync the FPU register state to current's memory register state when the
* * current task owns the FPU. The hardware register state is preserved.
* This only ever gets called for the current task.
*/ */
void fpu__save(struct fpu *fpu) void fpu_sync_fpstate(struct fpu *fpu)
{ {
WARN_ON_FPU(fpu != &current->thread.fpu); WARN_ON_FPU(fpu != &current->thread.fpu);
...@@ -221,18 +220,18 @@ void fpstate_init(union fpregs_state *state) ...@@ -221,18 +220,18 @@ void fpstate_init(union fpregs_state *state)
} }
EXPORT_SYMBOL_GPL(fpstate_init); EXPORT_SYMBOL_GPL(fpstate_init);
int fpu__copy(struct task_struct *dst, struct task_struct *src) /* Clone current's FPU state on fork */
int fpu_clone(struct task_struct *dst)
{ {
struct fpu *src_fpu = &current->thread.fpu;
struct fpu *dst_fpu = &dst->thread.fpu; struct fpu *dst_fpu = &dst->thread.fpu;
struct fpu *src_fpu = &src->thread.fpu;
/* The new task's FPU state cannot be valid in the hardware. */
dst_fpu->last_cpu = -1; dst_fpu->last_cpu = -1;
if (!static_cpu_has(X86_FEATURE_FPU)) if (!cpu_feature_enabled(X86_FEATURE_FPU))
return 0; return 0;
WARN_ON_FPU(src_fpu != &current->thread.fpu);
/* /*
* Don't let 'init optimized' areas of the XSAVE area * Don't let 'init optimized' areas of the XSAVE area
* leak into the child task: * leak into the child task:
......
...@@ -41,7 +41,7 @@ int regset_xregset_fpregs_active(struct task_struct *target, const struct user_r ...@@ -41,7 +41,7 @@ int regset_xregset_fpregs_active(struct task_struct *target, const struct user_r
static void sync_fpstate(struct fpu *fpu) static void sync_fpstate(struct fpu *fpu)
{ {
if (fpu == &current->thread.fpu) if (fpu == &current->thread.fpu)
fpu__save(fpu); fpu_sync_fpstate(fpu);
} }
/* /*
......
...@@ -87,8 +87,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) ...@@ -87,8 +87,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
#ifdef CONFIG_VM86 #ifdef CONFIG_VM86
dst->thread.vm86 = NULL; dst->thread.vm86 = NULL;
#endif #endif
return fpu_clone(dst);
return fpu__copy(dst, src);
} }
/* /*
......
...@@ -1046,9 +1046,10 @@ static void math_error(struct pt_regs *regs, int trapnr) ...@@ -1046,9 +1046,10 @@ static void math_error(struct pt_regs *regs, int trapnr)
} }
/* /*
* Save the info for the exception handler and clear the error. * Synchronize the FPU register state to the memory register state
* if necessary. This allows the exception handler to inspect it.
*/ */
fpu__save(fpu); fpu_sync_fpstate(fpu);
task->thread.trap_nr = trapnr; task->thread.trap_nr = trapnr;
task->thread.error_code = 0; task->thread.error_code = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment