linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* x86 fpu cleanups
@ 2019-06-04  7:15 Christoph Hellwig
  2019-06-04  7:15 ` [PATCH 1/3] x86/fpu: Simplify kernel_fpu_end Christoph Hellwig
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Christoph Hellwig @ 2019-06-04  7:15 UTC (permalink / raw)
  To: x86; +Cc: Sebastian Andrzej Siewior, linux-kernel

Hi all,

this series finishes off some cleanups that are possible now that
Sebastians fpu rework is finished.

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

* [PATCH 1/3] x86/fpu: Simplify kernel_fpu_end
  2019-06-04  7:15 x86 fpu cleanups Christoph Hellwig
@ 2019-06-04  7:15 ` Christoph Hellwig
  2019-06-17 10:31   ` [tip:x86/fpu] x86/fpu: Simplify kernel_fpu_end() tip-bot for Christoph Hellwig
  2019-06-04  7:15 ` [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin Christoph Hellwig
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Christoph Hellwig @ 2019-06-04  7:15 UTC (permalink / raw)
  To: x86; +Cc: Sebastian Andrzej Siewior, linux-kernel

Remove two little helpers and merge them into kernel_fpu_end to
streamline the function.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/kernel/fpu/core.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 466fca686fb9..1d09af1158e1 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -49,12 +49,6 @@ static void kernel_fpu_disable(void)
 	this_cpu_write(in_kernel_fpu, true);
 }
 
-static void kernel_fpu_enable(void)
-{
-	WARN_ON_FPU(!this_cpu_read(in_kernel_fpu));
-	this_cpu_write(in_kernel_fpu, false);
-}
-
 static bool kernel_fpu_disabled(void)
 {
 	return this_cpu_read(in_kernel_fpu);
@@ -115,11 +109,6 @@ static void __kernel_fpu_begin(void)
 	__cpu_invalidate_fpregs_state();
 }
 
