linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] reboot: add a "power cycle" quirk to prepare for a power off on reboot
@ 2020-06-29 20:56 Simon Arlott
  2020-06-29 20:58 ` [PATCH 2/2] x86/reboot/quirks: Add ASRock Z170 Extreme4 Simon Arlott
  2020-07-15 18:11 ` [PATCH 1/2] reboot: add a "power cycle" quirk to prepare for a power off on reboot Christoph Hellwig
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Arlott @ 2020-06-29 20:56 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
	H. Peter Anvin, Linux Kernel Mailing List, Jonathan Corbet,
	linux-doc
  Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	Bart Van Assche, Christoph Hellwig, Damien Le Moal, Pavel Machek,
	Henrique de Moraes Holschuh

I need to use "reboot=p" on my desktop because one of the PCIe devices
does not appear after a warm boot. This results in a very cold boot
because the BIOS turns the PSU off and on.

The scsi sd shutdown process does not send a stop command to disks
before the reboot happens (stop commands are only sent for a shutdown).

The result is that all of my SSDs experience a sudden power loss on
every reboot, which is undesirable behaviour because it could cause data
to be corrupted. These events are recorded in the SMART attributes.

Add a "power cycle" quirk to the reboot options to prepare all devices for
a power off by setting the system_state to SYSTEM_POWER_OFF instead of
SYSTEM_RESTART while still performing a restart as requested.

This uses the letter "C" for the parameter because of numerous uses of
"reboot=pci" that would otherwise trigger this behaviour if "c" was used.

Signed-off-by: Simon Arlott <simon@octiron.net>
---
Previous patches to make scsi/sd stop before a reboot:
https://lore.kernel.org/lkml/499138c8-b6d5-ef4a-2780-4f750ed337d3@0882a8b5-c6c3-11e9-b005-00805fc181fe/
https://lore.kernel.org/lkml/e726ffd8-8897-4a79-c3d6-6271eda8aebb@0882a8b5-c6c3-11e9-b005-00805fc181fe/

 Documentation/admin-guide/kernel-parameters.txt |  8 ++++++--
 include/linux/reboot.h                          |  4 ++++
 kernel/reboot.c                                 | 15 ++++++++++++++-
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index bee3b83d6f84..91359fd4fbcc 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4422,9 +4422,10 @@
 	reboot=		[KNL]
 			Format (x86 or x86_64):
 				[w[arm] | c[old] | h[ard] | s[oft] | g[pio]] \
-				[[,]s[mp]#### \
+				[[,]s[mp]####] \
 				[[,]b[ios] | a[cpi] | k[bd] | t[riple] | e[fi] | p[ci]] \
-				[[,]f[orce]
+				[[,]f[orce]] \
+				[[,]C]
 			Where reboot_mode is one of warm (soft) or cold (hard) or gpio
 					(prefix with 'panic_' to set mode for panic
 					reboot only),
@@ -4432,6 +4433,9 @@
 			      reboot_force is either force or not specified,
 			      reboot_cpu is s[mp]#### with #### being the processor
 					to be used for rebooting.
+			Quirks:
+				C = Rebooting includes a power cycle, prepare
+				    for a power off instead of a restart.
 
 	refscale.holdoff= [KNL]
 			Set test-start holdoff period.  The purpose of
diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index 3734cd8f38a8..b49559ba825a 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -39,6 +39,10 @@ extern int reboot_default;
 extern int reboot_cpu;
 extern int reboot_force;
 
+#define REBOOT_QUIRK_POWER_CYCLE                BIT(0)
+
+extern int reboot_quirks;
+
 
 extern int register_reboot_notifier(struct notifier_block *);
 extern int unregister_reboot_notifier(struct notifier_block *);
diff --git a/kernel/reboot.c b/kernel/reboot.c
index 491f1347bf43..5605c2894f2b 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -45,6 +45,7 @@ int reboot_default = 1;
 int reboot_cpu;
 enum reboot_type reboot_type = BOOT_ACPI;
 int reboot_force;
+int reboot_quirks;
 
 /*
  * If set, this is used for preparing the system to power off.
@@ -71,7 +72,15 @@ EXPORT_SYMBOL_GPL(emergency_restart);
 void kernel_restart_prepare(char *cmd)
 {
 	blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
-	system_state = SYSTEM_RESTART;
+	if (reboot_quirks & REBOOT_QUIRK_POWER_CYCLE) {
+		/*
+		 * The reboot will include a power cycle, so prepare all
+		 * devices for a power off.
+		 */
+		system_state = SYSTEM_POWER_OFF;
+	} else {
+		system_state = SYSTEM_RESTART;
+	}
 	usermodehelper_disable();
 	device_shutdown();
 }
@@ -583,6 +592,10 @@ static int __init reboot_setup(char *str)
 		case 'f':
 			reboot_force = 1;
 			break;
+
+		case 'C':
+			reboot_quirks |= REBOOT_QUIRK_POWER_CYCLE;
+			break;
 		}
 
 		str = strchr(str, ',');
