aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRik van Riel <riel@redhat.com>2016-10-04 20:34:36 -0400
committerIngo Molnar <mingo@kernel.org>2016-10-07 05:14:41 -0400
commit25d83b531c1aa4fca5b4e24ed10f493268f162bc (patch)
treeaeaef82d1ac996baa447d673ccda72225ca2e993
parent3d42de25d290fdfe604835d1b389845b8cba5bff (diff)
x86/fpu: Rename lazy restore functions to "register state valid"
Name the functions after the state they track, rather than the function they currently enable. This should make it more obvious when we use the fpu_register_state_valid() function for something else in the future. Signed-off-by: Rik van Riel <riel@redhat.com> Reviewed-by: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: pbonzini@redhat.com Link: http://lkml.kernel.org/r/1475627678-20788-8-git-send-email-riel@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/include/asm/fpu/internal.h26
-rw-r--r--arch/x86/kernel/fpu/core.c4
-rw-r--r--arch/x86/kernel/smpboot.c2
3 files changed, 23 insertions, 9 deletions
diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h
index 499d6ed0e376..d2cfe16dd9fa 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -479,18 +479,32 @@ extern int copy_fpstate_to_sigframe(void __user *buf, void __user *fp, int size)
479DECLARE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx); 479DECLARE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
480 480
481/* 481/*
482 * The in-register FPU state for an FPU context on a CPU is assumed to be
483 * valid if the fpu->last_cpu matches the CPU, and the fpu_fpregs_owner_ctx
484 * matches the FPU.
485 *
486 * If the FPU register state is valid, the kernel can skip restoring the
487 * FPU state from memory.
488 *
489 * Any code that clobbers the FPU registers or updates the in-memory
490 * FPU state for a task MUST let the rest of the kernel know that the
491 * FPU registers are no longer valid for this task. Calling either of
492 * these two invalidate functions is enough, use whichever is convenient.
493 *
482 * Must be run with preemption disabled: this clears the fpu_fpregs_owner_ctx, 494 * Must be run with preemption disabled: this clears the fpu_fpregs_owner_ctx,
483 * on this CPU. 495 * on this CPU.
484 *
485 * This will disable any lazy FPU state restore of the current FPU state,
486 * but if the current thread owns the FPU, it will still be saved by.
487 */ 496 */
488static inline void __cpu_disable_lazy_restore(unsigned int cpu) 497static inline void __cpu_invalidate_fpregs_state(unsigned int cpu)
489{ 498{
490 per_cpu(fpu_fpregs_owner_ctx, cpu) = NULL; 499 per_cpu(fpu_fpregs_owner_ctx, cpu) = NULL;
491} 500}
492 501
493static inline int fpu_want_lazy_restore(struct fpu *fpu, unsigned int cpu) 502static inline void __fpu_invalidate_fpregs_state(struct fpu *fpu)
503{
504 fpu->last_cpu = -1;
505}
506
507static inline int fpregs_state_valid(struct fpu *fpu, unsigned int cpu)
494{ 508{
495 return fpu == this_cpu_read_stable(fpu_fpregs_owner_ctx) && cpu == fpu->last_cpu; 509 return fpu == this_cpu_read_stable(fpu_fpregs_owner_ctx) && cpu == fpu->last_cpu;
496} 510}
@@ -588,7 +602,7 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)
588 } else { 602 } else {
589 old_fpu->last_cpu = -1; 603 old_fpu->last_cpu = -1;
590 if (fpu.preload) { 604 if (fpu.preload) {
591 if (fpu_want_lazy_restore(new_fpu, cpu)) 605 if (fpregs_state_valid(new_fpu, cpu))
592 fpu.preload = 0; 606 fpu.preload = 0;
593 else 607 else
594 prefetch(&new_fpu->state); 608 prefetch(&new_fpu->state);
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 6a37d525bdbe..25a45ddfdbcf 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -336,7 +336,7 @@ void fpu__activate_fpstate_write(struct fpu *fpu)
336 336
337 if (fpu->fpstate_active) { 337 if (fpu->fpstate_active) {
338 /* Invalidate any lazy state: */ 338 /* Invalidate any lazy state: */
339 fpu->last_cpu = -1; 339 __fpu_invalidate_fpregs_state(fpu);
340 } else { 340 } else {
341 fpstate_init(&fpu->state); 341 fpstate_init(&fpu->state);
342 trace_x86_fpu_init_state(fpu); 342 trace_x86_fpu_init_state(fpu);
@@ -379,7 +379,7 @@ void fpu__current_fpstate_write_begin(void)
379 * ensures we will not be lazy and skip a XRSTOR in the 379 * ensures we will not be lazy and skip a XRSTOR in the
380 * future. 380 * future.
381 */ 381 */
382 fpu->last_cpu = -1; 382 __fpu_invalidate_fpregs_state(fpu);
383} 383}
384 384
385/* 385/*
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 42a93621f5b0..ca4c4ca2f6af 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1111,7 +1111,7 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
1111 return err; 1111 return err;
1112 1112
1113 /* the FPU context is blank, nobody can own it */ 1113 /* the FPU context is blank, nobody can own it */
1114 __cpu_disable_lazy_restore(cpu); 1114 __cpu_invalidate_fpregs_state(cpu);
1115 1115
1116 common_cpu_up(cpu, tidle); 1116 common_cpu_up(cpu, tidle);
1117 1117