-static void __kernel_fpu_end(void)
-{
-	kernel_fpu_enable();
-}
-
 void kernel_fpu_begin(void)
 {
 	preempt_disable();
@@ -129,7 +118,9 @@ EXPORT_SYMBOL_GPL(kernel_fpu_begin);
 
 void kernel_fpu_end(void)
 {
-	__kernel_fpu_end();
+	WARN_ON_FPU(!this_cpu_read(in_kernel_fpu));
+
+	this_cpu_write(in_kernel_fpu, false);
 	preempt_enable();
 }
 EXPORT_SYMBOL_GPL(kernel_fpu_end);
-- 
2.20.1


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

* [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin
  2019-06-04  7:15 x86 fpu cleanups Christoph Hellwig
  2019-06-04  7:15 ` [PATCH 1/3] x86/fpu: Simplify kernel_fpu_end Christoph Hellwig
@ 2019-06-04  7:15 ` Christoph Hellwig
  2019-06-04 11:47   ` Peter Zijlstra
  2019-06-17 10:31   ` [tip:x86/fpu] x86/fpu: Simplify kernel_fpu_begin() tip-bot for Christoph Hellwig
  2019-06-04  7:15 ` [PATCH 3/3] x86/fpu: remove the fpu__save export Christoph Hellwig
  2019-06-04 17:54 ` [PATCH 4/3] x86/fpu: don't use current->mm to check for a kthread Christoph Hellwig
  3 siblings, 2 replies; 16+ messages in thread
From: Christoph Hellwig @ 2019-06-04  7:15 UTC (permalink / raw)
  To: x86; +Cc: Sebastian Andrzej Siewior, linux-kernel

Merge two helpers into the main function, remove a pointless local
variable and flatten a conditional.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/kernel/fpu/core.c | 35 +++++++++++------------------------
 1 file changed, 11 insertions(+), 24 deletions(-)

diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 1d09af1158e1..03c2d306e6f2 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -43,12 +43,6 @@ static DEFINE_PER_CPU(bool, in_kernel_fpu);
  */
 DEFINE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
 
-static void kernel_fpu_disable(void)
-{
-	WARN_ON_FPU(this_cpu_read(in_kernel_fpu));
-	this_cpu_write(in_kernel_fpu, true);
-}
-
 static bool kernel_fpu_disabled(void)
 {
 	return this_cpu_read(in_kernel_fpu);
@@ -88,32 +82,25 @@ bool irq_fpu_usable(void)
 }
 EXPORT_SYMBOL(irq_fpu_usable);
 
-static void __kernel_fpu_begin(void)
+void kernel_fpu_begin(void)
 {
-	struct fpu *fpu = &current->thread.fpu;
+	preempt_disable();
 
 	WARN_ON_FPU(!irq_fpu_usable());
+	WARN_ON_FPU(this_cpu_read(in_kernel_fpu));
 
-	kernel_fpu_disable();
+	this_cpu_write(in_kernel_fpu, true);
 
-	if (current->mm) {
-		if (!test_thread_flag(TIF_NEED_FPU_LOAD)) {
-			set_thread_flag(TIF_NEED_FPU_LOAD);
-			/*
-			 * Ignore return value -- we don't care if reg state
-			 * is clobbered.
-			 */
-			copy_fpregs_to_fpstate(fpu);
-		}
+	if (current->mm && !test_thread_flag(TIF_NEED_FPU_LOAD)) {
+		set_thread_flag(TIF_NEED_FPU_LOAD);
+		/*
+		 * Ignore return value -- we don't care if reg state
+		 * is clobbered.
+		 */
+		copy_fpregs_to_fpstate(&current->thread.fpu);
 	}
 	__cpu_invalidate_fpregs_state();
 }
-
-void kernel_fpu_begin(void)
-{
-	preempt_disable();
-	__kernel_fpu_begin();
-}
 EXPORT_SYMBOL_GPL(kernel_fpu_begin);
 
 void kernel_fpu_end(void)
-- 
2.20.1


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

* [PATCH 3/3] x86/fpu: remove the fpu__save export
  2019-06-04  7:15 x86 fpu cleanups Christoph Hellwig
  2019-06-04  7:15 ` [PATCH 1/3] x86/fpu: Simplify kernel_fpu_end Christoph Hellwig
  2019-06-04  7:15 ` [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin Christoph Hellwig
@ 2019-06-04  7:15 ` Christoph Hellwig
  2019-06-17 10:32   ` [tip:x86/fpu] x86/fpu: Remove the fpu__save() export tip-bot for Christoph Hellwig
  2019-06-04 17:54 ` [PATCH 4/3] x86/fpu: don't use current->mm to check for a kthread Christoph Hellwig
  3 siblings, 1 reply; 16+ messages in thread
From: Christoph Hellwig @ 2019-06-04  7:15 UTC (permalink / raw)
  To: x86; +Cc: Sebastian Andrzej Siewior, linux-kernel

This function is only use by the core fpu code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/kernel/fpu/core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 03c2d306e6f2..5e0240d029fd 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -133,7 +133,6 @@ void fpu__save(struct fpu *fpu)
 	trace_x86_fpu_after_save(fpu);
 	fpregs_unlock();
 }
-EXPORT_SYMBOL_GPL(fpu__save);
 
 /*
  * Legacy x87 fpstate state init:
-- 
2.20.1


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

* Re: [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin
  2019-06-04  7:15 ` [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin Christoph Hellwig
@ 2019-06-04 11:47   ` Peter Zijlstra
  2019-06-04 13:11     ` Christoph Hellwig
  2019-06-17 10:31   ` [tip:x86/fpu] x86/fpu: Simplify kernel_fpu_begin() tip-bot for Christoph Hellwig
  1 sibling, 1 reply; 16+ messages in thread
From: Peter Zijlstra @ 2019-06-04 11:47 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: x86, Sebastian Andrzej Siewior, linux-kernel

On Tue, Jun 04, 2019 at 09:15:23AM +0200, Christoph Hellwig wrote:
> +void kernel_fpu_begin(void)
>  {
> +	preempt_disable();
>  
>  	WARN_ON_FPU(!irq_fpu_usable());
> +	WARN_ON_FPU(this_cpu_read(in_kernel_fpu));
>  
> +	this_cpu_write(in_kernel_fpu, true);
>  
> +	if (current->mm && !test_thread_flag(TIF_NEED_FPU_LOAD)) {

Did that want to be: !(current->flags & PF_KTHREAD), instead?

Because I'm thinking that kernel_fpu_begin() on a kthread that has
use_mm() employed shouldn't be doing this..

> +		set_thread_flag(TIF_NEED_FPU_LOAD);
> +		/*
> +		 * Ignore return value -- we don't care if reg state
> +		 * is clobbered.
> +		 */
> +		copy_fpregs_to_fpstate(&current->thread.fpu);
>  	}
>  	__cpu_invalidate_fpregs_state();
>  }

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

* Re: [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin
  2019-06-04 11:47   ` Peter Zijlstra
@ 2019-06-04 13:11     ` Christoph Hellwig
  2019-06-04 13:34       ` Peter Zijlstra
  0 siblings, 1 reply; 16+ messages in thread
From: Christoph Hellwig @ 2019-06-04 13:11 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Christoph Hellwig, x86, Sebastian Andrzej Siewior, linux-kernel

On Tue, Jun 04, 2019 at 01:47:01PM +0200, Peter Zijlstra wrote:
> > +	if (current->mm && !test_thread_flag(TIF_NEED_FPU_LOAD)) {
> 
> Did that want to be: !(current->flags & PF_KTHREAD), instead?
> 
> Because I'm thinking that kernel_fpu_begin() on a kthread that has
> use_mm() employed shouldn't be doing this..

Well, this is intended to not change semantics.  If we should fix
this is should be a separate patch before or after this series.

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

* Re: [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin
  2019-06-04 13:11     ` Christoph Hellwig
@ 2019-06-04 13:34       ` Peter Zijlstra
  2019-06-04 14:34         ` Christoph Hellwig
  0 siblings, 1 reply; 16+ messages in thread
From: Peter Zijlstra @ 2019-06-04 13:34 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: x86, Sebastian Andrzej Siewior, linux-kernel

On Tue, Jun 04, 2019 at 03:11:38PM +0200, Christoph Hellwig wrote:
> On Tue, Jun 04, 2019 at 01:47:01PM +0200, Peter Zijlstra wrote:
> > > +	if (current->mm && !test_thread_flag(TIF_NEED_FPU_LOAD)) {
> > 
> > Did that want to be: !(current->flags & PF_KTHREAD), instead?
> > 
> > Because I'm thinking that kernel_fpu_begin() on a kthread that has
> > use_mm() employed shouldn't be doing this..
> 
> Well, this is intended to not change semantics.  If we should fix
> this is should be a separate patch before or after this series.

Sure; it's just that I just noticed it. We've recently ran into a
similar issue elsewhere.

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

* Re: [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin
  2019-06-04 13:34       ` Peter Zijlstra
@ 2019-06-04 14:34         ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2019-06-04 14:34 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Christoph Hellwig, x86, Sebastian Andrzej Siewior, linux-kernel

On Tue, Jun 04, 2019 at 03:34:17PM +0200, Peter Zijlstra wrote:
> > Well, this is intended to not change semantics.  If we should fix
> > this is should be a separate patch before or after this series.
> 
> Sure; it's just that I just noticed it. We've recently ran into a
> similar issue elsewhere.

Ok, I'll send a follow on.

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

* [PATCH 4/3] x86/fpu: don't use current->mm to check for a kthread
  2019-06-04  7:15 x86 fpu cleanups Christoph Hellwig
                   ` (2 preceding siblings ...)
  2019-06-04  7:15 ` [PATCH 3/3] x86/fpu: remove the fpu__save export Christoph Hellwig
@ 2019-06-04 17:54 ` Christoph Hellwig
  2019-06-11  7:52   ` Sebastian Andrzej Siewior
                     ` (2 more replies)
  3 siblings, 3 replies; 16+ messages in thread
From: Christoph Hellwig @ 2019-06-04 17:54 UTC (permalink / raw)
  To: x86; +Cc: Sebastian Andrzej Siewior, linux-kernel

current->mm can be non-NULL if a kthread calls use_mm.  Check for
PF_KTHREAD instead to decide when to store user mode FP state.

Fixes: 2722146eb784 ("x86/fpu: Remove fpu->initialized")
Reported-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/x86/include/asm/fpu/internal.h | 6 +++---
 arch/x86/kernel/fpu/core.c          | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h
index 9e27fa05a7ae..4c95c365058a 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -536,7 +536,7 @@ static inline void __fpregs_load_activate(void)
 	struct fpu *fpu = &current->thread.fpu;
 	int cpu = smp_processor_id();
 
-	if (WARN_ON_ONCE(current->mm == NULL))
+	if (WARN_ON_ONCE(current->flags & PF_KTHREAD))
 		return;
 
 	if (!fpregs_state_valid(fpu, cpu)) {
@@ -567,11 +567,11 @@ static inline void __fpregs_load_activate(void)
  * otherwise.
  *
  * The FPU context is only stored/restored for a user task and
- * ->mm is used to distinguish between kernel and user threads.
+ * PF_KTHREAD is used to distinguish between kernel and user threads.
  */
 static inline void switch_fpu_prepare(struct fpu *old_fpu, int cpu)
 {
-	if (static_cpu_has(X86_FEATURE_FPU) && current->mm) {
+	if (static_cpu_has(X86_FEATURE_FPU) && !(current->flags & PF_KTHREAD)) {
 		if (!copy_fpregs_to_fpstate(old_fpu))
 			old_fpu->last_cpu = -1;
 		else
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 5e0240d029fd..12c70840980e 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -91,7 +91,8 @@ void kernel_fpu_begin(void)
 
 	this_cpu_write(in_kernel_fpu, true);
 
-	if (current->mm && !test_thread_flag(TIF_NEED_FPU_LOAD)) {
+	if (!(current->flags & PF_KTHREAD) &&
+	    !test_thread_flag(TIF_NEED_FPU_LOAD)) {
 		set_thread_flag(TIF_NEED_FPU_LOAD);
 		/*
 		 * Ignore return value -- we don't care if reg state
-- 
2.20.1


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

* Re: [PATCH 4/3] x86/fpu: don't use current->mm to check for a kthread
  2019-06-04 17:54 ` [PATCH 4/3] x86/fpu: don't use current->mm to check for a kthread Christoph Hellwig
@ 2019-06-11  7:52   ` Sebastian Andrzej Siewior
  2019-06-13 19:03   ` Borislav Petkov
  2019-06-13 19:07   ` [tip:x86/urgent] x86/fpu: Don't " tip-bot for Christoph Hellwig
  2 siblings, 0 replies; 16+ messages in thread
From: Sebastian Andrzej Siewior @ 2019-06-11  7:52 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: x86, linux-kernel

On 2019-06-04 19:54:12 [+0200], Christoph Hellwig wrote:
> current->mm can be non-NULL if a kthread calls use_mm.  Check for
> PF_KTHREAD instead to decide when to store user mode FP state.
> 
> Fixes: 2722146eb784 ("x86/fpu: Remove fpu->initialized")
> Reported-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

For the whole series.

Sebastian

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

* Re: [PATCH 4/3] x86/fpu: don't use current->mm to check for a kthread
  2019-06-04 17:54 ` [PATCH 4/3] x86/fpu: don't use current->mm to check for a kthread Christoph Hellwig
  2019-06-11  7:52   ` Sebastian Andrzej Siewior
@ 2019-06-13 19:03   ` Borislav Petkov
  2019-06-13 19:07   ` [tip:x86/urgent] x86/fpu: Don't " tip-bot for Christoph Hellwig
  2 siblings, 0 replies; 16+ messages in thread
From: Borislav Petkov @ 2019-06-13 19:03 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: x86, Sebastian Andrzej Siewior, linux-kernel

On Tue, Jun 04, 2019 at 07:54:12PM +0200, Christoph Hellwig wrote:
> current->mm can be non-NULL if a kthread calls use_mm.  Check for
> PF_KTHREAD instead to decide when to store user mode FP state.
> 
> Fixes: 2722146eb784 ("x86/fpu: Remove fpu->initialized")
> Reported-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/x86/include/asm/fpu/internal.h | 6 +++---
>  arch/x86/kernel/fpu/core.c          | 3 ++-
>  2 files changed, 5 insertions(+), 4 deletions(-)

I had to take this one first because of the Fixes: tag and expedite it
through tip:x86/urgent. Check the tip-bot notification mail whether it
is still ok.

I'll redo the other ones ontop, or you can if you feel bored. :)

Thx.

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

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

* [tip:x86/urgent] x86/fpu: Don't use current->mm to check for a kthread
  2019-06-04 17:54 ` [PATCH 4/3] x86/fpu: don't use current->mm to check for a kthread Christoph Hellwig
  2019-06-11  7:52   ` Sebastian Andrzej Siewior
  2019-06-13 19:03   ` Borislav Petkov
@ 2019-06-13 19:07   ` tip-bot for Christoph Hellwig
  2 siblings, 0 replies; 16+ messages in thread
From: tip-bot for Christoph Hellwig @ 2019-06-13 19:07 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: bigeasy, hch, jannh, bp, mingo, aubrey.li, dave.hansen,
	linux-kernel, hpa, x86, tglx, riel, mingo, nstange, peterz

Commit-ID:  8d3289f2fa1e0c7e2f72c7352f1efb75d2ad7c76
Gitweb:     https://git.kernel.org/tip/8d3289f2fa1e0c7e2f72c7352f1efb75d2ad7c76
Author:     Christoph Hellwig <hch@lst.de>
AuthorDate: Tue, 4 Jun 2019 19:54:12 +0200
Committer:  Borislav Petkov <bp@suse.de>
CommitDate: Thu, 13 Jun 2019 20:57:49 +0200

x86/fpu: Don't use current->mm to check for a kthread

current->mm can be non-NULL if a kthread calls use_mm(). Check for
PF_KTHREAD instead to decide when to store user mode FP state.

Fixes: 2722146eb784 ("x86/fpu: Remove fpu->initialized")
Reported-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Aubrey Li <aubrey.li@intel.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jann Horn <jannh@google.com>
Cc: Nicolai Stange <nstange@suse.de>
Cc: Rik van Riel <riel@surriel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190604175411.GA27477@lst.de
---
 arch/x86/include/asm/fpu/internal.h | 6 +++---
 arch/x86/kernel/fpu/core.c          | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h
index 9e27fa05a7ae..4c95c365058a 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -536,7 +536,7 @@ static inline void __fpregs_load_activate(void)
 	struct fpu *fpu = &current->thread.fpu;
 	int cpu = smp_processor_id();
 
-	if (WARN_ON_ONCE(current->mm == NULL))
+	if (WARN_ON_ONCE(current->flags & PF_KTHREAD))
 		return;
 
 	if (!fpregs_state_valid(fpu, cpu)) {
@@ -567,11 +567,11 @@ static inline void __fpregs_load_activate(void)
  * otherwise.
  *
  * The FPU context is only stored/restored for a user task and
- * ->mm is used to distinguish between kernel and user threads.
+ * PF_KTHREAD is used to distinguish between kernel and user threads.
  */
 static inline void switch_fpu_prepare(struct fpu *old_fpu, int cpu)
 {
-	if (static_cpu_has(X86_FEATURE_FPU) && current->mm) {
+	if (static_cpu_has(X86_FEATURE_FPU) && !(current->flags & PF_KTHREAD)) {
 		if (!copy_fpregs_to_fpstate(old_fpu))
 			old_fpu->last_cpu = -1;
 		else
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 466fca686fb9..649fbc3fcf9f 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -102,7 +102,7 @@ static void __kernel_fpu_begin(void)
 
 	kernel_fpu_disable();
 
-	if (current->mm) {
+	if (!(current->flags & PF_KTHREAD)) {
 		if (!test_thread_flag(TIF_NEED_FPU_LOAD)) {
 			set_thread_flag(TIF_NEED_FPU_LOAD);
 			/*

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

* [tip:x86/fpu] x86/fpu: Simplify kernel_fpu_end()
  2019-06-04  7:15 ` [PATCH 1/3] x86/fpu: Simplify kernel_fpu_end Christoph Hellwig
@ 2019-06-17 10:31   ` tip-bot for Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: tip-bot for Christoph Hellwig @ 2019-06-17 10:31 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, bigeasy, hch, mingo, x86, linux-kernel, mingo, nstange,
	dave.hansen, bp, hpa, riel

Commit-ID:  b78ea19ac22fd7b32d7828066cce3d8f2db5226a
Gitweb:     https://git.kernel.org/tip/b78ea19ac22fd7b32d7828066cce3d8f2db5226a
Author:     Christoph Hellwig <hch@lst.de>
AuthorDate: Tue, 4 Jun 2019 09:15:22 +0200
Committer:  Borislav Petkov <bp@suse.de>
CommitDate: Mon, 17 Jun 2019 10:43:43 +0200

x86/fpu: Simplify kernel_fpu_end()

Remove two little helpers and merge them into kernel_fpu_end() to
streamline the function.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Nicolai Stange <nstange@suse.de>
Cc: Rik van Riel <riel@surriel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190604071524.12835-2-hch@lst.de
---
 arch/x86/kernel/fpu/core.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 649fbc3fcf9f..8e046068d20f 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -49,12 +49,6 @@ static void kernel_fpu_disable(void)
 	this_cpu_write(in_kernel_fpu, true);
 }
 
-static void kernel_fpu_enable(void)
-{
-	WARN_ON_FPU(!this_cpu_read(in_kernel_fpu));
-	this_cpu_write(in_kernel_fpu, false);
-}
-
 static bool kernel_fpu_disabled(void)
 {
 	return this_cpu_read(in_kernel_fpu);
@@ -115,11 +109,6 @@ static void __kernel_fpu_begin(void)
 	__cpu_invalidate_fpregs_state();
 }
 
-static void __kernel_fpu_end(void)
-{
-	kernel_fpu_enable();
-}
-
 void kernel_fpu_begin(void)
 {
 	preempt_disable();
@@ -129,7 +118,9 @@ EXPORT_SYMBOL_GPL(kernel_fpu_begin);
 
 void kernel_fpu_end(void)
 {
-	__kernel_fpu_end();
+	WARN_ON_FPU(!this_cpu_read(in_kernel_fpu));
+
+	this_cpu_write(in_kernel_fpu, false);
 	preempt_enable();
 }
 EXPORT_SYMBOL_GPL(kernel_fpu_end);

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

* [tip:x86/fpu] x86/fpu: Simplify kernel_fpu_begin()
  2019-06-04  7:15 ` [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin Christoph Hellwig
  2019-06-04 11:47   ` Peter Zijlstra
@ 2019-06-17 10:31   ` tip-bot for Christoph Hellwig
  1 sibling, 0 replies; 16+ messages in thread
From: tip-bot for Christoph Hellwig @ 2019-06-17 10:31 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, hpa, hch, bp, bigeasy, x86, riel, nstange, tglx, mingo,
	dave.hansen, linux-kernel

Commit-ID:  6d79d86f9600510e08ad45c72b9d7e664e439e62
Gitweb:     https://git.kernel.org/tip/6d79d86f9600510e08ad45c72b9d7e664e439e62
Author:     Christoph Hellwig <hch@lst.de>
AuthorDate: Tue, 4 Jun 2019 09:15:23 +0200
Committer:  Borislav Petkov <bp@suse.de>
CommitDate: Mon, 17 Jun 2019 12:19:49 +0200

x86/fpu: Simplify kernel_fpu_begin()

Merge two helpers into the main function, remove a pointless local
variable and flatten a conditional.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Nicolai Stange <nstange@suse.de>
Cc: Rik van Riel <riel@surriel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190604071524.12835-3-hch@lst.de
---
 arch/x86/kernel/fpu/core.c | 36 ++++++++++++------------------------
 1 file changed, 12 insertions(+), 24 deletions(-)

diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 8e046068d20f..3f92cfad88f0 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -43,12 +43,6 @@ static DEFINE_PER_CPU(bool, in_kernel_fpu);
  */
 DEFINE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
 
-static void kernel_fpu_disable(void)
-{
-	WARN_ON_FPU(this_cpu_read(in_kernel_fpu));
-	this_cpu_write(in_kernel_fpu, true);
-}
-
 static bool kernel_fpu_disabled(void)
 {
 	return this_cpu_read(in_kernel_fpu);
@@ -88,32 +82,26 @@ bool irq_fpu_usable(void)
 }
 EXPORT_SYMBOL(irq_fpu_usable);
 
-static void __kernel_fpu_begin(void)
+void kernel_fpu_begin(void)
 {
-	struct fpu *fpu = &current->thread.fpu;
+	preempt_disable();
 
 	WARN_ON_FPU(!irq_fpu_usable());
+	WARN_ON_FPU(this_cpu_read(in_kernel_fpu));
 
-	kernel_fpu_disable();
+	this_cpu_write(in_kernel_fpu, true);
 
-	if (!(current->flags & PF_KTHREAD)) {
-		if (!test_thread_flag(TIF_NEED_FPU_LOAD)) {
-			set_thread_flag(TIF_NEED_FPU_LOAD);
-			/*
-			 * Ignore return value -- we don't care if reg state
-			 * is clobbered.
-			 */
-			copy_fpregs_to_fpstate(fpu);
-		}
+	if (!(current->flags & PF_KTHREAD) &&
+	    !test_thread_flag(TIF_NEED_FPU_LOAD)) {
+		set_thread_flag(TIF_NEED_FPU_LOAD);
+		/*
+		 * Ignore return value -- we don't care if reg state
+		 * is clobbered.
+		 */
+		copy_fpregs_to_fpstate(&current->thread.fpu);
 	}
 	__cpu_invalidate_fpregs_state();
 }
-
-void kernel_fpu_begin(void)
-{
-	preempt_disable();
-	__kernel_fpu_begin();
-}
 EXPORT_SYMBOL_GPL(kernel_fpu_begin);
 
 void kernel_fpu_end(void)

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

* [tip:x86/fpu] x86/fpu: Remove the fpu__save() export
  2019-06-04  7:15 ` [PATCH 3/3] x86/fpu: remove the fpu__save export Christoph Hellwig
@ 2019-06-17 10:32   ` tip-bot for Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: tip-bot for Christoph Hellwig @ 2019-06-17 10:32 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, dave.hansen, mingo, bp, nstange, x86, linux-kernel, bigeasy,
	tglx, mingo, hch, riel

Commit-ID:  466329bf407cc5143c3211620faa2c132b9d9a06
Gitweb:     https://git.kernel.org/tip/466329bf407cc5143c3211620faa2c132b9d9a06
Author:     Christoph Hellwig <hch@lst.de>
AuthorDate: Tue, 4 Jun 2019 09:15:24 +0200
Committer:  Borislav Petkov <bp@suse.de>
CommitDate: Mon, 17 Jun 2019 12:21:26 +0200

x86/fpu: Remove the fpu__save() export

This function is only use by the core FPU code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Nicolai Stange <nstange@suse.de>
Cc: Rik van Riel <riel@surriel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190604071524.12835-4-hch@lst.de
---
 arch/x86/kernel/fpu/core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 3f92cfad88f0..12c70840980e 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -134,7 +134,6 @@ void fpu__save(struct fpu *fpu)
 	trace_x86_fpu_after_save(fpu);
 	fpregs_unlock();
 }
-EXPORT_SYMBOL_GPL(fpu__save);
 
 /*
  * Legacy x87 fpstate state init:

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

* x86: FPU cleanups
@ 2010-08-28 16:04 Brian Gerst
  0 siblings, 0 replies; 16+ messages in thread
From: Brian Gerst @ 2010-08-28 16:04 UTC (permalink / raw)
  To: hpa; +Cc: x86, linux-kernel

[PATCH 01/11] x86: Use correct type for %cr4
[PATCH 02/11] x86: Merge fpu_init()
[PATCH 03/11] x86: Merge tolerant_fwait()
[PATCH 04/11] x86: Merge __save_init_fpu()
[PATCH 05/11] x86-64: Disable preemption when using TS_USEDFPU
[PATCH 06/11] x86-64: Fix %cs value in convert_from_fxsr()
[PATCH 07/11] x86-64: Simplify constraints for fxsave/fxtstor
[PATCH 08/11] x86-32: Remove math_emulate stub
[PATCH 09/11] x86: Merge fpu_save_init()
[PATCH 10/11] x86: Remove unnecessary ifdefs from i387 code.
[PATCH 11/11] x86: Remove PSHUFB_XMM5_* macros

 arch/x86/include/asm/i387.h      |  188 ++++++++++----------------------------
 arch/x86/include/asm/processor.h |    4 +-
 arch/x86/kernel/cpu/common.c     |    7 --
 arch/x86/kernel/i387.c           |   49 ++++------
 arch/x86/kernel/process_64.c     |    2 +-
 arch/x86/kernel/traps.c          |   35 +------
 6 files changed, 78 insertions(+), 207 deletions(-)


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

end of thread, other threads:[~2019-06-17 10:33 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-04  7:15 x86 fpu cleanups Christoph Hellwig
2019-06-04  7:15 ` [PATCH 1/3] x86/fpu: Simplify kernel_fpu_end Christoph Hellwig
2019-06-17 10:31   ` [tip:x86/fpu] x86/fpu: Simplify kernel_fpu_end() tip-bot for Christoph Hellwig
2019-06-04  7:15 ` [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin Christoph Hellwig
2019-06-04 11:47   ` Peter Zijlstra
2019-06-04 13:11     ` Christoph Hellwig
2019-06-04 13:34       ` Peter Zijlstra
2019-06-04 14:34         ` Christoph Hellwig
2019-06-17 10:31   ` [tip:x86/fpu] x86/fpu: Simplify kernel_fpu_begin() tip-bot for Christoph Hellwig
2019-06-04  7:15 ` [PATCH 3/3] x86/fpu: remove the fpu__save export Christoph Hellwig
2019-06-17 10:32   ` [tip:x86/fpu] x86/fpu: Remove the fpu__save() export tip-bot for Christoph Hellwig
2019-06-04 17:54 ` [PATCH 4/3] x86/fpu: don't use current->mm to check for a kthread Christoph Hellwig
2019-06-11  7:52   ` Sebastian Andrzej Siewior
2019-06-13 19:03   ` Borislav Petkov
2019-06-13 19:07   ` [tip:x86/urgent] x86/fpu: Don't " tip-bot for Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2010-08-28 16:04 x86: FPU cleanups Brian Gerst

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).