Skip to content

Commit 97566d0

Browse files
ricardonrafaeljw
authored andcommitted
thermal: intel: hfi: Add syscore callbacks for system-wide PM
The kernel allocates a memory buffer and provides its location to the hardware, which uses it to update the HFI table. This allocation occurs during boot and remains constant throughout runtime. When resuming from hibernation, the restore kernel allocates a second memory buffer and reprograms the HFI hardware with the new location as part of a normal boot. The location of the second memory buffer may differ from the one allocated by the image kernel. When the restore kernel transfers control to the image kernel, its HFI buffer becomes invalid, potentially leading to memory corruption if the hardware writes to it (the hardware continues to use the buffer from the restore kernel). It is also possible that the hardware "forgets" the address of the memory buffer when resuming from "deep" suspend. Memory corruption may also occur in such a scenario. To prevent the described memory corruption, disable HFI when preparing to suspend or hibernate. Enable it when resuming. Add syscore callbacks to handle the package of the boot CPU (packages of non-boot CPUs are handled via CPU offline). Syscore ops always run on the boot CPU. Additionally, HFI only needs to be disabled during "deep" suspend and hibernation. Syscore ops only run in these cases. Cc: 6.1+ <stable@vger.kernel.org> # 6.1+ Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com> [ rjw: Comment adjustment, subject and changelog edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 1c53081 commit 97566d0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

drivers/thermal/intel/intel_hfi.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
#include <linux/processor.h>
3636
#include <linux/slab.h>
3737
#include <linux/spinlock.h>
38+
#include <linux/suspend.h>
3839
#include <linux/string.h>
40+
#include <linux/syscore_ops.h>
3941
#include <linux/topology.h>
4042
#include <linux/workqueue.h>
4143

@@ -571,6 +573,30 @@ static __init int hfi_parse_features(void)
571573
return 0;
572574
}
573575

576+
static void hfi_do_enable(void)
577+
{
578+
/* This code runs only on the boot CPU. */
579+
struct hfi_cpu_info *info = &per_cpu(hfi_cpu_info, 0);
580+
struct hfi_instance *hfi_instance = info->hfi_instance;
581+
582+
/* No locking needed. There is no concurrency with CPU online. */
583+
hfi_set_hw_table(hfi_instance);
584+
hfi_enable();
585+
}
586+
587+
static int hfi_do_disable(void)
588+
{
589+
/* No locking needed. There is no concurrency with CPU offline. */
590+
hfi_disable();
591+
592+
return 0;
593+
}
594+
595+
static struct syscore_ops hfi_pm_ops = {
596+
.resume = hfi_do_enable,
597+
.suspend = hfi_do_disable,
598+
};
599+
574600
void __init intel_hfi_init(void)
575601
{
576602
struct hfi_instance *hfi_instance;
@@ -602,6 +628,8 @@ void __init intel_hfi_init(void)
602628
if (!hfi_updates_wq)
603629
goto err_nomem;
604630

631+
register_syscore_ops(&hfi_pm_ops);
632+
605633
return;
606634

607635
err_nomem:

0 commit comments

Comments
 (0)