From patchwork Mon Nov 14 16:28:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19877 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2237638wru; Mon, 14 Nov 2022 08:30:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Z8GYA/OGiqFxvWVzST5fvhkp9k2Y+9+SeYk0Z7dlRXuZWi86LB+1+XExRmDyLeb2ShUxm X-Received: by 2002:a17:903:241:b0:188:6300:640f with SMTP id j1-20020a170903024100b001886300640fmr16857plh.124.1668443433502; Mon, 14 Nov 2022 08:30:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443433; cv=none; d=google.com; s=arc-20160816; b=ag+IMg8TX3X7V27/mt7fXnnb52ALwSu/DT+qNYpFVRqlNecXwTUkkf9wGLXptnSvQv jEBRGuVEvSqM7fAoSAfH+98sLTN7kKNSdTDCFiHpefaiS4SjwpFMCMZak3TXXZTbxWzB JKnpbccdzv7mAelhk87cLf1QcbWiMEUX6N1ZaH4RCkN7SL044VYJUxDLDWC8q3B4N5AR GRauiVAEhs4rDieqpmiTV3bgQfdNeKDsy2Y/uKEV+oBzeY5vVenD9aIkxFBeNY59Vjdd r7/3LjijS98QY/aqZSyJO6sGe/kcj0cchv8Vu3+VSxNLlA9gTlNvxkN/UIhJQPcS9AYS YuPg== 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=z+ceWAnsa/KUYKS9eQMSdOvjkUPTK0IOvZae2YpXUz647EyOov2Md5eKe0J5L8X/2G 8RQdZ3WB6HQqSwdTG1543i+FSqUqOqaw5eU8p1XZKaN8XCcTLBwemFPdIgTsJMHnyJyQ RnfmfNTt95h1fSy4ASvPDFj5zeSuIC2gp4BktWac2/44BO06A6W6at8UAIbpPDr8T7XO GqD+Y2KLPnnhh5crH6ZQ2ECyJb4Ev++q534zerxRXvx2QorwsWes5LIIQ8x1dahrHEKe ERDeIZG2boPYrMDFdj2lmxbnQNCludVi8m1OnqK0UcPZSBsZMGPiRPStax12bB2Od4c2 Y0FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZIb+4NiG; 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 cr15-20020a056a000f0f00b0056300ad8dd2si9013585pfb.367.2022.11.14.08.30.06; Mon, 14 Nov 2022 08:30: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=ZIb+4NiG; 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 S237527AbiKNQ3p (ORCPT + 99 others); Mon, 14 Nov 2022 11:29:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237437AbiKNQ3i (ORCPT ); Mon, 14 Nov 2022 11:29:38 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85F73E53; Mon, 14 Nov 2022 08:29:37 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443375; 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=ZIb+4NiGcX3L5i14ZL3n7tyukxCFrzAaN2u/yt52dY0OinERwz3VqBV0iF7GolWDeFJnsS svoW/OdbNhOb7rb654aqbqcDtFwbYfHWhVZ2ceuMPMcmhjv0V1q3gI9oTYPoEvd8jv81b2 ma9pcNTXKnS70k2gFZOc7Mia1+4plCCQeNOoytXM9nVFKXzKRZtPhuY59fzFOSCKq0RZRA poyjWM9clrOP4N2sx47bznvDPqWcHfs5npYE93Qb0Y0jv9sBxSYz56D2YmtmCZohhyLeYI KMrf2UiGEmrv9Y3gYhZPaxYcx475ZwaukWQ0CpuTNgN1i+6jxNyGMVDu29ZVDQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443375; 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=rHBzMhUuyyCGljjYgo6M9g2z9ptIJHtaTE0co9JJYi84qxrRS2zWgGLSRMhVC57vB7U60l V2qJLfb/YvGXv+AA== 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 v4 01/39] serial: kgdboc: Lock console list in probe function Date: Mon, 14 Nov 2022 17:34:54 +0106 Message-Id: <20221114162932.141883-2-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489741810101025?= X-GMAIL-MSGID: =?utf-8?q?1749489741810101025?= 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 Mon Nov 14 16:28:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19878 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2237705wru; Mon, 14 Nov 2022 08:30:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf70KPXAGsE20hIGg6F41qJyrwrDTDgcO9abl02BpzxJrk5KXng2l2BrqHGRFZG+ug2zdmWJ X-Received: by 2002:a17:902:bb8a:b0:17f:7f7e:70c7 with SMTP id m10-20020a170902bb8a00b0017f7f7e70c7mr35876pls.107.1668443440247; Mon, 14 Nov 2022 08:30:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443440; cv=none; d=google.com; s=arc-20160816; b=Pu9Ygt14+wq8MmneZwK7QauijljnfK/tUQt/+SbVFV+shCXXbWG2xyBGOrEmJSNmY8 DPulOSy7RdA/J88WCjVYfWAyw+IFSri6CNqgcmfPD1DMVM/42L1m/pETS3scd7jtpEEM q2s0FE+RaohS+j7gbKOZNoOYo9BoaTY7grhboytYLmIQKoTtkYqRDsoKdJOZzE6tREMN ONvtmeMT16Gva096Joce7tMxoC9D/LCHNuiIwjTgNYTwDizzSXsndGy3u3fVKJpscLDh 58RdPEKnmFcSyeH/W7DCDBLCzZkJ5tZkamYsiHffALk3SM7ru4J05auHIhoJ1QyFI7jb nwqA== 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=rqXeGFOU7qjCzdpWpSHk5iiknKvy9WV6QXGQpn8Ka+THaeaFxbfGUvFkZR2/PStelZ bCc0L3w+jbs38bv4PA75wK/kND9Bc6nzBGtyXC+FxRt8WhFr8oJwzhM2i0x7pF/gudSh v63Jk9pNNQwYdmXb5VwoKxHdJc1+5ddTNMk6WQKm+MStbC66wYYigypLwmelGe15RIAG 56gmDozBsqJOYmKR3mrRs2FoJkPbPC2vP1t54f3CMvVkrYI4nhD4Sohi3AIycXUT5hqr 0Ygy7ZlckUPDmX+2pbqGu/pYAURXcOSFw7wew2gOfyw3DUUQ6FxOii+lbFEdDwSN7T2N T0yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qKx+VJuD; dkim=neutral (no key) header.i=@linutronix.de header.b="BkeXAU/i"; 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 n27-20020aa7985b000000b0056c882d7065si9457988pfq.179.2022.11.14.08.30.11; Mon, 14 Nov 2022 08:30:40 -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=qKx+VJuD; dkim=neutral (no key) header.i=@linutronix.de header.b="BkeXAU/i"; 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 S237562AbiKNQ3s (ORCPT + 99 others); Mon, 14 Nov 2022 11:29:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237434AbiKNQ3i (ORCPT ); Mon, 14 Nov 2022 11:29: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 18EA22C0; Mon, 14 Nov 2022 08:29:37 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443375; 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=qKx+VJuDzpUJJXwJ3b9vs6bAjLubt6siELBgT+/DCZsajhHKOkdodlJbHKyBYzUTQl9X2K MBo7U6ZcGj/13xDDi241cAo2sBP1kHgw8JjW9cIo3Wq4busIZ59bCWXABMvosfia/0yscU UUoRRVYZlbr4W0xDK8zhGB8APbk/l/+d6Ygg6eTGAb0yUvts31imaUOK4k9PF1fXEKJStH 7wQ99bLM1thUiGw4T61ByBN/kU0XHseXl8btVFmAjlowH07dM9l2eIYKQfZxdV5o0zBSAP 0gvFqlVNrJUCa7jbvfQsuIFWBnTJL2U4zTU1YwRxfC4xgo3PmXa0uQpelb2b5Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443375; 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=BkeXAU/i0KB66XosuQwcWeAbn0K+op/NilejsszupovN74oMW1gMhqCMwMggNOh7oZTz28 jKfU4QduTJTFMcAg== 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 v4 02/39] printk: Convert console_drivers list to hlist Date: Mon, 14 Nov 2022 17:34:55 +0106 Message-Id: <20221114162932.141883-3-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489748802523503?= X-GMAIL-MSGID: =?utf-8?q?1749489748802523503?= 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 Mon Nov 14 16:28:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19882 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2237905wru; Mon, 14 Nov 2022 08:31:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf7z/uldVnydRT4DSJPf/ckGSJZ75HB9hbl0QaIQlAnjAdmo2Nyo+jeXq3Qi5Ks/JzrxoUQe X-Received: by 2002:a63:1403:0:b0:46f:53cb:65b5 with SMTP id u3-20020a631403000000b0046f53cb65b5mr11833608pgl.507.1668443460297; Mon, 14 Nov 2022 08:31:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443460; cv=none; d=google.com; s=arc-20160816; b=mwJAbpCUKdogCYSEI0HcwWoV4fXiNZ88xlkIoa+Pa5j90q+5yIHYOfob1inPyZOctv 7gRnB2lvkYWAUutdPJWAsBEuNwm8L6C8sh0pz5dL/rJdgVX3CUtnNv3zhKYtMMJQj0nv pSE3AJAP9VAFP2dP+CGBr6/TalzKymmxkooMXvfFBF8BNTpt40Ob7jyc2hDBzMNZ3MLs BjsY2CrGgDSWCNDV8YR8jvaf9BxHAdarxqWmnIA6Z5ETJ3v7SAoO5e22Wxr8xfCKSdQF Ahk/rUqe2EqhXNin/J014BN9y9y/5WpfnQEP+qVHd8JDokjLjJ+mQebG57BYJqSzoZ4M apjA== 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=tNDngHttcIojuRC9i2ip4JEFSroG8dsMCShr54uLid5ArPjOMs0/T/xzwk+ruWb01e nlUR4rT7c+kOKGy4CkI1D74dqyjwY2cK8eCsFDbNqG5tKxVAc8peZJPYUpnq4Y8X9YV7 0yM2zcnjJAHotiix7xDsgL050NmkIOgqXnhn8zCLEigRcC5UaeGyV0onITq24QCtF/uG LkBCPXvxD8HzAABgL7zffEnn4PcW2kb/oLMyTzN8MUEv9tMLmGU6pC5u73LqBx275+47 jpx9acepTB+LlzV/DQ6j/6xacupsohB9/l0AYuTDwtn6teUUOe+xjio7p9cqM53Psx1e 0ZaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JygoovyB; 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 l1-20020a056a0016c100b0056e48944824si10980293pfc.191.2022.11.14.08.30.16; Mon, 14 Nov 2022 08:31:00 -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=JygoovyB; 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 S237571AbiKNQ3x (ORCPT + 99 others); Mon, 14 Nov 2022 11:29:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237438AbiKNQ3i (ORCPT ); Mon, 14 Nov 2022 11:29:38 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85FAEEB1 for ; Mon, 14 Nov 2022 08:29:37 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443376; 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=JygoovyBYSjfFmhXKl3DmAhlTlJMYdCtcfRom0BM3TjsxVCd9RqT1dRYTPA3xW6S1Gl3A9 6Q1wZZ4PS7XESPMtpNAIuYFQAYhVd5hfIsXXQncmpNc60uwatFjTpnpglZ/vi8N3KEHtH0 XGwSXTpcH97xrfjJGHbC16W+Uqdg2qU2XXNqZlhU8hEMk188piz4DFQec/IuoSevJgSoxG kpqk9JTvNp5c4l7iPB9b5IVcZbHzqPKEa0y2GAMuWW+AFBSi3QOF4gnns5yR5YavWK357q gKLYDRd1C6Xk8GV3BiLv9ZI8QuIPB1YHqjcGEMj/A29bV7ZmOTgjcn8ePnePDA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443376; 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=C9bcEqkYCgPfBjJTl1ERYoNQdlGPpsHmxPDhPzApC7h3Yt9Zste8JJekNtPbq89aaPIlTv SXPDj6ORGcGXF3Cw== 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 v4 03/39] printk: Prepare for SRCU console list protection Date: Mon, 14 Nov 2022 17:34:56 +0106 Message-Id: <20221114162932.141883-4-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489770017819492?= X-GMAIL-MSGID: =?utf-8?q?1749489770017819492?= 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 --- .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 Mon Nov 14 16:28:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19879 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2237743wru; Mon, 14 Nov 2022 08:30:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf4BXNNMWJq8+OReX+1j/ScY84VUJBoj2C8hrLZqnXoPxZ3JoE2Jw1iDZlnt7DqGMtChUUM1 X-Received: by 2002:a63:4c60:0:b0:45e:4fd8:d966 with SMTP id m32-20020a634c60000000b0045e4fd8d966mr12201730pgl.100.1668443443616; Mon, 14 Nov 2022 08:30:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443443; cv=none; d=google.com; s=arc-20160816; b=De8NMo/QUbQZ3xvjUWklg9Nx4Xrp+iAId7N2vpNHP7G9ogJeF/9KaRhs53qYtri2gm To9JSsNM3ORarCgPYpFRJKPbSd7wKpvU9TQFGvL/dSGUmAaXkaXKUiD2l2wIXJWSmGUr Ez6T6X3SLwivy3XpKYeEI+7nOqBgUb8vTSfCqlKb9pAmowoybtcZTe2W5tTi1Ptusrhr O85NThKLb97J1sCawBj8OvPvNjZNn50W1K02p5kIhzbuMeRlpbsTo03N1YYJLX+Nsq84 poc1DgSBcB2U7qfiZHg3sX7WteOwwqC8D94VW8SqrV7AEzm7lZc8RKWNgi8ABexEqT9b ACpw== 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=pEuSpcGiXYy1rNkif2p1RcLRxWAuPnhCpMJ3boeNpjg=; b=EznnLzTsxLh+qgamgCSLOV3TWZodVFMhgAvEgx+7yKRtDC3SSR9wQxjagzMChQJ9AU hSeMb9heIqiEPImJoiyaJg7CaYbujoi0Uv+m+07zw0jfTxH+TX+24vuDoBn/KkbmZ9sD tueupV8OPNoYWXul8GXz0+jGHec+88xdg7THGUMAACsxTq6tq4InuVofRLLDzNKSYSkw f/hwXcu2KcXGOYs/XnkzXOk6Ab8nIddVjT6G5pF0692IzeunaQX0yaWkCctb+LNC1LU4 x9B0kzLRbDG0YzZ5syWpX+ujuhSLzavGe91a/n7Se2ntNXaio5RzCv2Ix0EQbvHKzEuj bX3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="N/bsqRck"; 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 a5-20020a63e845000000b0045837277570si9745409pgk.286.2022.11.14.08.30.17; Mon, 14 Nov 2022 08:30: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="N/bsqRck"; 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 S237577AbiKNQ34 (ORCPT + 99 others); Mon, 14 Nov 2022 11:29:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237441AbiKNQ3i (ORCPT ); Mon, 14 Nov 2022 11:29:38 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B037810AC for ; Mon, 14 Nov 2022 08:29:37 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443376; 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=pEuSpcGiXYy1rNkif2p1RcLRxWAuPnhCpMJ3boeNpjg=; b=N/bsqRcka6hlDrx/SlwGRNAsEbFEBXRjQwbdRoXt4hlze32AZsQt/rhmkNMken4IpcG54I +KvWEBHaer8/Gei53H6l+GCecFD4I7gidtMF6CWblJihnzxQzE5DwB42jQlbFiI1d7JifO hFuuAyVPpFY967KrUNNJmdGq8x356zKRjK8THEwPyuHhFB2E7udRjbXnkVyFPxcQxw1HqS B124lIIlpqwf3zgW5+iBRgUIoTHePgLGxtl5xlRRnuNpgcLJeXVGdEkcps40nCTPWHz7+L /hurUZ2DPWtDUY2bh67wq39C+NuG0oiArgS1VEasLsceGezG9sOlOXjveNMh1Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443376; 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=pEuSpcGiXYy1rNkif2p1RcLRxWAuPnhCpMJ3boeNpjg=; b=rsJm1DNOHkXtPr/zx3jxXiVx0pONhvzTAgITQSLoTexSWFuCX4rsVZoPheeJfALDD322mU Ob7/pqdT1WRODLCA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 04/39] printk: register_console: use "registered" for variable names Date: Mon, 14 Nov 2022 17:34:57 +0106 Message-Id: <20221114162932.141883-5-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489752178757486?= X-GMAIL-MSGID: =?utf-8?q?1749489752178757486?= 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 Mon Nov 14 16:28:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19880 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2237828wru; Mon, 14 Nov 2022 08:30:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf4qpsSdIy+Sj9snBMpkGPzpLjBElUebtcHVBkcZ/eh490Qid+MPhYOSaEAw2v0KXu+5M92F X-Received: by 2002:a17:90a:9ce:b0:206:238e:1379 with SMTP id 72-20020a17090a09ce00b00206238e1379mr14269891pjo.180.1668443452710; Mon, 14 Nov 2022 08:30:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443452; cv=none; d=google.com; s=arc-20160816; b=uRv7exu4F0o2/KbYF0VbZTUsM5Vdf29qiQdXu0v+ETxdH+puzbiYNTtNcZOtafACax JE8TJVQkA7JQP20CSMzOxpR8GeDdGCqYPe8rmngUceAc+d9BJHKzkCaAyg+edu8elH29 T27pLS0dQA70MUD6OtBbqH+HNU1wv7pfkVfbrGKQYhbJDBZk6TKahqOJwWa+gNK3JzN5 GE2asKt9mO8+ieUxdDeacjEHgxIJlO1+D+pkwwdrnuOOFD5vnmqxsF6Fz/KJwyxaB+d2 pq3McZ9AxQWp+rw0aBEXxiNGTkzYLNr8EkAPIOqJBFmieoq/52urTabHzC/ColsXUIN5 T2Ag== 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=BhPw3XXoH9XRWJswk/JBlglPwpWkjXWTrlT44qUapxw=; b=hg7H/sga1Iq7g9xtIyNY/NTZwewBLKazwmK1miPPrFMHB9sfbZXGa7PRxnOi2sd99x 0UiQYwhCTW0r0NAMhMeaBlCVootlSfeRUzINbzhMyrBbYq0CkB6nvS8IgzsBy5WTLx+b w6kpYEu5Zp8tcfKQOJjcsHDS8RwaxcS50my0/n0gFOrAGqVqOg6hJYi3iaj6h1Ir3X+q Q2M3aCMKIn1bWrNkbLzHNInj7448byJAaTvYQn3DH+hHujSuPfokXqUbggLb1xHX0Ost zIFrLwvKwQkrkT1pTsfUqVmMlJ0Z1JKErIRBMYIZ2A1hKc8PV7zdF09GPfbsqCyH5lXe PpHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Q1SMMXuy; 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 x11-20020a170902b40b00b0017db9b9d54asi9089795plr.300.2022.11.14.08.30.26; Mon, 14 Nov 2022 08:30:52 -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=Q1SMMXuy; 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 S237587AbiKNQaC (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237520AbiKNQ3j (ORCPT ); Mon, 14 Nov 2022 11:29:39 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FCB01090 for ; Mon, 14 Nov 2022 08:29:39 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443376; 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=BhPw3XXoH9XRWJswk/JBlglPwpWkjXWTrlT44qUapxw=; b=Q1SMMXuyxOWvBY4wLKbn6h5Ayn+3VnUgAJcz69djjTklbRksAE1N3c4XVMpOJtSekBo4HY CCmB6g/foSeYLFibrh7Uyxx8C86o3zjranTjmXECfC6cMBJ2aSLX7gB0UizVZVxOv3JvPY J5Ssv+H1AkQYBOXEqsf5JDpMEqWQoQ9PIpE84wRFAeddZvaMYCbj2hcFnKLG/lhdU1N0bH AxeNLePgmpp1h1Ff70eyoEXZ4dingPBZcY2PYsG+2udfVG/P7ad4gxFnURrJdE1vy6G7Ot RQsEcIBFSkvbKkmbMUQFf7H6ujxGmvtL8i3/gJiWZ2sNI60XOKQ1Qsjas0qPtA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443376; 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=BhPw3XXoH9XRWJswk/JBlglPwpWkjXWTrlT44qUapxw=; b=mcYx8biVkymW58t1QdV6MJQytDsSYwFv4bMvSNwMxW/UleRJ4Bh4P2+T+QkcYr7QJUtST6 9S69gAfrZxGJM7AA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 05/39] printk: fix setting first seq for consoles Date: Mon, 14 Nov 2022 17:34:58 +0106 Message-Id: <20221114162932.141883-6-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489761650071948?= X-GMAIL-MSGID: =?utf-8?q?1749489761650071948?= 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 possible to know which boot console a console is taking over, use the lowest @seq of all the enabled boot consoles. If no boot consoles are available/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 | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 3d449dfb1ed6..8dbf3461cba0 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3222,14 +3222,31 @@ void register_console(struct console *newcon) } newcon->dropped = 0; - if (newcon->flags & CON_PRINTBUFFER) { + 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, start with the message of the enabled + * boot console that is the furthest behind. + */ + if (bootcon_registered && !keep_bootcon) { + for_each_console(con) { + if ((con->flags & CON_BOOT) && + (con->flags & CON_ENABLED) && + con->seq < newcon->seq) { + newcon->seq = con->seq; + } + } + } } /* From patchwork Mon Nov 14 16:28:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19885 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238019wru; Mon, 14 Nov 2022 08:31:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf62XI2pcTy/5Ir+3HArlXl5BOJNMZdabAm80X/XWN9Y69Qz7HcTfGCa7GeZwbLGBZadyrUo X-Received: by 2002:a63:fe51:0:b0:459:a339:89e0 with SMTP id x17-20020a63fe51000000b00459a33989e0mr12441709pgj.300.1668443473649; Mon, 14 Nov 2022 08:31:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443473; cv=none; d=google.com; s=arc-20160816; b=oLRUSvHFBinswsNA1/vGsb8mhYck4MtfDLq6oW/YSeooCAwH5Jk1sLPZY67LmVW8mk a1oNX91pzgCh5WjIwUexSez56cYN9M8M7h9VUdRKVLzvGoYuSKVdr8fatWmaHRjchnuG cVhKEx/pPGeEp2qI3qcAEv6yFnFezRtWzUL2+YG/WOe2YPWYFOQtS6ErWa4hQK9x3tRK QqvQQAoEGq2tKc+6cSMH7THD3gQEF6nJAOTqnDqpVzUiOp689TIIUiAcgiwqTuo3TY6B /OzbsJ1R4L0VxeTbko+5/+b6K5hoNGprAS4+uh5J+Bvi6ImyzU9IB5buP5lcylLqvHVm yEIA== 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=qDbdcl0JxLD90ySPeoTj/gMcqoyq0Ck6iC9fOKAlutclJF31TFrccdvHq+wwnVDeRS AiN0n/JxItS8BCdzrDfT3lQa6e4dVWQ343OywsSorfnGOPiIN5ofIAm4fJvQTeoCGds7 +B5bhZt29Cgebi/+kKwWHLyCJdvUPBTLhe5Q2JBx6qSXYOQicxfcZil8ZmRJsq0BbZj6 GF5Upbfx9AB5fqM6GFRpwWuTbxbNPvTecPICrXZofszdmOlK6I5eQ//GhFwYShlFD10+ EpzyqSE8jjHZMWvcq5KhRl59HV6IA1i15iACPi+aBTblwppBpC7NhvTXHMPIQAhOY7HD ck8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hXrAuUk0; dkim=neutral (no key) header.i=@linutronix.de header.b=QxyEvyxZ; 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 m73-20020a633f4c000000b004708a45ee17si10190709pga.262.2022.11.14.08.30.36; Mon, 14 Nov 2022 08:31:13 -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=hXrAuUk0; dkim=neutral (no key) header.i=@linutronix.de header.b=QxyEvyxZ; 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 S237582AbiKNQ36 (ORCPT + 99 others); Mon, 14 Nov 2022 11:29:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237519AbiKNQ3j (ORCPT ); Mon, 14 Nov 2022 11:29:39 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D3BC26B for ; Mon, 14 Nov 2022 08:29:39 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443377; 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=hXrAuUk0veFL2Qfb6GL5q62iv8qbDJs1l0+JFrxmW/AwVib9zp2qJNhFunHfBfU9Zqg88+ JTlaYWS7koTSowUankx8ymKJVaHyRcKqL0FQPxX2kJ3jy87p7JCO3vqBZ1Xg6IdsGqC/oT lfU3BO3xPx8wKUf74di2LOduzLl9D0hKHBnVEf1DeVGsqjTcFOWF1MSo2/PAMnLQL8uQN3 VAD8oc3lspCaTS0b/swtjZpIdl7aAj3KT1/bn7t0kTKgCnK346lG/0P7emVoeyvNCFXDuy ffxx3KsbLdFJj2Cm/sFn07Hv/82wgyTbEOfHV2EOrBLqmpQmhXGCKMWHi2JSkQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443377; 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=QxyEvyxZCYa8n5ddhd4y/3oG8Ik1RqNDjid21OVOW9aSygXYvipEI3nPBP20kFecVjgnoJ PQ89LtwsJTOe6+DQ== 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 v4 06/39] um: kmsg_dump: only dump when no output console available Date: Mon, 14 Nov 2022 17:34:59 +0106 Message-Id: <20221114162932.141883-7-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489783626642813?= X-GMAIL-MSGID: =?utf-8?q?1749489783626642813?= 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 Mon Nov 14 16:29:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19881 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2237842wru; Mon, 14 Nov 2022 08:30:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf7m+5Uzcboh9KOUqjLm0aIgsOzX/7t5/lkf9PhGLQvkfqoWz5c18XoQMWHqA6BlW/8bl681 X-Received: by 2002:a63:486:0:b0:460:e9e5:1b46 with SMTP id 128-20020a630486000000b00460e9e51b46mr12145448pge.391.1668443455305; Mon, 14 Nov 2022 08:30:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443455; cv=none; d=google.com; s=arc-20160816; b=CtdaQLn+IsnvBRdI45lmq9g6tHee5baxCDd69Lc1J69JiaGBhiPH31OFfzRBQT9GHg hfLFda+Nf5HqAf21yu/zPhq8RmEO0yDjsKangf8BJDc74u2UZHMQiis6vlWeYExRpBLz oe4xrsTz828btP61tuuekPViJ4jJmh47WSVkXFtUOX4ozrPOnAJz2bos09ue1S7Hv30B jxVnYled0mahgR4z84t1HLZ/XZuE8uQYn8fM4A+c0MEac7j5z+apz4UFs93tnTS/9oX7 Czoqfg87sPWWvT32dZHNuuofk4Snrs5fR44f3Bo7gAjl8eVE2z6peitTUyegjodSu45W LDXA== 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=LeM6Jg4jDT+XoXiE8HEnVW0X8xGOduvTHNcubWb/a90HEYdfs+jK45PPnyHAPrOeIW /6r5862qMTWiey92Nn++ZQ/qAYi9hPCVU+PKN28RPTMvfSsA+Tai/h90XIf2fSZjKATp Qzvpo0R90bMVfJCe7d/u3K/43P0PoMprqz1X8gwbCRt77PgGegL31LMvMZ+7WDbbnygI N8mh7CjZ4uUlmRLlmUx93tuGSIIYm5UGJnUpG923nB0MLY9Hgqx3nMHkQ3Hiuq+RoRPN mGWdorNcahSmpiqEWVbdqIAbxFjQkoLCGpI0SPuhTy17HRFKzXZA/hpZ0+f9gzkpZri4 Edrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="07f/Iv1w"; dkim=neutral (no key) header.i=@linutronix.de header.b=tELjjwZ8; 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 b6-20020a170903228600b0016f1eb1317esi10799854plh.471.2022.11.14.08.30.27; Mon, 14 Nov 2022 08:30:55 -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="07f/Iv1w"; dkim=neutral (no key) header.i=@linutronix.de header.b=tELjjwZ8; 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 S237595AbiKNQaF (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237531AbiKNQ3k (ORCPT ); Mon, 14 Nov 2022 11:29:40 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 964EB102C; Mon, 14 Nov 2022 08:29:39 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443377; 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=07f/Iv1wL9DpAMhdAgc7Xt3WxoplT/3Nu02eKR1b8+j1+Y7qfzi1+FNR+cnpkz+yvo16Ze MBTxlfIFPnOpIaZmaWz8PKDgW1EEFLce5Z7cjkdy6Vz0eKot3ypTtDpD7aXfrOfrZ5b4jX QntAcdes7YddyPfeX5F8PQ8xBH1C/Xmv0UymHEQmXC9tX8u9cMQ0818P0ky0qz/V24Ia2u 6PtsU3Op8WIIueIM9CeNFqHhD5rmh6U9hltEKu6vOewN2wBbCliUb2DS6q5csf2Eu5FEkm eEGxJwFLBff19l0CYvNQu8UBltdyze2FqKOkIC9D+rP9sBHRrdRV24X32/Thow== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443377; 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=tELjjwZ800XS5coQk0qRU9bwQBSC526T8kNf1rYyslpyZ3bvfpKU2a+6OVmFy+qzAW3ZUV +iS9PnHyufG1tIDg== 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 v4 07/39] tty: serial: kgdboc: document console_lock usage Date: Mon, 14 Nov 2022 17:35:00 +0106 Message-Id: <20221114162932.141883-8-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489764406184777?= X-GMAIL-MSGID: =?utf-8?q?1749489764406184777?= 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 Mon Nov 14 16:29:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19884 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238023wru; Mon, 14 Nov 2022 08:31:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf7h325cZobJIuUvhANM+pgN95+6tu4ZStSpLVnqs5Gmpl7tQ2vuDV2dWCmGq8lf65CJ/wlg X-Received: by 2002:a62:5e47:0:b0:563:1ae2:6daf with SMTP id s68-20020a625e47000000b005631ae26dafmr14815257pfb.71.1668443473734; Mon, 14 Nov 2022 08:31:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443473; cv=none; d=google.com; s=arc-20160816; b=erh95wp1YcJvHS5+i+Rjj53Pm43gjAtmwFC6Qu5YJWrwe4XVJ/y6gM7mZau618/CYA xKsHrw3GwyxQm4wZodzS8nF9te5947dOgaw1+5Z/r9M0CDOjNppvMn1VJY4Nazi4PrK+ Z+oWE9VtNXocSxqM0lM+s+aCgPIxT2WYKnYkKEZpDMFkixszULjkhKNNMqHzQABXHNvG /8B2TYsh8uMh33oEk7/0TlyT+l2OvDwm7vPLQJT5GXHwR8XqvHxw2hslDT6PrIQNxrcf qrTm34y/GoAk6IRYXU7hwL4dFvnwY0FQen2dqn5WnoEP1u0u1D9aPpxbQbQOZvzNv/Aj H7/g== 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=w8p5Oo+8cSj9fa2wd2zBiaW+ua+MtkASN+gimVgrJE/hM4xfqakN1vLWbNVcaON707 J3B2fdoMzaDO3zMxM5ykdwCZcr1OPrmoZBemZSIeHqLutvXcWoE8uZKoiU11HGT5e9vU FF6o47353FwVJbpE6H2zkYRsj7pYNSFldOlEDkc2CpI2NQAF9PFUcKJ0uq+Ph7/dc08P cNj0xXv+jC/NmIQFCCy4HKwotjfJ/4/XbOI7jArmc+H6oEFSOQEQQMncRImEaI+CEIcV sSSL1q0QXrAcJkXo/cflRL68G3QL6WYIjiJ4cF2mVSMxXCDt9Yw9KT2Xcw75M680zoUp W7jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JCoPP84G; 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 x8-20020a63cc08000000b00451b094d74bsi9182733pgf.454.2022.11.14.08.30.35; Mon, 14 Nov 2022 08:31:13 -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=JCoPP84G; 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 S237605AbiKNQaO (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237528AbiKNQ3k (ORCPT ); Mon, 14 Nov 2022 11:29:40 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9189BEB1 for ; Mon, 14 Nov 2022 08:29:39 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443378; 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=JCoPP84GTD7S6ZKvY3Z/oW1faIG0mRb+VXwmEMq2/9maJnu2bJ4vVZwAKdnWc0JkCEwziB u9Z4tPX23Yk6Dq1b8w2jERlxWFg9DZ6B8ebtpQpj8Eh/HGr1vYGrbZvZRaddeJKAO3LlQx J1TeVrqc45Q8oimpMKSBUzA7sN8i9CC+jZFqFP8+fC6nuurYGVkEgO8NfYHmsCdyslWqR3 r49w15/LRtFVLv5xvSxiCEuHQy5VVbMYf5zi6z8gKRt9MYYconzIJI69+2S8dLZ+WC4xuX LH/xD2yPO2uk1n/+PeJzAvnTu0vVvHmwItiLx5zxsIDDlP21zAWNhv2/dqOwtQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443378; 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=XM0sZBUTpYOnV33YxdEq1ANzbOmI/ncNQRLlKWlmnypDTlRkCpe0fo3vqHy9OFToINmwjt D4N0MxF5n4UhX8DA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH printk v4 08/39] tty: tty_io: document console_lock usage Date: Mon, 14 Nov 2022 17:35:01 +0106 Message-Id: <20221114162932.141883-9-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489783766806188?= X-GMAIL-MSGID: =?utf-8?q?1749489783766806188?= 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 Mon Nov 14 16:29:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2237921wru; Mon, 14 Nov 2022 08:31:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf5/SjM0X+zB2YZ2ho0QHBiudqBaINS/65YMpBs20hb3Fi961Az2nHDNzookJZ43Jl8grTv/ X-Received: by 2002:a17:90a:488d:b0:212:c216:50c1 with SMTP id b13-20020a17090a488d00b00212c21650c1mr14648421pjh.163.1668443461421; Mon, 14 Nov 2022 08:31:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443461; cv=none; d=google.com; s=arc-20160816; b=guV5iUBnELb0A4lqx+OVqpmFOrW3D0Ag3UOmqzKzOmZG2j8vywtpgpYQPsCfgTkm8F J1nNWoT/1R2z8TmTll7uK80ODl33QzpR2T+NiCoC6yybsjup0XunFrNSNXphS2TJjdTq u86WNZpRf3gRce6WRMja5+ym5ZC+jcdH5Hj/gPNRoTK3nQgj7Aqqm099QYjLh828PjJK ELErj2FlMg9JEhFimyTMpSYrlj+5zqC3MaDEz9B3Gr193rCjBmoTKwxhwojToZaWwEwt UOkniW182xBgwXttApTfKdIq5BjIxn5oUdZxKYbIuC+raMhi1wle9JeaAWaYfYDO9CBN ghOQ== 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=uw5Ocx7V5IOaKkzAwx8ZYzJoQbHiH28/mNakL75NWLmYhpVtnhCvk5sacTzQbBFOGG /vKHWt8a6ypTWj3vo6kz6OTliiKNPe813rFaVYXk6y5qa/eyUW8aC+ysxqyd883sZhQk BLxtKHpKZwrCIJ6QQnm+1/BVyPlC5EnDuF6iovepT3TCWNHhnQ/cIGftMIkawu4m45Fo XY6cRwr9JvNMpBH0hN3j825YqEngV370RLcCZqB0sxxjGTGHF202Qio63whH1mwzeguO 3Dja1UNeW0etmpDy6I166hGSTYeuFmgWw4dU3bHFPOsOyRbW9ALItWjnNmBlEprf2Mwk pnPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=FqAoNjaB; 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 v191-20020a6389c8000000b0046ebb8fc292si10001039pgd.7.2022.11.14.08.30.31; Mon, 14 Nov 2022 08:31: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=FqAoNjaB; 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 S237600AbiKNQaJ (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237539AbiKNQ3l (ORCPT ); Mon, 14 Nov 2022 11:29:41 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C99426B; Mon, 14 Nov 2022 08:29:40 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443378; 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=FqAoNjaBB2Rlp2mNiLSbghpPzLzwe/mxSu1PahgKtAnhy0JYz8REmdtNz9jHFQFaj113nY ywZ/YEc1WnqLUt/lbm8feA+MyPzbJIRZv3VyR+hVIHoOTru/KIzygWDs2cWOkXnelZvsoo 32AkyhpdUEvPRj7CPilKpeib4j1jznLqH+nKWXz7/7IBnl7Xk86MCDk0tWzXGSqSVG/RUv QRAw1Gqdw/S2PhYt+lV+WuN3kZ8zlf7KMaF8BftoCfYw9WENgLe5lBCaUXBOUsalZFaZAb 9ZPCStORGaRXJVDKwcBdwVGTJacSupeBxD5165H9Ma8QabshUKzxXOyMSguQiA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443378; 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=TSOchCPgjdlhJPka+GKTvoyPM/0XtrZC5Yjg7o2tlsAmZW/yw3oP7dxd3MB5cXFma4zBBg 1gDZE59V6J1GTfDQ== 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 v4 09/39] proc: consoles: document console_lock usage Date: Mon, 14 Nov 2022 17:35:02 +0106 Message-Id: <20221114162932.141883-10-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489770894895643?= X-GMAIL-MSGID: =?utf-8?q?1749489770894895643?= 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 Mon Nov 14 16:29:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238136wru; Mon, 14 Nov 2022 08:31:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf7HeE8sEnAkI2JR4LHqbi2BzAEzkusqyfwXV8ZHXGoW/wau7dFTk/RAJ36VVV4fySeDLcvY X-Received: by 2002:a17:902:e5d0:b0:186:bb48:2b34 with SMTP id u16-20020a170902e5d000b00186bb482b34mr180948plf.1.1668443484322; Mon, 14 Nov 2022 08:31:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443484; cv=none; d=google.com; s=arc-20160816; b=c+TrbdA7yykwk1Ygyt1nIqkpzNlh+/cyt1Mt96buJd9J7n6nHruBO9ye3KtGVcaInF piuYX81i9TC0aZt2g33NBlwl+7IuO8yW/r2LEuivkiPRxGAkeMk+9v9RIY80bzKEFaG5 TJJRKFc48BunNXykJXW8/aH5vQPedlbqyFJErNt7gUS7m+XbuEJOzybh/elkBsJiIAhQ b49vgO5LYT/SWO3Pt5k3DNKYGyannnO93rKNOJuj9hLDyRjEjsV6e3qKPL+NDjKmLmqG 0q7CUwBaxo7WHxCaLnQT6zpjrTiI2GYprFsa2guYBdTQFMNe3mm72reBYqy3O+saEeA7 VBEA== 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=5JsDGu5IVhR/uTTIVh+OD2xeQMjAWfs9q7KkYfOMdPo=; b=zq6t6z/G3n7EMngvJP61W81yChOwIPeXfmLbZCBm4WsAiB8It+Sn3/O9oOYl6vKmg9 vl2Vl2Zz+zKVZwCHCrx2aKlCZbydtkFnDINSRyD8YVxKFAOMyPBDL4z2++P/KRdGZIha E8X8XwEgJjKpqz9wiULP8FljUyMZcgHwrBrw4BvXtBShBrJVwPD+yLsiYrMAIfj8Rsxt 7X92xUiTitRuNuDeFWbp7Qm/fpQl+9Ol2YrncuFGWBvaDb7e/dPCeV44SZvNe707q2zG 1tbJhPvT4k+4tdXP1pZkikpE7cXrhDwc0BdsZ0tRO9JUjr0DzLbq6hPiMvqoMAthLRxU WGew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0U7Vhra8; 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 s18-20020a632152000000b0045ce0eba520si9424414pgm.751.2022.11.14.08.30.39; Mon, 14 Nov 2022 08:31: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=0U7Vhra8; 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 S237613AbiKNQaT (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237542AbiKNQ3l (ORCPT ); Mon, 14 Nov 2022 11:29:41 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 529D41090 for ; Mon, 14 Nov 2022 08:29:40 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443379; 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=5JsDGu5IVhR/uTTIVh+OD2xeQMjAWfs9q7KkYfOMdPo=; b=0U7Vhra8kpNEeWbfS2OZvl45p4MAP21g7TlrthXGIolUtEWWkpaGim29mqHfuLdcOV8Bcs vzs+Yp6VoagioH2U3kRUcuOOLbGU5Zzgmz7f01M058bgPVvh2tCRDP6vh/Xw+feHwn3vdX TTqSPNxftntApw4EOKT03Nu8xzrIewiC+n4aC4iPsCMHcJuuO+AB4qY+6cI0FE58aYdTzp qWItjw6eqro2lR7nHvkcGJOa1nPChW3AFYHoA3qIYQsaMeaRXr7B9rLvuguocrRJpA2ZLI +gXt/AMdPowg1dfuOGk16b0DpqeIL94LsaWplBTv6xW3rYlFE27pByHV7sFzMw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443379; 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=5JsDGu5IVhR/uTTIVh+OD2xeQMjAWfs9q7KkYfOMdPo=; b=pbKCTsz9yGCQaP7FTXHPbuyfxCaX3Ev4YnxyWvQoj/S9QHk2p6KroYdyoQYVMsCeUv1uLN 7cnLqs+zlhxQcsCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v4 10/39] printk: introduce console_list_lock Date: Mon, 14 Nov 2022 17:35:03 +0106 Message-Id: <20221114162932.141883-11-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489795065597528?= X-GMAIL-MSGID: =?utf-8?q?1749489795065597528?= 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 8dbf3461cba0..e3f81dda5b09 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); @@ -3134,6 +3184,8 @@ static void try_enable_default_console(struct console *newcon) #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 @@ -3160,13 +3212,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 @@ -3177,7 +3230,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; } /* @@ -3208,7 +3261,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, @@ -3292,16 +3345,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); @@ -3350,6 +3408,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); /* @@ -3402,6 +3470,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; @@ -3419,9 +3488,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 Mon Nov 14 16:29:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19889 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238142wru; Mon, 14 Nov 2022 08:31:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf6x2YBPS2oMGXjaCaeczm8OZ7dWRqAOHPZ1sCTq0mx9Deobp4R6c0OVtZCvF6bmT3OXVNHk X-Received: by 2002:a17:90b:3d10:b0:212:ed36:fc74 with SMTP id pt16-20020a17090b3d1000b00212ed36fc74mr14807030pjb.172.1668443485038; Mon, 14 Nov 2022 08:31:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443485; cv=none; d=google.com; s=arc-20160816; b=hfclbKwRU5V3sQDPsSnhWThtFyzkt8ZlMNQrVSTqkodAYTMAF9tVDrKgjvHEYQ3EZx hIdnruSk/Jsap9J1U28YwBTABcHW8HI7ZouVHeUF9HtcfWA/nxyLR6xrouasU3afU1/4 O4H8MvsVpF3YebhL3xHm+SbtOKZzSzBjsUK+25lkbxWM83QPRfTe4aS6EDw8PStr4mEU ZC+t/Bw8BM5eWC+8sM+lR6X23Th7m3aRrDF6cL48lzIhroVrQdqrRtYfH7BJy7EeZD+h ZrLouPtTSaHZZx0tzqb6WUjkiSunCwgqxVGt0lvLHjUtWqdS39qlqqutEdLNUteroS33 h/ug== 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=yNQONpXKLQCgtojOiA7woSE6WWehDrB23B3xD86mEsY=; b=R3xIe05G7K5Z73Oh/uUOy85oVThaNgEDYn2pk+qO9JrIpB8Wpf7UPDByczCZN4WOSa iHlcukKxleqp36Qk2yOlR2VhVuVVXEFkyy7Ban4npKfMrMXMUI02RdTOT5jdl/0TCxTo /flkCmV+XtB9v8Eu1JYfF35+T7tuHM4IWlM4q+qJeXnlR/Om+eVp2YpjyEd568i75tyd np9P39xOxqDwh+ifIaYbJBdj+Vt5SywOLRs8Y0/7TuDN5l7RJpVoHPIHgRDTW2bCW+NR WpqTGgRVa9mmzn5f+YPnJIi8wLwIpq100Vaa9ZPiXc5uI1fn5X9XiZSDaedGRfA+Sxa9 YMAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="SGGd/1Vc"; dkim=neutral (no key) header.i=@linutronix.de header.b=xwbmKegz; 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 c8-20020a630d08000000b004629cd1dbb1si9804531pgl.329.2022.11.14.08.30.52; Mon, 14 Nov 2022 08:31:25 -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="SGGd/1Vc"; dkim=neutral (no key) header.i=@linutronix.de header.b=xwbmKegz; 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 S237606AbiKNQa1 (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237555AbiKNQ3q (ORCPT ); Mon, 14 Nov 2022 11:29:46 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E452EB1 for ; Mon, 14 Nov 2022 08:29:40 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443379; 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=yNQONpXKLQCgtojOiA7woSE6WWehDrB23B3xD86mEsY=; b=SGGd/1Vc58i2rYuzhVWBqWHjszRgMZhvnT3oKayx2GYx8/INV2Ype+7smcVWafRhlvCjsV dlFlOD2YIZru6VoP5bfq3KHTWxneCjpgDPUU9FZJdE7VdnZaIXcn8lOQuWonP1wUE55SJl aZ4ElXS0zoytLriQLgKBm7W73gXDCXsEC59rX+unP1M5AFR4iZDC6LBRFi6t8y/5QCHMut TuWpzZ8aHePjJGNKLFOA0+fzo4jQKvBrX6zgklJzVNXkru+1+Cnlu3wWqsM45ZBifxCAx3 7bwI4GqLAZJmhqMXHwyGVxz7VDih4xcq+QimpQXvQrJJcae3W2WvtgWVKqO5Hw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443379; 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=yNQONpXKLQCgtojOiA7woSE6WWehDrB23B3xD86mEsY=; b=xwbmKegzg6Lrvh1pBjkU3Brmk9CyefQmno6CuRD8GILGq6wDoOyIK4OWzsLrOE4M32qFvf kMk6pMrHBfUsxTBw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v4 11/39] console: introduce wrappers to read/write console flags Date: Mon, 14 Nov 2022 17:35:04 +0106 Message-Id: <20221114162932.141883-12-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489795619884941?= X-GMAIL-MSGID: =?utf-8?q?1749489795619884941?= 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 e3f81dda5b09..41c90b768c1c 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); @@ -3314,7 +3314,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 { @@ -3371,7 +3371,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(); @@ -3390,7 +3390,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 Mon Nov 14 16:29:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19888 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238145wru; Mon, 14 Nov 2022 08:31:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Ga6CUeipRovayzzaEa1Tli4mnXtpQvAPhU/AhxzfAZDLfsgmVB23N5oi+xrNax2vF6c9v X-Received: by 2002:a17:90b:2784:b0:213:d1d5:d661 with SMTP id pw4-20020a17090b278400b00213d1d5d661mr14637142pjb.43.1668443485158; Mon, 14 Nov 2022 08:31:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443485; cv=none; d=google.com; s=arc-20160816; b=BYTITHSMqYpWRM3+eBeT45ISHd0g67iVfOXt7U/nKa8lwfLVkBL62loeFWEERA6tG3 4xbUaHRWxoEuJOaqiA/jXflT+3MdzwmN0wSHoXjosylqDKPShSKa8ZEF5YCehvrmb17u e7MCFHWVptncXVtVqBRuuqnraeAKx41KFCWYWhflHIcqOng++C7g2BDTGWcjdtlwHufq daiLBNN7wv/1OKpaGvTNCgK12LN8PPRHB9fypwrOBlWqO2q5Jp14flVSALuyyuH++FZd /+bTOvYqhjR3B5xgKul2RkTYxkZRFDpBRogpk6J1UEgK0S7K8Y9Cr10pD7mhhS2VXeYn XYIQ== 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=I4avksfeFSio7DoQ3Qnd9VzTlUYnwkKt7GvmFNZQdgWg5F+7PUCXGvhVf5eJznSZfW 9ErVk3JdZaym9m8YH+6w2Bb7eOwkVKN5CyYBlX37JiX7QRCqcbDri7Su3DvyfFvvPZ6Y T7uuN1ETZa1WB3hVg18giBUIB95ami5x/sZLObq6i3xrQpWegDJT+qAcRuXCLgJKLbjp F69fJcDPl+e5rQp3ap9tBcHc+Vue/o0aFPK2EINmdE7BhMiJC7sS62n6gxmfPvREH8Fn u9p+jUJGkTNF6zTT7KfdQqwkWsvoU6tLc9TZZNViLa/iNvGm/UJvVtZ/dkGPHdPTdoEQ ZM/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fED6VtmD; 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 l186-20020a6388c3000000b004767ae4f4aasi4062852pgd.486.2022.11.14.08.30.43; Mon, 14 Nov 2022 08:31:25 -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=fED6VtmD; 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 S237620AbiKNQaX (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237537AbiKNQ3l (ORCPT ); Mon, 14 Nov 2022 11:29:41 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BA13102C for ; Mon, 14 Nov 2022 08:29:41 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443379; 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=fED6VtmDED6MuLvYHCpr7jg0s8uQ4ubFuV+VJrDBURlb+sRmrPLVdZhbCg7C9vkvldCcZC O3jnP3sS40Xc/9Nl61qOPe4tQo5M701OfeqSfviyYjbM9aVF5lpkSd4rH9cAes5ZiqmRXV qSC0fmcpzoHohSsnvCqpR2jm74hLpeXfas4Urmb+nz47yUrVVMWUckuYe0K6QhSQ0thxYe Do4tLzYO/CeZJ4lQo1ewHWpTh8mj47O/uroIOAzyntCZsQtDNfsDD/JIDWJTssmb6VX7O6 7zwiYUW4aXXfoFUuEEQfPo3tGoBVRNEWeL66ULaqMgc89bm5V3SqUuiZVWBb3A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443379; 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=X+VenatF4kHSWTowXfqC0zSVEJludzZYKhc6X1KeZyez9dy82GgAGpy+a7Avhfw9vUOvoe nAz42aPySqUAAZDA== 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 v4 12/39] um: kmsg_dumper: use srcu console list iterator Date: Mon, 14 Nov 2022 17:35:05 +0106 Message-Id: <20221114162932.141883-13-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489795911860001?= X-GMAIL-MSGID: =?utf-8?q?1749489795911860001?= 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 Mon Nov 14 16:29:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19886 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238113wru; Mon, 14 Nov 2022 08:31:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf5amWJ8hTX6cVLlyEZUJ+eb09aqcv3tf6fOVo+tMQzBmuf1V/Wohr6Tc4hgxNL6jvvNRguv X-Received: by 2002:a62:7b53:0:b0:56b:83d3:a22 with SMTP id w80-20020a627b53000000b0056b83d30a22mr14602698pfc.32.1668443481664; Mon, 14 Nov 2022 08:31:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443481; cv=none; d=google.com; s=arc-20160816; b=prJDDNzv9/jVHc728lehcWk7C72ZBz55+yC0jicSFP2q0uFEkjOW2IxLhFhKHVn2bc Vh/CvXhUQZ09YySSlx6QT5EgX1gvwtym5csKzhdD/C4+lVVbr1BLngHgYOH2Gq/UAE7a E8sB0b6cenGYFByK5SdQ4lNO8LYK5lcQObYArk2/tiCfSl/SyQvEBAl0+gdQ/w8Mp5UY NB9auvQIYr7tDWDDVMNo00F3DOeuu6FhQM3y2NZZvVSYpc3Fk+ZVR79hVBNlfnwsb524 TtLcYVzmAxR2tJv9l1zNq7mYt0jeIghQgb8kzyvCFYs3YsZvSTp0j30Jkq4YONGLuPbM 25nA== 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=dmQgD+t+Pywrubu3H0mhuWuMaWs++GAlupQRHdINU0E=; b=LuIv8AOtHb/wknHBn3vCZPoQABbAgQFS8w8STEtPYQRLxjJPpPyhzFvIARguOsVrvv or7UcQTkTpzz5aIBAT8zdTlcNBGC+sFjU9F6PrLS8R4l599I3+YpAJ7yV6uqV9Q7ci1R qTGVcnoX91lkyW763VvXRZMLqs4D2ZzGPp6n9mLMerADZARup/eYVqcm9OvMjdNWE56S QGrT68OO4Xm73m8KVigLJLvHUFh/jWD5DX/NpScjl0gTv1K7w2D5snstZX5aRcJTyGrl D+UCCpaHJE+bfKxUQs5InlvXNBMHDM0pwKG+VczgnBXn0y81HM8X2+KL98i55d1jTMHe IJ6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XQ9KB4oe; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=RTsdtTus; 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 74-20020a63024d000000b004403d4f1f6esi10017797pgc.458.2022.11.14.08.30.46; Mon, 14 Nov 2022 08:31: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=XQ9KB4oe; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=RTsdtTus; 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 S237639AbiKNQaZ (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237554AbiKNQ3q (ORCPT ); Mon, 14 Nov 2022 11:29:46 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2612116D for ; Mon, 14 Nov 2022 08:29:41 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443380; 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=dmQgD+t+Pywrubu3H0mhuWuMaWs++GAlupQRHdINU0E=; b=XQ9KB4oeyyyeCvUXMGQ2bqZFv93YVz5KGSl5A172siQS+8OuGoVz7/F/KnpUIaynkz30Dp kR2kETCMrLKZgEatVBs6HhoMFGvz8KgezFKHF9fyJDmnDbCfNsbmrmczlEVLF9Ry29VGvQ t8G8SOFz7fWVamv5nnHRbw2w4/WvrFzdv2qwZEsXXZNG+fqHiGHM+ldv0yOUhM9AB7HC+n PqdpZ6hgVYTjCqEWW9jv1c2vNJYWHDSw6YOV+e11DsrQlKDkrQr12iNfRLDQlPmHr/jkuY gujwc6Rq9oLYttRJ00U3/vfnvy6Q1XE4fL5/+X8lKDr5c21zlTaWuyeQuf7+hw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443380; 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=dmQgD+t+Pywrubu3H0mhuWuMaWs++GAlupQRHdINU0E=; b=RTsdtTusacNEWE15rK5zI5JAuKscbSo2PVn8TlR/kHK5kLMWgXvw5/Ga525pquU1vcOsps JLpNpTN3W+2dYvBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Luis Chamberlain , Aaron Tomlin , kgdb-bugreport@lists.sourceforge.net Subject: [PATCH printk v4 13/39] kdb: use srcu console list iterator Date: Mon, 14 Nov 2022 17:35:06 +0106 Message-Id: <20221114162932.141883-14-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489792525121554?= X-GMAIL-MSGID: =?utf-8?q?1749489792525121554?= Guarantee safe iteration of the console list by using SRCU. Signed-off-by: John Ogness Reviewed-by: Petr Mladek Reviewed-by: Aaron Tomlin --- 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 Mon Nov 14 16:29:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19893 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238260wru; Mon, 14 Nov 2022 08:31:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf5hDPXnNzVwAdL76aTX85sVNDXhb3hU35YrJlviGreXQF0yIxnIXSe2bKVwFMzXQxxExCcs X-Received: by 2002:a17:90a:8a15:b0:211:b2b0:25d8 with SMTP id w21-20020a17090a8a1500b00211b2b025d8mr14116625pjn.54.1668443497708; Mon, 14 Nov 2022 08:31:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443497; cv=none; d=google.com; s=arc-20160816; b=ZI513Yuog9WLprNG7oJoRiAs4Ir7vLmlq0uDcSdDcyp3dDJH1iQVHi0U47EBOxfpje I8UwO/2R68h4yBooUPEY33ZXIcecvjwWxX6TyKGUD8ReS+93WjtWdEbgsjZLO+ic3oHE ki6Gx2oCydalh56ngv3hXmNI9LZAXJZBaV/WFEl8ZASdHPMobyvd122KZhjyDkDxEBKo H0GezFQXXsp7yhXxswoE73Cqb/tYnpWz3h0ObGkBPnQ0Y+ihNT1p+iQLhfN4DL4ArKnC 3OJ2iLuvBDkCxmDgbj+VQVFiBfku9j+ATR5CCQLa+IsjerGrg18VIZTSEse9wP3tCORb wquw== 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=L7LcLWC5s4F/RyK0sKOkJZmEcWHo6be8Q4Ot+G43/3M=; b=PDfCXUZ8PbN1PEkoZkycEbJymnWf8HlrqdAAXHK9dypvNm4PkzWJV0VRODYjJs9rVO TLDgkGr2VW9W9kg5LYPaYfsbxUfCNyrpcluiyoeN+hGfHeKvL/TUcmlXpxCRmmgWK0Iz Gods+lbyZHP1vfJBvtfViZiYPtogu7w7mmneu5KpUCDJ7pNm35xQGVs1cZcKCQSAEjI4 99F0tkowSpPGoCS3j0YBf9q7auSVWDXKW37LoQDhgG7fh/BA0eoBFeu5Ft0w/qMEj89u QrxFlpfqdDTzJ2HHAft4dBJlJrWpJVgplNPlfpUeeYKShV9A72eRJp47paOaZ5Qs0o4e DdqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OFAAu1wQ; 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 hk11-20020a17090b224b00b001fd7d02c976si17361333pjb.87.2022.11.14.08.30.58; Mon, 14 Nov 2022 08:31:37 -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=OFAAu1wQ; 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 S237663AbiKNQad (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237556AbiKNQ3q (ORCPT ); Mon, 14 Nov 2022 11:29:46 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 351252AC3 for ; Mon, 14 Nov 2022 08:29:42 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443380; 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=L7LcLWC5s4F/RyK0sKOkJZmEcWHo6be8Q4Ot+G43/3M=; b=OFAAu1wQb8JE+XQ07aM7bHXpc19dnsNC9yP9c5ZzXx0bfjLiMGQMjE6XrwxsAuBePR1K/M pyNi/LcjvAOsZj/jSUTUV+xS+OQ4ZZxMr1DMwMwK4D3yNi4UIQ6TMKVXuaK6BFH9e6t/iQ EQ8OY/nZsNth+EEUYNm4rhKMDSO7OP61uITfT7JsR4MRgnwGEd9vaYKcQFi4tCFnwFcHGW ydrrAsYmcRcg6e/Z5lis67e33vbUoqquYc3Nl6e1ksQUn0pQBooYox8BTjEiUIwB55DkEf rh8Q0CHfk5ZG19dJYpL4EW2UlQfkjmtfiFlmiraf/6esqJmj4W4S0Ef/rRr/dA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443380; 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=L7LcLWC5s4F/RyK0sKOkJZmEcWHo6be8Q4Ot+G43/3M=; b=7sIkrDBZIW1O7yy5M+v1Q9mn5c0wOFxQxxNvWh3c0Ti2f1yIPuMOd+HPBIX0rDpXWU6XpO JI5l6JIzCl/kT3Cw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 14/39] printk: console_flush_all: use srcu console list iterator Date: Mon, 14 Nov 2022 17:35:07 +0106 Message-Id: <20221114162932.141883-15-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489808888716658?= X-GMAIL-MSGID: =?utf-8?q?1749489808888716658?= 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 41c90b768c1c..b37ca16abbd0 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 Mon Nov 14 16:29:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19890 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238173wru; Mon, 14 Nov 2022 08:31:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf4wuIBql7FiYg41gWyp5BY3LH958nNWPIUpriwfq75PkSPh/OirTuww252wuOMNDFDHt4uy X-Received: by 2002:aa7:9156:0:b0:56c:a60d:54d7 with SMTP id 22-20020aa79156000000b0056ca60d54d7mr14402767pfi.18.1668443488219; Mon, 14 Nov 2022 08:31:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443488; cv=none; d=google.com; s=arc-20160816; b=W1PFYlZNDx9lljRIMHR2G6UxGHUrWf3BKY8nre4c/GXmcBpJKNHjqlEONUGAwPQVt9 Wu0JiPaLwlSAb9bZeZSds/wRX3R0/GgHkY+ueVVYhNiU0J0YM2is1Xfa8lfIxXJK5a0A TATcbR/cfTg1TxsBBGYY1f1YkB4rePuOlYda2bnIPnPCSbe8uEtDvyj29lVmoqCgE4vA vvLictgUdmftYPbHgqQg8uhgsjU7DMD7QzxDkWTccEOHuKCPWvNl6w5KFyplH/IC+j08 OdX5FC1EOfQe9txvmjQKp8rPi7L0dg00jLWpdtzsKVmtPQ+u935LdEkS3BU1GLvEtYxS 87bA== 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=gNqL8lThA4YIywGDMJUU+3tDmR/wiL7uckrDiJUm3Yc=; b=uLEjms7cmwBmJMuzDEjOX0SiQEDR4VRaNisa6AEBd+1dtst+UfohNmXyZojDP0oIkJ wXz+fldKsDxRmWp4bAEcrNvGjzd6OQslEIP5cWOrJMmJ0s0/KaHGjzaFqYtwlkJexhJp 8+pZZaH2cwq5c8yxAbhHoAM8QrHeNjLL218MM0wjfeFmt8Shp/K6qwLcpkjCBWZKAcGy Udc6U39niWDXxaDr3wKuxYlfsjJxmQmmHf0k4FS+ZI+Dsgd2oAur6OGHIMoi4gzqrDqJ De77sHzjrvqSKL8Ya5tFG1dRSmaeLivGfA/ddJUSx3VJd5sEu3+qtWx4OxE3DgjVQxYK 3klw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=4P34KEWd; dkim=neutral (no key) header.i=@linutronix.de header.b=NtJVSn5M; 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 s18-20020a632152000000b0045ce0eba520si9424899pgm.751.2022.11.14.08.30.57; Mon, 14 Nov 2022 08:31:28 -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=4P34KEWd; dkim=neutral (no key) header.i=@linutronix.de header.b=NtJVSn5M; 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 S237658AbiKNQab (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237557AbiKNQ3q (ORCPT ); Mon, 14 Nov 2022 11:29:46 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5476E1CB07 for ; Mon, 14 Nov 2022 08:29:42 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443381; 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=gNqL8lThA4YIywGDMJUU+3tDmR/wiL7uckrDiJUm3Yc=; b=4P34KEWdum5Ad8J25GcIpklGjPLZyfP61f2N+FJq/EjuBLOCGQ402uYOuCvoGbXhkJRKlw TAFpdgqASC2/Qdr7QkpAThBldBcPuWfFfy5BtsG45GN3AISccx9ynbRBWAGkTSTgUcFfLP eLu1zs+FP/0ktSIiFPbtmQnqSC3lnyfQ0HrXy03qxk0YTMMqBhSxaXLyv4uc3dWa21Ln7t Wz4JMJAQcWlDqGjr0NBiQWWSiGOX4WyU9l/ySqaJpdS960EPrw/MOxErMLy0Co1qG++59U fTuggTBbCuSKexyxD578FCD/vn9pCaF5Qttt8ZjvuQ5uKVEPwa2YZRxbVtPSbA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443381; 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=gNqL8lThA4YIywGDMJUU+3tDmR/wiL7uckrDiJUm3Yc=; b=NtJVSn5Mg5MJsfN6WJJF9AlssUQDo7vZxv3r93RxJ++DnBUK7rFjhIZE4JTLWwLHlvVAzC epjYOkxx+Piio4Bg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 15/39] printk: __pr_flush: use srcu console list iterator Date: Mon, 14 Nov 2022 17:35:08 +0106 Message-Id: <20221114162932.141883-16-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489798935702153?= X-GMAIL-MSGID: =?utf-8?q?1749489798935702153?= 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 b37ca16abbd0..3d9e5bb1a50b 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3532,6 +3532,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; @@ -3542,9 +3543,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)) @@ -3553,6 +3560,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 Mon Nov 14 16:29:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19891 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238193wru; Mon, 14 Nov 2022 08:31:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf7lpfSeoMhd+AgbYK8OHzJfi0XqO32CnSuDW9Kb8ZDtmoyI/hd6qLdy2DlIeoD7P2e3QTid X-Received: by 2002:a17:90b:48cd:b0:213:47:57cc with SMTP id li13-20020a17090b48cd00b00213004757ccmr14086294pjb.174.1668443490966; Mon, 14 Nov 2022 08:31:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443490; cv=none; d=google.com; s=arc-20160816; b=fAmpvhjpb4tpUjO6+Vwq2X8Jr2BBFfP6bLtvQvtQjeRnN3UZn6tpwX0A71wy62ySZT l9cTyFPThy81ZT+5/3SafdfXcHHKnwwAQfbwXdOuFLktXMxQrhnm6TZPqqs3gLe86xsW KRi7ecTi3Xgljvm4JDlqjt5+jc8urIy2OWHANo4+vCCgYsJuOu19G50t0OiOBNI6PZfr h7kMO/DVsXAor4edYja4lA+jMpxjNeueqLlH9WgbfpEIdqkCIny8dVmdUFew23ILtIao JUY/TSPKzTqa0780o6YdvDtEIqVdZi0TYcwvl2hqfRhAdHvBkhhvtqSZZwkrJ9KOc9qP q6WA== 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=15kv2lfD0mZOWcVuclsvK9b1h/ynFw4leTYyP0YL6rw=; b=oar6LxdwK75KQ1KsaFzbyi+I2T1L/ItkoAdXpWcUlKIAPAAjIhsmt24hI9l116NPG4 9iQ2ueJB02lfIoP6HDi1ynp9Sa/xQvSwe7g6jHU5rKEDJegI/xmgn29Hol2D+H9v2C+f hOWBq8jgAjWg09NWfiRiibGrOgaFrZ5dmKWVh3Z5S4X0uJeSdBz9ZnVTVJBgh+IF7tGG BJ8UhSSJLDjaytGIUVIzIKhXzq00d5L+yKn/uD3FjqP8Tc4xd7jk88gx1KtDZRs8/fH6 fvxMUxZ8qEhnqWs6da9y6b3VVcPg/DbD33L9oN+D5BPu6BDENuLyySYDJtMhoNHmAI3Z mBYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=okh6A5Ql; 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 20-20020a631454000000b0044b5e15db73si10368506pgu.249.2022.11.14.08.31.01; Mon, 14 Nov 2022 08:31: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=okh6A5Ql; 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 S237669AbiKNQaf (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237427AbiKNQ3q (ORCPT ); Mon, 14 Nov 2022 11:29:46 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8A1B1D329 for ; Mon, 14 Nov 2022 08:29:42 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443381; 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=15kv2lfD0mZOWcVuclsvK9b1h/ynFw4leTYyP0YL6rw=; b=okh6A5QlkjpXnF9pvfDJcTztMcEqPE2ZSnWcrrxa3D8kuKAc8UTMRdT0c1hkuitjBXNNDM jhHlWRLXkX8q9iegblR2CQvjQgraDlaLGzqYlVGZUtAz/peO9lIHwhcH7h1SfDRDWjE0Jo pADbPTE4O44NqmyRyRKpjdsMVrW2yKAmXFF9mR03SnaMxDiX6ShaX066yswHAj21BHuVaf nvUjYGkkyBujbFZc+zxYh+0ZoO2NgyKwLLgfFWY11jLxO5ZPI50GRVptsLOOlyWfGYmQZu ex+5XtJByUT6RcllQbiHE3xIW2f2CcmN4+kl12Xb5IVcrAfkXFDOIC8rtAp0yg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443381; 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=15kv2lfD0mZOWcVuclsvK9b1h/ynFw4leTYyP0YL6rw=; b=OQIMQpLs1oTaVmqPcyzpUCH3snN/rsTE4GnEQR/mf0gHB+XdIdbvEWEUX7kbVh7tAr4HIb PFUVAyeQcHj6mwBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 16/39] printk: console_is_usable: use console_srcu_read_flags Date: Mon, 14 Nov 2022 17:35:09 +0106 Message-Id: <20221114162932.141883-17-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489802136629298?= X-GMAIL-MSGID: =?utf-8?q?1749489802136629298?= 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 3d9e5bb1a50b..bc563972e468 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 Mon Nov 14 16:29:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19896 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238475wru; Mon, 14 Nov 2022 08:31:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf7eB9Y41xFYjyAcBRirhdPz0pH1q99mPEpK8l0bprhafqaJdz1rHjNn3tSYB9P1LB9y/hEA X-Received: by 2002:a17:90b:2691:b0:213:971d:9022 with SMTP id pl17-20020a17090b269100b00213971d9022mr14635728pjb.47.1668443517753; Mon, 14 Nov 2022 08:31:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443517; cv=none; d=google.com; s=arc-20160816; b=lFfanLIhab2hjttqIgbnwiVxRj85mDeSrAnAoOOcXZz8ivAEZEj4CDeDEu3hJLSG0l 2BqtD05fELUlQo/Op7f2WeSW4E99MLIIeXbyl08PdYeTAsC72bU0AZoIj5TYbdQE1liI PwT7nR2hBbx9WJKOUcfWgjV6A2zQ4haMCMFOqvB7zRfuLT91HgznzXhWed6/d95+Szr3 hxBEzbNUODbI09bjVU08Lh6nXyC+82oniYuyFirTJE5NNw5+jaGqHX3X7Gn3mwBRZ67b fnU5K1jza4GUGTJxIpfD8eXOPaLMkO68QyAPp8ExDxPzwPianvh3VC7lj+6/oJAV1wqJ Q34Q== 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=jtDlGuAbTSSJEMWTvdI9kPHsEwopJ5BO8AfeZI8Xzok=; b=OWU2uTvZal427et8+V84bsVk1DFNlekUzUNvOYIclVCWlKSvV81yX/yAji7p4LVTFq s0YBxcgXSVs/rVXQNxDOOAMVTGD35vEuVhxdsVPsEM+wLZgkrYay6sY3l9BRxcL4ZXS0 H8ce/loPHuqTkQtRaGETdpDgtr71UG+umEGabLbcBVIivYCRoj/x6rwR0vHuTqNKPgsM hdkxvk7VtHGxmMNgZgAJeKHL+TN+iEoHax3EvRAQaM0cPCruZb3x8Z1rxz/2EEbUSUsn pSQnSY6uMyUk8xLg90Syl1VXa1bdh6MhB8Kr1Zf+0y9FxSmJopD21LQsn+B0EJqUZzPZ 9yPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jkUNUusO; 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 r9-20020a635d09000000b0046f0ae1bb8fsi9585324pgb.785.2022.11.14.08.31.19; Mon, 14 Nov 2022 08:31: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=jkUNUusO; 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 S237676AbiKNQaj (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237565AbiKNQ3u (ORCPT ); Mon, 14 Nov 2022 11:29:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E8302183B for ; Mon, 14 Nov 2022 08:29:43 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443381; 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=jtDlGuAbTSSJEMWTvdI9kPHsEwopJ5BO8AfeZI8Xzok=; b=jkUNUusOa/rDiW2kEjSYqIAHPvnAj0abKXtBCPnj584XACyyvzV5ZH44XLMH/6YFLzlBpm 307DWV5o/1MAT/hEvez85x/1QquMLgESndw0eclq3j6Pl8c23CjghF1wKJNCzuacJPoWMm t4lJOQJJ4MDdacZSgV+Kwz402KPfe/3kuN+oETlDp7DOce4+lG9OxxB68naMHDidDwUy0o /L7PY47fuINkEYgNlN2EdKuwEO0KabdJjQeWzq5vzOhggaizQ3HgoY36jS9DInC4A3aOVs 6+eiz2LZey/G0NOThgwe9aQm3JzXt9RX2zSI+J8CpRa/b2S7s/HIto/+ipbQUQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443381; 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=jtDlGuAbTSSJEMWTvdI9kPHsEwopJ5BO8AfeZI8Xzok=; b=6DT15jpBvvNOo7s7TIRJhL3KxV1amiVrLZFlRKfmiI6C04XMwZ2GNcWmwUPxZgcpSlkNs7 wUeDm3Q+7LaGrqBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 17/39] printk: console_unblank: use srcu console list iterator Date: Mon, 14 Nov 2022 17:35:10 +0106 Message-Id: <20221114162932.141883-18-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489830049898432?= X-GMAIL-MSGID: =?utf-8?q?1749489830049898432?= 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 bc563972e468..7304cbcd6dd4 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 Mon Nov 14 16:29:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19892 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238226wru; Mon, 14 Nov 2022 08:31:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf5VFqUTib27peVJLHwKFjy8sgOKAp/gwgdVEjADIxBcAO0MsL4g3F1iLnENX6hqwrfEkuFN X-Received: by 2002:a17:902:c652:b0:187:4920:3a78 with SMTP id s18-20020a170902c65200b0018749203a78mr67622pls.88.1668443494044; Mon, 14 Nov 2022 08:31:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443494; cv=none; d=google.com; s=arc-20160816; b=p11578aroSDiSEiKR9OyrZaI/XVHKkpGQVc7DxiD57+g8fmjFMDxczU2q5LZeRzWxK 8KKxiVLWJ3jBLapQb831h1G0L6EwABgnBynb/+MLUZsD3BX1OeZYM8Rw3s2uoeWsk7cv j/ESq+s6NusRFadwHbKBO9Oi4wUYfedERGBwktehIfjzT3JtWaI8dJQU8Kag/PLDgzQU LYbOZaX0oDYtZ4P9zxhVvaHOxjejtPJcZ128FN48C39MA0n17ASuyieYvgJBrAEonLo7 Wo7aFaCfqYNHOobbUw1CylMxnV5iNOKJyKPpB5TtMa4diXDN0GZpdsmJX08iEtbqkBHB FsDQ== 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=EQ/FYtHGXP7iZ3ZSMRcPCs9DaQP+JVaa/N3ps9AS5hs=; b=eDxFiplFMiWC1SV+Ih2NLBb2Zc54Yj22/afhFjjfBaDUKcih2xdUIcpRqevOn08KDD 6mveLZ2akPUCLal+yyQadq7DTyoV2cILN1jOGlTiZ7Z2AfVsbThT49WxCzuA/RBrMPzx 5R3FapFgdFqXA+9tat7wjKo+ixEiDl4e9LopC8+mOsZ81bYzkAtRT0XSojPENKMZK+g2 gZPjput19x1Pf0Cdi8919fbYiHW6e10DIdFqSiFjjn0+yZezxCyKOohI25YExMn1x8HP ZW8StYTacZSVJMbg+Gj3RkbELduLQy56edKutg2UykP0VUOkvy0VRdWSGbpzU0UYeYxy 5hLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MCbYSrYZ; 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 c3-20020a170902d48300b0018890a7e9c5si11446871plg.509.2022.11.14.08.31.07; Mon, 14 Nov 2022 08:31: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=MCbYSrYZ; 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 S237623AbiKNQan (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237434AbiKNQ3u (ORCPT ); Mon, 14 Nov 2022 11:29:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70BA6220E3 for ; Mon, 14 Nov 2022 08:29:43 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443382; 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=EQ/FYtHGXP7iZ3ZSMRcPCs9DaQP+JVaa/N3ps9AS5hs=; b=MCbYSrYZGc9XGEtVr6ccRpZvWfKLFaOdeuaK62QMBUjXY+nfurYfNzu1EaGFQXD4PWSFYv yC3uItnVyTLScP+KoaZPkU3ZlvX/JdrHb/LDYnsWmxGdhmA2IYQQiuDc4Nyq8WcPkI2m+8 2977dgIpYMx/aZzyOsn5DNCt6dh5ybpZ03+YZI+oQBh0VuzrfbpbpZi1zxcvsAX+HDP2Nj QxvNsTi7ox5bS4/LrxMnDpm9XNbVkD+0mnBXAdSSV2oj9t7W+cru5ioit5vrDHcaigPeLZ s86s9DxaQDNOxjWehsNlywPhM9W1CpB6ai700ZB8BoKfu7M2pLyAuVUCupIVwg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443382; 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=EQ/FYtHGXP7iZ3ZSMRcPCs9DaQP+JVaa/N3ps9AS5hs=; b=Ll08qw3MXmbQitfwoSqB+iIxBeEp9Lp6vRijiwhXG+cyEp/aoivI+HXmJ18Yri27v1x/u+ nqBFumtsCVXWYIAA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 18/39] printk: console_flush_on_panic: use srcu console list iterator Date: Mon, 14 Nov 2022 17:35:11 +0106 Message-Id: <20221114162932.141883-19-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489805210101599?= X-GMAIL-MSGID: =?utf-8?q?1749489805210101599?= 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 7304cbcd6dd4..f536233d8234 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 Mon Nov 14 16:29:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 19894 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238457wru; Mon, 14 Nov 2022 08:31:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf5M2xDXcwTD6wBi0DY7HeE55COA+zDf6c9u/tWXJm7fb5mvWfgSb4hnlIlMJNtu0N+tieSS X-Received: by 2002:a17:90a:8004:b0:212:c384:d386 with SMTP id b4-20020a17090a800400b00212c384d386mr14332889pjn.79.1668443515518; Mon, 14 Nov 2022 08:31:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443515; cv=none; d=google.com; s=arc-20160816; b=wftW/QymPKMXnGaTzTBcLkyDdpF9BaghB0fkyShsVWCmMZes+WUIKXMKvsLkspUS8r M1EGUNZtE3hi1FdXXVU0Ahj/iatvR2jaBQY8HWsZ3K75VL8jVvjegYHJvoy+alccG05i jle5kdalFiZ2dwivNTGMtmtBAcE77Kefa/Du8CocYuekOWofyjeqsHnbnYR4p8ZHawON lPobVF1BCwaA0vBlLkGWhUUvzmT+2NW1TD2qIBXCNP6ZizsrJOp6xpcSgkKfrAqbmsAz Nvhd0O4Yl+UBT+XMYXL6F+It+UWXvcx1hvPSHvFv9UAov2NNUJI/KWo40vOXvOBNrjpR E2Ew== 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=lXMXbp7RkCm+6HR9dgXj+chNQzy16FhmR2CfzYfqcKY=; b=Sr4Rb8/irsO6atWCsVQ24xHdSmPtYmTwR59M1VXqDPvB332mTQncVbIVURAGnTDfu+ HYszHzze/Kg/i7QSk5LcM2iQS8cqAV+wwsRd1Ewk4fnX+iIOkIR15in3ikNFff5df12W qHj2UDhehk3FmweqLHpEG6fhDrh1HL7CbALvcwQFdk2G/c3AAgYsTZ1SHs1lgaq+CMDr DNwIAy1QbAgUUIaPBJtcBIu/+sBSsD7jsVYLVaS9sTTyA94eQUJJbVqmcMlIA1eeJBaw IHMbo6iEnTnENiN0qHcsCb7lX6413pxnUw8Q992hYnTl8W48atWTjFV1tbYwTQtCwGpO NsFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bbR2W4gq; dkim=neutral (no key) header.i=@linutronix.de header.b=0FQ3W38V; 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 bm18-20020a656e92000000b0047688fc8acdsi2614165pgb.474.2022.11.14.08.31.11; Mon, 14 Nov 2022 08:31:55 -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=bbR2W4gq; dkim=neutral (no key) header.i=@linutronix.de header.b=0FQ3W38V; 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 S237690AbiKNQar (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237569AbiKNQ3v (ORCPT ); Mon, 14 Nov 2022 11:29:51 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD1FC2252D for ; Mon, 14 Nov 2022 08:29:43 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443382; 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=lXMXbp7RkCm+6HR9dgXj+chNQzy16FhmR2CfzYfqcKY=; b=bbR2W4gqB1076ROKgh/MNgK01Tzv0Le3BX+Zotvf/ft2eI7wlxLJhjLW27gCrMzbsLG/gK G6r5Ad9lmV0s2P8unlytWuKvcYuADR72fClD57tKzaEOi4ndiE3ME2QYSR4JJ9wNEherg6 7tC8+dinHlxyjiWfl9whO2u8jrBXBwL6pikjf/NN3WKm/FcyiDbUCLXKoz1CWpWWPlciex Fyals1BFl9+dtKFxw0Yn3wBjC1bSlRo93qnu9ieRsXPWK+JWE8S+SlJy9Iyq8NrItyqIwB PdLhEsG4AH8UF/7XHTyr/lxgxttkKw6egNT60YIJaHsVGkarmdfNjMo+y8sF9A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443382; 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=lXMXbp7RkCm+6HR9dgXj+chNQzy16FhmR2CfzYfqcKY=; b=0FQ3W38V4gG8pEPSTtVp12zhC1wqEbepo4UKy77fjui7MHnQj6A/VCbbcUMV+WhYXnre+L x+7lL5FXwnoLC6DQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 19/39] printk: console_device: use srcu console list iterator Date: Mon, 14 Nov 2022 17:35:12 +0106 Message-Id: <20221114162932.141883-20-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489827596886112?= X-GMAIL-MSGID: =?utf-8?q?1749489827596886112?= 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 f536233d8234..fb609a19f797 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 Mon Nov 14 16:29: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: 19897 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238476wru; Mon, 14 Nov 2022 08:31:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf6J7sU2ZDsgyzwgIOvMlXvdxdMyAcQntZFJYwR99+qT0XNYWbR1d8Fzk9XV1UU6WMegu2Px X-Received: by 2002:a17:90b:3949:b0:213:d630:f4af with SMTP id oe9-20020a17090b394900b00213d630f4afmr14490651pjb.77.1668443517807; Mon, 14 Nov 2022 08:31:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443517; cv=none; d=google.com; s=arc-20160816; b=Z+An57ILqTxx+tWD6xfO3ZLQhvtmajbCTJrUzDowYJG9g4bOwPhAwFj7gB6FasutiJ rU8sJyK7LiVUNvuD2ClDnUkYNoIC4cqHkSUbkBgmauo82c0JsscQECF5JO2aiUHATDhJ HNQ3m2HW/i6W8ioBwh34r1wVWfNlNTEmLoZUBjBS/kkPE6H1CAsQNi4wrtrp5/eXVsEW z+tKLbbgEchJxc3/a+Ju8CQhOvvfUC4tajkMffgU0Ev2JyGbBjeg0eTINDbg3SbA8SwJ x2czTarEOEqp7dgQy1e1ifgLZ+oLflu6/9ruTONP8oJDkWyTs0FUEDjLPXBzOKmDar74 Ns6g== 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=wX56Rx4ehD7yCLYC+HBYrPWlmwQCTi9+gNx/cMRdAa0=; b=GEQoOMAiXandWGYttHC+/ACwWuTbbLzHOqoKppIqjTXh+/DDht4cVDxu2/1fcPCXvM DReX6vG3jHQ53n+XEoUEEfiUTr8j9JSUt5CwQxX1jlrY5RKsSwMGBvpFvOVQyqHPS/T1 5K4flXrY85yDpg+J5EsF5dsPZ9oUVs3slV77FVQfnoU1q8SLYR6WE9Io3iNhVPxMqOzC j34NA2aeB+p70FqUVAZVXbQZZ+Fqgdvn4Wi63G8qkfUkIhFmiN4gh8/J+V1GQ+jxEzuF g064KkSU+xabCSRGvI2ZUZ9twcfuZbUClxhhGnmPhmRAqiC0704iLtDUyWuAOtD6I/2P RYTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=sZwXHYkH; 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 d27-20020a631d5b000000b00434d8692854si10254972pgm.541.2022.11.14.08.31.14; Mon, 14 Nov 2022 08:31: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=sZwXHYkH; 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 S237704AbiKNQav (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237607AbiKNQaP (ORCPT ); Mon, 14 Nov 2022 11:30:15 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2092922BC4 for ; Mon, 14 Nov 2022 08:29:44 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443382; 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=wX56Rx4ehD7yCLYC+HBYrPWlmwQCTi9+gNx/cMRdAa0=; b=sZwXHYkHvPbktNSwjxUK5aj2mlUfsNem40DSF6jkIhmjnLqme07Bj37zy8BIOHUrp4R+kO z20l7qtc9/VbGba0euziTCjOck6y0KeieHFYZ16r4/5p3EUfZkyVMuYj/ZUI1Y9PQXqyKQ wwabfaBCwER2N2R8NdsQJIhHmtea3R6RtskJewsP9Sc3cDiAnrz/ibxX+tysUT3L3qoZ9a RTuLJLASQj//Ycg2JFB4X8jCBVC8rTaTv/+ou5+jjJl98bUO4W74oj0ghdFP/CzB+UUTZK sV2lPIpF5ion3n4mLc5PiZdySngafhsq9WtLsLgbX/eTUODx2a9RiD+3L4b+Pw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443382; 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=wX56Rx4ehD7yCLYC+HBYrPWlmwQCTi9+gNx/cMRdAa0=; b=YSUY3x9QKkaBKpLI3HuYgJ3L+uxIygG746+BhVG6JRy2hyD9v0E6waIFwmYOUybnOdJ3Al G7H0jZldXWqYGJBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v4 20/39] console: introduce console_is_registered() Date: Mon, 14 Nov 2022 17:35:13 +0106 Message-Id: <20221114162932.141883-21-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489830264541121?= X-GMAIL-MSGID: =?utf-8?q?1749489830264541121?= 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 fb609a19f797..e770b1ede6c9 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3414,7 +3414,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 Mon Nov 14 16:29: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: 19895 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238470wru; Mon, 14 Nov 2022 08:31:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf4dbkqomTeh4CHsygoSUZlkBYc0CIweKtnYNCPLyNIeiYukLVjYY19j356iMUSTjjb8xxGJ X-Received: by 2002:a17:902:ab07:b0:188:cfc6:8543 with SMTP id ik7-20020a170902ab0700b00188cfc68543mr64059plb.95.1668443516787; Mon, 14 Nov 2022 08:31:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443516; cv=none; d=google.com; s=arc-20160816; b=Q7wiJOC6r4H9WseGMDH32s0ldN9RRWa/f706FSZOXKsET5xOaZ0aRy+awO7FA8qgaz SBy/szmvtP6G6gQObKbrbkx6Ngsfr6SFhCOw/VIzpqPZ0WBIWaovBIlrFoHD3rQUWs4n jLl4K8g5FE4Hy4XQpWd3tUBYmUd3xDFAH3+AuuMp51n4hZ5Ft5l3v2iiXLqEWegsAgfj qVwIw0rEpEGwmS63FcxvWoslgNJD44GNWKVQPPmF+Im3xB3hnrHtuR609cqIluWKBARE BvlBbFYQUiNvphYy6lvNBeFUB02iHID107dswSFGTkYFMEKnIJN6UkkC/o7fIle48RT+ BdLw== 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=el4NsP2T5diSCN/uYnWyaULKrAhxksCch0IR1WYUDlDcczhNTGvvSN87g4ulfjopAW K9WYN0xqmPZP8eZOs8aNk8eSguWPaF7OecG+q4Nx4oNh7IWma66cfRHycTHGB9D9ogSY q9SPhWDGhhrTbDgEr0nYQLoPP/lHI/NgKe31UhWbPnU1JFAAUj07uI/Dyb0z1cAfY+w4 wOGzhfpxhLH2luoruqf9CSe2hWCzcR4n6iAt4uDqYCiBOq86kasIbffWegEHj57Tb1Pn EbU8Z6hbnosIz9IQyyMimIFkpNfejnzHEH/0qbudX9PU12zxV4MycanLy/hCWHSrZhjw A9EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bz1sBZFQ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=K28m3TtQ; 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 m16-20020a63ed50000000b0046afa55b6a5si9507115pgk.708.2022.11.14.08.31.16; Mon, 14 Nov 2022 08:31:56 -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=bz1sBZFQ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=K28m3TtQ; 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 S237675AbiKNQa5 (ORCPT + 99 others); Mon, 14 Nov 2022 11:30:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237610AbiKNQaP (ORCPT ); Mon, 14 Nov 2022 11:30:15 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A842B23174; Mon, 14 Nov 2022 08:29:44 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443383; 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=bz1sBZFQ9FlXBPXMTmtVMbJRNxqfR+mzsZ4rRAsZyfDX14X/86pQ61WXJ9xCa5X77pHzeH XMAdv3qyOC9kE/KAeG2wxvFUx0iQwF/hRVrqqWa4MGDAPzvVpIYtPiEEEd9LR5DRWjwJO4 eE8DlIljkYklMTXuFtdRXqRHXB+HmSnieQKAnKLFneeTzXuE6PqyPa0eIbk4Ke6GiYZOG1 OZcVSL6skEeLJgXgrnfHmBP/vVHJ05r7OwEAjBiT0bjBmijzVJqkB9QSBQMz3jsi7we1K6 L5kW1kn7e1gSotYXjT0OECAXNjtendtg2727NH9IJWQgI4qSHxcJRhixEvlw0w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443383; 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=K28m3TtQEWACw5E1Ri6Wqs3FBdXDACqTkbbU+SVuLq50H9NVjXzb19t1SSArfgZLQ4Uahx bC3nejFtw9CmbNAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Lukas Wunner , Geert Uytterhoeven , linux-serial@vger.kernel.org Subject: [PATCH printk v4 21/39] serial_core: replace uart_console_enabled() with uart_console_registered() Date: Mon, 14 Nov 2022 17:35:14 +0106 Message-Id: <20221114162932.141883-22-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489829120638358?= X-GMAIL-MSGID: =?utf-8?q?1749489829120638358?= 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 Mon Nov 14 16:29: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: 19899 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238536wru; Mon, 14 Nov 2022 08:32:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf40GF+ybKxj7W80thZX3EzS7lt28WV3g4M7JeEoIX8Pm0jCPrOwXq71gra+n92BHIJ685rx X-Received: by 2002:a17:902:8647:b0:17f:63a3:cb48 with SMTP id y7-20020a170902864700b0017f63a3cb48mr21692plt.123.1668443523763; Mon, 14 Nov 2022 08:32:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443523; cv=none; d=google.com; s=arc-20160816; b=gh0urKfgIwumSTKdB9EKD+d3xeW78tGl5DvwMqp0Ltka9qtTgM8yzUFVmzFukEOEXw 34yNCfgxv0aPzTf7cIMYY438Y0b1dLeV3Ve/VB530DW6ErbMvXxtoKmL1EK2pzCCdSax d84+fLsiGuW+T062Xb1Yfh2QnuUWtdJVB4SEo1UDpqwQ30wtHGHPGmFkG8bE0mcJ1xHI MTtbr7scC+zykKYam/LKPzvYGn6j04oH3px2mZtJvzeLT8v/VvVrd1W/Y2VuY1eKaXOH K5jhbp9Kd0KM65k7UVEsZmL3FYi9pH+vGjw27RvzdlfvZYfVXsRO2E4kLfw7dkl0oamS 0DuA== 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=WuCvNpqsWpwV49S5/EiT2Eu/MmVMQdF6U0k8ms+rMbY=; b=RVu9M3pV1z4jWzibDXHJkqvXYDIwyO6bDAEvQy0f1Cjc13ixc9j4LlgOH97jwx1Q9y ameT9crfCMuOJcoAMQJLfnjQ7uROo5Qm9QgDkTSG8CUlertkzzDLRn4GJC2yGBv8l4Lb +X9YEMa1kj7vWZViY25snI3aG7EET7CLuSQYejX+JnjeTySEmlMO5uw8ZxzwHnVy+j9E UIR9M9GzLuG5SuT6Mt8/xEPaoxa9SjqeqdIRZsXrYVnl8tXmezhbI4K+U33CRxv/4hcq Sxhzvz7dwbylhFU0QZd45UY3iC5IvTBlASl6q0xI2FBU8Z0b/S7jvUsEA7p2++zZ0H93 sCvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Zq0ro6+R; 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 d4-20020a631d04000000b0046fcbcb1015si10340019pgd.331.2022.11.14.08.31.26; Mon, 14 Nov 2022 08:32: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=Zq0ro6+R; 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 S237701AbiKNQbD (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237624AbiKNQaX (ORCPT ); Mon, 14 Nov 2022 11:30:23 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 131552408B for ; Mon, 14 Nov 2022 08:29:45 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443383; 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=WuCvNpqsWpwV49S5/EiT2Eu/MmVMQdF6U0k8ms+rMbY=; b=Zq0ro6+RhBlIobVqcIjZKMHr+lsqn6RTbq/4EyeR2al6yeBAOLsUfwzHagX+OpThdDIYBn VZE/aYWC5cQ2/vx6ZAu1VmP+hab3UZ2YzY8SRYMvGEpYirjn96qqYewSqaotEIlUpyiZWd IdQnf2z4Dl6VKKpJ0mR1B4RNgDMnd6gDXi2CXWK5KPeM/1YpW/I0R6dEMqeFNtiwt2WYzs uU3lC8oWM6eohQfmqBlXdguZVOt/A0f6HQHlDRgq63C98P5PZU1stTY4muku6/skYgBZDW RekqyMf3j5W+N8/ukW2hKWe3aGXXoLYUBBeQX8j4E1y6LWIhHkhGsiyOzWca+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443383; 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=WuCvNpqsWpwV49S5/EiT2Eu/MmVMQdF6U0k8ms+rMbY=; b=jh/yhRRxZqyoNHCJ+pkEaPo+hN6JlHwv8X7cSv17o/jCQ4k5FSxhxITDL1Zg48QnQj2yIj DwyFvVmfj7sDM+DA== 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 v4 22/39] tty: nfcon: use console_is_registered() Date: Mon, 14 Nov 2022 17:35:15 +0106 Message-Id: <20221114162932.141883-23-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489836279415680?= X-GMAIL-MSGID: =?utf-8?q?1749489836279415680?= 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 --- 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 Mon Nov 14 16:29: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: 19900 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238620wru; Mon, 14 Nov 2022 08:32:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf7YJWwsOrFpEcSjlEyEDvWFkaeMO+hyw3rPqZXwEr/uiuqKEpZ5cj3Lmyr4w5j+4Zm0feLX X-Received: by 2002:a05:6402:28b0:b0:458:c66a:3664 with SMTP id eg48-20020a05640228b000b00458c66a3664mr11528447edb.79.1668443535175; Mon, 14 Nov 2022 08:32:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443535; cv=none; d=google.com; s=arc-20160816; b=SdzsV8Zm0fI28rY5lWiUagQCNb+fAxBHjFqZObTeGDBMh+WDdSu31uwAKUGa9IQesp LfbkZEBxA6VudRcG0ujAj1LI49+1FMRHHXebEmDYFT8JukZSTnpw5xk28oWJsxP8asgu dq3pddybkUSI5ule0xRUCRK0DGP4D7wVaYCDbwD6SGjrj0+WD8X3RKLy1+wWGGZSxrth Xc7GS95oY0XpsXo3ApdDmkTXQtwKEJz07DUtVA23g7jkCIHqQPAg9fn4tyHKXn4Hw2gw pMrU0VY0kstzpO121FhfWz81wp0xxg1j5DB7GCoifKRAIw/Q/Vsq/NmyhnKMkqOxpJBh J/tg== 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=UMXkAgZ5OFWvc8Ew5WVsrDF/TPSZ/EMvKwD6RvNzrIW8H5lFENaH/Up/emJof0rehZ Y9vEmnkjCYO3YbWS+A3jDx6Rw4ddVyzvLPzKMDPzbShf0SYF5jva+uqO79CnRm0WAqWQ 8BCK6BYRzSybM7BCAOrrLl59z16N8XWcmZwv2DhVrqRDb35BOgllmB4N1l1LSJfpT2Eu LqMYYFVDJH6L3R43FWC00Jujor6FikLAu+CIkWO3LyatW/vplOIAg+WZfViVMdw3wjC/ ReLgIcQ2JyytGVyuCYyuiKnO/Eigks8I+r2aGu33ek1zXv6JqMFzYyvGd+U73Vi2gdTf y/kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=DHNjpiJL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=vEj+hs9E; 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 ka15-20020a170907920f00b007ae4717bf0fsi7108441ejb.158.2022.11.14.08.31.30; Mon, 14 Nov 2022 08:32: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=DHNjpiJL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=vEj+hs9E; 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 S237773AbiKNQbG (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237626AbiKNQaY (ORCPT ); Mon, 14 Nov 2022 11:30:24 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7183E1BE94; Mon, 14 Nov 2022 08:29:45 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443384; 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=DHNjpiJLfHYPeBnKTTnM+gqdzzWvIqlmYY5kVw08d8BBUu2Rc0IsZfsni/Y4eZWl6DhYSF wfzBYXjsKpfAKL1z8bCxWk+nOkF+g97HnDSOYTdg5PwUjLeTriyS/8m9ACW8zNburxIzBt 6IAHB//+/zv3X1PZY9LDWcFwelqOscIXUYxfLbCRLz9HKSwuwmWwKWP0F3Cw1jO6gDSAL2 Rr9W5F/iqapUTqry+clh3Yarx/hndpzUNg2dfuHX0wkCwWl9EauSNiJ4auh+GAxG2rN6hq zjPQq6yDqVPiz9lCq17+Wg99Ec5MGzCsaoYVW6WvfWIvCP+Hhse24ox5lQMnlA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443384; 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=vEj+hs9ErdPijVo5crxMPO+17ysamncYBpFmUafWoOgXAcwaih7nynvEsz+28Upwhxx02B htoS4IAose+ZTBBQ== 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 v4 23/39] efi: earlycon: use console_is_registered() Date: Mon, 14 Nov 2022 17:35:16 +0106 Message-Id: <20221114162932.141883-24-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489848289377168?= X-GMAIL-MSGID: =?utf-8?q?1749489848289377168?= 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 Mon Nov 14 16:29: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: 19901 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238630wru; Mon, 14 Nov 2022 08:32:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf4EhBGwyAFqwpuYvz3Jj3T166jhberiMZrHkCaRJRMdXxlnvtfLVOdeAsuS99z/bRQD7KI5 X-Received: by 2002:a17:906:a401:b0:7ad:f398:78e6 with SMTP id l1-20020a170906a40100b007adf39878e6mr10765455ejz.341.1668443535894; Mon, 14 Nov 2022 08:32:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443535; cv=none; d=google.com; s=arc-20160816; b=yaJwKo++f/v3HGSTEUl9jzm9YykvgyKWZQO1IuSPAbqiGOwePuA2qLLlLeV7JRJdDB vv0zvqWZmxjv0+RYfBRZmfwWlQl5EhNcv551zR83PYYDQ6u5K5JY50glfhbGgsWoPYq6 7oM4Z3S45Vhk7EcAObJpVCjlfxjc/i2XnTWekizyAiPNjFj7gQNamYxeZcTlXcOrM82I WX4ioFoalIyCsQA2rb9bk/LP5TK/Z4vMPwvHJ2TVABMPOtDwqa6xWk0/KaTZBbwhcT4z nFIsPFVdvSV9zvwX8apYBfUomNHpDNcbFUbOC0+/trNcLwonWvMWNAye5Kd4UBmW1twQ 49aQ== 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=OsDc2muyu7kTPTZe/FmKhTfAFL62Jy4/uChI31Ux9QBgHCjGh0pBUz0CJZo9Bp2ebA u5CY+OJW/xO1zlwLYnv04V/XNDz2a9lx9c3p+7ftAELoJfNoHy/Fbf8Hv6eWDVZ7c4ua PJzNJJClMAu5fS2SzDVg/5o3PiZ/TWoz544Fn5lfUGgzkXgc53/M2Soznsny/N0AG+nJ /IUqT2Id5PKTl2vHTXCYN7jLetgLjdYpO4hIdhsfFNm1z338DNIBS3A5uIUkOGtfvGdx lZNrggtQxJID0rAgdmIWrwx0iceOtlrqwwtSEuZoHHOQXpFR6Bg0uQ0jlBlRuMtPpsjf qiUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AqUN9haB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=mZitRJc9; 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 e17-20020a17090618f100b00780f0b45416si7589285ejf.622.2022.11.14.08.31.32; Mon, 14 Nov 2022 08:32: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=AqUN9haB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=mZitRJc9; 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 S237778AbiKNQbJ (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237632AbiKNQaZ (ORCPT ); Mon, 14 Nov 2022 11:30: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 DEC3B1F2CB for ; Mon, 14 Nov 2022 08:29:45 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443384; 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=AqUN9haBzsP/HqmGWn7LninVTZwjqkkysLnOs9sIGh9FQdeeoKz7Gzt8aR3TUbQRR01ZD0 4fbSxfS2xwqbCSk4MGPZ/h9nKiWaZCjsUIYMtNaGYmCBLCtSYOMuMh/nWAMO/VbVximvSY qhW7QXGBolQdpr6mlObUNHsK8ptW93CSvfm/UHosiEe1R7oHb4NKrx2oEcBhHONoCsUtip WtYNXCCYjG94gDQtWriUL2ugK+/1sNbhHMGID8IONHOaIp2MmkGweRmUbLmExqlun3O0/3 16w4tC2pTh/0J4jTDAOoYO6LCO0OnMhXfiIRwUwS9CBL567Glz7vkU5qaYTNSw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443384; 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=mZitRJc9FS7M35SEGDgcrp6yBIpx7ZU+LTSfluPEhBlQEioB3RYMPItGTx/ey2cplmPiur 1rbpiEy4260r+8BA== 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 v4 24/39] tty: hvc: use console_is_registered() Date: Mon, 14 Nov 2022 17:35:17 +0106 Message-Id: <20221114162932.141883-25-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489849278630001?= X-GMAIL-MSGID: =?utf-8?q?1749489849278630001?= 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 Mon Nov 14 16:29: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: 19903 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238721wru; Mon, 14 Nov 2022 08:32:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf5uGA2RRVNa7XA/xNlD49KKTo2bK3aHQ3tSN+9ow4reRcfzrWteFMRGidbiA0QhKerbOlea X-Received: by 2002:a05:6402:3719:b0:462:6ace:c522 with SMTP id ek25-20020a056402371900b004626acec522mr11526831edb.91.1668443545281; Mon, 14 Nov 2022 08:32:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443545; cv=none; d=google.com; s=arc-20160816; b=kydqL3rZcmfkZMb+alAR25ACStaQGdMc52EVGIu1JwsISSRTReC9syJimtDISrkTzO z27Ru67MK7LMDoRQ8XTJFJ+DWSrMEEDBYgSag0wAGVgaf/tG+MNOcIGEp7O9g/u8iViN OJdVkw3pyC0BzDeRLnBtKUgk0dBCkTq9UCscIK3tjspwc2pLil2o6vkt8Ug3/QLww9/5 xDI4NthK9WAcdMfs6coVs3t2YS6Lyx4GDgpMe8I/J/7kiFRwOdig3rMTXqGDo2HIwWwt +0s0MD5YBYOYdBGzH9558SS3bpN/XowhBwB0F58uiPrtVsuRZeRwss9vFdbgVIW+bUDg i71Q== 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=EqmQXjOap0cxqPTppHRxE4+BATEPUG6p6nDYUK/EBF9XjFAAX1kDRDWeaG525TRQUx 3sBBWFFlyoJuCzNHitvjNdiCV1G6JQtZXSEo8LJ5iunLMIM5KZkFuaodHEXCYLJOdRqS MXVIpgHAVI3jTn/BrVnCHtAQrh3wOBx8DE8MRABsb6gA/M2J1hQFCDJx4AL5M87Rb4IK CdZCER6ctrnKGBW2VXTUiNy1cmbop+D3Pd81i+zGP6CTXm0mGSBZmyl4AXDXpFYmqPZM jffXVukcntznxLTbpm1dQrWOrs/8dqGCinysmLqZ/QUDfX0IlwdLk0Qtg7RsBYFwvJaQ 6Qag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3A3qm8uD; 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 js6-20020a17090797c600b0073dda1430b9si9778285ejc.403.2022.11.14.08.31.45; Mon, 14 Nov 2022 08:32:25 -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=3A3qm8uD; 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 S237814AbiKNQbV (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237633AbiKNQaZ (ORCPT ); Mon, 14 Nov 2022 11:30:25 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 462A3248DA; Mon, 14 Nov 2022 08:29:46 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443385; 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=3A3qm8uDKxldk2T+hFZX4oojBNblkduXllzMasj4W0ht7c2/3fqnH3zNEGNyz7UDm86I4R t9xNaY7SebfdzeMGbytN95G8jY2ce/0FUqYYjWsk9XkYvi0nWdcZqHayxg0mH0TEdFDQM4 wcluFDiKhfi2ejqyWTs4wTolKa2I3oGyg5K0MdUThrH4GzDkdygFjO3jy0bdDbtootI8Tp RraaolWi+bzN9nt6VpvWHUx+FDJczUk5x/EllO8pyEK37fhDFX8v1L3/vnC/0HqNpDH01l T5t20yuqcBRRSb3YbAfmH68OtB10CA4Es9BqH7O+2scnn3tvpqr8PLQ3kXlYzg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443385; 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=6SYcyGF1KYOUi2rQepMLbRowh0PZ02xDI4iFmHmOD+BhQAJdnS81gt5fyN4spMhZcaCS2/ rPEVeTTT6MB5zXDQ== 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 v4 25/39] tty: serial: earlycon: use console_is_registered() Date: Mon, 14 Nov 2022 17:35:18 +0106 Message-Id: <20221114162932.141883-26-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489859036047638?= X-GMAIL-MSGID: =?utf-8?q?1749489859036047638?= 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 Mon Nov 14 16:29: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: 19902 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238716wru; Mon, 14 Nov 2022 08:32:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf4msqVmAVUC0akK3k18MHFPdtTg9nGlt8i05xvunJY68+oQNrqj12GH5Zda9gtLGQTT/bmR X-Received: by 2002:a05:6402:538b:b0:461:abcc:328 with SMTP id ew11-20020a056402538b00b00461abcc0328mr11489939edb.318.1668443544969; Mon, 14 Nov 2022 08:32:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443544; cv=none; d=google.com; s=arc-20160816; b=vRWW15ddvXNDvZThYpv9kOGZ/SAyKc/49ZhoK9SyeMVXUTllDh/DfhAf2kMUnu4ZGE WM2gPaBoUvLMyNFyXD0wTmzREM2PVcm4H7qOWa4DXch8P0xp8yWfrPJ7mEt9Zh+WPqEQ 85Yo+/ASjj6Si6OAWNCERP0zuBYSVMC5jwwmRt1xrKR5/RCRFDRJbSP9+kNQkbIH5Q7y eQ4QZQsWKEtfI35ER1i6Hu4UMeO9tETgPdW45jHNW0xdty1sL+dO7TXVYnY5lc5VB4yq JUgvGqUHvCKp4k+EcahRfsDTeNqLG6g/NOGHCqT6Q4UwgP5qOz8ofaunwsiIKOC9n7mS PpDw== 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=jnT6J/Pj/qB54KZ/XwAxSmfSgWVvOfswObKcw/SyihbBrDVMvI7y760zRYhve9gUM+ VmFBRels5+6jUpoHLvXKM6crMUETJmRXnz4l1pm4+4tPNvXSlw6RWLxIbAHyR/edzetP JWRbpsfFtntkSfSZzkXGQ809hHlSoBqLUFjQLbte4ORvOjBBp9nWjVUUOOi6yXMf6mL5 9wWMD9+hZNf4zApy2rCu8nzN5F9jRlTQfXhwxw9xayqdF1S9rztIoqa4iiQEWBfW3Sao dNDlUqCzBrQEZBCIhu/qm3uwK9+ZHpVm6+hHoyNKGnxuUB7kWpzztHq9DBHuX8Bb1nyA sbjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="w5/sljKy"; dkim=neutral (no key) header.i=@linutronix.de header.b=wrDaBfnb; 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 br13-20020a170906d14d00b00780ec98afafsi7797404ejb.113.2022.11.14.08.31.43; Mon, 14 Nov 2022 08:32: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="w5/sljKy"; dkim=neutral (no key) header.i=@linutronix.de header.b=wrDaBfnb; 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 S237809AbiKNQbT (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237638AbiKNQaZ (ORCPT ); Mon, 14 Nov 2022 11:30:25 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B478226B; Mon, 14 Nov 2022 08:29:46 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443385; 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=w5/sljKyRtYkYJ1pMsxCYitTfJqtg6hNm6DfbHlCejsKkYAZvv1BDeo2va2iPvHtHKY5GX 0QaQavGsGMSD5blng+gKYq21uvVtKZw2zPhZvqxyxRDJR9a707NB1m2hdWm3F4USO3vC4d 2EVxtxHwBZuHtcIbY2HbPS0vbifvVpvbFh1AVLwgxqfb+5y0jj5/1gxsCj6CdNjV49qDM4 pVE5HnqZaeSvfbO6I5CkNrC92ArX5yHTFNPjOdbnhfKRgWRKkU3VAgDsg27qGFh5C+DJMY TJd+VZwciYr6yRrdjrpLXr86o8Gf9ui6s1I2FV7oIGvdPbvhA6Y1HXMS1mHGUQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443385; 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=wrDaBfnbdboxfSNqcK6NaH0l13NpOC/oqBFbDUHa9fhFMUBr4n0tN+svo6C1O0xwng8UUc wRZJdRMznoJCYcBg== 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 v4 26/39] tty: serial: pic32_uart: use console_is_registered() Date: Mon, 14 Nov 2022 17:35:19 +0106 Message-Id: <20221114162932.141883-27-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489858485950454?= X-GMAIL-MSGID: =?utf-8?q?1749489858485950454?= 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 Mon Nov 14 16:29: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: 19898 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238533wru; Mon, 14 Nov 2022 08:32:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf5+y8en5HgdWnb4fK1p/gtAsBUAydTfxn8ZcGJJKrKbUtXeXUmYJ78QkOg9T7zJY0gffl9M X-Received: by 2002:a17:906:339b:b0:78d:3862:4488 with SMTP id v27-20020a170906339b00b0078d38624488mr10307032eja.683.1668443522634; Mon, 14 Nov 2022 08:32:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443522; cv=none; d=google.com; s=arc-20160816; b=txUA+uOrmyUabm8UsfHj/BYWtKchB47tWexQ4xzY/wnkEF45pn8v4szwOOQOkM9xL+ BLGXf4/XljAbCH1BhGgx67susRh8TiA/Xi8Ayz2X14cq5AZA4IgjHSwM6ZW84zHT11yW tKiJyWELFI6bZZdcE4KYCYaoT4ptUtBqz1UDHMr0amyMgZd+u3T9MpvoW2hVQ/Ien+ft pdm5sSpiC2lFq1cHy7WiwmgWtDXTbT2Veq8zZoI64gu1hY10Z2LzURJufzA85N+adfLd yqEe0P4u5q7jFr1Z6Pt+XlPNzZIHctnrwA58sJQFIGUIfLaBTFO6q3RlkmW0oXF2wjKN JgYQ== 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=nbT5X3K3M1aoRDkZvMOtYZXlxXMlLSqc8Hp5XCYzckf7p0x1S4kKdkPCAk7hXVH5UR Bq0ZuZ9DMI1U8KBMhIrpiEv4JRRiUE5todg+sIAWtnlkTLGO2lQRH7b+AfZoEGAmtF8O 8AIYlxcWgm8faH/cmpqyhLKjrHtDIvDMJIjSUgR6b3ecGsiZciaXtKi5cpUYpH/kCDgi SWY8QJJByokFqhd4RfU351Xtg2lRgjgAVpmeJS7wFFuAuSyLy5m2hr8UmRjTjSaTuWam VHldubGnEAlwAsbhj0f8IFia/SnhjI53cDQ19CYXdQPpxYbxbHaXGc2EAwHFyTyrcfWK 1vQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="KI/u265x"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=S0O+bhg0; 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 hc17-20020a170907169100b007ae2dfe020bsi8593995ejc.783.2022.11.14.08.31.36; Mon, 14 Nov 2022 08:32:02 -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="KI/u265x"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=S0O+bhg0; 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 S237790AbiKNQbN (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237644AbiKNQa1 (ORCPT ); Mon, 14 Nov 2022 11:30:27 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 523B324F20; Mon, 14 Nov 2022 08:29:47 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443386; 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=KI/u265xmuLvr6nYRPE12M3LB74Oi9WZ9jjTmAaeaK+kKHpWrekJ8vWFzHf8TWNRA0tj3K xZTn/aUl6CkW7pwtzCHatJsXylMWpalDLTMwCTnZhBOXIveLBQplRtGpmjv+tBfcwfhNoG ypxEP5xN+krsbBrXUI9JfA3HvwfuSoSHQSSbQres2w59iXY02+XbXgPS9d1lT1AKxZsIDh Bh2lxvysNdC0JNEIgBC7CwfCGYolKRWk622Hfg2MIcrWg+A5GAQ8e6JssnHgv+tXS5kx7P u/gQBgdqhhP6s3rI50iH1/wIbm9/5SozuNvdKxYsvJXZnT/VVYKtYpwDnudbkQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443386; 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=S0O+bhg0ej26IlK6PIB9ok+JZdFnLZxpszF0zbQlv9EtIB/DxIisAa9QKXrNrypAhUhALr xGuslOOEe/kHTdAw== 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 v4 27/39] tty: serial: samsung_tty: use console_is_registered() Date: Mon, 14 Nov 2022 17:35:20 +0106 Message-Id: <20221114162932.141883-28-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489835342920910?= X-GMAIL-MSGID: =?utf-8?q?1749489835342920910?= 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 Mon Nov 14 16:29: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: 19905 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2239247wru; Mon, 14 Nov 2022 08:33:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf6cXv28eG3BlATm2N/HWzw4un2jlZe+KBwGk98cYhzqBVsmIboj4bI2FjNkKnwo6ILRXXkw X-Received: by 2002:aa7:c9cd:0:b0:458:dd63:e339 with SMTP id i13-20020aa7c9cd000000b00458dd63e339mr11301686edt.81.1668443601560; Mon, 14 Nov 2022 08:33:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443601; cv=none; d=google.com; s=arc-20160816; b=GxTC0JKcKstWxpBVjo4MvXvt2lYD2WPgp+DinRTt2Op4Rh7yLL25Qjl0+FnV9TqQ83 NhhIMGMx/OXRdy8XjuX5Lm2IC4SzW9JHuCjv7AGaAGw7JYIq0DHv5JU8AWjXowZUhknN 1mrPI5bfAw/FgGdTfpHVQWOjDkBY9UGHB6T2CRIco7UbcnJT2msRQ+amVvEicdQCxEb0 7GHP5SM9faVhGicGdjP5d7P03KQpCMrhsgrSjIqJ7tFuxPVkinwv7VCUkqjWqMpsh/F9 WjgdPykzhC5FiaiS5IBeO740wPCEeu/8r4mZR1Lm33ghxLfZ8/PHNroQVUvEEL+3o3gR 1y2g== 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=TfaZgwVXCTA9bCbWXFgIYcilhlXu0/LjfwIP5LQXs8gz/seHmbxhwD0311MjXK/OmR Ll4t44y/XfVA0FsYn+e7kCXFh0gj+DtAbZ76yPyYF7HnBeQpdF8oei0Kvq3h483TiRY9 PSnviI1UMkKvvJ+r2HndRzMfmcS8hl7oRvm2nhUNgVGdhk6ZZ23NUPCfFgEfX4GbEBuT 1XlA76Eo88ktV/F58xAtprdndK856uik4aviIR00YHYiPMZhxd2sR3ZkqNduDRX8Ir64 2Y9fe0Zn+rdjrdkATgSg8mu6FQLqBoMlQGuBqnG7XLf3ip2OTYczRdCx6KH8IQJNduoX SIOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ik2gD9BO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Uoe89GI1; 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 h11-20020a05640250cb00b0046786a5845bsi7048093edb.567.2022.11.14.08.32.22; Mon, 14 Nov 2022 08:33: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=ik2gD9BO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Uoe89GI1; 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 S237820AbiKNQbZ (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237654AbiKNQa2 (ORCPT ); Mon, 14 Nov 2022 11:30:28 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43E5B2EF25; Mon, 14 Nov 2022 08:29:47 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443386; 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=ik2gD9BOKao46XxC6TCnhhimQDLLmozLcpFqx8TKS2W9AAAd4RnuCQ2bbQ0lycjPzLklxr bcWWY0yPWfLHpyeO9hFwAENCRqzfQKAEh5roFS4NyO/1agfgHbS3OYDOgKPGCxeprV7uIO zkkDNu7gLoREFiNWcd4hDuLclqz7y5wl/T7tXeXDPZ3Kcn9jDx7zTPSxIsjapD+aBZ3/BI nrxxvjLJ6qavZNgJvDUf7bzbc2RQgImUqfCo9hEv7r9gdbrfk1y9g5Q8AVnEraLBLW0xjL Jt+H43JfgrbRSOf9agUO1nr1C/4UZTwTnBO79gwlqQ0c9FOywltgef+g6i6v2w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443386; 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=Uoe89GI1hDDdlGtS8mprP9W4jqx12PfBaIfPlDAV+vJIME0qk0i3PB8PwGQom6PfluumiG h1bZyaC86Q6Jd/CQ== 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 v4 28/39] tty: serial: xilinx_uartps: use console_is_registered() Date: Mon, 14 Nov 2022 17:35:21 +0106 Message-Id: <20221114162932.141883-29-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489917876144236?= X-GMAIL-MSGID: =?utf-8?q?1749489917876144236?= 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 Mon Nov 14 16:29: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: 19904 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2238735wru; Mon, 14 Nov 2022 08:32:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf6gioFzqmxeOccitCCmVhSsBUD4GcKKbO9V32Dhhcb3aBeKI9QdsXo3svjIDPBYNKNrBqcC X-Received: by 2002:a05:6402:12c2:b0:467:74b2:e17c with SMTP id k2-20020a05640212c200b0046774b2e17cmr10300456edx.344.1668443546988; Mon, 14 Nov 2022 08:32:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443546; cv=none; d=google.com; s=arc-20160816; b=kH2//cm2yBP5IaQII8HmbBNga+KjX0MlSC/FsW6GDOyUIo8LBx68o2u3QINJDFxkRw sbbL6DeDNzu4TCYvQc0jm8M9l0v+yCzl9N0LuYM/9Fp6U/Kc9lhSQrjxrcUGVKchnchW I3t8C61K97/AtvBDIJXvRMWc/KAgx27agxN/+WwwaNNVfsujLq9XXiRl1J8buypPLtrn i6UgmihXZ5Uq0GdKHh9E6htAPC4QjQ4u09nFfdY4c1rxN0gm89LK7qchs0j+SudlCuaG IKhWaLpUB0KGLz1M63kWi4e2Q4+D9tAy4NlfQm0VkRrWzmX+D43tFM+9SdrNTDkNqC5+ 9Ddw== 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=ihos3kVL43GcNnwvRQa8EAkart8aw0DgSI6lBkWbDJU=; b=hIGZ90uFjuLuqOt79/kp9EKvIy8qC4ke5mgRicotv6vOGB56ULbaXGMYuWBEPIAbyw D+gQWnQHXX3zuL7l8CbU3PuQBiCTlRTPZ737GRKHNMPZN4JMd04i21xOQa4GhNFfrCAd TadXmMxG/JLhhCr6lkCZ90gXHDBPEXxMe9ZQNFJs4ZDMFurpMKyFMSoe2LzlTYXwsVJi X2qNPmZ3dfkaMS2ayvcSOHLRjRtKhlkRuJly315s0fCYc0NmEYw32dgRONUtpvus4bu6 k5+r59eh4neLxSqgNL25Bhth5GHPvb7/jxzavAoREFCARGj/G95CZqWty9PdQw/1xFMj lVMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=gDRDGEIl; 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 go20-20020a1709070d9400b00783d5a873dcsi10327442ejc.341.2022.11.14.08.31.38; Mon, 14 Nov 2022 08:32: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=gDRDGEIl; 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 S237805AbiKNQbP (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237653AbiKNQa2 (ORCPT ); Mon, 14 Nov 2022 11:30:28 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 570182EF32; Mon, 14 Nov 2022 08:29:48 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443386; 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=ihos3kVL43GcNnwvRQa8EAkart8aw0DgSI6lBkWbDJU=; b=gDRDGEIlmAFx9jHad/WBpJk7dYEPGJDAe4Rk61bOKfOqT3mehUsQKb4keYsUMPSPsdPCH3 rh/IqkNd2kP12Z7ZZJ5Q6UpQi26MMcGDyn79l+kAgPljp3n+P/nE9gbcQHMels/aOZlf04 gvzaSIAO9Ov+RLj7wqaNb3eSDwxjPoyfs8flmUMma2qp4bWhG3+4S0HLB1HhV1AKJYSgCa szkb1zz0UHIRDO1rxOcXWYYeZyPGsEQDX3qRaTEnhRfn5nCLnkBEw1zRJUXCVuYN2De9ix pXy9j1e90b+yrfTItl3IJ3+fhxo/dA8V2eV6JZTU15Mr0n7Yj/pazIX44e1v5Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443386; 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=ihos3kVL43GcNnwvRQa8EAkart8aw0DgSI6lBkWbDJU=; b=qEGMwJgLtL6+f1KskwLCVPpGRA/Rkj8qPXYJz8mOscQn36t/rcF9+WsdQUG6lPJ/3gDIvG HaEcIL6ZNzGiLpDg== 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 v4 29/39] usb: early: xhci-dbc: use console_is_registered() Date: Mon, 14 Nov 2022 17:35:22 +0106 Message-Id: <20221114162932.141883-30-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489860836523170?= X-GMAIL-MSGID: =?utf-8?q?1749489860836523170?= 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 --- 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 Mon Nov 14 16:29: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: 19906 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2239271wru; Mon, 14 Nov 2022 08:33:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf7honBWdx31GmX1Y6oQwMJg88ESwyBeSnnSsWr+If4QMf2WvFTCSI7Lns/0w3FB4VIL2Cak X-Received: by 2002:a05:6402:1c85:b0:458:c339:4229 with SMTP id cy5-20020a0564021c8500b00458c3394229mr11642248edb.393.1668443603479; Mon, 14 Nov 2022 08:33:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443603; cv=none; d=google.com; s=arc-20160816; b=Ol5c53zbV344NeWkmHCRSx4ZpGIw1iwc8+Dh5nbawlYaG03zzQW6L6Tjq6V3XxFuoY KIAWKQkO0WaW9uyQY8uPTk7/eTOlYl4ntpCAWj/Bf0XX3SxnTFJWhpDCX5jerRmILYFH dc3fC3ExAfnknMt4VU5Au3wM4BjM3NntY+iyGhw2G1ubAwJX6uZkQD/Eiv4LTaorwaMW +z6yiD6LysnUuvDFvODGZQSV9OwPeoxXNOaFWu36+j4IRPM5d4PAzutnWDHZoAPrPaWO vhuSg6fWYXvnk+Adxh4obf0HijUO23q13x6pZFShtfpFMz7LOhb9n1VLBAKxT5/pRfZt NGbQ== 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=aZ5a5EQBj9nFALvEC01Cy7wZMEQ+YkOwGhv6npvhXY3r9BJEFmPTfw8SRyTODu3Mp9 pQu2IWVcdntjOrcL+zWZT+jmGTC/1AHwfoamZ7DqWMFhnXKgv65p/o63dR2/COC4SL4K EhPFMp8C5p7Ss3RGAaJzQlsAdcpKLHz54hcERNz7dWfrTRMkHmaA138cy6ap7NjmsNHc m+qhLwt6TcDey0QTOH3crAN5PA5VOWWYxwiud/Y/sHeGf2acCWrq5adzQCYGE61/grEW TcutjMluDS56kdH4RGaPcYggdx8k5gd147n51CoKkyjiLfqcTtNoJXHYYpIwxo/4fea1 GRTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=X2nZGlkZ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=SFxIRrs0; 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 h11-20020a05640250cb00b0046786a5845bsi7048110edb.567.2022.11.14.08.32.24; Mon, 14 Nov 2022 08:33: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=X2nZGlkZ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=SFxIRrs0; 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 S237825AbiKNQb2 (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237514AbiKNQaj (ORCPT ); Mon, 14 Nov 2022 11:30:39 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF76E2F005; Mon, 14 Nov 2022 08:29:48 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443387; 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=X2nZGlkZy8hrJxqmrFFecZCY+sQ9NUXkXt8yfVeEWVFTGthvoBAQzN5rmoP9KRNRE26w6t 9jiGJ1ON9wOdxumNo2q4ufzjYgzft3cZ0D0RQkq9tPmX5pe6xsYCWGCOwzghY2mWo0kPYB oVSq7hxOHpu9l2KcQnZhtQtSALKert3M5ENv9iyJIqM2g1ktbreAXhapRtNREBK59pA2uj plcXLIJFnoTYhySXS7zM/JuqN/YBOCCj3k1AZWEV6G6GOQJlt+bnurtPc1+/wa25Yz3NSh kUkrtnGJqdGdswSmI4u7aJZBoFIQT8mguQykB4cv+OGSYjdAtiJU0xWgg5JZpQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443387; 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=SFxIRrs0xCYkhUmANHStJ9PFRlamUrMYkDFOxLwsJ2Z1crrn2VCOnDK+DynOQDDQKTIYsj JUoobDFz1L4cWEBA== 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 v4 30/39] netconsole: avoid CON_ENABLED misuse to track registration Date: Mon, 14 Nov 2022 17:35:23 +0106 Message-Id: <20221114162932.141883-31-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489919976948844?= X-GMAIL-MSGID: =?utf-8?q?1749489919976948844?= 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 Mon Nov 14 16:29: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: 19910 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2239981wru; Mon, 14 Nov 2022 08:34:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf66mcwpFSvaTiTMtIq8/M5U1ca9OUuOrEMMS9ngHn7pADNbtjnehRTiFBu2i4evtsAPB/n5 X-Received: by 2002:a17:906:b41:b0:7a8:fd1a:c073 with SMTP id v1-20020a1709060b4100b007a8fd1ac073mr10887149ejg.4.1668443687475; Mon, 14 Nov 2022 08:34:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443687; cv=none; d=google.com; s=arc-20160816; b=gmOhUCV1/BdPcCLY1oELKzMmn/VM7THYM+nqvMvnRDy8qjsbzys9OyVKhNPrFTxXya egMy0DuXGIOKTGjpPk2pTbrAIlHwfpPCpJew4Xk3Le+Lnn/jJ1Aug4FHoJAnLSJ3a+BK 4HKaa40eRfahvkmVVqu6svrQ3Hj87MZT5zl/QAbbEYa71Yvluk4aw/ZytbUfHB2OqcFY Igfqx5hrXK/nZsi11EG+wnL0mmd9Ii+e5tDXITmIrqL6m5BkZ/CCtFKhlAU1gYQeqYZ5 2Fbg414UjMzL+c6ug5juhtyVeXFWOYfUTQRi0ss4E3y0VpluoTN+ky/TGEOhub/+EB3Q ep6g== 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=YDZaOSQfmA3ieeMvolr63sTSZIZ73N1pM1Ndsn4fuIc=; b=jGqyuAl1v8L8rQeM4vxHV67PzWbmSyvthELUx7pAis6PPdpjt7V4WzEkd7NDyD8Gi8 o+WJSmiirRAQDgY+pJ83F0NPC/8BqXR/G/+z/BOKIj4FQlz4ImOQ0x1w+wBi+hF4ivlS qWpy4VQ5dy/+kzyvN2Hwk5PFC1l1BzBRbgkeUDaTib4MN4ab2mWKbW6RQi67mZezDSlm XHjRuLbeqSV76gQH2VtnF27NpcW068TXICgTjxEYFkVq3ZG0rwRPC7mQkys+Bnze6KB5 eDMVKKMJoxkCK7lGQY+nJ+6zJPZaLaNEdBZNM3Kt9ATUzdTu2eGKAkB84YKpZtCxFBA8 QBCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dHJbmvzV; 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 hq6-20020a1709073f0600b007ade82b9e73si10688189ejc.757.2022.11.14.08.34.02; Mon, 14 Nov 2022 08:34:47 -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=dHJbmvzV; 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 S237852AbiKNQbl (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237681AbiKNQan (ORCPT ); Mon, 14 Nov 2022 11:30:43 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 807072F00D; Mon, 14 Nov 2022 08:29:49 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443388; 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=YDZaOSQfmA3ieeMvolr63sTSZIZ73N1pM1Ndsn4fuIc=; b=dHJbmvzVtPyJ1YbuVbBDgnUwEWvzqfIWX/lYG3qITzjamvKx/92bfjhlfedBeaYSYuS0Im yWcAO3B1E6yEYpBKXY9DAqh4w5MYqQrald2Xy8tyYfE/SWY/9Pvqj2aYR/nTRZ4xqgUBJ4 BwCpqphpuUcJjpFKWBWJpAAsCmVqnnVRJpZYuE/Az366y1W/WIAjXssnej2lMOy1SyXLtK DM78o+xXRSp+HpMDkEX9thcmyIq6GKVHX30uRk/xLxCIlajhvzUnN56off+bh1t6+vg+px 7Yo7D50qtqLgc8JemIqSf3cnkCD6XVy7fq+9oTDXpUzuxQp03SrFF7tZlHpSNw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443388; 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=YDZaOSQfmA3ieeMvolr63sTSZIZ73N1pM1Ndsn4fuIc=; b=Klw6CO0+RzlaQaF/TUs5OEp+YJFNKlnTXcnXdz4EGApnJTMd02z6VogUxfhBmPoyrSLS/L mpQPoXYjSbHQ65Dg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Helge Deller , Greg Kroah-Hartman , Javier Martinez Canillas , Thomas Zimmermann , Juergen Gross , Boris Ostrovsky , Tom Rix , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH printk v4 31/39] printk, xen: fbfront: create/use safe function for forcing preferred Date: Mon, 14 Nov 2022 17:35:24 +0106 Message-Id: <20221114162932.141883-32-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749490008518178507?= X-GMAIL-MSGID: =?utf-8?q?1749490008518178507?= 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 e770b1ede6c9..dff76c1cef80 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 @@ -3461,6 +3462,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_behind_rcu(&con->node, console_list.first); +} +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 Mon Nov 14 16:29: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: 19907 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2239288wru; Mon, 14 Nov 2022 08:33:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf54YWOu554hoQuH5vxs1aTAwrjhUM2J/rFby4hUNc1FN7aSIqEXpmNsmoqiqQGueUP/JQFs X-Received: by 2002:a17:906:348a:b0:78d:85fe:4946 with SMTP id g10-20020a170906348a00b0078d85fe4946mr11600587ejb.268.1668443605023; Mon, 14 Nov 2022 08:33:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443605; cv=none; d=google.com; s=arc-20160816; b=iUMs7+PPbOA4iS/G/4oabfy9qK07SJH+B++BdhGjoq2sLxiyjzZjwObke2Lc2yROOh gj0jjRWvFniVYLzsalj/RUH4NffbjzY5wlKdKLMrLm5IexxO0vV4cZbCFF5VbBO6+CIj 4AeVwbj/+k51jBLyzYClA+ttxTMeDftG8YL9ZdQFU0W/X7VrjufbcNQglEL5Ys2qw8il 8T1Q4VDIuSLTT+lAEO/UDyWn5Se9RmbayFsIWT7lZqCfQ+Yk8X2JEEc6EgZPojiMV+Sw JuM6E6riDmhYeJD+yHZA+pn9brpKuTgwLpE8S3XLboAtDgJ6tPqKBLafk7h3vceINfDQ AIiA== 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=jp0NQ9F6tyZq6knRIIGgMw2ViV8KxhEYrQesrg4ewuV2tFX53gMGXu73n1g+2n3xdu 21O+4krW5zlNrAro2hAQrFiIRznpMbOuhV3lxqzSybiW4fEMRRqLpjOTbUp6f/2FhBKV QBQZ+N9m8EeQzOq7vGP2jnKp+TeV6kOOYTmG1FoA+mzfWA12vsEbJswpVzsyc6HQgsvI 39HENfYK4LDPCbJ/klCYvziJNvz5eVcty8nz+xg6IfJOyIDftNHfyjEiMVeDrsYwYifp TWKZsJogp1z7knkJwhabJx+wPXWnuV/kE15NhYnqtrir3ttQnQrVnKPFuHSisvZp9elI WTZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=e4RGxHKa; 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 c6-20020a50d646000000b00461f5bb2b79si6506884edj.458.2022.11.14.08.32.24; Mon, 14 Nov 2022 08:33:25 -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=e4RGxHKa; 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 S237830AbiKNQbc (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237685AbiKNQan (ORCPT ); Mon, 14 Nov 2022 11:30:43 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 108D32F013 for ; Mon, 14 Nov 2022 08:29:49 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443388; 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=e4RGxHKaV+A6csE32Npmc1LaNjJO+yGnaJgyxNw2Ydb3n/MlFfdp82k5IGopNh9rhkPYDc uw5hpPJdQ9ylYsQ9smrb/4vApeL9YZXdK5GIKLZKXolbEeKOusV0baI8MatuMHZXt/Zdl7 vRLvig/O1OpP2pw0iChfCqh7HN9Zm/S155mIsokKbczREbnhitaxZY+66E1BHVfkMmbCHq rTno7pXQLb2kcRRDNrWP2OwmNRLYWATgHQ3tNRdCoJKvWl1JiKCXVDEOwu64fTcFNkRdA2 SeNwU1lAURpblTJJrxMfJRupptlyB9Qwcss3zfW1BRc6/a9btE8XWyYHzQTjIw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443388; 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=E+rT8J6y62Ltbv82PAwVnzioIzj4vZKL8ItN+HqqGjerV11bIFE3QSoLN6mLQ97U8z8pGq sAn83Tyri7FWyCAA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH printk v4 32/39] tty: tty_io: use console_list_lock for list synchronization Date: Mon, 14 Nov 2022 17:35:25 +0106 Message-Id: <20221114162932.141883-33-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489921806972166?= X-GMAIL-MSGID: =?utf-8?q?1749489921806972166?= 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 Mon Nov 14 16:29: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: 19908 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2239465wru; Mon, 14 Nov 2022 08:33:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf6flsA83FMaY4cnLCQabfyl7WgyupGGN7B7+D0aZTJrlb9EL95w8CVIiFFwmFS3upR3o+Sg X-Received: by 2002:a17:906:3551:b0:7ae:43f5:a2a3 with SMTP id s17-20020a170906355100b007ae43f5a2a3mr10425488eja.595.1668443621324; Mon, 14 Nov 2022 08:33:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443621; cv=none; d=google.com; s=arc-20160816; b=Eug2fRFMAolhUR1dMEUe8mpU/XcMVxrIptYFreLcNsUcKucAw3fS1IWnGrPhH9e4gL NCtOz4+MdNTSaINWlzKZKJ5ze5Otc3/WwPAen3tQsaedMDHih1Mbtgdp9qjZmZP+PWAF rvO0yqaaHb+lVeegVBYGAhuTXvq1phWs98G7jTCz4VCn8GwBwC22X5r8z1Z2HpzUbdWD rlHRpF48zCkXP9J9zroqhZHlOUvrsfPyE8qI8kUTqNNU9dawXWoEgjFGP537tg/f+cUf ZU3e9YhGoJGaNxT2SpIoXQ/SUGxVQ71WWUp4q7Ajt1ejViJyXithONG7GEDFQVpHHneg lOlw== 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=S2ean/TesJg8Mgf4DSaewBL9JZCmCttlh2q55l1NnYMjqyc+eOk5DniPtsTH9E59yg xR341mGO1a9YZlhgCIMCs68CMu8SXe3qfFHNrv/XUu2J5jjbKXQukTVSvXj28eGM6KE0 bm187jd4jNXMF+i46Ac/oo2WPgiVMaV4Wdewxc8YOCJGZTx7kx2l2Mde+ZUMJRI6IAex gzKGzRWMolkQoeyQac69wTFk5iRr944OvZe17S8td4M8ye5SOgwxooY7FTBP1iYwphP6 xuKasOvHbsyH1x2VjZqrGXx7ct7giBslPLsEKfaSviMBPEcz4DbFCteZ6lAD+Kxl+uBZ Dcig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mfXS5Cw3; 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 d13-20020a50cd4d000000b0045f802c0b98si8382231edj.443.2022.11.14.08.32.28; Mon, 14 Nov 2022 08:33: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=mfXS5Cw3; 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 S237717AbiKNQbf (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237694AbiKNQau (ORCPT ); Mon, 14 Nov 2022 11:30:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A80E2F01D; Mon, 14 Nov 2022 08:29:50 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443388; 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=mfXS5Cw3dKtbQJm9mn+jcg8yDvbnLClYULmacns+jvjhLW6rZek5GuH88Ux2VGAzSEiGM+ 22pWQ8qF/fPePKGvvi1k6uu4aDqJWXFK1WWBjtv0tmYOVBDYEAs/ROS4JLOyUa1YgTJSBS FFFAIJonz5AKb777jVgTUWJqIPr38s89l4QvRMZ07iCVdI/jvx0YXISW0ty7Kco/C2TABd qo4nWg+wlTKPATLOpOb3qPPDigJsPiZzdmOHVzXM+cn7TZM8nhVmW2F9ayfwK/EOgNftaP j5HxMDyy54fs41BQhQzBQDCOEqhxBVcysteCb/v9FgrJKxSVFyAApdCPeSkvZw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443388; 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=YF4kcTgIBdDPE43HzqRI7H6KMWjfmgcTt3tzko7kkdkywT7MIrIQCbxb+24VrZ/T8f2Pt3 dfouT9kVORt4Q/Dg== 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 v4 33/39] proc: consoles: use console_list_lock for list iteration Date: Mon, 14 Nov 2022 17:35:26 +0106 Message-Id: <20221114162932.141883-34-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749489938447453235?= X-GMAIL-MSGID: =?utf-8?q?1749489938447453235?= 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 Mon Nov 14 16:29: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: 19909 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2239979wru; Mon, 14 Nov 2022 08:34:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf6zvwpGSndoimTDUQ3dNbrwsFYJrGmarIpVZW/768ykx/Qa1pvkWCrBBg5RcMi7NY1AYbnv X-Received: by 2002:a17:906:1458:b0:7ae:d8f:893c with SMTP id q24-20020a170906145800b007ae0d8f893cmr10533598ejc.359.1668443687322; Mon, 14 Nov 2022 08:34:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443687; cv=none; d=google.com; s=arc-20160816; b=ISX5cXBItH9pPzc5RAdTqoF6RL+m0JUbFj3vf3sNEyKOP8a61H3/Bw5RZd75cLyxC7 eDtJd/FcINHFRA369dEzrSKy4CRDHhbkGZMeLVHYtkMPjQsrGGxVVu7f6Z1zDiofe9Be igOokb4OfREBYJXByxeqDNRwff+G+CqwN63YRlqbEwDHRD50HG1emSChTj0YBlNHEK04 1vxuXzZWeghzRDff3wzNrPTXhc+JpA8DAaKonVhI5i8DPVDJVBj0iUHTJiATcg6vCP72 UkZNnDwprBp2NlZQ8k4g4GlLImzEpl6FJEvC471iO8mzw+tHaagmDkyWniThhiy5iKah tUOA== 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=2wDn6g+8UuBdFK6wWrlxzslZkfyRUaJ6YAvy13J2JzM=; b=OhbG2tcFtcttqOm8oJreo0HtRjYL6uWQbHgavqXeWMIxo9H1z7i49BW5twusnYsDMR Ts0EuHSiJdt2rpgLeLkDKb+ftxYKPAn1AbMmSTZGa33+t1XjV+hCD2MksaH0nkqUX789 OUIdcY8ejLwBea+ZXLdpopM2gaI0DldgiO9HzAfb7QINQS/yWSnmBc4/X3HeQ3rrQxod ExwgipMDU2v8oo2aO1N42fBjPpAxgB1sHWK0resyagwY2wFiZa0/QxI4AP6Hrvh19qXj ePs8z1JIsRJgZb+K9F5QD8OEPKU2YiFAZM4pPFM/TjFwT25j84Iw56JxwM4yyowesi5n WPUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BImf087f; 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 v14-20020a170906b00e00b0078dec48d442si7275030ejy.680.2022.11.14.08.34.02; Mon, 14 Nov 2022 08:34:47 -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=BImf087f; 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 S237722AbiKNQbh (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237700AbiKNQau (ORCPT ); Mon, 14 Nov 2022 11:30:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECB652F031; Mon, 14 Nov 2022 08:29:50 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443389; 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=2wDn6g+8UuBdFK6wWrlxzslZkfyRUaJ6YAvy13J2JzM=; b=BImf087f9JnZ88MWf7ANkPfWPNC7L78l8GKfPWaZ1afRJ+A+JBuMrpM8D1Ka321WprAnA3 EGloFZFKdW72lAGMkaKfGh8DjWcnX/CaE/PiSwUMI6Ev+J+j0YujoKIAviukaNA6BNfXG6 vZQKB3mcJni3b4fbuzwdnXl0zvRf10T9m37lJxrHpv2cksUNBagpZ2TxbYiXBkkwN8uGFR QmO4TI8BuMPRs08ILB69SI8eB5ifJwO3XFa/Na0Ps0ULOqzEpXNv/aY2+GJpk5tnowTx8g lQWj2mP+9P3cjsdwI04CGBTnOSDytJN+t4szjXImS/5DCyylCW1RsCBuFWAI7g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443389; 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=2wDn6g+8UuBdFK6wWrlxzslZkfyRUaJ6YAvy13J2JzM=; b=1WUe4EQRUuyC882lbN52LVmxM2UtRXMjNbX4zkjqflQk4DO03Am6ce06RfjNxTxnINegur l44TkJN3V9duhpDA== 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 v4 34/39] tty: serial: kgdboc: use srcu console list iterator Date: Mon, 14 Nov 2022 17:35:27 +0106 Message-Id: <20221114162932.141883-35-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749490007958629693?= X-GMAIL-MSGID: =?utf-8?q?1749490007958629693?= 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 --- 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 Mon Nov 14 16:29: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: 19912 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2240957wru; Mon, 14 Nov 2022 08:36:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf4SQxBtM7zrfk0Si+QE1gW6DGya8jgwpBFNpGSk/uGYRrxtAfJxeIJh36RlswEWOA0DfPtH X-Received: by 2002:aa7:c04b:0:b0:464:6206:62bb with SMTP id k11-20020aa7c04b000000b00464620662bbmr12179459edo.337.1668443805077; Mon, 14 Nov 2022 08:36:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443805; cv=none; d=google.com; s=arc-20160816; b=lOdPBNgTG+MR+Lfn4JNJBB1AukeaaOhj8HyhNHbEtMhn5QzRHEQpT3v8WZCahx6jqv +VcAGLcpQysuITRiRksx/9C9OdvQKwU2pDusobCA42pPLa6448jM1InOCguW0QVPuf2z A2vO1hkdZ4pu3IEGztt1N/zWBB2tHQYD6/rDxFBqu44al5iA0lrsvxEWQi2DhnLbOZa7 6Ne5+ViBRQzdMQ2W6O8qD5RrdDp8efIMBTB9FsOPWqxAXZEsnJkCSdBNFlIiSa4e6MWm wG3F6bAcEktaK1ahm4kYVXMY/dYYXILjjgsmw6DwnbegyQnOOCH6JjlTCOzBlWfVygTR U9yw== 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=4PxzIkDOo+u2ZWn4WKSm9Hq+Fp48aeu4iQFbr0MeDXE=; b=SOTdSycx+08o8SUCZVLDrYfmer6NPivYVjmIUMP9deZPeU5Ayg63DiyfEkoLKkYIWl ytnvSbb7rXB0u/WjcRjcDIXcfFa0hj7bFw0Cv+m8x+SPHM19d0ndFytW8xzChOboShcJ ZdD1XlcpNMIM96dLkHJw9xsGlURTUfgdGeeD8dEqjy8AKfAaOea6lje8R+KwSmnmpNxX eltlnGmj2Jv4rhcbV2CPfTVADqhZonYkLR7nD659nxJBRqsTacUG3Nvbaa1+zhB68eQI S+hfvULcJLVPGig6pN1JBiHdx+wJWcwrFlEo1T5puJsiSLb7XizshL2tIjjtbqD18J65 78uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1BKrXov9; 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 gs10-20020a1709072d0a00b007a1b49ca799si9303437ejc.385.2022.11.14.08.36.03; Mon, 14 Nov 2022 08:36:45 -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=1BKrXov9; 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 S237862AbiKNQbq (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237708AbiKNQaw (ORCPT ); Mon, 14 Nov 2022 11:30: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 46FD02F393; Mon, 14 Nov 2022 08:29:51 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443389; 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=4PxzIkDOo+u2ZWn4WKSm9Hq+Fp48aeu4iQFbr0MeDXE=; b=1BKrXov9UpGW8i3q7hfrAts/TS9f1RYajAbeVEXEGrtL7vaFgC21p2/gycHpZdggcRdkMR ymAXLo3nI1XznOcfkM8o5VPA4u6dK12AQ9M+D9N/Y7xJ/VWzIzjgdzIM7jZdzTrLeTEgVf ldvYptvRObxoWgQM1mjVO0U5z0p5nGCAs7EtMbBk3dTvPNu5ImyjgmMlyxInldZZtJmK2A 1C5vFloKr8VFUqWXDe8yM2OiOhAi0RIy9lNx/vMF7VcWmlEYi+lu43zGfF6mavA+0ue7WX HCOKbjnE3m0/2oipWF8vmACY9N8pHiiQtSahib4N206+Wa9R/AOzX9tdp8cgXw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443389; 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=4PxzIkDOo+u2ZWn4WKSm9Hq+Fp48aeu4iQFbr0MeDXE=; b=YJxFMEQT+jRTL58bXGade43+HEy6xareEPmdNqBiX7GialR4nAAc3bII7mmuoQPHmtUymm dWTycSv7+nBOStCQ== 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 v4 35/39] tty: serial: kgdboc: use console_list_lock for list traversal Date: Mon, 14 Nov 2022 17:35:28 +0106 Message-Id: <20221114162932.141883-36-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749490131062072739?= X-GMAIL-MSGID: =?utf-8?q?1749490131062072739?= 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 --- 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 Mon Nov 14 16:29: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: 19911 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2240521wru; Mon, 14 Nov 2022 08:35:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf6w4YgtRXnib39i8GmddkvFOfdp/JgTSKJ1PV9tgw4BlBiTdtrR5t+4kfHEwi8zGO/o4vHI X-Received: by 2002:a17:906:698:b0:7a7:1d4f:c7d9 with SMTP id u24-20020a170906069800b007a71d4fc7d9mr10784043ejb.402.1668443749868; Mon, 14 Nov 2022 08:35:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443749; cv=none; d=google.com; s=arc-20160816; b=znxRhIHOUfQBuF4WkXxG2WQKistfYT7ygz/EwzhbemXJN/EgV7s0vCBvgHZRoWKwXo vjEgz9g80q2cP5EWwZFHDAa5Pg67pGJnqTRv1DoPoplwvs35cEa2T0fn0TPl5OCcqGhl RmkZdFmPEbZ9j09ZS3jr99r7fvbocl4dynPUywx2IM2Y3mkTGuMeYLgoWVCxmMAzA5j+ mSlnALy0P9ynpS+hpJAqcKBmQvZXsxUn8kdZl+UXjNzJQQf9WS6egN3r7WT7enpdKrNL I4BRbbCYCV1Zhmdr1xAtQuiWUxAxKMHA0XZz8L8klGChfB8NlRP23pE0x+Ctj9zWlRsm ltBg== 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=aTnE6XmtKAaiYAQz1R0edYBv8lQMbM429cbBgqTHQDyi9/XTlYpVRAaPbfe5PLVIFN N+uXWIB/PLIVCJakd17koky1aCELz9y2zkTRTO5oPIb/txLwZVlnpwZnvAIhI0WNDlT+ J/XzNlinhcGpb+DNkq5Een1PPCN629f4s49zyegpLofMH7vE7ievgf19RtFIF7US1zDb Xm/rNPx/wknKxxr/Uy9ZquQidYtjz+rhyW8FOW8xuEU61XCPmbSe+VI9z5aumYiApNzj I5V5XYOt1Z4alKD78gBDAXFSKS7GrWLty2euzslnuY9coc+zmEHzLvCOudQTRrloQbnd fDGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yLTA3smR; 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 bq13-20020a056402214d00b0045bfaaab6d1si7926797edb.48.2022.11.14.08.35.02; Mon, 14 Nov 2022 08:35:49 -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=yLTA3smR; 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 S237857AbiKNQbo (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237709AbiKNQaw (ORCPT ); Mon, 14 Nov 2022 11:30:52 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8F412F3A0; Mon, 14 Nov 2022 08:29:51 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443390; 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=yLTA3smRSwZAzo0WodrUiCw7R5e475OFiwy+MWrPjH2XP7ogPwQVMS/zXU+LhKNp3eKpXA KGtD1o1+JZmtwdaVIy0gg29vMf6kvK9rm2vrsZyonpaDUUTb5Sp/mH9T0OWeMIm1fw0CNZ yVxqCP1JkAW2TE0usGB3mIL6COdrOyYk7TGKh3uCK6ZEoKV1rsr8JN2AswuXWtLRch8B/g h9RBqzV3HRHCpEuRiQzw7NorZv1XRz1MTdoruSZvLqfVBLUkSQNCGeokFeJYuRRdnl1ChN gpVIJdkzBvjKIPQNYUsMfwB2OouUp3eQQlkvIZcwWD6vHw7JrG+3vaFv+Ovqvg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443390; 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=cu2GY0TtUc+v5tINvlKDlxbO+i9OxziAYNewzqmSMu9L8Im8ozqk0RzFdYXxlRic6fMIZq zx1LlYZGgEzZ0FCA== 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 v4 36/39] tty: serial: kgdboc: synchronize tty_find_polling_driver() and register_console() Date: Mon, 14 Nov 2022 17:35:29 +0106 Message-Id: <20221114162932.141883-37-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749490073285356111?= X-GMAIL-MSGID: =?utf-8?q?1749490073285356111?= 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 --- 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 Mon Nov 14 16:29: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: 19913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2241857wru; Mon, 14 Nov 2022 08:38:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Vm+aViVlbYr+e7g3t6LWGp1uaM0IqMtJTChgh7m6pc8j8UJVbDQRFSit/OHq6NiyxA8ty X-Received: by 2002:a17:906:2888:b0:78d:4b9f:c32 with SMTP id o8-20020a170906288800b0078d4b9f0c32mr10076914ejd.499.1668443921809; Mon, 14 Nov 2022 08:38:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443921; cv=none; d=google.com; s=arc-20160816; b=vu9mr9ZwnfU2UK9ZWAaNA/6HZs/vfWBKeEwJNKBqLt07s/7+7odpHgxCk050XCrbhe NpKaNDYGHoTpLs7q9jLdZbtgRSncwB9nI3+SvAKCnSfOPIsVxfs5Lh6Drqz1/FISzhwA Qw9SFbpkbFZYkSQ7V8oxPQJS5ABDZqlVccXsbH8+Z1dN63RSWEWiZP2ZjuwnDcFfEoJt V5aWDu4UzUwX/B3BIgGCJpBt4gCvXZIrX4udXzgXLFNJfT2li4ExEvdx8xDNz3mB1A6g xDjCDlJa0ReQ9G6d0U1Di2yr+JxIWDvCILRkwW0h7hL1dnyWwv2p47Z0Cvbt4K32rTOf SlbQ== 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=JOkvrhbt4At3+KGKt3iXGDkaWWXyub8ioYY3kksA+KNQvYAuGzCMGYF71+QxOJMlOY 9ugqWK/X51K7Lchxk8CAhwT4+Ood3rH8tV6dCc63xWUCdoPBfwYdXrfFpyuyZ7EhHkVM uTMvJ5eonyHvqhoquCTrbcHU1k+leWEleiooHWv54n7n5RylcfpD9CD1Tp+wuHe8HwQC Lp86ODcdISFyvIlIn8pWuLpm5mi/lc8nxEDrEDoeAKIsK3mQlHswdN8hUK4TeH+YFLIf lmmiYond0nEntXcrOH/4It+5kcKBOwhgOatMhiDUIoAMcFDR0slwm23s/0vNfuVIVSt5 8sTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=DacyzsBc; 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 y73-20020a50bb4f000000b0045d4f99616dsi9474981ede.456.2022.11.14.08.37.54; Mon, 14 Nov 2022 08:38: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=DacyzsBc; 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 S237872AbiKNQby (ORCPT + 99 others); Mon, 14 Nov 2022 11:31:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237715AbiKNQaw (ORCPT ); Mon, 14 Nov 2022 11:30: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 80A682F3B0; Mon, 14 Nov 2022 08:29:52 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443391; 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=DacyzsBcp752j0f06x6Q5nIQ3Y5gHBQvOHj6L2Z1z+kRtb13uwnRXYW37qeBlA7kgq5U5n OaG76pGwOCwmTLoNnu/ZsGzwldP/gJxxLG3s06WbdxVYr9g1JXPqk0nThtOkMIKl8nD9ZC J5NDzg7I6YeBPhNNt11xV2oCLyep6w6l3sQDsNbw86SZHUUGw3Z7L59dKKhdvveul7RcQw gTAN2eDqhT8DvmFpCl3VGyA+CLcij+AIKpEnvnW1Y2ot2Pkpr7hjHH5KLAm7Due/1vwzjr AB7lVHWHuwghLHNLPcTikzz1Xbjg9af9IqHrb2u8wSXUTwh+qQgOKXTfbaCX7Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443391; 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=5U/0tNMtf/1+xSx/qQ15ry4JRyEwzML/OTxzN7u46NDdwk8a6TlIBlnh67P6RTs4qrLo08 vYO+POSL/MrszBCw== 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 v4 37/39] tty: serial: kgdboc: use console_list_lock to trap exit Date: Mon, 14 Nov 2022 17:35:30 +0106 Message-Id: <20221114162932.141883-38-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749490253518676245?= X-GMAIL-MSGID: =?utf-8?q?1749490253518676245?= 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 Mon Nov 14 16:29: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: 19914 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2241867wru; Mon, 14 Nov 2022 08:38:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf6IwawNozUvoNgT7/4mlCEjttyC4IhBTjD4FDzunfnQRDtdhmADlvUbRSw4dOnypr1ADXtw X-Received: by 2002:aa7:cd13:0:b0:45d:2a5:2db8 with SMTP id b19-20020aa7cd13000000b0045d02a52db8mr11730326edw.105.1668443922615; Mon, 14 Nov 2022 08:38:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443922; cv=none; d=google.com; s=arc-20160816; b=VhpeABbXpeoJqHa7Dxcg7RVgccTEMnzzQWmRSnlMrWBoJ4YvOVur8JD5B3LTJZPj6M aYJ6CvdMYwuUA6uKzfn+DfRIzmngWl3QsYGsouAIa3albbOZXtEIlTA+atkG+ck62y0h K5yalFEaQVm4n7pGttCjUKMD/wmeBMJxrLe7Bb7Ca+3QNLrXPJBDT85/bJjtRed693PS uk8lqfdWOZIoAx5/Wiiam9rR2xu0021RT5O+UOU8dvbyHXEbJorw/JvxmLWrGVjx9lgj JFs6qjkdnfPWbK07PoKmzvHiRJbwovdAYdenZWVJqLHRikBsoo41d+5w90rqO22qEjN9 qH8Q== 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=e8qnAfFTCJMXSmY0z9NbV6BFCys+Bgcrek19V+DaSP4=; b=gehV3kJp9Kc/UTximU+bd7hVK8nzO2C1Wz8sVPMRtlxddeD2XPgkigldyfGNnDVp8I UbVs+7EZ/Qvy8Uy6+NSVCF3Jd0knVzHrZNsRW03BX1NLsVtUfmphX2J13B7iK7zVXT3P zECv4taEhfQMrRUDKMISQAUCF7W11LeqNhNI7eir4sKkqFzKgVlym3i7ccnC8kqdtrcm UQ2WovOaXIO7bWDdPVXtan7qhEBDd4lhfGDfOnJ29LCFbtMQ/nhHd7TIagnSxa6NRJ60 598yGusKGmZzG44lpAmwPkcpa2m1Xsd0Z8I/QYL99R3BQp2to8wnKwdgoipg0+L34EA3 e6/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SVbG4PEK; 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 ht10-20020a170907608a00b0078e19e971b2si6519902ejc.915.2022.11.14.08.37.56; Mon, 14 Nov 2022 08:38: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=SVbG4PEK; 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 S237636AbiKNQcW (ORCPT + 99 others); Mon, 14 Nov 2022 11:32:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237724AbiKNQaw (ORCPT ); Mon, 14 Nov 2022 11:30: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 D96BC2F642 for ; Mon, 14 Nov 2022 08:29:52 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443391; 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=e8qnAfFTCJMXSmY0z9NbV6BFCys+Bgcrek19V+DaSP4=; b=SVbG4PEKxAfH1E92FMTtE9BRZSIjc27GBLM2VkhgVtSRrzxNzR+aTM/aj0phkPxO7Rt/yY kzAjig+wcjxC+AmDMHmPxDPYPwbNT0XvqlmF0++7F/c916y6Kn0O2jIJRkPfECvyhWECev dI9lj/FxcerEjNO07uBv8QSAMRStiDR9Qe5s1SER/kk11wr288ZPxVpA1vz5NZ+sGiiDcz nIp+xNOvK2zsK2ktiJuieYIiR+MhHHECfpwq8TRAoEomSR/OcP2tyhZq1cgIFpqzEA9JcG rZM7q7LrQX8UssNG4FpuEmHQoCSerkvbQ+PDbtTKhrk49rS/OiaS+n0A/092sA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443391; 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=e8qnAfFTCJMXSmY0z9NbV6BFCys+Bgcrek19V+DaSP4=; b=IdXS+nHY6Hxx42ohYDYs3dMXShPYMab1+9r7Y2/TXhfUnf3OSGQ3URpdqRepwgEn7592sy qruYH2a1Ng+xJyBA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v4 38/39] printk: relieve console_lock of list synchronization duties Date: Mon, 14 Nov 2022 17:35:31 +0106 Message-Id: <20221114162932.141883-39-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749490254661768419?= X-GMAIL-MSGID: =?utf-8?q?1749490254661768419?= 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 | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index dff76c1cef80..8d635467882f 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); } @@ -3334,6 +3330,11 @@ void register_console(struct console *newcon) * boot console that is the furthest behind. */ if (bootcon_registered && !keep_bootcon) { + /* + * Hold the console_lock to guarantee safe access to + * console->seq. + */ + console_lock(); for_each_console(con) { if ((con->flags & CON_BOOT) && (con->flags & CON_ENABLED) && @@ -3341,6 +3342,7 @@ void register_console(struct console *newcon) newcon->seq = con->seq; } } + console_unlock(); } } @@ -3348,7 +3350,6 @@ void register_console(struct console *newcon) * Put this console in the list - keep the * preferred driver at the head of the list. */ - console_lock(); if (hlist_empty(&console_list)) { /* Ensure CON_CONSDEV is always set for the head. */ newcon->flags |= CON_CONSDEV; @@ -3362,7 +3363,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 @@ -3410,15 +3410,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); @@ -3434,8 +3430,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 Mon Nov 14 16:29: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: 19915 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2241885wru; Mon, 14 Nov 2022 08:38:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf4AZDBVejvai25BJ8TykhthQaI4b83Hz6ZGe/IE2nMF8HJFKO6cxpYRteZfF0f4x+UmAQwP X-Received: by 2002:a05:6402:b32:b0:461:a130:ea3c with SMTP id bo18-20020a0564020b3200b00461a130ea3cmr11402000edb.272.1668443925127; Mon, 14 Nov 2022 08:38:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443925; cv=none; d=google.com; s=arc-20160816; b=bh+FEPxA6WZsZE0CVS1eCvDRKVPBEAmQQw7IYazaWx6sKskYEzLZRrwIHhLtqYFyno k01fqNNIxPOY23oj8AWM0/NNbE60EO+kSYtbqK03mZ4yGOlPbFNHoBZwxFcH6+CYYLbH Z1/YxAOKEMUMh+ziWJFVz/ScHcX5Y5SCzTXe7eGl1p/xNIpM0aiCkcTuecb/iqqlS7EE nOx0+L/YxF8b//FSsOoDtvqpUpmjmQrD5ROaCrTr7f+GHAwOVay8zXtUUuiTfjPN3U2l 14ltvj1kjFKhzh4PlNxcImdi8BZjrjgDo/mtbyQpjD2yF8toVlIb9ktYhWWibclRm7BR RGiQ== 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=lyFJ0F0+PfcRjhKzuNkMUBeWMaE9PNLLtfp/JWoaB8Q=; b=Sj2tUx4JY731ta7VqpoxIbQNX5lO170aPuK9krRB/Sr4LUxxQjz2hU9IMkR/B9V/1t 2oHwxe/o8IKV76XqjdNa39Dk2xnXU9k66W+7C35KE7rfMK9NMfv3re2mPvgQSgCqDF8f 3/oeLVfEc/dEsY60zUS6/l/FxJobrsPPIapNwjg0y8XLKXSBH/sYRiZfC9bAUMokpMNm yIQA74sdi8qDTxGT0yDaVhmA0m/DCmW5p/3VUuz3ODDlQ/foMdDFJA4z1WK4wOdb1WrH juHZi5yTIMBqImiwxzEPyjN4+zHXsZuoXrrwEt2uvJDwFJCCNBKZtyBV3f+If0vV1X8s rGiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=o493Ws7O; 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 nd30-20020a170907629e00b0078da99ecbdbsi3017228ejc.673.2022.11.14.08.37.59; Mon, 14 Nov 2022 08:38:45 -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=o493Ws7O; 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 S237727AbiKNQc0 (ORCPT + 99 others); Mon, 14 Nov 2022 11:32:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237643AbiKNQaz (ORCPT ); Mon, 14 Nov 2022 11:30:55 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBF6B2F64D; Mon, 14 Nov 2022 08:29:53 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443392; 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=lyFJ0F0+PfcRjhKzuNkMUBeWMaE9PNLLtfp/JWoaB8Q=; b=o493Ws7OLoNBwC3oJekHe/zqr8d4O1r2boZdC330Lx7sXR/IS+LlFMlQSjiYgilqi2WvYy bK6oiaWKOaMF+Ov1zkmR7m17gutu6TqbBnx+DW+0CKcPwn/WP4WoTvHeOnxG3Dcpw50L0F uCuMhIdKv8bxHZuMIY7yE5xqI87CzHeE17gRcNmlIyNpc4AunL7RVRWKjhFqzm99845QTr GU9GdrUeraNW+PFqq9HeRlvM+uQT2Bk7lgRw4l2QqcvqrMlmgfyI3VLCm+SlLEyaEy08XS 9IYpB54UDdp25QGOFuwjoXwpDVZUiUqepmIgjw9G5zSxprsVTUdFu7iZnYfhNw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443392; 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=lyFJ0F0+PfcRjhKzuNkMUBeWMaE9PNLLtfp/JWoaB8Q=; b=3yUj92YNamRVgcCdfRvOJqzWFRVhH0VyAxXFN/+0roEsIDgaS8xom/DI+PxiHFB0NAZLYl geAOjgKKccPDeLAw== 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, Linux-sh list , Linux-Renesas , Geert Uytterhoeven Subject: [PATCH printk v4 39/39] tty: serial: sh-sci: use setup() callback for early console Date: Mon, 14 Nov 2022 17:35:32 +0106 Message-Id: <20221114162932.141883-40-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-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?1749490257401432447?= X-GMAIL-MSGID: =?utf-8?q?1749490257401432447?= 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;