linux/arch/x86/kernel/fpu
Fushuai Wang 31cd31c9e1 x86/fpu: Fix NULL dereference in avx512_status()
Problem
-------
With CONFIG_X86_DEBUG_FPU enabled, reading /proc/[kthread]/arch_status
causes a warning and a NULL pointer dereference.

This is because the AVX-512 timestamp code uses x86_task_fpu() but
doesn't check it for NULL. CONFIG_X86_DEBUG_FPU addles that function
for kernel threads (PF_KTHREAD specifically), making it return NULL.

The point of the warning was to ensure that kernel threads only access
task->fpu after going through kernel_fpu_begin()/_end(). Note: all
kernel tasks exposed in /proc have a valid task->fpu.

Solution
--------
One option is to silence the warning and check for NULL from
x86_task_fpu(). However, that warning is fairly fresh and seems like a
defense against misuse of the FPU state in kernel threads.

Instead, stop outputting AVX-512_elapsed_ms for kernel threads
altogether. The data was garbage anyway because avx512_timestamp is
only updated for user threads, not kernel threads.

If anyone ever wants to track kernel thread AVX-512 use, they can come
back later and do it properly, separate from this bug fix.

[ dhansen: mostly rewrite changelog ]

Fixes: 22aafe3bcb ("x86/fpu: Remove init_task FPU state dependencies, add debugging warning for PF_KTHREAD tasks")
Co-developed-by: Sohil Mehta <sohil.mehta@intel.com>
Signed-off-by: Sohil Mehta <sohil.mehta@intel.com>
Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20250811185044.2227268-1-sohil.mehta%40intel.com
2025-08-11 13:28:07 -07:00
..
bugs.c x86/msr: Prepare for including <linux/percpu.h> into <asm/msr.h> 2024-03-04 12:01:39 +01:00
context.h x86/fpu: Convert task_struct::thread.fpu accesses to use x86_task_fpu() 2025-04-14 08:18:29 +02:00
core.c x86/fpu: Remove xfd argument from __fpstate_reset() 2025-06-24 13:46:32 -07:00
init.c x86/fpu/xstate: Differentiate default features for host and guest FPUs 2025-06-24 13:46:32 -07:00
internal.h x86/fpu: Fully optimize out WARN_ON_FPU() 2025-02-10 14:45:59 -08:00
legacy.h
Makefile
regset.c x86/fpu: Convert task_struct::thread.fpu accesses to use x86_task_fpu() 2025-04-14 08:18:29 +02:00
signal.c x86/fpu: Refactor xfeature bitmask update code for sigframe XSAVE 2025-04-16 10:01:00 +02:00
xstate.c x86/fpu: Fix NULL dereference in avx512_status() 2025-08-11 13:28:07 -07:00
xstate.h Merge branch 'x86/msr' into x86/core, to resolve conflicts 2025-05-13 10:42:06 +02:00