Re: [PATCH] [RFC] kernel/reboot: Add orderly_suspend() via /sbin/suspend user mode helper
From: Bradley Morgan
Date: Tue Nov 17 2026 - 11:29:57 EST
On 17 November 2026 08:44:19 GMT, Marek Vasut
<marek.vasut+renesas@xxxxxxxxxxx> 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@xxxxxxxxxxx>
>---
>Cc: "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx>
>Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
>Cc: Breno Leitao <leitao@xxxxxxxxxx>
>Cc: Cristian Marussi <cristian.marussi@xxxxxxx>
>Cc: Edward Adam Davis <eadavis@xxxxxxxx>
>Cc: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
>Cc: Kees Cook <kees+treewide@xxxxxxxxxx>
>Cc: Marco Crivellari <marco.crivellari@xxxxxxxx>
>Cc: Michal Simek <michal.simek@xxxxxxx>
>Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
>Cc: Pan Chuang <panchuang@xxxxxxxx>
>Cc: Pavel Tikhomirov <ptikhomirov@xxxxxxxxxxxxx>
>Cc: Petr Mladek <pmladek@xxxxxxxx>
>Cc: Petr Pavlu <petr.pavlu@xxxxxxxx>
>Cc: Prasanna Kumar T S M <ptsm@xxxxxxxxxxxxxxxxxxx>
>Cc: Sudeep Holla <sudeep.holla@xxxxxxxxxx>
>Cc: arm-scmi@xxxxxxxxxxxxxxx
>Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
>Cc: linux-renesas-soc@xxxxxxxxxxxxxxx
>Cc: linux-kernel@xxxxxxxxxxxxxxx
>Cc: systemd-devel@xxxxxxxxxxxxxxxxxxxxx
>---
> .../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@xxxxxxxxx>
Since
1: this doesn't hurt to merge
2: this looks very very simple and quite cool tbh.
--- Thanks!