linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] x86/fpu: two more FPU cleanups
@ 2016-10-14 12:15 riel
  2016-10-14 12:15 ` [PATCH 1/2] x86/fpu: remove cpu argument to __cpu_invalidate_fpregs_state riel
  2016-10-14 12:15 ` [PATCH 2/2] x86/fpu: split old & new fpu handling into separate functions riel
  0 siblings, 2 replies; 9+ messages in thread
From: riel @ 2016-10-14 12:15 UTC (permalink / raw)
  To: linux-kernel; +Cc: hpa, mingo, bp, dave.hansen, luto, oleg

Two more small cleanups to the x86 FPU code, before I re-do the
functional FPU context switching changes I have been working on.

Neither of these should result in any noticeable differences,
besides for slightly fewer lines of code and updated comments :)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] x86/fpu: remove cpu argument to __cpu_invalidate_fpregs_state
  2016-10-14 12:15 [PATCH 0/2] x86/fpu: two more FPU cleanups riel
@ 2016-10-14 12:15 ` riel
  2016-10-14 16:53   ` Dave Hansen
  2016-10-16 11:25   ` [tip:x86/fpu] x86/fpu: Remove 'cpu' argument from __cpu_invalidate_fpregs_state() tip-bot for Rik van Riel
  2016-10-14 12:15 ` [PATCH 2/2] x86/fpu: split old & new fpu handling into separate functions riel
  1 sibling, 2 replies; 9+ messages in thread
From: riel @ 2016-10-14 12:15 UTC (permalink / raw)
  To: linux-kernel; +Cc: hpa, mingo, bp, dave.hansen, luto, oleg

From: Rik van Riel <riel@redhat.com>

The __{fpu,cpu}_invalidate_fpregs_state functions can only be used
to invalidate a resource they control.  Document that, and change
the API a little bit to reflect that.

Go back to open coding the fpu_fpregs_owner_ctx write in the CPU
hotplug code, which should be the exception, and move __kernel_fpu_begin
to this API.

This patch has no functional changes to the current code.

Signed-off-by: Rik van Riel <riel@redhat.com>
---
 arch/x86/include/asm/fpu/internal.h | 13 +++++++------
 arch/x86/kernel/fpu/core.c          |  2 +-
 arch/x86/kernel/smpboot.c           |  2 +-
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h
index ef52935f8a17..a75324675311 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -488,15 +488,16 @@ DECLARE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
  *
  * Any code that clobbers the FPU registers or updates the in-memory
  * FPU state for a task MUST let the rest of the kernel know that the
- * FPU registers are no longer valid for this task. Calling either of
- * these two invalidate functions is enough, use whichever is convenient.
+ * FPU registers are no longer valid for this task.
  *
- * Must be run with preemption disabled: this clears the fpu_fpregs_owner_ctx,
- * on this CPU.
+ * Either one of these invalidation functions is enough. Invalidate
+ * a resource you control: CPU if using the CPU for something else
+ * (with preemption disabled), FPU for the current task, or a task that
+ * is prevented from running by the current task.
  */
-static inline void __cpu_invalidate_fpregs_state(unsigned int cpu)
+static inline void __cpu_invalidate_fpregs_state(void)
 {
-	per_cpu(fpu_fpregs_owner_ctx, cpu) = NULL;
+	__this_cpu_write(fpu_fpregs_owner_ctx, NULL);
 }
 
 static inline void __fpu_invalidate_fpregs_state(struct fpu *fpu)
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 25a45ddfdbcf..30f11ab6c07e 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -106,7 +106,7 @@ void __kernel_fpu_begin(void)
 		 */
 		copy_fpregs_to_fpstate(fpu);
 	} else {
-		this_cpu_write(fpu_fpregs_owner_ctx, NULL);
+		__cpu_invalidate_fpregs_state();
 	}
 }
 EXPORT_SYMBOL(__kernel_fpu_begin);
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index ca4c4ca2f6af..5cb801acc2e5 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)
 		return err;
 
 	/* the FPU context is blank, nobody can own it */
-	__cpu_invalidate_fpregs_state(cpu);
+	per_cpu(fpu_fpregs_owner_ctx, cpu) = NULL;
 
 	common_cpu_up(cpu, tidle);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] x86/fpu: split old & new fpu handling into separate functions
  2016-10-14 12:15 [PATCH 0/2] x86/fpu: two more FPU cleanups riel
  2016-10-14 12:15 ` [PATCH 1/2] x86/fpu: remove cpu argument to __cpu_invalidate_fpregs_state riel
@ 2016-10-14 12:15 ` riel
  2016-10-14 17:14   ` Dave Hansen
  2016-10-16 11:25   ` [tip:x86/fpu] x86/fpu: Split old_fpu & new_fpu " tip-bot for Rik van Riel
  1 sibling, 2 replies; 9+ messages in thread
