Skip to content

Commit 8d3289f

Browse files
Christoph Hellwigsuryasaimadhu
authored andcommitted
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: 2722146 ("x86/fpu: Remove fpu->initialized") Reported-by: Peter Zijlstra <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Sebastian Andrzej Siewior <[email protected]> Cc: Aubrey Li <[email protected]> Cc: Dave Hansen <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jann Horn <[email protected]> Cc: Nicolai Stange <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: x86-ml <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 71ab832 commit 8d3289f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

arch/x86/include/asm/fpu/internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static inline void __fpregs_load_activate(void)
536536
struct fpu *fpu = &current->thread.fpu;
537537
int cpu = smp_processor_id();
538538

539-
if (WARN_ON_ONCE(current->mm == NULL))
539+
if (WARN_ON_ONCE(current->flags & PF_KTHREAD))
540540
return;
541541

542542
if (!fpregs_state_valid(fpu, cpu)) {
@@ -567,11 +567,11 @@ static inline void __fpregs_load_activate(void)
567567
* otherwise.
568568
*
569569
* The FPU context is only stored/restored for a user task and
570-
* ->mm is used to distinguish between kernel and user threads.
570+
* PF_KTHREAD is used to distinguish between kernel and user threads.
571571
*/
572572
static inline void switch_fpu_prepare(struct fpu *old_fpu, int cpu)
573573
{
574-
if (static_cpu_has(X86_FEATURE_FPU) && current->mm) {
574+
if (static_cpu_has(X86_FEATURE_FPU) && !(current->flags & PF_KTHREAD)) {
575575
if (!copy_fpregs_to_fpstate(old_fpu))
576576
old_fpu->last_cpu = -1;
577577
else

arch/x86/kernel/fpu/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static void __kernel_fpu_begin(void)
102102

103103
kernel_fpu_disable();
104104

105-
if (current->mm) {
105+
if (!(current->flags & PF_KTHREAD)) {
106106
if (!test_thread_flag(TIF_NEED_FPU_LOAD)) {
107107
set_thread_flag(TIF_NEED_FPU_LOAD);
108108
/*

0 commit comments

Comments
 (0)