]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/fpu: Make sure x86_task_fpu() doesn't get called for PF_KTHREAD|PF_USER_WORKER...
authorIngo Molnar <mingo@kernel.org>
Wed, 9 Apr 2025 21:11:25 +0000 (23:11 +0200)
committerIngo Molnar <mingo@kernel.org>
Mon, 14 Apr 2025 06:18:29 +0000 (08:18 +0200)
fpu__drop() and arch_release_task_struct() calls x86_task_fpu()
unconditionally, while the FPU context area will not be present
if it's the init task, and should not be in use when it's some
other type of kthread.

Return early for PF_KTHREAD or PF_USER_WORKER tasks. The debug
warning in x86_task_fpu() will catch any kthreads attempting to
use the FPU save area.

Fixed-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250409211127.3544993-7-mingo@kernel.org
arch/x86/kernel/fpu/core.c
arch/x86/kernel/process.c

index e4c20908ee49d150d5be2b3599650579fc70ab33..4a2193892e5d9db97d37ab961071600772bd486c 100644 (file)
@@ -683,7 +683,13 @@ int fpu_clone(struct task_struct *dst, unsigned long clone_flags, bool minimal,
  */
 void fpu__drop(struct task_struct *tsk)
 {
-       struct fpu *fpu = x86_task_fpu(tsk);
+       struct fpu *fpu;
+
+       /* PF_KTHREAD tasks do not use the FPU context area: */
+       if (tsk->flags & (PF_KTHREAD | PF_USER_WORKER))
+               return;
+
+       fpu = x86_task_fpu(tsk);
 
        preempt_disable();
 
index 5fb502c97b08d5c65c840d35e4922654147a0b11..7a1bfb61d86f49d066f43dd74a1aa61f02e6cd2b 100644 (file)
@@ -109,7 +109,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
 #ifdef CONFIG_X86_64
 void arch_release_task_struct(struct task_struct *tsk)
 {
-       if (fpu_state_size_dynamic())
+       if (fpu_state_size_dynamic() && !(tsk->flags & (PF_KTHREAD | PF_USER_WORKER)))
                fpstate_free(x86_task_fpu(tsk));
 }
 #endif