From: riel @ 2016-10-14 12:15 UTC (permalink / raw)
  To: linux-kernel; +Cc: hpa, mingo, bp, dave.hansen, luto, oleg

From: Rik van Riel <riel@redhat.com>

By moving all of the new fpu state handling into switch_fpu_finish,
the code can be simplified some more. This does get rid of the
prefetch, but given the size of the fpu register state on modern
CPUs, and the amount of work done by __switch_to in-between both
functions, the value of a single cache line prefetch seems somewhat
dubious anyway.

Signed-off-by: Rik van Riel <riel@redhat.com>
---
 arch/x86/include/asm/fpu/internal.h | 48 ++++++++++++-------------------------
 arch/x86/kernel/process_32.c        |  5 ++--
 arch/x86/kernel/process_64.c        |  5 ++--
 3 files changed, 19 insertions(+), 39 deletions(-)

diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h
index a75324675311..621ba3bfa2a7 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -552,27 +552,15 @@ static inline int fpregs_active(void)
  *
  * This is a two-stage process:
  *
- *  - switch_fpu_prepare() saves the old state and
- *    sets the new state of the CR0.TS bit. This is
- *    done within the context of the old process.
+ *  - switch_fpu_prepare() saves the old state.
+ *    This is done within the context of the old process.
  *
  *  - switch_fpu_finish() restores the new state as
  *    necessary.
  */
-typedef struct { int preload; } fpu_switch_t;
-
-static inline fpu_switch_t
-switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)
+static inline void
+switch_fpu_prepare(struct fpu *old_fpu, int cpu)
 {
-	fpu_switch_t fpu;
-
-	/*
-	 * If the task has used the math, pre-load the FPU on xsave processors
-	 * or if the past 5 consecutive context-switches used math.
-	 */
-	fpu.preload = static_cpu_has(X86_FEATURE_FPU) &&
-		      new_fpu->fpstate_active;
-
 	if (old_fpu->fpregs_active) {
 		if (!copy_fpregs_to_fpstate(old_fpu))
 			old_fpu->last_cpu = -1;
@@ -584,16 +572,6 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)
 		trace_x86_fpu_regs_deactivated(old_fpu);
 	} else
 		old_fpu->last_cpu = -1;
-
-	if (fpu.preload) {
-		if (fpregs_state_valid(new_fpu, cpu))
-			fpu.preload = 0;
-		else
-			prefetch(&new_fpu->state);
-		fpregs_activate(new_fpu);
-	}
-
-	return fpu;
 }
 
 /*
@@ -601,15 +579,19 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)
  */
 
 /*
- * By the time this gets called, we've already cleared CR0.TS and
- * given the process the FPU if we are going to preload the FPU
- * state - all we need to do is to conditionally restore the register
- * state itself.
+ * Set up the userspace FPU context for the new task, if the task
+ * has used the FPU.
  */
