From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58953C433FE for ; Wed, 19 Oct 2022 15:03:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231169AbiJSPDC (ORCPT ); Wed, 19 Oct 2022 11:03:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231282AbiJSPCq (ORCPT ); Wed, 19 Oct 2022 11:02:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A777C15D0A5; Wed, 19 Oct 2022 07:57:25 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191363; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NEhmZhH2pnDE6WuTxQwMCcvi/RbMP+L4l7DVKXhScfQ=; b=WkJA4pqmnV5juPN/ttgFR+jALEcs6JiTFkAuj55fv1Kc9Cx9UAm1N2rezLQc4WaDTdI/Ez m/HFdf7pZqHhdxeVSxmJ/wOoDKSjiMkAqJ8syecbdqYLzx9aZNdxjA9PJjkX7XcCeN9bSn bNe0JNx3plnLRTHu6/TZEDVzHEPTgZuc1wDuCH0zd719J7sckLPTqVJ2fAeNX8P7melcni 0q6XH6+z5F33XWbnvc5mJtt5eRYubPRu1pN8zAtwSWT7NlR9AjihtUMfpyxtPV4FPukpwg awmFOtjaGtFa430Q5t3JRNOLPoKJdpHRQeR0xyjB/xzpitnezB7/EUhmrWpzGg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191363; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NEhmZhH2pnDE6WuTxQwMCcvi/RbMP+L4l7DVKXhScfQ=; b=aDl1Im9QlC7jXBpafB/JPa5shMExjhVLO58+NwKbR8EV60/QUyHkbiIXWH+jwcsUkqMUn9 dwjFqk2pmsScIoAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk v2 01/38] serial: kgdboc: Lock console list in probe function Date: Wed, 19 Oct 2022 17:01:23 +0206 Message-Id: <20221019145600.1282823-2-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Unprotected list walks are not necessarily safe. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Petr Mladek Reviewed-by: Douglas Anderson Reviewed-by: Greg Kroah-Hartman Reviewed-by: Sergey Senozhatsky --- drivers/tty/serial/kgdboc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index 7aa37be3216a..e76f0186c335 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -193,6 +193,7 @@ static int configure_kgdboc(void) if (!p) goto noconfig; =20 + console_lock(); for_each_console(cons) { int idx; if (cons->device && cons->device(cons, &idx) =3D=3D p && @@ -201,6 +202,7 @@ static int configure_kgdboc(void) break; } } + console_unlock(); =20 kgdb_tty_driver =3D p; kgdb_tty_line =3D tty_line; --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E4E9C433FE for ; Wed, 19 Oct 2022 15:03:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231154AbiJSPDG (ORCPT ); Wed, 19 Oct 2022 11:03:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231509AbiJSPCq (ORCPT ); Wed, 19 Oct 2022 11:02:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 070DA199883; Wed, 19 Oct 2022 07:57:34 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191363; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ecwQGTiJHvr9yJfbRjmW+23+PW75dBYvC1lV+461LH0=; b=vumeh2cgLikwlvoyBG+8fjnw+7SiUoMjC1NiLuiD19CCNH+EyD9tuMgF7PjFHly5GZ+q0f zDYqcW7g1xjb3q9bHanG8DV/TsI3RGYqiWMm6tsIYCqLtRjwwnrSLCFRJ67AaaD14EIRvN +nXQb+ldGv1kFpDBnhzve1+pPmgXHJpzjBixNIKiJXGpcS8QMZfCPWLnlKGwaXTTMEQRuc DCuEnIJ7rizwPrmJFyV3m38XDb/+BmQ/PQSh9UgMh4VNH+QLuQiqycKdLLegRn86SvYSEe 1W5eLrqXvIYtxS/X7Qv595y4F8uCBWXcCOaPtnGDlD7tLiPdn3SZIoPD1Uqryg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191363; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ecwQGTiJHvr9yJfbRjmW+23+PW75dBYvC1lV+461LH0=; b=URfApYAAyZelmd2vmKjK2/tJ2Jg749/DVzo3680V6WWRpxslbjxBM2ChT9YF7UEyCVAKpu BUYPSY/QW6WhmpDw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , linux-fsdevel@vger.kernel.org Subject: [PATCH printk v2 02/38] printk: Convert console_drivers list to hlist Date: Wed, 19 Oct 2022 17:01:24 +0206 Message-Id: <20221019145600.1282823-3-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek Reviewed-by: Sergey Senozhatsky --- 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 =3D v; + ++*pos; - return con->next; + return hlist_entry_safe(con->node.next, struct console, node); } =20 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 =20 #include +#include #include =20 struct vc_data; @@ -154,14 +155,16 @@ struct console { u64 seq; unsigned long dropped; void *data; - struct console *next; + struct hlist_node node; }; =20 +extern struct hlist_head console_list; + /* * for_each_console() allows you to iterate on each console */ #define for_each_console(con) \ - for (con =3D console_drivers; con !=3D NULL; con =3D con->next) + hlist_for_each_entry(con, &console_list, node) =20 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); =20 /* - * 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); =20 /* * 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 mod= e) console_may_schedule =3D 0; =20 if (mode =3D=3D CONSOLE_REPLAY_ALL) { + struct hlist_node *tmp; struct console *c; u64 seq; =20 seq =3D 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 =3D 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__) =20 +#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) } =20 /* - * 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 =3D=3D NULL) { - newcon->next =3D console_drivers; - console_drivers =3D newcon; - if (newcon->next) - newcon->next->flags &=3D ~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 |=3D 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 &=3D ~CON_CONSDEV; + hlist_add_head(&newcon->node, &console_list); + } else { - newcon->next =3D console_drivers->next; - console_drivers->next =3D newcon; + hlist_add_behind(&newcon->node, console_list.first); } =20 newcon->dropped =3D 0; @@ -3209,16 +3222,18 @@ void register_console(struct console *newcon) if (bootcon_enabled && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) =3D=3D 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); =20 int unregister_console(struct console *console) { - struct console *con; int res; =20 con_printk(KERN_INFO, console, "disabled\n"); @@ -3229,32 +3244,30 @@ int unregister_console(struct console *console) if (res > 0) return 0; =20 - res =3D -ENODEV; console_lock(); - if (console_drivers =3D=3D console) { - console_drivers=3Dconsole->next; - res =3D 0; - } else { - for_each_console(con) { - if (con->next =3D=3D console) { - con->next =3D console->next; - res =3D 0; - break; - } - } + + /* Disable it unconditionally */ + console->flags &=3D ~CON_ENABLED; + + if (hlist_unhashed(&console->node)) { + res =3D -ENODEV; + goto out_unlock; } =20 - if (res) - goto out_disable_unlock; + hlist_del_init(&console->node); =20 /* + * * If this isn't the last console and it has CON_CONSDEV set, we * need to set it on the next preferred console. + * + * + * The above makes no sense as there is no guarantee that the next + * console has any device attached. Oh well.... */ - if (console_drivers !=3D NULL && console->flags & CON_CONSDEV) - console_drivers->flags |=3D CON_CONSDEV; + if (!hlist_empty(&console_list) && console->flags & CON_CONSDEV) + console_first()->flags |=3D CON_CONSDEV; =20 - console->flags &=3D ~CON_ENABLED; console_unlock(); console_sysfs_notify(); =20 @@ -3263,10 +3276,8 @@ int unregister_console(struct console *console) =20 return res; =20 -out_disable_unlock: - console->flags &=3D ~CON_ENABLED; +out_unlock: console_unlock(); - return res; } EXPORT_SYMBOL(unregister_console); @@ -3317,10 +3328,11 @@ void __init console_init(void) */ static int __init printk_late_init(void) { + struct hlist_node *tmp; struct console *con; int ret; =20 - for_each_console(con) { + hlist_for_each_entry_safe(con, tmp, &console_list, node) { if (!(con->flags & CON_BOOT)) continue; =20 @@ -3340,6 +3352,7 @@ static int __init printk_late_init(void) unregister_console(con); } } + ret =3D cpuhp_setup_state_nocalls(CPUHP_PRINTK_DEAD, "printk:dead", NULL, console_cpu_notify); WARN_ON(ret < 0); --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BB32C433FE for ; Wed, 19 Oct 2022 15:03:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229742AbiJSPDO (ORCPT ); Wed, 19 Oct 2022 11:03:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231455AbiJSPCr (ORCPT ); Wed, 19 Oct 2022 11:02:47 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 776EB161FFD for ; Wed, 19 Oct 2022 07:57:27 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c6Lc6N8r4GU5ofoIRm/xI96rlQR9N7h7xiEY7U0rrdo=; b=WcKxAuyJq3DhMytoZZKyfHvx3LUKiASxL0GbPcB1wiS/AN+FmRlf+Y30OSXWRsOlc3wVaq /SWkceKhUAinGtpHYuLE42d1xDizmjhjEIPqbNpXYHfKx9eqLDMDDxK3z2rZn9bPe12Wjg f6gN8yvnfKVrJP55j5feRIueav0JUWVpMkWvXrcpC/cyzetAvy9bjoXWLy1KvwWICGcfBF mN1zr8EeamOVmxzKEDR+Uxrf+ws2dse3cutZnK3IDTinucc0LRHOa4BfCtQmVxO3DMG80z YMl9KMskdAhYkhopMbjExWNpcqwr2+BspZELNDSDJrIfzAOlvm83EsTwjHNC0A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c6Lc6N8r4GU5ofoIRm/xI96rlQR9N7h7xiEY7U0rrdo=; b=1uEhuY8uFfwvbP4a9XQV3e1TWLBlz1xafI012vsQdF6svzD14yCfuelM5LkCwRU3pmoAVa WFoGoc7AIHW8TGDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Miguel Ojeda , "Paul E. McKenney" , Greg Kroah-Hartman Subject: [PATCH printk v2 03/38] printk: Prepare for SRCU console list protection Date: Wed, 19 Oct 2022 17:01:25 +0206 Message-Id: <20221019145600.1282823-4-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Provide an NMI-safe SRCU protected variant to walk the console list. Note that all console fields are now set before adding the console to the list to avoid the console becoming visible by SCRU readers before being fully initialized. This is a preparatory change for a new console infrastructure which operates independent of the console BKL. Signed-off-by: John Ogness Acked-by: Miguel Ojeda Reviewed-by: Paul E. McKenney --- .clang-format | 1 + include/linux/console.h | 28 +++++++++++++++- kernel/printk/printk.c | 72 ++++++++++++++++++++++++++++++++--------- 3 files changed, 85 insertions(+), 16 deletions(-) diff --git a/.clang-format b/.clang-format index 1247d54f9e49..04a675b56b57 100644 --- a/.clang-format +++ b/.clang-format @@ -222,6 +222,7 @@ ForEachMacros: - 'for_each_component_dais' - 'for_each_component_dais_safe' - 'for_each_console' + - 'for_each_console_srcu' - 'for_each_cpu' - 'for_each_cpu_and' - 'for_each_cpu_not' diff --git a/include/linux/console.h b/include/linux/console.h index 7b5f21f9e469..cff86cc615f8 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -15,7 +15,7 @@ #define _LINUX_CONSOLE_H_ 1 =20 #include -#include +#include #include =20 struct vc_data; @@ -158,8 +158,34 @@ struct console { struct hlist_node node; }; =20 +#ifdef CONFIG_LOCKDEP +extern bool console_srcu_read_lock_is_held(void); +#else +static inline bool console_srcu_read_lock_is_held(void) +{ + return 1; +} +#endif + +extern int console_srcu_read_lock(void); +extern void console_srcu_read_unlock(int cookie); + extern struct hlist_head console_list; =20 +/** + * for_each_console_srcu() - Iterator over registered consoles + * @con: struct console pointer used as loop cursor + * + * Although SRCU guarantees the console list will be consistent, the + * struct console fields may be updated by other CPUs while iterating. + * + * 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_console() allows you to iterate on each console */ diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 867becc40021..e8a56056cd50 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -85,6 +85,7 @@ EXPORT_SYMBOL(oops_in_progress); static DEFINE_SEMAPHORE(console_sem); HLIST_HEAD(console_list); EXPORT_SYMBOL_GPL(console_list); +DEFINE_STATIC_SRCU(console_srcu); =20 /* * System may need to suppress printk message under certain @@ -102,6 +103,11 @@ static int __read_mostly suppress_panic_printk; static struct lockdep_map console_lock_dep_map =3D { .name =3D "console_lock" }; + +bool console_srcu_read_lock_is_held(void) +{ + return srcu_read_lock_held(&console_srcu); +} #endif =20 enum devkmsg_log_bits { @@ -219,6 +225,32 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table,= int write, } #endif /* CONFIG_PRINTK && CONFIG_SYSCTL */ =20 +/** + * console_srcu_read_lock - Register a new reader for the + * SRCU-protected console list + * + * Use for_each_console_srcu() to iterate the console list + * + * Context: Any context. + */ +int console_srcu_read_lock(void) +{ + return srcu_read_lock_nmisafe(&console_srcu); +} +EXPORT_SYMBOL(console_srcu_read_lock); + +/** + * console_srcu_read_unlock - Unregister an old reader from + * the SRCU-protected console list + * + * Counterpart to console_srcu_read_lock() + */ +void console_srcu_read_unlock(int cookie) +{ + srcu_read_unlock_nmisafe(&console_srcu, cookie); +} +EXPORT_SYMBOL(console_srcu_read_unlock); + /* * Helper macros to handle lockdep when locking/unlocking console_sem. We = use * macros instead of functions so that _RET_IP_ contains useful informatio= n. @@ -2989,6 +3021,9 @@ void console_stop(struct console *console) console_lock(); console->flags &=3D ~CON_ENABLED; console_unlock(); + + /* Ensure that all SRCU list walks have completed */ + synchronize_srcu(&console_srcu); } EXPORT_SYMBOL(console_stop); =20 @@ -3179,6 +3214,17 @@ void register_console(struct console *newcon) newcon->flags &=3D ~CON_PRINTBUFFER; } =20 + newcon->dropped =3D 0; + if (newcon->flags & CON_PRINTBUFFER) { + /* Get a consistent copy of @syslog_seq. */ + mutex_lock(&syslog_lock); + newcon->seq =3D syslog_seq; + mutex_unlock(&syslog_lock); + } else { + /* Begin with next message. */ + newcon->seq =3D prb_next_seq(prb); + } + /* * Put this console in the list - keep the * preferred driver at the head of the list. @@ -3187,28 +3233,20 @@ void register_console(struct console *newcon) if (hlist_empty(&console_list)) { /* Ensure CON_CONSDEV is always set for the head. */ newcon->flags |=3D CON_CONSDEV; - hlist_add_head(&newcon->node, &console_list); + hlist_add_head_rcu(&newcon->node, &console_list); =20 } else if (newcon->flags & CON_CONSDEV) { /* Only the new head can have CON_CONSDEV set. */ console_first()->flags &=3D ~CON_CONSDEV; - hlist_add_head(&newcon->node, &console_list); + hlist_add_head_rcu(&newcon->node, &console_list); =20 } else { - hlist_add_behind(&newcon->node, console_list.first); - } - - newcon->dropped =3D 0; - if (newcon->flags & CON_PRINTBUFFER) { - /* Get a consistent copy of @syslog_seq. */ - mutex_lock(&syslog_lock); - newcon->seq =3D syslog_seq; - mutex_unlock(&syslog_lock); - } else { - /* Begin with next message. */ - newcon->seq =3D prb_next_seq(prb); + hlist_add_behind_rcu(&newcon->node, console_list.first); } console_unlock(); + + /* No need to synchronize SRCU here! */ + console_sysfs_notify(); =20 /* @@ -3254,7 +3292,7 @@ int unregister_console(struct console *console) goto out_unlock; } =20 - hlist_del_init(&console->node); + hlist_del_init_rcu(&console->node); =20 /* * @@ -3269,6 +3307,10 @@ int unregister_console(struct console *console) console_first()->flags |=3D CON_CONSDEV; =20 console_unlock(); + + /* Ensure that all SRCU list walks have completed */ + synchronize_srcu(&console_srcu); + console_sysfs_notify(); =20 if (console->exit) --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DABA6C433FE for ; Wed, 19 Oct 2022 15:03:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231175AbiJSPDn (ORCPT ); Wed, 19 Oct 2022 11:03:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiJSPCt (ORCPT ); Wed, 19 Oct 2022 11:02:49 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E251D17A964 for ; Wed, 19 Oct 2022 07:57:33 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hllJr9Cenmg6tA9bg55xooViBdr/MaRQODlzmP0LypQ=; b=mMoqhcUJaer0GASfzyAekKN+pSE8kqodiNK415JtDTtl/yYfijstiMQVyIVGVhbYJ7jiZy cKhgwp014bcWywD++czA8VHdfLmMfNHfT9xWvGVzDl1BSXzuTXhemseXYlrav5AHS4+h3b iXhswrgzZMfsRkUXSMPESUzJ+rSu3M7/YNj7ejdSKY5Yxhtm11uOmEXTnfiTuvJDajS8Dt gDw+WexxNI1DOGL9NoyYoTDrKUOZT02uu7KgiIO9lSmuToUrf/p0DUJZYwHx1FxGqlsn5D beK0nlWDHvmI58Iw3MyOaR7HUyvDEIWWDiLi+pCNT0K6BiV6dSSjn9hd4gaF8A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hllJr9Cenmg6tA9bg55xooViBdr/MaRQODlzmP0LypQ=; b=anaafIfR//UTCpo9Mk4ATxTaSPAW/cLDpNejXqfvkq1eS4iO6NOae6e9TO/xryKwhc8urc BQG9YbEHS5/MnBBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 04/38] printk: introduce console_is_enabled() wrapper Date: Wed, 19 Oct 2022 17:01:26 +0206 Message-Id: <20221019145600.1282823-5-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" After switching to SRCU for console list iteration, some readers will begin accessing console->flags as a data race. This is safe because there is at most one CPU modifying console->flags and using rmw operations. The primary reason for readers to access console->flags is to check if the console is enabled. Introduce console_is_enabled() to mark such access as a data race. Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman --- include/linux/console.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/console.h b/include/linux/console.h index cff86cc615f8..60195cd086dc 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -172,6 +172,26 @@ extern void console_srcu_read_unlock(int cookie); =20 extern struct hlist_head console_list; =20 +/** + * console_is_enabled - Check if the console is enabled + * @con: struct console pointer of console to check + * + * This should be used instead of manually testing for the CON_ENABLED + * bit in the console->flags. + * + * Context: Any context. + */ +static inline bool console_is_enabled(const struct console *con) +{ + /* + * If SRCU is used, reading of console->flags can be a data + * race. However, this is safe because there is at most one + * CPU modifying console->flags and it is using only + * read-modify-write operations to do so. + */ + return (data_race(READ_ONCE(con->flags)) & CON_ENABLED); +} + /** * for_each_console_srcu() - Iterator over registered consoles * @con: struct console pointer used as loop cursor --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6856C4332F for ; Wed, 19 Oct 2022 15:04:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231288AbiJSPEa (ORCPT ); Wed, 19 Oct 2022 11:04:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232059AbiJSPEC (ORCPT ); Wed, 19 Oct 2022 11:04:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62B6A1911C2 for ; Wed, 19 Oct 2022 07:58:33 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MP5rgFSdehBCliWVe71JQUPCb1f669tU8saiCWaIDO0=; b=SLqa5PhcnifAXBxPjzPq8RQ5wWHDsFsKLOjJ5Bmh9ZGDeMItqEb2c5andZCY9TcUyGDIR/ dkOOQxmdmn7/PnLwAAjrGDp8lt9Uz8mAMEoOd7urbGXYVldEk8zYCa8/iAY1dVNRfX1p+J Ha+qK8DetElb0MoGktri3Xu4lx9C3kUh6AtB+1DIReSvn7JRz1gWJTFDzw08nHyTiCmChQ XP4mRnKpUirH0pvAQWYC+E4LgSbE3mXbcssJIvwElnPgdqtXfCvaf4dvjVy2e7JmBlnloB h/m+zkpsEomfdmsy9Cb/TNtCQcjleQpQn0jWgpkY1m6W6keiAq6wL/v4NRO/PQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MP5rgFSdehBCliWVe71JQUPCb1f669tU8saiCWaIDO0=; b=ozZhE1jNVxKFfb0xYXFWRlrgrguzkQU0rcQ9xxPUoqXcDFSb1uLSsqks/WR9QsIUMSaQe8 g5NlOPi7VRafb3CA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 05/38] printk: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:27 +0206 Message-Id: <20221019145600.1282823-6-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness --- kernel/printk/printk.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e8a56056cd50..7ff2fc75fc3b 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2658,7 +2658,7 @@ static bool abandon_console_lock_in_panic(void) */ static inline bool console_is_usable(struct console *con) { - if (!(con->flags & CON_ENABLED)) + if (!console_is_enabled(con)) return false; =20 if (!con->write) @@ -2944,7 +2944,7 @@ void console_unblank(void) console_locked =3D 1; console_may_schedule =3D 0; for_each_console(c) - if ((c->flags & CON_ENABLED) && c->unblank) + if (console_is_enabled(c) && c->unblank) c->unblank(); console_unlock(); =20 @@ -3098,7 +3098,7 @@ static int try_enable_preferred_console(struct consol= e *newcon, * without matching. Accept the pre-enabled consoles only when match() * and setup() had a chance to be called. */ - if (newcon->flags & CON_ENABLED && c->user_specified =3D=3D user_specifie= d) + if (console_is_enabled(newcon) && (c->user_specified =3D=3D user_specifie= d)) return 0; =20 return -ENOENT; --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 692BFC433FE for ; Wed, 19 Oct 2022 15:04:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230102AbiJSPEf (ORCPT ); Wed, 19 Oct 2022 11:04:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232040AbiJSPEB (ORCPT ); Wed, 19 Oct 2022 11:04:01 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04B1B18F0DC for ; Wed, 19 Oct 2022 07:58:30 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DU0x5O5I9RpJgy/cp3SLsKJQ2S1+Cvd/4SG5pk09kAc=; b=lhmCsfzj24k5pXS6vMkayCOEXN89OO2hYrf+P3pHZY5Uc8awoFzbR1WNxWz89ah1Wl1RJN UtRafmMxB4eq47PUYX0qE2iORN8YW29s5ZnDfrP5jUKQPiiyl4BNEdt9VvwdqdaVebgWrb bjZCQqAwv1M/BpWVepcDcISB+HPBPTj0gP6x8ICe9SgTAdYYirF4m5oN4aE32nHj/+shau ApH8MIYM3AoxDo4z+waCfLB1Q2K4qJzeHe88mx4a6J5z85iJKei38O6MWBubQO7AXt30+1 D7HS2H/ONTFe2WaUqzkK+DuLx4bmh5Ovx8UXvnjyCaGMkNqsEVxcRb6DwDCd/Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DU0x5O5I9RpJgy/cp3SLsKJQ2S1+Cvd/4SG5pk09kAc=; b=l2g6FH6uxwNCpKlJ/oJ3Rl3UvT/3LcZFXUfEnwTA1nqbmIeYdpPfA8BOJpqZVkKkmgCGoD RO2dZOsG0h0CK+AA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Geert Uytterhoeven , linux-m68k@lists.linux-m68k.org Subject: [PATCH printk v2 06/38] tty: nfcon: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:28 +0206 Message-Id: <20221019145600.1282823-7-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- arch/m68k/emu/nfcon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/m68k/emu/nfcon.c b/arch/m68k/emu/nfcon.c index 557d60867f98..c542fc2b121f 100644 --- a/arch/m68k/emu/nfcon.c +++ b/arch/m68k/emu/nfcon.c @@ -49,7 +49,7 @@ static void nfcon_write(struct console *con, const char *= str, static struct tty_driver *nfcon_device(struct console *con, int *index) { *index =3D 0; - return (con->flags & CON_ENABLED) ? nfcon_tty_driver : NULL; + return console_is_enabled(con) ? nfcon_tty_driver : NULL; } =20 static struct console nf_console =3D { @@ -151,7 +151,7 @@ static int __init nfcon_init(void) =20 nfcon_tty_driver =3D driver; =20 - if (!(nf_console.flags & CON_ENABLED)) + if (!console_is_enabled(&nf_console)) register_console(&nf_console); =20 return 0; --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D73AC433FE for ; Wed, 19 Oct 2022 15:04:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231534AbiJSPEi (ORCPT ); Wed, 19 Oct 2022 11:04:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232039AbiJSPEB (ORCPT ); Wed, 19 Oct 2022 11:04:01 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0088332AB8 for ; Wed, 19 Oct 2022 07:58:34 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zWMphmFfDq8OlVxrrPCchY88v/O4bwRw57cpKirymSQ=; b=v9YrdXBBO/q6meOVsORl10DT9g8/uzZ23xImHaforLllPZJe1CnX//gDt3Ecm5guuqQ/so MACoct9zfApolTJ+v1FVD1h0RLDBoFkoLZNYKGiJ0DsuUqHcw+0rDpb9ZIPgagNu7Zgs+O gkRSYUFmeL4JqdZ1XKjm0OXKoaL+fnuYiiqcJ5sO4+rKUKDp2WLocmXDuVBuX2NTl2a3rl siY+No+tFyVN4CEiREVMo2jTwrxQd9bAZzkxg/EMqT9C3vVARDmTRLPn53t0VEHW9z18bu LhmZykhol1iWGLRrhrVr7+PEuWsHDTLrcyEQ2JthQ9gAU5biH4l812fGFSJhAg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zWMphmFfDq8OlVxrrPCchY88v/O4bwRw57cpKirymSQ=; b=Gq8pSMFow1Bxe2k6NvWVnYMVnjoP0hDNZGICKaqxJBt6kO5QnCEPHVFaH8KueqPAfoWClB v8NwqRojtfnaGHCQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org Subject: [PATCH printk v2 07/38] um: kmsg_dump: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:29 +0206 Message-Id: <20221019145600.1282823-8-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- arch/um/kernel/kmsg_dump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c index 0224fcb36e22..3a3bbbb22090 100644 --- a/arch/um/kernel/kmsg_dump.c +++ b/arch/um/kernel/kmsg_dump.c @@ -22,8 +22,8 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, return; =20 for_each_console(con) { - if(strcmp(con->name, "tty") =3D=3D 0 && - (con->flags & (CON_ENABLED | CON_CONSDEV)) !=3D 0) { + if (strcmp(con->name, "tty") =3D=3D 0 && + (console_is_enabled(con) || (con->flags & CON_CONSDEV))) { break; } } --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01DF9C433FE for ; Wed, 19 Oct 2022 15:05:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231673AbiJSPFS (ORCPT ); Wed, 19 Oct 2022 11:05:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232112AbiJSPEF (ORCPT ); Wed, 19 Oct 2022 11:04:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ACCBACF55; Wed, 19 Oct 2022 07:58:34 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ANsy39dTo+95E1TXTBS5kbs28UVGSNMF6vh3Au875fs=; b=wBedELtUaj0zJeFDpwmo+Eyrsj3vhnslVQMMnOkfh/q28nnuprj+u3It6GYfDmuHkyH1Z0 jNvgvw0kZdalO6FFSXJu2mqO47j5IZHrSszNINkfYz08dHv/g24BIipbzVvvkCUtwUEd6c /G5ZUEi7k1R4vBBcPi0q5lAPBZi73IxF0DRlGFYb+7B7MuBL8SZrA8ne0tSMtqkeo+Yjiz U1qZfnDQPMOveo2W5xC7mJmp6jwh2VhohUHK7OWYalPnB+MT+EKUDwMWLhHz3pybmY9YEy vCFG/SnEVbJb9yxV5uYCeNZTI0ekEncYcgbhvVRO+iKofY2lSZVNpoCyiHCTQw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ANsy39dTo+95E1TXTBS5kbs28UVGSNMF6vh3Au875fs=; b=H1yntJDtD/aMwcZTAmUYG8IvP4HBmdfAyCl/OBYwZYBB8EKsYSv3K4Ea8bOP1qKbt6ZJ1i mxTyv7pllOslw7AQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Ard Biesheuvel , linux-efi@vger.kernel.org Subject: [PATCH printk v2 08/38] efi: earlycon: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:30 +0206 Message-Id: <20221019145600.1282823-9-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Acked-by: Ard BIesheuvel Reviewed-by: Petr Mladek --- drivers/firmware/efi/earlycon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/efi/earlycon.c b/drivers/firmware/efi/earlyco= n.c index a52236e11e5f..8c27eb941d8e 100644 --- a/drivers/firmware/efi/earlycon.c +++ b/drivers/firmware/efi/earlycon.c @@ -30,7 +30,7 @@ static void *efi_fb; static int __init efi_earlycon_remap_fb(void) { /* bail if there is no bootconsole or it has been disabled already */ - if (!earlycon_console || !(earlycon_console->flags & CON_ENABLED)) + if (!earlycon_console || !console_is_enabled(earlycon_console)) return 0; =20 efi_fb =3D memremap(fb_base, screen_info.lfb_size, @@ -43,7 +43,7 @@ early_initcall(efi_earlycon_remap_fb); static int __init efi_earlycon_unmap_fb(void) { /* unmap the bootconsole fb unless keep_bootcon has left it enabled */ - if (efi_fb && !(earlycon_console->flags & CON_ENABLED)) + if (efi_fb && !console_is_enabled(earlycon_console)) memunmap(efi_fb); return 0; } --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A020DC433FE for ; Wed, 19 Oct 2022 15:04:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231588AbiJSPEm (ORCPT ); Wed, 19 Oct 2022 11:04:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232013AbiJSPEA (ORCPT ); Wed, 19 Oct 2022 11:04:00 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A1AF189C3E; Wed, 19 Oct 2022 07:58:32 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6uEJOM0caPrcvNJcHiErtW6cO4rX4lvkgAL5ZPoAngE=; b=CapeSp4lIuUCMT3A2F+Nh1MiAgJLkP2QvT6kPUMQDmJJFQsukbmY9zgoaeE4Mq6UuBqXXb FrZc++ZOPgsuLs9l7PcPyG4j8PgQByAcFR2QTb5ZOiIdmXyyFYqlRtydfmDmoK5yA3OP78 U0XmnXaelSW/V/NwDwJUqlWqX2IcrI2b9QoB5wTOni/8eC59uwoJspmELM/0AK/+2z5J0G bd1oHF0zuZVLDhAFAcJJT5y3CPqV4fXZIaKcBDHjVUzgpVkWqsTRUcD5J9GUYo05fhBIDg fYj1DxyE3Wu0F0Ede8aUNYGFTPayP73PEUKd+FQ5qnHfrV5Nu/mSQTYm2wS3RQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6uEJOM0caPrcvNJcHiErtW6cO4rX4lvkgAL5ZPoAngE=; b=ZQecdyT7PQky3Pel/Hzc+4qBo3aS7NXlfHW9v7oMg/iE63aGG0BcneUC9VkDNd/cxE1gob fBX8kx6iiefyiNCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: [PATCH printk v2 09/38] netconsole: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:31 +0206 Message-Id: <20221019145600.1282823-10-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/net/netconsole.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index bdff9ac5056d..073e59a06f21 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -332,7 +332,7 @@ static ssize_t enabled_store(struct config_item *item, } =20 if (enabled) { /* true */ - if (nt->extended && !(netconsole_ext.flags & CON_ENABLED)) { + if (nt->extended && !console_is_enabled(&netconsole_ext)) { netconsole_ext.flags |=3D CON_ENABLED; register_console(&netconsole_ext); } @@ -915,7 +915,7 @@ static int __init init_netconsole(void) if (err) goto undonotifier; =20 - if (netconsole_ext.flags & CON_ENABLED) + if (console_is_enabled(&netconsole_ext)) register_console(&netconsole_ext); register_console(&netconsole); pr_info("network logging started\n"); --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 886F9C4332F for ; Wed, 19 Oct 2022 15:05:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231670AbiJSPFL (ORCPT ); Wed, 19 Oct 2022 11:05:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232105AbiJSPEE (ORCPT ); Wed, 19 Oct 2022 11:04:04 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 196331929A9 for ; Wed, 19 Oct 2022 07:58:38 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191367; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q43bR7EIdzwEejtqYY/+0pBZ/1DlBf/ms3Th4977RU4=; b=CJ0wkcfDAIYxYlfRDwtWDHTwKRBKnIGO7mDk96DEhEfPYYF1oPQuNnmaWMjNVFx82t2g2p vzwkF94n0h7nEyhv0U93cY/SDg0gFrPMaHBWZPIoWnM4PkhT8ENrt1zwlq56m266UfO6ok E2Pf4W9zbKKXLfOeDb67zW0A+t3HCRbpaPaonrDqlLifvlY/UNRbzMHnKW0rU52czq11LU 2QA4703MQAMlTBiSbe41rKt7kIT0G7svma7Brz2sKaxLCd0oZwJQ/auRydmpv7zgddgQ7Z KT6cqgK7jbmb4Yo+LE3H9hyyE9UAia6OLCMO0LrI4vSPeblK36wIq1qdR3Gn5A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191367; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q43bR7EIdzwEejtqYY/+0pBZ/1DlBf/ms3Th4977RU4=; b=4/3XcDP9JpywLbtVPvYMt3perm+LULFBKeOfwGqUTnu4+/A8q5xycmiCMFah2+WEFeLmuc PyYB51N0P1g/zmCw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , Shile Zhang , Xianting Tian , linuxppc-dev@lists.ozlabs.org Subject: [PATCH printk v2 10/38] tty: hvc: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:32 +0206 Message-Id: <20221019145600.1282823-11-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/hvc/hvc_console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index 4802cfaa107f..6d1d7b72488c 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c @@ -265,7 +265,7 @@ static void hvc_port_destruct(struct tty_port *port) static void hvc_check_console(int index) { /* Already enabled, bail out */ - if (hvc_console.flags & CON_ENABLED) + if (console_is_enabled(&hvc_console)) return; =20 /* If this index is what the user requested, then register --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B434C4332F for ; Wed, 19 Oct 2022 15:05:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231808AbiJSPF3 (ORCPT ); Wed, 19 Oct 2022 11:05:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232136AbiJSPEG (ORCPT ); Wed, 19 Oct 2022 11:04:06 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 935CB17A01B; Wed, 19 Oct 2022 07:58:35 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cANA2HumoCM7OV3714mDIj5DFLk1sHCXsW4mcU0VIIA=; b=UH0/62giDRacTgc6LWjPHq8aCEv5jkdDEzI/MA8Jup622emiuKoX7BLt8gRNRy9hdeFVnl EfYBYT1slOvZDZRzEYjnihQ/kb/pSC0sh+4hDZTe//uS3JVcMaASNn8iGoYSm1SazG2vWu rfA1AG3yElx0WcfZJJG2/V97uLL7zKyUS5JShA2ytxO5Fh7YQzi8/7WTxInUnWi5M73WCI j6zCLeQepuBdR7m/KMJa5r18w82h1KE96DJxw5pUNwJwUMgjkxcZ9XzvU07IH3AtxI4al8 qGXhSz0aOTdStNeIxhst5X4QNC5Ip1L8vaF0n5xzmGMrOsDxYBuv3gLeRDfPdA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cANA2HumoCM7OV3714mDIj5DFLk1sHCXsW4mcU0VIIA=; b=KQbMsoI8kPiCKg4t2VNCGQ7wjHS2dtIutEdNfXg4Ksb0sa7p4/aiaOHQFSJrrFe8FAeRCI P7dHuNzNimUGeVCQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org Subject: [PATCH printk v2 11/38] tty: serial: earlycon: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:33 +0206 Message-Id: <20221019145600.1282823-12-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/serial/earlycon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c index a5f380584cda..bdfb60da97bd 100644 --- a/drivers/tty/serial/earlycon.c +++ b/drivers/tty/serial/earlycon.c @@ -181,7 +181,7 @@ int __init setup_earlycon(char *buf) if (!buf || !buf[0]) return -EINVAL; =20 - if (early_con.flags & CON_ENABLED) + if (console_is_enabled(&early_con)) return -EALREADY; =20 again: @@ -253,7 +253,7 @@ int __init of_setup_earlycon(const struct earlycon_id *= match, bool big_endian; u64 addr; =20 - if (early_con.flags & CON_ENABLED) + if (console_is_enabled(&early_con)) return -EALREADY; =20 spin_lock_init(&port->lock); --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05082C4332F for ; Wed, 19 Oct 2022 15:04:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231202AbiJSPEY (ORCPT ); Wed, 19 Oct 2022 11:04:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232052AbiJSPEC (ORCPT ); Wed, 19 Oct 2022 11:04:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C308211E46A; Wed, 19 Oct 2022 07:58:35 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jlKWc1Grue9kQfYwJIiewArVOaAkhAK4uRE7V4DMseI=; b=Kk2lnB0DeVDuCcQ2SWcnH8R0PgShB2CZwwsounOmf0c7TAxDw35ZfqSbSJ1PexWKje9a+0 NMoma2X+T0p0buJRG2CD0IdcQ3ox2o2rPGrDdFrPUj49Z35+fPcKgQeojLLcyw6shd+JZ9 7r6p+CtHoY10o8YGBeUNnQ0FJ053rbDPZzoW8bfvOwNdxeAh5JUrxV2//iLX8tpfhO5B/d l3lLWkkazcGkc6qDO/d6aqqwdZkfKULXqPgH+kzjyq67FPhYBElPgpY4K3E1YW+mL8gUT4 aXnp3oFg8O4sBrVcA7QxClrsqr+RzG3dLrE+NIR5PRiZa07ARtMvihKFdcmmsw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jlKWc1Grue9kQfYwJIiewArVOaAkhAK4uRE7V4DMseI=; b=Hrgpan7bNf/oEJbZZM6hsAcz+zCVZiCrz6fuzTkbXs/R1ESYYwgaiON5lh57jBdACO27c+ UT3EpQHIZr7qOrCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk v2 12/38] tty: serial: kgdboc: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:34 +0206 Message-Id: <20221019145600.1282823-13-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/serial/kgdboc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index e76f0186c335..b17aa7e49894 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -533,7 +533,7 @@ static int __init kgdboc_earlycon_init(char *opt) console_lock(); for_each_console(con) { if (con->write && con->read && - (con->flags & (CON_BOOT | CON_ENABLED)) && + (console_is_enabled(con) || (con->flags & CON_BOOT)) && (!opt || !opt[0] || strcmp(con->name, opt) =3D=3D 0)) break; } --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39438C4332F for ; Wed, 19 Oct 2022 15:05:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229875AbiJSPFI (ORCPT ); Wed, 19 Oct 2022 11:05:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232099AbiJSPEE (ORCPT ); Wed, 19 Oct 2022 11:04:04 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B956EB96; Wed, 19 Oct 2022 07:58:37 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CYLncsVrBizTn0tZlGmVU07Lo3jyJ/DS7XfMGutmnSA=; b=JPedjArJAuY5hRBDkNnnczWzi0rdtYdWSojm+d6XEyT740PpZPGKZQU8tT+uuaYGiVPfsv wihTQwPpb5Vfqyv+jnFaz5aslcibke0hRWUqpVTOTuDJ52Sk0LuaLb/GZm3txhIsikw6KC X9YIkrLQk7MjDOB4L+8dYq42ZQZWa0JICoBu63P2KT3BFI0l6VLvdUELcHhxm1urY9c4oO srY+3ajo1wLeddjhJXCk3lYKZGbHvMEMjeWmEZQ6iCGDF2dgpc5Hw+kMV7spvVFzkpsW9a N9oAjW1J4KS75rVtgGeiiia5qozkB4wZddYkiJVVpOYDHNoA8R8m6cygY7P6QQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CYLncsVrBizTn0tZlGmVU07Lo3jyJ/DS7XfMGutmnSA=; b=S7pfiQDwwJc4IAaG+ohuEdR5wq8i6B5ZKrnBe8A+GkV8vDCEdvI4ws2GTEvObuZQVkx4oN ggzfXJPGE1IMo9CA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org Subject: [PATCH printk v2 13/38] tty: serial: pic32_uart: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:35 +0206 Message-Id: <20221019145600.1282823-14-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/serial/pic32_uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/pic32_uart.c b/drivers/tty/serial/pic32_uar= t.c index 2beada66c824..d70344dc6e8a 100644 --- a/drivers/tty/serial/pic32_uart.c +++ b/drivers/tty/serial/pic32_uart.c @@ -843,7 +843,7 @@ console_initcall(pic32_console_init); */ static int __init pic32_late_console_init(void) { - if (!(pic32_console.flags & CON_ENABLED)) + if (!console_is_enabled(&pic32_console)) register_console(&pic32_console); =20 return 0; --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08800C433FE for ; Wed, 19 Oct 2022 15:05:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231723AbiJSPFY (ORCPT ); Wed, 19 Oct 2022 11:05:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232122AbiJSPEG (ORCPT ); Wed, 19 Oct 2022 11:04:06 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1153D1C5A5F; Wed, 19 Oct 2022 07:58:33 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ECvJGB97Hla1u507jwp5akWm1qCQ1lChgjmZWmbHvAU=; b=U0BupZGCQHaRq+D5r1dZHhQ+O1tvmXp1DO3geOOs8K5K2OV5M7k0FFEhZuxAaivxGr3jDh LfFdNYEVY3ONqrvO31yQDmC4pv9lZbZ65u9VWYnvToQk3eYero1RZj02ZbuD6ghbDhttP0 lJA7ZTAiSL9vkXIVlIyBZZR4P+kilPLa8KiUKPFUDOhCgL35CEuVqTijttmO8iVFoUk9ik 0QsrUBkBSsE14vhvOIsyklFwXFJO8kecQ310Ish2cbJIx3/4N2ekjBu0ZcTA+w6OhfiRcy m3ozY+le97N9+MO4n35Tyllx9o4l3z7cTXJQyGh2O7btDGrwSYIhS/VdcnmDdQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ECvJGB97Hla1u507jwp5akWm1qCQ1lChgjmZWmbHvAU=; b=GI/hKiJLWVa+vepqZzJ+pH7neoD0sTcrbTqVtFMsZA/DipeGp5quDMaKAppqq2BiIO9vW2 5J+fk9L/z5Q+9zDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Krzysztof Kozlowski , Alim Akhtar , Greg Kroah-Hartman , Jiri Slaby , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH printk v2 14/38] tty: serial: samsung_tty: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:36 +0206 Message-Id: <20221019145600.1282823-15-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/serial/samsung_tty.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_= tty.c index 77d1363029f5..8142a0e53ffa 100644 --- a/drivers/tty/serial/samsung_tty.c +++ b/drivers/tty/serial/samsung_tty.c @@ -1732,7 +1732,7 @@ static void __init s3c24xx_serial_register_console(vo= id) =20 static void s3c24xx_serial_unregister_console(void) { - if (s3c24xx_serial_console.flags & CON_ENABLED) + if (console_is_enabled(&s3c24xx_serial_console)) unregister_console(&s3c24xx_serial_console); } =20 --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29D82C433FE for ; Wed, 19 Oct 2022 15:06:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231960AbiJSPGl (ORCPT ); Wed, 19 Oct 2022 11:06:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231834AbiJSPFk (ORCPT ); Wed, 19 Oct 2022 11:05:40 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEA2D32047; Wed, 19 Oct 2022 07:59:15 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191370; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KzgyVUdc3c3kCjuysiyU5ciOaxj14Ka8qNAluIGo2ws=; b=oMqTMwFgA7TRBPKkkgg2SqcRq6lIX5GGgXm4dRv/bMgruBa0iJWddlwoaLUfKzhFqpC6WR gwr90qgT4eOy+NBCyDnpmsmy21dVcFJfucOAlyOaD0dBidVgI84sy3+hasNAbOJlFopeIX EoGBXAmUhpgj+FmhG/kz41N/6M8NIlNgrCEMfeZjFloXm7gwFQyF30r1x8A5O1Ae0MgVdJ w9n7t84CPDZqWN9vXSJzz+kCubBP+BWaDlt+OHM8hc8e8905TZMfm5ln6dAhILh8HZ273m myRuJkzDuM/0PtnahsjcVV7NerXl1J+nrLHS7FK5f2OsLl4h+1Sz88UbEye5LA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191370; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KzgyVUdc3c3kCjuysiyU5ciOaxj14Ka8qNAluIGo2ws=; b=538n87jf9fQBuIO0i1kQOYmPKMxRqFehBEvcShiER+MFwipHan1NRjt/wMAfdBOIqq93S6 /K6fsXGFCl2rWVBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org Subject: [PATCH printk v2 15/38] tty: serial: serial_core: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:37 +0206 Message-Id: <20221019145600.1282823-16-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/serial/serial_core.c | 2 +- include/linux/serial_core.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_c= ore.c index 179ee199df34..ebf609e4e179 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2573,7 +2573,7 @@ uart_configure_port(struct uart_driver *drv, struct u= art_state *state, * successfully registered yet, try to re-register it. * It may be that the port was not available. */ - if (port->cons && !(port->cons->flags & CON_ENABLED)) + if (port->cons && !console_is_enabled(port->cons)) register_console(port->cons); =20 /* diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index d657f2a42a7b..ed5d1aeb91e1 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -745,7 +745,7 @@ static inline int setup_earlycon(char *buf) { return 0;= } =20 static inline bool uart_console_enabled(struct uart_port *port) { - return uart_console(port) && (port->cons->flags & CON_ENABLED); + return uart_console(port) && console_is_enabled(port->cons); } =20 struct uart_port *uart_get_console(struct uart_port *ports, int nr, --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2780EC4332F for ; Wed, 19 Oct 2022 15:06:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232082AbiJSPGp (ORCPT ); Wed, 19 Oct 2022 11:06:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231847AbiJSPFk (ORCPT ); Wed, 19 Oct 2022 11:05:40 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C8C334993; Wed, 19 Oct 2022 07:59:17 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191370; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jjpBzMIZil2dmLUT+irfoeemb7oKmLhPxEY4dlNGawQ=; b=SRSJfh36p3UleipLxlUtTUFpPUDmxLS8yo+PBwx959oqjUNw376zK6DIo/TpEECQam0Wav /2i/bDbwVlsuguU4ipVk+E4hAwVZr3ThbxI4eRGPkgdkCfPFhUgsuu/0h07oZavqc7iS6J j2MiWZcfTsr11cF4dBtCFOpcYxI5k3TlsXRagqXz+bBUpm3HMvQNYCWx3izXsjdjez+Q9W wEFLfevTyEeT3C/B5o9VIhitHIt0qyzvN3XoWRCvsHwrp7R5LrgqTxXEsewej4Jm6gnydQ aBuETCfoPiaOSRdbyc7ZRmpDtL6UqKZgreHmyf0z8VczL/og4nKGiDSM/2agug== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191370; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jjpBzMIZil2dmLUT+irfoeemb7oKmLhPxEY4dlNGawQ=; b=HzSWZdqEZL2J95BBvsCPnMwoU3L+/EMg5oVAvdeTTFj3KSaG3KgrIou7oKqs+PVEiiY/lu WxdYmH+I94CFn5DA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , Michal Simek , linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH printk v2 16/38] tty: serial: xilinx_uartps: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:38 +0206 Message-Id: <20221019145600.1282823-17-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/serial/xilinx_uartps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx= _uartps.c index 2eff7cff57c4..e1fe95bd55c1 100644 --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -1631,7 +1631,7 @@ static int cdns_uart_probe(struct platform_device *pd= ev) #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE /* This is not port which is used for console that's why clean it up */ if (console_port =3D=3D port && - !(cdns_uart_uart_driver.cons->flags & CON_ENABLED)) { + !console_is_enabled(cdns_uart_uart_driver.cons)) { console_port =3D NULL; cdns_uart_console.index =3D -1; } --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A3A6C433FE for ; Wed, 19 Oct 2022 15:06:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231987AbiJSPGK (ORCPT ); Wed, 19 Oct 2022 11:06:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231613AbiJSPFF (ORCPT ); Wed, 19 Oct 2022 11:05:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E5091DDC6 for ; Wed, 19 Oct 2022 07:59:03 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191371; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A5NubkodPN0irIWt1R4/lmY742ka0PyGCnf6KGs6APw=; b=WEzWfi4KYJK6tM+UtRO9gMqcL80wT6ZfChj8pVIGHeb3YIK8WqcUSy2zLWw/YojPSsGNup y7TQiRk0nnLkGjmOTqw0TEl1/pK8HDisoKp2Nk5Yb4JeRsivDB1CzI0E2o2qg0LVhsdq8m zyNH5ObjKPbpSu80an465e/0eKD5IrMpnPWTzA90Ir/JAkTes5pABQ40isFhZEHLol3hQf G/9qi1yXpMDuoHf2/pGXSYMCmXLbcMI9K/QMqEtFkkge19m+3XWRUYic9PsXu+yn2/vmRZ FNkJG8kyRt1kEdOSxEc5o/S3bJfASgsb4wf/OAS1njjVebC3sch6ryLQd2ZEmQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191371; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A5NubkodPN0irIWt1R4/lmY742ka0PyGCnf6KGs6APw=; b=7C+o7eTStwH+TXiK5kilPxMT0uoA0rWx2USLmgf4Q5VlRjt97pmtga3hTsgy3a6OZTtOaX Cj0gT50z2MtWHsDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH printk v2 17/38] tty: tty_io: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:39 +0206 Message-Id: <20221019145600.1282823-18-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/tty_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index de06c3c2ff70..2050e63963bb 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3532,7 +3532,7 @@ static ssize_t show_cons_active(struct device *dev, continue; if (!c->write) continue; - if ((c->flags & CON_ENABLED) =3D=3D 0) + if (!console_is_enabled(c)) continue; cs[i++] =3D c; if (i >=3D ARRAY_SIZE(cs)) --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67CCCC433FE for ; Wed, 19 Oct 2022 15:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230016AbiJSPGB (ORCPT ); Wed, 19 Oct 2022 11:06:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230442AbiJSPER (ORCPT ); Wed, 19 Oct 2022 11:04:17 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B6B413FDDA; Wed, 19 Oct 2022 07:59:04 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ROOYEsR0MhxheCxKtRPcb2mfw4k8DWEDO6Xw87lE788=; b=dj7K4xySpq7whNrvoUhtROBd4luyoKbpg6xTwFwhdIXZhbdt5NpgczLROroEXs3PgPR5nV 6HyH+7+1+Yrdno3e7XSvm+Rjun5P+yUigjsQD0kip44MepJ/Q022Y5oOoN2gaVaa8YRfl2 6KkfTfDFLG8D29GLh1KJj/8usWDl8staheqlg16yBFk55WoMgh3s8R3HdP3566EXWHdGH6 o7Jh2LwVPpRUpZwQ1KaXB7R3RaCUqh3kXswyT6GrZvNhezCCaXRsvfm77BMTZHoEQMPfxJ d6S8ayitsuWXl06xJ3vmxP14O6b/Blx/0zYuHK1UiScgBw0QdiyNqqvsWRpJLA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ROOYEsR0MhxheCxKtRPcb2mfw4k8DWEDO6Xw87lE788=; b=ryuSpo1BnIE5ZnNgWQJ91gufZbr2BMikTU+gIGl5WJJn0EfZEC0dlR7JSp8t5SfbRRzeKa qe9zWCaaaGZeIqAA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Peter Zijlstra , Mike Rapoport , Mathias Nyman , Andrew Morton , linux-usb@vger.kernel.org Subject: [PATCH printk v2 18/38] usb: early: xhci-dbc: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:40 +0206 Message-Id: <20221019145600.1282823-19-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/usb/early/xhci-dbc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c index bfb7e2b85299..b1a9c393160b 100644 --- a/drivers/usb/early/xhci-dbc.c +++ b/drivers/usb/early/xhci-dbc.c @@ -927,7 +927,7 @@ void __init early_xdbc_register_console(void) =20 static void xdbc_unregister_console(void) { - if (early_xdbc_console.flags & CON_ENABLED) + if (console_is_enabled(&early_xdbc_console)) unregister_console(&early_xdbc_console); } =20 --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A498EC4332F for ; Wed, 19 Oct 2022 15:06:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231508AbiJSPGW (ORCPT ); Wed, 19 Oct 2022 11:06:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231804AbiJSPF0 (ORCPT ); Wed, 19 Oct 2022 11:05:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EA86192D9F for ; Wed, 19 Oct 2022 07:59:05 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I1RFx/v+hUfcDGQrJ2jjINSDPUuF1n3qxJyJC8w20Fo=; b=Na76VoWVvHR8U/NeE5ZW4Qj/8y6x7pe9hXOgikZ8soMx+eMpjEC1D0Ljtsuf7gKOPi1SDV O3H/i2rcTIQgphMFvzlgRv/uQQZ/LEqst5WRZnTXPkWrOxFhCP0cC+X4xmwV9QwQt8kwca JYqIAB/VA0uqLjmgRGxiFV3y2r4MhAxXTUQjFEifIzKwTlsUDV55eIk4i97ma0O49fC/xv vZIf5vcZpREDTpUHMQcJcVIUftRDZvqEiNVhEF4yBmFJvpLY8XZrmnW3/QU04Bt97BGLkB AELofnWb5Zk+quDqxs23odjOpZ43C65y97abkXno++P/O3VWUEZmj6ZrHjrAFQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I1RFx/v+hUfcDGQrJ2jjINSDPUuF1n3qxJyJC8w20Fo=; b=bXJPsQ9Ibdzn9lP6cPILeOojpe35Hpu6UnYqHQ3BjsYI2l13B6GR71QgyJ9Uqh17/ObVif drEUXkAw21hR9pBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Luis Chamberlain , Aaron Tomlin , kgdb-bugreport@lists.sourceforge.net Subject: [PATCH printk v2 19/38] kdb: kdb_io: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:41 +0206 Message-Id: <20221019145600.1282823-20-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). Signed-off-by: John Ogness Reviewed-by: Douglas Anderson Reviewed-by: Petr Mladek --- kernel/debug/kdb/kdb_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 67d3c48a1522..550fe8b456ec 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -559,7 +559,7 @@ static void kdb_msg_write(const char *msg, int msg_len) } =20 for_each_console(c) { - if (!(c->flags & CON_ENABLED)) + if (!console_is_enabled(c)) continue; if (c =3D=3D dbg_io_ops->cons) continue; --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66D7EC4332F for ; Wed, 19 Oct 2022 15:06:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229752AbiJSPGS (ORCPT ); Wed, 19 Oct 2022 11:06:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231617AbiJSPFF (ORCPT ); Wed, 19 Oct 2022 11:05:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50FEB17A023 for ; Wed, 19 Oct 2022 07:59:04 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2RcyNuvhxtc3XAp6KUXXBEZGfBTKoyRNmah0KdJRqUM=; b=s+uK2CVyfeRWS2SM8ONtEm3ezF4TKCfBKPBHIwbQeW7/3EKdt2DXK8Se8xiredxeNeCSkY ZKidWJ9kOFMnJ+GDRhqzajlfU0p4AFkX17OY/4V8RDFxWqEJS/1ZvxtBmCOcbU/4l2IV5+ uARnYyoVv6Nyvh9wOtzsxW1T3vJw5LOkY1LuXAHyxPLMVW6YaxF14EZEX4gyzIy+5CXUjS vS1F3O108Xc1xgSipOJuPxZcLQ/qV1jeZloh/cC1xGCqj2wAIwT9zN8nuby6knA2dC3umy BQvb2BMGIRylFs6NDquzoIBMVcnZI7H6sM7m8P0T/FddSctNfiRBDKDOqpiRPg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2RcyNuvhxtc3XAp6KUXXBEZGfBTKoyRNmah0KdJRqUM=; b=o+Tf43pKW3jb3K3SYt/Uyhx64JMO0G2cG8/ulnFuahJncjT6ev9pQxCcwgJEpI8Oeo5SuX YSUluQ/obMklGtAg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org Subject: [PATCH printk v2 20/38] um: kmsg_dumper: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:42 +0206 Message-Id: <20221019145600.1282823-21-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Rather than using the console_lock to guarantee safe console list traversal, use srcu console list iteration. Signed-off-by: John Ogness --- arch/um/kernel/kmsg_dump.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c index 3a3bbbb22090..44a418dec919 100644 --- a/arch/um/kernel/kmsg_dump.c +++ b/arch/um/kernel/kmsg_dump.c @@ -16,20 +16,17 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dump= er, struct console *con; unsigned long flags; size_t len =3D 0; + int cookie; =20 /* only dump kmsg when no console is available */ - if (!console_trylock()) - return; - - for_each_console(con) { + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(con) { if (strcmp(con->name, "tty") =3D=3D 0 && (console_is_enabled(con) || (con->flags & CON_CONSDEV))) { break; } } - - console_unlock(); - + console_srcu_read_unlock(cookie); if (con) return; =20 --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EF53C4332F for ; Wed, 19 Oct 2022 15:06:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232118AbiJSPGy (ORCPT ); Wed, 19 Oct 2022 11:06:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231892AbiJSPFm (ORCPT ); Wed, 19 Oct 2022 11:05:42 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 432F6193EE9; Wed, 19 Oct 2022 07:59:07 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aHpEExScLzm4b3PGICcqjxP6eSShWDRVil4o7DIdRaU=; b=eDfs/FrHZ7HvnRF4atKhYEZ/pRXno8GEGAkw6IqnyiCmO75Q9sEJ6bqLoRWApu5I/kGcQh KCTzK1MrPYWFQHFbhhZ4ddIBd7thtElTQ1FhTZSvTGr+D/NiY6ja5av6esQrgKRy3JmdV3 rrRE8vZ1b74ucDPVRwBFE1RIC+RhuKL5DdLWniGfxLfcajr60p331h+dY6KdEzGysIZMdC yATsOHK/PLnHwsUFjoxiti7aJ0XxaKU0B+KQDroX00sQ4UKCeboef9oWWEJpZprSsCboLS UQL5y2A8i38TojR6bF2UMoVPjjyV/EALMD7ITlxAjhc539biNA5Q3/A88oMp9w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aHpEExScLzm4b3PGICcqjxP6eSShWDRVil4o7DIdRaU=; b=ag8wipmZjScVK96FvYUT41NwW8W8jBS77tduneOJOnLYN8uLmQW8RkuO+x9sTyAf/SfPXA QV5RyDV2N62v9UBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk v2 21/38] serial: kgdboc: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:43 +0206 Message-Id: <20221019145600.1282823-22-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use srcu console list iteration for safe console list traversal. Note that configure_kgdboc() still requires the console_lock in order to ensure that no console is in its write() callback when its direct() callback is called. Add comments to clarify this. Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman --- drivers/tty/serial/kgdboc.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index b17aa7e49894..e9d3f8c6e3dc 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -171,6 +171,7 @@ static int configure_kgdboc(void) int err =3D -ENODEV; char *cptr =3D config; struct console *cons; + int cookie; =20 if (!strlen(config) || isspace(config[0])) { err =3D 0; @@ -193,8 +194,14 @@ static int configure_kgdboc(void) if (!p) goto noconfig; =20 + /* + * Stop console printing because the device() callback may + * assume the console is not within its write() callback. + */ console_lock(); - for_each_console(cons) { + + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(cons) { int idx; if (cons->device && cons->device(cons, &idx) =3D=3D p && idx =3D=3D tty_line) { @@ -202,6 +209,8 @@ static int configure_kgdboc(void) break; } } + console_srcu_read_unlock(cookie); + console_unlock(); =20 kgdb_tty_driver =3D p; @@ -451,6 +460,7 @@ static void kgdboc_earlycon_pre_exp_handler(void) { struct console *con; static bool already_warned; + int cookie; =20 if (already_warned) return; @@ -463,9 +473,14 @@ static void kgdboc_earlycon_pre_exp_handler(void) * serial drivers might be OK with this, print a warning once per * boot if we detect this case. */ - for_each_console(con) + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(con) { if (con =3D=3D kgdboc_earlycon_io_ops.cons) - return; + break; + } + console_srcu_read_unlock(cookie); + if (con) + return; =20 already_warned =3D true; pr_warn("kgdboc_earlycon is still using bootconsole\n"); --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2D7BC433FE for ; Wed, 19 Oct 2022 15:06:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231533AbiJSPGF (ORCPT ); Wed, 19 Oct 2022 11:06:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230353AbiJSPFF (ORCPT ); Wed, 19 Oct 2022 11:05:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85B872F007; Wed, 19 Oct 2022 07:59:07 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ACPI8gcDk9OHrPL7ke5XVpq5ui7KkEF2l2bHZNH8aSI=; b=Ccgy/tfHlK5pUky0RE3+PgIt1rgjfkq3Tlb6Sd8WDUWfjg35ogZEbfXvjsXgVU7QAtpI49 nw+J0Yr/pj68t053bnHszLo5Yf5Got25SfdJCTQ1XQR/4b43Xz8/x2LVdovnTWreK9d35z WppqeLftN6a6CqKiUrS4MgpzyM4QuBB9/5G05SLCI2HKV5qPIqRLUZfGfcz/gCiINc34o6 h7jJYblRSvG5ZqO55I7PrZ9Ycato2Lu3jOD83rw09TuE0vlq+TQ/1tpX9HLurzS3xA447+ yFPYxB156iSolo2OCep4UyfsiV0RLod+tQBCSKSpjrxSxsn1FDpKIja+pCHk1w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ACPI8gcDk9OHrPL7ke5XVpq5ui7KkEF2l2bHZNH8aSI=; b=yIzC1pH27dxiAovKC98wbTRSEd+6o8YRWTr6jNZ8jbaA2SP9qlYcbF+l4kQ4Idnk3qN43O wYA6fbuZuIsJFdCw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk v2 22/38] serial: kgdboc: document console_lock usage Date: Wed, 19 Oct 2022 17:01:44 +0206 Message-Id: <20221019145600.1282823-23-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" kgdboc_earlycon_init() uses the console_lock to ensure that no consoles are unregistered until the kgdboc_earlycon is setup. This is necessary because the trapping of the exit() callback assumes that the exit() callback is not called before the trap is setup. Explicitly document this non-typical console_lock usage. Signed-off-by: John Ogness Reviewed-by: Douglas Anderson Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/serial/kgdboc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index e9d3f8c6e3dc..48000666789a 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -545,6 +545,14 @@ static int __init kgdboc_earlycon_init(char *opt) * Look for a matching console, or if the name was left blank just * pick the first one we find. */ + + /* + * Hold the console_lock to guarantee that no consoles are + * unregistered until the kgdboc_earlycon setup is complete. + * Trapping the exit() callback relies on exit() not being + * called until the trap is setup. This also allows safe + * traversal of the console list. + */ console_lock(); for_each_console(con) { if (con->write && con->read && --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E37CC433FE for ; Wed, 19 Oct 2022 15:06:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232059AbiJSPGh (ORCPT ); Wed, 19 Oct 2022 11:06:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231835AbiJSPFk (ORCPT ); Wed, 19 Oct 2022 11:05:40 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EB4B13D0F for ; Wed, 19 Oct 2022 07:59:09 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rxx7a00tnCHfnWXA978Xi0IL/mfHFWoLJumPfZjxuVQ=; b=odMAd6jZuExx16Yi0L8xd1hm9Jh9VTjUOvjUUgrX8qFZQuCWOzfAaZvh89StL/uY5ZVjZ4 7F0py/hns3GzhNljNb4CSr+P5RvwEKeVFVSo7ucX0apDwGWsb+zxnCp4263f8YKJ9a5ej1 2rV6t+eru8+PT568/dvEv0WiF4bn/adCAwyLxplBuLF8aZHWoHD+n5evDi2JVgnqY8rjNr Pt3sSFfwb1FV+WRk5mWlhtAOGR/p0dm76Sw3rc+OGGbhM33YJGS18mUoUTGARbsvXP77z4 CFsQZ+FmootigSKYJ31Vjh5hqGF6+j1S9tpl8U4eAuAup1tordjr0REfQ7pl7A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rxx7a00tnCHfnWXA978Xi0IL/mfHFWoLJumPfZjxuVQ=; b=q9rIFA276lgWZLXV5mkpOktuUZD6YWke7bg19dKAJViyJu9A6OrFIkzYrQzLJ2n8EtnLIQ id3MWXWGrsWj0ZDA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH printk v2 23/38] tty: tty_io: document console_lock usage Date: Wed, 19 Oct 2022 17:01:45 +0206 Message-Id: <20221019145600.1282823-24-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" show_cons_active() uses the console_lock to gather information on 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 Reviewed-by: Greg Kroah-Hartman --- drivers/tty/tty_io.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 2050e63963bb..333579bfa335 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3526,6 +3526,14 @@ static ssize_t show_cons_active(struct device *dev, struct console *c; ssize_t count =3D 0; =20 + /* + * Hold the console_lock to guarantee that no consoles are + * unregistered until all console processing is complete. + * This also allows safe traversal of the console list. + * + * Stop console printing because the device() callback may + * assume the console is not within its write() callback. + */ console_lock(); for_each_console(c) { if (!c->device) --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 310D1C433FE for ; Wed, 19 Oct 2022 15:06:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230150AbiJSPGv (ORCPT ); Wed, 19 Oct 2022 11:06:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231878AbiJSPFm (ORCPT ); Wed, 19 Oct 2022 11:05:42 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87FCD38A0; Wed, 19 Oct 2022 07:59:21 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yQcHjaE6CQfq7iO6zRmu96wMYI8aMwb9KZsnUEYxyHY=; b=uJxwQf34Ytc+E+xlVFr+QJdkNyrMOfUvwvaZcWKOsw0HPBVGrb4yMLRvikG5fD7cUCCc3C 28HKnPfM+uG1Z5z4L56fxWXyrRIKTZSVZptsjItATwqm3Q4MhzYIPKqCJpyLB7fFVS0j6u /X9PqMg8IxzzFdciI7TDe8A+OYuDmG+ME1toyuS2fFqmqa1hTm+YBUxQV3oCJZHXuqalbQ QU8S/p/3lIK/8LUUToUovSXE4jfY76zMpDU7MTtRzM++2mNnVj7bKvcl8AgTMdYYD4YXz3 z8y5puCaOyxnbNpSsfsdnnyyPts9YXiBFHfz2EsNyXbwpHaTQcRNqZA6iu/ZOw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yQcHjaE6CQfq7iO6zRmu96wMYI8aMwb9KZsnUEYxyHY=; b=FnIygPB0dsrSCCUyaFzWqQi5S8pnwh8nD/V378wLSKMrAbys4FHt9SsFaYaowHj8t+QBgh QwF/uqpaFI+ppICQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Helge Deller , Thomas Zimmermann , Javier Martinez Canillas , Boris Ostrovsky , Juergen Gross , Tom Rix , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH printk v2 24/38] xen: fbfront: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:46 +0206 Message-Id: <20221019145600.1282823-25-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since the console_lock is not being used for anything other than safe console list traversal, use srcu console list iteration instead. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/video/fbdev/xen-fbfront.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fb= front.c index 4d2694d904aa..2552c853c6c2 100644 --- a/drivers/video/fbdev/xen-fbfront.c +++ b/drivers/video/fbdev/xen-fbfront.c @@ -500,16 +500,18 @@ static int xenfb_probe(struct xenbus_device *dev, static void xenfb_make_preferred_console(void) { struct console *c; + int cookie; =20 if (console_set_on_cmdline) return; =20 - console_lock(); - for_each_console(c) { + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(c) { if (!strcmp(c->name, "tty") && c->index =3D=3D 0) break; } - console_unlock(); + console_srcu_read_unlock(cookie); + if (c) { unregister_console(c); c->flags |=3D CON_CONSDEV; --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03F78C4332F for ; Wed, 19 Oct 2022 15:07:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231237AbiJSPHK (ORCPT ); Wed, 19 Oct 2022 11:07:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231754AbiJSPFq (ORCPT ); Wed, 19 Oct 2022 11:05:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DACD4BE38; Wed, 19 Oct 2022 07:59:24 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vk9lLFSPw7DVFHn+Ltr9+ux4PzL45JriVQ+GTbz1WOY=; b=qy+XfEMThEbkLnrE1n36Z2pN+sVWm/xcWaaykneLdYt/vpE15mr9kwHlg/KLo+RWPWYf34 etPdErRihRuc+qZDB4lMGkJwkzOj0k873ip2RAnXf1ME6l4C75Nr7d+ZfLt0A0Xix765FH uOFeEgTaLBDP2HXzMyNMjWIC6zZ5DT5w5YwqCIu/1LYCInpQWEgjFfzVpFkk5Po66g2mEg NgEYb4GBaW4tD2U/AaebbabvrhjAUfC3V7esyJ4gKfuPnB8m9poV9ANs+Oggu69i9E/XY4 u16HcZa6/YcQ4gML73ZuMD0kDTA/mUUFqcAiH6w2xMHdUNjXCQYt02KOINdzng== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vk9lLFSPw7DVFHn+Ltr9+ux4PzL45JriVQ+GTbz1WOY=; b=Bczhayh0iGG8icRI55cYRrg7pJAHOfB2u8QZ/VTPoePhI61+DqIcsXd3xFHatJNL5JU+gj 3w0K/ax5IwNRZjBw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH printk v2 25/38] proc: consoles: document console_lock usage Date: Wed, 19 Oct 2022 17:01:47 +0206 Message-Id: <20221019145600.1282823-26-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- fs/proc/consoles.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c index cf2e0788f9c7..32512b477605 100644 --- a/fs/proc/consoles.c +++ b/fs/proc/consoles.c @@ -63,6 +63,14 @@ static void *c_start(struct seq_file *m, loff_t *pos) struct console *con; loff_t off =3D 0; =20 + /* + * Stop console printing because the device() callback may + * assume the console is not within its write() callback. + * + * 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++ =3D=3D *pos) --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86918C4332F for ; Wed, 19 Oct 2022 15:07:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230527AbiJSPHG (ORCPT ); Wed, 19 Oct 2022 11:07:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbiJSPFp (ORCPT ); Wed, 19 Oct 2022 11:05:45 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9DCD6573 for ; Wed, 19 Oct 2022 07:59:25 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l6JL8Q05OijoTEvKKyIiYa7K6VvZeDLREPexuqG68w4=; b=2lE2ZSVvaLYxX/mxts/imwzBNHAp8IFSDC/ai7lkxP1zyF6vpMFV8KAaG0pwB+zKzWkutn BNZQsjhTA+fE9mUGf/9zLZQuPNRIBu0owJpd7GDzfuULoEKri5Ic8olH4bE1eI5Rf1CKGy vTs3ThAfna4xN6EPjQmcBVcPNNwb7z99UsM+MaDiSMsHRWQQdQDukhcxIu7T4tOZ2TYmxg Bfdt5cy+/S+IRAvC/LS6NYxQYe0e79/FQQRYb/Mcd8jS8qxWB1iuXQe85SqXEhXYqiH8j4 +8mgUokSmCQOtAKhWeO3fUlqU5Flbi2cC2akX0Xw1B69Gv1ldKxWWm+8ITOUfQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l6JL8Q05OijoTEvKKyIiYa7K6VvZeDLREPexuqG68w4=; b=CQZkI2DXDnPwDZmhG2PVbvPciqqo6PQ6K7EPwjaFXRMKTNR/ZrE840g4rZSpD8aFVitZok a6Wx9DhxTm9LofBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Luis Chamberlain , Aaron Tomlin , kgdb-bugreport@lists.sourceforge.net Subject: [PATCH printk v2 26/38] kdb: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:48 +0206 Message-Id: <20221019145600.1282823-27-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Guarantee safe iteration of the console list by using SRCU. Signed-off-by: John Ogness --- kernel/debug/kdb/kdb_io.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 550fe8b456ec..5c0bd93c3574 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -545,6 +545,7 @@ static void kdb_msg_write(const char *msg, int msg_len) { struct console *c; const char *cp; + int cookie; int len; =20 if (msg_len =3D=3D 0) @@ -558,7 +559,8 @@ static void kdb_msg_write(const char *msg, int msg_len) cp++; } =20 - for_each_console(c) { + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(c) { if (!console_is_enabled(c)) continue; if (c =3D=3D dbg_io_ops->cons) @@ -577,6 +579,7 @@ static void kdb_msg_write(const char *msg, int msg_len) --oops_in_progress; touch_nmi_watchdog(); } + console_srcu_read_unlock(cookie); } =20 int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A779C4332F for ; Wed, 19 Oct 2022 15:07:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229912AbiJSPH3 (ORCPT ); Wed, 19 Oct 2022 11:07:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230430AbiJSPFr (ORCPT ); Wed, 19 Oct 2022 11:05:47 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F823220FF for ; Wed, 19 Oct 2022 07:59:28 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dg+eirxPEtXsZsT+nvxwn7klIpJXP2S7/lYWcLQsq5o=; b=MPYjmlBAQJxd8Rggng1mxW4di7b7xYOCjLNGRWpjRItXh3zWEx5mIiT5FQKnOr3++nqdFC pe86OdsADSBSH5eHo+UuSujM5JBEBpxz4EqDYayBdbpNcMLU9lC9OlX+CxEuViL3w0XxBH xw8pxjWFvUNr5Edl/oW9ZbygohqM9mxtghTUvuuRVvuUhF+m9H0bWLFljDXTwz8k7NuXOO sCTinHr3ebMbna/ZdTfsspODBgffQYwaNnL2PKRKsQR5J7KHns5Ztl30N8PQHMgTWj18rj 6HnkVcBl5OkAIL3PZyV8kgLNYcAjsfCjNaihlBxF2F8vGFgwMhFh9yuFifCIOQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dg+eirxPEtXsZsT+nvxwn7klIpJXP2S7/lYWcLQsq5o=; b=EtIY4tyi7hLpay8rDK+lcQKRKX8CIAg4otKaMkH3lPH6wnLHsrvZ4XcHsVGirSMNMsusC9 780jjF0WOKRvUkDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 27/38] printk: console_flush_all: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:49 +0206 Message-Id: <20221019145600.1282823-28-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Guarantee safe iteration of the console list by using SRCU. Note that in the case of a handover, the SRCU read lock is also released. This is documented in the function description and as comments in the code. It is a bit tricky, but this preserves the lockdep lock ordering for the context handing over the console_lock: console_lock() | mutex_acquire(&console_lock_dep_map) <-- console lock | console_unlock() | console_flush_all() | | srcu_read_lock(&console_srcu) <-- srcu lock | | console_emit_next_record() | | | console_lock_spinning_disable_and_check() | | | | srcu_read_unlock(&console_srcu) <-- srcu unlock | | | | mutex_release(&console_lock_dep_map) <-- console unlock Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 7ff2fc75fc3b..c4d5d58b5977 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1851,7 +1851,7 @@ static void console_lock_spinning_enable(void) * * Return: 1 if the lock rights were passed, 0 otherwise. */ -static int console_lock_spinning_disable_and_check(void) +static int console_lock_spinning_disable_and_check(int cookie) { int waiter; =20 @@ -1870,6 +1870,12 @@ static int console_lock_spinning_disable_and_check(v= oid) =20 spin_release(&console_owner_dep_map, _THIS_IP_); =20 + /* + * Preserve lockdep lock ordering. Release the SRCU read lock before + * releasing the console_lock. + */ + console_srcu_read_unlock(cookie); + /* * Hand off console_lock to waiter. The waiter will perform * the up(). After this, the waiter is the console_lock owner. @@ -2353,7 +2359,7 @@ static ssize_t msg_print_ext_body(char *buf, size_t s= ize, char *text, size_t text_len, struct dev_printk_info *dev_info) { return 0; } static void console_lock_spinning_enable(void) { } -static int console_lock_spinning_disable_and_check(void) { return 0; } +static int console_lock_spinning_disable_and_check(int cookie) { return 0;= } static void call_console_driver(struct console *con, const char *text, siz= e_t len, char *dropped_text) { @@ -2695,8 +2701,8 @@ static void __console_unlock(void) * DROPPED_TEXT_MAX. Otherwise @dropped_text must be NULL. * * @handover will be set to true if a printk waiter has taken over the - * console_lock, in which case the caller is no longer holding the - * console_lock. Otherwise it is set to false. + * console_lock, in which case the caller is no longer holding both the + * console_lock and the SRCU read lock. Otherwise it is set to false. * * Returns false if the given console has no next record to print, otherwi= se * true. @@ -2704,7 +2710,7 @@ static void __console_unlock(void) * Requires the console_lock. */ static bool console_emit_next_record(struct console *con, char *text, char= *ext_text, - char *dropped_text, bool *handover) + char *dropped_text, bool *handover, int cookie) { static int panic_console_dropped; struct printk_info info; @@ -2764,7 +2770,7 @@ static bool console_emit_next_record(struct console *= con, char *text, char *ext_ =20 con->seq++; =20 - *handover =3D console_lock_spinning_disable_and_check(); + *handover =3D console_lock_spinning_disable_and_check(cookie); printk_safe_exit_irqrestore(flags); skip: return true; @@ -2801,6 +2807,7 @@ static bool console_flush_all(bool do_cond_resched, u= 64 *next_seq, bool *handove bool any_usable =3D false; struct console *con; bool any_progress; + int cookie; =20 *next_seq =3D 0; *handover =3D false; @@ -2808,7 +2815,8 @@ static bool console_flush_all(bool do_cond_resched, u= 64 *next_seq, bool *handove do { any_progress =3D false; =20 - for_each_console(con) { + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(con) { bool progress; =20 if (!console_is_usable(con)) @@ -2819,12 +2827,17 @@ static bool console_flush_all(bool do_cond_resched,= u64 *next_seq, bool *handove /* Extended consoles do not print "dropped messages". */ progress =3D console_emit_next_record(con, &text[0], &ext_text[0], NULL, - handover); + handover, cookie); } else { progress =3D console_emit_next_record(con, &text[0], NULL, &dropped_text[0], - handover); + handover, cookie); } + + /* + * If a handover has occurred, the SRCU read lock + * is already released. + */ if (*handover) return false; =20 @@ -2838,14 +2851,19 @@ static bool console_flush_all(bool do_cond_resched,= u64 *next_seq, bool *handove =20 /* Allow panic_cpu to take over the consoles safely. */ if (abandon_console_lock_in_panic()) - return false; + goto abandon; =20 if (do_cond_resched) cond_resched(); } + console_srcu_read_unlock(cookie); } while (any_progress); =20 return any_usable; + +abandon: + console_srcu_read_unlock(cookie); + return false; } =20 /** --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22A26C4332F for ; Wed, 19 Oct 2022 15:05:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231562AbiJSPFy (ORCPT ); Wed, 19 Oct 2022 11:05:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbiJSPEm (ORCPT ); Wed, 19 Oct 2022 11:04:42 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4AED17A00F for ; Wed, 19 Oct 2022 07:59:11 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EqMbZeBSwCTLR7jNGQqhFOnz+Wzb4xZRR+OQHg2ho6o=; b=lobQdIkShxdMxRZEwTiKHKRdYrav0E98bLb9pr2dQOcNULPLucAZSh3RnXK47pdlrnRy7e rKvaMi2imL2d8ki0pJMqOXyRXTfCb+ul8uXBYGuHo7GwL49QRSx2L9VK1XBQJjs6yP2zwb tOnmcTHkIw9Qp1vNXr9lSiMYbFGeETSZwSlVVvooCwWgx2rrd9VrlCjUbcosHABwVQxDAH E71fyzXayt5EED6w2RBkiifmqE+ntg+B5mJ4fxLHsz6pTtFDVtbbKrjvpFfXmyj4++KFLZ y4R29TPq7RP6erhqm2MBnwMRn01T7DiJXs/bj+D5Af6g9rFIHk5t0eTS4nhrww== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EqMbZeBSwCTLR7jNGQqhFOnz+Wzb4xZRR+OQHg2ho6o=; b=hLMMc2KrQ3G15NfP/J2YPlS4qSK28nPxhtnXaVM7oNoI0MAE7GvWTiYbgzRVHjyLUFvKEt Lp1mlmci6t0st2CQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 28/38] printk: console_unblank: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:50 +0206 Message-Id: <20221019145600.1282823-29-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use srcu console list iteration for console list traversal. Document why the console_lock is still necessary. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index c4d5d58b5977..0c37ab208395 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2948,10 +2948,14 @@ EXPORT_SYMBOL(console_conditional_schedule); void console_unblank(void) { struct console *c; + int cookie; =20 /* - * console_unblank can no longer be called in interrupt context unless - * oops_in_progress is set to 1.. + * Stop console printing because the unblank() callback may + * assume the console is not within its write() callback. + * + * If @oops_in_progress is set, this may be an atomic context. + * In that case, attempt a trylock as best-effort. */ if (oops_in_progress) { if (down_trylock_console_sem() !=3D 0) @@ -2961,9 +2965,14 @@ void console_unblank(void) =20 console_locked =3D 1; console_may_schedule =3D 0; - for_each_console(c) + + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(c) { if (console_is_enabled(c) && c->unblank) c->unblank(); + } + console_srcu_read_unlock(cookie); + console_unlock(); =20 if (!oops_in_progress) --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E584C433FE for ; Wed, 19 Oct 2022 15:07:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231725AbiJSPHO (ORCPT ); Wed, 19 Oct 2022 11:07:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231948AbiJSPFr (ORCPT ); Wed, 19 Oct 2022 11:05:47 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 169E0201AE for ; Wed, 19 Oct 2022 07:59:27 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s9ex8lzRPv2fLvIIrbPhNI07gh3HOaIObjp42xbSQhM=; b=dV8eeJVkJqnYI4Tntl1R3l7jZCsG9aTkqgpLBzaep2kY0IpfWQ7AkgrFxuD0Aa3hlViZnt ZZRK5iRTG84EysIrt3V4DA4GmMpvfrR4x9fqaPMgBv4GmPgnJmb14MJFSFl0uFVMr9q71p oSDQNSWKNoB8WJZ8deTwEu0BfGAlvwRs+SgN/tNjuqT+X5J1YgCdw6HanP40357h5g2B4A 6YNAFBkSg15DyUCvdL3htD/Ho6Tf0MCwFafxoCOOfoRR0aeGRkfoFItU243LcFdgK+9JP1 hERXGmQ7msAr35hPgWEk40C+RcKtWqBob98VeE5EsrIjw0MHnYs/pQEyU7BwPw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s9ex8lzRPv2fLvIIrbPhNI07gh3HOaIObjp42xbSQhM=; b=3QTHJMOIlL3X1RHmjXFjR8ZUj0J6xFSmlHeAL+ESJ8836arfruLwiyCsruxtdvCScpYlAN bsHq2FAjEV58YVCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 29/38] printk: console_flush_on_panic: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:51 +0206 Message-Id: <20221019145600.1282823-30-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With SRCU it is now safe to traverse the console list, even if the console_trylock() failed. However, overwriting console->seq when console_trylock() failed is still an issue. Switch to SRCU iteration and document remaining issue with console->seq. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 0c37ab208395..e478cb92e7ba 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2998,21 +2998,22 @@ void console_flush_on_panic(enum con_flush_mode mod= e) console_may_schedule =3D 0; =20 if (mode =3D=3D CONSOLE_REPLAY_ALL) { - struct hlist_node *tmp; struct console *c; + int cookie; u64 seq; =20 seq =3D prb_first_valid_seq(prb); - /* - * 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) + + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(c) { + /* + * If the above console_trylock() failed, this is an + * unsynchronized assignment. But in that case, the + * kernel is in "hope and pray" mode anyway. + */ c->seq =3D seq; + } + console_srcu_read_unlock(cookie); } console_unlock(); } --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B1B6C43219 for ; Wed, 19 Oct 2022 15:06:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232010AbiJSPGN (ORCPT ); Wed, 19 Oct 2022 11:06:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231755AbiJSPF0 (ORCPT ); Wed, 19 Oct 2022 11:05:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98472153835 for ; Wed, 19 Oct 2022 07:59:11 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kDZ6pRjPX3M/aNWQNadxCVy2Ern3rX+BUG+UFbJRacE=; b=vZ++W4VE4AQQNPASVoIgQEv9QFic6MvrPxW9APkzUtJQWlJmpTRafFJlXDcuEug7iTrgAr Q68gq3cOHoYxad58FRzrhkyde3adxE+hwep+0uWLN2/qDedGH7Q7xx1AmRkMh/mK0VoNFv nMsU91BskHVFEannoZwBQZA7Z1nTnh3feCTKpKo/0ocU/OTDbu3KpsM2BSapW5B13XOBk4 XEBAiQvwiu+9W09sKCUpa/szF8Xe08dS43bdhg5WwWcE38dtMvjprltTZX5kT84uDgwvUo ks5/LYqdhSVgBppHnyQB/LpicRRiUXa15t6U5CopyRfzugDG8cvli1d2t8CL9Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kDZ6pRjPX3M/aNWQNadxCVy2Ern3rX+BUG+UFbJRacE=; b=zlEFWao8VJz19cq1+qrdLmGFpWXLPFk4nyCnR24oE/kjsnhlT2viimgpJo1H5sm4DIHUYs PFn0fdw64FnnTOBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 30/38] printk: console_device: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:52 +0206 Message-Id: <20221019145600.1282823-31-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use srcu console list iteration for console list traversal. Document why the console_lock is still necessary. Signed-off-by: John Ogness --- kernel/printk/printk.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e478cb92e7ba..410ad9d5649c 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3025,15 +3025,24 @@ struct tty_driver *console_device(int *index) { struct console *c; struct tty_driver *driver =3D NULL; + int cookie; =20 + /* + * Stop console printing because the device() callback may + * assume the console is not within its write() callback. + */ console_lock(); - for_each_console(c) { + + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(c) { if (!c->device) continue; driver =3D c->device(c, index); if (driver) break; } + console_srcu_read_unlock(cookie); + console_unlock(); return driver; } --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D5C0C4332F for ; Wed, 19 Oct 2022 15:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232213AbiJSPHd (ORCPT ); Wed, 19 Oct 2022 11:07:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230455AbiJSPFs (ORCPT ); Wed, 19 Oct 2022 11:05:48 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EAA2205CC for ; Wed, 19 Oct 2022 07:59:28 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f12nNYu1o1nheACyaBAz3IPbjPiOwdCr955JKGftNi0=; b=gEk/56dyVdJxDt/J7kVgFStcKjvZrGcgIOwQYk0XwQKdK8FsV0Y9dvc9y2PrxlYjtuLQT3 fSJL3lf/BuDtIhc+l6cIXdtEsuXqSJu6EpaxJSdLt15yliOrYrRp1+h7ASkvcNnkIleiOK WZ+Tm++vLlUFSJX9OqsxsxRrd4s4tFKvj3VUqZdNFTfb3Xhi8xUPk8f1Hr6A5xGkJiRoR+ A2sCQpxxeuWpEagnAVMwC/rga5HRcHoOkPCaPZzrNI1r1Nzz5TeNQX3rrKHlEpNHJHjOfV JKp1j4/HoOOs0hPNpCf8W0nyoa5ouc48VUQum9WrHC4viYimonEL+j+iP2L95A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f12nNYu1o1nheACyaBAz3IPbjPiOwdCr955JKGftNi0=; b=Hy5IF74AngV6AgkVUBSfbWawZSbLHUumgqjJi1aW8Es4tyHbxXvp1fWUJHJOyfgmdOtGqL +/HMreGlQbQCBDAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 31/38] printk: register_console: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:53 +0206 Message-Id: <20221019145600.1282823-32-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use srcu console list iteration for console list traversal. Now the traversal at the beginning of register_console() is safe. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 410ad9d5649c..809c43e596d8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3188,20 +3188,23 @@ void register_console(struct console *newcon) struct console *con; bool bootcon_enabled =3D false; bool realcon_enabled =3D false; + int cookie; int err; =20 - for_each_console(con) { + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(con) { if (WARN(con =3D=3D newcon, "console '%s%d' already registered\n", - con->name, con->index)) + con->name, con->index)) { + console_srcu_read_unlock(cookie); return; - } + } =20 - for_each_console(con) { if (con->flags & CON_BOOT) bootcon_enabled =3D true; else realcon_enabled =3D true; } + console_srcu_read_unlock(cookie); =20 /* Do not register boot consoles when there already is a real one. */ if (newcon->flags & CON_BOOT && realcon_enabled) { --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C36BC433FE for ; Wed, 19 Oct 2022 15:06:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231903AbiJSPGZ (ORCPT ); Wed, 19 Oct 2022 11:06:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbiJSPFj (ORCPT ); Wed, 19 Oct 2022 11:05:39 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9676F1C2EB3 for ; Wed, 19 Oct 2022 07:59:12 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dEfLDywQMbLFMveMIU5ztmggdkM8VKhqRGZUba4knEA=; b=tvGWDuIbnMg81nElIpNQcHDQap243WbjOFmLBBssheT3WAcSo/uy+6Y/V1xLaZOuvbqvoP HGWUcc6muabTL3JhrtCL2O+nHHlD1uN8YVPQtxkig8QS8ESpv/V3WRMZA7Rxl4IIndi7hD szwUUd+8jDai9nm38yOHM416UH1skAKg+0nBI9frWXFXAUAQs4OkB5nXnBEBkEVbgTC1Rk qZ92WfVER0K26YNlgAgm71hLsBMCs+JmDbBTQmx0vFv52LhECZBDo3JbTp3eTUIpFu0dzy 5cZYtV6xxBzm2eo129s+wAAZgFZr0dg9IA7FHp+XlWd3FtdHSpugj1GkLYE18g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dEfLDywQMbLFMveMIU5ztmggdkM8VKhqRGZUba4knEA=; b=zJjK8oc9MpyW+AN+CgjCFO34fO7H6UGzAb1JPwNkz17MJ2pO3wmfGFId0+ak7aOpZp8Q+5 uWrTfF0L395aPXBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 32/38] printk: __pr_flush: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:54 +0206 Message-Id: <20221019145600.1282823-33-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use srcu console list iteration for console list traversal. Document why the console_lock is still necessary. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 809c43e596d8..2faa6e3e2fb8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3454,6 +3454,7 @@ static bool __pr_flush(struct console *con, int timeo= ut_ms, bool reset_on_progre struct console *c; u64 last_diff =3D 0; u64 printk_seq; + int cookie; u64 diff; u64 seq; =20 @@ -3464,9 +3465,15 @@ static bool __pr_flush(struct console *con, int time= out_ms, bool reset_on_progre for (;;) { diff =3D 0; =20 + /* + * Hold the console_lock to guarantee safe access to + * console->seq and to prevent changes to @console_suspended + * until all consoles have been processed. + */ console_lock(); =20 - for_each_console(c) { + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(c) { if (con && con !=3D c) continue; if (!console_is_usable(c)) @@ -3475,6 +3482,7 @@ static bool __pr_flush(struct console *con, int timeo= ut_ms, bool reset_on_progre if (printk_seq < seq) diff +=3D seq - printk_seq; } + console_srcu_read_unlock(cookie); =20 /* * If consoles are suspended, it cannot be expected that they --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B914C433FE for ; Wed, 19 Oct 2022 15:07:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231965AbiJSPHW (ORCPT ); Wed, 19 Oct 2022 11:07:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230409AbiJSPFr (ORCPT ); Wed, 19 Oct 2022 11:05:47 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 259E42FFFA for ; Wed, 19 Oct 2022 07:59:28 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BcRSHDvvNo4h9AdyzONtntflPRCM65zBDjJsA3cL8rk=; b=3AWz2y6+1k39Qj6Orp5DwOJpZBtwPBMP63eraBDBEEUg437H+y+VYXgKoH9orU/SwQDGLU 06R/Lg+9+gV+G6DSMSlPyThKh8IWtZh/b43yUs60YI9x5Aq/QYZPclNqeSYqa8O2qovVRV 7/gu1pKhqmDsprIbI1+hsU5FoG0FOfzUURCDxKiHetLklfjLBP1LTxW2WvhJ9z4+zKWji3 tgjKytTz6ySvnqr15SPuktV4b5GI7pZo1dPB6vCZKbgEqk5+IaFkLzfG/AW5UjO0AD6gSi 5mb9w4Tsxx5XDz0L3BY0zgVL5qerQDYGxg22CjiNbu4slbsmj1kKOPNkR1S2lA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BcRSHDvvNo4h9AdyzONtntflPRCM65zBDjJsA3cL8rk=; b=InuA5nejuGJ/h2WMXNzVlmQY/B0egmLyfHHBCPaaVQ1w3jLH75R9dCp2uDasRu0WaqbXca /BZkfNms60ta+KBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 33/38] printk: introduce console_list_lock Date: Wed, 19 Oct 2022 17:01:55 +0206 Message-Id: <20221019145600.1282823-34-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently there exist races in console_register(), where the types of registered consoles are checked (without holding the console_lock) and then after acquiring the console_lock, it is assumed that the list has not changed. Also, some code that performs console_unregister() make similar assumptions. Introduce a console_list_lock to provide full synchronization for any console list changes. The console_list_lock also provides synchronization for updates to console->flags. Note that one of the various responsibilities of the console_lock is also intended to provide this synchronization. Later changes will update call sites relying on the console_lock for this purpose. Once all call sites have been updated, the console_lock will be relieved of synchronizing console_list and console->flags updates. Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- include/linux/console.h | 20 ++++++++-- kernel/printk/printk.c | 82 +++++++++++++++++++++++++++++++++++------ 2 files changed, 88 insertions(+), 14 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 60195cd086dc..bf1e8136424a 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -159,8 +159,12 @@ struct console { }; =20 #ifdef CONFIG_LOCKDEP +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_list_lock_held(void) +{ +} static inline bool console_srcu_read_lock_is_held(void) { return 1; @@ -170,6 +174,9 @@ static inline bool console_srcu_read_lock_is_held(void) extern int console_srcu_read_lock(void); extern void console_srcu_read_unlock(int cookie); =20 +extern void console_list_lock(void) __acquires(console_mutex); +extern void console_list_unlock(void) __releases(console_mutex); + extern struct hlist_head console_list; =20 /** @@ -206,10 +213,17 @@ static inline bool console_is_enabled(const struct co= nsole *con) hlist_for_each_entry_srcu(con, &console_list, node, \ console_srcu_read_lock_is_held()) =20 -/* - * for_each_console() allows you to iterate on each console +/** + * for_each_console() - Iterator over registered consoles + * @con: struct console pointer used as loop cursor + * + * The console list and all struct console fields are immutable while + * iterating. + * + * Requires console_list_lock to be held. */ -#define for_each_console(con) \ +#define for_each_console(con) \ + lockdep_assert_console_list_lock_held(); \ hlist_for_each_entry(con, &console_list, node) =20 extern int console_set_on_cmdline; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 2faa6e3e2fb8..3615ee6d68fd 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -78,6 +78,9 @@ EXPORT_SYMBOL(ignore_console_lock_warning); int oops_in_progress; EXPORT_SYMBOL(oops_in_progress); =20 +/* console_mutex protects console_list and console->flags updates. */ +static DEFINE_MUTEX(console_mutex); + /* * console_sem protects console_list and console->flags updates, and also * provides serialization for access to the entire console driver system. @@ -104,6 +107,11 @@ static struct lockdep_map console_lock_dep_map =3D { .name =3D "console_lock" }; =20 +void lockdep_assert_console_list_lock_held(void) +{ + lockdep_assert_held(&console_mutex); +} + bool console_srcu_read_lock_is_held(void) { return srcu_read_lock_held(&console_srcu); @@ -225,6 +233,40 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table,= int write, } #endif /* CONFIG_PRINTK && CONFIG_SYSCTL */ =20 +/** + * console_list_lock - Lock the console list + * + * For console list or console->flags updates + */ +void console_list_lock(void) +{ +#ifdef CONFIG_DEBUG_LOCK_ALLOC + /* + * In unregister_console(), synchronize_srcu() is called with the + * console_list_lock held. Therefore it is not allowed that the + * console_list_lock is taken with the srcu_lock held. + * + * Whether or not this context is in the read-side critical section + * can only be detected if the appropriate debug options are enabled. + */ + WARN_ON_ONCE(debug_lockdep_rcu_enabled() && + srcu_read_lock_held(&console_srcu)); +#endif + mutex_lock(&console_mutex); +} +EXPORT_SYMBOL(console_list_lock); + +/** + * console_list_unlock - Unlock the console list + * + * Counterpart to console_list_lock() + */ +void console_list_unlock(void) +{ + mutex_unlock(&console_mutex); +} +EXPORT_SYMBOL(console_list_unlock); + /** * console_srcu_read_lock - Register a new reader for the * SRCU-protected console list @@ -3055,9 +3097,11 @@ struct tty_driver *console_device(int *index) void console_stop(struct console *console) { __pr_flush(console, 1000, true); + console_list_lock(); console_lock(); console->flags &=3D ~CON_ENABLED; console_unlock(); + console_list_unlock(); =20 /* Ensure that all SRCU list walks have completed */ synchronize_srcu(&console_srcu); @@ -3066,9 +3110,11 @@ EXPORT_SYMBOL(console_stop); =20 void console_start(struct console *console) { + console_list_lock(); console_lock(); console->flags |=3D CON_ENABLED; console_unlock(); + console_list_unlock(); __pr_flush(console, 1000, true); } EXPORT_SYMBOL(console_start); @@ -3164,6 +3210,8 @@ static void try_enable_default_console(struct console= *newcon) #define console_first() \ hlist_entry(console_list.first, struct console, node) =20 +static int unregister_console_locked(struct console *console); + /* * The console driver calls this routine during kernel initialization * to register the console printing procedure with printk() and to @@ -3188,15 +3236,14 @@ void register_console(struct console *newcon) struct console *con; bool bootcon_enabled =3D false; bool realcon_enabled =3D false; - int cookie; int err; =20 - cookie =3D console_srcu_read_lock(); - for_each_console_srcu(con) { + console_list_lock(); + + for_each_console(con) { if (WARN(con =3D=3D newcon, "console '%s%d' already registered\n", con->name, con->index)) { - console_srcu_read_unlock(cookie); - return; + goto unlock; } =20 if (con->flags & CON_BOOT) @@ -3204,13 +3251,12 @@ void register_console(struct console *newcon) else realcon_enabled =3D true; } - console_srcu_read_unlock(cookie); =20 /* Do not register boot consoles when there already is a real one. */ if (newcon->flags & CON_BOOT && realcon_enabled) { pr_info("Too late to register bootconsole %s%d\n", newcon->name, newcon->index); - return; + goto unlock; } =20 /* @@ -3241,7 +3287,7 @@ void register_console(struct console *newcon) =20 /* printk() messages are not printed to the Braille console. */ if (err || newcon->flags & CON_BRL) - return; + goto unlock; =20 /* * If we have a bootconsole, and are switching to a real console, @@ -3304,13 +3350,15 @@ void register_console(struct console *newcon) =20 hlist_for_each_entry_safe(con, tmp, &console_list, node) { if (con->flags & CON_BOOT) - unregister_console(con); + unregister_console_locked(con); } } +unlock: + console_list_unlock(); } EXPORT_SYMBOL(register_console); =20 -int unregister_console(struct console *console) +static int unregister_console_locked(struct console *console) { int res; =20 @@ -3362,6 +3410,16 @@ int unregister_console(struct console *console) console_unlock(); return res; } + +int unregister_console(struct console *console) +{ + int res; + + console_list_lock(); + res =3D unregister_console_locked(console); + console_list_unlock(); + return res; +} EXPORT_SYMBOL(unregister_console); =20 /* @@ -3414,6 +3472,7 @@ static int __init printk_late_init(void) struct console *con; int ret; =20 + console_list_lock(); hlist_for_each_entry_safe(con, tmp, &console_list, node) { if (!(con->flags & CON_BOOT)) continue; @@ -3431,9 +3490,10 @@ static int __init printk_late_init(void) */ pr_warn("bootconsole [%s%d] uses init memory and must be disabled even = before the real one is ready\n", con->name, con->index); - unregister_console(con); + unregister_console_locked(con); } } + console_list_unlock(); =20 ret =3D cpuhp_setup_state_nocalls(CPUHP_PRINTK_DEAD, "printk:dead", NULL, console_cpu_notify); --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AB81C4332F for ; Wed, 19 Oct 2022 15:06:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231843AbiJSPGc (ORCPT ); Wed, 19 Oct 2022 11:06:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231172AbiJSPFj (ORCPT ); Wed, 19 Oct 2022 11:05:39 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09281125015; Wed, 19 Oct 2022 07:59:13 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FdvxHOKwRIeI8BiM8k+rYwU/Yx30rZAhLXmKb87AiP8=; b=YJM/Q8Y/iU41nYJhp3ruJ3GZbQPygcVKdQtdGfYKzTF62VPMx1mnPM9tcgyukJ54yaBxZA GVrkuBdRj36R50zyHRbByxcwzeIkJ2CitT346w2Db5zH5yWwwEieG+szD/pwmPecMyCI1h 0OEDEw9VNJtjb26YQe62EHk5Rwz/lbk5LQrNjCrzvDvUiIssEVgWHSJaoJO/87vO/A/kOf XaEI1oeCR6s/TkWDLLjt70+k/1a69wPsRy2nuUIWcbB/Vtekle1QbRVEcd04sjNyqVuA0D 1WVA1iDuqI9sMaCvV7EaPS+iAWUQOLFn2okif3uEEF9aGgVMzxDui9lC/dsqAA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FdvxHOKwRIeI8BiM8k+rYwU/Yx30rZAhLXmKb87AiP8=; b=8EnO9qClCf1jaZEbNBimixqghlBQ62awKnPSz1PmBmcugCl3Z+v0WMz2rs+IIgPUeCv/Ol Snw30DIMiYbGmfDw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk v2 34/38] serial: kgdboc: use console_list_lock instead of console_lock Date: Wed, 19 Oct 2022 17:01:56 +0206 Message-Id: <20221019145600.1282823-35-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" kgdboc_earlycon_init() uses the console_lock to ensure that no consoles are unregistered until the kgdboc_earlycon is setup. The console_list_lock should be used instead because list synchronization repsponsibility will be removed from the console_lock in a later change. Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/serial/kgdboc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index 48000666789a..0d85596aebe2 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -547,13 +547,13 @@ static int __init kgdboc_earlycon_init(char *opt) */ =20 /* - * Hold the console_lock to guarantee that no consoles are + * Hold the console_list_lock to guarantee that no consoles are * unregistered until the kgdboc_earlycon setup is complete. * Trapping the exit() callback relies on exit() not being * called until the trap is setup. This also allows safe * traversal of the console list. */ - console_lock(); + console_list_lock(); for_each_console(con) { if (con->write && con->read && (console_is_enabled(con) || (con->flags & CON_BOOT)) && @@ -595,7 +595,7 @@ static int __init kgdboc_earlycon_init(char *opt) } =20 unlock: - console_unlock(); + console_list_unlock(); =20 /* Non-zero means malformed option so we always return zero */ return 0; --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF145C433FE for ; Wed, 19 Oct 2022 15:06:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232091AbiJSPGs (ORCPT ); Wed, 19 Oct 2022 11:06:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231844AbiJSPFk (ORCPT ); Wed, 19 Oct 2022 11:05:40 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BBC729359 for ; Wed, 19 Oct 2022 07:59:16 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4O5jxh5GAGfpdp5oJs484DSsKK6l20yyCIa5aoPwGXk=; b=iTFnKkvnbpZV48iaml8m+GkgSuO5UhuOPyuwAZtb2zPnRQi7Q9F4bM6+9lA4A7g8iLXRPd YskL9UUUkyQiWaD7JtvivltiLNH8BP8o6m91bP4hX2T8rN8aIfG2pRKSjDnwavHqzgJPPV nrYAxW/rTJ6goH7HYUGv9GT708RbC4YLBn8W9dJ8z3JyuVftTLtv+1ZS/5rmxKUb9ktAUm BgVLY8s9nkfmIpUG/QSKgxDcIcLYqhI4RlNOE8A1GA41IpZ+VNXZl9Gg4FBPnbWvrjYEqb U0yyXtmvo+SVOmto2TaiY3F5ePVRNqLXYpMZ3YduuR2WllgLWVcBt1SII0WNoQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4O5jxh5GAGfpdp5oJs484DSsKK6l20yyCIa5aoPwGXk=; b=Fu+pjLGgV9HHXN5WM5d4ymQB19nzJZDTwV/1OFZhHc0jWJPZqGp6+7wJwb+s9hVvpKQ2+6 kYID/meOJJNW9SAg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH printk v2 35/38] tty: tty_io: use console_list_lock for list synchronization Date: Wed, 19 Oct 2022 17:01:57 +0206 Message-Id: <20221019145600.1282823-36-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" show_cons_active() uses the console_lock to gather information on registered consoles. It requires that no consoles are unregistered until it is finished. The console_list_lock should be used because list synchronization repsponsibility will be removed from the console_lock in a later change. Note, the console_lock is still needed to stop console printing. Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/tty_io.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 333579bfa335..46a0e3c5c3a5 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3527,14 +3527,12 @@ static ssize_t show_cons_active(struct device *dev, ssize_t count =3D 0; =20 /* - * Hold the console_lock to guarantee that no consoles are + * Hold the console_list_lock to guarantee that no consoles are * unregistered until all console processing is complete. * This also allows safe traversal of the console list. - * - * Stop console printing because the device() callback may - * assume the console is not within its write() callback. */ - console_lock(); + console_list_lock(); + for_each_console(c) { if (!c->device) continue; @@ -3546,6 +3544,12 @@ static ssize_t show_cons_active(struct device *dev, if (i >=3D ARRAY_SIZE(cs)) break; } + + /* + * Stop console printing because the device() callback may + * assume the console is not within its write() callback. + */ + console_lock(); while (i--) { int index =3D cs[i]->index; struct tty_driver *drv =3D cs[i]->device(cs[i], &index); @@ -3561,6 +3565,8 @@ static ssize_t show_cons_active(struct device *dev, } console_unlock(); =20 + console_list_unlock(); + return count; } static DEVICE_ATTR(active, S_IRUGO, show_cons_active, NULL); --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2B4DC43217 for ; Wed, 19 Oct 2022 15:08:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232252AbiJSPIJ (ORCPT ); Wed, 19 Oct 2022 11:08:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231835AbiJSPGi (ORCPT ); Wed, 19 Oct 2022 11:06:38 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C213F36798; Wed, 19 Oct 2022 07:59:31 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191381; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M9ps/+3zFTTMX/Xw+H343+FOn0pASHbTafsRYfPyD80=; b=xryRBIthFWhP4UrwlfzbLHB1wneSnBcBBrCWGbfzhFtyZZ62blHFAAWadbR3RfJ0xiS3D8 E8G/EiTVA2QAo78BFXu4HLdwD+wAF6JL8ZZPT3fT3XiPQ0U3QnQkiqFxYtRNWpb8fxr2Cx A/Cmed+jZKcC1QRl0fM0J5BhpF3Ep4COPsunR9DMwyMVrS6nOyn1FZdHgAvIlS9jd3c3/u DNATXphbwlgI1vTSZ6DZy++PAOL/yQeAkH6xkw/VIyWpUi46a/OKZkof+PQOokG1dN51E3 ScxR1SESvRXx3+MDvobD2S55zRzzj6vOpkbNnDYcWKvXBeaZ6jqGRdPZWw68+w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191381; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M9ps/+3zFTTMX/Xw+H343+FOn0pASHbTafsRYfPyD80=; b=nK0TpZ0gm/hS4UwI6UaYUoHDooyjpXsBf4rDrK5NbkFeKSjWQqGLTzLJJFbqmldTgUwgZh deKrFqZ6DM/L2uDQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH printk v2 36/38] proc: consoles: use console_list_lock for list iteration Date: Wed, 19 Oct 2022 17:01:58 +0206 Message-Id: <20221019145600.1282823-37-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The console_lock is used in part to guarantee safe list iteration. The console_list_lock should be used because list synchronization repsponsibility will be removed from the console_lock in a later change. Note, the console_lock is still needed to stop console printing. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- fs/proc/consoles.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c index 32512b477605..77409b176569 100644 --- a/fs/proc/consoles.c +++ b/fs/proc/consoles.c @@ -33,7 +33,15 @@ static int show_console_dev(struct seq_file *m, void *v) if (con->device) { const struct tty_driver *driver; int index; + + /* + * Stop console printing because the device() callback may + * assume the console is not within its write() callback. + */ + console_lock(); driver =3D con->device(con, &index); + console_unlock(); + if (driver) { dev =3D MKDEV(driver->major, driver->minor_start); dev +=3D index; @@ -64,14 +72,11 @@ static void *c_start(struct seq_file *m, loff_t *pos) loff_t off =3D 0; =20 /* - * Stop console printing because the device() callback may - * assume the console is not within its write() callback. - * - * Hold the console_lock to guarantee safe traversal of the + * Hold the console_list_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(); + console_list_lock(); for_each_console(con) if (off++ =3D=3D *pos) break; @@ -89,7 +94,7 @@ static void *c_next(struct seq_file *m, void *v, loff_t *= pos) =20 static void c_stop(struct seq_file *m, void *v) { - console_unlock(); + console_list_unlock(); } =20 static const struct seq_operations consoles_op =3D { --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21238C433FE for ; Wed, 19 Oct 2022 15:07:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231446AbiJSPG7 (ORCPT ); Wed, 19 Oct 2022 11:06:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231894AbiJSPFn (ORCPT ); Wed, 19 Oct 2022 11:05:43 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87C3D2DC6 for ; Wed, 19 Oct 2022 07:59:21 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191381; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ERAmScBWw3AWOQd/N8KPYvjMNho4M2d8wqoVxvpkojg=; b=p7EHFUdVULSPTa08I7V4W4rGuOGZwbKXMbpmy7FQ/hM/Akq2VHbWOybQyOPaIOQrMynit4 ej7WV/9P69E8eZBOhLDiLJlrtilFtFK9XGJgoWlTrZNjwAdU/JWjcQgAlEaOPb4G1nWl5b TReEvqMia7ozppHpRIsh6OEWPdoTOkcPeJH4N8SEI0A/MzxlshaDMF13LQKP1TnMI+ubx9 Xl4NboHNjl6nuEPXtwS+kozYdOGmAF+ePdeob47Ak0wL6PRzU1obyGe39bWtW3Iy7oJVyD Vkv8yDL44DmJ8w3tppP5p/BE8zRaOFrxQ6dZE4JLY+ict0Hs+OTjbOcit2hpwA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191381; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ERAmScBWw3AWOQd/N8KPYvjMNho4M2d8wqoVxvpkojg=; b=XSBfRYfXfVmjl1gxZkSLwF2XwQJDPNi9TKXi2UryMFR1GEHWj2Cu4NTSvRskEHY/1hTm0t 8ZS0wYOq2I7A30BQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 37/38] printk: relieve console_lock of list synchronization duties Date: Wed, 19 Oct 2022 17:01:59 +0206 Message-Id: <20221019145600.1282823-38-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The console_list_lock provides synchronization for console list and console->flags updates. All call sites that were using the console_lock for this synchronization have either switched to use the console_list_lock or the SRCU list iterator. Remove console_lock usage for console list updates and console->flags updates. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 3615ee6d68fd..840d581c4b23 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -82,8 +82,8 @@ EXPORT_SYMBOL(oops_in_progress); static DEFINE_MUTEX(console_mutex); =20 /* - * console_sem protects console_list and console->flags updates, and also - * provides serialization for access to the entire console driver system. + * console_sem protects updates to console->seq and console_suspended, + * and also provides serialization for console printing. */ static DEFINE_SEMAPHORE(console_sem); HLIST_HEAD(console_list); @@ -2635,7 +2635,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 console_list. + * exclusive access to the console system. * * Can sleep, returns nothing. */ @@ -2655,7 +2655,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 console_list. + * access to the console system. * * returns 1 on success, and 0 on failure to acquire the lock. */ @@ -2911,8 +2911,7 @@ static bool console_flush_all(bool do_cond_resched, u= 64 *next_seq, bool *handove /** * console_unlock - unlock the console system * - * Releases the console_lock which the caller holds on the console system - * and the console driver list. + * Releases the console_lock which the caller holds on the console system. * * While the console_lock was held, console output may have been buffered * by printk(). If this is the case, console_unlock(); emits @@ -3098,9 +3097,7 @@ void console_stop(struct console *console) { __pr_flush(console, 1000, true); console_list_lock(); - console_lock(); console->flags &=3D ~CON_ENABLED; - console_unlock(); console_list_unlock(); =20 /* Ensure that all SRCU list walks have completed */ @@ -3111,9 +3108,7 @@ EXPORT_SYMBOL(console_stop); void console_start(struct console *console) { console_list_lock(); - console_lock(); console->flags |=3D CON_ENABLED; - console_unlock(); console_list_unlock(); __pr_flush(console, 1000, true); } @@ -3315,7 +3310,6 @@ void register_console(struct console *newcon) * Put this console in the list - keep the * preferred driver at the head of the list. */ - console_lock(); if (hlist_empty(&console_list)) { /* Ensure CON_CONSDEV is always set for the head. */ newcon->flags |=3D CON_CONSDEV; @@ -3329,7 +3323,6 @@ void register_console(struct console *newcon) } else { hlist_add_behind_rcu(&newcon->node, console_list.first); } - console_unlock(); =20 /* No need to synchronize SRCU here! */ =20 @@ -3370,8 +3363,6 @@ static int unregister_console_locked(struct console *= console) if (res > 0) return 0; =20 - console_lock(); - /* Disable it unconditionally */ console->flags &=3D ~CON_ENABLED; =20 @@ -3394,8 +3385,6 @@ static int unregister_console_locked(struct console *= console) if (!hlist_empty(&console_list) && console->flags & CON_CONSDEV) console_first()->flags |=3D CON_CONSDEV; =20 - console_unlock(); - /* Ensure that all SRCU list walks have completed */ synchronize_srcu(&console_srcu); =20 --=20 2.30.2 From nobody Tue Apr 7 20:48:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37B70C433FE for ; Wed, 19 Oct 2022 15:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231584AbiJSPIM (ORCPT ); Wed, 19 Oct 2022 11:08:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232066AbiJSPGi (ORCPT ); Wed, 19 Oct 2022 11:06:38 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A69479620; Wed, 19 Oct 2022 07:59:31 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191382; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aXcesGHiS9CJwBLB5AtQkJ+SjPh3MNkbA2I4bHFlwT4=; b=vyVdNsmDCOtZ1td7FZJE2kL0NFcmHJkDeb8tBWR6iDUAHMNtB/gaxUaCu7IOuYDjCtdTGf 7JMy3AFlQHUwJVxxWRF61DKsEUyqZRkxV7auxPl3IWWrfKeqXCbTFP1XCjq4+t36WbX9n3 Lk0u97wao4rNY5seMwaeTD9hMMmwwZAO7FNkBian35LLG7JI5kr+LIiauXac/JHyFLh0oS 0bab60tCRUjG95HHblokpeEUA2qyzG6Wp6FwAKRehYx7odX+BRLntV+unpa7brXAp90riX g0saBHF8isP/h2pPYkiVRR0qX2oN2XOyv2ogU5splu0VZKufFuAm+1ETP7yO7Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191382; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aXcesGHiS9CJwBLB5AtQkJ+SjPh3MNkbA2I4bHFlwT4=; b=3KenGGEQ+2eWZ5r+4AzHNAE//1dUZSpARbtG8UMeJGjl8XQGUV1nPPSymknxmfh1mJh3sK E+W71aY0Z0vk/3Bg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Helge Deller , Greg Kroah-Hartman , Javier Martinez Canillas , Thomas Zimmermann , Juergen Gross , Boris Ostrovsky , Tom Rix , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH printk v2 38/38] printk, xen: fbfront: create/use safe function for forcing preferred Date: Wed, 19 Oct 2022 17:02:00 +0206 Message-Id: <20221019145600.1282823-39-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With commit 9e124fe16ff2("xen: Enable console tty by default in domU if it's not a dummy") a hack was implemented to make sure that the tty console remains the console behind the /dev/console device. The main problem with the hack is that, after getting the console pointer to the tty console, it is assumed the pointer is still valid after releasing the console_sem. This assumption is incorrect and unsafe. Make the hack safe by introducing a new function console_force_preferred() to perform the full operation under the console_list_lock. Signed-off-by: John Ogness --- drivers/video/fbdev/xen-fbfront.c | 8 +--- include/linux/console.h | 1 + kernel/printk/printk.c | 69 +++++++++++++++++++------------ 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fb= front.c index 2552c853c6c2..aa362b25a60f 100644 --- a/drivers/video/fbdev/xen-fbfront.c +++ b/drivers/video/fbdev/xen-fbfront.c @@ -512,12 +512,8 @@ static void xenfb_make_preferred_console(void) } console_srcu_read_unlock(cookie); =20 - if (c) { - unregister_console(c); - c->flags |=3D CON_CONSDEV; - c->flags &=3D ~CON_PRINTBUFFER; /* don't print again */ - register_console(c); - } + if (c) + console_force_preferred(c); } =20 static int xenfb_resume(struct xenbus_device *dev) diff --git a/include/linux/console.h b/include/linux/console.h index bf1e8136424a..41378b00bbdd 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -235,6 +235,7 @@ enum con_flush_mode { }; =20 extern int add_preferred_console(char *name, int idx, char *options); +extern void console_force_preferred(struct console *c); extern void register_console(struct console *); extern int unregister_console(struct console *); extern void console_lock(void); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 840d581c4b23..9a056a42b8d8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3207,38 +3207,17 @@ static void try_enable_default_console(struct conso= le *newcon) =20 static int unregister_console_locked(struct console *console); =20 -/* - * The console driver calls this routine during kernel initialization - * to register the console printing procedure with printk() and to - * print any messages that were printed by the kernel before the - * console driver was initialized. - * - * This can happen pretty early during the boot process (because of - * early_printk) - sometimes before setup_arch() completes - be careful - * of what kernel features are used - they may not be initialised yet. - * - * There are two types of consoles - bootconsoles (early_printk) and - * "real" consoles (everything which is not a bootconsole) which are - * handled differently. - * - Any number of bootconsoles can be registered at any time. - * - As soon as a "real" console is registered, all bootconsoles - * will be unregistered automatically. - * - Once a "real" console is registered, any attempt to register a - * bootconsoles will be rejected - */ -void register_console(struct console *newcon) +static void register_console_locked(struct console *newcon) { struct console *con; bool bootcon_enabled =3D false; bool realcon_enabled =3D false; int err; =20 - console_list_lock(); - for_each_console(con) { if (WARN(con =3D=3D newcon, "console '%s%d' already registered\n", con->name, con->index)) { - goto unlock; + return; } =20 if (con->flags & CON_BOOT) @@ -3251,7 +3230,7 @@ void register_console(struct console *newcon) if (newcon->flags & CON_BOOT && realcon_enabled) { pr_info("Too late to register bootconsole %s%d\n", newcon->name, newcon->index); - goto unlock; + return; } =20 /* @@ -3282,7 +3261,7 @@ void register_console(struct console *newcon) =20 /* printk() messages are not printed to the Braille console. */ if (err || newcon->flags & CON_BRL) - goto unlock; + return; =20 /* * If we have a bootconsole, and are switching to a real console, @@ -3346,7 +3325,31 @@ void register_console(struct console *newcon) unregister_console_locked(con); } } -unlock: +} + +/* + * The console driver calls this routine during kernel initialization + * to register the console printing procedure with printk() and to + * print any messages that were printed by the kernel before the + * console driver was initialized. + * + * This can happen pretty early during the boot process (because of + * early_printk) - sometimes before setup_arch() completes - be careful + * of what kernel features are used - they may not be initialised yet. + * + * There are two types of consoles - bootconsoles (early_printk) and + * "real" consoles (everything which is not a bootconsole) which are + * handled differently. + * - Any number of bootconsoles can be registered at any time. + * - As soon as a "real" console is registered, all bootconsoles + * will be unregistered automatically. + * - Once a "real" console is registered, any attempt to register a + * bootconsoles will be rejected + */ +void register_console(struct console *newcon) +{ + console_list_lock(); + register_console_locked(newcon); console_list_unlock(); } EXPORT_SYMBOL(register_console); @@ -3411,6 +3414,20 @@ int unregister_console(struct console *console) } EXPORT_SYMBOL(unregister_console); =20 +void console_force_preferred(struct console *c) +{ + console_list_lock(); + + if (unregister_console_locked(c) =3D=3D 0) { + c->flags |=3D CON_CONSDEV; + c->flags &=3D ~CON_PRINTBUFFER; /* don't print again */ + register_console_locked(c); + } + + console_list_unlock(); +} +EXPORT_SYMBOL(console_force_preferred); + /* * Initialize the console device. This is called *early*, so * we can't necessarily depend on lots of kernel help here. --=20 2.30.2