Re: [PATCH 0/2] thermal: intel: hfi: Stop hardware writing to freed memory after kexec
From: Ricardo Neri
Date: Thu Nov 19 2026 - 00:38:44 EST
On Fri, Nov 13, 2026 at 04:26:06PM +0100, Rafael J. Wysocki (Intel) wrote:
> On Wed, Oct 28, 2026 at 1:20 AM Jez Ng via B4 Relay
> <devnull+jez.sfcompute.com@xxxxxxxxxx> wrote:
> >
> > 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.
>
> Ricardo, can you please have a look at this series and let me know
> what you think about it?
Hi Rafael, Jez,
These patches fix a real problem, and I think they can be applied
once we close on my comments on patch 2.
This series does not cover processors that ignore a write to
MSR_IA32_HW_FEEDBACK_PTR after the first one. On those processors, the
HFI table of the first kernel after reset must be preserved across
kexec and reused by the next kernel. I have work in progress for that,
based on Kexec Handover (KHO), and plan to send it as a follow-up to
this series.