[PATCH 0/2] thermal: intel: hfi: Stop hardware writing to freed memory after kexec
From: Jez Ng via B4 Relay
Date: Tue Oct 27 2026 - 20:20:55 EST
HFI hardware writes updates to a table at a physical address the kernel
programs. Nothing disables HFI on shutdown, and since commit b33f3d2677b8
("thermal: intel: hfi: Enable HFI only when required") a kernel that
starts without thermal netlink clients does not touch HFI at all. So
after a kexec, hardware keeps writing into the previous kernel's table,
which the new kernel treats as free memory.
We hit this on dual-socket Sapphire Rapids hosts (Xeon Platinum 8462Y+)
that boot a Debian 6.1 kernel and kexec into a 7.0 kernel. The new
kernel crashed in find_inode_fast() when the inode hash table landed on
one of the old table pages. Reading MSR 0x17d0 on the running 7.0
kernel showed both packages still pointing at the 6.1 kernel's tables,
and the corruption had the HFI table layout: a timestamp, a changed
flag, then one row per CPU.
Patch 1 disables HFI in a syscore shutdown callback, which covers
reboot, power off and kexec, and keeps it disabled afterwards: on kexec,
user space runs until machine_shutdown(), so a new thermal netlink
client could otherwise enable HFI again. Patch 2 makes a starting kernel
disable HFI if the previous kernel left it enabled. Patch 2 can only
narrow the window: hardware can still write between kernel start and
the moment the package's first CPU reaches the thermal online callback,
which was about 30 seconds into boot on these hosts.
This is the kexec counterpart of the hibernation corruption fixed by
commit 97566d09fd02 ("thermal: intel: hfi: Add syscore callbacks for
system-wide PM"), which disables HFI for suspend and hibernation but not
for shutdown.
Tested on one of the hosts above with both patches applied to this base,
alternating 100 kexecs (kexec_file_load + reboot(LINUX_REBOOT_CMD_KEXEC))
between the patched kernel and an unpatched 7.0 kernel. Before each
kexec, a thermal netlink subscriber enabled HFI on both packages. All
100 passed:
- Patch 1: after each of the 50 kexecs out of the patched kernel, the
unpatched kernel read HW_FEEDBACK_CONFIG = 0 on both packages.
- Patch 2: after each of the 50 kexecs into the patched kernel, it
logged "HFI left enabled on package N, disabled" for both packages
and read HW_FEEDBACK_CONFIG = 0.
A test-only 5 second sleep after the shutdown callback, with a thermal
netlink client subscribing during it, showed that patch 1 keeps HFI
disabled. Without the hfi_shutdown_done check, the next kernel found HFI
enabled again.
Thanks to Andrew James and John Ranzie for reviewing.
The investigation and testing were done via Opus 5.5, as were the
drafting of the patches and changelogs. I reviewed all of it.
---
Jez Ng (2):
thermal: intel: hfi: Disable HFI on shutdown and kexec
thermal: intel: hfi: Disable HFI left enabled by a previous kernel
drivers/thermal/intel/intel_hfi.c | 71 ++++++++++++++++++++++++++++++++++-----
1 file changed, 63 insertions(+), 8 deletions(-)
---
base-commit: 70f331d89564126fdcaaa37f25194fe391d8f3fa
change-id: 20261027-hfi-kexec-e7c4b7f584be
Best regards,
--
Jez Ng <jez@xxxxxxxxxxxxx>