-static inline void switch_fpu_finish(struct fpu *new_fpu, fpu_switch_t fpu_switch)
+static inline void switch_fpu_finish(struct fpu *new_fpu, int cpu)
 {
-	if (fpu_switch.preload)
-		copy_kernel_to_fpregs(&new_fpu->state);
+	bool preload = static_cpu_has(X86_FEATURE_FPU) &&
+		       new_fpu->fpstate_active;
+
+	if (preload) {
+		if (!fpregs_state_valid(new_fpu, cpu))
+			copy_kernel_to_fpregs(&new_fpu->state);
+		fpregs_activate(new_fpu);
+	}
 }
 
 /*
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index bd7be8efdc4c..7dc8c9c3d801 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -232,11 +232,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
 	struct fpu *next_fpu = &next->fpu;
 	int cpu = smp_processor_id();
 	struct tss_struct *tss = &per_cpu(cpu_tss, cpu);
-	fpu_switch_t fpu_switch;
 
 	/* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
 
-	fpu_switch = switch_fpu_prepare(prev_fpu, next_fpu, cpu);
+	switch_fpu_prepare(prev_fpu, cpu);
 
 	/*
 	 * Save away %gs. No need to save %fs, as it was saved on the
@@ -295,7 +294,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
 	if (prev->gs | next->gs)
 		lazy_load_gs(next->gs);
 
-	switch_fpu_finish(next_fpu, fpu_switch);
+	switch_fpu_finish(next_fpu, cpu);
 
 	this_cpu_write(current_task, next_p);
 
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index ee944bd2310d..705669efb762 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -264,9 +264,8 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
 	int cpu = smp_processor_id();
 	struct tss_struct *tss = &per_cpu(cpu_tss, cpu);
 	unsigned prev_fsindex, prev_gsindex;
-	fpu_switch_t fpu_switch;
 
-	fpu_switch = switch_fpu_prepare(prev_fpu, next_fpu, cpu);
+	switch_fpu_prepare(prev_fpu, cpu);
 
 	/* We must save %fs and %gs before load_TLS() because
 	 * %fs and %gs may be cleared by load_TLS().
@@ -416,7 +415,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
 		prev->gsbase = 0;
 	prev->gsindex = prev_gsindex;
 
-	switch_fpu_finish(next_fpu, fpu_switch);
+	switch_fpu_finish(next_fpu, cpu);
 
 	/*
 	 * Switch the PDA and FPU contexts.
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] x86/fpu: remove cpu argument to __cpu_invalidate_fpregs_state
  2016-10-14 12:15 ` [PATCH 1/2] x86/fpu: remove cpu argument to __cpu_invalidate_fpregs_state riel
@ 2016-10-14 16:53   ` Dave Hansen
  2016-10-16 11:25   ` [tip:x86/fpu] x86/fpu: Remove 'cpu' argument from __cpu_invalidate_fpregs_state() tip-bot for Rik van Riel
  1 sibling, 0 replies; 9+ messages in thread
From: Dave Hansen @ 2016-10-14 16:53 UTC (permalink / raw)
  To: riel, linux-kernel; +Cc: hpa, mingo, bp, luto, oleg

On 10/14/2016 05:15 AM, riel@redhat.com wrote:
> From: Rik van Riel <riel@redhat.com>
> 
> The __{fpu,cpu}_invalidate_fpregs_state functions can only be used
> to invalidate a resource they control.  Document that, and change
> the API a little bit to reflect that.
> 
> Go back to open coding the fpu_fpregs_owner_ctx write in the CPU
> hotplug code, which should be the exception, and move __kernel_fpu_begin
> to this API.
> 
> This patch has no functional changes to the current code.
> 
> Signed-off-by: Rik van Riel <riel@redhat.com>

Looks totally sane to me.

Acked-by: Dave Hansen <dave.hansen@intel.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] x86/fpu: split old & new fpu handling into separate functions
  2016-10-14 12:15 ` [PATCH 2/2] x86/fpu: split old & new fpu handling into separate functions riel
@ 2016-10-14 17:14   ` Dave Hansen
  2016-10-16 11:25   ` [tip:x86/fpu] x86/fpu: Split old_fpu & new_fpu " tip-bot for Rik van Riel
  1 sibling, 0 replies; 9+ messages in thread
From: Dave Hansen @ 2016-10-14 17:14 UTC (permalink / raw)
  To: riel, linux-kernel; +Cc: hpa, mingo, bp, luto, oleg

On 10/14/2016 05:15 AM, riel@redhat.com wrote:
> From: Rik van Riel <riel@redhat.com>
> 
> By moving all of the new fpu state handling into switch_fpu_finish,
> the code can be simplified some more. This does get rid of the
> prefetch, but given the size of the fpu register state on modern
> CPUs, and the amount of work done by __switch_to in-between both
> functions, the value of a single cache line prefetch seems somewhat
> dubious anyway.
...
> -
> -	if (fpu.preload) {
> -		if (fpregs_state_valid(new_fpu, cpu))
> -			fpu.preload = 0;
> -		else
> -			prefetch(&new_fpu->state);
> -		fpregs_activate(new_fpu);
> -	}
> -
> -	return fpu;
>  }

Yeah, that prefetch is highly dubious.  XRSTOR might not even be
_reading_ that cacheline if the state isn't present (xstate->xfeatures
bit is 0).  If we had to pick *a* cacheline to prefetch for XRSTOR, it
would be the XSAVE header, *not* the FPU state.

I actually did some attempts to optimize the PKRU handling by touching
and prefetching the state before calling XRSTOR.  It actually made
things overall _worse_ when I touched it before the XRSTOR.

It would be ideal to have some data on whether this actually _does_
anything, but I can't imagine it being a real delta in either direction.

Acked-by: Dave Hansen <dave.hansen@intel.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [tip:x86/fpu] x86/fpu: Remove 'cpu' argument from __cpu_invalidate_fpregs_state()
  2016-10-14 12:15 ` [PATCH 1/2] x86/fpu: remove cpu argument to __cpu_invalidate_fpregs_state riel
  2016-10-14 16:53   ` Dave Hansen
@ 2016-10-16 11:25   ` tip-bot for Rik van Riel
  1 sibling, 0 replies; 9+ messages in thread
From: tip-bot for Rik van Riel @ 2016-10-16 11:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: brgerst, oleg, dave.hansen, bp, tglx, jpoimboe, torvalds, riel,
	mingo, hpa, dvlasenk, peterz, dave.hansen, quentin.casasnovas,
	linux-kernel, fenghua.yu, luto

Commit-ID:  317b622cb2fda1812d8646e211cdb23dce2564d0
Gitweb:     http://git.kernel.org/tip/317b622cb2fda1812d8646e211cdb23dce2564d0
Author:     Rik van Riel <riel@redhat.com>
AuthorDate: Fri, 14 Oct 2016 08:15:30 -0400
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sun, 16 Oct 2016 11:38:31 +0200

x86/fpu: Remove 'cpu' argument from __cpu_invalidate_fpregs_state()

The __{fpu,cpu}_invalidate_fpregs_state() functions can only be used
to invalidate a resource they control.  Document that, and change
the API a little bit to reflect that.

Go back to open coding the fpu_fpregs_owner_ctx write in the CPU
hotplug code, which should be the exception, and move __kernel_fpu_begin()
to this API.

This patch has no functional changes to the current code.

Signed-off-by: Rik van Riel <riel@redhat.com>
Acked-by: Dave Hansen <dave.hansen@intel.com>
Cc: 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>
Link: http://lkml.kernel.org/r/1476447331-21566-2-git-send-email-riel@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/fpu/internal.h | 13 +++++++------
 arch/x86/kernel/fpu/core.c          |  2 +-
 arch/x86/kernel/smpboot.c           |  2 +-
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h
index 1dcb29e..590f274 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -488,15 +488,16 @@ DECLARE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
  *
  * Any code that clobbers the FPU registers or updates the in-memory
  * FPU state for a task MUST let the rest of the kernel know that the
- * FPU registers are no longer valid for this task. Calling either of
- * these two invalidate functions is enough, use whichever is convenient.
+ * FPU registers are no longer valid for this task.
  *
- * Must be run with preemption disabled: this clears the fpu_fpregs_owner_ctx,
- * on this CPU.
+ * Either one of these invalidation functions is enough. Invalidate
+ * a resource you control: CPU if using the CPU for something else
+ * (with preemption disabled), FPU for the current task, or a task that
+ * is prevented from running by the current task.
  */
