From: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
To: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: Chen Yu <yu.c.chen@intel.com>, Len Brown <len.brown@intel.com>,
Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>,
Zhang Rui <rui.zhang@intel.com>, Zhao Liu <zhao1.liu@intel.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 4/4] thermal: intel: hfi: Add a suspend notifier
Date: Tue, 2 Jan 2024 20:14:59 -0800 [thread overview]
Message-ID: <20240103041459.11113-5-ricardo.neri-calderon@linux.intel.com> (raw)
In-Reply-To: <20240103041459.11113-1-ricardo.neri-calderon@linux.intel.com>
The kernel gives the HFI hardware a memory region that the latter uses to
provide updates to the HFI table. The kernel allocates this memory region
at boot. It remains constant throughout runtime time.
When resuming from suspend or 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. Subsequently, when the
restore kernel transfers control to the image kernel, the second buffer
becomes invalid, potentially leading to memory corruption if the hardware
writes to it (hardware continues using the buffer from the restore kernel).
Add a suspend notifier to disable all HFI instances before jumping to the
image kernel and enable them once the image kernel has been restored. Use
the memory buffer that the image kernel allocated.
For non-boot CPUs, rely on the CPU hotplug callbacks as CPUs are disabled
and enabled during suspend and resume, respectively.
The CPU hotplug callbacks do not cover the boot CPU. Handle the HFI
instance of the boot CPU from the suspend notifier callback.
Cc: Chen Yu <yu.c.chen@intel.com>
Cc: Len Brown <len.brown@intel.com>
Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Zhao Liu <zhao1.liu@linux.intel.com>
Cc: linux-pm@vger.kernel.org
Cc: stable@vger.kernel.org # 6.1
Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
--
Changes since v1:
* Moved registration of the suspend notifier towards the end of
intel_hfi_init(). (Stan)
* Renamed hfi_do_pm_[enable|disable]() to hfi_do_[enable|disable](). Stan
will use these functions outside the suspend notifier. (Stan)
* Added locking to calls to hfi_[enable|disable]() from the suspend
notifier. (Rafael)
---
drivers/thermal/intel/intel_hfi.c | 62 +++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/intel_hfi.c
index 22445403b520..8d6e4f8dc67a 100644
--- a/drivers/thermal/intel/intel_hfi.c
+++ b/drivers/thermal/intel/intel_hfi.c
@@ -30,11 +30,13 @@
#include <linux/kernel.h>
#include <linux/math.h>
#include <linux/mutex.h>
+#include <linux/notifier.h>
#include <linux/percpu-defs.h>
#include <linux/printk.h>
#include <linux/processor.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
+#include <linux/suspend.h>
#include <linux/string.h>
#include <linux/topology.h>
#include <linux/workqueue.h>
@@ -571,6 +573,60 @@ static __init int hfi_parse_features(void)
return 0;
}
+static void hfi_do_enable(void *info)
+{
+ struct hfi_instance *hfi_instance = info;
+
+ hfi_set_hw_table(hfi_instance);
+ hfi_enable();
+}
+
+static void hfi_do_disable(void *info)
+{
+ hfi_disable();
+}
+
+static int hfi_pm_notify(struct notifier_block *nb,
+ unsigned long mode, void *unused)
+{
+ struct hfi_cpu_info *info = &per_cpu(hfi_cpu_info, 0);
+ struct hfi_instance *hfi = info->hfi_instance;
+ int ret = 0;
+
+ /* HFI may not be in use. */
+ if (!hfi)
+ return ret;
+
+ mutex_lock(&hfi_instance_lock);
+ /*
+ * Only handle the HFI instance of the package of the boot CPU. The
+ * instances of other packages are handled in the CPU hotplug callbacks.
+ */
+ switch (mode) {
+ case PM_HIBERNATION_PREPARE:
+ case PM_SUSPEND_PREPARE:
+ case PM_RESTORE_PREPARE:
+ ret = smp_call_function_single(0, hfi_do_disable, NULL, true);
+ break;
+
+ case PM_POST_RESTORE:
+ case PM_POST_HIBERNATION:
+ case PM_POST_SUSPEND:
+ ret = smp_call_function_single(0, hfi_do_enable, hfi, true);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ mutex_unlock(&hfi_instance_lock);
+
+ return ret;
+}
+
+static struct notifier_block hfi_pm_nb = {
+ .notifier_call = hfi_pm_notify,
+};
+
void __init intel_hfi_init(void)
{
struct hfi_instance *hfi_instance;
@@ -602,8 +658,14 @@ void __init intel_hfi_init(void)
if (!hfi_updates_wq)
goto err_nomem;
+ if (register_pm_notifier(&hfi_pm_nb))
+ goto err_pm_notif;
+
return;
+err_pm_notif:
+ destroy_workqueue(hfi_updates_wq);
+
err_nomem:
for (j = 0; j < i; ++j) {
hfi_instance = &hfi_instances[j];
--
2.25.1
next prev parent reply other threads:[~2024-01-03 4:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-03 4:14 [PATCH v2 0/4] thermal: intel: hfi: Fix memory corruption on resume from hibernation Ricardo Neri
2024-01-03 4:14 ` [PATCH v2 1/4] thermal: intel: hfi: Refactor enabling code into helper functions Ricardo Neri
2024-01-03 4:14 ` [PATCH v2 2/4] thermal: intel: hfi: Enable an HFI instance from its first online CPU Ricardo Neri
2024-01-03 4:14 ` [PATCH v2 3/4] thermal: intel: hfi: Disable an HFI instance when all its CPUs go offline Ricardo Neri
2024-01-03 4:14 ` Ricardo Neri [this message]
2024-01-03 13:34 ` [PATCH v2 4/4] thermal: intel: hfi: Add a suspend notifier Rafael J. Wysocki
2024-01-03 13:38 ` Rafael J. Wysocki
2024-01-04 3:02 ` Ricardo Neri
2024-01-03 15:02 ` Stanislaw Gruszka
2024-01-03 18:21 ` Rafael J. Wysocki
2024-01-04 3:04 ` Ricardo Neri
2024-01-03 13:15 ` [PATCH v2 0/4] thermal: intel: hfi: Fix memory corruption on resume from hibernation Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240103041459.11113-5-ricardo.neri-calderon@linux.intel.com \
--to=ricardo.neri-calderon@linux.intel.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=rui.zhang@intel.com \
--cc=srinivas.pandruvada@linux.intel.com \
--cc=stanislaw.gruszka@linux.intel.com \
--cc=yu.c.chen@intel.com \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®