public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC] misc/pvpanic: add support for normal shutdowns
@ 2023-11-04 11:29 Thomas Weißschuh
  2023-11-04 13:05 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 13+ messages in thread
From: Thomas Weißschuh @ 2023-11-04 11:29 UTC (permalink / raw)
  To: Arnd Bergmann, Greg Kroah-Hartman
  Cc: linux-kernel, Zhangjin Wu, Willy Tarreau, Yuan Tan,
	Thomas Weißschuh

Shutdown requests are normally hardware dependent.
By extending pvpanic to also handle shutdown requests, guests can
submit such requests with an easily implementable and cross-platform
mechanism.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
The corresponding patch to qemu has also been submitted[0].
General discussions about the feature should happen on the other thread.

[0] https://lore.kernel.org/qemu-devel/20231104-pvpanic-shutdown-v1-0-02353157891b@t-8ch.de/
---
 drivers/misc/pvpanic/pvpanic.c | 19 +++++++++++++++++--
 include/uapi/misc/pvpanic.h    |  1 +
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/pvpanic/pvpanic.c b/drivers/misc/pvpanic/pvpanic.c
index 305b367e0ce3..d7d807f5e47a 100644
--- a/drivers/misc/pvpanic/pvpanic.c
+++ b/drivers/misc/pvpanic/pvpanic.c
@@ -15,6 +15,7 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/panic_notifier.h>
+#include <linux/reboot.h>
 #include <linux/types.h>
 #include <linux/cdev.h>
 #include <linux/list.h>
@@ -74,6 +75,13 @@ static struct notifier_block pvpanic_panic_nb = {
 	.priority = INT_MAX,
 };
 
+static int pvpanic_sys_off(struct sys_off_data *data)
+{
+	pvpanic_send_event(PVPANIC_SHUTDOWN);
+
+	return NOTIFY_DONE;
+}
+
 static void pvpanic_remove(void *param)
 {
 	struct pvpanic_instance *pi_cur, *pi_next;
@@ -152,7 +160,7 @@ int devm_pvpanic_probe(struct device *dev, void __iomem *base)
 		return -ENOMEM;
 
 	pi->base = base;
-	pi->capability = PVPANIC_PANICKED | PVPANIC_CRASH_LOADED;
+	pi->capability = PVPANIC_PANICKED | PVPANIC_CRASH_LOADED | PVPANIC_SHUTDOWN;
 
 	/* initlize capability by RDPT */
 	pi->capability &= ioread8(base);
@@ -168,12 +176,18 @@ int devm_pvpanic_probe(struct device *dev, void __iomem *base)
 }
 EXPORT_SYMBOL_GPL(devm_pvpanic_probe);
 
+static struct sys_off_handler *sys_off_handler;
+
 static int pvpanic_init(void)
 {
 	INIT_LIST_HEAD(&pvpanic_list);
 	spin_lock_init(&pvpanic_lock);
 
 	atomic_notifier_chain_register(&panic_notifier_list, &pvpanic_panic_nb);
+	sys_off_handler = register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_DEFAULT,
+						   pvpanic_sys_off, NULL);
+	if (IS_ERR(sys_off_handler))
+		sys_off_handler = NULL;
 
 	return 0;
 }
@@ -182,6 +196,7 @@ module_init(pvpanic_init);
 static void pvpanic_exit(void)
 {
 	atomic_notifier_chain_unregister(&panic_notifier_list, &pvpanic_panic_nb);
-
+	if (sys_off_handler)
+		unregister_sys_off_handler(sys_off_handler);
 }
 module_exit(pvpanic_exit);
diff --git a/include/uapi/misc/pvpanic.h b/include/uapi/misc/pvpanic.h
index 54b7485390d3..82fc618bfbcf 100644
--- a/include/uapi/misc/pvpanic.h
+++ b/include/uapi/misc/pvpanic.h
@@ -5,5 +5,6 @@
 
 #define PVPANIC_PANICKED	(1 << 0)
 #define PVPANIC_CRASH_LOADED	(1 << 1)
+#define PVPANIC_SHUTDOWN	(1 << 2)
 
 #endif /* __PVPANIC_H__ */

---
base-commit: 90b0c2b2edd1adff742c621e246562fbefa11b70
change-id: 20231104-pvpanic-shutdown-5fa38a879ad1

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>


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

end of thread, other threads:[~2024-02-28  7:02 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-04 11:29 [PATCH RFC] misc/pvpanic: add support for normal shutdowns Thomas Weißschuh
2023-11-04 13:05 ` Greg Kroah-Hartman
2023-11-04 13:16   ` Thomas Weißschuh
2023-11-04 13:28     ` Greg Kroah-Hartman
2023-11-04 13:53       ` Thomas Weißschuh
2023-11-04 13:56         ` Willy Tarreau
2023-11-04 17:07           ` Greg Kroah-Hartman
2023-11-04 17:32             ` Thomas Weißschuh
2023-11-05  6:59               ` Willy Tarreau
2024-02-13 10:41   ` Michael S. Tsirkin
2024-02-21 17:18     ` Thomas Weißschuh
2024-02-28  6:48     ` Thomas Weißschuh
2024-02-28  7:02       ` Arnd Bergmann

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