All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernel/reboot: Explicitly notify if halt occurred instead of power off
@ 2023-11-03  6:14 Dongmin Lee
  2023-11-04  1:05 ` kernel test robot
  0 siblings, 1 reply; 3+ messages in thread
From: Dongmin Lee @ 2023-11-03  6:14 UTC (permalink / raw)
  To: linux-kernel; +Cc: Dongmin Lee

When kernel_can_power_off() returns false, and reboot has called with
LINUX_REBOOT_CMD_POWER_OFF, kernel_halt() will be initiated instead of
actual power off function.

However, in this situation, Kernel never explicitly notifies user that
system halted instead of requested power off.

Since halt and power off perform different behavior, and user initiated
reboot call with power off command, not halt, This could be unintended
behavior to user, like this:

~ # poweroff -f
[    3.581482] reboot: System halted

Therefore, this explicitly notifies user that poweroff is not available,
and halting has been occured as an alternative behavior instead:

~ # poweroff -f
[    4.123668] reboot: Power off not available: System halted instead

Signed-off-by: Dongmin Lee <ldmldm05@gmail.com>
---
 kernel/reboot.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/kernel/reboot.c b/kernel/reboot.c
index 395a0ea3c7a8..dd33b07cc2f1 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -58,6 +58,13 @@ struct sys_off_handler {
 	struct device *dev;
 };
 
+/*
+ * This variable is used to indicate if a halt initiated instead when
+ * reboot call is invoked with LINUX_REBOOT_CMD_POWER_OFF, but system
+ * cannot be powered off. This allowes kernel_halt() to notify that.
+ */
+int poweroff_fallback_to_halt = 0;
+
 /*
  * Temporary stub that prevents linkage failure while we're in process
  * of removing all uses of legacy pm_power_off() around the kernel.
@@ -297,7 +304,10 @@ void kernel_halt(void)
 	kernel_shutdown_prepare(SYSTEM_HALT);
 	migrate_to_reboot_cpu();
 	syscore_shutdown();
-	pr_emerg("System halted\n");
+	if(poweroff_fallback_to_halt)
+		pr_emerg("Power off not available: System halted instead\n");
+	else
+		pr_emerg("System halted\n");
 	kmsg_dump(KMSG_DUMP_SHUTDOWN);
 	machine_halt();
 }
@@ -732,8 +742,10 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 	/* Instead of trying to make the power_off code look like
 	 * halt when pm_power_off is not set do it the easy way.
 	 */
-	if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !kernel_can_power_off())
+	if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !kernel_can_power_off()) {
+		poweroff_fallback_to_halt = 1;
 		cmd = LINUX_REBOOT_CMD_HALT;
+	}
 
 	mutex_lock(&system_transition_mutex);
 	switch (cmd) {

base-commit: bc3012f4e3a9765de81f454cb8f9bb16aafc6ff5
-- 
2.39.3 (Apple Git-145)


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

* Re: [PATCH] kernel/reboot: Explicitly notify if halt occurred instead of power off
  2023-11-03  6:14 [PATCH] kernel/reboot: Explicitly notify if halt occurred instead of power off Dongmin Lee
@ 2023-11-04  1:05 ` kernel test robot
  2023-11-04 11:33   ` [PATCH v2] " Dongmin Lee
  0 siblings, 1 reply; 3+ messages in thread
From: kernel test robot @ 2023-11-04  1:05 UTC (permalink / raw)
  To: Dongmin Lee, linux-kernel; +Cc: oe-kbuild-all, Dongmin Lee

Hi Dongmin,

kernel test robot noticed the following build warnings:

[auto build test WARNING on bc3012f4e3a9765de81f454cb8f9bb16aafc6ff5]

url:    https://github.com/intel-lab-lkp/linux/commits/Dongmin-Lee/kernel-reboot-Explicitly-notify-if-halt-occurred-instead-of-power-off/20231103-142501
base:   bc3012f4e3a9765de81f454cb8f9bb16aafc6ff5
patch link:    https://lore.kernel.org/r/20231103061448.68118-1-ldmldm05%40gmail.com
patch subject: [PATCH] kernel/reboot: Explicitly notify if halt occurred instead of power off
config: x86_64-randconfig-123-20231104 (https://download.01.org/0day-ci/archive/20231104/202311040832.yiyrijgk-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231104/202311040832.yiyrijgk-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311040832.yiyrijgk-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> kernel/reboot.c:66:5: sparse: sparse: symbol 'poweroff_fallback_to_halt' was not declared. Should it be static?

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* [PATCH v2] kernel/reboot: Explicitly notify if halt occurred instead of power off
  2023-11-04  1:05 ` kernel test robot
