From patchwork Thu Jan 28 13:06:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "J, KEERTHY" X-Patchwork-Id: 8149891 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 18C659F38B for ; Thu, 28 Jan 2016 13:07:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 32A4820364 for ; Thu, 28 Jan 2016 13:07:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F2DA2034C for ; Thu, 28 Jan 2016 13:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967322AbcA1NGz (ORCPT ); Thu, 28 Jan 2016 08:06:55 -0500 Received: from bear.ext.ti.com ([192.94.94.41]:33927 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967139AbcA1NGw (ORCPT ); Thu, 28 Jan 2016 08:06:52 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id u0SD6cdj018917; Thu, 28 Jan 2016 07:06:38 -0600 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id u0SD6cca008488; Thu, 28 Jan 2016 07:06:38 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.224.2; Thu, 28 Jan 2016 07:06:37 -0600 Received: from ula0393675.apr.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id u0SD6T8w031594; Thu, 28 Jan 2016 07:06:34 -0600 From: Keerthy To: , , , , , CC: , , , , , , Subject: [PATCH 1/2] reboot: Introduce emergency poweroff function Date: Thu, 28 Jan 2016 18:36:28 +0530 Message-ID: <1453986389-15887-2-git-send-email-j-keerthy@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453986389-15887-1-git-send-email-j-keerthy@ti.com> References: <1453986389-15887-1-git-send-email-j-keerthy@ti.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP emergency_poweroff function can be called in critical situations to poweroff the system after a configurable period of time. The default value of the delay is 0 triggers system poweroff immediately. Signed-off-by: Keerthy Suggested-by: Ingo Molnar Reported-by: Nishanth Menon --- arch/Kconfig | 9 +++++++++ include/linux/reboot.h | 1 + kernel/reboot.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index f6b649d..0962ea7 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -37,6 +37,15 @@ config OPROFILE_NMI_TIMER def_bool y depends on PERF_EVENTS && HAVE_PERF_EVENTS_NMI && !PPC64 +config EMERGENCY_POWEROFF_DELAY_MS + int "Emergency poweroff delay in milli-seconds" + default 0 + help + The number of milliseconds to delay before emergency + poweroff kicks in. + + If set to 0 poweroff will happen immediately. + config KPROBES bool "Kprobes" depends on MODULES diff --git a/include/linux/reboot.h b/include/linux/reboot.h index a7ff409..108b4ce 100644 --- a/include/linux/reboot.h +++ b/include/linux/reboot.h @@ -71,6 +71,7 @@ void ctrl_alt_del(void); extern char poweroff_cmd[POWEROFF_CMD_PATH_LEN]; extern void orderly_poweroff(bool force); +extern void emergency_poweroff(void); extern void orderly_reboot(void); /* diff --git a/kernel/reboot.c b/kernel/reboot.c index bd30a97..def195b 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -469,6 +469,37 @@ void orderly_poweroff(bool force) } EXPORT_SYMBOL_GPL(orderly_poweroff); +/** + * emergency_poweroff_func - emergency poweroff work after a known delay + * @work: work_struct associated with the emergency poweroff function + * + * This function is called in very critical situations to force + * a kernel poweroff after a configurable timeout value. + */ +static void emergency_poweroff_func(struct work_struct *work) +{ + pr_warn("Attempting kernel_power_off\n"); + kernel_power_off(); + + pr_warn("kernel_power_off has failed! Attempting emergency_restart\n"); + emergency_restart(); +} + +static DECLARE_DELAYED_WORK(emergency_poweroff_work, emergency_poweroff_func); + +/** + * emergency_poweroff - Trigger an emergency system poweroff + * + * This may be called from any critical situation to trigger a system shutdown + * after a known period of time. By default the delay is 0 millisecond + */ +void emergency_poweroff(void) +{ + schedule_delayed_work(&emergency_poweroff_work, + msecs_to_jiffies(CONFIG_EMERGENCY_POWEROFF_DELAY_MS)); +} +EXPORT_SYMBOL_GPL(emergency_poweroff); + static void reboot_work_func(struct work_struct *work) { __orderly_reboot();