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>
This commit is contained in:
Ingo Molnar
2015-04-23 12:46:20 +02:00
parent 4540d3faa7
commit 4c1384100e
7 changed files with 22 additions and 19 deletions

View File

@@ -242,7 +242,7 @@ int fpu__copy(struct task_struct *dst, struct task_struct *src)
task_disable_lazy_fpu_restore(dst);
if (tsk_used_math(src)) {
if (src->flags & PF_USED_MATH) {
int err = fpstate_alloc(&dst->thread.fpu);
if (err)
@@ -331,7 +331,7 @@ void fpu__restore(void)
struct task_struct *tsk = current;
struct fpu *fpu = &tsk->thread.fpu;
if (!tsk_used_math(tsk)) {
if (!(tsk->flags & PF_USED_MATH)) {
local_irq_enable();
/*
* does a slab alloc which can sleep
@@ -361,12 +361,14 @@ EXPORT_SYMBOL_GPL(fpu__restore);
void fpu__flush_thread(struct task_struct *tsk)
{
WARN_ON(tsk != current);
if (!use_eager_fpu()) {
/* FPU state will be reallocated lazily at the first use. */
drop_fpu(tsk);
fpstate_free(&tsk->thread.fpu);
} else {
if (!tsk_used_math(tsk)) {
if (!(tsk->flags & PF_USED_MATH)) {
/* kthread execs. TODO: cleanup this horror. */
if (WARN_ON(fpstate_alloc_init(tsk)))
force_sig(SIGKILL, tsk);
@@ -383,12 +385,12 @@ void fpu__flush_thread(struct task_struct *tsk)
*/
int fpregs_active(struct task_struct *target, const struct user_regset *regset)
{
return tsk_used_math(target) ? regset->n : 0;
return (target->flags & PF_USED_MATH) ? regset->n : 0;
}
int xfpregs_active(struct task_struct *target, const struct user_regset *regset)
{
return (cpu_has_fxsr && tsk_used_math(target)) ? regset->n : 0;
return (cpu_has_fxsr && (target->flags & PF_USED_MATH)) ? regset->n : 0;
}
int 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)
struct task_struct *tsk = current;
int fpvalid;
fpvalid = !!used_math();
fpvalid = !!(tsk->flags & PF_USED_MATH);
if (fpvalid)
fpvalid = !fpregs_get(tsk, NULL,
0, sizeof(struct user_i387_ia32_struct),

View File

@@ -349,7 +349,7 @@ int __restore_xstate_sig(void __user *buf, void __user *buf_fx, int size)
if (!access_ok(VERIFY_READ, buf, size))
return -EACCES;
if (!used_math() && fpstate_alloc_init(tsk))
if (!(tsk->flags & PF_USED_MATH) && fpstate_alloc_init(tsk))
return -1;
if (!static_cpu_has(X86_FEATURE_FPU))
@@ -384,12 +384,12 @@ int __restore_xstate_sig(void __user *buf, void __user *buf_fx, int size)
int err = 0;
/*
* Drop the current fpu which clears used_math(). This ensures
* Drop the current fpu which clears PF_USED_MATH. This ensures
* that any context-switch during the copy of the new state,
* avoids the intermediate state from getting restored/saved.
* Thus avoiding the new restored state from getting corrupted.
* We will be ready to restore/save the state only after
* set_used_math() is again set.
* PF_USED_MATH is again set.
*/
drop_fpu(tsk);
@@ -401,7 +401,7 @@ int __restore_xstate_sig(void __user *buf, void __user *buf_fx, int size)
sanitize_restored_xstate(tsk, &env, xstate_bv, fx_only);
}
set_used_math();
tsk->flags |= PF_USED_MATH;
if (use_eager_fpu()) {
preempt_disable();
fpu__restore();
@@ -685,7 +685,7 @@ void xsave_init(void)
*/
void __init_refok eager_fpu_init(void)
{
WARN_ON(used_math());
WARN_ON(current->flags & PF_USED_MATH);
current_thread_info()->status = 0;
if (eagerfpu == ENABLE)