Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp971847imp; Thu, 21 Feb 2019 15:24:25 -0800 (PST) X-Google-Smtp-Source: AHgI3IZG6Gcnoz8Y4doiC1N/I2bha0xwwBAlQlrWN5j5t+MtwGt8xx5G4jrQhqsLtfqgwVovxwX9 X-Received: by 2002:a17:902:b784:: with SMTP id e4mr1086917pls.308.1550791465259; Thu, 21 Feb 2019 15:24:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550791465; cv=none; d=google.com; s=arc-20160816; b=gH80fb9XtblQlRRJauteLM8cFMwjZpg9je80pM36bv/liHh0670AFg1n9LvF42FtbD rFHsj9eXnaKA6WYaeyghKs9y962Ju99sEkFbVdlmyqXqD3n2vi0J1VOyKHKCa7BwDsq1 RAaqHZtIawHvQg5tfW44Me4D/TLMImJfL9jyGYhAuXDNufUp8c7ekHyiU5ZRVlSTw89z 471wir5EKY4AM4+cynBjr2S5WAn5eGu2a+JAl7WzTOzODrOhPRBZwHT+ljGQ0ez5ps3C tEPkA7BDDRW1AIeJiVzgP8OFqBEAQ7pCajnyseVWBKxZu2SP2K20R6u90p2ckj67fmOn XF/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=6co8PGy7u85N+i3IlEktJmTVtQ6xkF9M55t0eDiBs3Y=; b=DAx6wEql3yNAO+MIxe6YBSy+kymsV7YhK9RYVhRtFtK59Jjb/cg2iOi5GmmjiOtnLA 783K3sbo2EBLHUV/3mif+WyXkamX++cHGqE/zCHOiSQtKafkqQitjGxVikiEAbQA/CR9 u9qKccLzPILDitQ3ih0fz2WaFBBkwVDNLIxiHQNCHZ21MWGWBabGVZo63mTyIcsYkROu Qv3pUoopaHq8LXU54wLIICjZYYsLc4FkgLuZNxw6gFW3mJeploKAEaIMzIHyIoviQV/J zxl8AzF7s+u7R3Lax+s5SqJF6KwrlZoAcWYj2I1xPKf+ZkZKbn5ZoKDYZHVYKgtLscd6 mXgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KwkdVR05; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1si179494pfn.10.2019.02.21.15.24.09; Thu, 21 Feb 2019 15:24:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KwkdVR05; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727106AbfBUXXr (ORCPT + 99 others); Thu, 21 Feb 2019 18:23:47 -0500 Received: from mail-ua1-f65.google.com ([209.85.222.65]:40711 "EHLO mail-ua1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726165AbfBUXXo (ORCPT ); Thu, 21 Feb 2019 18:23:44 -0500 Received: by mail-ua1-f65.google.com with SMTP id c5so319591uaq.7 for ; Thu, 21 Feb 2019 15:23:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6co8PGy7u85N+i3IlEktJmTVtQ6xkF9M55t0eDiBs3Y=; b=KwkdVR05mH9V4K25y/0vvm+PLLGBQjN8HO91K94Eoc/DzLn83lhTieFHXW6x/9QwT1 AZvqGZCaKRm9Z7LQA6PfR4HQ77a4lMDKgbnsQjd8PncD2noEp9YyHs40pWmaJAX/xM4Q UcHr//7ZG7mNLtz8BWnbNDeVrlAHrgDpECa2M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6co8PGy7u85N+i3IlEktJmTVtQ6xkF9M55t0eDiBs3Y=; b=WCJZzst/pBaIIX6kaON11vSEkxWKqNlSjEVWD/JI9y8gZrO57PLYyihC9HJja1bg7G riC4OdfLqTTz6+QVRi1UH/RiJsmjC9dYqyyFIiNFwwhCSExW0N1IPO7/bNnnvcy3ABE3 BJ5iAQKA7r7aJsb561wG5eMtGPH/Ak+s1IGfNfjAk4twnUAfDs75MKg0M/86UZwonEIX Oq8j3Fj2L1vlhyX073qAecprpx8KhN4dviXmsT+2x8a73mnr8z9S16KFmuiR6Dj1sHZr db42VREyP07yGF9Q9YZADNnj4cbtQjjfHTt42LGDF4H9FeE4nVTSJrLZDOs7OOhjbFjr WuAA== X-Gm-Message-State: AHQUAuZ76OiHxKQdqolwbzAYIIgeftiogiezGnS4yrDvhZfFjSBT9SU5 fZ8xW7wHx/jLg7s/TFcS8ryL2H4HLf0= X-Received: by 2002:ab0:72d5:: with SMTP id g21mr667307uap.16.1550791422747; Thu, 21 Feb 2019 15:23:42 -0800 (PST) Received: from mail-ua1-f48.google.com (mail-ua1-f48.google.com. [209.85.222.48]) by smtp.gmail.com with ESMTPSA id k75sm99048vkk.1.2019.02.21.15.23.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Feb 2019 15:23:42 -0800 (PST) Received: by mail-ua1-f48.google.com with SMTP id q17so360582uam.0 for ; Thu, 21 Feb 2019 15:23:41 -0800 (PST) X-Received: by 2002:a67:fa45:: with SMTP id j5mr693156vsq.48.1550791421383; Thu, 21 Feb 2019 15:23:41 -0800 (PST) MIME-Version: 1.0 References: <20190221230641.8797-1-aaro.koskinen@iki.fi> In-Reply-To: <20190221230641.8797-1-aaro.koskinen@iki.fi> From: Kees Cook Date: Thu, 21 Feb 2019 15:23:29 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] panic/reboot: allow specifying reboot_mode for panic only To: Aaro Koskinen , Andrew Morton Cc: LKML , Aaro Koskinen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 21, 2019 at 3:06 PM Aaro Koskinen wrote: > > From: Aaro Koskinen > > 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. > > Signed-off-by: Aaro Koskinen Reviewed-by: Kees Cook -Kees > --- > > v3: Move REBOOT_UNDEFINED before REBOOT_COLD. > > v2: https://marc.info/?t=155078129700004&r=1&w=2 > > Use REBOOT_UNDEFINED instead of -1 > > v1: https://marc.info/?t=154957416600005&r=1&w=2 > > .../admin-guide/kernel-parameters.txt | 4 +++- > include/linux/reboot.h | 2 ++ > kernel/panic.c | 2 ++ > kernel/reboot.c | 20 ++++++++++++++----- > 4 files changed, 22 insertions(+), 6 deletions(-) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index 858b6c0b9a15..5705b4689565 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -3949,7 +3949,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 > diff --git a/include/linux/reboot.h b/include/linux/reboot.h > index e63799a6e895..3734cd8f38a8 100644 > --- a/include/linux/reboot.h > +++ b/include/linux/reboot.h > @@ -14,6 +14,7 @@ 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, > @@ -21,6 +22,7 @@ enum reboot_mode { > REBOOT_GPIO, > }; > extern enum reboot_mode reboot_mode; > +extern enum reboot_mode panic_reboot_mode; > > enum reboot_type { > BOOT_TRIPLE = 't', > diff --git a/kernel/panic.c b/kernel/panic.c > index f121e6ba7e11..a0d839f883b7 100644 > --- a/kernel/panic.c > +++ b/kernel/panic.c > @@ -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__ > diff --git a/kernel/reboot.c b/kernel/reboot.c > index e1b79b6a2735..b9e79e8c7226 100644 > --- a/kernel/reboot.c > +++ b/kernel/reboot.c > @@ -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 > @@ -519,6 +520,8 @@ 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 > @@ -526,17 +529,24 @@ static int __init reboot_setup(char *str) > */ > 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': > @@ -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': > -- > 2.17.0 > -- Kees Cook