-- 
2.17.1

-- 
Simon Arlott

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

* [PATCH 2/2] x86/reboot/quirks: Add ASRock Z170 Extreme4
  2020-06-29 20:56 [PATCH 1/2] reboot: add a "power cycle" quirk to prepare for a power off on reboot Simon Arlott
@ 2020-06-29 20:58 ` Simon Arlott
  2020-07-15 18:12   ` Christoph Hellwig
  2020-07-15 18:11 ` [PATCH 1/2] reboot: add a "power cycle" quirk to prepare for a power off on reboot Christoph Hellwig
  1 sibling, 1 reply; 5+ messages in thread
From: Simon Arlott @ 2020-06-29 20:58 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
	H. Peter Anvin, Linux Kernel Mailing List, Jonathan Corbet,
	linux-doc
  Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	Bart Van Assche, Christoph Hellwig, Damien Le Moal, Pavel Machek,
	Henrique de Moraes Holschuh

If a PCI mode reboot is performed on the ASRock Z170 Extreme4, a power
cycle will occur. Automatically set the reboot quirk for this to prepare
for the power off (i.e. stop all disks).

This will only take effect if PCI mode is manually used. It'll be too late
in the reboot process to prepare for power off if the other reboot methods
fail.

It is necessary to re-order the processing of DMI checks because this quirk
must apply even if a reboot= command line parameter is used as that's the
only way to specify a PCI mode reboot.

Signed-off-by: Simon Arlott <simon@octiron.net>
---
Previous patches to make scsi/sd stop before a reboot:
https://lore.kernel.org/lkml/499138c8-b6d5-ef4a-2780-4f750ed337d3@0882a8b5-c6c3-11e9-b005-00805fc181fe/
https://lore.kernel.org/lkml/e726ffd8-8897-4a79-c3d6-6271eda8aebb@0882a8b5-c6c3-11e9-b005-00805fc181fe/

 arch/x86/kernel/reboot.c | 51 ++++++++++++++++++++++++++++++++++------
 1 file changed, 44 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index 0ec7ced727fe..a82d5db1c8ca 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -147,6 +147,13 @@ STACK_FRAME_NON_STANDARD(machine_real_restart);
  */
 static int __init set_pci_reboot(const struct dmi_system_id *d)
 {
+	/*
+	 * Only apply the DMI-based change if reboot_type hasn't been
+	 * overridden on the command line.
+	 */
+	if (!reboot_default)
+		return 0;
+
 	if (reboot_type != BOOT_CF9_FORCE) {
 		reboot_type = BOOT_CF9_FORCE;
 		pr_info("%s series board detected. Selecting %s-method for reboots.\n",
@@ -157,6 +164,13 @@ static int __init set_pci_reboot(const struct dmi_system_id *d)
 
 static int __init set_kbd_reboot(const struct dmi_system_id *d)
 {
+	/*
+	 * Only apply the DMI-based change if reboot_type hasn't been
+	 * overridden on the command line.
+	 */
+	if (!reboot_default)
+		return 0;
+
 	if (reboot_type != BOOT_KBD) {
 		reboot_type = BOOT_KBD;
 		pr_info("%s series board detected. Selecting %s-method for reboot.\n",
@@ -165,6 +179,21 @@ static int __init set_kbd_reboot(const struct dmi_system_id *d)
 	return 0;
 }
 
+static int __init set_pci_power_cycle_reboot(const struct dmi_system_id *d)
+{
+	/*
+	 * This has to be applied even if reboot_type has been set on the
+	 * command line because that's the only way to enable PCI mode.
+	 */
+
+	if (reboot_type == BOOT_CF9_FORCE) {
+		reboot_quirks |= REBOOT_QUIRK_POWER_CYCLE;
+		pr_info("%s series board detected. Assume that a PCI reboot includes a power cycle.\n",
+			d->ident);
+	}
+	return 0;
+}
+
 /*
  * This is a single dmi_table handling all reboot quirks.
  */
@@ -247,6 +276,14 @@ static const struct dmi_system_id reboot_dmi_table[] __initconst = {
 			DMI_MATCH(DMI_BOARD_NAME, "Q1900DC-ITX"),
 		},
 	},
+	{	/* PCI reboots cause a power cycle */
+		.callback = set_pci_power_cycle_reboot,
+		.ident = "ASRock Z170 Extreme4",
+		.matches = {
+			DMI_MATCH(DMI_BOARD_VENDOR, "ASRock"),
+			DMI_MATCH(DMI_BOARD_NAME, "Z170 Extreme4"),
+		},
+	},
 
 	/* ASUS */
 	{	/* Handle problems with rebooting on ASUS P4S800 */
@@ -494,13 +531,6 @@ static int __init reboot_init(void)
 {
 	int rv;
 
-	/*
-	 * Only do the DMI check if reboot_type hasn't been overridden
-	 * on the command line
-	 */
-	if (!reboot_default)
-		return 0;
-
 	/*
 	 * The DMI quirks table takes precedence. If no quirks entry
 	 * matches and the ACPI Hardware Reduced bit is set and EFI
@@ -508,6 +538,13 @@ static int __init reboot_init(void)
 	 */
 	rv = dmi_check_system(reboot_dmi_table);
 
+	/*
+	 * Only force EFI reboot if reboot_type hasn't been overridden
+	 * on the command line.
+	 */
+	if (!reboot_default)
+		return 0;
+
 	if (!rv && efi_reboot_required() && !efi_runtime_disabled())
 		reboot_type = BOOT_EFI;
 
-- 
2.17.1

-- 
Simon Arlott

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

* Re: [PATCH 1/2] reboot: add a "power cycle" quirk to prepare for a power off on reboot
  2020-06-29 20:56 [PATCH 1/2] reboot: add a "power cycle" quirk to prepare for a power off on reboot Simon Arlott
  2020-06-29 20:58 ` [PATCH 2/2] x86/reboot/quirks: Add ASRock Z170 Extreme4 Simon Arlott
