[PATCH v3 2/2] x86/fpu: Update the debug flow for x86_task_fpu()
From: Sohil Mehta
Date: Wed Jul 23 2025 - 21:36:06 EST
Kernel threads aren't expected to directly access struct fpu using
x86_task_fpu(). They typically access the FPU state using pairs of
kernel_fpu_begin()/kernel_fpu_end().
When CONFIG_X86_DEBUG_FPU is set, any usage of x86_task_fpu() by kernel
threads is flagged with a WARN_ON_ONCE(). However, along with the
warning, x86_task_fpu() returns a NULL pointer, which deviates from the
flow without the debug config.
Changing the return value could make failures harder to debug by masking
problems or introducing its own set of issues. Keep the behavior of
x86_task_fpu() consistent across debug and non-debug configurations,
except for the warning.
Also, update the warning to include PF_USER_WORKER, as these tasks are
treated as equivalent to kernel threads during FPU state management as
well as context switch.
Signed-off-by: Sohil Mehta <sohil.mehta@xxxxxxxxx>
---
v3: Improve commit message
v2: New patch
This patch is less urgent than Patch 1, which fixes the real issue.
---
arch/x86/kernel/fpu/core.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index ea138583dd92..ba16dda697b1 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -58,8 +58,7 @@ DEFINE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
#ifdef CONFIG_X86_DEBUG_FPU
struct fpu *x86_task_fpu(struct task_struct *task)
{
- if (WARN_ON_ONCE(task->flags & PF_KTHREAD))
- return NULL;
+ WARN_ON_ONCE(task->flags & (PF_KTHREAD | PF_USER_WORKER));
return (void *)task + sizeof(*task);
}
--
2.43.0