Re: [PATCH v2 2/2] x86/fpu: Update the debug flow for x86_task_fpu()

From: Sohil Mehta
Date: Mon Jul 21 2025 - 21:40:36 EST


On 7/21/2025 3:34 PM, Dave Hansen wrote:
> On 7/21/25 14:53, Sohil Mehta wrote:
>> Also, update the warning to include PF_USER_WORKER, as these tasks are
>> treated the same as kernel threads in the FPU context.
>
> How so?

There are quite a few checks that special case PF_KTHREAD along with
PF_USER_WORKER. For example, FPSTATE allocation and freeing as well as
some context switch paths. Did I misinterpret something?

I believe it originates here:
https://lore.kernel.org/all/560c844c-f128-555b-40c6-31baff27537f@xxxxxxxxx/

switch_fpu():
if (!test_tsk_thread_flag(old, TIF_NEED_FPU_LOAD) &&
cpu_feature_enabled(X86_FEATURE_FPU) &&
!(old->flags & (PF_KTHREAD | PF_USER_WORKER))) {
struct fpu *old_fpu = x86_task_fpu(old);


arch_release_task_struct():
if (fpu_state_size_dynamic() && !(tsk->flags & (PF_KTHREAD |
PF_USER_WORKER)))
fpstate_free(x86_task_fpu(tsk));


fpregs_restore_userregs():
if (WARN_ON_ONCE(current->flags & (PF_KTHREAD | PF_USER_WORKER)))
return;

kernel_fpu_begin_mask():
if (!(current->flags & (PF_KTHREAD | PF_USER_WORKER)) &&
!test_thread_flag(TIF_NEED_FPU_LOAD)) {
set_thread_flag(TIF_NEED_FPU_LOAD);
save_fpregs_to_fpstate(x86_task_fpu(current));
}