-static inline void __cpu_invalidate_fpregs_state(unsigned int cpu)
+static inline void __cpu_invalidate_fpregs_state(void)
 {
-	per_cpu(fpu_fpregs_owner_ctx, cpu) = NULL;
+	__this_cpu_write(fpu_fpregs_owner_ctx, NULL);
 }
 
 static inline void __fpu_invalidate_fpregs_state(struct fpu *fpu)
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 25a45dd..30f11ab 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -106,7 +106,7 @@ void __kernel_fpu_begin(void)
 		 */
 		copy_fpregs_to_fpstate(fpu);
 	} else {
-		this_cpu_write(fpu_fpregs_owner_ctx, NULL);
+		__cpu_invalidate_fpregs_state();
 	}
 }
 EXPORT_SYMBOL(__kernel_fpu_begin);
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index ca4c4ca..5cb801a 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)
 		return err;
 
 	/* the FPU context is blank, nobody can own it */
-	__cpu_invalidate_fpregs_state(cpu);
+	per_cpu(fpu_fpregs_owner_ctx, cpu) = NULL;
 
 	common_cpu_up(cpu, tidle);
 

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [tip:x86/fpu] x86/fpu: Split old_fpu & new_fpu handling into separate functions
  2016-10-14 12:15 ` [PATCH 2/2] x86/fpu: split old & new fpu handling into separate functions riel
  2016-10-14 17:14   ` Dave Hansen
@ 2016-10-16 11:25   ` tip-bot for Rik van Riel
  2017-01-24 12:13     ` you have a new message from... c92Y Izuchukwu Francis
  1 sibling, 1 reply; 9+ messages in thread
