lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20230525211655.627415-3-evalenti@kernel.org>
Date:   Thu, 25 May 2023 14:16:54 -0700
From:   Eduardo Valentin <evalenti@...nel.org>
To:     daniel.lezcano@...aro.org, rafael@...nel.org,
        linux-pm@...r.kernel.org
Cc:     Eduardo Valentin <eduval@...zon.com>,
        Amit Kucheria <amitk@...nel.org>,
        Zhang Rui <rui.zhang@...el.com>,
        Jonathan Corbet <corbet@....net>, linux-doc@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: [PATCH 2/3] thermal: core: register reboot nb

From: Eduardo Valentin <eduval@...zon.com>

This commit will register a reboot notifier block
callback for giving opportunity tearing down
thermal zones, e.g. remove their workqueues, and
for giving the governors the opportunity to leave
the hardware in a known safe state.

Cc: "Rafael J. Wysocki" <rafael@...nel.org> (supporter:THERMAL)
Cc: Daniel Lezcano <daniel.lezcano@...aro.org> (supporter:THERMAL)
Cc: Amit Kucheria <amitk@...nel.org> (reviewer:THERMAL)
Cc: Zhang Rui <rui.zhang@...el.com> (reviewer:THERMAL)
Cc: Jonathan Corbet <corbet@....net> (maintainer:DOCUMENTATION)
Cc: linux-pm@...r.kernel.org (open list:THERMAL)
Cc: linux-doc@...r.kernel.org (open list:DOCUMENTATION)
Cc: linux-kernel@...r.kernel.org (open list)

Signed-off-by: Eduardo Valentin <eduval@...zon.com>
---
 drivers/thermal/thermal_core.c | 39 ++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 359e7b2ff0e3..66a255fb650b 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -319,6 +319,12 @@ static void handle_error_temperature(struct thermal_zone_device *tz, int error)
 		tz->governor->check_error(tz, error);
 }
 
+static void handle_reboot_prepare(struct thermal_zone_device *tz)
+{
+	if (tz->governor && tz->governor->reboot_prepare)
+		tz->governor->reboot_prepare(tz);
+}
+
 void thermal_zone_device_critical(struct thermal_zone_device *tz)
 {
 	/*
@@ -1508,6 +1514,30 @@ struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name)
 }
 EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
 
+/* Best effort attempt to leave thermal zones at a safe state across reboots */
+static void thermal_reboot_prepare(void)
+{
+	struct thermal_zone_device *tz;
+
+	list_for_each_entry(tz, &thermal_tz_list, node) {
+		cancel_delayed_work(&tz->poll_queue);
+		handle_reboot_prepare(tz);
+	}
+}
+
+static int thermal_reboot_notify(struct notifier_block *nb,
+				 unsigned long mode, void *_unused)
+{
+	switch (mode) {
+	case SYS_RESTART:
+		thermal_reboot_prepare();
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+
 static int thermal_pm_notify(struct notifier_block *nb,
 			     unsigned long mode, void *_unused)
 {
@@ -1539,6 +1569,10 @@ static struct notifier_block thermal_pm_nb = {
 	.notifier_call = thermal_pm_notify,
 };
 
+static struct notifier_block thermal_reboot_nb = {
+	.notifier_call = thermal_reboot_notify,
+};
+
 static int __init thermal_init(void)
 {
 	int result;
@@ -1572,6 +1606,11 @@ static int __init thermal_init(void)
 		pr_warn("Thermal: Can not register suspend notifier, return %d\n",
 			result);
 
+	result = register_reboot_notifier(&thermal_reboot_nb);
+	if (result)
+		pr_warn("Thermal: Can not register reboot notifier, return %d\n",
+			result);
+
 	return 0;
 
 unregister_governors:
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