Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [RFC] kernel/reboot: Add orderly_suspend() via /sbin/suspend user mode helper
@ 2026-11-17  8:44 Marek Vasut
  2026-11-17 16:29 ` Bradley Morgan
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Vasut @ 2026-11-17  8:44 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Marek Vasut, Matthew Wilcox (Oracle), Andrew Morton, Breno Leitao,
	Cristian Marussi, Edward Adam Davis, Geert Uytterhoeven,
	Kees Cook, Marco Crivellari, Michal Simek, Oleg Nesterov,
	Pan Chuang, Pavel Tikhomirov, Petr Mladek, Petr Pavlu,
	Prasanna Kumar T S M, Sudeep Holla, arm-scmi, linux-renesas-soc,
	linux-kernel, systemd-devel

Currently, Linux responds to firmware-issued poweroff and reboot requests
by invoking user mode helpers /sbin/poweroff and /sbin/reboot, which give
userspace the ability to perform orderly poweroff and reboot according to
policy set by userspace.

This is not the case for firmware-issued suspend request, which directly
invokes pm_suspend(PM_SUSPEND_MEM), without giving userspace any way to
determine the suspend policy. This is problematic, because the userspace
might not be quite ready to suspend right the instant when the suspend
request from firmware arrives, e.g. because the user is interacting with
the device and the userspace knows that interaction will end in the near
future, at which point the system can be suspended perfectly well.

Introduce a user mode helper, /sbin/suspend, which acts the same way as
the other user mode helpers, and which is invoked when firmware-issued
suspend request arrives. Userspace can use the helper to apply suspend
policy, most likely by invoking init system suspend target. In case the
helper is not present, retain current behavior and suspend immediately.

Note that /sbin/suspend is non-standard. I also considered registering
an input device and sending KEY_SUSPEND via such a device, but that does
not seems nice. I also had a look at wake locks, but I don't think this
is the right tool either. I am sending this as an RFC, because I would
like to get input on this. I am including change for two platforms, SCMI
and ZynqMP, which could benefit from this. Thank you for your input !

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Breno Leitao <leitao@debian.org>
Cc: Cristian Marussi <cristian.marussi@arm.com>
Cc: Edward Adam Davis <eadavis@sina.com>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Kees Cook <kees+treewide@kernel.org>
Cc: Marco Crivellari <marco.crivellari@suse.com>
Cc: Michal Simek <michal.simek@amd.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Pan Chuang <panchuang@vivo.com>
Cc: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Petr Pavlu <petr.pavlu@suse.com>
Cc: Prasanna Kumar T S M <ptsm@linux.microsoft.com>
Cc: Sudeep Holla <sudeep.holla@kernel.org>
Cc: arm-scmi@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-renesas-soc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: systemd-devel@lists.freedesktop.org
---
 .../firmware/arm/scmi/scmi_power_control.c    | 11 +-----
 drivers/soc/xilinx/zynqmp_power.c             |  4 +--
 include/linux/reboot.h                        |  1 +
 kernel/reboot.c                               | 34 +++++++++++++++++++
 4 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/drivers/firmware/arm/scmi/scmi_power_control.c b/drivers/firmware/arm/scmi/scmi_power_control.c
index e791a206768c2..b61afb46ca7ef 100644
--- a/drivers/firmware/arm/scmi/scmi_power_control.c
+++ b/drivers/firmware/arm/scmi/scmi_power_control.c
@@ -80,7 +80,6 @@ enum scmi_syspower_state {
  * @reboot_nb: A notifier_block optionally used to track reboot progress
  * @forceful_work: A worker used to trigger a forceful transition once a
  *		   graceful has timed out.
- * @suspend_work: A worker used to trigger system suspend
  */
 struct scmi_syspower_conf {
 	struct device *dev;
@@ -93,7 +92,6 @@ struct scmi_syspower_conf {
 	struct notifier_block reboot_nb;
 
 	struct delayed_work forceful_work;
-	struct work_struct suspend_work;
 };
 
 #define userspace_nb_to_sconf(x)	\
@@ -254,7 +252,7 @@ static void scmi_request_graceful_transition(struct scmi_syspower_conf *sc,
 		orderly_reboot();
 		break;
 	case SCMI_SYSTEM_SUSPEND:
-		schedule_work(&sc->suspend_work);
+		orderly_suspend();
 		break;
 	default:
 		break;
@@ -323,11 +321,6 @@ static int scmi_userspace_notifier(struct notifier_block *nb,
 	return NOTIFY_OK;
 }
 
-static void scmi_suspend_work_func(struct work_struct *work)
-{
-	pm_suspend(PM_SUSPEND_MEM);
-}
-
 static int scmi_syspower_probe(struct scmi_device *sdev)
 {
 	int ret;
@@ -352,8 +345,6 @@ static int scmi_syspower_probe(struct scmi_device *sdev)
 	sc->dev = &sdev->dev;
 	dev_set_drvdata(&sdev->dev, sc);
 
-	INIT_WORK(&sc->suspend_work, scmi_suspend_work_func);
-
 	return handle->notify_ops->devm_event_notifier_register(sdev,
 							   SCMI_PROTOCOL_SYSTEM,
 					 SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER,
diff --git a/drivers/soc/xilinx/zynqmp_power.c b/drivers/soc/xilinx/zynqmp_power.c
index ce75bc5ca9633..cd1cab58e84ca 100644
--- a/drivers/soc/xilinx/zynqmp_power.c
+++ b/drivers/soc/xilinx/zynqmp_power.c
@@ -112,7 +112,7 @@ static irqreturn_t zynqmp_pm_isr(int irq, void *data)
 			orderly_poweroff(true);
 			break;
 		case SUSPEND_POWER_REQUEST:
-			pm_suspend(PM_SUSPEND_MEM);
+			orderly_suspend();
 			break;
 		default:
 			pr_err("%s Unsupported InitSuspendCb reason code %d\n",
@@ -196,7 +196,7 @@ static void zynqmp_pm_init_suspend_work_fn(struct work_struct *work)
 	if (pm_work->args[0] == SUSPEND_SYSTEM_SHUTDOWN) {
 		orderly_poweroff(true);
 	} else if (pm_work->args[0] == SUSPEND_POWER_REQUEST) {
-		pm_suspend(PM_SUSPEND_MEM);
+		orderly_suspend();
 	} else {
 		pr_err("%s Unsupported InitSuspendCb reason code %d.\n",
 		       __func__, pm_work->args[0]);
diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index aa08c3bbbf59a..c009deb3eb2b6 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -177,6 +177,7 @@ void ctrl_alt_del(void);
 
 extern void orderly_poweroff(bool force);
 extern void orderly_reboot(void);
+extern void orderly_suspend(void);
 
 /**
  * enum hw_protection_action - Hardware protection action
diff --git a/kernel/reboot.c b/kernel/reboot.c
index bc71183d4ad87..1d830051dc920 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -851,6 +851,7 @@ void ctrl_alt_del(void)
 #define POWEROFF_CMD_PATH_LEN  256
 static char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff";
 static const char reboot_cmd[] = "/sbin/reboot";
+static const char suspend_cmd[] = "/sbin/suspend";
 
 static int run_cmd(const char *cmd)
 {
@@ -872,6 +873,20 @@ static int run_cmd(const char *cmd)
 	return ret;
 }
 
+static int __orderly_suspend(void)
+{
+	int ret;
+
+	ret = run_cmd(suspend_cmd);
+
+	if (ret) {
+		pr_info("Failed to start orderly suspend: fall back to suspend-to-mem\n");
+		pm_suspend(PM_SUSPEND_MEM);
+	}
+
+	return ret;
+}
+
 static int __orderly_reboot(void)
 {
 	int ret;
@@ -951,6 +966,25 @@ void orderly_reboot(void)
 }
 EXPORT_SYMBOL_GPL(orderly_reboot);
 
+static void suspend_work_func(struct work_struct *work)
+{
+	__orderly_suspend();
+}
+
+static DECLARE_WORK(suspend_work, suspend_work_func);
+
+/**
+ * orderly_suspend - Trigger an orderly system suspend
+ *
+ * This may be called from any context to trigger a system suspend.
+ * If the orderly suspend fails, it will force an immediate suspend.
+ */
+void orderly_suspend(void)
+{
+	schedule_work(&suspend_work);
+}
+EXPORT_SYMBOL_GPL(orderly_suspend);
+
 static const char *hw_protection_action_str(enum hw_protection_action action)
 {
 	switch (action) {
-- 
2.53.0



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

* Re: [PATCH] [RFC] kernel/reboot: Add orderly_suspend() via /sbin/suspend user mode helper
  2026-11-17  8:44 [PATCH] [RFC] kernel/reboot: Add orderly_suspend() via /sbin/suspend user mode helper Marek Vasut
@ 2026-11-17 16:29 ` Bradley Morgan
  0 siblings, 0 replies; 2+ messages in thread
