Re: [PATCH] x86/fpu: Put non-enabled dynamic features into init state on sigreturn
From: Chang S. Bae
Date: Sat Nov 21 2026 - 17:08:14 EST
On 11/18/2026 5:38 PM, Andrei Vagin wrote:
How could that happen?
The code relies on this: while a task owns the FPU registers, a dynamic
feature it has not enabled is in its init state.
restore_fpregs_from_fpstate() maintains that by restoring with
fpu_kernel_cfg.max_features (the comment there describes exactly this
case), and fpu__clear_user_states() does the same on signal delivery.
The 64-bit sigreturn path doesn't. restore_fpregs_from_user() restores
from the user buffer with RFBM and init_bv both limited to
fpstate->user_xfeatures, then calls fpregs_mark_activate(). That clears
TIF_NEED_FPU_LOAD, so the full restore on exit to user, which would have
put XTILE_DATA into init state, never runs.
If the registers still belonged to current, that's fine. But the task
can lose them inside rt_sigreturn: the first XRSTOR from the frame
faults and fault_in_readable() sleeps, or the task is simply preempted.
Switching out only saves the registers. It doesn't clear them, so the
next AMX user leaves its tiles there:
CPU0
A: rt_sigreturn() A has AMX permission, XTILE_DATA not enabled
sleeps / preempted A's state saved, TIF_NEED_FPU_LOAD set
B: runs, uses AMX B's tiles are now in the registers
A: back in rt_sigreturn()
restore_fpregs_from_user()
xfd_update_state() XFD[18] set: B's tiles hidden, not cleared
XRSTOR(frame, RFBM) bit 18 not in RFBM or init_bv: untouched
fpregs_mark_activate()
A: exit to user no reload, B's tiles still in the registers
Thanks! Much better description to me.
Here is the selftest to rerpoduce the issue:
Yes, this is good. Maybe better to trim a bit if considering to the mainline.
Thanks,
Chang