aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/printk
diff options
context:
space:
mode:
authorJohn Ogness <john.ogness@linutronix.de>2022-11-16 17:27:24 +0106
committerPetr Mladek <pmladek@suse.com>2022-12-02 11:25:00 +0100
commit100bdef2c198b8dc64df011dc4a2152db913c8ba (patch)
tree49aa89134c32a85a46b6fb7d38015a12bbb37b38 /kernel/printk
parent4dc64682ad37abb02c54ca598430ac27de60c21a (diff)
downloadlinux-100bdef2c198b8dc64df011dc4a2152db913c8ba.tar.gz
console: introduce wrappers to read/write console flags
After switching to SRCU for console list iteration, some readers will begin readings console->flags as a data race. Locklessly reading console->flags provides a consistent value because there is at most one CPU modifying console->flags and that CPU is using only read-modify-write operations. Introduce a wrapper for SRCU iterators to read console flags. Introduce a matching wrapper to write to flags of registered consoles. Writing to flags of registered consoles is synchronized by the console_list_lock. Signed-off-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20221116162152.193147-13-john.ogness@linutronix.de
Diffstat (limited to 'kernel/printk')
-rw-r--r--kernel/printk/printk.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 2b4506673a860..cad65d34c96d3 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3069,7 +3069,7 @@ void console_stop(struct console *console)
__pr_flush(console, 1000, true);
console_list_lock();
console_lock();
- console->flags &= ~CON_ENABLED;
+ console_srcu_write_flags(console, console->flags & ~CON_ENABLED);
console_unlock();
console_list_unlock();
@@ -3087,7 +3087,7 @@ void console_start(struct console *console)
{
console_list_lock();
console_lock();
- console->flags |= CON_ENABLED;
+ console_srcu_write_flags(console, console->flags | CON_ENABLED);
console_unlock();
console_list_unlock();
__pr_flush(console, 1000, true);
@@ -3343,7 +3343,7 @@ void register_console(struct console *newcon)
} else if (newcon->flags & CON_CONSDEV) {
/* Only the new head can have CON_CONSDEV set. */
- console_first()->flags &= ~CON_CONSDEV;
+ console_srcu_write_flags(console_first(), console_first()->flags & ~CON_CONSDEV);
hlist_add_head_rcu(&newcon->node, &console_list);
} else {
@@ -3400,7 +3400,7 @@ static int unregister_console_locked(struct console *console)
console_lock();
/* Disable it unconditionally */
- console->flags &= ~CON_ENABLED;
+ console_srcu_write_flags(console, console->flags & ~CON_ENABLED);
if (hlist_unhashed(&console->node)) {
console_unlock();
@@ -3419,7 +3419,7 @@ static int unregister_console_locked(struct console *console)
* console has any device attached. Oh well....
*/
if (!hlist_empty(&console_list) && console->flags & CON_CONSDEV)
- console_first()->flags |= CON_CONSDEV;
+ console_srcu_write_flags(console_first(), console_first()->flags | CON_CONSDEV);
console_unlock();