Message ID | 20221116162152.193147-36-john.ogness@linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp233828wru; Wed, 16 Nov 2022 08:26:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf5WvBB5LS3rHklHhe09aFZf7yiymh8P7R+hpGlw9UmIh8+LzxD/da55wjSIBQQ1HJXObpES X-Received: by 2002:a62:6342:0:b0:55a:d8f6:c65 with SMTP id x63-20020a626342000000b0055ad8f60c65mr23872119pfb.32.1668615996984; Wed, 16 Nov 2022 08:26:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668615996; cv=none; d=google.com; s=arc-20160816; b=eHBo8hFX0VjcArx6mgAcq2gur3nerDfhgOZsg3PvQ9TGmDgz1wXwObYpNqUxn9oLrd yrmU8nQvckNgH5Yl93YzaTPzKNYupeESGgRe+NL4lL2gIIC6lCoNh/MCelMDMQDOVO2m hbpwigpPTgmOtibSDvRDkQ/FYbWwU7DH+nMC1/+fntQPxL/8s4xYJAgVxlUDevybAjhU V3+AEi8TDle3NEchr9VzUS0KaL/06+tpHJa0KAEGwc45L1joG4Vu8unyfpmg0wZnF3XQ DfeR8RVC6eefdG83toX+qo8AqwJ23fgKou8fPfwgIBFTiPiXzebUSu59YnO03d8wC0xi rOZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=XOHwuBaQ1W+3awwG2RAkUq8lXTwRKxgLO4vJVGnxlV8=; b=Q38s19SAUod7FG5/3PA/dmhpQJ/bpkigIdgfTchnE2Vxdr3od6JtPyBos+8k5L+F1F EYsIZtRz11AqX/RDQUeIU1+owMdzuRFjMZ+30MZqk1QqgT9mBu5lsljSyc4kZnt4cKYP x6N1MOfkecu0q2JagRtuQuy5diSwC2NvAKyfQjSDkF0O5VswHaDq3gFNUcW/LmOh7oNo 151HIMXNf5Goxr/Snv5HzHv+l9xpOcMQ3NEDkuv4FMTQiFO9pkCiTQ7pMsAy3C93BvYx Yp5eAjEn37+Pb56sEAdHLt+Hzx76smSz6hNK3LQJXiUqDzhrw+BV5siEau5F/NCEGvaX XuKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zwABEZ9m; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a190-20020a6390c7000000b0046b043d221csi15577902pge.55.2022.11.16.08.26.23; Wed, 16 Nov 2022 08:26:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zwABEZ9m; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238982AbiKPQZy (ORCPT <rfc822;just.gull.subs@gmail.com> + 99 others); Wed, 16 Nov 2022 11:25:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238085AbiKPQXE (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 16 Nov 2022 11:23:04 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAD3958BE3; Wed, 16 Nov 2022 08:22:15 -0800 (PST) From: John Ogness <john.ogness@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XOHwuBaQ1W+3awwG2RAkUq8lXTwRKxgLO4vJVGnxlV8=; b=zwABEZ9mxonAyBNUeWB10LZTBQNhVUWXnM4uJOtaQ2YyZadMZ5Bi3atLrrsSkVEU/BnViB xAZVnMRA2dR8k2nO0aVndbNd46Y1KfXjZxNnIMCd0MWCLq21gTPYXnDQlH47HazQ4NDvNt wmcJ6p2S4E6O3pkDLBoS7eyHnNAg3KsSCoQvLEKQjz/CSbQe3nu6Pon8WzaivpF79mr26K BAILjyp28M6MufGbgldEQGXoQwcNvfSuPpzdX/UBg8mB6SWPRgUX+uX2ZRJIGeOWZIQXpE 2Z/4P+skN/oruOza9baWAElWHHWGDsIWdsfXNjTGDHR5DZfUdF7y4XpQqQEB6w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XOHwuBaQ1W+3awwG2RAkUq8lXTwRKxgLO4vJVGnxlV8=; b=s9R0LFz1ZdiHDzIlIEwfz6Uf9mV1b7pU/Ru3/LSGYsFj+6aDJGhMs03+ARyz6ujFNcaXLF WcI0pM16uwfwndDg== To: Petr Mladek <pmladek@suse.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org>, Steven Rostedt <rostedt@goodmis.org>, Thomas Gleixner <tglx@linutronix.de>, linux-kernel@vger.kernel.org, Jason Wessel <jason.wessel@windriver.com>, Daniel Thompson <daniel.thompson@linaro.org>, Douglas Anderson <dianders@chromium.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jiri Slaby <jirislaby@kernel.org>, kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk v5 35/40] tty: serial: kgdboc: use srcu console list iterator Date: Wed, 16 Nov 2022 17:27:47 +0106 Message-Id: <20221116162152.193147-36-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670688107216118?= X-GMAIL-MSGID: =?utf-8?q?1749670688107216118?= |
Series |
reduce console_lock scope
|
|
Commit Message
John Ogness
Nov. 16, 2022, 4:21 p.m. UTC
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 <john.ogness@linutronix.de> Reviewed-by: Petr Mladek <pmladek@suse.com> --- drivers/tty/serial/kgdboc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
Comments
Hi, On Wed, Nov 16, 2022 at 8:22 AM John Ogness <john.ogness@linutronix.de> wrote: > > 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 <john.ogness@linutronix.de> > Reviewed-by: Petr Mladek <pmladek@suse.com> > --- > 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; Is there truly any guarantee that "con" will be NULL if for_each_console_srcu() finishes naturally (AKA without a "break" being executed)? It looks as if currently this will be true but nothing in the comments of for_each_console_srcu() nor hlist_for_each_entry_srcu() (which it calls) guarantees this, right? It would be nice if that was documented, but I guess it's not a huge deal. Also: wasn't there just some big issue about people using loop iteration variables after the loop finished? https://lwn.net/Articles/885941/ Ah, I guess that's a slightly different problem and probably not relevant here. So it seems like this is fine. Reviewed-by: Douglas Anderson <dianders@chromium.org>
Hi Doug, On 2022-11-16, Doug Anderson <dianders@chromium.org> wrote: >> @@ -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; > > Is there truly any guarantee that "con" will be NULL if > for_each_console_srcu() finishes naturally (AKA without a "break" > being executed)? Right now it is true because @con becoming NULL is the exit criteria for the loop. > It looks as if currently this will be true but nothing in the comments > of for_each_console_srcu() nor hlist_for_each_entry_srcu() (which it > calls) guarantees this, right? It would be nice if that was > documented, but I guess it's not a huge deal. Yes, if it is frowned upon that the iterator is used outside the loop, it would be nice if the for_each macros explicitly provided some hints in their documentation. > Also: wasn't there just some big issue about people using loop > iteration variables after the loop finished? > > https://lwn.net/Articles/885941/ Thanks for referencing that article! Indeed if the macros are changed so that the iterator is defined in the loop, then code like this will break. But I would expect that making such macro changes will also require updating the call sites to avoid unused variables outside the loops. And then this code could receive the appropriate fixup. I feel like if I add extra code to guarantee a NULL without relying on the macro implementation, I'll get more resistance due to unnecessarily adding code and variables. But I may be wrong. > Reviewed-by: Douglas Anderson <dianders@chromium.org> Thanks. John
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");