proc: consoles: document console_lock usage
authorJohn Ogness <john.ogness@linutronix.de>
Wed, 16 Nov 2022 16:21:22 +0000 (17:27 +0106)
committerPetr Mladek <pmladek@suse.com>
Fri, 2 Dec 2022 10:25:00 +0000 (11:25 +0100)
The console_lock is held throughout the start/show/stop procedure
to print out device/driver information about all registered
consoles. Since the console_lock is being used for multiple reasons,
explicitly document these reasons. This will be useful when the
console_lock is split into fine-grained locking.

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-11-john.ogness@linutronix.de
fs/proc/consoles.c

index cf2e078..46b305f 100644 (file)
@@ -63,6 +63,15 @@ static void *c_start(struct seq_file *m, loff_t *pos)
        struct console *con;
        loff_t off = 0;
 
+       /*
+        * Take console_lock to serialize device() callback with
+        * other console operations. For example, fg_console is
+        * modified under console_lock when switching vt.
+        *
+        * Hold the console_lock to guarantee safe traversal of the
+        * console list. SRCU cannot be used because there is no
+        * place to store the SRCU cookie.
+        */
        console_lock();
        for_each_console(con)
                if (off++ == *pos)