diff mbox series

[RFC,09/10] x86/fpu: copy non-resident FPU state at fork time

Message ID 20180912133353.20595-10-bigeasy@linutronix.de (mailing list archive)
State New, archived
Headers show
Series [RFC,01/10] x86/entry: remove _TIF_ALLWORK_MASK | expand

Commit Message

Sebastian Andrzej Siewior Sept. 12, 2018, 1:33 p.m. UTC
From: Rik van Riel <riel@surriel.com>

If the FPU state is not loaded in registers at fork time, memcpy the
fpstate from the parent task to the child task.

Signed-off-by: Rik van Riel <riel@surriel.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/x86/kernel/fpu/core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 2ea85b32421a0..8564086c217fc 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -210,11 +210,14 @@  int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu)
 	 * ( The function 'fails' in the FNSAVE case, which destroys
 	 *   register contents so we have to copy them back. )
 	 */
-	if (!copy_fpregs_to_fpstate(dst_fpu)) {
+	__fpregs_changes_begin();
+	if (test_thread_flag(TIF_LOAD_FPU)) {
+		memcpy(&src_fpu->state, &dst_fpu->state, fpu_kernel_xstate_size);
+	} else if (!copy_fpregs_to_fpstate(dst_fpu)) {
 		memcpy(&src_fpu->state, &dst_fpu->state, fpu_kernel_xstate_size);
 		copy_kernel_to_fpregs(&src_fpu->state);
 	}
-
+	__fpregs_changes_end();
 	trace_x86_fpu_copy_src(src_fpu);
 	trace_x86_fpu_copy_dst(dst_fpu);