@@ -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 */
@@ -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.
@@ -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.
*/
@@ -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 */
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 <linux@roeck-us.net> --- include/linux/notifier.h | 1 + include/linux/reboot.h | 2 ++ kernel/notifier.c | 6 ++++++ kernel/reboot.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+)