From: tip-bot for Rik van Riel @ 2016-10-16 11:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: luto, quentin.casasnovas, dave.hansen, oleg, dvlasenk, riel,
	fenghua.yu, hpa, jpoimboe, tglx, linux-kernel, mingo, bp,
	torvalds, dave.hansen, peterz, brgerst

Commit-ID:  c474e50711aa79b7bd0ea30b44744baca5650375
Gitweb:     http://git.kernel.org/tip/c474e50711aa79b7bd0ea30b44744baca5650375
Author:     Rik van Riel <riel@redhat.com>
AuthorDate: Fri, 14 Oct 2016 08:15:31 -0400
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sun, 16 Oct 2016 11:38:41 +0200

x86/fpu: Split old_fpu & new_fpu handling into separate functions

By moving all of the new_fpu state handling into switch_fpu_finish(),
the code can be simplified some more.

This gets rid of the prefetch, but given the size of the FPU register
state on modern CPUs, and the amount of work done by __switch_to()
inbetween both functions, the value of a single cache line prefetch
seems somewhat dubious anyway.

Signed-off-by: Rik van Riel <riel@redhat.com>
Acked-by: Dave Hansen <dave.hansen@intel.com>
Cc: 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>
Link: http://lkml.kernel.org/r/1476447331-21566-3-git-send-email-riel@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/fpu/internal.h | 48 ++++++++++++-------------------------
 arch/x86/kernel/process_32.c        |  5 ++--
 arch/x86/kernel/process_64.c        |  5 ++--
 3 files changed, 19 insertions(+), 39 deletions(-)

diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h
index 590f274..d4a6849 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -552,27 +552,15 @@ static inline int fpregs_active(void)
  *
  * This is a two-stage process:
  *
- *  - switch_fpu_prepare() saves the old state and
- *    sets the new state of the CR0.TS bit. This is
- *    done within the context of the old process.
+ *  - switch_fpu_prepare() saves the old state.
+ *    This is done within the context of the old process.
  *
  *  - switch_fpu_finish() restores the new state as
  *    necessary.
  */
-typedef struct { int preload; } fpu_switch_t;
-
-static inline fpu_switch_t
-switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)
+static inline void
+switch_fpu_prepare(struct fpu *old_fpu, int cpu)
 {
-	fpu_switch_t fpu;
-
-	/*
-	 * If the task has used the math, pre-load the FPU on xsave processors
-	 * or if the past 5 consecutive context-switches used math.
-	 */
-	fpu.preload = static_cpu_has(X86_FEATURE_FPU) &&
-		      new_fpu->fpstate_active;
-
 	if (old_fpu->fpregs_active) {
 		if (!copy_fpregs_to_fpstate(old_fpu))
 			old_fpu->last_cpu = -1;
@@ -584,16 +572,6 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)
 		trace_x86_fpu_regs_deactivated(old_fpu);
 	} else
 		old_fpu->last_cpu = -1;
-
-	if (fpu.preload) {
-		if (fpregs_state_valid(new_fpu, cpu))
-			fpu.preload = 0;
-		else
-			prefetch(&new_fpu->state);
-		fpregs_activate(new_fpu);
-	}
-
-	return fpu;
 }
 
 /*
@@ -601,15 +579,19 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)
  */
 
 /*
- * By the time this gets called, we've already cleared CR0.TS and
- * given the process the FPU if we are going to preload the FPU
- * state - all we need to do is to conditionally restore the register
- * state itself.
+ * Set up the userspace FPU context for the new task, if the task
+ * has used the FPU.
  */