From: Bradley Morgan @ 2026-11-17 16:29 UTC (permalink / raw)
  To: marek.vasut+renesas
  Cc: akpm, arm-scmi, cristian.marussi, eadavis, geert+renesas,
	kees+treewide, leitao, linux-arm-kernel, linux-kernel,
	linux-renesas-soc, marco.crivellari, michal.simek, oleg,
	panchuang, petr.pavlu, pmladek, ptikhomirov, ptsm, sudeep.holla,
	systemd-devel, willy

On 17 November 2026 08:44:19 GMT, Marek Vasut
<marek.vasut+renesas@mailbox.org> wrote:
>Currently, Linux responds to firmware-issued poweroff and reboot requests
>by invoking user mode helpers /sbin/poweroff and /sbin/reboot, which give
>userspace the ability to perform orderly poweroff and reboot according to
>policy set by userspace.
>
>This is not the case for firmware-issued suspend request, which directly
>invokes pm_suspend(PM_SUSPEND_MEM), without giving userspace any way to
>determine the suspend policy. This is problematic, because the userspace
>might not be quite ready to suspend right the instant when the suspend
>request from firmware arrives, e.g. because the user is interacting with
>the device and the userspace knows that interaction will end in the near
>future, at which point the system can be suspended perfectly well.
>
>Introduce a user mode helper, /sbin/suspend, which acts the same way as
>the other user mode helpers, and which is invoked when firmware-issued
>suspend request arrives. Userspace can use the helper to apply suspend
>policy, most likely by invoking init system suspend target. In case the
>helper is not present, retain current behavior and suspend immediately.
>
>Note that /sbin/suspend is non-standard. I also considered registering
>an input device and sending KEY_SUSPEND via such a device, but that does
>not seems nice. I also had a look at wake locks, but I don't think this
>is the right tool either. I am sending this as an RFC, because I would
>like to get input on this. I am including change for two platforms, SCMI
>and ZynqMP, which could benefit from this. Thank you for your input !

