aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/process.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2014-09-02 13:57:23 -0400
committerH. Peter Anvin <hpa@linux.intel.com>2014-09-02 17:51:16 -0400
commitf1853505d9ca1c3ea27c29cf83c24661531c527b (patch)
tree724f80f438400a192baba1ef9c28119475894ba8 /arch/x86/kernel/process.c
parent31d963389f67165402aa447a8e8ce5ffb9188b3d (diff)
x86, fpu: copy_process: Avoid fpu_alloc/copy if !used_math()
arch_dup_task_struct() copies thread.fpu if fpu_allocated(), this looks suboptimal and misleading. Say, a forking process could use FPU only once in a signal handler but now tsk_used_math(src) == F, in this case the child gets a copy of fpu->state for no reason. The child won't use the saved registers anyway even if it starts to use FPU, this can only avoid fpu_alloc() in do_device_not_available(). Change this code to check tsk_used_math(current) instead. We still need to clear fpu->has_fpu/state, we could do this memset(0) under fpu_allocated() check but I think this doesn't make sense. See also the next change. use_eager_fpu() assumes that fpu_allocated() is always true, but a forking task (and thus its child) must always have PF_USED_MATH set, otherwise the child can either use FPU without used_math() (note that switch_fpu_prepare() doesn't do stts() in this case), or it will be killed by do_device_not_available()->BUG_ON(use_eager_fpu). Signed-off-by: Oleg Nesterov <oleg@redhat.com> Link: http://lkml.kernel.org/r/20140902175723.GA21659@redhat.com Reviewed-by: Suresh Siddha <sbsiddha@gmail.com> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'arch/x86/kernel/process.c')
-rw-r--r--arch/x86/kernel/process.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index f804dc935d2a..b9ba9d52020e 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -64,14 +64,13 @@ EXPORT_SYMBOL_GPL(task_xstate_cachep);
64 */ 64 */
65int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) 65int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
66{ 66{
67 int ret;
68
69 *dst = *src; 67 *dst = *src;
70 if (fpu_allocated(&src->thread.fpu)) { 68
71 memset(&dst->thread.fpu, 0, sizeof(dst->thread.fpu)); 69 memset(&dst->thread.fpu, 0, sizeof(dst->thread.fpu));
72 ret = fpu_alloc(&dst->thread.fpu); 70 if (tsk_used_math(src)) {
73 if (ret) 71 int err = fpu_alloc(&dst->thread.fpu);
74 return ret; 72 if (err)
73 return err;
75 fpu_copy(dst, src); 74 fpu_copy(dst, src);
76 } 75 }
77 return 0; 76 return 0;