summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2015-04-23 06:46:20 -0400
committerIngo Molnar <mingo@kernel.org>2015-05-19 09:47:24 -0400
commit4c1384100ebf51651d02430a7f70661ef1ef06ac (patch)
treea1c942ae45d43be4f34cf463fb33c54c781d7e3d
parent4540d3faa7c3fca6a6125448861de0e2e485658b (diff)
x86/fpu: Open code PF_USED_MATH usages
PF_USED_MATH is used directly, but also in a handful of helper inlines. To ease the elimination of PF_USED_MATH, convert all inline helpers to open-coded PF_USED_MATH usage. Reviewed-by: Borislav Petkov <bp@alien8.de> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/ia32/ia32_signal.c2
-rw-r--r--arch/x86/include/asm/fpu-internal.h5
-rw-r--r--arch/x86/kernel/fpu/core.c14
-rw-r--r--arch/x86/kernel/fpu/xsave.c10
-rw-r--r--arch/x86/kernel/signal.c6
-rw-r--r--arch/x86/kvm/x86.c2
-rw-r--r--arch/x86/math-emu/fpu_entry.c2
7 files changed, 22 insertions, 19 deletions
diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
index 4bafd5b05aca..bffb2c49ceb6 100644
--- a/arch/x86/ia32/ia32_signal.c
+++ b/arch/x86/ia32/ia32_signal.c
@@ -321,7 +321,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
321 ksig->ka.sa.sa_restorer) 321 ksig->ka.sa.sa_restorer)
322 sp = (unsigned long) ksig->ka.sa.sa_restorer; 322 sp = (unsigned long) ksig->ka.sa.sa_restorer;
323 323
324 if (used_math()) { 324 if (current->flags & PF_USED_MATH) {
325 unsigned long fx_aligned, math_size; 325 unsigned long fx_aligned, math_size;
326 326
327 sp = alloc_mathframe(sp, 1, &fx_aligned, &math_size); 327 sp = alloc_mathframe(sp, 1, &fx_aligned, &math_size);
diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
index 44516ad6c890..2cac49e3b4bd 100644
--- a/arch/x86/include/asm/fpu-internal.h
+++ b/arch/x86/include/asm/fpu-internal.h
@@ -375,7 +375,8 @@ static inline void drop_fpu(struct task_struct *tsk)
375 __thread_fpu_end(fpu); 375 __thread_fpu_end(fpu);
376 } 376 }
377 377
378 clear_stopped_child_used_math(tsk); 378 tsk->flags &= ~PF_USED_MATH;
379
379 preempt_enable(); 380 preempt_enable();
380} 381}
381 382
@@ -423,7 +424,7 @@ static inline fpu_switch_t switch_fpu_prepare(struct task_struct *old, struct ta
423 * If the task has used the math, pre-load the FPU on xsave processors 424 * If the task has used the math, pre-load the FPU on xsave processors
424 * or if the past 5 consecutive context-switches used math. 425 * or if the past 5 consecutive context-switches used math.
425 */ 426 */
426 fpu.preload = tsk_used_math(new) && 427 fpu.preload = (new->flags & PF_USED_MATH) &&
427 (use_eager_fpu() || new->thread.fpu.counter > 5); 428 (use_eager_fpu() || new->thread.fpu.counter > 5);
428 429
429 if (old_fpu->has_fpu) { 430 if (old_fpu->has_fpu) {
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index cf49cd574d32..90f624d68b26 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -242,7 +242,7 @@ int fpu__copy(struct task_struct *dst, struct task_struct *src)
242 242
243 task_disable_lazy_fpu_restore(dst); 243 task_disable_lazy_fpu_restore(dst);
244 244
245 if (tsk_used_math(src)) { 245 if (src->flags & PF_USED_MATH) {
246 int err = fpstate_alloc(&dst->thread.fpu); 246 int err = fpstate_alloc(&dst->thread.fpu);
247 247
248 if (err) 248 if (err)
@@ -331,7 +331,7 @@ void fpu__restore(void)
331 struct task_struct *tsk = current; 331 struct task_struct *tsk = current;
332 struct fpu *fpu = &tsk->thread.fpu; 332 struct fpu *fpu = &tsk->thread.fpu;
333 333
334 if (!tsk_used_math(tsk)) { 334 if (!(tsk->flags & PF_USED_MATH)) {
335 local_irq_enable(); 335 local_irq_enable();
336 /* 336 /*
337 * does a slab alloc which can sleep 337 * does a slab alloc which can sleep
@@ -361,12 +361,14 @@ EXPORT_SYMBOL_GPL(fpu__restore);
361 361
362void fpu__flush_thread(struct task_struct *tsk) 362void fpu__flush_thread(struct task_struct *tsk)
363{ 363{
364 WARN_ON(tsk != current);
365
364 if (!use_eager_fpu()) { 366 if (!use_eager_fpu()) {
365 /* FPU state will be reallocated lazily at the first use. */ 367 /* FPU state will be reallocated lazily at the first use. */
366 drop_fpu(tsk); 368 drop_fpu(tsk);
367 fpstate_free(&tsk->thread.fpu); 369 fpstate_free(&tsk->thread.fpu);
368 } else { 370 } else {
369 if (!tsk_used_math(tsk)) { 371 if (!(tsk->flags & PF_USED_MATH)) {
370 /* kthread execs. TODO: cleanup this horror. */ 372 /* kthread execs. TODO: cleanup this horror. */
371 if (WARN_ON(fpstate_alloc_init(tsk))) 373 if (WARN_ON(fpstate_alloc_init(tsk)))
372 force_sig(SIGKILL, tsk); 374 force_sig(SIGKILL, tsk);
@@ -383,12 +385,12 @@ void fpu__flush_thread(struct task_struct *tsk)
383 */ 385 */
384int fpregs_active(struct task_struct *target, const struct user_regset *regset) 386int fpregs_active(struct task_struct *target, const struct user_regset *regset)
385{ 387{
386 return tsk_used_math(target) ? regset->n : 0; 388 return (target->flags & PF_USED_MATH) ? regset->n : 0;
387} 389}
388 390
389int xfpregs_active(struct task_struct *target, const struct user_regset *regset) 391int xfpregs_active(struct task_struct *target, const struct user_regset *regset)
390{ 392{
391 return (cpu_has_fxsr && tsk_used_math(target)) ? regset->n : 0; 393 return (cpu_has_fxsr && (target->flags & PF_USED_MATH)) ? regset->n : 0;
392} 394}
393 395
394int xfpregs_get(struct task_struct *target, const struct user_regset *regset, 396int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
@@ -719,7 +721,7 @@ int dump_fpu(struct pt_regs *regs, struct user_i387_struct *fpu)
719 struct task_struct *tsk = current; 721 struct task_struct *tsk = current;
720 int fpvalid; 722 int fpvalid;
721 723
722 fpvalid = !!used_math(); 724 fpvalid = !!(tsk->flags & PF_USED_MATH);
723 if (fpvalid) 725 if (fpvalid)
724 fpvalid = !fpregs_get(tsk, NULL, 726 fpvalid = !fpregs_get(tsk, NULL,
725 0, sizeof(struct user_i387_ia32_struct), 727 0, sizeof(struct user_i387_ia32_struct),
diff --git a/arch/x86/kernel/fpu/xsave.c b/arch/x86/kernel/fpu/xsave.c
index 61696c5005eb..8cd127049c9b 100644
--- a/arch/x86/kernel/fpu/xsave.c
+++ b/arch/x86/kernel/fpu/xsave.c
@@ -349,7 +349,7 @@ int __restore_xstate_sig(void __user *buf, void __user *buf_fx, int size)
349 if (!access_ok(VERIFY_READ, buf, size)) 349 if (!access_ok(VERIFY_READ, buf, size))
350 return -EACCES; 350 return -EACCES;
351 351
352 if (!used_math() && fpstate_alloc_init(tsk)) 352 if (!(tsk->flags & PF_USED_MATH) && fpstate_alloc_init(tsk))
353 return -1; 353 return -1;
354 354
355 if (!static_cpu_has(X86_FEATURE_FPU)) 355 if (!static_cpu_has(X86_FEATURE_FPU))
@@ -384,12 +384,12 @@ int __restore_xstate_sig(void __user *buf, void __user *buf_fx, int size)
384 int err = 0; 384 int err = 0;
385 385
386 /* 386 /*
387 * Drop the current fpu which clears used_math(). This ensures 387 * Drop the current fpu which clears PF_USED_MATH. This ensures
388 * that any context-switch during the copy of the new state, 388 * that any context-switch during the copy of the new state,
389 * avoids the intermediate state from getting restored/saved. 389 * avoids the intermediate state from getting restored/saved.
390 * Thus avoiding the new restored state from getting corrupted. 390 * Thus avoiding the new restored state from getting corrupted.
391 * We will be ready to restore/save the state only after 391 * We will be ready to restore/save the state only after
392 * set_used_math() is again set. 392 * PF_USED_MATH is again set.
393 */ 393 */
394 drop_fpu(tsk); 394 drop_fpu(tsk);
395 395
@@ -401,7 +401,7 @@ int __restore_xstate_sig(void __user *buf, void __user *buf_fx, int size)
401 sanitize_restored_xstate(tsk, &env, xstate_bv, fx_only); 401 sanitize_restored_xstate(tsk, &env, xstate_bv, fx_only);
402 } 402 }
403 403
404 set_used_math(); 404 tsk->flags |= PF_USED_MATH;
405 if (use_eager_fpu()) { 405 if (use_eager_fpu()) {
406 preempt_disable(); 406 preempt_disable();
407 fpu__restore(); 407 fpu__restore();
@@ -685,7 +685,7 @@ void xsave_init(void)
685 */ 685 */
686void __init_refok eager_fpu_init(void) 686void __init_refok eager_fpu_init(void)
687{ 687{
688 WARN_ON(used_math()); 688 WARN_ON(current->flags & PF_USED_MATH);
689 current_thread_info()->status = 0; 689 current_thread_info()->status = 0;
690 690
691 if (eagerfpu == ENABLE) 691 if (eagerfpu == ENABLE)
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index 35f867aa597e..8e2529ebb8c6 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -217,7 +217,7 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
217 } 217 }
218 } 218 }
219 219
220 if (used_math()) { 220 if (current->flags & PF_USED_MATH) {
221 sp = alloc_mathframe(sp, config_enabled(CONFIG_X86_32), 221 sp = alloc_mathframe(sp, config_enabled(CONFIG_X86_32),
222 &buf_fx, &math_size); 222 &buf_fx, &math_size);
223 *fpstate = (void __user *)sp; 223 *fpstate = (void __user *)sp;
@@ -233,7 +233,7 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
233 return (void __user *)-1L; 233 return (void __user *)-1L;
234 234
235 /* save i387 and extended state */ 235 /* save i387 and extended state */
236 if (used_math() && 236 if ((current->flags & PF_USED_MATH) &&
237 save_xstate_sig(*fpstate, (void __user *)buf_fx, math_size) < 0) 237 save_xstate_sig(*fpstate, (void __user *)buf_fx, math_size) < 0)
238 return (void __user *)-1L; 238 return (void __user *)-1L;
239 239
@@ -664,7 +664,7 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs)
664 /* 664 /*
665 * Ensure the signal handler starts with the new fpu state. 665 * Ensure the signal handler starts with the new fpu state.
666 */ 666 */
667 if (used_math()) 667 if (current->flags & PF_USED_MATH)
668 fpu_reset_state(current); 668 fpu_reset_state(current);
669 } 669 }
670 signal_setup_done(failed, ksig, stepping); 670 signal_setup_done(failed, ksig, stepping);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index be276e0fe0ff..0635a1fd43ba 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6600,7 +6600,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
6600 int r; 6600 int r;
6601 sigset_t sigsaved; 6601 sigset_t sigsaved;
6602 6602
6603 if (!tsk_used_math(current) && fpstate_alloc_init(current)) 6603 if (!(current->flags & PF_USED_MATH) && fpstate_alloc_init(current))
6604 return -ENOMEM; 6604 return -ENOMEM;
6605 6605
6606 if (vcpu->sigset_active) 6606 if (vcpu->sigset_active)
diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
index c9ff09a02385..bf628804d67c 100644
--- a/arch/x86/math-emu/fpu_entry.c
+++ b/arch/x86/math-emu/fpu_entry.c
@@ -148,7 +148,7 @@ void math_emulate(struct math_emu_info *info)
148 unsigned long code_limit = 0; /* Initialized to stop compiler warnings */ 148 unsigned long code_limit = 0; /* Initialized to stop compiler warnings */
149 struct desc_struct code_descriptor; 149 struct desc_struct code_descriptor;
150 150
151 if (!used_math()) { 151 if (!(current->flags & PF_USED_MATH)) {
152 if (fpstate_alloc_init(current)) { 152 if (fpstate_alloc_init(current)) {
153 do_group_exit(SIGKILL); 153 do_group_exit(SIGKILL);
154 return; 154 return;