From patchwork Wed Jan 13 12:33:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "J, KEERTHY" X-Patchwork-Id: 8024651 Return-Path: X-Original-To: patchwork-linux-arm@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 470569F744 for ; Wed, 13 Jan 2016 12:37:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 58E49202F0 for ; Wed, 13 Jan 2016 12:37:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5E45820458 for ; Wed, 13 Jan 2016 12:37:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aJKdG-00060h-R9; Wed, 13 Jan 2016 12:34:34 +0000 Received: from bear.ext.ti.com ([192.94.94.41]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aJKdD-0005uw-As for linux-arm-kernel@lists.infradead.org; Wed, 13 Jan 2016 12:34:32 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id u0DCXVjg009702; Wed, 13 Jan 2016 06:33:31 -0600 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id u0DCXVXH004822; Wed, 13 Jan 2016 06:33:31 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.224.2; Wed, 13 Jan 2016 06:33:31 -0600 Received: from ula0393675.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id u0DCXQic017685; Wed, 13 Jan 2016 06:33:26 -0600 From: Keerthy To: Subject: [PATCH v2] reboot: Backup orderly_poweroff Date: Wed, 13 Jan 2016 18:03:25 +0530 Message-ID: <1452688405-15087-1-git-send-email-j-keerthy@ti.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160113_043431_498194_E36F5453 X-CRM114-Status: GOOD ( 10.77 ) X-Spam-Score: -6.9 (------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nm@ti.com, grygorii.strashko@ti.com, linux-pm@vger.kernel.org, peterz@infradead.org, j-keerthy@ti.com, josh@joshtriplett.org, edubezval@gmail.com, joel@jms.id.au, mpe@ellerman.id.au, akpm@linux-foundation.org, linux-omap@vger.kernel.org, dyoung@redhat.com, mingo@kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 orderly_poweroff is triggered when a graceful shutdown of system is desired. This may be used in many critical states of the kernel such as when subsystems detects conditions such as critical temperature conditions. However, in certain conditions in system boot up sequences like those in the middle of driver probes being initiated, userspace will be unable to power off the system in a clean manner and leaves the system in a critical state. In cases like these, the /sbin/poweroff will return success (having forked off to attempt powering off the system. However, the system overall will fail to completely poweroff (since other modules will be probed) and the system is still functional with no userspace (since that would have shut itself off). However, there is no clean way of detecting such failure of userspace powering off the system. In such scenarios, it is necessary for a backup workqueue to be able to force a shutdown of the system when orderly shutdown is not successful after a configurable time period. Signed-off-by: Keerthy Suggested-by: Eduardo Valentin Reported-by: Nishanth Menon --- Links to previous discussion can be found here: http://www.spinics.net/lists/linux-omap/msg124925.html Boot tested on DRA7. changes in v2: * Changed #ifdef to #if CONFIG_SHUTDOWN_BACKUP_DELAY_MS arch/Kconfig | 7 +++++++ kernel/reboot.c | 23 ++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) Index: linux/arch/Kconfig =================================================================== --- linux.orig/arch/Kconfig 2016-01-11 15:26:07.732173131 +0530 +++ linux/arch/Kconfig 2016-01-11 15:26:07.728173205 +0530 @@ -37,6 +37,18 @@ def_bool y depends on PERF_EVENTS && HAVE_PERF_EVENTS_NMI && !PPC64 +config SHUTDOWN_BACKUP_DELAY_MS + int "Backup shutdown delay in milli-seconds" + default 0 + help + The number of milliseconds to delay before backup workqueue + executes attempting to poweroff the system after the + orderly_poweroff function has failed to complete. + + If set to 0, the backup workqueue is not active. The value + should be conservatively configured based on userspace latencies + expected for a given system. + config KPROBES bool "Kprobes" depends on MODULES Index: linux/kernel/reboot.c =================================================================== --- linux.orig/kernel/reboot.c 2016-01-11 15:26:07.732173131 +0530 +++ linux/kernel/reboot.c 2016-01-11 15:38:33.502341511 +0530 @@ -424,6 +424,38 @@ return ret; } +#if CONFIG_SHUTDOWN_BACKUP_DELAY_MS + +/** + * shutdown_backup_func - shutdown backup work after a known delay + * @work: work_struct associated with the backup shutdown function + * + * In system bootup sequences like those in the middle of driver probes being + * initiated, userspace will be unable to power off the system in a clean + * manner and leaves the system in a critical state. + * In such scenarios, this backup workqueue forces a shutdown of the system + * when orderly shutdown is not successful after a configurable time period. + */ +static void shutdown_backup_func(struct work_struct *work) +{ + pr_warn("Orderly_poweroff has failed! 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(bkup_shutdown_work, shutdown_backup_func); + +static inline void setup_backup_shutdown_workqueue(void) +{ + schedule_delayed_work(&bkup_shutdown_work, + msecs_to_jiffies(CONFIG_SHUTDOWN_BACKUP_DELAY_MS)); +} +#else +static inline void setup_backup_shutdown_workqueue(void) { } +#endif + static int __orderly_poweroff(bool force) { int ret; @@ -442,6 +474,12 @@ kernel_power_off(); } + /* + * Schedule a backup work function to execute after a known time + * when orderly shutdown fails. + */ + setup_backup_shutdown_workqueue(); + return ret; }