From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: John Ogness <john.ogness@linutronix.de>
Cc: Petr Mladek <pmladek@suse.com>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH printk v2 02/38] printk: Convert console_drivers list to hlist
Date: Wed, 19 Oct 2022 17:44:50 +0200 [thread overview]
Message-ID: <Y1AbcjQP4TGPxpsv@kroah.com> (raw)
In-Reply-To: <20221019145600.1282823-3-john.ogness@linutronix.de>
On Wed, Oct 19, 2022 at 05:01:24PM +0206, John Ogness wrote:
> Replace the open coded single linked list with a hlist so a conversion
> to SRCU protected list walks can reuse the existing primitives.
>
> Signed-off-by: John Ogness <john.ogness@linutronix.de>
> ---
> fs/proc/consoles.c | 3 +-
> include/linux/console.h | 8 ++--
> kernel/printk/printk.c | 99 +++++++++++++++++++++++------------------
> 3 files changed, 63 insertions(+), 47 deletions(-)
>
> diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c
> index dfe6ce3505ce..cf2e0788f9c7 100644
> --- a/fs/proc/consoles.c
> +++ b/fs/proc/consoles.c
> @@ -74,8 +74,9 @@ static void *c_start(struct seq_file *m, loff_t *pos)
> static void *c_next(struct seq_file *m, void *v, loff_t *pos)
> {
> struct console *con = v;
> +
> ++*pos;
> - return con->next;
> + return hlist_entry_safe(con->node.next, struct console, node);
> }
>
> static void c_stop(struct seq_file *m, void *v)
> diff --git a/include/linux/console.h b/include/linux/console.h
> index 8c1686e2c233..7b5f21f9e469 100644
> --- a/include/linux/console.h
> +++ b/include/linux/console.h
> @@ -15,6 +15,7 @@
> #define _LINUX_CONSOLE_H_ 1
>
> #include <linux/atomic.h>
> +#include <linux/list.h>
> #include <linux/types.h>
>
> struct vc_data;
> @@ -154,14 +155,16 @@ struct console {
> u64 seq;
> unsigned long dropped;
> void *data;
> - struct console *next;
> + struct hlist_node node;
> };
>
> +extern struct hlist_head console_list;
> +
> /*
> * for_each_console() allows you to iterate on each console
> */
> #define for_each_console(con) \
> - for (con = console_drivers; con != NULL; con = con->next)
> + hlist_for_each_entry(con, &console_list, node)
>
> extern int console_set_on_cmdline;
> extern struct console *early_console;
> @@ -174,7 +177,6 @@ enum con_flush_mode {
> extern int add_preferred_console(char *name, int idx, char *options);
> extern void register_console(struct console *);
> extern int unregister_console(struct console *);
> -extern struct console *console_drivers;
> extern void console_lock(void);
> extern int console_trylock(void);
> extern void console_unlock(void);
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index e4f1e7478b52..867becc40021 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -79,13 +79,12 @@ int oops_in_progress;
> EXPORT_SYMBOL(oops_in_progress);
>
> /*
> - * console_sem protects the console_drivers list, and also
> - * provides serialisation for access to the entire console
> - * driver system.
> + * console_sem protects console_list and console->flags updates, and also
> + * provides serialization for access to the entire console driver system.
> */
> static DEFINE_SEMAPHORE(console_sem);
> -struct console *console_drivers;
> -EXPORT_SYMBOL_GPL(console_drivers);
> +HLIST_HEAD(console_list);
> +EXPORT_SYMBOL_GPL(console_list);
>
> /*
> * System may need to suppress printk message under certain
> @@ -2556,7 +2555,7 @@ static int console_cpu_notify(unsigned int cpu)
> * console_lock - lock the console system for exclusive use.
> *
> * Acquires a lock which guarantees that the caller has
> - * exclusive access to the console system and the console_drivers list.
> + * exclusive access to the console system and console_list.
> *
> * Can sleep, returns nothing.
> */
> @@ -2576,7 +2575,7 @@ EXPORT_SYMBOL(console_lock);
> * console_trylock - try to lock the console system for exclusive use.
> *
> * Try to acquire a lock which guarantees that the caller has exclusive
> - * access to the console system and the console_drivers list.
> + * access to the console system and console_list.
> *
> * returns 1 on success, and 0 on failure to acquire the lock.
> */
> @@ -2940,11 +2939,20 @@ void console_flush_on_panic(enum con_flush_mode mode)
> console_may_schedule = 0;
>
> if (mode == CONSOLE_REPLAY_ALL) {
> + struct hlist_node *tmp;
> struct console *c;
> u64 seq;
>
> seq = prb_first_valid_seq(prb);
> - for_each_console(c)
> + /*
> + * This cannot use for_each_console() because it's not established
> + * that the current context has console locked and neither there is
> + * a guarantee that there is no concurrency in that case.
> + *
> + * Open code it for documentation purposes and pretend that
> + * it works.
> + */
> + hlist_for_each_entry_safe(c, tmp, &console_list, node)
> c->seq = seq;
> }
> console_unlock();
> @@ -3081,6 +3089,9 @@ static void try_enable_default_console(struct console *newcon)
> (con->flags & CON_BOOT) ? "boot" : "", \
> con->name, con->index, ##__VA_ARGS__)
>
> +#define console_first() \
> + hlist_entry(console_list.first, struct console, node)
> +
> /*
> * The console driver calls this routine during kernel initialization
> * to register the console printing procedure with printk() and to
> @@ -3140,8 +3151,8 @@ void register_console(struct console *newcon)
> * flag set and will be first in the list.
> */
> if (preferred_console < 0) {
> - if (!console_drivers || !console_drivers->device ||
> - console_drivers->flags & CON_BOOT) {
> + if (hlist_empty(&console_list) || !console_first()->device ||
> + console_first()->flags & CON_BOOT) {
> try_enable_default_console(newcon);
> }
> }
> @@ -3169,20 +3180,22 @@ void register_console(struct console *newcon)
> }
>
> /*
> - * Put this console in the list - keep the
> - * preferred driver at the head of the list.
> + * Put this console in the list - keep the
> + * preferred driver at the head of the list.
> */
> console_lock();
> - if ((newcon->flags & CON_CONSDEV) || console_drivers == NULL) {
> - newcon->next = console_drivers;
> - console_drivers = newcon;
> - if (newcon->next)
> - newcon->next->flags &= ~CON_CONSDEV;
> - /* Ensure this flag is always set for the head of the list */
> + if (hlist_empty(&console_list)) {
> + /* Ensure CON_CONSDEV is always set for the head. */
> newcon->flags |= CON_CONSDEV;
> + hlist_add_head(&newcon->node, &console_list);
> +
> + } else if (newcon->flags & CON_CONSDEV) {
> + /* Only the new head can have CON_CONSDEV set. */
> + console_first()->flags &= ~CON_CONSDEV;
> + hlist_add_head(&newcon->node, &console_list);
> +
> } else {
> - newcon->next = console_drivers->next;
> - console_drivers->next = newcon;
> + hlist_add_behind(&newcon->node, console_list.first);
> }
>
> newcon->dropped = 0;
> @@ -3209,16 +3222,18 @@ void register_console(struct console *newcon)
> if (bootcon_enabled &&
> ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) &&
> !keep_bootcon) {
> - for_each_console(con)
> + struct hlist_node *tmp;
> +
> + hlist_for_each_entry_safe(con, tmp, &console_list, node) {
> if (con->flags & CON_BOOT)
> unregister_console(con);
> + }
> }
> }
> EXPORT_SYMBOL(register_console);
>
> int unregister_console(struct console *console)
> {
> - struct console *con;
> int res;
>
> con_printk(KERN_INFO, console, "disabled\n");
> @@ -3229,32 +3244,30 @@ int unregister_console(struct console *console)
> if (res > 0)
> return 0;
>
> - res = -ENODEV;
> console_lock();
> - if (console_drivers == console) {
> - console_drivers=console->next;
> - res = 0;
> - } else {
> - for_each_console(con) {
> - if (con->next == console) {
> - con->next = console->next;
> - res = 0;
> - break;
> - }
> - }
> +
> + /* Disable it unconditionally */
> + console->flags &= ~CON_ENABLED;
> +
> + if (hlist_unhashed(&console->node)) {
How can this ever be hit? The console lock is held, so it shouldn't
have gone away already. Or am I missing something else here?
Other than that minor question, looks good to me!
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
next prev parent reply other threads:[~2022-10-19 15:50 UTC|newest]
Thread overview: 129+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-19 14:55 [PATCH printk v2 00/38] reduce console_lock scope John Ogness
2022-10-19 14:55 ` [PATCH printk v2 01/38] serial: kgdboc: Lock console list in probe function John Ogness
2022-10-19 15:41 ` Greg Kroah-Hartman
2022-10-24 5:22 ` Sergey Senozhatsky
2022-10-25 0:34 ` Doug Anderson
2022-10-19 14:55 ` [PATCH printk v2 02/38] printk: Convert console_drivers list to hlist John Ogness
2022-10-19 15:44 ` Greg Kroah-Hartman [this message]
2022-10-19 21:46 ` John Ogness
2022-10-20 7:43 ` Greg Kroah-Hartman
2022-10-20 12:36 ` Petr Mladek
2022-10-24 5:23 ` Sergey Senozhatsky
2022-10-19 14:55 ` [PATCH printk v2 03/38] printk: Prepare for SRCU console list protection John Ogness
2022-10-19 15:16 ` Miguel Ojeda
2022-10-19 17:12 ` Paul E. McKenney
2022-10-21 8:34 ` Petr Mladek
2022-10-31 13:06 ` John Ogness
2022-10-31 14:09 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 04/38] printk: introduce console_is_enabled() wrapper John Ogness
2022-10-19 16:01 ` Greg Kroah-Hartman
2022-10-21 8:57 ` Petr Mladek
2022-10-21 9:37 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 05/38] printk: use console_is_enabled() John Ogness
2022-10-21 9:25 ` Petr Mladek
2022-10-31 15:39 ` John Ogness
2022-10-19 14:55 ` [PATCH printk v2 06/38] tty: nfcon: " John Ogness
2022-10-21 9:55 ` Petr Mladek
2022-10-31 15:59 ` John Ogness
2022-11-01 8:57 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 07/38] um: kmsg_dump: " John Ogness
2022-10-21 12:46 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 08/38] efi: earlycon: " John Ogness
2022-10-19 15:32 ` Ard Biesheuvel
2022-10-21 12:53 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 09/38] netconsole: " John Ogness
2022-10-21 13:14 ` Petr Mladek
2022-11-04 15:12 ` John Ogness
2022-10-19 14:55 ` [PATCH printk v2 10/38] tty: hvc: " John Ogness
2022-10-19 16:01 ` Greg Kroah-Hartman
2022-10-21 13:22 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 11/38] tty: serial: earlycon: " John Ogness
2022-10-19 16:01 ` Greg Kroah-Hartman
2022-10-21 13:51 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 12/38] tty: serial: kgdboc: " John Ogness
2022-10-19 16:00 ` Greg Kroah-Hartman
2022-10-21 14:10 ` Petr Mladek
2022-10-24 22:46 ` Doug Anderson
2022-10-25 0:49 ` Doug Anderson
2022-10-25 11:28 ` John Ogness
2022-11-04 16:23 ` John Ogness
2022-11-07 8:47 ` Petr Mladek
2022-11-07 9:45 ` John Ogness
2022-10-19 14:55 ` [PATCH printk v2 13/38] tty: serial: pic32_uart: " John Ogness
2022-10-19 16:01 ` Greg Kroah-Hartman
2022-10-21 14:11 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 14/38] tty: serial: samsung_tty: " John Ogness
2022-10-19 16:00 ` Greg Kroah-Hartman
2022-10-21 14:14 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 15/38] tty: serial: serial_core: " John Ogness
2022-10-19 16:00 ` Greg Kroah-Hartman
2022-10-21 14:14 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 16/38] tty: serial: xilinx_uartps: " John Ogness
2022-10-19 16:01 ` Greg Kroah-Hartman
2022-10-21 14:23 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 17/38] tty: tty_io: " John Ogness
2022-10-19 16:00 ` Greg Kroah-Hartman
2022-10-21 14:24 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 18/38] usb: early: xhci-dbc: " John Ogness
2022-10-19 16:01 ` Greg Kroah-Hartman
2022-10-21 14:27 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 19/38] kdb: kdb_io: " John Ogness
2022-10-21 14:28 ` Petr Mladek
2022-10-25 0:34 ` Doug Anderson
2022-10-19 14:55 ` [PATCH printk v2 20/38] um: kmsg_dumper: use srcu console list iterator John Ogness
2022-10-21 14:56 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 21/38] serial: kgdboc: " John Ogness
2022-10-19 16:02 ` Greg Kroah-Hartman
2022-10-21 15:09 ` Petr Mladek
2022-10-25 0:33 ` Doug Anderson
2022-10-19 14:55 ` [PATCH printk v2 22/38] serial: kgdboc: document console_lock usage John Ogness
2022-10-20 7:42 ` Greg Kroah-Hartman
2022-10-25 0:36 ` Doug Anderson
2022-10-25 10:09 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 23/38] tty: tty_io: " John Ogness
2022-10-20 7:43 ` Greg Kroah-Hartman
2022-10-25 13:31 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 24/38] xen: fbfront: use srcu console list iterator John Ogness
2022-10-25 13:39 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 25/38] proc: consoles: document console_lock usage John Ogness
2022-10-25 14:40 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 26/38] kdb: use srcu console list iterator John Ogness
2022-10-25 0:47 ` Doug Anderson
2022-10-25 14:59 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 27/38] printk: console_flush_all: " John Ogness
2022-10-25 15:17 ` Petr Mladek
2022-11-07 0:00 ` John Ogness
2022-11-07 13:03 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 28/38] printk: console_unblank: " John Ogness
2022-10-25 15:28 ` Petr Mladek
2022-10-25 15:31 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 29/38] printk: console_flush_on_panic: " John Ogness
2022-10-25 15:32 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 30/38] printk: console_device: " John Ogness
2022-10-25 15:35 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 31/38] printk: register_console: " John Ogness
2022-10-26 8:20 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 32/38] printk: __pr_flush: " John Ogness
2022-10-26 8:33 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 33/38] printk: introduce console_list_lock John Ogness
2022-10-20 7:53 ` Greg Kroah-Hartman
2022-10-27 10:09 ` Petr Mladek
2022-10-27 18:50 ` Paul E. McKenney
2022-10-28 18:09 ` Boqun Feng
2022-10-28 18:42 ` Paul E. McKenney
2022-11-07 10:10 ` John Ogness
2022-11-07 16:16 ` Paul E. McKenney
2022-10-19 14:55 ` [PATCH printk v2 34/38] serial: kgdboc: use console_list_lock instead of console_lock John Ogness
2022-10-20 7:52 ` Greg Kroah-Hartman
2022-10-27 10:13 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 35/38] tty: tty_io: use console_list_lock for list synchronization John Ogness
2022-10-20 7:43 ` Greg Kroah-Hartman
2022-10-27 10:17 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 36/38] proc: consoles: use console_list_lock for list iteration John Ogness
2022-10-27 12:02 ` Petr Mladek
2022-10-19 14:55 ` [PATCH printk v2 37/38] printk: relieve console_lock of list synchronization duties John Ogness
2022-10-27 12:40 ` Petr Mladek
2022-10-19 14:56 ` [PATCH printk v2 38/38] printk, xen: fbfront: create/use safe function for forcing preferred John Ogness
2022-10-27 13:18 ` Petr Mladek
2022-10-27 13:35 ` John Ogness
2022-10-27 14:27 ` Petr Mladek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y1AbcjQP4TGPxpsv@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=john.ogness@linutronix.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox