From patchwork Mon Jun 30 19:11:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 4453961 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1E2F7BEEAA for ; Mon, 30 Jun 2014 19:14:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3682E2037E for ; Mon, 30 Jun 2014 19:14:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 41D482037D for ; Mon, 30 Jun 2014 19:14:44 +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 1X1h0A-0005D8-Pi; Mon, 30 Jun 2014 19:12:30 +0000 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X1gzq-0004sg-Uc for linux-arm-kernel@lists.infradead.org; Mon, 30 Jun 2014 19:12:12 +0000 Received: by mail-pa0-f44.google.com with SMTP id rd3so9192268pab.3 for ; Mon, 30 Jun 2014 12:11:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=d1XJPZCsG79M92l7eQECGWUTAx4VytBrHIFxovfD42w=; b=qSFn60ybLx9E/3rgCtS6HDblwuCHqQ2klp1FSdLkW7/8FVDgdxuNsZgBiSSF6R+pX+ f3XfhVnKz9OOH9zBzo1yk4GX7sKvh4k+nk9YwU41pfDciONW3WN9bqIk6F00JBWLS3vz 2h5Uw/rpOlAtG5al6FPjzEcGDQHoXlkhguJkujQQNOUWeA9HjPgumKGw+M7QViQYjFI/ t9Tsj+ulyrxj1o3hFzTeye95Rqfly3COdKT1Drx6gygUkK6hu2+3BK0kGC1yg+h3ciGg 6W7GTjkcCABowsByKxERi6RROjGG6tydemsEld9f0uPUBrJwLqwiW/upno6KeuUpMtw/ oMyA== X-Received: by 10.66.240.130 with SMTP id wa2mr54072213pac.73.1404155509550; Mon, 30 Jun 2014 12:11:49 -0700 (PDT) Received: from localhost (108-223-40-66.lightspeed.sntcca.sbcglobal.net. [108.223.40.66]) by mx.google.com with ESMTPSA id ph6sm17048995pbc.38.2014.06.30.12.11.47 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 30 Jun 2014 12:11:49 -0700 (PDT) From: Guenter Roeck To: linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH 1/6] kernel: Add support for restart notifier call chain Date: Mon, 30 Jun 2014 12:11:34 -0700 Message-Id: <1404155499-21177-2-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1404155499-21177-1-git-send-email-linux@roeck-us.net> References: <1404155499-21177-1-git-send-email-linux@roeck-us.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140630_121211_035030_0A2E2120 X-CRM114-Status: GOOD ( 22.68 ) X-Spam-Score: -0.4 (/) Cc: Ingo Molnar , Russell King , Heiko Stuebner , Arnd Bergmann , linux-doc@vger.kernel.org, Catalin Marinas , Randy Dunlap , Will Deacon , linux-kernel@vger.kernel.org, Steven Rostedt , Jonas Jensen , Wim Van Sebroeck , Maxime Ripard , Andrew Morton , Guenter Roeck X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=no 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 Various drivers implement architecture and/or device specific means to restart (reset) the system. Various mechanisms have been implemented to support those schemes. The best known mechanism is arm_pm_restart, which is a function pointer to be set either from platform specific code or from drivers. Another mechanism is to use hardware watchdogs to issue a reset; this mechanism is used if there is no other method available to reset a board or system. Two examples are alim7101_wdt, which currently uses the reboot notifier to trigger a reset, and moxart_wdt, which registers the arm_pm_restart function. The existing mechanisms have a number of drawbacks. Typically only one scheme to restart the system is supported (at least if arm_pm_restart is used). At least in theory there can be mutliple means to restart the system, some of which may be less desirable (for example one mechanism may only reset the CPU, while another may reset the entire system). Using arm_pm_restart can also be racy if the function pointer is set from a driver, as the driver may be in the process of being unloaded when arm_pm_restart is called. Using the reboot notifier is always racy, as it is unknown if and when other functions using the reboot notifier have completed execution by the time the watchdog fires. To solve the problem, introduce a system restart notifier. This notifier is expected to be called from the architecture specific machine_restart() function. Drivers providing system restart functionality (such as the watchdog drivers mentioned above) are expected to register with this notifier. Signed-off-by: Guenter Roeck --- include/linux/notifier.h | 1 + include/linux/reboot.h | 2 ++ kernel/notifier.c | 6 ++++++ kernel/reboot.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/include/linux/notifier.h b/include/linux/notifier.h index d14a4c3..3d7d2fc 100644 --- a/include/linux/notifier.h +++ b/include/linux/notifier.h @@ -210,6 +210,7 @@ static inline int notifier_to_errno(int ret) #define KBD_POST_KEYSYM 0x0005 /* Called after keyboard keysym interpretation */ extern struct blocking_notifier_head reboot_notifier_list; +extern struct blocking_notifier_head restart_notifier_list; #endif /* __KERNEL__ */ #endif /* _LINUX_NOTIFIER_H */ diff --git a/include/linux/reboot.h b/include/linux/reboot.h index 48bf152..f8e7e0a 100644 --- a/include/linux/reboot.h +++ b/include/linux/reboot.h @@ -38,6 +38,8 @@ extern int reboot_force; extern int register_reboot_notifier(struct notifier_block *); extern int unregister_reboot_notifier(struct notifier_block *); +extern int register_restart_notifier(struct notifier_block *); +extern int unregister_restart_notifier(struct notifier_block *); /* * Architecture-specific implementations of sys_reboot commands. diff --git a/kernel/notifier.c b/kernel/notifier.c index 4803da6..2f2b071 100644 --- a/kernel/notifier.c +++ b/kernel/notifier.c @@ -14,6 +14,12 @@ BLOCKING_NOTIFIER_HEAD(reboot_notifier_list); /* + * Notifier list for kernel code which wants to be called + * to restart the system. + */ +BLOCKING_NOTIFIER_HEAD(restart_notifier_list); + +/* * Notifier chain core routines. The exported routines below * are layered on top of these, with appropriate locking added. */ diff --git a/kernel/reboot.c b/kernel/reboot.c index a3a9e24..374896f 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -104,6 +104,38 @@ int unregister_reboot_notifier(struct notifier_block *nb) } EXPORT_SYMBOL(unregister_reboot_notifier); +/** + * register_restart_notifier - Register function to be called to reset + * the system + * @nb: Info about notifier function to be called + * + * Registers a function with the list of functions + * to be called to restart the system. + * + * Currently always returns zero, as blocking_notifier_chain_register() + * always returns zero. + */ +int register_restart_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&restart_notifier_list, nb); +} +EXPORT_SYMBOL(register_restart_notifier); + +/** + * unregister_restart_notifier - Unregister previously registered + * restart notifier + * @nb: Hook to be unregistered + * + * Unregisters a previously registered restart notifier function. + * + * Returns zero on success, or %-ENOENT on failure. + */ +int unregister_restart_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&restart_notifier_list, nb); +} +EXPORT_SYMBOL(unregister_restart_notifier); + void migrate_to_reboot_cpu(void) { /* The boot cpu is always logical cpu 0 */