Hmm. let me use my thinking glasses.

>
>Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
>---
>Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
>Cc: Andrew Morton <akpm@linux-foundation.org>
>Cc: Breno Leitao <leitao@debian.org>
>Cc: Cristian Marussi <cristian.marussi@arm.com>
>Cc: Edward Adam Davis <eadavis@sina.com>
>Cc: Geert Uytterhoeven <geert+renesas@glider.be>
>Cc: Kees Cook <kees+treewide@kernel.org>
>Cc: Marco Crivellari <marco.crivellari@suse.com>
>Cc: Michal Simek <michal.simek@amd.com>
>Cc: Oleg Nesterov <oleg@redhat.com>
>Cc: Pan Chuang <panchuang@vivo.com>
>Cc: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
>Cc: Petr Mladek <pmladek@suse.com>
>Cc: Petr Pavlu <petr.pavlu@suse.com>
>Cc: Prasanna Kumar T S M <ptsm@linux.microsoft.com>
>Cc: Sudeep Holla <sudeep.holla@kernel.org>
>Cc: arm-scmi@vger.kernel.org
>Cc: linux-arm-kernel@lists.infradead.org
>Cc: linux-renesas-soc@vger.kernel.org
>Cc: linux-kernel@vger.kernel.org
>Cc: systemd-devel@lists.freedesktop.org
>---
> .../firmware/arm/scmi/scmi_power_control.c    | 11 +-----
> drivers/soc/xilinx/zynqmp_power.c             |  4 +--
> include/linux/reboot.h                        |  1 +
> kernel/reboot.c                               | 34 +++++++++++++++++++
> 4 files changed, 38 insertions(+), 12 deletions(-)
>
>diff --git a/drivers/firmware/arm/scmi/scmi_power_control.c b/drivers/firmware/arm/scmi/scmi_power_control.c
>index e791a206768c2..b61afb46ca7ef 100644
>--- a/drivers/firmware/arm/scmi/scmi_power_control.c
>+++ b/drivers/firmware/arm/scmi/scmi_power_control.c
>@@ -80,7 +80,6 @@ enum scmi_syspower_state {
>  * @reboot_nb: A notifier_block optionally used to track reboot progress
>  * @forceful_work: A worker used to trigger a forceful transition once a
>  *		   graceful has timed out.
>- * @suspend_work: A worker used to trigger system suspend
>  */
> struct scmi_syspower_conf {
> 	struct device *dev;
>@@ -93,7 +92,6 @@ struct scmi_syspower_conf {
> 	struct notifier_block reboot_nb;
> 
> 	struct delayed_work forceful_work;
>-	struct work_struct suspend_work;
> };
> 
> #define userspace_nb_to_sconf(x)	\
>@@ -254,7 +252,7 @@ static void scmi_request_graceful_transition(struct scmi_syspower_conf *sc,
> 		orderly_reboot();
> 		break;
> 	case SCMI_SYSTEM_SUSPEND:
>-		schedule_work(&sc->suspend_work);
>+		orderly_suspend();
> 		break;
> 	default:
> 		break;
>@@ -323,11 +321,6 @@ static int scmi_userspace_notifier(struct notifier_block *nb,
> 	return NOTIFY_OK;
> }
> 
>-static void scmi_suspend_work_func(struct work_struct *work)
>-{
>-	pm_suspend(PM_SUSPEND_MEM);
>-}
>-
> static int scmi_syspower_probe(struct scmi_device *sdev)
> {
> 	int ret;
>@@ -352,8 +345,6 @@ static int scmi_syspower_probe(struct scmi_device *sdev)
> 	sc->dev = &sdev->dev;
> 	dev_set_drvdata(&sdev->dev, sc);
> 
>-	INIT_WORK(&sc->suspend_work, scmi_suspend_work_func);
>-
> 	return handle->notify_ops->devm_event_notifier_register(sdev,
> 							   SCMI_PROTOCOL_SYSTEM,
> 					 SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER,
>diff --git a/drivers/soc/xilinx/zynqmp_power.c b/drivers/soc/xilinx/zynqmp_power.c
>index ce75bc5ca9633..cd1cab58e84ca 100644
>--- a/drivers/soc/xilinx/zynqmp_power.c
>+++ b/drivers/soc/xilinx/zynqmp_power.c
>@@ -112,7 +112,7 @@ static irqreturn_t zynqmp_pm_isr(int irq, void *data)
> 			orderly_poweroff(true);
> 			break;
> 		case SUSPEND_POWER_REQUEST:
>-			pm_suspend(PM_SUSPEND_MEM);
>+			orderly_suspend();
> 			break;
> 		default:
> 			pr_err("%s Unsupported InitSuspendCb reason code %d\n",
>@@ -196,7 +196,7 @@ static void zynqmp_pm_init_suspend_work_fn(struct work_struct *work)
> 	if (pm_work->args[0] == SUSPEND_SYSTEM_SHUTDOWN) {
> 		orderly_poweroff(true);
> 	} else if (pm_work->args[0] == SUSPEND_POWER_REQUEST) {
>-		pm_suspend(PM_SUSPEND_MEM);
>+		orderly_suspend();
> 	} else {
> 		pr_err("%s Unsupported InitSuspendCb reason code %d.\n",
> 		       __func__, pm_work->args[0]);
>diff --git a/include/linux/reboot.h b/include/linux/reboot.h
>index aa08c3bbbf59a..c009deb3eb2b6 100644
>--- a/include/linux/reboot.h
>+++ b/include/linux/reboot.h
>@@ -177,6 +177,7 @@ void ctrl_alt_del(void);
> 
> extern void orderly_poweroff(bool force);
> extern void orderly_reboot(void);
>+extern void orderly_suspend(void);
> 
> /**
>  * enum hw_protection_action - Hardware protection action
>diff --git a/kernel/reboot.c b/kernel/reboot.c
>index bc71183d4ad87..1d830051dc920 100644
>--- a/kernel/reboot.c
>+++ b/kernel/reboot.c
>@@ -851,6 +851,7 @@ void ctrl_alt_del(void)
> #define POWEROFF_CMD_PATH_LEN  256
> static char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff";
> static const char reboot_cmd[] = "/sbin/reboot";
>+static const char suspend_cmd[] = "/sbin/suspend";
> 
> static int run_cmd(const char *cmd)
> {
>@@ -872,6 +873,20 @@ static int run_cmd(const char *cmd)
> 	return ret;
> }
> 
>+static int __orderly_suspend(void)
>+{
>+	int ret;
>+
>+	ret = run_cmd(suspend_cmd);
>+
>+	if (ret) {
>+		pr_info("Failed to start orderly suspend: fall back to suspend-to-mem\n");
>+		pm_suspend(PM_SUSPEND_MEM);
>+	}
>+
>+	return ret;
>+}
>+
> static int __orderly_reboot(void)
> {
> 	int ret;
>@@ -951,6 +966,25 @@ void orderly_reboot(void)
> }
> EXPORT_SYMBOL_GPL(orderly_reboot);
> 
>+static void suspend_work_func(struct work_struct *work)
>+{
>+	__orderly_suspend();
>+}
>+
>+static DECLARE_WORK(suspend_work, suspend_work_func);
>+
>+/**
>+ * orderly_suspend - Trigger an orderly system suspend
>+ *
>+ * This may be called from any context to trigger a system suspend.
>+ * If the orderly suspend fails, it will force an immediate suspend.
>+ */
>+void orderly_suspend(void)
>+{
>+	schedule_work(&suspend_work);
>+}
>+EXPORT_SYMBOL_GPL(orderly_suspend);
>+
> static const char *hw_protection_action_str(enum hw_protection_action
> action)
> {
> 	switch (action) {
>


Right, I had a look, this doesn't "hurt" to merge, like for example
nothing will break, and this looks simple enough, but again, as you said,
/sbin/suspend isn't standard, so that's a crux. I'm thinking using PM may
be a "lightbulb" idea for me here. But I may be going crazy.

hmm, if I had to say tag or no, I'd give the tag:

Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>

Since

1: this doesn't hurt to merge
2: this looks very very simple and quite cool tbh.


--- Thanks!


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

end of thread, other threads:[~2026-11-17 16:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17  8:44 [PATCH] [RFC] kernel/reboot: Add orderly_suspend() via /sbin/suspend user mode helper Marek Vasut
2026-11-17 16:29 ` Bradley Morgan

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