Skip to content

Commit c360bdc

Browse files
author
Ingo Molnar
committed
x86/fpu: Make sure x86_task_fpu() doesn't get called for PF_KTHREAD|PF_USER_WORKER tasks during exit
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
1 parent ec2227e commit c360bdc

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

arch/x86/kernel/fpu/core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,13 @@ int fpu_clone(struct task_struct *dst, unsigned long clone_flags, bool minimal,
683683
*/
684684
void fpu__drop(struct task_struct *tsk)
685685
{
686-
struct fpu *fpu = x86_task_fpu(tsk);
686+
struct fpu *fpu;
687+
688+
/* PF_KTHREAD tasks do not use the FPU context area: */
689+
if (tsk->flags & (PF_KTHREAD | PF_USER_WORKER))
690+
return;
691+
692+
fpu = x86_task_fpu(tsk);
687693

688694
preempt_disable();
689695

arch/x86/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
109109
#ifdef CONFIG_X86_64
110110
void arch_release_task_struct(struct task_struct *tsk)
111111
{
112-
if (fpu_state_size_dynamic())
112+
if (fpu_state_size_dynamic() && !(tsk->flags & (PF_KTHREAD | PF_USER_WORKER)))
113113
fpstate_free(x86_task_fpu(tsk));
114114
}
115115
#endif

0 commit comments

Comments
 (0)