Re: [patch RFC 06/29] printk: Protect [un]register_console() with a mutex

From: Sergey Senozhatsky
Date: Wed Sep 14 2022 - 08:32:09 EST


On (22/09/11 00:27), Thomas Gleixner wrote:
[..]
> + * console_sem protects the console_drivers list, and also provides
> + * serialization for access to the entire console driver system.
> + *
> + * console_mutex serializes register/unregister. console_sem has to be
> + * taken for any list manipulation inside the console_mutex locked
> + * section to keep the console BKL machinery happy.
> */
> +static DEFINE_MUTEX(console_mutex);
> static DEFINE_SEMAPHORE(console_sem);
[..]
> /*
> * Helper macros to handle lockdep when locking/unlocking console_sem. We use
> * macros instead of functions so that _RET_IP_ contains useful information.
> @@ -2978,17 +3008,21 @@ struct tty_driver *console_device(int *i
> void console_stop(struct console *console)
> {
> __pr_flush(console, 1000, true);
> + console_list_lock();
> console_lock();
> console->flags &= ~CON_ENABLED;
> console_unlock();
> + console_list_unlock();
> }
> EXPORT_SYMBOL(console_stop);
>
> void console_start(struct console *console)
> {
> + console_list_lock();
> console_lock();
> console->flags |= CON_ENABLED;
> console_unlock();
> + console_list_unlock();
> __pr_flush(console, 1000, true);
> }
> EXPORT_SYMBOL(console_start);

So the comment says that list lock (console_mutex) is to serialize
register/unregister, but then we take it in stop/start as well. What
does list lock protect us against in start/stop? console->flags reader
(console_is_usable()) does not take list lock, it's called under console
lock and console->flags writers (console_unregister() and console_stop())
modify console->flags under console_lock.