Skip to content

Commit a401f45

Browse files
ChangSeokBaeKAGA-KOKO
authored andcommitted
x86/fpu: Exclude dynamic states from init_fpstate
== Background == The XSTATE init code initializes all enabled and supported components. Then, the init states are saved in the init_fpstate buffer that is statically allocated in about one page. The AMX TILE_DATA state is large (8KB) but its init state is zero. And the feature comes only with the compacted format with these established dependencies: AMX->XFD->XSAVES. So this state is excludable from init_fpstate. == Problem == But the buffer is formatted to include that large state. Then, this can be the cause of a noisy splat like the below. This came from XRSTORS for the task with init_fpstate in its XSAVE buffer. It is reproducible on AMX systems when the running kernel is built with CONFIG_DEBUG_PAGEALLOC=y and CONFIG_DEBUG_PAGEALLOC_ENABLE_DEFAULT=y: Bad FPU state detected at restore_fpregs_from_fpstate+0x57/0xd0, reinitializing FPU registers. ... RIP: 0010:restore_fpregs_from_fpstate+0x57/0xd0 ? restore_fpregs_from_fpstate+0x45/0xd0 switch_fpu_return+0x4e/0xe0 exit_to_user_mode_prepare+0x17b/0x1b0 syscall_exit_to_user_mode+0x29/0x40 do_syscall_64+0x67/0x80 ? do_syscall_64+0x67/0x80 ? exc_page_fault+0x86/0x180 entry_SYSCALL_64_after_hwframe+0x63/0xcd == Solution == Adjust init_fpstate to exclude dynamic states. XRSTORS from init_fpstate still initializes those states when their bits are set in the requested-feature bitmap. Fixes: 2308ee5 ("x86/fpu/amx: Enable the AMX feature in 64-bit mode") Reported-by: Lin X Wang <[email protected]> Signed-off-by: Chang S. Bae <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Lin X Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d3e021a commit a401f45

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

arch/x86/kernel/fpu/xstate.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,9 +857,12 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
857857
update_regset_xstate_info(fpu_user_cfg.max_size,
858858
fpu_user_cfg.max_features);
859859

860-
/* Bring init_fpstate size and features up to date */
861-
init_fpstate.size = fpu_kernel_cfg.max_size;
862-
init_fpstate.xfeatures = fpu_kernel_cfg.max_features;
860+
/*
861+
* init_fpstate excludes dynamic states as they are large but init
862+
* state is zero.
863+
*/
864+
init_fpstate.size = fpu_kernel_cfg.default_size;
865+
init_fpstate.xfeatures = fpu_kernel_cfg.default_features;
863866

864867
if (init_fpstate.size > sizeof(init_fpstate.regs)) {
865868
pr_warn("x86/fpu: init_fpstate buffer too small (%zu < %d), disabling XSAVE\n",

0 commit comments

Comments
 (0)