The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Bradley Morgan <bradley.morgan@linux.dev>
To: marek.vasut+renesas@mailbox.org
Cc: akpm@linux-foundation.org, arm-scmi@vger.kernel.org,
	cristian.marussi@arm.com, eadavis@sina.com,
	geert+renesas@glider.be, kees+treewide@kernel.org,
	leitao@debian.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	marco.crivellari@suse.com, michal.simek@amd.com, oleg@redhat.com,
	panchuang@vivo.com, petr.pavlu@suse.com, pmladek@suse.com,
	ptikhomirov@virtuozzo.com, ptsm@linux.microsoft.com,
	sudeep.holla@kernel.org, systemd-devel@lists.freedesktop.org,
	willy@infradead.org
Subject: Re: [PATCH] [RFC] kernel/reboot: Add orderly_suspend() via /sbin/suspend user mode helper
Date: Tue, 17 Nov 2026 16:29:47 +0000	[thread overview]
Message-ID: <03D974DA-29CF-404A-99BD-545D199E0A6B@linux.dev> (raw)
In-Reply-To: <20261117084523.50711-1-marek.vasut+renesas@mailbox.org>

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!

      reply	other threads:[~2026-11-17 16:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=03D974DA-29CF-404A-99BD-545D199E0A6B@linux.dev \
    --to=bradley.morgan@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=arm-scmi@vger.kernel.org \
    --cc=cristian.marussi@arm.com \
    --cc=eadavis@sina.com \
    --cc=geert+renesas@glider.be \
    --cc=kees+treewide@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=marco.crivellari@suse.com \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=michal.simek@amd.com \
    --cc=oleg@redhat.com \
    --cc=panchuang@vivo.com \
    --cc=petr.pavlu@suse.com \
    --cc=pmladek@suse.com \
    --cc=ptikhomirov@virtuozzo.com \
    --cc=ptsm@linux.microsoft.com \
    --cc=sudeep.holla@kernel.org \
    --cc=systemd-devel@lists.freedesktop.org \
    --cc=willy@infradead.org \
    /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