lkml.org 
[lkml]   [2022]   [Sep]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[patch RFC 12/29] printk: Prepare for SCRU console list protection
Date
Provide a SRCU protected variant to walk the console list.

Preperatory change for a new console infrastructure which operates
independent of console BKL.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
include/linux/console.h | 14 +++++++++++++-
kernel/printk/printk.c | 16 +++++++++++++---
2 files changed, 26 insertions(+), 4 deletions(-)

--- 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;
@@ -161,6 +161,7 @@ struct console {
#ifdef CONFIG_LOCKDEP
extern void lockdep_assert_console_lock_held(void);
extern void lockdep_assert_console_list_lock_held(void);
+extern bool console_srcu_read_lock_is_held(void);
#else
static inline void lockdep_assert_console_lock_held(void) { }
static inline void lockdep_assert_console_list_lock_held(void) { }
@@ -172,6 +173,17 @@ extern void console_list_lock(void) __ac
extern void console_list_unlock(void) __releases(console_mutex);

/**
+ * for_each_console_srcu() - Iterator over registered consoles
+ * @con: struct console pointer used as loop cursor
+ *
+ * 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_registered_console() - Iterator over registered consoles
* @con: struct console pointer used as loop cursor
*
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -90,6 +90,7 @@ static DEFINE_MUTEX(console_mutex);
static DEFINE_SEMAPHORE(console_sem);
HLIST_HEAD(console_list);
EXPORT_SYMBOL_GPL(console_list);
+DEFINE_STATIC_SRCU(console_srcu);

/*
* System may need to suppress printk message under certain
@@ -118,6 +119,10 @@ void lockdep_assert_console_list_lock_he
lockdep_assert_held(&console_mutex);
}

+bool console_srcu_read_lock_is_held(void)
+{
+ return srcu_read_lock_held(&console_srcu);
+}
#endif

enum devkmsg_log_bits {
@@ -3227,9 +3232,9 @@ void register_console(struct console *ne
*/
console_lock();
if (newcon->flags & CON_CONSDEV || hlist_empty(&console_list))
- hlist_add_head(&newcon->node, &console_list);
+ hlist_add_head_rcu(&newcon->node, &console_list);
else
- hlist_add_behind(&newcon->node, console_list.first);
+ hlist_add_behind_rcu(&newcon->node, console_list.first);

/* Ensure this flag is always set for the head of the list */
cons_first()->flags |= CON_CONSDEV;
@@ -3245,6 +3250,7 @@ void register_console(struct console *ne
newcon->seq = prb_next_seq(prb);
}
console_unlock();
+ /* No need to synchronize SRCU here! */
console_sysfs_notify();

/*
@@ -3290,7 +3296,7 @@ static int console_unregister_locked(str
if (hlist_unhashed(&console->node))
goto out_unlock;

- hlist_del_init(&console->node);
+ hlist_del_init_rcu(&console->node);

/*
* <HISTORICAL>
@@ -3305,6 +3311,10 @@ static int console_unregister_locked(str
cons_first()->flags |= CON_CONSDEV;

console_unlock();
+
+ /* Ensure that all SRCU list walks have completed */
+ synchronize_srcu(&console_srcu);
+
console_sysfs_notify();

if (console->exit)
\
 
 \ /
  Last update: 2022-09-11 00:29    [W:0.186 / U:0.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site