-static inline void switch_fpu_finish(struct fpu *new_fpu, fpu_switch_t fpu_switch)
+static inline void switch_fpu_finish(struct fpu *new_fpu, int cpu)
 {
-	if (fpu_switch.preload)
-		copy_kernel_to_fpregs(&new_fpu->state);
+	bool preload = static_cpu_has(X86_FEATURE_FPU) &&
+		       new_fpu->fpstate_active;
+
+	if (preload) {
+		if (!fpregs_state_valid(new_fpu, cpu))
+			copy_kernel_to_fpregs(&new_fpu->state);
+		fpregs_activate(new_fpu);
+	}
 }
 
 /*
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index bd7be8e..7dc8c9c 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -232,11 +232,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
 	struct fpu *next_fpu = &next->fpu;
 	int cpu = smp_processor_id();
 	struct tss_struct *tss = &per_cpu(cpu_tss, cpu);
-	fpu_switch_t fpu_switch;
 
 	/* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
 
-	fpu_switch = switch_fpu_prepare(prev_fpu, next_fpu, cpu);
+	switch_fpu_prepare(prev_fpu, cpu);
 
 	/*
 	 * Save away %gs. No need to save %fs, as it was saved on the
@@ -295,7 +294,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
 	if (prev->gs | next->gs)
 		lazy_load_gs(next->gs);
 
-	switch_fpu_finish(next_fpu, fpu_switch);
+	switch_fpu_finish(next_fpu, cpu);
 
 	this_cpu_write(current_task, next_p);
 
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index ee944bd..705669e 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -264,9 +264,8 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
 	int cpu = smp_processor_id();
 	struct tss_struct *tss = &per_cpu(cpu_tss, cpu);
 	unsigned prev_fsindex, prev_gsindex;
-	fpu_switch_t fpu_switch;
 
-	fpu_switch = switch_fpu_prepare(prev_fpu, next_fpu, cpu);
+	switch_fpu_prepare(prev_fpu, cpu);
 
 	/* We must save %fs and %gs before load_TLS() because
 	 * %fs and %gs may be cleared by load_TLS().
@@ -416,7 +415,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
 		prev->gsbase = 0;
 	prev->gsindex = prev_gsindex;
 
-	switch_fpu_finish(next_fpu, fpu_switch);
+	switch_fpu_finish(next_fpu, cpu);
 
 	/*
 	 * Switch the PDA and FPU contexts.

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: you have a new message from... c92Y
  2016-10-16 11:25   ` [tip:x86/fpu] x86/fpu: Split old_fpu & new_fpu " tip-bot for Rik van Riel
@ 2017-01-24 12:13     ` Izuchukwu Francis
  2017-02-10 13:52       ` Izuchukwu Francis
  0 siblings, 1 reply; 9+ messages in thread
From: Izuchukwu Francis @ 2017-01-24 12:13 UTC (permalink / raw)
  To: quentin.casasnovas, dave.hansen, luto, dvlasenk, oleg, riel,
	fenghua.yu, hpa, jpoimboe, tglx, linux-kernel, bp, mingo,
	dave.hansen, brgerst, peterz, torvalds

bless may i know u

On 10/16/16, tip-bot for Rik van Riel <tipbot@zytor.com> wrote:
> You can do whatever you want to me izundunaoyi
>
> Tell me where you want my cum
>
> and don't let it be a disappointing location
>
>
> [image]
> [image]
>
> To OPT_OUT,Please Click Here....
>
>
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: you have a new message from... c92Y
  2017-01-24 12:13     ` you have a new message from... c92Y Izuchukwu Francis
@ 2017-02-10 13:52       ` Izuchukwu Francis
  0 siblings, 0 replies; 9+ messages in thread
From: Izuchukwu Francis @ 2017-02-10 13:52 UTC (permalink / raw)
  To: quentin.casasnovas, dave.hansen, luto, dvlasenk, oleg, riel,
	fenghua.yu, hpa, jpoimboe, tglx, linux-kernel, bp, mingo,
	dave.hansen, brgerst, peterz, torvalds

sori am ntt around since wia re u nw

On 1/24/17, Izuchukwu Francis <izundunaoyi@gmail.com> wrote:
> bless may i know u
>
> On 10/16/16, tip-bot for Rik van Riel <tipbot@zytor.com> wrote:
>> You can do whatever you want to me izundunaoyi
>>
>> Tell me where you want my cum
>>
>> and don't let it be a disappointing location
>>
>>
>> [image]
>> [image]
>>
>> To OPT_OUT,Please Click Here....
>>
>>
>>
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-02-10 13:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-14 12:15 [PATCH 0/2] x86/fpu: two more FPU cleanups riel
2016-10-14 12:15 ` [PATCH 1/2] x86/fpu: remove cpu argument to __cpu_invalidate_fpregs_state riel
2016-10-14 16:53   ` Dave Hansen
2016-10-16 11:25   ` [tip:x86/fpu] x86/fpu: Remove 'cpu' argument from __cpu_invalidate_fpregs_state() tip-bot for Rik van Riel
2016-10-14 12:15 ` [PATCH 2/2] x86/fpu: split old & new fpu handling into separate functions riel
2016-10-14 17:14   ` Dave Hansen
2016-10-16 11:25   ` [tip:x86/fpu] x86/fpu: Split old_fpu & new_fpu " tip-bot for Rik van Riel
2017-01-24 12:13     ` you have a new message from... c92Y Izuchukwu Francis
2017-02-10 13:52       ` Izuchukwu Francis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).