mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] thermal: intel: hfi: Stop hardware writing to freed memory after kexec
@ 2026-10-28  0:14 Jez Ng via B4 Relay
  2026-10-28  0:14 ` [PATCH 1/2] thermal: intel: hfi: Disable HFI on shutdown and kexec Jez Ng via B4 Relay
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jez Ng via B4 Relay @ 2026-10-28  0:14 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Ricardo Neri, Len Brown, Stanislaw Gruszka
  Cc: Rafael J. Wysocki, linux-pm, linux-kernel, stable, Andrew James,
	John Ranzie, Jez Ng

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@sfcompute.com>



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-19  5:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-28  0:14 [PATCH 0/2] thermal: intel: hfi: Stop hardware writing to freed memory after kexec Jez Ng via B4 Relay
2026-10-28  0:14 ` [PATCH 1/2] thermal: intel: hfi: Disable HFI on shutdown and kexec Jez Ng via B4 Relay
2026-11-19  5:42   ` Ricardo Neri
2026-10-28  0:14 ` [PATCH 2/2] thermal: intel: hfi: Disable HFI left enabled by a previous kernel Jez Ng via B4 Relay
2026-11-19  5:42   ` Ricardo Neri
2026-11-13 15:26 ` [PATCH 0/2] thermal: intel: hfi: Stop hardware writing to freed memory after kexec Rafael J. Wysocki (Intel)
2026-11-19  5:45   ` Ricardo Neri

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®