@ 2020-07-15 18:11 ` Christoph Hellwig
  2020-07-15 20:14   ` Martin K. Petersen
  1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2020-07-15 18:11 UTC (permalink / raw)
  To: Simon Arlott
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
	H. Peter Anvin, Linux Kernel Mailing List, Jonathan Corbet,
	linux-doc, James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	Bart Van Assche, Christoph Hellwig, Damien Le Moal, Pavel Machek,
	Henrique de Moraes Holschuh

Except for the fact that I think that usage of the BIT() macro is
a horrible pattern, this looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 2/2] x86/reboot/quirks: Add ASRock Z170 Extreme4
  2020-06-29 20:58 ` [PATCH 2/2] x86/reboot/quirks: Add ASRock Z170 Extreme4 Simon Arlott
@ 2020-07-15 18:12   ` Christoph Hellwig
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2020-07-15 18:12 UTC (permalink / raw)
  To: Simon Arlott
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
	H. Peter Anvin, Linux Kernel Mailing List, Jonathan Corbet,
	linux-doc, James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	Bart Van Assche, Christoph Hellwig, Damien Le Moal, Pavel Machek,
	Henrique de Moraes Holschuh

On Mon, Jun 29, 2020 at 09:58:05PM +0100, Simon Arlott wrote:
> If a PCI mode reboot is performed on the ASRock Z170 Extreme4, a power
> cycle will occur. Automatically set the reboot quirk for this to prepare
> for the power off (i.e. stop all disks).
> 
> This will only take effect if PCI mode is manually used. It'll be too late
> in the reboot process to prepare for power off if the other reboot methods
> fail.
> 
> It is necessary to re-order the processing of DMI checks because this quirk
> must apply even if a reboot= command line parameter is used as that's the
> only way to specify a PCI mode reboot.
> 
> Signed-off-by: Simon Arlott <simon@octiron.net>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 1/2] reboot: add a "power cycle" quirk to prepare for a power off on reboot
  2020-07-15 18:11 ` [PATCH 1/2] reboot: add a "power cycle" quirk to prepare for a power off on reboot Christoph Hellwig
@ 2020-07-15 20:14   ` Martin K. Petersen
  0 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2020-07-15 20:14 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Simon Arlott, Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
	H. Peter Anvin, Linux Kernel Mailing List, Jonathan Corbet,
	linux-doc, James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	Bart Van Assche, Damien Le Moal, Pavel Machek,
	Henrique de Moraes Holschuh


Christoph,

> Except for the fact that I think that usage of the BIT() macro is
> a horrible pattern, this looks good:
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Looks good to me too.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2020-07-15 20:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29 20:56 [PATCH 1/2] reboot: add a "power cycle" quirk to prepare for a power off on reboot Simon Arlott
2020-06-29 20:58 ` [PATCH 2/2] x86/reboot/quirks: Add ASRock Z170 Extreme4 Simon Arlott
2020-07-15 18:12   ` Christoph Hellwig
2020-07-15 18:11 ` [PATCH 1/2] reboot: add a "power cycle" quirk to prepare for a power off on reboot Christoph Hellwig
2020-07-15 20:14   ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).