@ 2023-11-04 11:33   ` Dongmin Lee
  0 siblings, 0 replies; 3+ messages in thread
From: Dongmin Lee @ 2023-11-04 11:33 UTC (permalink / raw)
  To: akpm, lkp; +Cc: ldmldm05, linux-kernel, oe-kbuild-all

When kernel_can_power_off() returns false, and reboot has called with
LINUX_REBOOT_CMD_POWER_OFF, kernel_halt() will be initiated instead of
actual power off function.

However, in this situation, Kernel never explicitly notifies user that
system halted instead of requested power off.

Since halt and power off perform different behavior, and user initiated
reboot call with power off command, not halt, This could be unintended
behavior to user, like this:

~ # poweroff -f
[    3.581482] reboot: System halted

Therefore, this explicitly notifies user that poweroff is not available,
and halting has been occured as an alternative behavior instead:

~ # poweroff -f
[    4.123668] reboot: Power off not available: System halted instead

Signed-off-by: Dongmin Lee <ldmldm05@gmail.com>
---
v1->v2:
 - changed new variable poweroff_fallback_to_halt to static bool as per
   kernel test robot's sparse warning notification.
 - fixed minor coding style issue

 kernel/reboot.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/kernel/reboot.c b/kernel/reboot.c
index 395a0ea3c7a8..34ea519e3d94 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -58,6 +58,13 @@ struct sys_off_handler {
 	struct device *dev;
 };
 
+/*
+ * This variable is used to indicate if a halt initiated instead when
+ * reboot call is invoked with LINUX_REBOOT_CMD_POWER_OFF, but system
+ * cannot be powered off. This allowes kernel_halt() to notify that.
+ */
+static bool poweroff_fallback_to_halt;
+
 /*
  * Temporary stub that prevents linkage failure while we're in process
  * of removing all uses of legacy pm_power_off() around the kernel.
@@ -297,7 +304,10 @@ void kernel_halt(void)
 	kernel_shutdown_prepare(SYSTEM_HALT);
 	migrate_to_reboot_cpu();
 	syscore_shutdown();
-	pr_emerg("System halted\n");
+	if (poweroff_fallback_to_halt)
+		pr_emerg("Power off not available: System halted instead\n");
+	else
+		pr_emerg("System halted\n");
 	kmsg_dump(KMSG_DUMP_SHUTDOWN);
 	machine_halt();
 }
@@ -732,8 +742,10 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 	/* Instead of trying to make the power_off code look like
 	 * halt when pm_power_off is not set do it the easy way.
 	 */
-	if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !kernel_can_power_off())
+	if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !kernel_can_power_off()) {
+		poweroff_fallback_to_halt = true;
 		cmd = LINUX_REBOOT_CMD_HALT;
+	}
 
 	mutex_lock(&system_transition_mutex);
 	switch (cmd) {

base-commit: bc3012f4e3a9765de81f454cb8f9bb16aafc6ff5
-- 
2.39.3 (Apple Git-145)


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

end of thread, other threads:[~2023-11-04 11:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-03  6:14 [PATCH] kernel/reboot: Explicitly notify if halt occurred instead of power off Dongmin Lee
2023-11-04  1:05 ` kernel test robot
2023-11-04 11:33   ` [PATCH v2] " Dongmin Lee

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.