[PATCH 0/6] x86/fpu: Fix issues around resetting fpstate
From: Chang S. Bae
Date: Mon Nov 30 2026 - 16:19:19 EST
Hi all,
This series addresses a couple of issues in fpu_flush_thread():
Guixiong first reported and posted a patch [1] to address the memory
leak on the exec() path. When TILE_DATA is active, the fpstate storage
is expanded to record the large state. Then an exec() will reset the
current fpstate entirely. But the issue there is not free up the
reallocated fpstate memory - addressed in patch5 and test case in patch6.
While working on this, syzbot reported another issue [2,3] on this path
for resetting fpstate without fpregs_lock(). There is a race condition.
Patch3 has the fix.
Then a couple of follow-up on that:
Right now fpu_reset_fpstate_regs() is called on the exec() path only
but it holds the lock just for the register storage. Including the
metadata reset, as per Dave's suggestion, makes the same code sequence
as in fpu_clone(). Similarily fpstate free code could be restructured.
So, the series ends up including some refactoring (patch2/4).
Finally, while looking at the fpstate_reset() sites, a removable one
was also found, so include the minor fix as well (patch1).
Cc'ed stable@ since those refactoring if bought will change the base
where the fixes are applied.
[1]: https://lore.kernel.org/20260929151013.81562-2-weiguixiong@xxxxxxxxxxxxx
[2]: https://syzkaller.appspot.com/bug?extid=58cbd7974a103b8b8916
[3]: https://syzkaller.appspot.com/bug?extid=b07ec23d35be305855be
Thanks,
Chang
Chang S. Bae (6):
x86/fpu: Remove remaining fpstate reset for init_task
x86/fpu: Refactor fpstate storage reset sequence
x86/fpu: Reset the fpstate on exec() under fpregs_lock()
x86/fpu: Refactor fpstate memory free helpers
x86/fpu: Fix memory leak with dynamic fpstate and exec()
selftests/x86/amx: Test fpstate memory cleanup on exec()
arch/x86/include/asm/fpu/api.h | 6 +-
arch/x86/kernel/fpu/core.c | 111 +++++++++++++++---------
arch/x86/kernel/fpu/xstate.c | 19 ++--
arch/x86/kernel/process.c | 2 +-
tools/testing/selftests/x86/Makefile | 1 +
tools/testing/selftests/x86/amx.c | 51 ++++++++++-
tools/testing/selftests/x86/amx_exec.sh | 87 +++++++++++++++++++
7 files changed, 223 insertions(+), 54 deletions(-)
create mode 100755 tools/testing/selftests/x86/amx_exec.sh
base-commit: 75b8262a97abcb972ef897dad5f94d425157b635
--
2.53.0