x86 fpu cleanups
Hi all,
this series finishes off some cleanups that are possible now that Sebastians fpu rework is finished.
PATCH 1/3 x86/fpu: Simplify kernel_fpu_end
Remove two little helpers and merge them into kernel_fpu_end to streamline the function.
--- arch/x86/kernel/fpu/core.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
arch/x86/kernel/fpu/core.c +3 -12
@@ -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);
Signature · 1 line
2.20.1
tip-bot for Christoph Hellwig
merge bot[tip:x86/fpu] x86/fpu: Simplify kernel_fpu_end()
x86/fpu: Simplify kernel_fpu_end()
Commit-ID: b78ea19ac22fd7b32d7828066cce3d8f2db5226a Gitweb: https://git.kernel.org/tip/b78ea19ac22fd7b32d7828066cce3d8f2db5226a Author: Christoph Hellwig <[email protected]> AuthorDate: Tue, 4 Jun 2019 09:15:22 +0200 Committer: Borislav Petkov <[email protected]> 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.
--- arch/x86/kernel/fpu/core.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
arch/x86/kernel/fpu/core.c +3 -12
@@ -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);
PATCH 2/3 x86/fpu: Simplify kernel_fpu_begin
In reply to Christoph HellwigMerge two helpers into the main function, remove a pointless local variable and flatten a conditional.
--- arch/x86/kernel/fpu/core.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-)
arch/x86/kernel/fpu/core.c +11 -24
@@ -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 = ¤t->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 (¤t->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 )
Signature · 1 line
2.20.1
Re: [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin
arch/x86/kernel/fpu/core.c bool irq_fpu_usable(void) · line 94
Quoted 10 lines · Christoph Hellwig
arch/x86/kernel/fpu/core.c +5
-0+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..
Quoted 9 lines
arch/x86/kernel/fpu/core.c +6
-0+set_thread_flag (TIF_NEED_FPU_LOAD ); +/* +* Ignore return value -- we don't care if reg state +* is clobbered. +*/ +copy_fpregs_to_fpstate (¤t->thread.fpu); }__cpu_invalidate_fpregs_state (); }
Re: [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin
Quoted 6 lines · Peter Zijlstra
arch/x86/kernel/fpu/core.c bool irq_fpu_usable(void) · line 94
Quoted 1 line
arch/x86/kernel/fpu/core.c +1
-0+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 hasuse_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.
Re: [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Peter Zijlstra
arch/x86/kernel/fpu/core.c bool irq_fpu_usable(void) · line 94
Quoted 1 line
arch/x86/kernel/fpu/core.c +1
-0+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 hasuse_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.
Re: [PATCH 2/3] x86/fpu: Simplify kernel_fpu_begin
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines
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.
tip-bot for Christoph Hellwig
merge bot[tip:x86/fpu] x86/fpu: Simplify kernel_fpu_begin()
In reply to Christoph Hellwigx86/fpu: Simplify kernel_fpu_begin()
Commit-ID: 6d79d86f9600510e08ad45c72b9d7e664e439e62 Gitweb: https://git.kernel.org/tip/6d79d86f9600510e08ad45c72b9d7e664e439e62 Author: Christoph Hellwig <[email protected]> AuthorDate: Tue, 4 Jun 2019 09:15:23 +0200 Committer: Borislav Petkov <[email protected]> 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.
--- arch/x86/kernel/fpu/core.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-)
arch/x86/kernel/fpu/core.c +12 -24
@@ -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 = ¤t->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 (¤t->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 )
PATCH 3/3 x86/fpu: remove the fpu__save export
In reply to Christoph HellwigThis function is only use by the core fpu code.
--- arch/x86/kernel/fpu/core.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kernel/fpu/core.c +0 -1
@@ -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:
Signature · 1 line
2.20.1
tip-bot for Christoph Hellwig
merge bot[tip:x86/fpu] x86/fpu: Remove the fpu__save() export
x86/fpu: Remove the fpu__save() export
Commit-ID: 466329bf407cc5143c3211620faa2c132b9d9a06 Gitweb: https://git.kernel.org/tip/466329bf407cc5143c3211620faa2c132b9d9a06 Author: Christoph Hellwig <[email protected]> AuthorDate: Tue, 4 Jun 2019 09:15:24 +0200 Committer: Borislav Petkov <[email protected]> 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.
--- arch/x86/kernel/fpu/core.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kernel/fpu/core.c +0 -1
@@ -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:
[PATCH 4/3] x86/fpu: don't use current->mm to check for a kthread
In reply to Christoph Hellwigcurrent->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.
--- arch/x86/include/asm/fpu/internal.h | 6 +++--- arch/x86/kernel/fpu/core.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-)
arch/x86/include/asm/fpu/internal.h +3 -3
@@ -536,7 +536,7 @@ static inline void __fpregs_load_activate(void)struct fpu *fpu = ¤t->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
arch/x86/kernel/fpu/core.c +2 -1
@@ -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
Signature · 1 line
2.20.1
Sebastian Andrzej Siewior
Acked-byRe: [PATCH 4/3] x86/fpu: don't use current->mm to check for a kthread
Quoted 6 lines · Christoph Hellwig
current->mmcan be non-NULL if a kthread callsuse_mm. Check forPF_KTHREADinstead to decide when to store user mode FP state.Fixes 2722146eb784 ("x86/fpu: Remove fpu->initialized")Reported-by Peter Zijlstra <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>
For the whole series.
Sebastian
Borislav Petkov
maintainerRe: [PATCH 4/3] x86/fpu: don't use current->mm to check for a kthread
In reply to Christoph HellwigQuoted 10 lines · Christoph Hellwig
current->mmcan be non-NULL if a kthread callsuse_mm. Check forPF_KTHREADinstead to decide when to store user mode FP state.Fixes 2722146eb784 ("x86/fpu: Remove fpu->initialized")Reported-by Peter Zijlstra <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>--- 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.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.tip-bot for Christoph Hellwig
merge bot[tip:x86/urgent] x86/fpu: Don't use current->mm to check for a kthread
In reply to Christoph Hellwigx86/fpu: Don't use current->mm to check for a kthread
Commit-ID: 8d3289f2fa1e0c7e2f72c7352f1efb75d2ad7c76 Gitweb: https://git.kernel.org/tip/8d3289f2fa1e0c7e2f72c7352f1efb75d2ad7c76 Author: Christoph Hellwig <[email protected]> AuthorDate: Tue, 4 Jun 2019 19:54:12 +0200 Committer: Borislav Petkov <[email protected]> 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.
--- arch/x86/include/asm/fpu/internal.h | 6 +++--- arch/x86/kernel/fpu/core.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/fpu/internal.h +3 -3
@@ -536,7 +536,7 @@ static inline void __fpregs_load_activate(void)struct fpu *fpu = ¤t->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
arch/x86/kernel/fpu/core.c +1 -1
@@ -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 );/*