Skip to content

Commit

Permalink
panic/reboot: allow specifying reboot_mode for panic only
Browse files Browse the repository at this point in the history
Allow specifying reboot_mode for panic only.  This is needed on systems
where ramoops is used to store panic logs, and user wants to use warm
reset to preserve those, while still having cold reset on normal
reboots.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Aaro Koskinen <[email protected]>
Reviewed-by: Kees Cook <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
aakoskin authored and torvalds committed May 15, 2019
1 parent c39ea0b commit b287a25
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Documentation/admin-guide/kernel-parameters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4064,7 +4064,9 @@
[[,]s[mp]#### \
[[,]b[ios] | a[cpi] | k[bd] | t[riple] | e[fi] | p[ci]] \
[[,]f[orce]
Where reboot_mode is one of warm (soft) or cold (hard) or gpio,
Where reboot_mode is one of warm (soft) or cold (hard) or gpio
(prefix with 'panic_' to set mode for panic
reboot only),
reboot_type is one of bios, acpi, kbd, triple, efi, or pci,
reboot_force is either force or not specified,
reboot_cpu is s[mp]#### with #### being the processor
Expand Down
2 changes: 2 additions & 0 deletions include/linux/reboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ struct device;
#define SYS_POWER_OFF 0x0003 /* Notify of system power off */

enum reboot_mode {
REBOOT_UNDEFINED = -1,
REBOOT_COLD = 0,
REBOOT_WARM,
REBOOT_HARD,
REBOOT_SOFT,
REBOOT_GPIO,
};
extern enum reboot_mode reboot_mode;
extern enum reboot_mode panic_reboot_mode;

enum reboot_type {
BOOT_TRIPLE = 't',
Expand Down
2 changes: 2 additions & 0 deletions kernel/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ void panic(const char *fmt, ...)
* shutting down. But if there is a chance of
* rebooting the system it will be rebooted.
*/
if (panic_reboot_mode != REBOOT_UNDEFINED)
reboot_mode = panic_reboot_mode;
emergency_restart();
}
#ifdef __sparc__
Expand Down
20 changes: 15 additions & 5 deletions kernel/reboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ EXPORT_SYMBOL(cad_pid);
#define DEFAULT_REBOOT_MODE
#endif
enum reboot_mode reboot_mode DEFAULT_REBOOT_MODE;
enum reboot_mode panic_reboot_mode = REBOOT_UNDEFINED;

/*
* This variable is used privately to keep track of whether or not
Expand Down Expand Up @@ -519,24 +520,33 @@ EXPORT_SYMBOL_GPL(orderly_reboot);
static int __init reboot_setup(char *str)
{
for (;;) {
enum reboot_mode *mode;

/*
* Having anything passed on the command line via
* reboot= will cause us to disable DMI checking
* below.
*/
reboot_default = 0;

if (!strncmp(str, "panic_", 6)) {
mode = &panic_reboot_mode;
str += 6;
} else {
mode = &reboot_mode;
}

switch (*str) {
case 'w':
reboot_mode = REBOOT_WARM;
*mode = REBOOT_WARM;
break;

case 'c':
reboot_mode = REBOOT_COLD;
*mode = REBOOT_COLD;
break;

case 'h':
reboot_mode = REBOOT_HARD;
*mode = REBOOT_HARD;
break;

case 's':
Expand All @@ -553,11 +563,11 @@ static int __init reboot_setup(char *str)
if (rc)
return rc;
} else
reboot_mode = REBOOT_SOFT;
*mode = REBOOT_SOFT;
break;
}
case 'g':
reboot_mode = REBOOT_GPIO;
*mode = REBOOT_GPIO;
break;

case 'b':
Expand Down

0 comments on commit b287a25

Please sign in to comment.