summaryrefslogtreecommitdiff
path: root/include/linux/console.h
diff options
context:
space:
mode:
authorJohn Ogness <john.ogness@linutronix.de>2022-11-16 19:21:15 +0300
committerPetr Mladek <pmladek@suse.com>2022-12-02 13:24:59 +0300
commit6c4afa79147e4aa86665795695ac4a5f25e73176 (patch)
tree303743239f481d5eeb6ae90f33ec164de2e48a3a /include/linux/console.h
parentd9a4af5690e26afa8a2eb83c575d3a9ef52cde1d (diff)
downloadlinux-6c4afa79147e4aa86665795695ac4a5f25e73176.tar.xz
printk: Prepare for SRCU console list protection
Provide an NMI-safe SRCU protected variant to walk the console list. Note that all console fields are now set before adding the console to the list to avoid the console becoming visible by SCRU readers before being fully initialized. This is a preparatory change for a new console infrastructure which operates independent of the console BKL. Suggested-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: John Ogness <john.ogness@linutronix.de> Acked-by: Miguel Ojeda <ojeda@kernel.org> Reviewed-by: Paul E. McKenney <paulmck@kernel.org> Reviewed-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20221116162152.193147-4-john.ogness@linutronix.de
Diffstat (limited to 'include/linux/console.h')
-rw-r--r--include/linux/console.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/include/linux/console.h b/include/linux/console.h
index 7b5f21f9e469..f4f0c9523835 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -15,7 +15,7 @@
#define _LINUX_CONSOLE_H_ 1
#include <linux/atomic.h>
-#include <linux/list.h>
+#include <linux/rculist.h>
#include <linux/types.h>
struct vc_data;
@@ -158,8 +158,34 @@ struct console {
struct hlist_node node;
};
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+extern bool console_srcu_read_lock_is_held(void);
+#else
+static inline bool console_srcu_read_lock_is_held(void)
+{
+ return 1;
+}
+#endif
+
+extern int console_srcu_read_lock(void);
+extern void console_srcu_read_unlock(int cookie);
+
extern struct hlist_head console_list;
+/**
+ * for_each_console_srcu() - Iterator over registered consoles
+ * @con: struct console pointer used as loop cursor
+ *
+ * Although SRCU guarantees the console list will be consistent, the
+ * struct console fields may be updated by other CPUs while iterating.
+ *
+ * Requires console_srcu_read_lock to be held. Can be invoked from
+ * any context.
+ */
+#define for_each_console_srcu(con) \
+ hlist_for_each_entry_srcu(con, &console_list, node, \
+ console_srcu_read_lock_is_held())
+
/*
* for_each_console() allows you to iterate on each console
*/