From patchwork Wed Nov 16 16:21:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp232209wru; Wed, 16 Nov 2022 08:23:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf63EqX+NonrXz/obeOtLa9pCUc5FRtQqojLH3SMi2irZBqr95eBX+oDHa9JdZmp0S6R1Gro X-Received: by 2002:a17:906:4156:b0:78d:6ba1:74dd with SMTP id l22-20020a170906415600b0078d6ba174ddmr18493286ejk.119.1668615791009; Wed, 16 Nov 2022 08:23:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615791; cv=none; d=google.com; s=arc-20160816; b=ooLuRwjO+HJIhbQmN3NuzajMtd/jrHy1ruw+Jhw2Qf5+drwmFUIdlCP8/1tADgMBQA cb/3nf/dWlV/YVCFp2Yasejh7fVC5lxAyZxJLkdn/Pv9RtNmb4635lenEpvDjgQ0DF1H XVeXYLdEotQf0mzGZSNcJss1hQVP2u6X4vmYTf8zeZ6MEgjVljI5Xl6zWTTP4+tjQ+26 kJQJuPR0ivP+G/2XPN2VhTa43IzUc+2Ox3ngMVDWv17Am6m69KlQ82Bp98PN8olX7R5M ysIe3bKUlUKsjvovy7/IRvrRkhXigzhyBW8hIayaTb8+2e3229wakhv9HQt7jyMLWu12 vjmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=MpXDwx4HKdMdBWDyluBjDSAFdjedUOkxkf204NlGPAs=; b=Z2rG+xcfNKSJ04YKn26eSuo39gQIGg27QuoT+A2co6BGTg/8u7blqCX+HxBf4HyUfb yJo8J2+YGxkDbTu0wfHQLABc3O3h/5nJW+PuUjyhYrR5mm4w0XZeqs/6PCuiaHlqdFYP u0lqe2Dm2y61G+pv2oJvCPmcx0LOVAPA3yliCzLZMfQwiDRqXClSHATMsN0aLeOSGbWr Q7HV7BSDOvP+9Tka/pKNo+fdmTTuhhsouPWVUYgTZ0tO3CO3rjzSdOc3yJoPwqC27gWT 4t4HcExPSp5eX3+bvDlcVfWgAnS+F/NJxYWvVD9cC1QYghsQO5zAeyzYJS65sPpddRfs Ey6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LqzUIFfW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=KpNtEbzl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb39-20020a1709077ea700b007aeaacd5592si11863184ejc.124.2022.11.16.08.22.47; Wed, 16 Nov 2022 08:23:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LqzUIFfW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=KpNtEbzl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233496AbiKPQWE (ORCPT + 99 others); Wed, 16 Nov 2022 11:22:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231224AbiKPQWB (ORCPT ); Wed, 16 Nov 2022 11:22:01 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CAC726495; Wed, 16 Nov 2022 08:22:00 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615718; 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=MpXDwx4HKdMdBWDyluBjDSAFdjedUOkxkf204NlGPAs=; b=LqzUIFfWKdEdiyeDT4SA4emyQt7a9a+2ayMhlNuY8oKBxOZ55QB5G2qQqcYfRRW2xlUICW tBwDtRYB7JMPPvjHX4UxY5ypgN6jVCNWuE/WjNV6Ur8UrMVRcsBmdQuVxrOQ+dqHuMDUTP 1qm5jh0qN+dcqhLR8NCFhFcm/ntrqaL7JO1PtX4eXnjEtGvhUa+irm7Cqewqp/dPHWPpir loS78h/J/Y2VzMyenoQlqx/7uSrTjLRrp4Z4Gv2Or3yKv4I7e9jJ05pSDNY5sngtzthllA BYZqI6OU9WxkkKJuMK1lZhzdDMcEAvjzz7rJiL8FLy2y7oOwam8IlCUML4DVHg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615718; 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=MpXDwx4HKdMdBWDyluBjDSAFdjedUOkxkf204NlGPAs=; b=KpNtEbzlAdwIW6nKnDTQJbZW60PKBRcYjMQXzivs6ATu0YjHy6ToNZTwuGwHb2+Ivz8DwO UUVw2DECAzI7ufDA== 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 v5 01/40] serial: kgdboc: Lock console list in probe function Date: Wed, 16 Nov 2022 17:27:13 +0106 Message-Id: <20221116162152.193147-2-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670471450402968?= X-GMAIL-MSGID: =?utf-8?q?1749670471450402968?= From: Thomas Gleixner Unprotected list walks are not necessarily safe. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Douglas Anderson Reviewed-by: Sergey Senozhatsky Reviewed-by: Petr Mladek Reviewed-by: Daniel Thompson --- 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; + console_lock(); for_each_console(cons) { int idx; if (cons->device && cons->device(cons, &idx) == p && @@ -201,6 +202,7 @@ static int configure_kgdboc(void) break; } } + console_unlock(); kgdb_tty_driver = p; kgdb_tty_line = tty_line; From patchwork Wed Nov 16 16:21:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21136 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp232200wru; Wed, 16 Nov 2022 08:23:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf5K/+u0VsbBoOJBQcKrZlzIMPrG5Fn1wP9/UuJOoIlLyUmP8vfvcv7NKqdf9BFl/ONVfQL0 X-Received: by 2002:a17:902:e5c4:b0:187:4738:bf85 with SMTP id u4-20020a170902e5c400b001874738bf85mr9855857plf.94.1668615790453; Wed, 16 Nov 2022 08:23:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615790; cv=none; d=google.com; s=arc-20160816; b=j4/u2TxoZ6cnvxhkH5nBb6oYMBSTQRdklj2ndfZtQdbMTOKlux3MWgGKdv3c1gvgqa PSauFu1wbFPHCK5y4CQQC3dMxraeRRrRzNyh3iSLYdpUcvsvSVFGdN5W+h27iIdLt7M6 NkBBQaekAo+nWQBPzIlP4wqZ/3UUdWdox3Y0Ba4NtpiSy25HPaKmLYd6nUM+kYuzyseQ kqdStsUZmPGjCE1vZUF9OuwilUUGOoOrkc2+02N8Xo+lZNWaopWtCZthF/FRMmzljBUl daKJQN193PpoQVjYyj/ZQwRcjOCsdGlvL0d0GjB5YSqvOH9AO2IVZALr7t7FUO55ozxw Pn7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=tqcgl/PatKp2kr+pgaPtk6Kzu4HMlErNR4mnxas6jwk=; b=xtOl7UoWwMT5e0SZjpMqzPk/4p7e4y3HTAY57PI6+6RGgWvssHD/sB9WVTKeBiyfFA 4onvYGy+UxMwWbYlFO999a3+tP565RdqoKfMF/wQIQIuFU9xdRG87URql02o6VppA3WW YA+WqSGzhHFRKSoIU6sU+gpNPBPzRwEt80O1p1WbU830m1JDAarO+/C+n8eGbSX9B9tp 4cf4VlvGIlBLuXkg0hWn9dJ62W2tZLqWHjbav0FGP4n87eXEW6iFkKVI5uLntXI1uF8H FQShWkcTFSNtClwmhg1Aw9iFrzGDqs8w/E2k43JsvSDFX1LKpMpAs8sb3c9Zb+OuC/G8 s82Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CAhyYWcU; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f27-20020a63555b000000b0046efd063864si15171049pgm.109.2022.11.16.08.22.57; Wed, 16 Nov 2022 08:23:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CAhyYWcU; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234520AbiKPQWO (ORCPT + 99 others); Wed, 16 Nov 2022 11:22:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232590AbiKPQWC (ORCPT ); Wed, 16 Nov 2022 11:22:02 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B943E62; Wed, 16 Nov 2022 08:22:00 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615718; 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=tqcgl/PatKp2kr+pgaPtk6Kzu4HMlErNR4mnxas6jwk=; b=CAhyYWcUtgpL29I4JsFsCnnvkt6pZB13B+vslAV1iCvfmqXKD1OfFb4iua4XvHf49XSJy8 JVU2MyKCI5fcEEoRDGlLZkgWjgv1FunSUdLxFj+x8ZUtxTit9sQN5fHU+PUs11Yilgj1CF kw1oJmhvNm4PokAmAOOl/YJZf6Vn47Kr5CpdEemUDrwe69h/Fh1DW9CEUxs6ap8+wBWQNg 9x11cxU9xeCVzpWHix9cN8JCI/31tQvIMqYIZCweU+JYcFww8xBHMDMtRoQj1PrvzS9PeU hBaBov6X5dlU21twZwTuE82v1SwB74ayZu5CvsfUbzeFa8gSYYdyJMIKlxO/Jw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615718; 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=tqcgl/PatKp2kr+pgaPtk6Kzu4HMlErNR4mnxas6jwk=; b=btpW5OcIeYGDfwkxKpxg0nj2/riSRWYDAivf+ElRM1PG1Q1tHAriLxmzKURtssaWVDLkqW vtZJzZ0eps2ClUAA== 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 v5 02/40] printk: Convert console_drivers list to hlist Date: Wed, 16 Nov 2022 17:27:14 +0106 Message-Id: <20221116162152.193147-3-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670471070413475?= X-GMAIL-MSGID: =?utf-8?q?1749670471070413475?= From: Thomas Gleixner Replace the open coded single linked list with a hlist so a conversion to SRCU protected list walks can reuse the existing primitives. Co-developed-by: John Ogness Signed-off-by: John Ogness Signed-off-by: Thomas Gleixner Reviewed-by: Greg Kroah-Hartman Reviewed-by: Sergey Senozhatsky Reviewed-by: Petr Mladek --- fs/proc/consoles.c | 3 +- include/linux/console.h | 8 ++-- kernel/printk/printk.c | 101 ++++++++++++++++++++++------------------ 3 files changed, 62 insertions(+), 50 deletions(-) diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c index dfe6ce3505ce..cf2e0788f9c7 100644 --- a/fs/proc/consoles.c +++ b/fs/proc/consoles.c @@ -74,8 +74,9 @@ static void *c_start(struct seq_file *m, loff_t *pos) static void *c_next(struct seq_file *m, void *v, loff_t *pos) { struct console *con = v; + ++*pos; - return con->next; + return hlist_entry_safe(con->node.next, struct console, node); } static void c_stop(struct seq_file *m, void *v) diff --git a/include/linux/console.h b/include/linux/console.h index 8c1686e2c233..7b5f21f9e469 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -15,6 +15,7 @@ #define _LINUX_CONSOLE_H_ 1 #include +#include #include struct vc_data; @@ -154,14 +155,16 @@ struct console { u64 seq; unsigned long dropped; void *data; - struct console *next; + struct hlist_node node; }; +extern struct hlist_head console_list; + /* * for_each_console() allows you to iterate on each console */ #define for_each_console(con) \ - for (con = console_drivers; con != NULL; con = con->next) + hlist_for_each_entry(con, &console_list, node) extern int console_set_on_cmdline; extern struct console *early_console; @@ -174,7 +177,6 @@ enum con_flush_mode { extern int add_preferred_console(char *name, int idx, char *options); extern void register_console(struct console *); extern int unregister_console(struct console *); -extern struct console *console_drivers; extern void console_lock(void); extern int console_trylock(void); extern void console_unlock(void); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e4f1e7478b52..e6f0832e71f0 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -79,13 +79,12 @@ int oops_in_progress; EXPORT_SYMBOL(oops_in_progress); /* - * console_sem protects the console_drivers list, and also - * provides serialisation for access to the entire console - * driver system. + * console_sem protects console_list and console->flags updates, and also + * provides serialization for access to the entire console driver system. */ static DEFINE_SEMAPHORE(console_sem); -struct console *console_drivers; -EXPORT_SYMBOL_GPL(console_drivers); +HLIST_HEAD(console_list); +EXPORT_SYMBOL_GPL(console_list); /* * System may need to suppress printk message under certain @@ -2556,7 +2555,7 @@ static int console_cpu_notify(unsigned int cpu) * console_lock - lock the console system for exclusive use. * * Acquires a lock which guarantees that the caller has - * exclusive access to the console system and the console_drivers list. + * exclusive access to the console system and console_list. * * Can sleep, returns nothing. */ @@ -2576,7 +2575,7 @@ EXPORT_SYMBOL(console_lock); * console_trylock - try to lock the console system for exclusive use. * * Try to acquire a lock which guarantees that the caller has exclusive - * access to the console system and the console_drivers list. + * access to the console system and console_list. * * returns 1 on success, and 0 on failure to acquire the lock. */ @@ -2940,11 +2939,20 @@ void console_flush_on_panic(enum con_flush_mode mode) console_may_schedule = 0; if (mode == CONSOLE_REPLAY_ALL) { + struct hlist_node *tmp; struct console *c; u64 seq; seq = prb_first_valid_seq(prb); - for_each_console(c) + /* + * This cannot use for_each_console() because it's not established + * that the current context has console locked and neither there is + * a guarantee that there is no concurrency in that case. + * + * Open code it for documentation purposes and pretend that + * it works. + */ + hlist_for_each_entry_safe(c, tmp, &console_list, node) c->seq = seq; } console_unlock(); @@ -3081,6 +3089,9 @@ static void try_enable_default_console(struct console *newcon) (con->flags & CON_BOOT) ? "boot" : "", \ con->name, con->index, ##__VA_ARGS__) +#define console_first() \ + hlist_entry(console_list.first, struct console, node) + /* * The console driver calls this routine during kernel initialization * to register the console printing procedure with printk() and to @@ -3140,8 +3151,8 @@ void register_console(struct console *newcon) * flag set and will be first in the list. */ if (preferred_console < 0) { - if (!console_drivers || !console_drivers->device || - console_drivers->flags & CON_BOOT) { + if (hlist_empty(&console_list) || !console_first()->device || + console_first()->flags & CON_BOOT) { try_enable_default_console(newcon); } } @@ -3169,20 +3180,22 @@ void register_console(struct console *newcon) } /* - * Put this console in the list - keep the - * preferred driver at the head of the list. + * Put this console in the list - keep the + * preferred driver at the head of the list. */ console_lock(); - if ((newcon->flags & CON_CONSDEV) || console_drivers == NULL) { - newcon->next = console_drivers; - console_drivers = newcon; - if (newcon->next) - newcon->next->flags &= ~CON_CONSDEV; - /* Ensure this flag is always set for the head of the list */ + if (hlist_empty(&console_list)) { + /* Ensure CON_CONSDEV is always set for the head. */ newcon->flags |= CON_CONSDEV; + hlist_add_head(&newcon->node, &console_list); + + } else if (newcon->flags & CON_CONSDEV) { + /* Only the new head can have CON_CONSDEV set. */ + console_first()->flags &= ~CON_CONSDEV; + hlist_add_head(&newcon->node, &console_list); + } else { - newcon->next = console_drivers->next; - console_drivers->next = newcon; + hlist_add_behind(&newcon->node, console_list.first); } newcon->dropped = 0; @@ -3209,16 +3222,18 @@ void register_console(struct console *newcon) if (bootcon_enabled && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) && !keep_bootcon) { - for_each_console(con) + struct hlist_node *tmp; + + hlist_for_each_entry_safe(con, tmp, &console_list, node) { if (con->flags & CON_BOOT) unregister_console(con); + } } } EXPORT_SYMBOL(register_console); int unregister_console(struct console *console) { - struct console *con; int res; con_printk(KERN_INFO, console, "disabled\n"); @@ -3229,32 +3244,30 @@ int unregister_console(struct console *console) if (res > 0) return 0; - res = -ENODEV; console_lock(); - if (console_drivers == console) { - console_drivers=console->next; - res = 0; - } else { - for_each_console(con) { - if (con->next == console) { - con->next = console->next; - res = 0; - break; - } - } + + /* Disable it unconditionally */ + console->flags &= ~CON_ENABLED; + + if (hlist_unhashed(&console->node)) { + console_unlock(); + return -ENODEV; } - if (res) - goto out_disable_unlock; + hlist_del_init(&console->node); /* + * * 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 != NULL && console->flags & CON_CONSDEV) - console_drivers->flags |= CON_CONSDEV; + if (!hlist_empty(&console_list) && console->flags & CON_CONSDEV) + console_first()->flags |= CON_CONSDEV; - console->flags &= ~CON_ENABLED; console_unlock(); console_sysfs_notify(); @@ -3262,12 +3275,6 @@ int unregister_console(struct console *console) res = console->exit(console); return res; - -out_disable_unlock: - console->flags &= ~CON_ENABLED; - console_unlock(); - - return res; } EXPORT_SYMBOL(unregister_console); @@ -3317,10 +3324,11 @@ void __init console_init(void) */ static int __init printk_late_init(void) { + struct hlist_node *tmp; struct console *con; int ret; - for_each_console(con) { + hlist_for_each_entry_safe(con, tmp, &console_list, node) { if (!(con->flags & CON_BOOT)) continue; @@ -3340,6 +3348,7 @@ static int __init printk_late_init(void) unregister_console(con); } } + ret = cpuhp_setup_state_nocalls(CPUHP_PRINTK_DEAD, "printk:dead", NULL, console_cpu_notify); WARN_ON(ret < 0); From patchwork Wed Nov 16 16:21:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21144 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp232705wru; Wed, 16 Nov 2022 08:24:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf6iFilqKbJE5DWHtGCWaQpnp+wicaQPWYQhb1CET2z8WLXr6y86ShbNLAiJRv9csZU9Ducj X-Received: by 2002:a17:90a:5d81:b0:212:cf2e:2b0b with SMTP id t1-20020a17090a5d8100b00212cf2e2b0bmr4459808pji.169.1668615855971; Wed, 16 Nov 2022 08:24:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615855; cv=none; d=google.com; s=arc-20160816; b=KxKvpVHFMCYzWzknHy5hnfxRznDmZ8X4gOGffCDBAq/IGaSf1HBFK+QIJkzE29LQ3o ZUsNSicssU+8rpgmcrjvmySjl36uaiT8YR2v9KNqbw/VtXDtWYO13pI6OfJSw6UZRtKv R14ctcZDsGmL5+XnFoUA7MQYmmETC4b3MxPeAeZaLrIWUMIGfU7WfjtRnJ2CJZZTALOJ +dEcX4BHDZm/gaK2H1nUQVK3PS6RjDllM/HSBCXWjnApUQVJ+MvtwVhSuX8KL9n79clc ze50ivGxR9riacTOCNyoLsdKQom8vK6FpcAzGkp9dWbXMaUptdxZjJ6FL4BljJiRkdWx fcoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=1B4/BOJeAGf7Dtoezu6zTfoEVRhsIga8Xj9og7bYHLY=; b=Is4bRESJ6pbDMT3pNvHgC5FgkK15Y5IwIJA5ye2cClY96SjHBp5RDDdbG11AQ+WEe1 QvDLo5paI1j9U2gYiMLCHgfPR3sZqRm4XtPQssnUaS47DMDQDqxbuzzkBVxapNNZ8q+h VM2QkNMyFRkJv7DExT9pBMXZm6DoVajJQM3OyDKz5hpKATHFxsAXS/vjeb6mgVdgbaxx gFoIJogJUFp/CQ8t6it8x4OKmb5BQ1TV7P8XjgmuKC44e6ZqJ/tLcmCKsDpoDs22WxQU B+4yeDvnFqqBAChQaU8pFFVv2AVrewoBqFhg9IV5ZuhVuTkeaapwDOP71f2qm2OwGQAT zYXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NhfDuPfr; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nl7-20020a17090b384700b00213b10313efsi2756983pjb.175.2022.11.16.08.24.02; Wed, 16 Nov 2022 08:24:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NhfDuPfr; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234377AbiKPQWH (ORCPT + 99 others); Wed, 16 Nov 2022 11:22:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232974AbiKPQWC (ORCPT ); Wed, 16 Nov 2022 11:22:02 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58E8C419B4 for ; Wed, 16 Nov 2022 08:22:00 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615719; 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=1B4/BOJeAGf7Dtoezu6zTfoEVRhsIga8Xj9og7bYHLY=; b=NhfDuPfrTQdAhS2yS2TjTsBngwncnpG132e/pQbGvoRRmBnDOd6bOxR3TRPbxCd64WD+gc 3xQQ5Vks76kND/HCXvDvGUtlOZpYJ/40AgsqSP178m+U4sWZN2SFc2Y5KuLaTUmCz5sCnP VGq90QQLbTBq4x9+vi98VoxWnS9wN4SaJxILO79hhZZuNw6PpkRai26p04wqJRi//dlvUH MKZ7p1cRS9ogwmzMbTR1zK2Fb0bKGhjOr8rYiY1yAqYSJd3oMKK53xSOkfVvVG0FQgj0DH 8jLujte6ocwtLVI9fskRZ2XruudSzRWOHVbFNn9Y6j5b5+DvRWVUbuYuxDS3MQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615719; 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=1B4/BOJeAGf7Dtoezu6zTfoEVRhsIga8Xj9og7bYHLY=; b=zICGtHOqKGJha+Es2Kka/4nSFRG/vK4Gjiqee7KTkBwn8W7eNWY7vMpyVUShDkLbPp28+5 xyz9HnRcdXiQcEAw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Miguel Ojeda , Greg Kroah-Hartman , "Paul E . McKenney" Subject: [PATCH printk v5 03/40] printk: Prepare for SRCU console list protection Date: Wed, 16 Nov 2022 17:27:15 +0106 Message-Id: <20221116162152.193147-4-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670539566454038?= X-GMAIL-MSGID: =?utf-8?q?1749670539566454038?= 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. Suggested-by: Thomas Gleixner Signed-off-by: John Ogness Acked-by: Miguel Ojeda Reviewed-by: Paul E. McKenney Reviewed-by: Petr Mladek Tested-by: John Ogness --- .clang-format | 1 + include/linux/console.h | 28 ++++++++++++- kernel/printk/printk.c | 87 ++++++++++++++++++++++++++++++++++------- 3 files changed, 100 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..f4f0c9523835 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -15,7 +15,7 @@ #define _LINUX_CONSOLE_H_ 1 #include -#include +#include #include struct vc_data; @@ -158,8 +158,34 @@ struct console { struct hlist_node node; }; +#ifdef CONFIG_DEBUG_LOCK_ALLOC +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; +/** + * 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 e6f0832e71f0..173f46a29252 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); /* * System may need to suppress printk message under certain @@ -104,6 +105,13 @@ static struct lockdep_map console_lock_dep_map = { }; #endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC +bool console_srcu_read_lock_is_held(void) +{ + return srcu_read_lock_held(&console_srcu); +} +#endif + enum devkmsg_log_bits { __DEVKMSG_LOG_BIT_ON = 0, __DEVKMSG_LOG_BIT_OFF, @@ -219,6 +227,32 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, } #endif /* CONFIG_PRINTK && CONFIG_SYSCTL */ +/** + * 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 information. @@ -2989,6 +3023,14 @@ void console_stop(struct console *console) console_lock(); console->flags &= ~CON_ENABLED; console_unlock(); + + /* + * Ensure that all SRCU list walks have completed. All contexts must + * be able to see that this console is disabled so that (for example) + * the caller can suspend the port without risk of another context + * using the port. + */ + synchronize_srcu(&console_srcu); } EXPORT_SYMBOL(console_stop); @@ -3179,6 +3221,17 @@ void register_console(struct console *newcon) newcon->flags &= ~CON_PRINTBUFFER; } + newcon->dropped = 0; + if (newcon->flags & CON_PRINTBUFFER) { + /* Get a consistent copy of @syslog_seq. */ + mutex_lock(&syslog_lock); + newcon->seq = syslog_seq; + mutex_unlock(&syslog_lock); + } else { + /* Begin with next message. */ + newcon->seq = prb_next_seq(prb); + } + /* * Put this console in the list - keep the * preferred driver at the head of the list. @@ -3187,28 +3240,24 @@ void register_console(struct console *newcon) if (hlist_empty(&console_list)) { /* Ensure CON_CONSDEV is always set for the head. */ newcon->flags |= CON_CONSDEV; - hlist_add_head(&newcon->node, &console_list); + hlist_add_head_rcu(&newcon->node, &console_list); } else if (newcon->flags & CON_CONSDEV) { /* Only the new head can have CON_CONSDEV set. */ console_first()->flags &= ~CON_CONSDEV; - hlist_add_head(&newcon->node, &console_list); + hlist_add_head_rcu(&newcon->node, &console_list); } else { - hlist_add_behind(&newcon->node, console_list.first); - } - - newcon->dropped = 0; - if (newcon->flags & CON_PRINTBUFFER) { - /* Get a consistent copy of @syslog_seq. */ - mutex_lock(&syslog_lock); - newcon->seq = syslog_seq; - mutex_unlock(&syslog_lock); - } else { - /* Begin with next message. */ - newcon->seq = prb_next_seq(prb); + hlist_add_behind_rcu(&newcon->node, console_list.first); } console_unlock(); + + /* + * No need to synchronize SRCU here! The caller does not rely + * on all contexts being able to see the new console before + * register_console() completes. + */ + console_sysfs_notify(); /* @@ -3254,7 +3303,7 @@ int unregister_console(struct console *console) return -ENODEV; } - hlist_del_init(&console->node); + hlist_del_init_rcu(&console->node); /* * @@ -3269,6 +3318,14 @@ int unregister_console(struct console *console) console_first()->flags |= CON_CONSDEV; console_unlock(); + + /* + * Ensure that all SRCU list walks have completed. All contexts + * must not be able to see this console in the list so that any + * exit/cleanup routines can be performed safely. + */ + synchronize_srcu(&console_srcu); + console_sysfs_notify(); if (console->exit) From patchwork Wed Nov 16 16:21:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21137 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp232293wru; Wed, 16 Nov 2022 08:23:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf5JCEnv2k5xr9gt43t6C5fPvPHRsWkEN/BgvFST0cBa58QPT9ymI4chHhI2O80ju169VM6Q X-Received: by 2002:aa7:88c7:0:b0:561:c694:80b with SMTP id k7-20020aa788c7000000b00561c694080bmr23787578pff.47.1668615801144; Wed, 16 Nov 2022 08:23:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615801; cv=none; d=google.com; s=arc-20160816; b=DSsgJDNpNXzGONT3LQp12C63apmDilNFYlrEw6qcDiwDE8PO1vfXKVozHb2eJr2p7W 8XdTmgERejwg2jeQmNmDGLIRQ8OOZ/zPlRG7BziPpFYQMwWCI1c5USPUBVVkdbSEHbUa 63XUKH77KqpMZnZTPhGJ9z9iiQlC7G3Ge1Ex3aPX3+jtlu40Apn+1pAGzEGGrck5RnNb Neaux6EZhJqxD7LdYNCTGxrws/U4s13n3FUkhSIE2WRR9WTfZyj5RSGjFDCzsE/UhTf7 SM0HTytGC7UPbo/0qsvGsTtImRhZcfErzMkxIPCQgQT9AVQ0THzU+jubgpKNeTvTeKjS GNoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=+1TqEd+pwmRnewIM2sroSQVcuwkSMDWChGspRlPqu/A=; b=oFcZqi8KLCILyV5qJ3HUMpsItdNRnUT6WV2TFrbXD4JPLpJG8QeeMQ0Co1Rx2pXPib rwiKzVCQlAZXLcuvTRIMYiPNeRvLetkaWAxiPeh6BqskQV32nfLITb4tCXt6JVVSWNcp uKuGOaY15i0TRMKHEAQsj1XbenepW51m6Aptn8zSjtCUSZReM6Fv/BA37+9GTASXyY2S zPySEOCBhr/wDOISHfTrGI+0r5MxMdayJU6s+wsuja9b3TFCQ+n99CUQSg1syu7WuOdI 1cdOhAiFCKNuF+vTN5JLT+Dy1SpYh+Ehuse4TPFRtg9oS++paNWLU70k3v8/Ur4CT+Hj jogg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qkWNZuHI; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n13-20020a635c4d000000b00476dd604aa8si3205710pgm.767.2022.11.16.08.23.07; Wed, 16 Nov 2022 08:23:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qkWNZuHI; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234583AbiKPQWU (ORCPT + 99 others); Wed, 16 Nov 2022 11:22:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233256AbiKPQWC (ORCPT ); Wed, 16 Nov 2022 11:22:02 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAB6F43856 for ; Wed, 16 Nov 2022 08:22:00 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615719; 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=+1TqEd+pwmRnewIM2sroSQVcuwkSMDWChGspRlPqu/A=; b=qkWNZuHIxGALpO16uCXZdJ0UuvGmJmsNr20J0bzpEBue6UaxzNZCJq1PYOPHQo0mny88+2 S8iJQI1dPomnzF3jtLFK+W82WvVJ/5hbXiqaIXfnt6RQmYCU2oZn+13JOqaROuN0y0gzwG 73Gwr7hBFk25eIvHWW7261YYsJdqJiQwan8tVK933Xt79BS9E160iDOkoIB4CQlv/Kg+QY iNxy2JFmnFdBCkG2dFXomeU6qWFOMl0fsfvWQ3EFTE3YrWtDGw9SSMU8MYeN17CVgMsKu8 BAAw9WsJxFb0lK1gQAIsYG+wVMPJP8rZNV7Izm4FdgXd1XVuhXr7gRmSLjgMUw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615719; 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=+1TqEd+pwmRnewIM2sroSQVcuwkSMDWChGspRlPqu/A=; b=7n/mofXba0q/ZMlL7TlNyX0vnqpss/9Hvmr9KIGRFCUuszM8XhWj4URUkgM6600JCmmnpJ JCyjTH3cInixUQDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 04/40] printk: register_console: use "registered" for variable names Date: Wed, 16 Nov 2022 17:27:16 +0106 Message-Id: <20221116162152.193147-5-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670482037359972?= X-GMAIL-MSGID: =?utf-8?q?1749670482037359972?= The @bootcon_enabled and @realcon_enabled local variables actually represent if such console types are registered. In general there has been a confusion about enabled vs. registered. Incorrectly naming such variables promotes such confusion. Rename the variables to _registered. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 173f46a29252..3d449dfb1ed6 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3156,8 +3156,8 @@ static void try_enable_default_console(struct console *newcon) void register_console(struct console *newcon) { struct console *con; - bool bootcon_enabled = false; - bool realcon_enabled = false; + bool bootcon_registered = false; + bool realcon_registered = false; int err; for_each_console(con) { @@ -3168,13 +3168,13 @@ void register_console(struct console *newcon) for_each_console(con) { if (con->flags & CON_BOOT) - bootcon_enabled = true; + bootcon_registered = true; else - realcon_enabled = true; + realcon_registered = true; } /* Do not register boot consoles when there already is a real one. */ - if (newcon->flags & CON_BOOT && realcon_enabled) { + if ((newcon->flags & CON_BOOT) && realcon_registered) { pr_info("Too late to register bootconsole %s%d\n", newcon->name, newcon->index); return; @@ -3216,7 +3216,7 @@ void register_console(struct console *newcon) * the real console are the same physical device, it's annoying to * see the beginning boot messages twice */ - if (bootcon_enabled && + if (bootcon_registered && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV)) { newcon->flags &= ~CON_PRINTBUFFER; } @@ -3268,7 +3268,7 @@ void register_console(struct console *newcon) * went to the bootconsole (that they do not see on the real console) */ con_printk(KERN_INFO, newcon, "enabled\n"); - if (bootcon_enabled && + if (bootcon_registered && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) && !keep_bootcon) { struct hlist_node *tmp; From patchwork Wed Nov 16 16:21:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21139 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp232436wru; Wed, 16 Nov 2022 08:23:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf6uI+jC1XW518+fyi7xCI2/BO1zDK1ste/d/sOKv58uXaZHbY7r0GIbBYvSEKS5JzzbAYGo X-Received: by 2002:a17:906:e29a:b0:78d:d2e5:7a11 with SMTP id gg26-20020a170906e29a00b0078dd2e57a11mr18852116ejb.144.1668615818094; Wed, 16 Nov 2022 08:23:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615818; cv=none; d=google.com; s=arc-20160816; b=ltGxQ8W5v+p8it4i5z3bO0JH4xPq9/fMHxkdweHq4Vp0gSflzh7OlVtDFrC+6usFHK kwppnqctO1KcSBJWBzbrwcNck/SHmImzN4kNEhH+Wy1YKHU9K8HVnNJx2dvffcM/dFPj Fnu7Sd/jnR0q++hWncIEIqV7NgO3RHm7kiVssyP0EbZS3HPpNDynw8q3FWPROpomjMOP rcZf6fqBxXNYjWJFbZJEHlWNUKVQ4eaNV0bNqBjewLdZZd1TmsmFaaalYgRD8APDi3u3 XzubMf5msMXNnZMI2hOEGZZvdsDqtOecvcqTUbOef7JbKpV4MaDOhnzHAQQMyOUqgcbH CjZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=EN1ltT10tlp5gUO3+3LVGUGiufYOOsSefqI80mCBCpE=; b=ATCMVMiwzCSvHtgPy/uQ17CwvZK3dMR//+o9hXUbidaaf878u6P+g811TS0iv1f5Ni GDP6cVYLSqE5wrdk7rmijrK0MVl+X75FLj40CgyLmcB9t2CUEnUN1j7pQM8bJpxhk55k zVOienp3LvS83qEnZOkq6QWcFWBibGGBXUWKE5h7sqqRl4t1WqKL9aw8UiNBbb6Wtnza +xQ4vFjpB7eJksTfghz6xI13BiHTVTSZ6hzRs9R2nOrcHJTFyTUwBO4xTdQKbfvAaURo RN93YvUhi+K4ehj4vnDDpw0zQnNfL3q78AHqqjrnJd86PvwAN3WIbJPAvXJtbe1G98IA oGvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WPdwLGjn; dkim=neutral (no key) header.i=@linutronix.de header.b=J+8IXAJx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b17-20020a170906661100b00783a5f78700si6090659ejp.226.2022.11.16.08.23.14; Wed, 16 Nov 2022 08:23:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WPdwLGjn; dkim=neutral (no key) header.i=@linutronix.de header.b=J+8IXAJx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234622AbiKPQWZ (ORCPT + 99 others); Wed, 16 Nov 2022 11:22:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233335AbiKPQWD (ORCPT ); Wed, 16 Nov 2022 11:22:03 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 719E1D135 for ; Wed, 16 Nov 2022 08:22:02 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615719; 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=EN1ltT10tlp5gUO3+3LVGUGiufYOOsSefqI80mCBCpE=; b=WPdwLGjnnt1bS979u4sLT0ES6LFDbMLi7N2xzKnRQME44bqQm+SOt+o5g2PwviFi9WijgQ RBb99RpeWmpU9pVxhWLn5g66mzj8Ocxc8dWM4RCKpQHhvxbxNzcIZuIOLNtX4Ddq5/xqjd NisGFQFP3XCrWtP/mk6vRNtLLMH7AL/G2UeWNJraDyaD4cJI6YU6+Ge5bnxJojjX9RLEEA jyERdZM67/YAMRMSdktHvTio9Z2FIdZLscXeK2LYEV2DzMUADw1ejELcWjZq+ilM2Gu/ZJ C97woYLBDyIb0aFxgyHR2ZSZsTM696G7/qQ7d2Ue8Hpy9mjFHTtyWAhF5d7XMQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615719; 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=EN1ltT10tlp5gUO3+3LVGUGiufYOOsSefqI80mCBCpE=; b=J+8IXAJxUIi+rarf9xER0OU8t61+ODSJX3QmJ+F9MmZjZaJ14ftCmAo1TTl3sNy7gPAlD9 364wszigXArpVzDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 05/40] printk: move @seq initialization to helper Date: Wed, 16 Nov 2022 17:27:17 +0106 Message-Id: <20221116162152.193147-6-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670499741462230?= X-GMAIL-MSGID: =?utf-8?q?1749670499741462230?= The code to initialize @seq for a new console needs to consider more factors when choosing an initial value. Move the code into a helper function console_init_seq() "as is" so this code can be expanded without causing register_console() to become too long. A later commit will implement the additional code. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 3d449dfb1ed6..31d9d1cf8682 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3131,6 +3131,19 @@ static void try_enable_default_console(struct console *newcon) (con->flags & CON_BOOT) ? "boot" : "", \ con->name, con->index, ##__VA_ARGS__) +static void console_init_seq(struct console *newcon) +{ + if (newcon->flags & CON_PRINTBUFFER) { + /* Get a consistent copy of @syslog_seq. */ + mutex_lock(&syslog_lock); + newcon->seq = syslog_seq; + mutex_unlock(&syslog_lock); + } else { + /* Begin with next message. */ + newcon->seq = prb_next_seq(prb); + } +} + #define console_first() \ hlist_entry(console_list.first, struct console, node) @@ -3222,15 +3235,7 @@ void register_console(struct console *newcon) } newcon->dropped = 0; - if (newcon->flags & CON_PRINTBUFFER) { - /* Get a consistent copy of @syslog_seq. */ - mutex_lock(&syslog_lock); - newcon->seq = syslog_seq; - mutex_unlock(&syslog_lock); - } else { - /* Begin with next message. */ - newcon->seq = prb_next_seq(prb); - } + console_init_seq(newcon); /* * Put this console in the list - keep the From patchwork Wed Nov 16 16:21:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21138 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp232342wru; Wed, 16 Nov 2022 08:23:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf7aKdS9J19NaExVj4xD/7FgBOXt9IP5W3StNW+8KQko/plkFm7nrTjV2qgvY8X02pyo9Bll X-Received: by 2002:a63:5d15:0:b0:434:7885:6ade with SMTP id r21-20020a635d15000000b0043478856ademr20904559pgb.243.1668615809242; Wed, 16 Nov 2022 08:23:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615809; cv=none; d=google.com; s=arc-20160816; b=r/xXho9K7QgFvWOhnOe6EtnLEojowguB9o1qle8RlKDk4mV1HniRVnYMwQPvYspWQP GiGBoOtOgeFo7ws4kUftrz8EpYXktc0LIFz84+fCtvaUJxUsaUQN1bfTZdMpuWINXc10 Lmz856SHThLyywfoT2YAeJAVFC/Icwx1OGShu9B8bN1vGbmc6C1A3VZiAhgqZ2HTqwO0 78yc5a6lkFdQxI7VQF9Ryfq+LfRGHMdG0lyBk4kSOI5mtZH0ayMvQG42uAFrLHi79NvQ Viw7Nt8573XzLC2xLEw30UidxkAOfGNl/a63hAEmEHnBdphkbcquvt7y+DetQdyCU1GY 6WJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=EXztAQTlLoZJohd2YWLlNMXfDo93BSWHA8w8Mma17HQ=; b=q0sJXbsbXZSL0Vr2wlqzXVF49L50zRtFdFUmhSFh4WyUUfYExpSwT0evJNg/UDhA0I McPKPrpPkfbIMOCX0jJ2q6kdzBbG2hYy0Hh71VKi3JeJpqb6zyFkrqk1DuNBU1OUXF1M P2/7hgaFiVdswsMZefmXNSUyvchkJXAJSfPtgN6aijA0WY5KtJM5iSCD3tpG75IgDAlQ 61vnIYYWnUwzJIcwGf6vaf+G8vwoNgD+kC+bswUmzS4JSBOTeA26AWNK2eTEKVMPimrx 0c2WaQC0qmDj/0BR9W2thJBagsyJ7HJ5gK/SaAitJavi2ERBUVyu3bT7oTcf5+E7sGpy exiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yAhjS6EM; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mw16-20020a17090b4d1000b00218616d4f78si1140221pjb.36.2022.11.16.08.23.16; Wed, 16 Nov 2022 08:23:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yAhjS6EM; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234653AbiKPQW3 (ORCPT + 99 others); Wed, 16 Nov 2022 11:22:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233489AbiKPQWD (ORCPT ); Wed, 16 Nov 2022 11:22:03 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76B6D26495 for ; Wed, 16 Nov 2022 08:22:02 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615720; 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=EXztAQTlLoZJohd2YWLlNMXfDo93BSWHA8w8Mma17HQ=; b=yAhjS6EMHDwR29tHfXch75ulrWxpc1Dllv4e1A6L/CRuj3qaC6My52J05yB5LS9GYDty3S YbJygu6L8FxPUC3xceTSgU17KYRVnrlWuB69bhLpPC403se7hEx4Y0zChaqnPgAjnfE3oW Cr/u+gUpRuLp3lgAm6HWu80ooQi1vkv9JOU4lFDi94Hh4ol3jEk7tlMEzm3JYwypNq3QvI ZZEEWOZ3w5ptvZASYNKSNKyz7XCQb8XSV3fsXq+BPK9moc2EAkkxEE8VuOtAMaVnvNRPZv rSa3L1G9AM+0MYYCxgUVlc+6a/gZgm8lmIXcpscIaLPQ4b5XlBe7RIvfGCgKOg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615720; 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=EXztAQTlLoZJohd2YWLlNMXfDo93BSWHA8w8Mma17HQ=; b=J45KvR1CKJPOFPEjopi9x5va7WC/8qt7O7J18LAFBh1vT0vVGDJioBw26YKvI+8Sp5ai6K rFudH5T5A87CiaAA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 06/40] printk: fix setting first seq for consoles Date: Wed, 16 Nov 2022 17:27:18 +0106 Message-Id: <20221116162152.193147-7-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670490585026332?= X-GMAIL-MSGID: =?utf-8?q?1749670490585026332?= It used to be that all consoles were synchronized with respect to which message they were printing. After commit a699449bb13b ("printk: refactor and rework printing logic"), all consoles have their own @seq for tracking which message they are on. That commit also changed how the initial sequence number was chosen. Instead of choosing the next non-printed message, it chose the sequence number of the next message that will be added to the ringbuffer. That change created a possibility that a non-boot console taking over for a boot console might skip messages if the boot console was behind and did not have a chance to catch up before being unregistered. Since it is not known which boot console is the same device, flush all consoles and, if necessary, start with the message of the enabled boot console that is the furthest behind. If no boot consoles are enabled, begin with the next message that will be added to the ringbuffer. Also, since boot consoles are meant to be used at boot time, handle them the same as CON_PRINTBUFFER to ensure that no initial messages are skipped. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 50 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 31d9d1cf8682..c84654444a02 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3131,16 +3131,56 @@ static void try_enable_default_console(struct console *newcon) (con->flags & CON_BOOT) ? "boot" : "", \ con->name, con->index, ##__VA_ARGS__) -static void console_init_seq(struct console *newcon) +static void console_init_seq(struct console *newcon, bool bootcon_registered) { - if (newcon->flags & CON_PRINTBUFFER) { + struct console *con; + bool handover; + + if (newcon->flags & (CON_PRINTBUFFER | CON_BOOT)) { /* Get a consistent copy of @syslog_seq. */ mutex_lock(&syslog_lock); newcon->seq = syslog_seq; mutex_unlock(&syslog_lock); } else { - /* Begin with next message. */ + /* Begin with next message added to ringbuffer. */ newcon->seq = prb_next_seq(prb); + + /* + * If any enabled boot consoles are due to be unregistered + * shortly, some may not be caught up and may be the same + * device as @newcon. Since it is not known which boot console + * is the same device, flush all consoles and, if necessary, + * start with the message of the enabled boot console that is + * the furthest behind. + */ + if (bootcon_registered && !keep_bootcon) { + /* + * Flush all consoles and set the console to start at + * the next unprinted sequence number. + */ + if (!console_flush_all(true, &newcon->seq, &handover)) { + /* + * Flushing failed. Just choose the lowest + * sequence of the enabled boot consoles. + */ + + /* + * If there was a handover, this context no + * longer holds the console_lock. + */ + if (handover) + console_lock(); + + newcon->seq = prb_next_seq(prb); + for_each_console(con) { + if ((con->flags & CON_BOOT) && + (con->flags & CON_ENABLED) && + con->seq < newcon->seq) { + newcon->seq = con->seq; + } + } + } + } } } @@ -3235,13 +3275,13 @@ void register_console(struct console *newcon) } newcon->dropped = 0; - console_init_seq(newcon); + console_lock(); + console_init_seq(newcon, bootcon_registered); /* * 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 |= CON_CONSDEV; From patchwork Wed Nov 16 16:21:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21141 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp232577wru; Wed, 16 Nov 2022 08:23:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf57aVm1m9BOYN5Xxh2xu+wKls6WbDG7GpPXCeoVbIugUQ2Wo6DCHWRtdIZTPknejsQlrgSS X-Received: by 2002:a05:6402:1204:b0:461:e3f2:38bc with SMTP id c4-20020a056402120400b00461e3f238bcmr20156964edw.149.1668615839584; Wed, 16 Nov 2022 08:23:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615839; cv=none; d=google.com; s=arc-20160816; b=Fw3GGAF+3MUacBbCy9F3QAcTIPbNKbrdoL+OCFVYTUnI4UNcGa0Q9yeoF+xKbErORk jY+jPI0tt4zSf2gCJe03P2EV8XovgjSwhl5m2Ar2pPvA3dk5UzuG6C1CBQBnPgrypFpf QFZH3CZnkh7fzJbxKruwaUHK01ibACwqRTU1Y8QZtospKIZxRWu3nsuv8Gl43GCB+Bmh h6R7gg6Vf+hCftNpRFeKzQFSEPgHhkdi8lS76YQaa/gE5sr8kQYzYU3p/DjiDr7gtuqs UiK0+FwzOu16S243O+ASLLxsFSlErYP3iqWW2pLiiRPSmdS3vKARLKpRS4zKCFo64AdS XYKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=eUV7NYFJOYRPWEVh0G/EU6zT1t7HGJ6qLPZoOxwFJX0=; b=MPUEB1sW/lYsLzGIpvQseMG4MAFkDJ/VIclxmkqFqYz4E6TZVOhUvKkRsIKDLk4W4r FJDGR2cRI3ZSud0mNx2wGhz6YEFWWpL3ztePBMIitHNlCZJY7XRzxeMu1QP7CfE1y5Np F+/Bi7h8nULDHsHwTXQBvydQKiYR+MFB6Dk1gYOYQ3nb4JZOyoxxalS223OMfaEiTGUo yrY7Guz2hPpQqvVt/3jVC2BHAcbBpTH491auR2F3YICoF/hfZ8p/p3rZ1fvSRf1/CeH0 tfmBny1mjVwSkrs77C+p3pa0sAlc6nmeyk78Vckg48ZbH9MZaoYPXPfOEtVXHiCyU5x0 Jdxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=i6rR4UWr; dkim=neutral (no key) header.i=@linutronix.de header.b=DKb9EMCX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r19-20020a05640251d300b00461c852af19si17155475edd.633.2022.11.16.08.23.35; Wed, 16 Nov 2022 08:23:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=i6rR4UWr; dkim=neutral (no key) header.i=@linutronix.de header.b=DKb9EMCX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235008AbiKPQWr (ORCPT + 99 others); Wed, 16 Nov 2022 11:22:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233533AbiKPQWE (ORCPT ); Wed, 16 Nov 2022 11:22:04 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60129E62 for ; Wed, 16 Nov 2022 08:22:03 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615720; 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=eUV7NYFJOYRPWEVh0G/EU6zT1t7HGJ6qLPZoOxwFJX0=; b=i6rR4UWrVsi6o7VcT0dSMzT5OauKeph8Ma1KOTE1b3BM6zKYwJAEGVd6iEJRPcFdOzFCsV HFHmgCNxA9Fub/V2HRwn5xTn33moUGNvgJO1eRSW7ZjzDCd6FDzinZgDymoEquukHZHHq8 s0CfN3++aC4Wd7OuFwJFvCQsDYHtBi7rsrcCbu9lZoG91wvkVze/0dhNIfwRkt0O7vFlHa rE7O6ZmuYj60l/uRvg4R+LV7hz+mhxPJqdVMQJcBtOHc7Hs81xukaMun6CQZh40u/UZ7RM NeBEbscz4y231v4m1OKF/5nSrs2B2K8EMQ5CSNYZsDingtF4zCMr28jZldooGg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615720; 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=eUV7NYFJOYRPWEVh0G/EU6zT1t7HGJ6qLPZoOxwFJX0=; b=DKb9EMCX8Wi5FM8m4Bsdn/mxAv1cbCLE/1Q/F6hUtEvssXkb+GtLbarPzOkGGdX5WYOnik tlusV+pfZJZlBrAA== 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 v5 07/40] um: kmsg_dump: only dump when no output console available Date: Wed, 16 Nov 2022 17:27:19 +0106 Message-Id: <20221116162152.193147-8-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670522340151577?= X-GMAIL-MSGID: =?utf-8?q?1749670522340151577?= The initial intention of the UML kmsg_dumper is to dump the kernel buffers to stdout if there is no console available to perform the regular crash output. However, if ttynull was registered as a console, no crash output was seen. Commit e23fe90dec28 ("um: kmsg_dumper: always dump when not tty console") tried to fix this by performing the kmsg_dump unless the stdio console was behind /dev/console or enabled. But this allowed kmsg dumping to occur even if other non-stdio consoles will output the crash output. Also, a console being the driver behind /dev/console has nothing to do with a crash scenario. Restore the initial intention by dumping the kernel buffers to stdout only if a non-ttynull console is registered and enabled. Also add detailed comments so that it is clear why these rules are applied. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- arch/um/kernel/kmsg_dump.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c index 0224fcb36e22..40abf1e9ccb1 100644 --- a/arch/um/kernel/kmsg_dump.c +++ b/arch/um/kernel/kmsg_dump.c @@ -17,13 +17,22 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, unsigned long flags; size_t len = 0; - /* only dump kmsg when no console is available */ + /* + * If no consoles are available to output crash information, dump + * the kmsg buffer to stdout. + */ + if (!console_trylock()) return; for_each_console(con) { - if(strcmp(con->name, "tty") == 0 && - (con->flags & (CON_ENABLED | CON_CONSDEV)) != 0) { + /* + * The ttynull console and disabled consoles are ignored + * since they cannot output. All other consoles are + * expected to output the crash information. + */ + if (strcmp(con->name, "ttynull") != 0 && + (con->flags & CON_ENABLED)) { break; } } From patchwork Wed Nov 16 16:21:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21140 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp232519wru; Wed, 16 Nov 2022 08:23:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf5W5xEiCILYmiLakhaApEq35MciE+GhM75y2OZZDUhBgu9OybUtNeCe4NIJwdkkiLj4VWgI X-Received: by 2002:a63:c116:0:b0:46a:e818:b622 with SMTP id w22-20020a63c116000000b0046ae818b622mr20944823pgf.550.1668615831266; Wed, 16 Nov 2022 08:23:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615831; cv=none; d=google.com; s=arc-20160816; b=oO/6RCMjlD0ZV3aXBYEMaNVm94HRWlRROzqiTlV3PGq6OE2g/ZSVuCpe2j8noxrMqK /Fm2tGQEO1jVDN701fpbvzXZPI6KmuvYWb3rxDiA1ndlqNskdVcajbjzjoW/LY+Aso2I ynPz+TH8ej5HTp96YB0mMKx2eHQF+sikuZoTeWtBN6ogF2Y9uH9TM+PQhjapjBpIjxQh wxZvaKJPHjlBuFsNy8X2/outnLUjfUkDCoFB68ru13ceGN1LA1EIe1wBfLHSkW4oPXxR 11mRvkMgVJUgPNiU4W3S1WjUdlSSgaf+qXEwFj7NoTlslUph7jvKeGygyyHyKvgMBGYQ U45A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=OX8P8PjcP3et+B8RxGuAu/qJSUE13puFYmEXVzvc8MY=; b=jKUuN47lB3TgbSmijr4TrLw280L2BSFKMVHdfdo82bptMg17HZuIhF8bVSfhtwgY4f AGsfW0cfuRAb5a45+PuiGma1ewrGLW14H5QrSVm7/K5IFuDQTU8qg+3u+nkB5W8LlNjD 8ftjYBL/YEYAu5k4Q+aYRooJrq1U0yQEQq6TRtRS5JW4j7ig8SgIAYgbEesXXv31h5eK R6BVanIvasXecpwJ2/+iargUqq20qpd3NuDUsLS+Rt5rVTGJbtUiIarsA/9cByIb7Dda hA00/hi7U96rDubETG1YEj465YiwjqXtMY7vyKkL7skOwputO+oTXqRemzc62piSlH3f /fqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CEddAbi3; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c4-20020a170903234400b00172c1c6abc1si17941407plh.172.2022.11.16.08.23.34; Wed, 16 Nov 2022 08:23:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CEddAbi3; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234908AbiKPQWl (ORCPT + 99 others); Wed, 16 Nov 2022 11:22:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233536AbiKPQWE (ORCPT ); Wed, 16 Nov 2022 11:22:04 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60F56326F5; Wed, 16 Nov 2022 08:22:03 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615721; 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=OX8P8PjcP3et+B8RxGuAu/qJSUE13puFYmEXVzvc8MY=; b=CEddAbi3RzraEuQWrV50K39HBCaBs5n1hbnWKQvKdxtvYvNn7qth0mD3hPQU/k5IM6/6jI tsakH1BSYxyMEWSQ+SYJ0ZbSLVzyVLLN6/OuY208TtKzgXC6M7StlhGoOqITVvqEeeSE2M X8Is4GU+dlc+eKJOSLahx8apQ/7CBFU4io8nbjAZNv2xNFB/IGOy7i8ahbNIx2TlwkTdyz ibPl1VaO0F9fOd8M9cClH3/bgDQIBr7zIZlGTmpNxRMFTCwefsc+Ksw5eBzns2iBBhnSdp K1UNeEN6Iqb9zCaC3+k2B4ePn7UMXh2KRldr715r7YqNpg/80ijcaDxMTepW6w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615721; 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=OX8P8PjcP3et+B8RxGuAu/qJSUE13puFYmEXVzvc8MY=; b=wWUGVs3m5zf238cl2T7E7PtRK7QDcJHWNVj1NK/JvMgbbu2/yMeyvExDpCJ6+ELC+PGYAH BBDa/hEaxQ3F/JAw== 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 v5 08/40] tty: serial: kgdboc: document console_lock usage Date: Wed, 16 Nov 2022 17:27:20 +0106 Message-Id: <20221116162152.193147-9-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670513950750858?= X-GMAIL-MSGID: =?utf-8?q?1749670513950750858?= 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: Greg Kroah-Hartman Reviewed-by: Douglas Anderson Reviewed-by: Daniel Thompson 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 e76f0186c335..5be381003e58 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -530,6 +530,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 and race-free reading of @flags. + */ console_lock(); for_each_console(con) { if (con->write && con->read && From patchwork Wed Nov 16 16:21:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21150 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233207wru; Wed, 16 Nov 2022 08:25:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf4QnYljy5Mgm8dPVMmh00e6uBiRIUbQUgi9EKSSIjokBamwdj4ek1zD9VJkqIvKoxoylMMO X-Received: by 2002:a17:90a:3f89:b0:217:90e0:3f8c with SMTP id m9-20020a17090a3f8900b0021790e03f8cmr4465806pjc.192.1668615923593; Wed, 16 Nov 2022 08:25:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615923; cv=none; d=google.com; s=arc-20160816; b=H1AmMcS/6v1Rx1aVSRSdBe9xCGk5nAEiMXC60ngsGB3eThvYT1IV2X3ocx/soO1SLh poDojhrrB0ZiNkQ0FH1Kte9UXwtD6twoD8XG5rYcPL58tL7gHVuOLEyKj8jxAqsoupxB XQeGl+lio9j7nOagbUeD1yi8fK/LnycLrZMiUO6dg8cS8W953XrLoO0Me8+NmJFDRAkY PiAmWtPjkKBJHUuC9R0rRUqecmaNtkN4RZe9P4sz02DBy2gFbAHed1EZBrq6hY4rrmKw 6gGfC4KymXq52dhAWGm4GidMa1fxuGH9RJny0QCVh60rCIloP6+qXtT0gsb9WXvEAWTS FpVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=6POxijvlWYTfJk68FJg54j07I7MpPRBTNu3UsEFQG6Y=; b=u+3brIg9NUZrAkYSOrjHBRwdSk0oiRDKbp+DqZjBhODdl72PFyAV8EJzOfamK05yuJ rtBdFheXQvtDbqHNWEuFBDrvTh6biyhe38mcx8+lbkadvrzz/uD8yVeOo3PaozaoYlGL nIHJtGnh04UT582jpLu6BcQqiC5NtGi1WMTPhJCzZmphBcNLl/suBc+clsYod/cklF4N gF/ek5G8V0fL5fbiZMudsb30OB6DVKn6RG4wTt/Q6XQrZQSee8PGyuf2M/0hdhXsRAqU N3HElSQOyOIQTfeL5yABDDhb8xSGayaSC95lvqyC6XO+6N85J++LmMA2IlS3gUE+hnpH epTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OebKUG+9; dkim=neutral (no key) header.i=@linutronix.de header.b=B51xiNcC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n3-20020a638f03000000b00476b6fa2963si3051628pgd.599.2022.11.16.08.25.09; Wed, 16 Nov 2022 08:25:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OebKUG+9; dkim=neutral (no key) header.i=@linutronix.de header.b=B51xiNcC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234780AbiKPQWh (ORCPT + 99 others); Wed, 16 Nov 2022 11:22:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233565AbiKPQWE (ORCPT ); Wed, 16 Nov 2022 11:22:04 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7591C4387A for ; Wed, 16 Nov 2022 08:22:03 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615721; 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=6POxijvlWYTfJk68FJg54j07I7MpPRBTNu3UsEFQG6Y=; b=OebKUG+9hP69pRlZMztMu0OHTK0KmUwcaRtKZFHo5zqyxDOLI65rXuEET4p1Lk1V+7m0f3 7x10qYARiDy6hBZPGK6/eBM5e0tGVfVLLq0NITUsDAEgNa+4ywiA9Yg+rmjkwBOWCh4mN6 2wdIFM5W9Q50P5rD5AAye7Mu+gsKGSmUizLR3B2K9Id+i/01EEdGIuaGY4NcxnXfr8rWgW 8a5BQHscjbfIDbTPwi5zAl9JIHQqvkctfgIkseR6QoLsaNgOvkkfTI/FsYqPWlxSg+T74Q pyqCWXCqxiPPwM5dhO0rgRPNcPEkryBYtlOEf5+KvmyK2XMVJ1n9dlOBhUqAwA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615721; 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=6POxijvlWYTfJk68FJg54j07I7MpPRBTNu3UsEFQG6Y=; b=B51xiNcCGa1IY9q1AAsoLFLq22Zmf3cYE2XoyKGJbHGKFoq0JcF8rDLof3zNoY/T1BrlGv Qb/xofw3wS72f9Dw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH printk v5 09/40] tty: tty_io: document console_lock usage Date: Wed, 16 Nov 2022 17:27:21 +0106 Message-Id: <20221116162152.193147-10-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670610401272503?= X-GMAIL-MSGID: =?utf-8?q?1749670610401272503?= 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: Petr Mladek --- drivers/tty/tty_io.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index de06c3c2ff70..ee4da2fec328 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3526,6 +3526,16 @@ static ssize_t show_cons_active(struct device *dev, struct console *c; ssize_t count = 0; + /* + * 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 and + * race-free reading of @flags. + * + * Take console_lock to serialize device() callback with + * other console operations. For example, fg_console is + * modified under console_lock when switching vt. + */ console_lock(); for_each_console(c) { if (!c->device) From patchwork Wed Nov 16 16:21:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21157 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233487wru; Wed, 16 Nov 2022 08:25:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf7/d+kaJaYxRebOdiAbJOUmdEg4WuaQ5T8HMJCXMtkQHaUNBfAH49z7hSmVZStk1+DUByYd X-Received: by 2002:a17:902:b598:b0:186:8516:cd5f with SMTP id a24-20020a170902b59800b001868516cd5fmr9796447pls.11.1668615957803; Wed, 16 Nov 2022 08:25:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615957; cv=none; d=google.com; s=arc-20160816; b=WpsM/IHVbk43qay2cHvmX5zjxRGXQigoLqnDa4kuy8hMzt+EC4Elv/3gtI66cTsaFH FRgJ13Hn54ekpiPGy0Eq1OdSPgddS4lUyVMkHBtu3xxjU2WTRP6vQmgmW/afXvpIBWgF sF/aBOsyVgFKB+VRIlOxSwDr47CVYK2lJEVptnmbdZ91fV9zdTpzLtgehXQK8YBwuGjO 4r7FS9IYusx0J8gIRMMguUXqKqZPyVmJE6lUf1uD0hWYqGWmZlv+p+7DnyMknrrJwQll +vDaiNfWf0tzp4w7b1azC9Z7G/RagH50eV33Pee0zl9mZmVeYb6BrU3WA148hch0yXul r4nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=WyGtVM99u5kVDH70iZExE1J1KzxzFf6H5/dTCHJGWmg=; b=ieOg0TnZ+Krvtfn7MsgXK8z7fxIE8EXYwXmo2Outf0FwxZWeWW3LwrYratywrq7oqj Nge48x9JY8XxoDdiNcM+2bi0ujzRNu7kJjHTrlJhqIQ9fuAD8jQlgIGaOraXW9CM/Y7c Yxe8DCi/5t2k59engZ4nGUxl8+t5Osk1+doTzSKiCiVjPE8aLtv8KoHzWQJDqi8B0r0F ZRIaDEpdolKU7DDt0qa5sdCXpfVyv1hLAZ2sonO3SNvJ2Nl0F/2pPZRZgltKdiI39hXr dxLj9y0924BJKBfI7R/caMJ9mhGDCXmaNGpFbw6fvAe3683HTmBLF5FEwnz/t9lt9b3n VUiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OkggJBlH; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b22-20020a056a000cd600b0056d67d820ecsi16693460pfv.258.2022.11.16.08.25.45; Wed, 16 Nov 2022 08:25:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OkggJBlH; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235995AbiKPQWt (ORCPT + 99 others); Wed, 16 Nov 2022 11:22:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233587AbiKPQWE (ORCPT ); Wed, 16 Nov 2022 11:22:04 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE17D49B68; Wed, 16 Nov 2022 08:22:03 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615722; 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=WyGtVM99u5kVDH70iZExE1J1KzxzFf6H5/dTCHJGWmg=; b=OkggJBlHCa9L4cp9ZDwwAsfL5ubRsoOncME3GDT90isJ+qp7J73h9NygngEEZiEoWr+es/ 3Upl4H1KrQnB9vC4v5gJ8xNfgM03fTyq0Hvw3HyW+NTRBO9RDXHTzuY5yyRaWNip4KoUlo jv8o3KtDRDJ5vnJjCybJF2iNMAlOfQr0Z0EssP9z6UoZbQUp+vf741jMgzncq8Q944gZyU q/EDZaCvZe+84tYeDpcZt+1MrsFtlBB5PuIi0o6f70Fv1eF0z3tUS8sMp3rL7kwVtceE+v QzzsEhnN/iuaaeQLCD0aYQE0OgwigXV3QCHRchsu1ujqaQU2+c+KX3u9rJFQzQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615722; 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=WyGtVM99u5kVDH70iZExE1J1KzxzFf6H5/dTCHJGWmg=; b=05p9Fgr9oIC1rseJZa7drAisqg0/FWrb79iEbbJ3VXznN77H03kThzDxWjsXNFc/82FzCY mJAwymv7Gr0kdEBw== 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 v5 10/40] proc: consoles: document console_lock usage Date: Wed, 16 Nov 2022 17:27:22 +0106 Message-Id: <20221116162152.193147-11-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670646759914535?= X-GMAIL-MSGID: =?utf-8?q?1749670646759914535?= 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 Reviewed-by: Petr Mladek --- fs/proc/consoles.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c index cf2e0788f9c7..46b305fa04ed 100644 --- a/fs/proc/consoles.c +++ b/fs/proc/consoles.c @@ -63,6 +63,15 @@ static void *c_start(struct seq_file *m, loff_t *pos) struct console *con; loff_t off = 0; + /* + * Take console_lock to serialize device() callback with + * other console operations. For example, fg_console is + * modified under console_lock when switching vt. + * + * Hold the console_lock to guarantee safe traversal of the + * console list. SRCU cannot be used because there is no + * place to store the SRCU cookie. + */ console_lock(); for_each_console(con) if (off++ == *pos) From patchwork Wed Nov 16 16:21:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21147 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp232933wru; Wed, 16 Nov 2022 08:24:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5MU2Z9HyOCvDbLL76GwqTUYF6YWJXj39Ylp0tZ7xJf98Ix5CWq7khMZVULP5sKIn7ZRRMA X-Received: by 2002:a63:db03:0:b0:470:4f30:f743 with SMTP id e3-20020a63db03000000b004704f30f743mr21526007pgg.434.1668615882453; Wed, 16 Nov 2022 08:24:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615882; cv=none; d=google.com; s=arc-20160816; b=GAGVYb2IVjH1bNkNfONd93dtYsRDHjVzH1yqyKZ+ANSD52SYnXxfuCCPdHKZ+GmtuS b0QaJM73qQkg/utAjjp9FnjzsqVbjAiEQ/RfRNR1s8UtsHLhN2XfsPodVX/9EuLQ+rHh O+Fe1Lc4I6FK5mjAdwVjiHaK5Xe+hhejraL6qHxepkZzT+xPulgCiULzjTiByAgJzJAA o19+RYCwKZzvf4bXHgRrLVho5Cy5PWfuzwyuZgZSo7GdrayS4ItAafLS+Jg6EN7EuPTQ 7KLjsLgieJPHuJlyzNNP7dbT6SijpZvcCvgu9WEIDjvHHmnfjuyH/7HItwQfSwdnJkfk jz0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=D0yiqlWHKjUfN3CTpeVT5faO7XM4VrtxPaB39KRWxC4=; b=XaySz7ozucW297ap5M8s+VioBseWEQBVh5q8z6KBqxLxClKHyYMbwDB7b8Yx1WT+/l zAl+nNBGoyKKkrZtAtnHVrPx191mECswGV0LCMcmWVqJAMBHrMlsoQY+O77e6qp5jtWo GV/cUWaQJfH6qOEequ+8ztCpc8XAO0DQXRoSZY45NtCyuu5ngJQh2I4BnaNd1eB6RZ2D xJfVARVlfz8PJsEMG1CrPwzCN93OT8Q5AJv7A3tVTqKggpr6j8au7cR64DJGFaj/RnGh E2HfxZ2efXhaeOkEgyXwvDvmm6hPzD2c1RXgvi9nBuRwmHUcFXuXu738pfSalgnFORnY kwJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=leXe4QiZ; dkim=neutral (no key) header.i=@linutronix.de header.b=bs4SNRb8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s207-20020a632cd8000000b0044d72a10aafsi15314312pgs.34.2022.11.16.08.24.29; Wed, 16 Nov 2022 08:24:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=leXe4QiZ; dkim=neutral (no key) header.i=@linutronix.de header.b=bs4SNRb8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238629AbiKPQXe (ORCPT + 99 others); Wed, 16 Nov 2022 11:23:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234097AbiKPQWF (ORCPT ); Wed, 16 Nov 2022 11:22:05 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 400D3D135 for ; Wed, 16 Nov 2022 08:22:04 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615722; 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=D0yiqlWHKjUfN3CTpeVT5faO7XM4VrtxPaB39KRWxC4=; b=leXe4QiZ8wRz2PSCRAhU/lDyJUQZx/C9+KNbQm3NhkUvsJknkIxst5BOwG1NHXphhW2+zy Psu3YtQflD+Mn16JYVZRTv5Ug8RuRcOGwGxoZq6MkTvaaA3/gGFP42DczeskmHVszdHO4f VJZ154DGj+Vt5l6hLuRjAsggFAoxJ/b6CEpQB5d6etgsAzwp40HcYrv66RumHnXYwqodPA YEf03aZdE0DHIHuq5zoSbA8k4ax6MqZUJgP1MU3xhOLV274l8GdQBmSWdR4RC75AL2JbcF kdvjPVE1B+sCVb768wfXJTV3L5Pju0DFvyeNJLsCoKyDVrN4MHiGkPr8DKdmQQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615722; 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=D0yiqlWHKjUfN3CTpeVT5faO7XM4VrtxPaB39KRWxC4=; b=bs4SNRb8D5u+/TLixYX3sXC1rR1UQXL6oe89iQZTTQ8PSp9QCiQFsQF8s1zkSoZ9YZv23A MYer/DRq2d7D0eAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v5 11/40] printk: introduce console_list_lock Date: Wed, 16 Nov 2022 17:27:23 +0106 Message-Id: <20221116162152.193147-12-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670567407119397?= X-GMAIL-MSGID: =?utf-8?q?1749670567407119397?= Currently there exist races in register_console(), 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. It might be possible to fix these races using the console_lock. But it would require a complex analysis of all console drivers to make sure that the console_lock is not taken in match() and setup() callbacks. And we really prefer to split up and reduce the responsibilities of console_lock rather than expand its complexity. Therefore, introduce a new console_list_lock to provide full synchronization for any console list changes. In addition, also use console_list_lock for synchronization of console->flags updates. All flags are either static or modified only during the console registration. There are only two exceptions. The first exception is CON_ENABLED, which is also modified by console_start()/console_stop(). Therefore, these functions must also take the console_list_lock. The second exception is when the flags are modified by the console driver init code before the console is registered. These will be ignored because they are not visible to the rest of the system via the console_drivers list. Note that one of the various responsibilities of the console_lock is also intended to provide console list and console->flags synchronization. Later changes will update call sites relying on the console_lock for these purposes. Once all call sites have been updated, the console_lock will be relieved of synchronizing console_list and console->flags updates. Suggested-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- include/linux/console.h | 23 +++++++++-- kernel/printk/printk.c | 88 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 99 insertions(+), 12 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index f4f0c9523835..24d83e24840b 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -158,6 +158,14 @@ struct console { struct hlist_node node; }; +#ifdef CONFIG_LOCKDEP +extern void lockdep_assert_console_list_lock_held(void); +#else +static inline void lockdep_assert_console_list_lock_held(void) +{ +} +#endif + #ifdef CONFIG_DEBUG_LOCK_ALLOC extern bool console_srcu_read_lock_is_held(void); #else @@ -170,6 +178,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); +extern void console_list_lock(void) __acquires(console_mutex); +extern void console_list_unlock(void) __releases(console_mutex); + extern struct hlist_head console_list; /** @@ -186,10 +197,16 @@ extern struct hlist_head console_list; 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 +/** + * for_each_console() - Iterator over registered consoles + * @con: struct console pointer used as loop cursor + * + * The console list and the console->flags 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) extern int console_set_on_cmdline; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index c84654444a02..f7479fd73114 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -78,6 +78,13 @@ EXPORT_SYMBOL(ignore_console_lock_warning); int oops_in_progress; EXPORT_SYMBOL(oops_in_progress); +/* + * console_mutex protects console_list updates and console->flags updates. + * The flags are synchronized only for consoles that are registered, i.e. + * accessible via the console list. + */ +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. @@ -103,6 +110,11 @@ static int __read_mostly suppress_panic_printk; static struct lockdep_map console_lock_dep_map = { .name = "console_lock" }; + +void lockdep_assert_console_list_lock_held(void) +{ + lockdep_assert_held(&console_mutex); +} #endif #ifdef CONFIG_DEBUG_LOCK_ALLOC @@ -227,6 +239,40 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, } #endif /* CONFIG_PRINTK && CONFIG_SYSCTL */ +/** + * console_list_lock - Lock the console list + * + * For console list or console->flags updates + */ +void console_list_lock(void) +{ + /* + * 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. + * + * Detecting if this context is really in the read-side critical + * section is only possible if the appropriate debug options are + * enabled. + */ + WARN_ON_ONCE(debug_lockdep_rcu_enabled() && + srcu_read_lock_held(&console_srcu)); + + 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 @@ -3020,9 +3066,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 &= ~CON_ENABLED; console_unlock(); + console_list_unlock(); /* * Ensure that all SRCU list walks have completed. All contexts must @@ -3036,9 +3084,11 @@ EXPORT_SYMBOL(console_stop); void console_start(struct console *console) { + console_list_lock(); console_lock(); console->flags |= CON_ENABLED; console_unlock(); + console_list_unlock(); __pr_flush(console, 1000, true); } EXPORT_SYMBOL(console_start); @@ -3187,6 +3237,8 @@ static void console_init_seq(struct console *newcon, bool bootcon_registered) #define console_first() \ hlist_entry(console_list.first, struct console, node) +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 @@ -3213,13 +3265,14 @@ void register_console(struct console *newcon) bool realcon_registered = false; int err; + console_list_lock(); + for_each_console(con) { if (WARN(con == newcon, "console '%s%d' already registered\n", - con->name, con->index)) - return; - } + con->name, con->index)) { + goto unlock; + } - for_each_console(con) { if (con->flags & CON_BOOT) bootcon_registered = true; else @@ -3230,7 +3283,7 @@ void register_console(struct console *newcon) if ((newcon->flags & CON_BOOT) && realcon_registered) { pr_info("Too late to register bootconsole %s%d\n", newcon->name, newcon->index); - return; + goto unlock; } /* @@ -3261,7 +3314,7 @@ void register_console(struct console *newcon) /* printk() messages are not printed to the Braille console. */ if (err || newcon->flags & CON_BRL) - return; + goto unlock; /* * If we have a bootconsole, and are switching to a real console, @@ -3320,16 +3373,21 @@ void register_console(struct console *newcon) 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); -int unregister_console(struct console *console) +/* Must be called under console_list_lock(). */ +static int unregister_console_locked(struct console *console) { int res; + lockdep_assert_console_list_lock_held(); + con_printk(KERN_INFO, console, "disabled\n"); res = _braille_unregister_console(console); @@ -3378,6 +3436,16 @@ int unregister_console(struct console *console) return res; } + +int unregister_console(struct console *console) +{ + int res; + + console_list_lock(); + res = unregister_console_locked(console); + console_list_unlock(); + return res; +} EXPORT_SYMBOL(unregister_console); /* @@ -3430,6 +3498,7 @@ static int __init printk_late_init(void) struct console *con; int ret; + console_list_lock(); hlist_for_each_entry_safe(con, tmp, &console_list, node) { if (!(con->flags & CON_BOOT)) continue; @@ -3447,9 +3516,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(); ret = cpuhp_setup_state_nocalls(CPUHP_PRINTK_DEAD, "printk:dead", NULL, console_cpu_notify); From patchwork Wed Nov 16 16:21:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21145 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp232711wru; Wed, 16 Nov 2022 08:24:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf5FAKzEFh2zloNOqO3kDbGSxOZJ+3JUZBcv2gYQ9cPGEK3KQlhD7/nSz1ImfRX9nMaZbQ8I X-Received: by 2002:a63:1720:0:b0:46f:f93b:ddc8 with SMTP id x32-20020a631720000000b0046ff93bddc8mr20478838pgl.389.1668615856395; Wed, 16 Nov 2022 08:24:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615856; cv=none; d=google.com; s=arc-20160816; b=kQoOSCtrebNWtx+RFfdqyee90C7v1hjR/lVVZk/Uq6ZgtIZgzsQD+oDx/PwK+evRgC o9eBaH7n+JYLCKWKi4bisBGKP7SHYrQFdM1NGaLWccQ2e+kHoJqYyIX3Bc2GJOqbRV0K fhn6vbrzbgp0fk4lsUo1OUJMoQzX0Rep2yhZap8g2lyqF62BHnjpREjb5tJskCXr/exH zGBt3ZWjIeLX/im7rF3wUWrT6hNK+cFHy4lQbnjegFLW+mPPQFl5LnXlIKcIhLqu5Guz vzQO6uvXLPZECmZq3Ebyvp5wuPci2HvXUDqpVY7glgizcdNE/RUe+Kq8rhmyM9sCvfCJ dFCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=dwik/3763uUHWTxRRunPLlxyK1IUw8NqJotbljpAOY4=; b=vVc1Hm4ya9aMkUeOH/4LWL9juxFGO1JQAxr3E4V72nXGaRrRUBLZ9x3JfEeF3KDQyu 0yGnx8QZzRhNGThmZ+A9y3jr/lfUYggWId63WWa7m5pEogPU/8Abf4QnXmNC5Gyfb2WD Hxcspy8lDTsNEcw3h5m+TqCtwfah0FpnkAMdYnon0IIQbSls/OLagVrKOdT7tugv/1wW EgzDNMx6d7n+S004WxThjdWkmQCQGiaGzgafOKFPFtEZXbbFgTCu5cZGbYQeBIYwu0CK U6gJwMmiECo0ORRxxg8ooZPkxdy6P27iRYP/7ZyKUTGm+RgDXtNmHq9/LPfHOgVpU0OK idHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JaroB9hP; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y4-20020a170902cac400b0016cca53817dsi12826239pld.341.2022.11.16.08.24.03; Wed, 16 Nov 2022 08:24:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JaroB9hP; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238402AbiKPQXK (ORCPT + 99 others); Wed, 16 Nov 2022 11:23:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234117AbiKPQWF (ORCPT ); Wed, 16 Nov 2022 11:22:05 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B01B143856 for ; Wed, 16 Nov 2022 08:22:04 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615723; 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=dwik/3763uUHWTxRRunPLlxyK1IUw8NqJotbljpAOY4=; b=JaroB9hPopOfMxbrqK090Z6M7wyOVm0NA0cKZ/SDYVDZGLIkZT9+z6j2ZZwuc03pmrhTbf eux7prTSPhbkaV7o+K8JCq3wHjSfQBJhtez+j65ip10w9XcNvBOruUuIJ7k6YWFkSIhK8l CYPGprrzT+Ybcf3PEIDSohCq/5yNXbnpKbq1BS51PUZU2bAktoTAlvpazS3mTtYn7oPWuE j+VWpzgR/+8mJ2ibx7C3hxVVVtN0OVa+iQLPGCbXznNFQU/M8E/MqmLhG6tQufxdiCmYmj oncn8PFDf8RnWTnyreefgQ9xHQZF1LLdVi4Rmcc3al8S7oRvm3fceP69GYfZNA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615723; 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=dwik/3763uUHWTxRRunPLlxyK1IUw8NqJotbljpAOY4=; b=C8fSR7WZSQABfcv0J42d47XCNSOx+CBmi+brrOhA6dvtvdINUAEBbCH7+QH107YGjCCeAB H2Lo20plN1YMKYCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v5 12/40] console: introduce wrappers to read/write console flags Date: Wed, 16 Nov 2022 17:27:24 +0106 Message-Id: <20221116162152.193147-13-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670540299056678?= X-GMAIL-MSGID: =?utf-8?q?1749670540299056678?= After switching to SRCU for console list iteration, some readers will begin readings console->flags as a data race. Locklessly reading console->flags provides a consistent value because there is at most one CPU modifying console->flags and that CPU is using only read-modify-write operations. Introduce a wrapper for SRCU iterators to read console flags. Introduce a matching wrapper to write to flags of registered consoles. Writing to flags of registered consoles is synchronized by the console_list_lock. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- include/linux/console.h | 45 +++++++++++++++++++++++++++++++++++++++++ kernel/printk/printk.c | 10 ++++----- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 24d83e24840b..c1ca461d088a 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -183,6 +183,51 @@ extern void console_list_unlock(void) __releases(console_mutex); extern struct hlist_head console_list; +/** + * console_srcu_read_flags - Locklessly read the console flags + * @con: struct console pointer of console to read flags from + * + * This function provides the necessary READ_ONCE() and data_race() + * notation for locklessly reading the console flags. The READ_ONCE() + * in this function matches the WRITE_ONCE() when @flags are modified + * for registered consoles with console_srcu_write_flags(). + * + * Only use this function to read console flags when locklessly + * iterating the console list via srcu. + * + * Context: Any context. + */ +static inline short console_srcu_read_flags(const struct console *con) +{ + WARN_ON_ONCE(!console_srcu_read_lock_is_held()); + + /* + * Locklessly reading console->flags provides a consistent + * read value because there is at most one CPU modifying + * console->flags and that CPU is using only read-modify-write + * operations to do so. + */ + return data_race(READ_ONCE(con->flags)); +} + +/** + * console_srcu_write_flags - Write flags for a registered console + * @con: struct console pointer of console to write flags to + * @flags: new flags value to write + * + * Only use this function to write flags for registered consoles. It + * requires holding the console_list_lock. + * + * Context: Any context. + */ +static inline void console_srcu_write_flags(struct console *con, short flags) +{ + lockdep_assert_console_list_lock_held(); + + /* This matches the READ_ONCE() in console_srcu_read_flags(). */ + WRITE_ONCE(con->flags, flags); +} + /** * for_each_console_srcu() - Iterator over registered consoles * @con: struct console pointer used as loop cursor diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index f7479fd73114..35018f18f5aa 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3068,7 +3068,7 @@ void console_stop(struct console *console) __pr_flush(console, 1000, true); console_list_lock(); console_lock(); - console->flags &= ~CON_ENABLED; + console_srcu_write_flags(console, console->flags & ~CON_ENABLED); console_unlock(); console_list_unlock(); @@ -3086,7 +3086,7 @@ void console_start(struct console *console) { console_list_lock(); console_lock(); - console->flags |= CON_ENABLED; + console_srcu_write_flags(console, console->flags | CON_ENABLED); console_unlock(); console_list_unlock(); __pr_flush(console, 1000, true); @@ -3342,7 +3342,7 @@ void register_console(struct console *newcon) } else if (newcon->flags & CON_CONSDEV) { /* Only the new head can have CON_CONSDEV set. */ - console_first()->flags &= ~CON_CONSDEV; + console_srcu_write_flags(console_first(), console_first()->flags & ~CON_CONSDEV); hlist_add_head_rcu(&newcon->node, &console_list); } else { @@ -3399,7 +3399,7 @@ static int unregister_console_locked(struct console *console) console_lock(); /* Disable it unconditionally */ - console->flags &= ~CON_ENABLED; + console_srcu_write_flags(console, console->flags & ~CON_ENABLED); if (hlist_unhashed(&console->node)) { console_unlock(); @@ -3418,7 +3418,7 @@ static int unregister_console_locked(struct console *console) * console has any device attached. Oh well.... */ if (!hlist_empty(&console_list) && console->flags & CON_CONSDEV) - console_first()->flags |= CON_CONSDEV; + console_srcu_write_flags(console_first(), console_first()->flags | CON_CONSDEV); console_unlock(); From patchwork Wed Nov 16 16:21:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21146 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp232773wru; Wed, 16 Nov 2022 08:24:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf7S9HROEmLy0diCLlQAuRjDGTPwDZxzPLNpndCQ23TAj2Yjmj4EYpYb1x4WuOpJ8Xa1LJ7P X-Received: by 2002:a05:6402:40a:b0:461:a5ac:61d4 with SMTP id q10-20020a056402040a00b00461a5ac61d4mr19939813edv.340.1668615862907; Wed, 16 Nov 2022 08:24:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615862; cv=none; d=google.com; s=arc-20160816; b=y1GDabFK/mfPz1moscEajZrGSClyKYXQX/LlJ6AsTODeG4lyoKJuP+sgy8TyBZdTpp aebLPRInRkeYNU7eekSGbDyq8TpOYJjf5ba2CyBm4trTD6KYNbSa2KK0+npvEjdtpnqc gDgddJRuZmU2+JKL8T9lTCG8EDRqzZ2flKYV4+gneCM4aQ4QDODDrQBeJi9r+aVB4Enm 4YChu7zzBDQob2iypXGDSfJEZ/mmG1ikVo7EPjitQAaTGIFR1THhGQvmM8BBvXWQ4rjq FMGVE+yGvXnFyVxWSNTlrpxqYAVCP6fdIJuQm6Ms+IqoAofA7jjJLLHiJfnEooxYSu1E TJyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=GEhKO0dJc2f16pdA5isP3tyKiWxAMb8gJwHLg9bJtvU=; b=s+bMFaF6nYlNeeIrZzoYLmAvntKR53XJAGs80b5Q+3WUD2gAW2bPl5Z9tcVkSn/Xc7 2Rn7a09UGxMihdS1VgB8s5Dr6w2UUtbXis3sc2t6I3FJXWw94fDqao0ci6LLIqRl+z1V xxHlwR6iYz6Mto8Eexa/vu/n1GciwS+qdIq0ShOAhr/ZqKkrCnNUNBE+8w9b51tMSE0I 2Q5r8YJWyGY0JGHUavKP3Gi9yWV9J6PIYhUzOwLFW3KsRocBoVrDWPOvezuIwFyqtkp1 vnJayt/ftQYktqg6ZKWy9DiX5AjEgBIJTA5W9a+UGhA0zMmT6AWUx2plX3w459V32ajp dqAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=oIuBdriz; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=OZ7EGuhs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o22-20020a509b16000000b00462e23be64fsi13010272edi.578.2022.11.16.08.23.57; Wed, 16 Nov 2022 08:24:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=oIuBdriz; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=OZ7EGuhs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238258AbiKPQXH (ORCPT + 99 others); Wed, 16 Nov 2022 11:23:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234314AbiKPQWH (ORCPT ); Wed, 16 Nov 2022 11:22:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25EF849B6B for ; Wed, 16 Nov 2022 08:22:05 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615723; 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=GEhKO0dJc2f16pdA5isP3tyKiWxAMb8gJwHLg9bJtvU=; b=oIuBdriz4JcEynWjZAm586o5EvapOAFjcQM7Y2h/jaFjTqDiY6uPhp8aLR8nBjL3sNQ3Dd wHZzRlW7PVlMFZSrjuZBAdlaxGYKCPXOLT+eJt0Bx/Bf77XSVU/Sdj0fUXPID4f2JKMYWO xth7HR45tX4LCgAiYQR9UtjW3xY/OwKJbQ+MTsyvDkIBwVQsRDJgcmxvXQmLUsb4ji4IMo 1l0xna2GGygbTY1KnRexudbFu2wA9TeXsj853JqPUmudt8ywLyxwW5Iiqh0Ree6FU5BaTz iM41PTKy8qkj5y2nB37PhrfFjKOUabUIaaJMqZLYTWFwtJKpjb3tdQms5EUKig== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615723; 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=GEhKO0dJc2f16pdA5isP3tyKiWxAMb8gJwHLg9bJtvU=; b=OZ7EGuhsAVFVp8NSWYxYiCIDMCwa1My5MhuROv6LAzBXyKI2zB/l2XJjq2B5TvLEf2EdaF XZjkrE4iliwyN5CQ== 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 v5 13/40] um: kmsg_dumper: use srcu console list iterator Date: Wed, 16 Nov 2022 17:27:25 +0106 Message-Id: <20221116162152.193147-14-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670546981606235?= X-GMAIL-MSGID: =?utf-8?q?1749670546981606235?= Rather than using the console_lock to guarantee safe console list traversal, use srcu console list iteration. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- arch/um/kernel/kmsg_dump.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c index 40abf1e9ccb1..427dd5a61a38 100644 --- a/arch/um/kernel/kmsg_dump.c +++ b/arch/um/kernel/kmsg_dump.c @@ -16,29 +16,26 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, struct console *con; unsigned long flags; size_t len = 0; + int cookie; /* * If no consoles are available to output crash information, dump * the kmsg buffer to stdout. */ - if (!console_trylock()) - return; - - for_each_console(con) { + cookie = console_srcu_read_lock(); + for_each_console_srcu(con) { /* * The ttynull console and disabled consoles are ignored * since they cannot output. All other consoles are * expected to output the crash information. */ if (strcmp(con->name, "ttynull") != 0 && - (con->flags & CON_ENABLED)) { + (console_srcu_read_flags(con) & CON_ENABLED)) { break; } } - - console_unlock(); - + console_srcu_read_unlock(cookie); if (con) return; From patchwork Wed Nov 16 16:21:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21142 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp232614wru; Wed, 16 Nov 2022 08:24:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf7og/oDpoud78fXkro21fAaCiQRzaaBhcyyVotWefyBTa0wvC8a2bl+g/OgIX/TAScFN67h X-Received: by 2002:a17:902:7b81:b0:186:8518:6c97 with SMTP id w1-20020a1709027b8100b0018685186c97mr9759039pll.94.1668615845002; Wed, 16 Nov 2022 08:24:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615844; cv=none; d=google.com; s=arc-20160816; b=Yje0B4HN1Hf2mRkYQGsVB2g8y/hLwG2pcIWfch52GYnSd2Ab9wT6YXxnfgvX1NBTyt 5uBT88XWtzqyItxXxAzHTZC9IAsodlFGL1SyWkgpMkuYgovmyofHJjQgqkQFkPYzkRzv /WJF0YXmdPnENTlpQGF2vGejmejefHfKmQl8gI/iOyhR1cYbzAJeebSeRlOuvDJVB5BL wQL4LLwFe/N8jRFx7ebUzQ8Lebgsa9TfHvFVDgpatSzW5s+/+0A1YP78ZkCmrSjlFMrj iGIqKIc/RgdxBxp27mI4W/Yy82boff+B5QCkznsTK29stL9fUCLW859rKZORVc+8ODhr DYQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=/Z8Y08lU4gBzUjFFzV1bgJ9D4slaSXi2GlBsKiKXaB8=; b=IoJb2o8ffKb8jKjN92ASjuuZl+ryGOfD5gX+v/6oL8yUsm8+nyuQGBq/P5l2O+2qJw /MH8TgDmJDYnuh/MiU6+9ljYcr1AgxgdYfHbUjXrnFpJVdWJSYvE7o7qyq0KhWVtCVrM uma9vYRNQgA/ZTVaiibM378OTYMqx0uA3R/btgKDHPOXGorzL8/tzbp5+6LjhqSOuKiZ GEoyHj3G/m9GDkIBDx2rcHhWfKZtfYzReU9m87iPvdKfFyEOp2xPBINA8KZCM0pCUHhJ B7i/WYoaE/zVE/0i6yHveLMG6gvhbn/B1UQ8Rpxl3E2xHfGckJrSlPQrgaP/aD3AGShn 6mqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AlFnjhG6; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l6-20020a170903120600b0016bea2a8b16si7671951plh.364.2022.11.16.08.23.51; Wed, 16 Nov 2022 08:24:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AlFnjhG6; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233378AbiKPQW7 (ORCPT + 99 others); Wed, 16 Nov 2022 11:22:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234366AbiKPQWH (ORCPT ); Wed, 16 Nov 2022 11:22:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B178D4AF04 for ; Wed, 16 Nov 2022 08:22:05 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615724; 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=/Z8Y08lU4gBzUjFFzV1bgJ9D4slaSXi2GlBsKiKXaB8=; b=AlFnjhG6yoalddGZUFtJcAolOgncQCDPgISMOQ36V6hlKtWG/cSc/rczN/innYrbR/Jywt 6BvsgBT8OM0LI0Zl93AGE5DcOK1Hk6PuqLE9MA6ZMxEFV140/y9Mh5kvEiN3u+2H3AgdKK +yLeMp6/Iwq+h0Rj2BKXdtZip7O7SGTdH/pr5EM1c/UOFDnm/rWDQpxmN58Gn4s3l0jWhT iGumgzq8mY+cbvxvXW6Wg5Fr6sjE/yVmwbnkPerYdOX99Q0eOvyJBOl6ryyIUf2n5ylE35 XNUzA/3US4iPGW+at2fOIIkGxF9+2P6fccpt+a2QBG7OmpQDcRtLnBgi2WuoXA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615724; 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=/Z8Y08lU4gBzUjFFzV1bgJ9D4slaSXi2GlBsKiKXaB8=; b=UPIFaN5gtyWRJGSpTKiuex30w225CCf2nyuT23Yek69V+hFQwIVsUK9SGiI9NihuAmA3qc np5rsSzRcXc59rDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Aaron Tomlin , Luis Chamberlain , kgdb-bugreport@lists.sourceforge.net, Aaron Tomlin Subject: [PATCH printk v5 14/40] kdb: use srcu console list iterator Date: Wed, 16 Nov 2022 17:27:26 +0106 Message-Id: <20221116162152.193147-15-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670528581664609?= X-GMAIL-MSGID: =?utf-8?q?1749670528581664609?= Guarantee safe iteration of the console list by using SRCU. Signed-off-by: John Ogness Reviewed-by: Petr Mladek Reviewed-by: Aaron Tomlin Reviewed-by: Douglas Anderson --- kernel/debug/kdb/kdb_io.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 67d3c48a1522..5c7e9ba7cd6b 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; if (msg_len == 0) @@ -558,8 +559,20 @@ static void kdb_msg_write(const char *msg, int msg_len) cp++; } - for_each_console(c) { - if (!(c->flags & CON_ENABLED)) + /* + * The console_srcu_read_lock() only provides safe console list + * traversal. The use of the ->write() callback relies on all other + * CPUs being stopped at the moment and console drivers being able to + * handle reentrance when @oops_in_progress is set. + * + * There is no guarantee that every console driver can handle + * reentrance in this way; the developer deploying the debugger + * is responsible for ensuring that the console drivers they + * have selected handle reentrance appropriately. + */ + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { + if (!(console_srcu_read_flags(c) & CON_ENABLED)) continue; if (c == dbg_io_ops->cons) continue; @@ -577,6 +590,7 @@ static void kdb_msg_write(const char *msg, int msg_len) --oops_in_progress; touch_nmi_watchdog(); } + console_srcu_read_unlock(cookie); } int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) From patchwork Wed Nov 16 16:21:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21162 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233615wru; Wed, 16 Nov 2022 08:26:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf5M4SV2y4ZyDQwL9guhehyGpQgmzRtrlM1xHgoWi8I7yOqSXoaMEIJH2vb90nCCSwmAH3CQ X-Received: by 2002:a65:63c2:0:b0:46b:2753:2a60 with SMTP id n2-20020a6563c2000000b0046b27532a60mr21076132pgv.192.1668615971965; Wed, 16 Nov 2022 08:26:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615971; cv=none; d=google.com; s=arc-20160816; b=c6L8BncC3/aEd7KXddYQfLR1vDYEIwtwlwQH3i62F1xYzEojLq6h558Mt+NPdLrmFN farqapEPJXyTd6ejnsu+Wx9JhVXJkNlAcLm/tLhykP0LlGoJJEnR6bFcZsHQ4Xd7dFtV FNnUKUgXYN3t1fZA15fRSaO/ihU296zeVI0QFQZ7MEjTVTyErGLx4aKhw4eEhpLwQ++e opXNRaninFPLRKteGDXjbSYhGKHjS0rf6qiC1gvpAstX+9ghTsvHVjjXVLJZeBbfAvYZ m8jvp4bd6zAYhZbIhIZ4ZSJ+ZgL6u9Gjf2aAr9ix373z1YZwE+zIG4QFXao2VRA90OLL Jimg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=YVcIuv27uGLo38bBlF6a0snyz5C3DG9fbWr+xW+r2BY=; b=H7zbSSNuQ1hwcdUGivlharFc+YEmM0w+c7+9wkRkxwaSbFB39p5RS+/aJWYIsDTPIu y9R84GIzjXeagZj6CzjwbhCW7XydJMM03xjQVlK6tPdoZeHEWGbdQX93VpvqKrfGO7NC TfJVyakgcQu5ET/aYCujmXukL2uU3SuLTO3B2s7DMNTu4U7HEyEEF3EJs6QmEE/ZZJpk gEJFA0LIpoFHUmdDfvBuejjDmUF6/z4GtpJV7PHUiJ4PON5LtEDNjXCBwhcw/Yb0d3EG 8l274IEcbg+58iUcPWlws3xTcaEwy154pK8uV51LFJD72Z8BZQhZWo5GM6TsmKxOrS3Z MN8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3ellLLMY; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 24-20020a631258000000b0046eda1d5784si12751593pgs.462.2022.11.16.08.25.55; Wed, 16 Nov 2022 08:26:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3ellLLMY; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236617AbiKPQXZ (ORCPT + 99 others); Wed, 16 Nov 2022 11:23:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234365AbiKPQWH (ORCPT ); Wed, 16 Nov 2022 11:22:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D7EA326E8 for ; Wed, 16 Nov 2022 08:22:06 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615724; 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=YVcIuv27uGLo38bBlF6a0snyz5C3DG9fbWr+xW+r2BY=; b=3ellLLMY/2Jf20hAsajoIK3yqG9lrmjthAmz0GvSIVxqA1zQwW2TEeb87Z1qKnl0koeAgD izST/3Dnj5JKGMrjJ7603fcRmOgxWvL8j+Zdar+kkbD/Szty0lmdXyu0Z8Tg2wSgiUAyr3 m9gLne1gbI3VP/hoyUOVho4vnPVgSuTeDLoi0e5z7OoHVuCPjLrQMZUdJvcsLMjH4aa7bS 8k9CLMRqJr7CFYxQcwpw+sj8VSozxEQOHGcbXN7GkY4i6tBzwM3aQvNJzJtniOdcBteQFb RNnJWhimMRrpwTyD1aKf2uCZwA5eHAmyEmKZX3Grd2OU+8l00iFDMUMtAqc6rw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615724; 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=YVcIuv27uGLo38bBlF6a0snyz5C3DG9fbWr+xW+r2BY=; b=UChYZvgjqm0Zoiqmc+shyxCgeQ2G7GhTa5LqESdfoK3LeEySnsm/QJeIMoOmQmdn56wczq AvLZQP6PbGccdeDA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 15/40] printk: console_flush_all: use srcu console list iterator Date: Wed, 16 Nov 2022 17:27:27 +0106 Message-Id: <20221116162152.193147-16-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670661307269633?= X-GMAIL-MSGID: =?utf-8?q?1749670661307269633?= 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 | 50 +++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 35018f18f5aa..3a7b1931b7c9 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1893,13 +1893,13 @@ static void console_lock_spinning_enable(void) * safe to start busy waiting for the lock. Second, it checks if * there is a busy waiter and passes the lock rights to her. * - * Important: Callers lose the lock if there was a busy waiter. - * They must not touch items synchronized by console_lock - * in this case. + * Important: Callers lose both the console_lock and the SRCU read lock if + * there was a busy waiter. They must not touch items synchronized by + * console_lock or SRCU read lock in this case. * * 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; @@ -1918,6 +1918,12 @@ static int console_lock_spinning_disable_and_check(void) spin_release(&console_owner_dep_map, _THIS_IP_); + /* + * 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. @@ -2401,7 +2407,7 @@ static ssize_t msg_print_ext_body(char *buf, size_t size, 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, size_t len, char *dropped_text) { @@ -2743,16 +2749,18 @@ 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. + * + * @cookie is the cookie from the SRCU read lock. * * Returns false if the given console has no next record to print, otherwise * true. * - * Requires the console_lock. + * Requires the console_lock and the SRCU read 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; @@ -2812,7 +2820,7 @@ static bool console_emit_next_record(struct console *con, char *text, char *ext_ con->seq++; - *handover = console_lock_spinning_disable_and_check(); + *handover = console_lock_spinning_disable_and_check(cookie); printk_safe_exit_irqrestore(flags); skip: return true; @@ -2849,6 +2857,7 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove bool any_usable = false; struct console *con; bool any_progress; + int cookie; *next_seq = 0; *handover = false; @@ -2856,23 +2865,29 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove do { any_progress = false; - for_each_console(con) { + cookie = console_srcu_read_lock(); + for_each_console_srcu(con) { bool progress; if (!console_is_usable(con)) continue; any_usable = true; - if (con->flags & CON_EXTENDED) { + if (console_srcu_read_flags(con) & CON_EXTENDED) { /* Extended consoles do not print "dropped messages". */ progress = console_emit_next_record(con, &text[0], &ext_text[0], NULL, - handover); + handover, cookie); } else { progress = 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; @@ -2886,14 +2901,19 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove /* Allow panic_cpu to take over the consoles safely. */ if (abandon_console_lock_in_panic()) - return false; + goto abandon; if (do_cond_resched) cond_resched(); } + console_srcu_read_unlock(cookie); } while (any_progress); return any_usable; + +abandon: + console_srcu_read_unlock(cookie); + return false; } /** From patchwork Wed Nov 16 16:21:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21143 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp232648wru; Wed, 16 Nov 2022 08:24:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf6LnOF8j5wrKNlK1w16vWzzWJZII/TRQw1XXbEHzQFWJ8rIy7GT4gOEYBw+VmeCXDvbfd9t X-Received: by 2002:a50:ccc7:0:b0:467:cc91:903b with SMTP id b7-20020a50ccc7000000b00467cc91903bmr12882759edj.130.1668615850180; Wed, 16 Nov 2022 08:24:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615850; cv=none; d=google.com; s=arc-20160816; b=F4m8NA4k52nmY6d6N66YrjDzuh8DOW+hACczBVoe4gLfS70DWjfQBHXgqxNjTODltJ Ujgay6DjuuCSpqdPJCtQvqwGVQEN4/y5cYg+5SxorvpkiuGzEk++PKKGwLBnETd53t0m Y8M6Z6jodaLowGYl3x0iQK8q2J/ILc/xDXwXrKpvrq3/dEjJJooAH276Aai0SXMRnnAK HE/pO7zWmVS66fpdaERLke09sWRzc6NAo/i6uq2l0aYeLNWhz8cYtmrSmTOQq+vujneT uLHYSOCJYb+14UlBZKX1V5y7fUoXZsrIznfrWje5zWiVCGoevMPVdGm12j3aeqIljc6a 4Iqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=gtH4yW3JeyI4F3eGTioeuhi1fpVcHx73Hw0G9i8hSSU=; b=HSpQVfGwDL+j1BUK8EmzWjn3YvHZ6Q4tlON1EFiYxCEV6rv30tsAvzAGs5bdqLXk7j kn6liIb3GMRIANsAYynjOBJFjgr3FS5V+8Vh7O5n62OV39GmxCe6A3OLB4Dl692KD6ip pS4RUbPQrQex8xP7N0TB9vSa2NUdkVhXcM9h1jBd64/7c/n0o9M32mLzJL0GAfPIVwP3 3hX5DEi/G4R92otrWHVI6tQus7tlddEa2l3bg9hwoBqwKlwXNyHnl8btdD1DSrraS67C w9bFXp1H/9p/r8GXq+XqC961tb4BYOPm42ZiNw4eEf89haSD+vORAoh/VTKvIJgOV+tO wSnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kayQnh7l; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa6-20020a170907868600b007a45e4f4ff0si15830128ejc.885.2022.11.16.08.23.46; Wed, 16 Nov 2022 08:24:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kayQnh7l; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233296AbiKPQWx (ORCPT + 99 others); Wed, 16 Nov 2022 11:22:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234420AbiKPQWH (ORCPT ); Wed, 16 Nov 2022 11:22:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B0C953EE9 for ; Wed, 16 Nov 2022 08:22:06 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615725; 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=gtH4yW3JeyI4F3eGTioeuhi1fpVcHx73Hw0G9i8hSSU=; b=kayQnh7l4s1491kWSKsE/fOVnX9St78ObnsuaLA1l80ClxwMsYALUbty4DW6fqOiG5YVUa lg4IoP9w8yOjeLX4z39itvhtah+ckgU060CVoM7oO6lzA0XOWohgesE7+MLAwzzUJK/9JF McJBvjt14QhEPdiWLpuZ2QRn5X3tI4qkl6flh3vUgYemOXjw+A7Nn1pEGjBPY1b4VcBawz 2Z5IFC9i4PVN4C+bUtIZNOF368QeWu3VNuuCp2Ld/5LafIGNTU41lOfmP3m3JDB9I1pgXb avVBlbxv32SlYFsQFcml1Ss+YxWCCDK3kqlG/eEGkZdBzvGBB3Vovt0cuvdKmQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615725; 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=gtH4yW3JeyI4F3eGTioeuhi1fpVcHx73Hw0G9i8hSSU=; b=p+tlMt2fKLrSZ7uozDnyug3YD7ymR7gPSP52ARH76IKRuFjFDWwCw/QeQIfwzypdQBhSZB c2vSgXnuvgiNAuDQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 16/40] printk: __pr_flush: use srcu console list iterator Date: Wed, 16 Nov 2022 17:27:28 +0106 Message-Id: <20221116162152.193147-17-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670534035166686?= X-GMAIL-MSGID: =?utf-8?q?1749670534035166686?= Use srcu console list iteration for console list traversal. Document why the console_lock is still necessary. Note that this is a preparatory change for when console_lock no longer provides synchronization for the console list. 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 3a7b1931b7c9..6666cc27a014 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3560,6 +3560,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre struct console *c; u64 last_diff = 0; u64 printk_seq; + int cookie; u64 diff; u64 seq; @@ -3570,9 +3571,15 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre for (;;) { diff = 0; + /* + * 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(); - for_each_console(c) { + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { if (con && con != c) continue; if (!console_is_usable(c)) @@ -3581,6 +3588,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre if (printk_seq < seq) diff += seq - printk_seq; } + console_srcu_read_unlock(cookie); /* * If consoles are suspended, it cannot be expected that they From patchwork Wed Nov 16 16:21:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21148 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233094wru; Wed, 16 Nov 2022 08:25:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf70VdsHy0YBdpEnPgwaNxUMvy7ebqoivOEm5K4In9IsyfA0pUHeFC5zLiumEG9Ko8zvkj6g X-Received: by 2002:a17:902:e782:b0:17f:52af:d035 with SMTP id cp2-20020a170902e78200b0017f52afd035mr9993789plb.106.1668615906153; Wed, 16 Nov 2022 08:25:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615906; cv=none; d=google.com; s=arc-20160816; b=vJuXsDhckwEbaO6G0rW1tVEVlg0BQaaoquYjsjuhQA6AIiPFrqtHt3RmSwbT8KjdeN g7Skqqk6W9QTHMcrduMPrGhIwNvIfCt02LlA5mZWXENBYoLncD/vyQ8j9OHz4bNvOJmC Y0CYpsQ/03LhwmddLSEOQtGWScGA4LswbyXQ0yRQwJ6A8q3m468E73Kptmlxkm+Ktcyt 7KytAf5yDxbtkTAG6pgITnl63JNgvWHybay2nobX3Pqr//bXVPGf/AuntOHELiYe3mYS PDWOfjYospP+2eyVTjRsMv3sUTB1Xhur0oWmQK+kiYgD2vQwxSKiQ7+nM8M4dkIDaugm s6Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=nhhJ4NEYDrYYk962PRI1KO7CTDJYZ90BsmoX/yxQ/gI=; b=fSOqDaGQn2ee0x0uX7+7OVZaEYK3cjejxnYqy3EXSgYz44APY+OcCHlBOfY+UW+VC8 jFQoE0omU9p8T4sfhC+9FgPE+8uAM/A5COi/35OLR1RL4K1NyQ34j73GXSXkd7KjYDxb 0pqNmh5HQZ4epQLaKzepzBOtahKQ41mT/XxooxlNM7pVPhB+N6VsPzBnPQCsb965f9pL DB4yoNmCDOiOjew0zR8zojRGlL5C7K0+G66TvFYYxKo0V8FjR4PO3iKrEor2QBr1O2iu 1mU8e5esbCTDykuF6w/nzIM1By2g+ZvUUUk6wnO747VtZH8AQjq1z4D3BnSdKlp4qca1 lvpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lRDydq5F; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 18-20020a631052000000b00473d2c2c082si15765797pgq.361.2022.11.16.08.24.52; Wed, 16 Nov 2022 08:25:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lRDydq5F; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238657AbiKPQXl (ORCPT + 99 others); Wed, 16 Nov 2022 11:23:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234426AbiKPQWI (ORCPT ); Wed, 16 Nov 2022 11:22:08 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDC2747311 for ; Wed, 16 Nov 2022 08:22:06 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615725; 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=nhhJ4NEYDrYYk962PRI1KO7CTDJYZ90BsmoX/yxQ/gI=; b=lRDydq5FRZTnwLjVZHwb0EFCh4BnmAql/o3iD/Qhwm+z4zzC7IEwqkBDf2PopO8HzRgRB9 rYWm/6nGUKDvhLD52VVku54Wzv3n+RpLJ1VYDeXtDYnm81qg/kqn67NNDxXntUC4ZqHj5T 76kg6Qu3zH/jNH7WI5zmxvWp96rFCt2IpIJ+lqpcQXLaI32egKpudioKS2bXTKJOOFx/kM l5yZrET/CWXg6D0NcF1jzBUJuVzPtFCyqGSgcctEYxK5uPOnTXkovYxcy0G++vcVykd5DO sYa/WzWP4KKm77GyhziPCSDqiwU5LZi+ZHnuBvk8ZXMJoicHCDGCmFB3idMIEw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615725; 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=nhhJ4NEYDrYYk962PRI1KO7CTDJYZ90BsmoX/yxQ/gI=; b=bY0sIjstLLp8P/5/imQZ/AMuPiIf5JzcDLwL9jC+9b1Sxa18frPcCl9+jZamwRBFbekt5C rWE6Za9htWGPuTAw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 17/40] printk: console_is_usable: use console_srcu_read_flags Date: Wed, 16 Nov 2022 17:27:29 +0106 Message-Id: <20221116162152.193147-18-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670592436167529?= X-GMAIL-MSGID: =?utf-8?q?1749670592436167529?= All users of console_is_usable() are SRCU iterators. Use the appropriate wrapper function to locklessly read the flags. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 6666cc27a014..75951c4bda05 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2708,11 +2708,13 @@ static bool abandon_console_lock_in_panic(void) * Check if the given console is currently capable and allowed to print * records. * - * Requires the console_lock. + * Requires the console_srcu_read_lock. */ static inline bool console_is_usable(struct console *con) { - if (!(con->flags & CON_ENABLED)) + short flags = console_srcu_read_flags(con); + + if (!(flags & CON_ENABLED)) return false; if (!con->write) @@ -2723,8 +2725,7 @@ static inline bool console_is_usable(struct console *con) * allocated. So unless they're explicitly marked as being able to * cope (CON_ANYTIME) don't call them until this CPU is officially up. */ - if (!cpu_online(raw_smp_processor_id()) && - !(con->flags & CON_ANYTIME)) + if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) return false; return true; From patchwork Wed Nov 16 16:21:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233354wru; Wed, 16 Nov 2022 08:25:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf7KUsxjjGgHwN5IobmpPmch/iLa4j0YdhmhA/So12kSNSUAeGMa+it9rmqxkQeNpGrPdsiK X-Received: by 2002:a05:6402:ea0:b0:461:a9ce:5408 with SMTP id h32-20020a0564020ea000b00461a9ce5408mr19891338eda.201.1668615943076; Wed, 16 Nov 2022 08:25:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615943; cv=none; d=google.com; s=arc-20160816; b=qgaCPwL95x2NcvS19JM9jvDs9FfIX8iqiM33inywh96qeyCXIlyDiE5cPivfOGZLkQ gmNENxJ7z7uogHp7tBVe+5Ugk2hi/WRlhwBBdCR8zIXu7tw7Y8T2hJT4K0KxZ1YHTHK4 DPTjv9yq2Fzgxd7J9gOaiNqqaKe1YQ0QWGwCZennFWJbxqiwO78x486bMr6avIlVjDAx 2vVesn1ct5gmEE7heZaX1ZBHB2BVo9JmbGmNLcWkjPTVwsXnyLOCkSAbCOEJ0dQ2B1Zx OS/Iot9/ZjhCH0OrdL9MC3tEbQLsGj+an14CiXD7gigwqFXYcu5kOOo8TK9x2xoSbKEs 034A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=q0qlTUKV9y3QSw09vgZHZ2kx/Yss2JifrQdnD+gXn68=; b=agw8w0kT2neAphl3BgcjV+hwnNjECl2X1/7W2PUNpIgAOcrlqk2AyTJ64q1Ih69YoY VeNuw1KoyYxdEyrYBP/LGx7inB6SKDsDHStCH5oou0jXLTGDB3zoH7XRA39tbEXrYXHY sEJvBe5aPVEGh4WRpQK//RuNYjClKnAqFZD2D3VnD/3SA1U1Uppfhmt1y/BTbvjlPNRF m56XOBznH84zuSdtjURa73/keSgFxQw+LsdWJk8gjdevWff9rVGtU+FyivQMwEz1mHc5 gXUPlE+TL7y+DyiNyTQbwP8Pfe2M+JOZbVubgxWrHZP2skLrX1KI8rqT/g19ocrIHVek 60lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=t2HcoKXh; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=x9m2gRFm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oq19-20020a170906cc9300b0078772382b35si11354978ejb.91.2022.11.16.08.25.16; Wed, 16 Nov 2022 08:25:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=t2HcoKXh; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=x9m2gRFm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238685AbiKPQXt (ORCPT + 99 others); Wed, 16 Nov 2022 11:23:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233991AbiKPQWc (ORCPT ); Wed, 16 Nov 2022 11:22:32 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F42226495 for ; Wed, 16 Nov 2022 08:22:07 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615725; 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=q0qlTUKV9y3QSw09vgZHZ2kx/Yss2JifrQdnD+gXn68=; b=t2HcoKXheo/9cKQLAg3L3ksvZhwzlBHB2iUjivKMmeWAOQ7QYzUhxH0EMOGkmJplEeP8ff QoHLhCiF1him5w0dcj2u5w5ITkU6WbgMgYFCnwAJ1gaVBXmySBijfFa785IKlScZO6tXDX BO64psIYULhP5UmnTGw0coO85633ZdhTBSwVCGdTVuUYZslepqLX74AFjsPLG5reOMZ3Af hpFQpyhG1VlwJ1qzZBxERmW/0f9SDEkLmpCIC8cHCxFwS7fGh9TAxtogF8RDu/kvUBab91 yOHJJWCSqJ6VvXlFsMqtFhCHwH3PGzLYWoN4lI2OIba8zID69cevqUb4/kBXDQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615725; 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=q0qlTUKV9y3QSw09vgZHZ2kx/Yss2JifrQdnD+gXn68=; b=x9m2gRFmDedx3teMkiLLQUfM2cC+aisawOZm8nNBomlUsbehXNe4+5wP2d+xmXJ6jYL8NO oQ8q1WuUnKc8UiAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 18/40] printk: console_unblank: use srcu console list iterator Date: Wed, 16 Nov 2022 17:27:30 +0106 Message-Id: <20221116162152.193147-19-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670630815419084?= X-GMAIL-MSGID: =?utf-8?q?1749670630815419084?= Use srcu console list iteration for console list traversal. Document why the console_lock is still necessary. Note that this is a preparatory change for when console_lock no longer provides synchronization for the console list. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 75951c4bda05..b4be3b08d909 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2999,10 +2999,14 @@ EXPORT_SYMBOL(console_conditional_schedule); void console_unblank(void) { struct console *c; + int cookie; /* - * 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() != 0) @@ -3012,9 +3016,14 @@ void console_unblank(void) console_locked = 1; console_may_schedule = 0; - for_each_console(c) - if ((c->flags & CON_ENABLED) && c->unblank) + + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { + if ((console_srcu_read_flags(c) & CON_ENABLED) && c->unblank) c->unblank(); + } + console_srcu_read_unlock(cookie); + console_unlock(); if (!oops_in_progress) From patchwork Wed Nov 16 16:21:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp234166wru; Wed, 16 Nov 2022 08:27:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ziVIrLTqr+gj2sZQEFx3zZfOaAH7nBNt71sEHwjWysRqU03ZEUwpxHHtdKFmBnti5hJVt X-Received: by 2002:a17:902:8645:b0:186:5a0c:85a2 with SMTP id y5-20020a170902864500b001865a0c85a2mr9606976plt.79.1668616040006; Wed, 16 Nov 2022 08:27:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616039; cv=none; d=google.com; s=arc-20160816; b=Z+8P7+K1CiRovH8u6EI6UNxV3+a9YGbs6wC+F4+4lvpsf9xexXNrIiCshJAqvleE5D 6ETZSRyC8LNTfSDXYcYjki75k4uzmc/bi8g3NwGSYyhwZxTfPBb1PyidqMjcpgfcP6ie dWEHE+9K6UWua3fxr+o4VZuuNzK5ZzARPQBL99Fl2IIjDplH5HS8UtCqJRMGxLMj6xVf dPJpdiH8J4gp6mE1Mm4Q0fjvRqREIyD2sWbgM4HN5KAUmIovuByL5pMKGdZX175yNpBx BzPKy+TAYgCws+aRRgr+nMjpeerThuKiPkSNLHnGIxcP5blGH04ZVmqaiCdrd8+Cef9K 8Rkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=IVEyyo7p00eD9RPDb2JhbrHc13EdmCMyj9VsyLQFgy8=; b=lXNPdy4z+BmrHlZ7D63YIomLvysf1WkdfT5M7szXrOP+ZuWyDoWHGgzpdasS2v1Jwb 6vSefMRg8Loghvpc6nnHg98C2x0bTSWrBcwP7CVkL9xNfAxRY8gH8cTp9a4zAVdSczGQ OqzlR4On5ARpE0li5PNmX5BeEV7IKbBoEUpk7QdszSeVNIkmQdTDzv9xBMMLvp4bCwxH 3nRhMzfC+migpXliPvJpoQVvxYlhESeV3nPfHi5h+6/YkBEpgcD8X2nOB9ZNXcSEL4Ny dxhqdFnU5cOaxQg+F93EYQFt4xke/8Da4++qn8U3wDFobr3dXFpKlbNPEOJSxJAeYFIT e27w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=sTxOuw9r; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=PvcnYVBP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e23-20020a63db17000000b0047632d0ec49si12067684pgg.347.2022.11.16.08.27.07; Wed, 16 Nov 2022 08:27:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=sTxOuw9r; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=PvcnYVBP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238781AbiKPQXz (ORCPT + 99 others); Wed, 16 Nov 2022 11:23:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234352AbiKPQWc (ORCPT ); Wed, 16 Nov 2022 11:22:32 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB50D56ED1 for ; Wed, 16 Nov 2022 08:22:07 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615726; 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=IVEyyo7p00eD9RPDb2JhbrHc13EdmCMyj9VsyLQFgy8=; b=sTxOuw9rM214SMJzCfx+HKjrQUF/mTpRzM+B/lCLL7hyaTNlBpzwQSvIRhqwSfvgVD3Gyc sEApjwVJ0WqCozTqqEmj8agYVaXrcRjFI6kA07+VBbZ/tugYhMlixLEXmdtlH5RMehAbRQ fwdca4X+pSWesLAEXIaGDjkVvY2xCPj9KvORWxMbaQh7p1cUdEIyUcUrjugxCTM2kQPISn M37p6pf5xACQyEWa2nmO91fuX+/YB7y6cja8uO3qwXbk3ILTnyh/a04thRTfHdghRW/ALT JENYXZt4FPJebfRLVlJunL12KjZF6j2IqFPnttypTPpI6OKx2XdzoM5f2EjgGw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615726; 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=IVEyyo7p00eD9RPDb2JhbrHc13EdmCMyj9VsyLQFgy8=; b=PvcnYVBPLntB2fGmHVVPmL6WouNpD04Mu+Xc6JN2IjcZpqlc32gguaNIJ3bsNkK0Gb4S8x U9YLMPZmn0BliHBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 19/40] printk: console_flush_on_panic: use srcu console list iterator Date: Wed, 16 Nov 2022 17:27:31 +0106 Message-Id: <20221116162152.193147-20-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670733154901985?= X-GMAIL-MSGID: =?utf-8?q?1749670733154901985?= 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 b4be3b08d909..1a805ebdfe94 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3049,21 +3049,22 @@ void console_flush_on_panic(enum con_flush_mode mode) console_may_schedule = 0; if (mode == CONSOLE_REPLAY_ALL) { - struct hlist_node *tmp; struct console *c; + int cookie; u64 seq; seq = 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 = 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 = seq; + } + console_srcu_read_unlock(cookie); } console_unlock(); } From patchwork Wed Nov 16 16:21:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21149 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233178wru; Wed, 16 Nov 2022 08:25:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Yul5CGtyyALZmbVnbBhMmkYIZTjJXXN+kWxoGcmBCr2lkrDY2fD/EOkt4aPGUH3jT9Y/p X-Received: by 2002:a63:565c:0:b0:46f:e658:a8ff with SMTP id g28-20020a63565c000000b0046fe658a8ffmr21125734pgm.493.1668615920192; Wed, 16 Nov 2022 08:25:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615920; cv=none; d=google.com; s=arc-20160816; b=OAZCpMc7y1z7vx29KWyXL+MypAmAQrbKu44ojxgBvPM/d9yfElonVEgtgCdmKzdU5H AESwLUmT7RGGy1prZpiE2EvzaWCAAJnF6892Xa4AHZs3uCb4r6CfaKWQDSULwQUR8CLo l1GmCQoZeQ1DWmnYTc/FheU8OnS8VPq5dP5H2oGenISRB1ax/cC6HYgPsck9Ch4hHxek jrlUcGpHaBXi8lQcsXdmaVzVAt+xUiXIMAEu39sjJPZbcqxtiVPy1i3PzfWxVjyqcaLz Z3anfMskrQzrpThNuy8URTkENAcAhefUBIt4BIy0lMb+5bPJJ3XPgMpJRzGxXuHyl6OS BNUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=KmfyhSE4r6WUxdHMjntiag5r5BjOY39c0HqbRdrpwyk=; b=IAZxx3VZrE27YhYBzXeeIfNl3tEAInzfk4hqzYcrXQDsGZeTdox6GQVnpPLMJFq1Q4 dmvOIqFODk4VPKpvi/gwJQYp9qlIy6tWgP5UkQ3Ns1F052EWy57ggO9THvpP1uYa8P/F jkRhSzkgeaJ8+jTnx5ALkQUrAw3Uh8X6wDfGHJ7jrPOM7Ctvvtz5uPhrcBXaLZEWj+0K UYcsr8tUXHQcsHus1Y5CrvksJfyXev0EQ6xQgrZ1p4kRhCOm0XBIAiJs26yCnL4QcahY vZbu/bjldtTw2RN7ucN/2b9/isJ4Cn80VbMHZ6LheOF++0Ksp8093ZVMjUp7dHyV+QiN Ebvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="k/cRkSzu"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l27-20020a63571b000000b0046f622b47b9si15970811pgb.180.2022.11.16.08.25.07; Wed, 16 Nov 2022 08:25:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="k/cRkSzu"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238791AbiKPQYB (ORCPT + 99 others); Wed, 16 Nov 2022 11:24:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233472AbiKPQWd (ORCPT ); Wed, 16 Nov 2022 11:22:33 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8E27326F5 for ; Wed, 16 Nov 2022 08:22:07 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615726; 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=KmfyhSE4r6WUxdHMjntiag5r5BjOY39c0HqbRdrpwyk=; b=k/cRkSzuFCT+qLGQGkimjidC2S2ewQnumtvJw+ZaIw2kd+mtyfYy9IDf+wRPav3Z6JAB3W yPERjIarGDkPzFRVqTufPPgKmx4BK0i6aseuo+Yjja1rFdrV5XJ5k1WBdOguLmdv5QsyPe eqKAPKqI82efDymKZ0fsPD7RNWXNLJgD+noCTM8rnZDqxJzmYGbZ1OMcv23JC9HGjJGwsN HxoYF605s6qqpxK94MpbPyh543sKAnGUO88n/4muBc6o+CsE3JHTcKrxHVdNm/l2MncEfQ HlU7VMMmg6t4dEy7gqKJPyPqx/BEtOpKYzOp3OYAYVAS+eMHhFFJ9uSEvzJL6g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615726; 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=KmfyhSE4r6WUxdHMjntiag5r5BjOY39c0HqbRdrpwyk=; b=ZgnqSOHRDB9ITTyaqG0OzhGDy6iC+fOzqVTExO/t8Tiuha/tipl08vwtipSqjr/KO4CXCI YfEAjtozcg8gaaBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 20/40] printk: console_device: use srcu console list iterator Date: Wed, 16 Nov 2022 17:27:32 +0106 Message-Id: <20221116162152.193147-21-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670607283797321?= X-GMAIL-MSGID: =?utf-8?q?1749670607283797321?= Use srcu console list iteration for console list traversal. It is acceptable because the consoles might come and go at any time. Strict synchronizing with console registration code would not bring any advantage over srcu. Document why the console_lock is still necessary. Note that this is a preparatory change for when console_lock no longer provides synchronization for the console list. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 1a805ebdfe94..694c2da2919c 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3076,15 +3076,25 @@ struct tty_driver *console_device(int *index) { struct console *c; struct tty_driver *driver = NULL; + int cookie; + /* + * Take console_lock to serialize device() callback with + * other console operations. For example, fg_console is + * modified under console_lock when switching vt. + */ console_lock(); - for_each_console(c) { + + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { if (!c->device) continue; driver = c->device(c, index); if (driver) break; } + console_srcu_read_unlock(cookie); + console_unlock(); return driver; } From patchwork Wed Nov 16 16:21:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21151 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233286wru; Wed, 16 Nov 2022 08:25:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf6EzYN0/kxkimoLyXcxRAQjk9YwU2qth/2YOTVM04Ch+LtOYL4P2S0E+sIKTLHZpZq/k3Oa X-Received: by 2002:a17:902:a70e:b0:185:3659:1ce9 with SMTP id w14-20020a170902a70e00b0018536591ce9mr9410935plq.26.1668615933320; Wed, 16 Nov 2022 08:25:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615933; cv=none; d=google.com; s=arc-20160816; b=vMRDI6rn3wLoEMojZgLzwnh/zwaxZb24qr/lvYczkpbzxTvJAG1w/dLViTDsgEFNfe 5sZz9tsPRkooRBDMpTgIyEb/EPpqom4So2g0fpMp+OTNN2GFhrav1IAgadBLWV2FOVyc jYKo1537lLg0mPQNuxfgBI1ZGS8q7Cs0VrH7+4l+oZMbSDVtn25AFTM44zDwZ91kd0xN KArEXHRW1yvIbPsY3kUxtQsTcYnxHqPdNAUIxJoHTKragvGeYS/+2yyAulZIePKCXEMN mnssg+cOOelFSJJ+8wlbbTn8aN+X5FaXYxlTHF78iqoEsg0gRXGwUDZFUkVa4q5maHnY Vu2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=tIwoX0Bk+kxNtXZMH8Js6OcNrjaRyTCIbtxVTzV9N5c=; b=ayapOwky+MRet5sNtxzueDSTsapvifjE3XcLtEpqXe/dw0ImPDOse5lHhFVru5CzOh ca/V5FkYYMJ+dDqVjNIwWXBbM66cwRyhtHiUPRkK6SJMcDv4QLZyhdtDPJ+WqaXyM/+T 7SJ4n/RABZ5UWdZ0gIOydf7VyA/gzQAhWIP3V+9y0MQAJPhlObnOGBYVdd6lKOjJ+bnE sqQSwhOTv+d82U1yYOuGpa16scSqbRCxjlBaywcrWNWI3rK7LK9gBGV8VIdx10cfj0+X PP+pZbP7/zbkbOp5kRKpZA13ngG48ePWSI6d7OjpXqMMwYOspfbVTFl7xiqZzXgzLr9e USvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xcqLPvXz; dkim=neutral (no key) header.i=@linutronix.de header.b=vPamkzAF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f30-20020a63101e000000b0045d60c88ad2si14400384pgl.164.2022.11.16.08.25.18; Wed, 16 Nov 2022 08:25:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xcqLPvXz; dkim=neutral (no key) header.i=@linutronix.de header.b=vPamkzAF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234196AbiKPQYM (ORCPT + 99 others); Wed, 16 Nov 2022 11:24:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234691AbiKPQWd (ORCPT ); Wed, 16 Nov 2022 11:22:33 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 450AC4387A for ; Wed, 16 Nov 2022 08:22:08 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615726; 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=tIwoX0Bk+kxNtXZMH8Js6OcNrjaRyTCIbtxVTzV9N5c=; b=xcqLPvXzPMgHdZZh+aXQCizAJ1XcnxxwXTkI+btHIIdQ4kvlrEsbNgBpUxjqvnnR+zVSn9 3JSrnTZjVdlF49aQ/Kgiy2FynLe85lyw54J1zv3sMBLhmplkdE36gAizD6w7UbOt5CZW8l GrHsM4B01GO3P7TUKMbg4AUtXp6RIoqhqfWdTKzyb5u5xx+ZFChoN2tkkIud60rT2R8s18 jD3Ys3yHwuTuSou8ejDuyens0/1AkXPXE9BWMc2tbP9eaTZlYQBd/a1g7SbbtFxL9wmGz4 m5VwsghJP24DHW+IBInJTQZq5Xv3I0IBgYqMea91K0xhttKUmOGy1Y3ZbxSlew== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615726; 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=tIwoX0Bk+kxNtXZMH8Js6OcNrjaRyTCIbtxVTzV9N5c=; b=vPamkzAFqDij3uBH26BvWV95aqv/chtnpWE5mzM+Bh7iTi7jwn73ewDS2NvSKZ6MGSzpjy k8Erz5VO4oG5CVCQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v5 21/40] console: introduce console_is_registered() Date: Wed, 16 Nov 2022 17:27:33 +0106 Message-Id: <20221116162152.193147-22-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670620673821434?= X-GMAIL-MSGID: =?utf-8?q?1749670620673821434?= Currently it is not possible for drivers to detect if they have already successfully registered their console. Several drivers have multiple paths that lead to console registration. To avoid attempting a 2nd registration (which leads to a WARN), drivers are implementing their own solution. Introduce console_is_registered() so drivers can easily identify if their console is currently registered. A _locked() variant is also provided if the caller is already holding the console_list_lock. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- include/linux/console.h | 28 ++++++++++++++++++++++++++++ kernel/printk/printk.c | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/linux/console.h b/include/linux/console.h index c1ca461d088a..f716e1dd9eaf 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -228,6 +228,34 @@ static inline void console_srcu_write_flags(struct console *con, short flags) WRITE_ONCE(con->flags, flags); } +/* Variant of console_is_registered() when the console_list_lock is held. */ +static inline bool console_is_registered_locked(const struct console *con) +{ + lockdep_assert_console_list_lock_held(); + return !hlist_unhashed(&con->node); +} + +/* + * console_is_registered - Check if the console is registered + * @con: struct console pointer of console to check + * + * Context: Process context. May sleep while acquiring console list lock. + * Return: true if the console is in the console list, otherwise false. + * + * If false is returned for a console that was previously registered, it + * can be assumed that the console's unregistration is fully completed, + * including the exit() callback after console list removal. + */ +static inline bool console_is_registered(const struct console *con) +{ + bool ret; + + console_list_lock(); + ret = console_is_registered_locked(con); + console_list_unlock(); + return ret; +} + /** * for_each_console_srcu() - Iterator over registered consoles * @con: struct console pointer used as loop cursor diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 694c2da2919c..410d3f2cdeb3 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3442,7 +3442,7 @@ static int unregister_console_locked(struct console *console) /* Disable it unconditionally */ console_srcu_write_flags(console, console->flags & ~CON_ENABLED); - if (hlist_unhashed(&console->node)) { + if (!console_is_registered_locked(console)) { console_unlock(); return -ENODEV; } From patchwork Wed Nov 16 16:21:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21152 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233293wru; Wed, 16 Nov 2022 08:25:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ra2ae0uMcRtX8/5mkqcAYD7htR9/Xz2ayaWV88x4j0rzFpsWxZ4jT08f/M65p4tQBNNX1 X-Received: by 2002:a62:7b53:0:b0:56b:83d3:a22 with SMTP id w80-20020a627b53000000b0056b83d30a22mr24009364pfc.32.1668615934980; Wed, 16 Nov 2022 08:25:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615934; cv=none; d=google.com; s=arc-20160816; b=MjCJMIeKmFF+DAWN8yqFszYGFXt8uDspAgbKJPHhqCjXEJ//ngHMSQ12cHzYp7F8V+ ztrfO6lAg3OUYYiIqMRFCWPSvQzfvsExy3Wsrk0WuIZEdKBv6IJ9mHOselCoqtvPEJ+K 5fXtp8ul1pc7GDAzOMDoHWr7kebgtZ5V+V/aDhKvuJwfubxQwrekSkz0k0oVUUvE9D/u JQt472sxlmZ3e6YBGOT7bFVvhGRHhI1pAGmmCIwoPZofQvEiwqq0LirzZKdHuQdMBSI0 kubdbKHqiCVQlrzmIck6U1XjX4asHLWXXtlPiNcddTPp/j+tVOnZR7EiSlj9O7Oow60P B+TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=uvYIlIwdOZX0ToDjYltIx1ojqweQggTLKVs/EsUfUxM=; b=uRt2+QjXkNGdgGojJO7abHK8oPvjoWcVkxv5Yyq9kr7f6XGhe8IuuqUa0gGTlgYyG2 T/kBRxjYpAUSWlzfOXQvMuSlyjqzJXCMBJhO/xtEEduDE7f23cGFBZZHGvsv1O3NPCCp dU/C1kN4uxizy3I+E98DRnbgcjy4wHy6VHYDlik8z53RKZ/D76dxTQKGTgxemFs68jS3 rMiS2p7qQezK7DlgWDxT5xjgbivIMrBFK3+nvoyLMDZoyxJGOfBOzpT75ApwNj/r+lr+ p8XoSVsTaOsZwsCZpTltA8QfjLzaENwTbfKubSthBYxL4rDmSaGGf+dXqv/GkyMrrmzB gcYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cDkHuByF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds14-20020a056a004ace00b005726ac39d2esi5292177pfb.30.2022.11.16.08.25.19; Wed, 16 Nov 2022 08:25:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cDkHuByF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238842AbiKPQY2 (ORCPT + 99 others); Wed, 16 Nov 2022 11:24:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234791AbiKPQWh (ORCPT ); Wed, 16 Nov 2022 11:22:37 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5EDD56EE1; Wed, 16 Nov 2022 08:22:08 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615727; 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=uvYIlIwdOZX0ToDjYltIx1ojqweQggTLKVs/EsUfUxM=; b=cDkHuByF8QExd1GzBvcO0Kt+WxLMtwjdTUOjC1Nx7dklHUvQJAlA1sNg5coF7q2rC7AWD6 P3Z+ORdHR1pxbm0K+YzrMnac67OvU46jjMVNB7LL2GLWgE3+XblyNAEe8rVxvs70fmg0Fv KQX2bhp26f4Yk3zWfZCiVXeY0XqKN4WNDJR3L6WfeAlrwmmDou0KZJE/vHWLddRiaV7G8Y n74SjpC07KjR+Jr6Gqru1CCO9E+ATUGtJv9vG4IBuhfNyKphfYgIF/sdXFFB/YIdEe5jxI vV2QkFv9raU0RxhKR/c5A+3SNDgWx5JRSl5OCOKDbCCiZyJLfnbuyo5T3r6Xmg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615727; 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=uvYIlIwdOZX0ToDjYltIx1ojqweQggTLKVs/EsUfUxM=; b=UMmPPfjn/9pjYQ1xq/OO3fIsM130tZbyDJI1u9YMmWJRne9j/mf6hd2YYK5HXxEuJS3gbM uNscX4mSzGEWblAg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , Andy Shevchenko , =?utf-8?q?Ilpo_J=C3=A4?= =?utf-8?q?rvinen?= , Lukas Wunner , Geert Uytterhoeven , linux-serial@vger.kernel.org Subject: [PATCH printk v5 22/40] serial_core: replace uart_console_enabled() with uart_console_registered() Date: Wed, 16 Nov 2022 17:27:34 +0106 Message-Id: <20221116162152.193147-23-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670622469547750?= X-GMAIL-MSGID: =?utf-8?q?1749670622469547750?= All users of uart_console_enabled() really want to know if a console is registered. It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. A _locked() variant is provided because uart_set_options() is always called with the console_list_lock held and must check if a console is registered in order to synchronize with kgdboc. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/tty/serial/8250/8250_core.c | 2 +- drivers/tty/serial/pic32_uart.c | 2 +- drivers/tty/serial/serial_core.c | 14 +++++++------- include/linux/serial_core.h | 10 ++++++++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index 94fbf0add2ce..74568292186f 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -565,7 +565,7 @@ serial8250_register_ports(struct uart_driver *drv, struct device *dev) up->port.dev = dev; - if (uart_console_enabled(&up->port)) + if (uart_console_registered(&up->port)) pm_runtime_get_sync(up->port.dev); serial8250_apply_quirks(up); diff --git a/drivers/tty/serial/pic32_uart.c b/drivers/tty/serial/pic32_uart.c index 2beada66c824..1183b2a26539 100644 --- a/drivers/tty/serial/pic32_uart.c +++ b/drivers/tty/serial/pic32_uart.c @@ -919,7 +919,7 @@ static int pic32_uart_probe(struct platform_device *pdev) } #ifdef CONFIG_SERIAL_PIC32_CONSOLE - if (uart_console_enabled(port)) { + if (uart_console_registered(port)) { /* The peripheral clock has been enabled by console_setup, * so disable it till the port is used. */ diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 179ee199df34..b9fbbee598b8 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2223,11 +2223,11 @@ uart_set_options(struct uart_port *port, struct console *co, /* * Ensure that the serial-console lock is initialised early. * - * Note that the console-enabled check is needed because of kgdboc, - * which can end up calling uart_set_options() for an already enabled + * Note that the console-registered check is needed because + * kgdboc can call uart_set_options() for an already registered * console via tty_find_polling_driver() and uart_poll_init(). */ - if (!uart_console_enabled(port) && !port->console_reinit) + if (!uart_console_registered_locked(port) && !port->console_reinit) uart_port_spin_lock_init(port); memset(&termios, 0, sizeof(struct ktermios)); @@ -2573,7 +2573,7 @@ uart_configure_port(struct uart_driver *drv, struct uart_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_registered(port->cons)) register_console(port->cons); /* @@ -2956,7 +2956,7 @@ static ssize_t console_show(struct device *dev, mutex_lock(&port->mutex); uport = uart_port_check(state); if (uport) - console = uart_console_enabled(uport); + console = uart_console_registered(uport); mutex_unlock(&port->mutex); return sprintf(buf, "%c\n", console ? 'Y' : 'N'); @@ -2978,7 +2978,7 @@ static ssize_t console_store(struct device *dev, mutex_lock(&port->mutex); uport = uart_port_check(state); if (uport) { - oldconsole = uart_console_enabled(uport); + oldconsole = uart_console_registered(uport); if (oldconsole && !newconsole) { ret = unregister_console(uport->cons); } else if (!oldconsole && newconsole) { @@ -3086,7 +3086,7 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) * If this port is in use as a console then the spinlock is already * initialised. */ - if (!uart_console_enabled(uport)) + if (!uart_console_registered(uport)) uart_port_spin_lock_init(uport); if (uport->cons && uport->dev) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index d657f2a42a7b..91871464b99d 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -743,9 +743,15 @@ static const bool earlycon_acpi_spcr_enable EARLYCON_USED_OR_UNUSED; static inline int setup_earlycon(char *buf) { return 0; } #endif -static inline bool uart_console_enabled(struct uart_port *port) +/* Variant of uart_console_registered() when the console_list_lock is held. */ +static inline bool uart_console_registered_locked(struct uart_port *port) { - return uart_console(port) && (port->cons->flags & CON_ENABLED); + return uart_console(port) && console_is_registered_locked(port->cons); +} + +static inline bool uart_console_registered(struct uart_port *port) +{ + return uart_console(port) && console_is_registered(port->cons); } struct uart_port *uart_get_console(struct uart_port *ports, int nr, From patchwork Wed Nov 16 16:21:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233349wru; Wed, 16 Nov 2022 08:25:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4nSKRszekPac4SlJPW3chCf182qCRf1aAVYHCnqKTb9bmT9VAdmBAPR4p7t9pOcp3mmL+g X-Received: by 2002:a17:903:492:b0:188:758f:f45e with SMTP id jj18-20020a170903049200b00188758ff45emr9751432plb.12.1668615941929; Wed, 16 Nov 2022 08:25:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615941; cv=none; d=google.com; s=arc-20160816; b=P4JMC+m3fpSGylXIbJhD4pO86p8iLCOivh15lh5ExOG3B6jx7eZMIIXqqu2NbxntMe Mz27XXzNJym4gJfQD33eCHWWoZGVDw5SkW4f014eHbhxfgeMd9icvacB1lFka9K2GxjR afEiUDThuHnfjg1qQ+AubModR0I165Ozv+neMAOS/F9zasBV1uBgeQvksJWMWk1dx98Q 51kGXnqHbPxLM6ZAtH9zxUj6CUK1t3bQPZexsSJ8ezxHdBKKuZp+4O9vSCNSkKYkSeNj bGI01Qq8LjSScap/E73xeu+YCQPjQtPYS/hWPnkhs5kHCg8pZYl7OKb8YJMw6ia4srxm chAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=W6b5NfOqKhbCO1n0vtfDs0FHEhscqKbHgSYvxQsImbM=; b=We1pfvEd3vtJJz6LMvH+Nd4S/wJm9hhM3PMYIEfKY2wUIrvGpaV0el8lCN0WB+drcJ 9qyrriWw+6jAPibIwzUdrL11lbbHzZyomnqeyF4NVrFd/0tkU3D4sYrpzB8iA2mK8wa/ GLRJCIb1z/MGHgXCCAZGEmllp1fsO6vx/Bv65KKCvaercuV3PMGiM7C9cCXtzRMzYPiI 69QWWNEnxsb4Nd62ls9ytlRy5mCuB7c9nxnxxcSwHCmeETevy4ib/4UtyFDTl9SWfhAD aN6LHBZ2RxgtLGfK2aeY5SJ9DrP3fShKSvk/xWHYmjbbaAoLlYdaoSdPCooCi1q8mkRj 9ptQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IBcr1RxL; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w3-20020a170902e88300b001846e0e0511si17460672plg.226.2022.11.16.08.25.27; Wed, 16 Nov 2022 08:25:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IBcr1RxL; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233528AbiKPQYn (ORCPT + 99 others); Wed, 16 Nov 2022 11:24:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234852AbiKPQWi (ORCPT ); Wed, 16 Nov 2022 11:22:38 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4655C56EE3 for ; Wed, 16 Nov 2022 08:22:09 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615727; 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=W6b5NfOqKhbCO1n0vtfDs0FHEhscqKbHgSYvxQsImbM=; b=IBcr1RxLLQMeyECtbEihD5+SDG2qe7fRWjloWrZA2o4slYup3U8euFE14aIPz1HRHxa183 CoHwh0r1nnCCq/kVLBav99fCpMmwf8HbZod20k0BgxGL3/QduwfUoc1od2xf8BJO7CCnvD ygTXemlU10X5pYiBYBpz+zh3Tvr8uDTkvgrL2EfBOOHirNL1k0XkHhbx0MT2by9Y+1+P3j ScpGGGr3ZzrLsRGMSh2ggRF5U/snEVrx5Dg4KAcbJvvvDqKhlIJ/B/vLWWNT5/AMv17/2+ TvXximoOPlAMtZWKZ/+Li4h/lLdlVYU1BqLOiJ08cZqYOylus+X8wJZkoC3Jcg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615727; 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=W6b5NfOqKhbCO1n0vtfDs0FHEhscqKbHgSYvxQsImbM=; b=aCdGy65F2gyHzwQcJS4XmrabRrVViXls9okyGZ3p0ecSnxm0D+X6Mq6XYE9k0CGaxAQFeW TyAwIYANT63+pfBQ== 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 v5 23/40] tty: nfcon: use console_is_registered() Date: Wed, 16 Nov 2022 17:27:35 +0106 Message-Id: <20221116162152.193147-24-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670630148484247?= X-GMAIL-MSGID: =?utf-8?q?1749670630148484247?= Currently CON_ENABLED is being (mis)used to identify if the console has been registered. This is not reliable because it can be set even though registration failed or it can be unset, even though the console is registered. Use console_is_registered() instead. Signed-off-by: John Ogness Reviewed-by: Petr Mladek Reviewed-by: Geert Uytterhoeven Acked-by: Geert Uytterhoeven --- arch/m68k/emu/nfcon.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/m68k/emu/nfcon.c b/arch/m68k/emu/nfcon.c index 557d60867f98..6fdc13610565 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 = 0; - return (con->flags & CON_ENABLED) ? nfcon_tty_driver : NULL; + return console_is_registered(con) ? nfcon_tty_driver : NULL; } static struct console nf_console = { @@ -107,6 +107,11 @@ static int __init nf_debug_setup(char *arg) stderr_id = nf_get_id("NF_STDERR"); if (stderr_id) { + /* + * The console will be enabled when debug=nfcon is specified + * as a kernel parameter. Since this is a non-standard way + * of enabling consoles, it must be explicitly enabled. + */ nf_console.flags |= CON_ENABLED; register_console(&nf_console); } @@ -151,7 +156,7 @@ static int __init nfcon_init(void) nfcon_tty_driver = driver; - if (!(nf_console.flags & CON_ENABLED)) + if (!console_is_registered(&nf_console)) register_console(&nf_console); return 0; From patchwork Wed Nov 16 16:21:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21156 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233460wru; Wed, 16 Nov 2022 08:25:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf5iogzm3Cw6p7e/Z6Mrv+H9KkaqiXK1yJInIOStaqSw4a8ZMH7iDP5dtDWWLlfufo0/slaT X-Received: by 2002:a17:903:32cb:b0:187:337a:b692 with SMTP id i11-20020a17090332cb00b00187337ab692mr9079183plr.166.1668615954280; Wed, 16 Nov 2022 08:25:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615954; cv=none; d=google.com; s=arc-20160816; b=G0Dao/sEopGU5EDXEcxA4EC2asdYV2b+X6/G3RRGPSzpBo3ELss2zmIfLhqkFxZEZQ 8Gwh8UsAzQL9fXXl+sbFHcB9YfBZUxQetVxOCBgjz3oRnolbkuVzSXYiNgLa7K5z5ySV RbaWMU9yfnzBHMpSxJrwbaoGo7DdC/EPuSqWp5GKFAgPF2PnSfIuVuirOOoKDM46tBQm UCoqqPY6da+xGaRkc/L5U12Kf99mMjyl+WAaavxYih20k2E2ta2mu4DjM/als1Oj39U1 uAh/xAe3ky7cjapbPrWYzvkc4xxiNimVP0p65j79ZFAfGxBgMvMmCSt3Edf7RwDrhoIh ZVgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=pnYsucPfrpcazGqKeRJP+E7nPSCgbYv1OZ+fSFJF3FE=; b=V7Hkje0axlEzxRZ71ecZb6721rDF0q9vqy8F0WWKNhVaKaqdsaO0hTBlTlAA2dlYi5 UEvPNieXDaF9jvAYf1f0NzAGOeLarYP7XazhsqEWBI6/x7fy1he087V1Y0fZgcxrRCEK hSRxN3SooQrq77/1sJSdYMWHLLSXTYaSgYf7bA/GY12YAw08EAGzfHTA2mcWctOU2s9s kZiKSE78zchkJXt8yMFRJwMPQ9vIKEgQAFdbqMmdes3W94i5jJwMISxMplWHP4XHwhlH RUtPZA4CuTVaZri9FHwLkGylpP1D/ZUm1lhSd9gFRT6uuK8TX/j1VUDuTzZTmsywPZfp tZIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Mij3VvRC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=rPN9XGHV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020a17090a8a8100b001f31f339134si2199809pjn.152.2022.11.16.08.25.40; Wed, 16 Nov 2022 08:25:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Mij3VvRC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=rPN9XGHV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238865AbiKPQZE (ORCPT + 99 others); Wed, 16 Nov 2022 11:25:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234873AbiKPQWi (ORCPT ); Wed, 16 Nov 2022 11:22:38 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A837B4AF0F; Wed, 16 Nov 2022 08:22:09 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615728; 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=pnYsucPfrpcazGqKeRJP+E7nPSCgbYv1OZ+fSFJF3FE=; b=Mij3VvRC/6EFTcGjMoRfMHKmgufFADNOVvPxUDDVOOSOrPddxUf/MjL2jIte04n+xoT2hr 91sUQeFxNGfr+TLQTWsfBfqspOt9n255fq7uCyNxCtf0H/QmixcO5zuiecKTJ3HQk8EGPB unRmNVM+bEFHt6BoKHxnkKeoU7Etnpubat9VOidw3dLcm2+nPy7+2Cr+fSr0huD9IC4zh+ 8Otv988TZ1oHvi2a69DyX5RNZMMV2/uuj2Lf0QofQOj5pJKVcTjQOkAZvEIcREllQs2jcf P12Ld2nSBgsjL9MKh+b3ogWx23jDl8wStPXMiAee30DgS5qWmgh+dzU9u8vmjA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615728; 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=pnYsucPfrpcazGqKeRJP+E7nPSCgbYv1OZ+fSFJF3FE=; b=rPN9XGHVg2e7lvGMMTXZazg1MjVG50yjAsBuQPQhCpeWSPiuq/4enuNAqKmPa7UzDRTB0I 9YoMKvyB5Px6vWCQ== 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 v5 24/40] efi: earlycon: use console_is_registered() Date: Wed, 16 Nov 2022 17:27:36 +0106 Message-Id: <20221116162152.193147-25-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670642745195501?= X-GMAIL-MSGID: =?utf-8?q?1749670642745195501?= The CON_ENABLED status of a console is a runtime setting that does not involve the console driver. Drivers must not assume that if the console is disabled then proper hardware management is not needed. For the EFI earlycon case, it is about remapping/unmapping memory for the framebuffer. Use console_is_registered() instead of checking CON_ENABLED. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/firmware/efi/earlycon.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/efi/earlycon.c b/drivers/firmware/efi/earlycon.c index a52236e11e5f..4d6c5327471a 100644 --- a/drivers/firmware/efi/earlycon.c +++ b/drivers/firmware/efi/earlycon.c @@ -29,8 +29,8 @@ 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)) + /* bail if there is no bootconsole or it was unregistered already */ + if (!earlycon_console || !console_is_registered(earlycon_console)) return 0; efi_fb = memremap(fb_base, screen_info.lfb_size, @@ -42,8 +42,8 @@ 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)) + /* unmap the bootconsole fb unless keep_bootcon left it registered */ + if (efi_fb && !console_is_registered(earlycon_console)) memunmap(efi_fb); return 0; } From patchwork Wed Nov 16 16:21:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21155 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233362wru; Wed, 16 Nov 2022 08:25:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Up10EtmsSYUoGWZsTmLUrIf2Z2yFMT/vTaSfy51fIlC2sPUahOufr9OTi9/LaRfqGmEuV X-Received: by 2002:aa7:9197:0:b0:572:7b49:4f48 with SMTP id x23-20020aa79197000000b005727b494f48mr7669704pfa.33.1668615944275; Wed, 16 Nov 2022 08:25:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615944; cv=none; d=google.com; s=arc-20160816; b=VE7Tyy2EDtM6oxGYYhcMrm1oCxTIpRFvdzQ1UI2lPB3FsdyRgVz3OySyr8jp2deMQL d3Ej3WeiHzHQK4ysEijBj16ABbIZ7lkEBd+T7JH3IZifyCspPnaiUyYepfeK06L+E28/ hi1ZHRkbpDydmNgqCsT4LT5Hqw3lKRfdevQYw+EGCIYXEmlvl+iatqD5nTVzGt5DrYJ6 FL1No6gVNiV3Tt5JSHiRV8lL2Okd968yrAhMEcjnylB6nofylTshT+6hzEPYxWlkoc3o 0n2vEs3MymMATSMw1TUQoU1e+LjIYjGiqSk9PS+dxBgnDfQCblB4d/Yl25S64qQnOGVY ZWog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=WoAi/IMpBqhMANDygn8dBGFjZ2GQ0xeR1eRQRwl7/a4=; b=TSIVIe1EqIleDtxkM+5UtUbVkbW2RBazLwzkAekkWjd4Aq2BO/kIuRMmV6fxau2oNT vhbGiuJTgzek1rfnrFDErzbbu6dwtPCHnEulKNoViIzF2Qamu3O3rW16Y5evq95IOMaT 1CuQiI9B87KC9rU4bRpETU80nkDY8c407+Nky7eZj+EvgCXDIfQTDjYSXYDiodOzADtX Lw2+Bh6kJixX1ZnsHqr/R4bWwFNbZMdpzsadZ4zAa9TPq8J7w7WFp/2JIXIjxDSN19c5 n9S5DdPTMHqHhbAG9gIKeRUtncFp0/naX0lUk+tu8ADcTcJ8syCApoHtU7R6yEJ2+Ht4 A+VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3DQ4ybTO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=BAcrakEp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ja7-20020a170902efc700b001854f631c8esi14420448plb.221.2022.11.16.08.25.30; Wed, 16 Nov 2022 08:25:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3DQ4ybTO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=BAcrakEp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234423AbiKPQZA (ORCPT + 99 others); Wed, 16 Nov 2022 11:25:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234879AbiKPQWi (ORCPT ); Wed, 16 Nov 2022 11:22:38 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 195CE56EEC for ; Wed, 16 Nov 2022 08:22:10 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615728; 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=WoAi/IMpBqhMANDygn8dBGFjZ2GQ0xeR1eRQRwl7/a4=; b=3DQ4ybTOYcFtmwITLSHIYeVyVwnAXkGWFQW/4sJDsRLNKaCHLDRnlfSlMsgSfYPJL06aU6 HObqr0W9cSaKt1dPrg88oy2FnVMdizwcMqHQh/H9lJHeqvg7UgarLJvkZW/wof37+IqYp0 PUM5sQ0uYjBDY8iSw0ByaONYCNjofDYn38xrzQcO68QqVPwBLsAzqSolO9quGnzP4IqYSL Kw7JHvV4ZuZra98V5OSvbL4vcRlGBWHVUS9pmiBj7zVX8jdPOPuJHOJ0O0mq2VO3o03dXo bvMpC71N/uhuEhtU7QQaUNzrCbgtikuD2C5DSalmb+Zl1yXI7vuDI9zlf/D9Bg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615728; 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=WoAi/IMpBqhMANDygn8dBGFjZ2GQ0xeR1eRQRwl7/a4=; b=BAcrakEpk8MQUdoOPQfpxF5sGvK4lMHn3g/fTME1TCNLAdTunomPlI5CyDW0olh1v3Kiq5 +U26bZuftwKQNSBw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linuxppc-dev@lists.ozlabs.org Subject: [PATCH printk v5 25/40] tty: hvc: use console_is_registered() Date: Wed, 16 Nov 2022 17:27:37 +0106 Message-Id: <20221116162152.193147-26-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670632566851483?= X-GMAIL-MSGID: =?utf-8?q?1749670632566851483?= It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/tty/hvc/hvc_console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index 4802cfaa107f..a683e21df19c 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c @@ -264,8 +264,8 @@ 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) + /* Already registered, bail out */ + if (console_is_registered(&hvc_console)) return; /* If this index is what the user requested, then register From patchwork Wed Nov 16 16:21:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21158 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233486wru; Wed, 16 Nov 2022 08:25:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf6SEXjSSeqX77litoR019Z5UIUE3vsjhUi+Cor4vnuLm7Vny9Pr3IBnii9w2dgOP2iY2fL4 X-Received: by 2002:a17:90a:5d8f:b0:213:aa8:dda with SMTP id t15-20020a17090a5d8f00b002130aa80ddamr4609596pji.111.1668615957833; Wed, 16 Nov 2022 08:25:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615957; cv=none; d=google.com; s=arc-20160816; b=HxOdgEOG3jmTaCFq+puve+/gKJ0dcVA1//4kUTfkrbvlAZZNDNqCipxpEtuXIg2h/R 0iKcBRlL0qk0XSF2DdufefsVmZxSqCHyIk9QgPUXl3M47HOjMz23UA1c7kvqtY70QFXB /LhBc+z9t51PaGEdDGBVAVsvisCmMJrSJPm7fWo/BL49blflPoafZLuOIzcG5swLPiQU qUu4P8szjGIGnrDdPvs3vv7o1YZnXRXK23R/fGvKrK3St1jVhPGoyhmM79+73zGY/CEG +EmAhxMlU54OEYoKZd/RfPf8lgQKO0LLAna/nzM136nyjwtqNgnOKQ3kqtCH6p53QURZ K34A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=6hf4u/s4+AojpME8OJwmFCYo46PpjYxYo+DIhKotoZ0=; b=ew8DJtt4agDQGl54uK/wPozgaWcaX12vEQLaTOgh5r0mZb6vc5ityY+I14lhXXINY0 LITbkHYuQ33QzG24ibg3+AdS+v0mU5NbcnMgPDftOdTtDqZeMrWrIjuEGvLJzlEhkdKe Xh1De54XYu/U6aJnRzLOIQf/wkltTJ7yb9eGxkVCzjnzIBlnx9tfAcoSKhGS4xCEaila GonvwgZ4/Ub387vfh7d8iUgNVtZiqBoMSOrxqT2mcYtGT6pPdGzoaGVf3FKI8JlBJEWr USP+6xvQ2fyfw0YYwfJxqVOQCpUeNRrHF0h0MQKqlr477vAxewfXh/4Ji/ChBnchhFCM 7iuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Q2qeOzzI; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=9tm5BNT5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a65580e000000b0046ff70b1cf3si15683972pgr.463.2022.11.16.08.25.44; Wed, 16 Nov 2022 08:25:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Q2qeOzzI; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=9tm5BNT5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238876AbiKPQZK (ORCPT + 99 others); Wed, 16 Nov 2022 11:25:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234892AbiKPQWi (ORCPT ); Wed, 16 Nov 2022 11:22:38 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EEDC58002; Wed, 16 Nov 2022 08:22:10 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615729; 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=6hf4u/s4+AojpME8OJwmFCYo46PpjYxYo+DIhKotoZ0=; b=Q2qeOzzILKPeM4Fxhi7r+Gq3cQ9jsmx9lGVYfDR+fWfGhaFfr8vPWZU5AC5raFSFI/LRBA 6wpD/myRS0aIc+52+F4YdG1NGnuklXCsd9q4HAz4KM6D2UV/Qg5qo98SlFEOPLH3voeZJm g3zwpeTHvWz/+uO1Y0NYaWoiOAGYMKIRESt+fWNVYxwXCYV9D7yyZ+aA9dK3AfsIXz5UXV iZgU/RIRTXfQwttH8CJyoW1syhCUQIIq3ZAUNbBNx6wkhfpLB5pPR4tui2BTXbg428HM7R /Jlj1K86Tpu7g2BM+LQhtVZfiyc90H1FbW51PbngNGRQ4TTR4o5p6MeB2yVllg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615729; 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=6hf4u/s4+AojpME8OJwmFCYo46PpjYxYo+DIhKotoZ0=; b=9tm5BNT5j4GwYhklIDEkUD/Np15mgjT+9v3F//XA1pRocGB74UMrUCC3bDkAUA3wY9wRpJ LUSB57yO9g6sRrDg== 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 v5 26/40] tty: serial: earlycon: use console_is_registered() Date: Wed, 16 Nov 2022 17:27:38 +0106 Message-Id: <20221116162152.193147-27-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670646420690935?= X-GMAIL-MSGID: =?utf-8?q?1749670646420690935?= It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. Signed-off-by: John Ogness 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..4f6e9bf57169 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; - if (early_con.flags & CON_ENABLED) + if (console_is_registered(&early_con)) return -EALREADY; again: @@ -253,7 +253,7 @@ int __init of_setup_earlycon(const struct earlycon_id *match, bool big_endian; u64 addr; - if (early_con.flags & CON_ENABLED) + if (console_is_registered(&early_con)) return -EALREADY; spin_lock_init(&port->lock); From patchwork Wed Nov 16 16:21:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21159 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233512wru; Wed, 16 Nov 2022 08:26:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf4yJ+Bra0XII1Xi+39KAZBKQkjyh6gzTtSF8nxVaNra2oyFz5ZIjtaz0NJhj1URXN3gx7K+ X-Received: by 2002:a17:902:f601:b0:17c:b7ac:86f with SMTP id n1-20020a170902f60100b0017cb7ac086fmr9556360plg.140.1668615961358; Wed, 16 Nov 2022 08:26:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615961; cv=none; d=google.com; s=arc-20160816; b=tNoMTfcfzkoUBj61Ug25ialkYU96FxlI/iUQ9G6ffumOwmAJqjPGXh4Sr+uliX/Gyl vlRj1K7mjuv4AruI/2tLnxEtGsMY26fOSWxve5C7cKgwdMmuzjltPdFoM8ew9CEe9Poj coKZZ1VhRXQfVK6j62nShDmTiZcEaURCAp7rPBCgsLX/RROFNStSgyPSnESnWnl8N3ws 7aK6Mqjzas98thy6o4062cz9NI9d/VLwNEbBF276bkm5ME4iBzRpLuzdj0QCrKLL9ni+ VMauseXEnRGP1Fc9dgl4kND4fcvndWQT/Dc8G+qes+P2hHRLhB0gzT6x1GV0PSb0unAl x9zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=mrnamDANz6jBB9jzBVW9G8ct2/m0qCRJ/AQBo5wVT6Y=; b=Z6PJmzqg1qLdfZ4EmRu9koPmsOihmujZOKTqPnMasE+IbzuUgJLDaVhrpXZPHslOol sAcK2Cj3pdht4lBaxvKZGvzv6pJL11dHHRtm+jp+LjpwdSXdmhAAmwxGW22JC6V7H1CE kjzmDXhjMVfu/6uYcMlNpKIcMREYDNyFlHiOL1sbfV6MshW0iznptKWLqrTTqI+uY3Il DpKebmwauvN+tLJIt9EuN92f2ZNFFAA3Z14/EIti0bsnArN6VTr74hxZCzIyzAiu75m4 F7+A8piJXOygA5mP8MpQOygq04epj9XLgnlv94CRiSs6j85h3sv2XZv/fv+lrXVcv3s9 pXYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IHfhXeIj; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rm10-20020a17090b3eca00b00213d512f07csi2415936pjb.182.2022.11.16.08.25.47; Wed, 16 Nov 2022 08:26:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IHfhXeIj; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238910AbiKPQZN (ORCPT + 99 others); Wed, 16 Nov 2022 11:25:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234897AbiKPQWi (ORCPT ); Wed, 16 Nov 2022 11:22:38 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3FFA5800A; Wed, 16 Nov 2022 08:22:10 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615729; 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=mrnamDANz6jBB9jzBVW9G8ct2/m0qCRJ/AQBo5wVT6Y=; b=IHfhXeIjsu1hLZtohnzmRyDQmIktHtCYtoLquUTX2WSs5AO+5oHUdvyoEj3rssbn/r0Y/n LMkEMBqml3FqzurxWRiZbvgQnknV+eWTnQhVjLO4dqmzTHdT6nEJ/dHdm5ueYtBLFKnVPG 7np6nZtKtTBIMf2c1cwFYwYyJXAnKkmrvQZyEAr0GTCs9TTNGzYN0X64YR72T3shSCPxGM PBt+JjIrnMCiHi276+OsE946KngZDh4Ca/QFJt3t66u781zZfphAn6s3CglQk0EWgWzB4R /N6YP7kfixbkSrERtdxAiyQ8AkodcDy2N4VKRKd96wdm31dqJaNXmUvQIxGZBg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615729; 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=mrnamDANz6jBB9jzBVW9G8ct2/m0qCRJ/AQBo5wVT6Y=; b=olP4GBMpkyeoYDHbACveIAi5zWc4NUMK1WYldtniy3N5RaKslutK2zK06oNEdudevtz8ET WYnWXIL4VwK4nqDQ== 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 v5 27/40] tty: serial: pic32_uart: use console_is_registered() Date: Wed, 16 Nov 2022 17:27:39 +0106 Message-Id: <20221116162152.193147-28-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670650367610893?= X-GMAIL-MSGID: =?utf-8?q?1749670650367610893?= It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. Signed-off-by: John Ogness 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_uart.c index 1183b2a26539..c38754d593ca 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_registered(&pic32_console)) register_console(&pic32_console); return 0; From patchwork Wed Nov 16 16:21:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21160 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233540wru; Wed, 16 Nov 2022 08:26:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf5PTaMbq+W2757I/ijSE8szYg2AOj+DiJybqbKqUBN9quD9LbBBUHXU8Zmwz0K5cLzv0P4i X-Received: by 2002:a65:4606:0:b0:454:228c:742b with SMTP id v6-20020a654606000000b00454228c742bmr20952397pgq.494.1668615963689; Wed, 16 Nov 2022 08:26:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615963; cv=none; d=google.com; s=arc-20160816; b=unSI5347NIYNuXNlcyfLkZQaaGBkYsSAC3Cr8W9TmfKvDVQdtBCZU/7mySInuvCFWB GVz6i6brBXwpwN0+8yrBMFYsd65bNPBaoLlcKfdIm9XUmuMJhYu3IuVMWL00cFbDVqVw vs1HwkrE18a/d4W7swCJQo0fDhDxU+uEnIW3Q+CZCi49fDnWnvfPdw+oKby0mBQRGIjy vYL8xzxfSdG++Cn9nLtwAwJUqd5+kHcWPaCVji4HHbz0C8qx/76RYKyk024wHEfdB0WK 5yS445z919F5tpGoOpinLFtdERj9fSot6JxhswSqEINKcLQGXOR3mCO/qaIcLdQ6PN2i JR9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=d6cWj091YR59AcrR/13CETRi+pH3BIcbTfvrd6iofMY=; b=ZMxxzN0TOBX1uC18gw14OffHAQ0wB/Oo8kWy+CDO6Xn3XpVwN0xFfpQI0AB2cjiIZf BTuPQHZTaaRItAmkhxsKsWRmF6Y7FE7xjX9qY7t0I3mWjb2OoUnhgvmKyAv1kRcpyZXC IU+ssH+ycolT7taPAVOqMtT+If+9Br1sw4US8KxN7n7I1beY8/g52QSl1HgmF1auIG0z byNHg6ED4c+ctgb73E7GvW7d3MR3VoMuiRKje4aGh7E7u791gmw0IVmCyEQ+B0W94QV7 5qymezwHiX4flZdbMM72elFCaeI/NZFeKcYOaKypHepZrJSIyB0waKyAcyKFeCP7ri44 oMAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3khnPpY+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=hFnbxyiz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k4-20020a170902c40400b001782a6fbc7csi17695123plk.463.2022.11.16.08.25.50; Wed, 16 Nov 2022 08:26:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3khnPpY+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=hFnbxyiz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238812AbiKPQZS (ORCPT + 99 others); Wed, 16 Nov 2022 11:25:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237515AbiKPQWw (ORCPT ); Wed, 16 Nov 2022 11:22:52 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BD8558023; Wed, 16 Nov 2022 08:22:12 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615730; 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=d6cWj091YR59AcrR/13CETRi+pH3BIcbTfvrd6iofMY=; b=3khnPpY+/0fVbClsRREkWs+Q0rzC4dedV7WP9ZYEJeza3chK230FUcVWmGWZWi1f1bhKyB fEyERbPaQyvmfBXggZEKkfr3zRQAv9j8vm+Jm1CSdYHYaUI878LYiSxaZBkgYEdU7VUwZf XTC8wpcneFOj9epONio+fEkm/kmfZRM+BgzHRQ3fYJMoOxhoRulDRrWT5jId6d8uNHOHhc J9yfIl/8aHl5bX32DTboKW286Y8/ZWbtCHcjonQIObk1Fznbhbyknyc68CVCthdwJcVx4O dAbw47J/ZTIxqoSQPE3Lwhm8znog0lnFqpZXChRtuniK/s+a9+v3ETRX6DRoSA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615730; 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=d6cWj091YR59AcrR/13CETRi+pH3BIcbTfvrd6iofMY=; b=hFnbxyizVoAFtF6UneYybCMMjmZEAsRbkbgOmUKZJnHjqlNXWF0OaEpllQoZiooagRT1M1 uPmVcrJryP7t0XDA== 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 v5 28/40] tty: serial: samsung_tty: use console_is_registered() Date: Wed, 16 Nov 2022 17:27:40 +0106 Message-Id: <20221116162152.193147-29-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670652763458376?= X-GMAIL-MSGID: =?utf-8?q?1749670652763458376?= It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. Signed-off-by: John Ogness 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..9c252c9ca95a 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(void) static void s3c24xx_serial_unregister_console(void) { - if (s3c24xx_serial_console.flags & CON_ENABLED) + if (console_is_registered(&s3c24xx_serial_console)) unregister_console(&s3c24xx_serial_console); } From patchwork Wed Nov 16 16:21:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21161 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233566wru; Wed, 16 Nov 2022 08:26:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf7+gV9edBi9JSkUWV7gLjPIwwUbbtde+JNzftOcmw5lTztzPMhoPpAfdCOVGUFKMKgoURYk X-Received: by 2002:a17:90b:1bc3:b0:212:ed58:2825 with SMTP id oa3-20020a17090b1bc300b00212ed582825mr4547403pjb.199.1668615968255; Wed, 16 Nov 2022 08:26:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615968; cv=none; d=google.com; s=arc-20160816; b=OqjTzA+u6V3uJe8EWU/NBy2Et1FDhB/yXvAzIdbQGFeSKbyn7nIVJ0cFaGuYlkVhpD YlpSWRag3j8uN0NfbZ5zZnrqlcZQFhBO/4dcEHjHGSxyjTvxmrtfgWEErIwmMj+QooOm UK20whSyVCp1f6t3pxIfm1J/t08Spk3MwXAXXyUphwG7i7oo1m7IZW/fdlIdGlY+u818 ha2DZtOYyb76WrQFALNBLPciAsk7OfQFbCcq2hm5l5kWtcxZxU7z73yJy1UsVyN9rZtM +R91hU6xRL9trsvL4kTXHVr4xrY6GbXmIJ5Iwl8YwOkSU9w0X/yNWc3Mhfu3mGzbChux LrmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=n0N6+oqs8YDesp1N8syBA/TOKLtd+9UFIcKPgI5bch8=; b=CIrrnvmab3eaefQ0yFasP31zuT4pL82W+ss6LsUTA4RFv1Hf9CxPDS/ldMuKdPFmJR L3jE0FyBc2wi2SbiM5Rpe6tAPoNf8wsYtk3IeuiaJvrf+5C9fWU3Xs7hCNCxLkOsc41q j3FZ72yDtZyb+FOq5cORmB362+aYo/EQLhGSFjyBlm0HRXOcJL3Gn3+M+URcxZHe6Rns g6ioj1sWNt1LPO+U4DFucQZzRuWGE0dihOIm0h3SI0D42vDKs3Nq19MhGQsvhI1i4H4W H50ymfQjVbzSLOF5j1LDiRQRxjVrk5qNHvI85ZYEQAeVToumMcZftl49oexPbAW7Lu3x INEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wPgQxX1o; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p10-20020a635b0a000000b0043934d930e4si14915742pgb.297.2022.11.16.08.25.54; Wed, 16 Nov 2022 08:26:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wPgQxX1o; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236176AbiKPQZV (ORCPT + 99 others); Wed, 16 Nov 2022 11:25:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237567AbiKPQWw (ORCPT ); Wed, 16 Nov 2022 11:22:52 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9596057B5D; Wed, 16 Nov 2022 08:22:12 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615731; 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=n0N6+oqs8YDesp1N8syBA/TOKLtd+9UFIcKPgI5bch8=; b=wPgQxX1oQOVhnIHx4abeauz5e7rEg0cwq5AOSReGNyVI0GuDMJ6kOxzMqgo1hBiby93eiw 5hBeCrKYPerk7JvYO8vosiWvKyDPP4cAvtIpw/1zVg+gGlgIShIO0DOXM0NlWFYl5WeH1w WA8DgdazYTIbRMqodAkgxFBB3+Mm0uDgTkJf3dn5f46ZjCd5kn97toOZnVj/equ7JrSvUO r/4XzPjW/bQmnrL64Or8kzA5/4EVeUCgg1O+2wDvVFNd9QBb1iSKtJUbwpkRHjvnQ/F/U4 G0cFr/34shXiB9Hei+AMjQk4UsbqUF58IDPWuUFjW50qPwjkdAmfQ9w5cU+LXQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615731; 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=n0N6+oqs8YDesp1N8syBA/TOKLtd+9UFIcKPgI5bch8=; b=MyQecpelV/Y/Ej5hHdh0TQTK+n3Ui1E7BQDeR9U4wt14VpwlS8pr/VUvxnyUuEshVddrWN FzYp4/jEDqsa0BBg== 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 v5 29/40] tty: serial: xilinx_uartps: use console_is_registered() Date: Wed, 16 Nov 2022 17:27:41 +0106 Message-Id: <20221116162152.193147-30-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670657097007727?= X-GMAIL-MSGID: =?utf-8?q?1749670657097007727?= It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. Signed-off-by: John Ogness 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..0cbd1892c53b 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 *pdev) #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 == port && - !(cdns_uart_uart_driver.cons->flags & CON_ENABLED)) { + !console_is_registered(cdns_uart_uart_driver.cons)) { console_port = NULL; cdns_uart_console.index = -1; } From patchwork Wed Nov 16 16:21:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233783wru; Wed, 16 Nov 2022 08:26:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf4nAxbAxvHpdr66tJckXcfDbpVaTFJzm5qu/SrUQJ44upe4hS7F1QF06WCw/8oGCw8zR4Th X-Received: by 2002:a17:906:ae53:b0:78b:15dc:2355 with SMTP id lf19-20020a170906ae5300b0078b15dc2355mr18064998ejb.306.1668615990752; Wed, 16 Nov 2022 08:26:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615990; cv=none; d=google.com; s=arc-20160816; b=HIU+BDbqtkMKrnRJxPuEyDEVZQ9rEbMNII52GSUgaiVFiBf9yMMt9kXnguHRRH+akO 4pp6nQqGziacvVLK07tJpYIExMvWcJIhHEZhLXyF3QgDoPRlJlBvgu91XFMJNWRCO5nS Mx0vqUk4IEqE7x29oOgvow8bLM5F20uLFdm+3rwfsOVPg2OGNTUeLFNbmFpIU3rfs6Ji qmf6FSue1v1UXXL0+oW6C6oZkRsTB6t85McTJ6NS3CAndETohVHjJlzsxuF83F2qIobM a8boyDvYJvmbyZ/hvfQcwpEBeMpSzXjfvQsIqv8rMZzbziBC2BhaTjL/hcm7+nTGq4dW OzXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=pqonCTPpfZXjo2LPJFdK8fQ8y1w5Fa/kW7qM4AbVqk0=; b=p45foi6545j+HLU2Llz7yNnc0xNY7EwCEaFFw6h0kb+7t+73sHpxTm9ai5wWmB3VfQ bOGb1nWC3jYqRGMBu6SCf9eVCCEQgWHjBAluemfL5mFxibFt9qolEXMfgtZXDVcxx/a7 MUJ6u2bKMnXCEXkhN136SlmMHyi+6Ay9waFaX54uBckRHhpJ1QnfcbJV9MaAAEPHKoj+ v/QeSSjHQifAdf355N0vlZXlWMTi9VZC3F2aJj5bsq96m4KXhFn8FtZ+oKSHFzMSGabJ 8FI9P6PzkgRKZ9AvH/W7mKw9whBISBiijsZVvfwzYDlaFulENJYUfx6HU4s4SWi6qVpy bu2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OgkpFCVa; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=JV6AAcU+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b17-20020a170906661100b00783a5f78700si6090659ejp.226.2022.11.16.08.26.01; Wed, 16 Nov 2022 08:26:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OgkpFCVa; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=JV6AAcU+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238971AbiKPQZd (ORCPT + 99 others); Wed, 16 Nov 2022 11:25:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237725AbiKPQWx (ORCPT ); Wed, 16 Nov 2022 11:22:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FCB558025; Wed, 16 Nov 2022 08:22:13 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615731; 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=pqonCTPpfZXjo2LPJFdK8fQ8y1w5Fa/kW7qM4AbVqk0=; b=OgkpFCVaiSeO+LQ/j6+zQtq0n6iDywSpXysWk+wGMxn5NY8Lpi6yEZG29Hs13yIGUGGf7R IovDJ3VKpFrFu0ZT3784+ms4boN8yY81gPMPLxy5VLgxm9VswgG4LDSV6RwpCD6M18PPQ3 DyvuO05Uo5p96U8R2Agq2vPpwEMV8YpJCMOK2BdOpY5PZsYXMaM19hhfMKY/s3owD+3a5k O/HcKUBHgAWTZQjptpPfbkxfcF3tdywNkKIjcDhE2kwOn6GOZFG+EbEt0l4AsvopEYk96q N4BTImkK5B+on64cfPxFCgcXeQozIy0aoaIyDk++6N4dgk7GQcfgKy1so48+ng== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615731; 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=pqonCTPpfZXjo2LPJFdK8fQ8y1w5Fa/kW7qM4AbVqk0=; b=JV6AAcU+EGEfeBSOpHE/d0qAz6Prk9Itjm/unhVn8fP0nUKjQJimz54c1dr/2zk1crSuUF XRu1eOSeIs9uzyBw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Peter Zijlstra , Mathias Nyman , linux-usb@vger.kernel.org Subject: [PATCH printk v5 30/40] usb: early: xhci-dbc: use console_is_registered() Date: Wed, 16 Nov 2022 17:27:42 +0106 Message-Id: <20221116162152.193147-31-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670680892776173?= X-GMAIL-MSGID: =?utf-8?q?1749670680892776173?= It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. Signed-off-by: John Ogness 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..797047154820 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) static void xdbc_unregister_console(void) { - if (early_xdbc_console.flags & CON_ENABLED) + if (console_is_registered(&early_xdbc_console)) unregister_console(&early_xdbc_console); } From patchwork Wed Nov 16 16:21:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21163 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233687wru; Wed, 16 Nov 2022 08:26:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf5f/rOZZVjH9yEa2Ih5+mvStTVPOWLfvzrx9C6+1M5IE8AHgGPRWAmD+VRpJjtsDTJl5WBB X-Received: by 2002:a17:902:760e:b0:186:a185:1327 with SMTP id k14-20020a170902760e00b00186a1851327mr9529536pll.54.1668615979416; Wed, 16 Nov 2022 08:26:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615979; cv=none; d=google.com; s=arc-20160816; b=G6tBnbbxqmAmQVanIkRxyW1Ph7YlMX3To1c/NXFfzvt0TWnXAzwnrsIJF3Dcd/h71N Z/9DRWZHq20Dsg1IjV0i6bttweXPli3BtS/WgkR2/t4NfG/N1aaejt3wQxsZfyAdbzCK qVQFQd+2ZfkZ42/j36y+ZYg6ZR2j3a1e/5NfqGCMtv5eMp0bpWlLramRMkfAO4R1DCCG Wn20DkT6WEwUmTeSsDmgxKorCaiFlbFWRIeJFzE4ywWKH73KkX1wR+CRODebf16Ho0uE e+fxC0qWCkGedPROOj3SaJeewDCEtNz7puujRHEpNtaqAOp8F0lbxnRZ/sYuJ2NaygWP PA4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=nTf9OGb9zWeAnXP7WUtzyXzYpJkGff40DU/J1LONmEY=; b=xwtHW9ljH5mAN1tD4TJC3RzPTNzj+Q2zm/UowkjIzcuDKtiG5hPUFCUEYwVqB5T6q2 jmD7o0lUyDp8CShPRdQplsLvVBWd/jQZP4ew+te8v1h+SgOJ+qx3thRiFiRGwfQa76/H 2tvcY+ErpZDvhaRw9AnIo02CerFTS4TJjvlDouU5jbuRZuBqbFaiwiw7UNSZg2rwN9/e BzZAIP+CKIxTNMSoxm95khGc29X2g+BzTg+0F0cfC+W0tKIBEmFhvlw0d76zMEEMx8S7 ABsC/pzHx8oBHBmsuobx6aY+LQej4i6oSDzi4rtgfd27Sj7v4LgY2LerQ+225zcCBFKt NUEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Y1QeJrew; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mu14-20020a17090b388e00b00217d892ab40si2627344pjb.29.2022.11.16.08.26.05; Wed, 16 Nov 2022 08:26:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Y1QeJrew; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234801AbiKPQZi (ORCPT + 99 others); Wed, 16 Nov 2022 11:25:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231448AbiKPQWx (ORCPT ); Wed, 16 Nov 2022 11:22:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F1F957B6D; Wed, 16 Nov 2022 08:22:13 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615732; 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=nTf9OGb9zWeAnXP7WUtzyXzYpJkGff40DU/J1LONmEY=; b=Y1QeJrew+e6r3Z7q+FGlwdWrI4cvw5D3zZSh+yYtZ1MEqsgX+54C7plSKQvhmMf4aOXQaT VB5UDGsmTAu5RiwkT/vpLkAveZNL/nhhSnKNreP1IwT1LB66fbpTXNYBLVTqTfTUInn2uZ ZtMz6nBbtfygicnQlCkMnZvKSiNfzeroIUJwCciUpSdoB3yTAViIjUm4q3Zuy9YPA0IAZZ hH9dJXCHjBzaMXXotdH2VL1Vny2M7EHH1CVH/T2z7nhLqxD22Yv43bQ+yMIO8HuFnDu9kt dij2aDJdZte4xlClhtTtLXnEduAIei5RzfkkwJbyZ3CfXdwosiQANNs1SlEaGA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615732; 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=nTf9OGb9zWeAnXP7WUtzyXzYpJkGff40DU/J1LONmEY=; b=yP8+k9Y87ZNwimyqdvpkoA/iVWsPUdCLDpRYhp8K7DNK/Q2rt0iVEsSU3DDL7sxRHTzyY8 cXk/oSk+2Cr8pcBQ== 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 v5 31/40] netconsole: avoid CON_ENABLED misuse to track registration Date: Wed, 16 Nov 2022 17:27:43 +0106 Message-Id: <20221116162152.193147-32-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670669044202460?= X-GMAIL-MSGID: =?utf-8?q?1749670669044202460?= The CON_ENABLED flag is being misused to track whether or not the extended console should be or has been registered. Instead use a local variable to decide if the extended console should be registered and console_is_registered() to determine if it has been registered. Also add a check in cleanup_netconsole() to only unregister the extended console if it has been registered. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/net/netconsole.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index bdff9ac5056d..4f4f79532c6c 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -332,10 +332,8 @@ static ssize_t enabled_store(struct config_item *item, } if (enabled) { /* true */ - if (nt->extended && !(netconsole_ext.flags & CON_ENABLED)) { - netconsole_ext.flags |= CON_ENABLED; + if (nt->extended && !console_is_registered(&netconsole_ext)) register_console(&netconsole_ext); - } /* * Skip netpoll_parse_options() -- all the attributes are @@ -869,7 +867,7 @@ static void write_msg(struct console *con, const char *msg, unsigned int len) static struct console netconsole_ext = { .name = "netcon_ext", - .flags = CON_EXTENDED, /* starts disabled, registered on first use */ + .flags = CON_ENABLED | CON_EXTENDED, .write = write_ext_msg, }; @@ -883,6 +881,7 @@ static int __init init_netconsole(void) { int err; struct netconsole_target *nt, *tmp; + bool extended = false; unsigned long flags; char *target_config; char *input = config; @@ -895,11 +894,12 @@ static int __init init_netconsole(void) goto fail; } /* Dump existing printks when we register */ - if (nt->extended) - netconsole_ext.flags |= CON_PRINTBUFFER | - CON_ENABLED; - else + if (nt->extended) { + extended = true; + netconsole_ext.flags |= CON_PRINTBUFFER; + } else { netconsole.flags |= CON_PRINTBUFFER; + } spin_lock_irqsave(&target_list_lock, flags); list_add(&nt->list, &target_list); @@ -915,7 +915,7 @@ static int __init init_netconsole(void) if (err) goto undonotifier; - if (netconsole_ext.flags & CON_ENABLED) + if (extended) register_console(&netconsole_ext); register_console(&netconsole); pr_info("network logging started\n"); @@ -945,7 +945,8 @@ static void __exit cleanup_netconsole(void) { struct netconsole_target *nt, *tmp; - unregister_console(&netconsole_ext); + if (console_is_registered(&netconsole_ext)) + unregister_console(&netconsole_ext); unregister_console(&netconsole); dynamic_netconsole_exit(); unregister_netdevice_notifier(&netconsole_netdev_notifier); From patchwork Wed Nov 16 16:21:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21165 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233746wru; Wed, 16 Nov 2022 08:26:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf48n9kWmXDG7FMBijk3s3CS5DC3Dtc6uKOJMm7bKcbF/03AP1FjqeYdvjENS5rw7molbGM1 X-Received: by 2002:a17:90b:46d2:b0:212:510b:5851 with SMTP id jx18-20020a17090b46d200b00212510b5851mr4408953pjb.57.1668615986096; Wed, 16 Nov 2022 08:26:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615986; cv=none; d=google.com; s=arc-20160816; b=PFiPLUthzG+PMYXM56bJZ6qtdBc6IGcndi2maJJpiDjdgjKPbkUWEuO0FzwjxApy8r dMvgk18+kReFvHno4RhnP3ZKSCbHtUvbjgvdVzGX+RrmoFFc80M1i2NjnXmYdnSIklzR lnSawQrSt/TMTGc1KfVfzcNm6uCMzUwhjkgSAow3nu4hhWYR46VUrX1E44BMSY2kMJLK qHMpaGd8rXkAUT0oNgUHE5P4vWnNlpHf+/BaJJ+S8G8Ju80Cv7JojZcpWcDzzs5YyyAO fNz5tfsiYzPhkecGrNoTETqLOHUwpdTrtX+wRZ/dRY9InqHzLxKhLGVYToV1minC/ome vrNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=TXbxC6JVJ+uC/rHR//oihXQviGVU9SyaOLb0BW4WVkQ=; b=lmEN7xwh2MWAfUVBlyc1zRJnc8Z2m1pVI+PqrQ28frakAaEP2DeHPyYFxtTgD+zLVX ecldNeTDzilVuy2Bh2FRkG1ZfqkjKR2nbYT97J72huCg+gB9C/eNBtjLRggXvzrBNJcQ yTvZN9M1Mz8E7YoaB6MS0b074OEMwQVb+xGmBMPf3Nz3oCEfAOzqlNUvsteKwDB7+uev AJ0OZk9wZTzmrnU7YYKK34/FmsqGZjtkeRfYDa/B3RwMslu8AjJ8uG1rPMehQTx8vQn1 0p0YFuExDm738dcqLIY4lU4BtHU2Rf+UkswRLO1aEqGJL4sOgUCW1Lit4WcP3+vmx8lM axcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LkpXIHJO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pj8-20020a17090b4f4800b0021308f24606si2324622pjb.123.2022.11.16.08.26.11; Wed, 16 Nov 2022 08:26:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LkpXIHJO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238725AbiKPQZq (ORCPT + 99 others); Wed, 16 Nov 2022 11:25:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237885AbiKPQWy (ORCPT ); Wed, 16 Nov 2022 11:22:54 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2908E58BCE; Wed, 16 Nov 2022 08:22:14 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615732; 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=TXbxC6JVJ+uC/rHR//oihXQviGVU9SyaOLb0BW4WVkQ=; b=LkpXIHJO8B+YQGVTcPEhOmF6o85fbBVZsjNCb9sna4O0OUflqM62zl7N8YLgWUtINRBDq9 6loOUJNzVVpmAhyP6TDqkZAgy2b+mvZVDCouf4GSyq86hzmRxgtezOj4rELb7tocUScO4J 2DZjAcUhvrNUcjl9DGPJex9xVKNBtJgAgIbA7I9hqDxka3fENpGkCHHFDD/Bs5jbbTDdOa LuRBlUdyNLAyaf6qB6291uSzCLyXW3HqT4OyoXaYQZrqdciDZVDsm9HM8BlWNrufeLn/c6 jYo1WB6s3s7NlsFNAFmDgPC2uqPJKlTomPPgESDMnrms5xVN23fG91jl8N0Y9g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615732; 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=TXbxC6JVJ+uC/rHR//oihXQviGVU9SyaOLb0BW4WVkQ=; b=aJ+OvlENo5zCvnworlHkhLW2ECjAESLEwtxR1qampDPfmlrUySSqcLernNYaBQewAHGX5b JujLFM840TLOzQCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Helge Deller , Greg Kroah-Hartman , Thomas Zimmermann , Javier Martinez Canillas , Juergen Gross , Boris Ostrovsky , Tom Rix , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH printk v5 32/40] printk, xen: fbfront: create/use safe function for forcing preferred Date: Wed, 16 Nov 2022 17:27:44 +0106 Message-Id: <20221116162152.193147-33-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670675899801499?= X-GMAIL-MSGID: =?utf-8?q?1749670675899801499?= 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_locked() and perform the full operation under the console_list_lock. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- drivers/video/fbdev/xen-fbfront.c | 12 +++----- include/linux/console.h | 1 + kernel/printk/printk.c | 49 +++++++++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/drivers/video/fbdev/xen-fbfront.c b/drivers/video/fbdev/xen-fbfront.c index 4d2694d904aa..8752d389e382 100644 --- a/drivers/video/fbdev/xen-fbfront.c +++ b/drivers/video/fbdev/xen-fbfront.c @@ -504,18 +504,14 @@ static void xenfb_make_preferred_console(void) if (console_set_on_cmdline) return; - console_lock(); + console_list_lock(); for_each_console(c) { if (!strcmp(c->name, "tty") && c->index == 0) break; } - console_unlock(); - if (c) { - unregister_console(c); - c->flags |= CON_CONSDEV; - c->flags &= ~CON_PRINTBUFFER; /* don't print again */ - register_console(c); - } + if (c) + console_force_preferred_locked(c); + console_list_unlock(); } static int xenfb_resume(struct xenbus_device *dev) diff --git a/include/linux/console.h b/include/linux/console.h index f716e1dd9eaf..9cea254b34b8 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -291,6 +291,7 @@ enum con_flush_mode { }; extern int add_preferred_console(char *name, int idx, char *options); +extern void console_force_preferred_locked(struct console *con); 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 410d3f2cdeb3..ece34abbc9cc 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -247,9 +247,10 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void console_list_lock(void) { /* - * 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. + * In unregister_console() and console_force_preferred_locked(), + * 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. * * Detecting if this context is really in the read-side critical * section is only possible if the appropriate debug options are @@ -3489,6 +3490,48 @@ int unregister_console(struct console *console) } EXPORT_SYMBOL(unregister_console); +/** + * console_force_preferred_locked - force a registered console preferred + * @con: The registered console to force preferred. + * + * Must be called under console_list_lock(). + */ +void console_force_preferred_locked(struct console *con) +{ + struct console *cur_pref_con; + + if (!console_is_registered_locked(con)) + return; + + cur_pref_con = console_first(); + + /* Already preferred? */ + if (cur_pref_con == con) + return; + + /* + * Delete, but do not re-initialize the entry. This allows the console + * to continue to appear registered (via any hlist_unhashed_lockless() + * checks), even though it was briefly removed from the console list. + */ + hlist_del_rcu(&con->node); + + /* + * Ensure that all SRCU list walks have completed so that the console + * can be added to the beginning of the console list and its forward + * list pointer can be re-initialized. + */ + synchronize_srcu(&console_srcu); + + con->flags |= CON_CONSDEV; + WARN_ON(!con->device); + + /* Only the new head can have CON_CONSDEV set. */ + console_srcu_write_flags(cur_pref_con, cur_pref_con->flags & ~CON_CONSDEV); + hlist_add_head_rcu(&con->node, &console_list); +} +EXPORT_SYMBOL(console_force_preferred_locked); + /* * Initialize the console device. This is called *early*, so * we can't necessarily depend on lots of kernel help here. From patchwork Wed Nov 16 16:21:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21164 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233719wru; Wed, 16 Nov 2022 08:26:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf5xpC4SjhaN9PaWJ+GzIJpPXgNMAIQhhSjXY+jvIN9AbKQB5tu8AsZcl3oHElqx0VGKN1IT X-Received: by 2002:a17:90a:470e:b0:20a:61a4:9389 with SMTP id h14-20020a17090a470e00b0020a61a49389mr4467913pjg.20.1668615983695; Wed, 16 Nov 2022 08:26:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615983; cv=none; d=google.com; s=arc-20160816; b=hXDuHVeX5oYKrszEmR3cAomxbghbYACEYIzMUXAp4oYXdnDQpOwtw2dW0HlaMB5fGm bl+5/kZK+4CfmskZRTDYUq64h03nic4YZFw/irXbcFW89BfSN2CUZPiD2kXT//T/yfPh eWSAStEoqEyfLux6SvzRE+qtPN+YwijEWzgp71sG6L4hcBBQcXCT9G+wZPNbITN7Cyu0 eGCMILkr1aBZxkKEeKGb2xrTjvwN3UHleN95UnTv2owctgXT2t1+6oVdQkAN3zGv91uX cVoT6OO5urjkF8WIyRp5xpM9MM+xTsKZA977N23+FJIo0xUQ8P9v6yxoKTxvqG1GBxHi fVZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=OuuuTA4YWeOsJFG5PLdantkjarf2V1vxrJ2SuyPt64s=; b=vn1OSxP9nwmhi5wzLrNSLgppE8wojE7r2iRyN3jBRdQXUOMDeCFr7l9YOcymm0j2ND UV0iefkT6GXYs6N4v8t6x6jk9UEEfoeSEovxu0SgvLyphidI38vkiWnDpo1rOR6FYuCq WT2vOtXNlmc6+hlXqomAHHN4y6pR2vo/2tshObwG7YobvTbFSoY+MXc2wiAfANqoXxm2 K/QLdGNCRYiGXrCI6htKBSN9D5Ky42lZXbJfgsCiCu0Vc/fg4YZ01Xqu9tNsQBmuz6tS 6j8BIa3enyIU/FBUK+ErWQwQgPfaMDjvoWL9ywmOUQtkV1vXhsLw208MRtiHbxPclqGI jNOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GqEDEE3z; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=cWNjqkii; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f36-20020a631024000000b0046f72960506si15775328pgl.422.2022.11.16.08.26.09; Wed, 16 Nov 2022 08:26:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GqEDEE3z; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=cWNjqkii; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238617AbiKPQZn (ORCPT + 99 others); Wed, 16 Nov 2022 11:25:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237884AbiKPQWy (ORCPT ); Wed, 16 Nov 2022 11:22:54 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8293758BD5 for ; Wed, 16 Nov 2022 08:22:14 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615733; 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=OuuuTA4YWeOsJFG5PLdantkjarf2V1vxrJ2SuyPt64s=; b=GqEDEE3zp/IRKIG7fVAtRnGyQYw8WjwWd4Q42w/o6PvPKiYO/I2UO9DeTHM3FJ0AKO0jvp LdOOd6uoG+vhbGCFBO7LBcXhhdAUApmgiQs0vuidLt14ucgw4AvLmW3ELjtEKxLG3N4KGx Q+9wx4UCYMejQEuvs0LMZiYK45HlAH2uV2vbxLpNjLMnhI4VYzHLHvp7JVcTvWg9ZPaU4Y qBnwFK9fzDv3qO7YojD6nmxsxJ6UqqxLGW+8ec2hNQOjRHVhBBr3T21cpJRNKBLJGbDGij w/e68WEuDCriejd7+eCTKF+cvy9G5bS5T0Z2sVAKmxN7wYRNwAe3135cVf0Dhg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615733; 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=OuuuTA4YWeOsJFG5PLdantkjarf2V1vxrJ2SuyPt64s=; b=cWNjqkiifbJnp+I8ut0vwNHx0n+1msAV6ALZLKMXEExGS/PVCCHSzpewmPRNwZytzWeWNm pETM9jyn9FGbzaBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH printk v5 33/40] tty: tty_io: use console_list_lock for list synchronization Date: Wed, 16 Nov 2022 17:27:45 +0106 Message-Id: <20221116162152.193147-34-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670673808729089?= X-GMAIL-MSGID: =?utf-8?q?1749670673808729089?= 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 responsibility will be removed from the console_lock in a later change. Note, the console_lock is still needed to serialize the device() callback with other console operations. Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- drivers/tty/tty_io.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index ee4da2fec328..cafdff575716 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3527,16 +3527,13 @@ static ssize_t show_cons_active(struct device *dev, ssize_t count = 0; /* - * 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 and * race-free reading of @flags. - * - * Take console_lock to serialize device() callback with - * other console operations. For example, fg_console is - * modified under console_lock when switching vt. */ - console_lock(); + console_list_lock(); + for_each_console(c) { if (!c->device) continue; @@ -3548,6 +3545,13 @@ static ssize_t show_cons_active(struct device *dev, if (i >= ARRAY_SIZE(cs)) break; } + + /* + * Take console_lock to serialize device() callback with + * other console operations. For example, fg_console is + * modified under console_lock when switching vt. + */ + console_lock(); while (i--) { int index = cs[i]->index; struct tty_driver *drv = cs[i]->device(cs[i], &index); @@ -3563,6 +3567,8 @@ static ssize_t show_cons_active(struct device *dev, } console_unlock(); + console_list_unlock(); + return count; } static DEVICE_ATTR(active, S_IRUGO, show_cons_active, NULL); From patchwork Wed Nov 16 16:21:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21168 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233863wru; Wed, 16 Nov 2022 08:26:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf7MaRQwX2L3/LGAFeOo1uU93zTSqPL98tF6PLUSdlJYn2Cf9FKfGjus2Ry5uubqRrzV+I09 X-Received: by 2002:a17:906:9453:b0:78d:88c7:c1bf with SMTP id z19-20020a170906945300b0078d88c7c1bfmr18247611ejx.299.1668616002153; Wed, 16 Nov 2022 08:26:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616002; cv=none; d=google.com; s=arc-20160816; b=Cd9iHmLNE4GOSTfn97NVaVaUdoQxGpk20x3JrjXs6C/07dkVouE9u7rdBMO8IDQb7p edprFHBOd8k1hddni6PiXF8LU64/9gAxottGe2HQSSMxdC4aWWFW5vqAoQ66NfM21YSV ycQSJb0NSWcYUlB/gWNAxltC0ercWu/kMgH1/1DMazm/uP1sG1d8zHWGJPUpSJF2OdLn JcCcYexPI4wxaSPB6zEGs2AGtpwPeG8xIF21wrTinLgtjk3bKeUgzZdFQSb0sO3e4Drq BZaLaydrcgMmmLL2tmfkB8nzq1X6U0/fwT11jBo91VJKrk5sGhWgeCG7DUaBOfNU/bfm MYFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=gLhbxNRRzLzgVuMAENy9jlZuW5IHKymo+X5t98vmt7E=; b=o9AWlZFiF/LYeBX2tQmYKVcJmpgnGTovUHHC17vN+6qrU9wCiVQ4/tDA6Ubj79q0Vs kvLbTPoGmOK+GDFsv7WX316JgDWbuGMWzkwgfTp7n/9fMIn5pz+vlLQHAu9rQhGMptCX KVtRxh7togrmFEIKD5UPHlLDRZ/KpEH/5+v+epRq79z6ONtCfJ4ZFN3YHy2D59Yg+dEG 3GFcjxJ4AC0llqa97Rzs1xjG+JG3HUNBuk1P9eYNXWuvIlCbwMdN5ihrO1GkQUY3wwva ufHQR/7oyxWXxw1O36HEeqDRU2sWxBxoaiErcB6oWsEvLA0YopPdp9DUaSCwiE8vKF0J Ih+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qybUVOHQ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r19-20020a05640251d300b00461c852af19si17155475edd.633.2022.11.16.08.26.19; Wed, 16 Nov 2022 08:26:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qybUVOHQ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238973AbiKPQZt (ORCPT + 99 others); Wed, 16 Nov 2022 11:25:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238019AbiKPQXD (ORCPT ); Wed, 16 Nov 2022 11:23:03 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6617658BE1; Wed, 16 Nov 2022 08:22:15 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615733; 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=gLhbxNRRzLzgVuMAENy9jlZuW5IHKymo+X5t98vmt7E=; b=qybUVOHQ3lcpPJORwUZxfRKNSDT/E1lW8xR9jQFAUnk+CmGFCk6egkthMCR3TQeua2DtWM VyojWSc5t+MeGT9e4X2IlZEDixaROC4FQDK+95FFmvVk3mBvNNZZurhDgYXAjTiINlLEpF qg4PxKKgKoK5ZTSTBHifiUwP480lYx3KbdCcXDHRTbRcqsdmOZnVSY0fGJZ8UV9PZv5U3V o2INZ38YMktP/5lqXKutOY83w6LM0Iv/JvaPFKxh05++GiySPm5y//mPl3U1g2AGNuTkCg CJFulvLQk226W5njRJXauh3efYaiUiH+LlheE8AI7XiIf0Zi9/Vf7eqCzK8qTg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615733; 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=gLhbxNRRzLzgVuMAENy9jlZuW5IHKymo+X5t98vmt7E=; b=HsEGN6tMo3uc7PUkebWaEn1oYTUp5bx/ZwX+WR68pMluY1e7aak5EW/DR9K2+PrfNPUAQ1 iiHhLYBATOPUnIDg== 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 v5 34/40] proc: consoles: use console_list_lock for list iteration Date: Wed, 16 Nov 2022 17:27:46 +0106 Message-Id: <20221116162152.193147-35-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670693069240684?= X-GMAIL-MSGID: =?utf-8?q?1749670693069240684?= The console_lock is used in part to guarantee safe list iteration. The console_list_lock should be used because list synchronization responsibility will be removed from the console_lock in a later change. Note, the console_lock is still needed to serialize the device() callback with other console operations. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- fs/proc/consoles.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c index 46b305fa04ed..e0758fe7936d 100644 --- a/fs/proc/consoles.c +++ b/fs/proc/consoles.c @@ -33,7 +33,16 @@ static int show_console_dev(struct seq_file *m, void *v) if (con->device) { const struct tty_driver *driver; int index; + + /* + * Take console_lock to serialize device() callback with + * other console operations. For example, fg_console is + * modified under console_lock when switching vt. + */ + console_lock(); driver = con->device(con, &index); + console_unlock(); + if (driver) { dev = MKDEV(driver->major, driver->minor_start); dev += index; @@ -64,15 +73,11 @@ static void *c_start(struct seq_file *m, loff_t *pos) loff_t off = 0; /* - * Take console_lock to serialize device() callback with - * other console operations. For example, fg_console is - * modified under console_lock when switching vt. - * - * Hold the console_lock to guarantee safe traversal of the + * 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++ == *pos) break; @@ -90,7 +95,7 @@ static void *c_next(struct seq_file *m, void *v, loff_t *pos) static void c_stop(struct seq_file *m, void *v) { - console_unlock(); + console_list_unlock(); } static const struct seq_operations consoles_op = { From patchwork Wed Nov 16 16:21:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21167 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233828wru; Wed, 16 Nov 2022 08:26:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf5WvBB5LS3rHklHhe09aFZf7yiymh8P7R+hpGlw9UmIh8+LzxD/da55wjSIBQQ1HJXObpES X-Received: by 2002:a62:6342:0:b0:55a:d8f6:c65 with SMTP id x63-20020a626342000000b0055ad8f60c65mr23872119pfb.32.1668615996984; Wed, 16 Nov 2022 08:26:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615996; cv=none; d=google.com; s=arc-20160816; b=eHBo8hFX0VjcArx6mgAcq2gur3nerDfhgOZsg3PvQ9TGmDgz1wXwObYpNqUxn9oLrd yrmU8nQvckNgH5Yl93YzaTPzKNYupeESGgRe+NL4lL2gIIC6lCoNh/MCelMDMQDOVO2m hbpwigpPTgmOtibSDvRDkQ/FYbWwU7DH+nMC1/+fntQPxL/8s4xYJAgVxlUDevybAjhU V3+AEi8TDle3NEchr9VzUS0KaL/06+tpHJa0KAEGwc45L1joG4Vu8unyfpmg0wZnF3XQ DfeR8RVC6eefdG83toX+qo8AqwJ23fgKou8fPfwgIBFTiPiXzebUSu59YnO03d8wC0xi rOZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=XOHwuBaQ1W+3awwG2RAkUq8lXTwRKxgLO4vJVGnxlV8=; b=Q38s19SAUod7FG5/3PA/dmhpQJ/bpkigIdgfTchnE2Vxdr3od6JtPyBos+8k5L+F1F EYsIZtRz11AqX/RDQUeIU1+owMdzuRFjMZ+30MZqk1QqgT9mBu5lsljSyc4kZnt4cKYP x6N1MOfkecu0q2JagRtuQuy5diSwC2NvAKyfQjSDkF0O5VswHaDq3gFNUcW/LmOh7oNo 151HIMXNf5Goxr/Snv5HzHv+l9xpOcMQ3NEDkuv4FMTQiFO9pkCiTQ7pMsAy3C93BvYx Yp5eAjEn37+Pb56sEAdHLt+Hzx76smSz6hNK3LQJXiUqDzhrw+BV5siEau5F/NCEGvaX XuKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zwABEZ9m; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a190-20020a6390c7000000b0046b043d221csi15577902pge.55.2022.11.16.08.26.23; Wed, 16 Nov 2022 08:26:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zwABEZ9m; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238982AbiKPQZy (ORCPT + 99 others); Wed, 16 Nov 2022 11:25:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238085AbiKPQXE (ORCPT ); Wed, 16 Nov 2022 11:23:04 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAD3958BE3; Wed, 16 Nov 2022 08:22:15 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615734; 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=XOHwuBaQ1W+3awwG2RAkUq8lXTwRKxgLO4vJVGnxlV8=; b=zwABEZ9mxonAyBNUeWB10LZTBQNhVUWXnM4uJOtaQ2YyZadMZ5Bi3atLrrsSkVEU/BnViB xAZVnMRA2dR8k2nO0aVndbNd46Y1KfXjZxNnIMCd0MWCLq21gTPYXnDQlH47HazQ4NDvNt wmcJ6p2S4E6O3pkDLBoS7eyHnNAg3KsSCoQvLEKQjz/CSbQe3nu6Pon8WzaivpF79mr26K BAILjyp28M6MufGbgldEQGXoQwcNvfSuPpzdX/UBg8mB6SWPRgUX+uX2ZRJIGeOWZIQXpE 2Z/4P+skN/oruOza9baWAElWHHWGDsIWdsfXNjTGDHR5DZfUdF7y4XpQqQEB6w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615734; 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=XOHwuBaQ1W+3awwG2RAkUq8lXTwRKxgLO4vJVGnxlV8=; b=s9R0LFz1ZdiHDzIlIEwfz6Uf9mV1b7pU/Ru3/LSGYsFj+6aDJGhMs03+ARyz6ujFNcaXLF WcI0pM16uwfwndDg== 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 v5 35/40] tty: serial: kgdboc: use srcu console list iterator Date: Wed, 16 Nov 2022 17:27:47 +0106 Message-Id: <20221116162152.193147-36-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670688107216118?= X-GMAIL-MSGID: =?utf-8?q?1749670688107216118?= Use srcu console list iteration for safe console list traversal. Note that this is a preparatory change for when console_lock no longer provides synchronization for the console list. Signed-off-by: John Ogness Reviewed-by: Petr Mladek Reviewed-by: Douglas Anderson --- drivers/tty/serial/kgdboc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index 5be381003e58..c6df9ef34099 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -451,6 +451,7 @@ static void kgdboc_earlycon_pre_exp_handler(void) { struct console *con; static bool already_warned; + int cookie; if (already_warned) return; @@ -463,9 +464,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 = console_srcu_read_lock(); + for_each_console_srcu(con) { if (con == kgdboc_earlycon_io_ops.cons) - return; + break; + } + console_srcu_read_unlock(cookie); + if (con) + return; already_warned = true; pr_warn("kgdboc_earlycon is still using bootconsole\n"); From patchwork Wed Nov 16 16:21:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21171 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp234627wru; Wed, 16 Nov 2022 08:28:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf4S7tBX2l54nFqESgGEqN+MjHobgS7BKRew7/vUKIbE4/iQ175hKgANNPAc72NRTVT277pc X-Received: by 2002:a63:ed0a:0:b0:46f:b44b:3522 with SMTP id d10-20020a63ed0a000000b0046fb44b3522mr21015490pgi.288.1668616119401; Wed, 16 Nov 2022 08:28:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616119; cv=none; d=google.com; s=arc-20160816; b=Rzu5utpaAcFBeB/yk3RxQcccWgYeuJZ9V1577GmB2ZHIqX+EsEkYFFzClNHNu1UPxK p27HHqWlZ3Lhfbq3SkPCZ/ezSqCnxM5UV3a7xV/sqU6CtyuQBt651dNrZ46cx/fUVE+z y5qyIz+TC4schbDt8D83yFDdz1XIxS2R78j8Y6y4RN+g334/wJ2Ll3hvWmBhZyv89QaA 7RWGxPCGRxjzyoDE/pA01+VKWZAXUrVkPvtnz8Da0eAm2wOiFNjfsXwEdNwr3BePcdSA QAHyStzxfzK4rnjtVn6wQznmwzhbhs/x1suVm+ydBEupU85uCOofTztTu0+AEd5Sdhmh 45Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=8rR7OgmI/JUsM6cOvDEez6+6LhtAAivMeCFIKDYeiDs=; b=BwTlgrN5I4deOGcihraTutEU9E/ZngUGU75U5Va6Z+0QtYHUhfCcgEwaub+Ez/oe0/ 4F0D6d+Yk5k7vgjcxSjdZMR4y7ihJaDRUYpHAL6PiJgXSmv+2cz3m8exUmRTJESbqHYQ tcOq3ZLOzBVGQ139uoGVkGlwMv+QMHFxpQfEyawVB7Ee2frAqJE5Bu5814izkt3Hs9zV 2vr4ON54lEKKAiBxkBQH7VOf3eRxvY+5P67q+0ys+VwBWcnbWrlrW6dtucRFw0zs8nWK HknwrHcqpFndLIBohbGhFX3RYLkuNVxSNPtnyb7BeBAhifnKCPjZiCu7r3wG++4PZny0 RfKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yek+I+AW; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h15-20020a056a00230f00b0056783062eaasi16295643pfh.23.2022.11.16.08.28.26; Wed, 16 Nov 2022 08:28:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yek+I+AW; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238988AbiKPQZ5 (ORCPT + 99 others); Wed, 16 Nov 2022 11:25:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238422AbiKPQXK (ORCPT ); Wed, 16 Nov 2022 11:23:10 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 415C458BF2; Wed, 16 Nov 2022 08:22:17 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615735; 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=8rR7OgmI/JUsM6cOvDEez6+6LhtAAivMeCFIKDYeiDs=; b=yek+I+AWhez5rkEA5jpNLeS+dTK2vOYMuw49/4KeOx+vZ3j7fSICGh+A7GDKzg5z7TNe2w GNw3aJ8GgsUetQiTtAe6edQKm2iFjgqj4sP/xbEFwx5FjRjF+o3qdfUN8VptbvgQ1FTgSU XNuT7pmvKcUE6jWrDCsA8If0jfaxz/Nfe59VftfvTuxUeW3lurw11BtZ43HdyVaJd/ROh6 AXV7vSqILME+Fby/jKq7IUA2zE+x+sKNyx1ZxF8IafSf1P7CUoGoNq4M6G9DeWlhcmumgB 9rzjBdRedJFUuh6GLZNJHCwNg1g0XRq+YBkVa1FS/uzQFrOkhHTRPBf3H3u0jQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615735; 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=8rR7OgmI/JUsM6cOvDEez6+6LhtAAivMeCFIKDYeiDs=; b=BUIX13s3OtJiinZiPhHeHtVgfLl3mq3vyjm9l09/OnWGIn8MwDBkNG+hBGTwiLBOEgYOs4 z5ZfPI5vGKcwmmCA== 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 v5 36/40] tty: serial: kgdboc: use console_list_lock for list traversal Date: Wed, 16 Nov 2022 17:27:48 +0106 Message-Id: <20221116162152.193147-37-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670816091492983?= X-GMAIL-MSGID: =?utf-8?q?1749670816091492983?= configure_kgdboc() uses the console_lock for console list iteration. Use the console_list_lock instead because list synchronization responsibility will be removed from the console_lock in a later change. The SRCU iterator could have been used here, but a later change will relocate the locking of the console_list_lock to also provide synchronization against register_console(). Note, the console_lock is still needed to serialize the device() callback with other console operations. Signed-off-by: John Ogness Reviewed-by: Petr Mladek Reviewed-by: Douglas Anderson --- drivers/tty/serial/kgdboc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index c6df9ef34099..82b4b4d67823 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -193,7 +193,16 @@ static int configure_kgdboc(void) if (!p) goto noconfig; + /* For safe traversal of the console list. */ + console_list_lock(); + + /* + * Take console_lock to serialize device() callback with + * other console operations. For example, fg_console is + * modified under console_lock when switching vt. + */ console_lock(); + for_each_console(cons) { int idx; if (cons->device && cons->device(cons, &idx) == p && @@ -202,8 +211,11 @@ static int configure_kgdboc(void) break; } } + console_unlock(); + console_list_unlock(); + kgdb_tty_driver = p; kgdb_tty_line = tty_line; From patchwork Wed Nov 16 16:21:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21170 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp234544wru; Wed, 16 Nov 2022 08:28:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf4wqvuzUN6ipOg+JqLRQQb6pll9u8zq1mZKAxPlbpHb7IT3QI7w0rNCCUsfAvgkMj2IHGG3 X-Received: by 2002:a17:90a:d501:b0:20d:7716:b0bd with SMTP id t1-20020a17090ad50100b0020d7716b0bdmr4453040pju.122.1668616104717; Wed, 16 Nov 2022 08:28:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616104; cv=none; d=google.com; s=arc-20160816; b=rVTuhdyunq5z6DBnQnvFBZl999HXEt0i1WynpafXKcDw9jrgy4+h/T+vjDdwHnDqhG gBfJHWd1AHxXFWXX0j1WKzV2lYUWu2i7lqUco/gV1yfW3ISzFHlecYkRLmaVas1rsJ0k tv5e239/kI2C3f1L3D8Y5nRHX5nFMZVr/kDa85VISocWp7RrGAEWkm4F6PxdiUd36KeO VX1ui5PswC9fKngZq4VnfP1ItAVp35/Q86ZAkl+WPNTOC26biNtztQY/Lpn29y+x2ZVE ZILXwabeFoVt6tSxS7Glwl51fqm8bwh+qemMThFiaxgKa4+P+jj5E34f9pneEzdIKpeE EIXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=Ekc6YsdvItEWqTtBsALAxHEjpl5Na6n2oyZUMYkLTB4=; b=Yym6v3pvG/P8jDbHWTrSu7qNKIBTuMLmiYjHw3bxtPDayFSDYy865ZOTN2wCYuaHUf YfDxTMVuwYRq1K0mU3p4QyEk26EDIYZUfeTiE9OXdMaSWXXf3IJmG2ZBpPUWkFBHm95i e8HIc8QTuvxiqCzyxdwdxDwSnRe3RybpYaPNLlw2Wk3eozQkoMETrXa/xhWSmpHtWfOa 05AWk1fBSWMgl4TpcS1vDgPEEh61gOHWHQIlcyINgCGaGVY0pe/1O1e7Nnp54hETOdMq f2f/fX2j/F76SKfe1J+VhwktFasdVxvUvAuaajXYQR1Is1MOA1NbsdbamtbTc/GycIXh ZQpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=YEIsKnrW; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z4-20020a656644000000b004706a2c7d4fsi15596265pgv.611.2022.11.16.08.28.11; Wed, 16 Nov 2022 08:28:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=YEIsKnrW; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238797AbiKPQ0C (ORCPT + 99 others); Wed, 16 Nov 2022 11:26:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238529AbiKPQXQ (ORCPT ); Wed, 16 Nov 2022 11:23:16 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABC7558BFA; Wed, 16 Nov 2022 08:22:17 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615736; 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=Ekc6YsdvItEWqTtBsALAxHEjpl5Na6n2oyZUMYkLTB4=; b=YEIsKnrWvsEfDeMqLEWhW6CXWRSoij42e4hjpZ+1669Vh0CQIDA7UpSzm2yKlTtivfgld6 fAUyEZtmncagEKKTWslRFbM/nqbjElptv8qPMLgXLBfd3n6maJUYJzOXmKxMv94bFpP3LJ oRthfqYM02vvTa7UIH/tU0JXATfnroC4zP/w1c9d2QDPNnMBcmWrL6Dcc6yS1BTyyw9ko9 8Hh/JDRcF9lttL63XHcP00xzRrML04R8a5M/zokM9FemiYdVjP6iWiOK+LgM7Xso7y6GF5 D+SeLSgCP5+paJP3b0PiOW2tOC2LZ4hcbvGplkl5FtyJ0PAkh/nMhKow/QzbTQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615736; 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=Ekc6YsdvItEWqTtBsALAxHEjpl5Na6n2oyZUMYkLTB4=; b=Lu8i/3DrLZMyeZDhwbNSreisjN68CvYSPVUqy5KUkBeiHdQUQjFwCwxhm3DUm6CfS8JewM lFXpVW57c/CwP/CA== 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 v5 37/40] tty: serial: kgdboc: synchronize tty_find_polling_driver() and register_console() Date: Wed, 16 Nov 2022 17:27:49 +0106 Message-Id: <20221116162152.193147-38-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670800721460023?= X-GMAIL-MSGID: =?utf-8?q?1749670800721460023?= Calling tty_find_polling_driver() can lead to uart_set_options() being called (via the poll_init() callback of tty_operations) to configure the uart. But uart_set_options() can also be called by register_console() (via the setup() callback of console). Take the console_list_lock to synchronize against register_console() and also use it for console list traversal. This also ensures the console list cannot change until the polling console has been chosen. Signed-off-by: John Ogness Reviewed-by: Daniel Thompson Reviewed-by: Petr Mladek Reviewed-by: Douglas Anderson --- drivers/tty/serial/kgdboc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index 82b4b4d67823..8c2b7ccdfebf 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -189,12 +189,20 @@ static int configure_kgdboc(void) if (kgdboc_register_kbd(&cptr)) goto do_register; + /* + * tty_find_polling_driver() can call uart_set_options() + * (via poll_init) to configure the uart. Take the console_list_lock + * in order to synchronize against register_console(), which can also + * configure the uart via uart_set_options(). This also allows safe + * traversal of the console list. + */ + console_list_lock(); + p = tty_find_polling_driver(cptr, &tty_line); - if (!p) + if (!p) { + console_list_unlock(); goto noconfig; - - /* For safe traversal of the console list. */ - console_list_lock(); + } /* * Take console_lock to serialize device() callback with From patchwork Wed Nov 16 16:21:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21173 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp238101wru; Wed, 16 Nov 2022 08:35:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf47nQB4sWvAYLe+Bp2nzYpQ/T9WaC1zva9rlpG26bAMLZaqLM/wQJTyhDKMUJUoKGgAK7cs X-Received: by 2002:a17:902:70c3:b0:186:af8e:7ed4 with SMTP id l3-20020a17090270c300b00186af8e7ed4mr9682489plt.7.1668616550305; Wed, 16 Nov 2022 08:35:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616550; cv=none; d=google.com; s=arc-20160816; b=QWIuwGBb9QSNlJI2QRAS2QwXIxCjUqABDkASjyeTNdGIyqYlhLjSsTmNw4pT1AbipY NJjIiQhu/pJ4gw/w0QDQvdHtbm5eeqwXqV9CxbOytweeOHhc51acB1ZQkw1x8LObUUj4 MLhWb3F9L0p0U+lc81prlpSq6kqsakmBSujjLGSf6gvNSFMpik2asM9FwFeCKIUrey8V vdSywJ6u2tjnDxOaJx/2TpTvsjSUcut+iqyC5xkZLaOQ7kWNsBC4IShjAexc+c56oxev 8XyVHsm/9Xwt+tuU3VUqb+QqiVev98wX5npJiVbzG9rkuHCHWcua5R789XnphEMsS0SD Y8Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=R9VqGyF+glKoWbwrATKZGXQP3ZfoC2SELt3pYx7i6e4=; b=oOkr1ysd9dSsSBi+pjKUthH9Z9sePRO3HCeKMfHwYbyQD1bdvXFgj/X1SRTuC5QiaC BMrJU5BSQhIGPLEdq6IMcZcZOKqFqmy+fdXBJlK2ax5axiUAlYUrWE6OUEjIkQwg6irc yS2XweBukzZRtBBys1cjW1dES3RT/NQypo3d9tyfGT7qoJWCV8fwFYXfAN33VGnpqKvY 7a8sVvWpCMH8rtMwe3YOHTlMglTGJJKoFFW1l6EeUDnpUM5eZNxzdQhfdgl//H79Gsin goc+8mvOhQbfrFcALZdtyBJgYGodfFVbdk6bFXEYIOquWMesQouMsTTMSE/k5y+/EV7b FdBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JFsQt9Ym; dkim=neutral (no key) header.i=@linutronix.de header.b=4QlR9bdm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e20-20020a63f554000000b0046fe97419aasi16040567pgk.120.2022.11.16.08.35.36; Wed, 16 Nov 2022 08:35:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JFsQt9Ym; dkim=neutral (no key) header.i=@linutronix.de header.b=4QlR9bdm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238808AbiKPQ0I (ORCPT + 99 others); Wed, 16 Nov 2022 11:26:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238551AbiKPQXR (ORCPT ); Wed, 16 Nov 2022 11:23:17 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FED059848; Wed, 16 Nov 2022 08:22:18 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615736; 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=R9VqGyF+glKoWbwrATKZGXQP3ZfoC2SELt3pYx7i6e4=; b=JFsQt9YmKmGYiNMCmtvxB3r69uHQoFqE8e46/QPCeV4UzhXpIrH/WBkT8OVqrE9LmK1igd 8MYMnuoCiKcekVXCEqztixtf06Z+X0tmr4ZCp4z2KnxJX4XizYz6iFOt4XbmEnOrfWpMEd 9pJfm2udp0lnzaqCp9qDyM7fk/zZO8dGcumh8J4QcUMBqF2OsCea9tAj0AmtK+QRm10uw2 STmOa5knG3Xl4Ae3JELKSNNr1ur3iSmPTmxeT36HTAadHweraHKRNB9IUvEnThYR5yot/r BFK8xrc0lOODKN2Lb2Rqnd0X+EUw0Z5u+ngrj+fd0rY+uQAN8YbkjA/WOCmrAw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615736; 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=R9VqGyF+glKoWbwrATKZGXQP3ZfoC2SELt3pYx7i6e4=; b=4QlR9bdmeVF94Qc5Vu64CzXPINchKf2DFGK9G/aISYm0uexwOLYizOLQ6gSDk2jDy/Sr04 FB7QWs6ZgcD1g+Cw== 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 v5 38/40] tty: serial: kgdboc: use console_list_lock to trap exit Date: Wed, 16 Nov 2022 17:27:50 +0106 Message-Id: <20221116162152.193147-39-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749671267533369546?= X-GMAIL-MSGID: =?utf-8?q?1749671267533369546?= 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 responsibility will be removed from the console_lock in a later change. Signed-off-by: John Ogness Reviewed-by: Daniel Thompson 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 8c2b7ccdfebf..a3ed9b34e2ab 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -558,13 +558,13 @@ static int __init kgdboc_earlycon_init(char *opt) */ /* - * 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 and race-free reading of @flags. */ - console_lock(); + console_list_lock(); for_each_console(con) { if (con->write && con->read && (con->flags & (CON_BOOT | CON_ENABLED)) && @@ -606,7 +606,7 @@ static int __init kgdboc_earlycon_init(char *opt) } unlock: - console_unlock(); + console_list_unlock(); /* Non-zero means malformed option so we always return zero */ return 0; From patchwork Wed Nov 16 16:21:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21174 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp238391wru; Wed, 16 Nov 2022 08:36:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf7SaQI+wl3JcmRvHm3KaCeoj4dYSi3jo62SxefRn1a514vxClP9N8/pCkFmcHkPhKRAMZ/R X-Received: by 2002:a17:902:6943:b0:187:3a43:3a9d with SMTP id k3-20020a170902694300b001873a433a9dmr9647725plt.152.1668616584486; Wed, 16 Nov 2022 08:36:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616584; cv=none; d=google.com; s=arc-20160816; b=btGvC4LyYqCrGMrlA1MDPadKAkvbXJ9XKnwtJ0MOdebWU/bNTwon8EygTqqEzT1UQC oflO1uZqlpceapZxd4dtfBNDquqOpTDV11ITQmSP7lV/E9rCs2nBXaC6v5GV0yAzsWg4 t8zDMMLX4XaP5XUDJfCTKT8egw6Q/gIoaujPrKPlFzZI8pfPfuS9Lj/Y5Zn20qywJwGM /Y3VaUos89dhliS4S4XQElisZYxdcDRp7J9eAVAu7P1qVhFT6WV2HHfwCkqlwXRsfowD HwuJjl1MJaCwOBLZzUHxL6JJWdbHas0jSWtoUiMBGal6RXCXv8oZf++e75v0FnpvZd7t 6veA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=fRaCkCeGsMszYT9s9X+v38mM38ySFiKFFQd/VYKUf0w=; b=hcn5ms38MN6IR1hhc5thikve7BvSwkLLr7C1iyOgJ3S9Jh7oZ7Kk5C+UWc/ztY27h+ 0BTATgYxsKByzVJ9xgdxybLxuMfGFuyIjzjsh21MUzaV7FLRL0O/XJpprThNxJbWKqiR Yub3H4ZPpER79lWquD/oOxk5n4SJyfAanUVJxqyB+PfEIDY1YyVPT07hNxZ3da3eq8p8 GUUGKYTQx/ww1XKyPaaMdKv1MY2sX32o8u1+w3WVUT8J9A9X5tEnuvBT3vXhwXJFyFZN 95TQYOyu1K4YuIR6ZyFg0wLbrHvTa5r5k2HWgHZrVG6jcMms6Rm/i1cLVsgptNRiS+ZA vAVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=e+jN8ABV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=L3dIG7lJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020a17090a580200b00202c7f4631esi2220713pji.19.2022.11.16.08.36.11; Wed, 16 Nov 2022 08:36:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=e+jN8ABV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=L3dIG7lJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233861AbiKPQ0W (ORCPT + 99 others); Wed, 16 Nov 2022 11:26:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236796AbiKPQXZ (ORCPT ); Wed, 16 Nov 2022 11:23:25 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E37B58BC8 for ; Wed, 16 Nov 2022 08:22:18 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615737; 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=fRaCkCeGsMszYT9s9X+v38mM38ySFiKFFQd/VYKUf0w=; b=e+jN8ABV45ZyfD4tNmWn90X36lOsX1xDsiVghP3TjowoogutUHte6IrzfdrMp4obJT61tz +hVYOpxVLufBw4bJ43rJi1DtHuYn8mNuonJkPAOOeqxX2LfoZFy5LOY5v+KzJR1EsKADvm RRosd2A32Jf5Vsza/2FlvBTxI09mpcvs/1ihMIO+XP8rAvhgdsAb/TKQhKCbki8DF9rfaY xfSuX21b9y/E9AN2XyL1DWP5dJCnS8UjQMWPjdgNU/vzw8Dszu8/9o/9lJEk0vYn0etvPb NDIiO5gZKAOH0ehEvyq9MrfL14hR13udM3FynxkfzBXYLjTM+dYUzEyJ3sf8SA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615737; 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=fRaCkCeGsMszYT9s9X+v38mM38ySFiKFFQd/VYKUf0w=; b=L3dIG7lJdJtTQB41A4X/200Ys2o64NZ13GG/NpEMSbMANtT4ykRV6E/mKFlrHgzvhoivNk 4hnuPRB8SHK9XEDQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 39/40] printk: relieve console_lock of list synchronization duties Date: Wed, 16 Nov 2022 17:27:51 +0106 Message-Id: <20221116162152.193147-40-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749671303473193686?= X-GMAIL-MSGID: =?utf-8?q?1749671303473193686?= 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 | 44 +++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index ece34abbc9cc..094017c4a5ca 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -86,8 +86,8 @@ EXPORT_SYMBOL(oops_in_progress); 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. + * 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); @@ -2639,10 +2639,10 @@ static int console_cpu_notify(unsigned int cpu) } /** - * console_lock - lock the console system for exclusive use. + * console_lock - block the console subsystem from printing * - * Acquires a lock which guarantees that the caller has - * exclusive access to the console system and console_list. + * Acquires a lock which guarantees that no consoles will + * be in or enter their write() callback. * * Can sleep, returns nothing. */ @@ -2659,10 +2659,10 @@ void console_lock(void) EXPORT_SYMBOL(console_lock); /** - * console_trylock - try to lock the console system for exclusive use. + * console_trylock - try to block the console subsystem from printing * - * Try to acquire a lock which guarantees that the caller has exclusive - * access to the console system and console_list. + * Try to acquire a lock which guarantees that no consoles will + * be in or enter their write() callback. * * returns 1 on success, and 0 on failure to acquire the lock. */ @@ -2919,10 +2919,10 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove } /** - * console_unlock - unlock the console system + * console_unlock - unblock the console subsystem from printing * - * 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 to block printing of + * the console subsystem. * * While the console_lock was held, console output may have been buffered * by printk(). If this is the case, console_unlock(); emits @@ -3109,9 +3109,7 @@ void console_stop(struct console *console) { __pr_flush(console, 1000, true); console_list_lock(); - console_lock(); console_srcu_write_flags(console, console->flags & ~CON_ENABLED); - console_unlock(); console_list_unlock(); /* @@ -3127,9 +3125,7 @@ EXPORT_SYMBOL(console_stop); void console_start(struct console *console) { console_list_lock(); - console_lock(); console_srcu_write_flags(console, console->flags | CON_ENABLED); - console_unlock(); console_list_unlock(); __pr_flush(console, 1000, true); } @@ -3246,6 +3242,12 @@ static void console_init_seq(struct console *newcon, bool bootcon_registered) * the furthest behind. */ if (bootcon_registered && !keep_bootcon) { + /* + * Hold the console_lock to stop console printing and + * guarantee safe access to console->seq. + */ + console_lock(); + /* * Flush all consoles and set the console to start at * the next unprinted sequence number. @@ -3272,6 +3274,8 @@ static void console_init_seq(struct console *newcon, bool bootcon_registered) } } } + + console_unlock(); } } } @@ -3370,7 +3374,6 @@ void register_console(struct console *newcon) } newcon->dropped = 0; - console_lock(); console_init_seq(newcon, bootcon_registered); /* @@ -3390,7 +3393,6 @@ void register_console(struct console *newcon) } else { hlist_add_behind_rcu(&newcon->node, console_list.first); } - console_unlock(); /* * No need to synchronize SRCU here! The caller does not rely @@ -3438,15 +3440,11 @@ static int unregister_console_locked(struct console *console) if (res > 0) return 0; - console_lock(); - /* Disable it unconditionally */ console_srcu_write_flags(console, console->flags & ~CON_ENABLED); - if (!console_is_registered_locked(console)) { - console_unlock(); + if (!console_is_registered_locked(console)) return -ENODEV; - } hlist_del_init_rcu(&console->node); @@ -3462,8 +3460,6 @@ static int unregister_console_locked(struct console *console) if (!hlist_empty(&console_list) && console->flags & CON_CONSDEV) console_srcu_write_flags(console_first(), console_first()->flags | CON_CONSDEV); - console_unlock(); - /* * Ensure that all SRCU list walks have completed. All contexts * must not be able to see this console in the list so that any From patchwork Wed Nov 16 16:21:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21172 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp237490wru; Wed, 16 Nov 2022 08:34:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf5a93H67faBtaj7kk1Jwm533dfImKU8oaJ+HUhPn8I4CkRwcWSCW2dgUKXs2GxSgKlrdnSW X-Received: by 2002:a17:906:b1c8:b0:78d:474c:2a59 with SMTP id bv8-20020a170906b1c800b0078d474c2a59mr18094482ejb.759.1668616478926; Wed, 16 Nov 2022 08:34:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616478; cv=none; d=google.com; s=arc-20160816; b=NuG9bAjxRLkvcPlQBqltWyGcL33NO4F0w2MEvn2ysQcB7f2cZwK5hKiIFVVEORBAho hRvAajKIwdVM1O62YCaYXI6oMcGC3o7wj5jF7/Wm5X/qYL6aa6PFXwvKn0u/LXTzV8o2 fLKlYIj/TjQ3ds+WPjk44QbO3kpiPHnmM3RGWuSCVWpM2x9bvQwAMIki0bx6p+B/buqM DFn//5BvgvywNy/LdncVTAgmBDPpZd33Qm72g/9/yLMPlFQKorRs64SYQLtPZKaX6lqe EZfJVXRWCVHgqMhip8z4/Hirv5cxUQzH/kYrCTNM6xLbAh2qjb5BhNgA14a1AaXFwlme rk1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=cDzPKGMTkhpNbvwnnhR0RElQZrV0hyGRgg+q/Zsvwrs=; b=nmMWBDXUXHBFFSMp+Z0qMtXVLrdVWwr3DEKxTsjo9gyLh19w1jp9XvYFPGfLismDL5 0RBqSm8R+wRk7aj78/e4ZYo0scrB79RulHcP+oOO55Y61qFMkjxXLpDrIiVJAlJcxd/U Mt8hBYD22EMwdZn9OC6I9rITmd4qU40BTJ5rF5iZey7YK1AQ+u7oVjVjF+jlZa6+jktY KjRAv0FGdiOvHvHePYl43dUtKBf+bsRmOFVjHquJEhymfxpRFvA2nA7QReSjYDdDguVf 6VbdgLU0xCMZl9od3ks4CVyTCh46eQeYULMSwgn+GX/VHhCQ9MFjod1E8FI1AojPF/t+ CzFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UfLU5wHJ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f19-20020a056402355300b0045981993486si11244976edd.227.2022.11.16.08.34.13; Wed, 16 Nov 2022 08:34:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UfLU5wHJ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238787AbiKPQ0Q (ORCPT + 99 others); Wed, 16 Nov 2022 11:26:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238577AbiKPQXZ (ORCPT ); Wed, 16 Nov 2022 11:23:25 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2300F59856; Wed, 16 Nov 2022 08:22:19 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615737; 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=cDzPKGMTkhpNbvwnnhR0RElQZrV0hyGRgg+q/Zsvwrs=; b=UfLU5wHJLWp2NQ8DrGn+ZhapyKLJzuFNlQXXldDXx0k+nP4yAyUOy2sHJk6ME9MoiZti5p fcu2oBfa9wWuRVhWK9Ulklw3Nj2rHGXadOoRecmBnUmWBbZgQC13WOWqP0rNqLAY7E59hH lrkhUWficQyx3cs3jEPN22zCYn6k4LhknPT0qgMs677kzH5/m1BTEzkcr3VugcRF3+h7DZ WUZpIWelOtzA/fVObnfzb12Ci/iLk5aPJNnNpVgFRZ9Kh2U52ogF/TK2e4kB+vcWmoNfhr mb7h/4k0WLiMPS+KEnrxEQSg1ItPKuz5UqS9KYRL6McjVRXqTPXUrYtP6TkjNw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615737; 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=cDzPKGMTkhpNbvwnnhR0RElQZrV0hyGRgg+q/Zsvwrs=; b=rho7inCMOM4wtFYfYjQ2Ghv5PGoPaL+iWTbYTlh/MLc6tA17+ZIDyyY1rjFXbM4M80xO8a IViyH4PqOY1vbcDg== 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, Geert Uytterhoeven Subject: [PATCH printk v5 40/40] tty: serial: sh-sci: use setup() callback for early console Date: Wed, 16 Nov 2022 17:27:52 +0106 Message-Id: <20221116162152.193147-41-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749671192973137329?= X-GMAIL-MSGID: =?utf-8?q?1749671192973137329?= When setting up the early console, the setup() callback of the regular console is used. It is called manually before registering the early console instead of providing a setup() callback for the early console. This is probably because the early setup needs a different @options during the early stage. The issue here is that the setup() callback is called without the console_list_lock held and functions such as uart_set_options() expect that. Rather than manually calling the setup() function before registering, provide an early console setup() callback that will use the different early options. This ensures that the error checking, ordering, and locking context when setting up the early console are correct. Since this early console can only be registered via the earlyprintk= parameter, the @options argument of the setup() callback will always be NULL. Rather than simply ignoring the argument, add a WARN_ON() to get our attention in case the setup() callback semantics should change in the future. Note that technically the current implementation works because it is only used in early boot. And since the early console setup is performed before registering, it cannot race with anything and thus does not need any locking. However, longterm maintenance is easier when drivers rely on the subsystem API rather than manually implementing steps that could cause breakage in the future. Signed-off-by: John Ogness Reviewed-by: Geert Uytterhoeven Reviewed-by: Petr Mladek --- drivers/tty/serial/sh-sci.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 62f773286d44..76452fe2af86 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -3054,15 +3054,29 @@ static struct console serial_console = { }; #ifdef CONFIG_SUPERH +static char early_serial_buf[32]; + +static int early_serial_console_setup(struct console *co, char *options) +{ + /* + * This early console is always registered using the earlyprintk= + * parameter, which does not call add_preferred_console(). Thus + * @options is always NULL and the options for this early console + * are passed using a custom buffer. + */ + WARN_ON(options); + + return serial_console_setup(co, early_serial_buf); +} + static struct console early_serial_console = { .name = "early_ttySC", .write = serial_console_write, + .setup = early_serial_console_setup, .flags = CON_PRINTBUFFER, .index = -1, }; -static char early_serial_buf[32]; - static int sci_probe_earlyprintk(struct platform_device *pdev) { const struct plat_sci_port *cfg = dev_get_platdata(&pdev->dev); @@ -3074,8 +3088,6 @@ static int sci_probe_earlyprintk(struct platform_device *pdev) sci_init_single(pdev, &sci_ports[pdev->id], pdev->id, cfg, true); - serial_console_setup(&early_serial_console, early_serial_buf); - if (!strstr(early_serial_buf, "keep")) early_serial_console.flags |= CON_BOOT;