Message ID | 20221107141638.3790965-37-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 l7csp2079355wru; Mon, 7 Nov 2022 06:22:09 -0800 (PST) X-Google-Smtp-Source: AMsMyM5BJ1Q5ODBLoc4SrWxZZXx/XUZZ5h1QpBN+q3lKGseL1FjQyR4CxQMioEtpjdV+MG/Wqqia X-Received: by 2002:a17:906:e44:b0:7ae:62b:3088 with SMTP id q4-20020a1709060e4400b007ae062b3088mr28592465eji.28.1667830929723; Mon, 07 Nov 2022 06:22:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830929; cv=none; d=google.com; s=arc-20160816; b=qLHNjmAOybPp6bol1IFRoIbsGQvBSpAZElasWN/+W6flANrjSyIQka0FPBD8e2M+hs Qn8OUle4yK1VGQGQfS7JyMha08sqiepV+eSLpEX6/oBQ/CULWw6X5fVzHx5jqNxGPQiW TLeSYrb78z0Nj/y+UgOB1meeHuAyCPxEFLMXAowFWA7WYPKtAZAYfDkyvsNpNkuSKpMy UFju4ru3TmsZjCmrqix5M4tJGj5QVRV3j/POyBEmewR1/9nwXE11qz0lLCl5GQRy+Udn UmZpbxZXqJXQ036s/rLoSeYw+LcByBTVXv3wbx3B7ZdbVm6sYRfzXeRTamrBAwPNaX+j JSDg== 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=SVseywoielHQsdgFj4SQ2wUZa0m9RxiqWqQHkSQjPis=; b=MzQ18CbWCTXFhWm04SkwyZ25tmQRyL0RsW4C4LxROfa8i1Flz4FQwbWss+ocApwhUr tyY0+6+9h0bU3/hCo4xOChMA3K67aY3SKEq5HOBeKis0/80I7/P5yCrJj0uMn3hwTwnh xHug286JeqJMUA14dgTPTgvy3cPiDlmeSuTffkzqY/SkgRvIDpmGwqCrN1iZyJ045lvL W2NpAQ49LMtycCprUUUWZLwEVsMsA7w0MmXm9csrgXFrnEQ5bZG+wpRNJsxlOVxmZN8I pNngQUUKVVSa4Nx6vyYj2/kuDVqFjqn9H00i4fDuwj8WQexUeGrBFdzumGeNIDQ3r0vy KN3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=gqAyq8wc; 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 ca2-20020a170906a3c200b0078d3b940ec5si7395695ejb.373.2022.11.07.06.21.44; Mon, 07 Nov 2022 06:22:09 -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=gqAyq8wc; 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 S232446AbiKGOTT (ORCPT <rfc822;hjfbswb@gmail.com> + 99 others); Mon, 7 Nov 2022 09:19:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232158AbiKGORk (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 7 Nov 2022 09:17: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 5AA621D33E; Mon, 7 Nov 2022 06:16:58 -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=1667830617; 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=SVseywoielHQsdgFj4SQ2wUZa0m9RxiqWqQHkSQjPis=; b=gqAyq8wc/xmtR7iqeOG6HKRPQNaHenvleIBzDQ/LW3mKRO51oeZo94GS/qRNuT8ieSU0xm 67Ezdbpop5bIKLaW4vynak6kv+RutOCMz7GJmsmWvJ7ztSxvOPnfZsII/sczgr4+zwlbH0 bvBpYYScUM3+IVnwUhj0PRvYRquDb0k9dX6d4FiyUu64Q/sTrT/pd/vzPWoMAYhgg2rfNa 2MwuVE4oyZ5XOUiJrMrXKb8HCarltDgby4NEQN13ZduKMvpyiMLdZaTIIaHReLQ4CPsOXo WmDQpN1gWbLYKOD9QXS7ZKEJtYAVyIu5cwJ/0yLtFFfv2+ZH5482Fb2f8IS7XA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830617; 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=SVseywoielHQsdgFj4SQ2wUZa0m9RxiqWqQHkSQjPis=; b=Z547tJz8CL/7ne/rUO0T2mCvQYl5X73Ya4ph+/4nhh6mLeSrOtoKGcN6H+lDnm6AvUFYKH ymi7EfX8Rj0GaIBw== 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 v3 36/40] tty: serial: kgdboc: use console_list_lock for list traversal Date: Mon, 7 Nov 2022 15:22:34 +0106 Message-Id: <20221107141638.3790965-37-john.ogness@linutronix.de> In-Reply-To: <20221107141638.3790965-1-john.ogness@linutronix.de> References: <20221107141638.3790965-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?1748847484636173613?= X-GMAIL-MSGID: =?utf-8?q?1748847484636173613?= |
Series |
reduce console_lock scope
|
|
Commit Message
John Ogness
Nov. 7, 2022, 2:16 p.m. UTC
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 <john.ogness@linutronix.de>
---
drivers/tty/serial/kgdboc.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
Comments
On Mon, Nov 07, 2022 at 03:22:34PM +0106, John Ogness wrote: > 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 <john.ogness@linutronix.de> > --- > drivers/tty/serial/kgdboc.c | 22 ++++++++++++++++++++-- > 1 file changed, 20 insertions(+), 2 deletions(-) > > diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c > index 5be381003e58..82b4b4d67823 100644 > --- a/drivers/tty/serial/kgdboc.c > +++ b/drivers/tty/serial/kgdboc.c > @@ -451,6 +463,7 @@ static void kgdboc_earlycon_pre_exp_handler(void) > { > struct console *con; > static bool already_warned; > + int cookie; > > if (already_warned) > return; > @@ -463,9 +476,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; This change isn't mentioned in the patch description. Daniel.
On 2022-11-09, Daniel Thompson <daniel.thompson@linaro.org> wrote: >> @@ -463,9 +476,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; > > This change isn't mentioned in the patch description. I will move this change into its own separate patch. tty: serial: kgdboc: use srcu console list iterator Use srcu console list iteration for safe console list traversal. Thanks. John
On Wed 2022-11-09 10:50:43, John Ogness wrote: > On 2022-11-09, Daniel Thompson <daniel.thompson@linaro.org> wrote: > >> @@ -463,9 +476,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; > > > > This change isn't mentioned in the patch description. > > I will move this change into its own separate patch. > > tty: serial: kgdboc: use srcu console list iterator > > Use srcu console list iteration for safe console list traversal. Yes, split it please :-) Anyway, both changes look good to me. Best Regards, Petr
diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index 5be381003e58..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; @@ -451,6 +463,7 @@ static void kgdboc_earlycon_pre_exp_handler(void) { struct console *con; static bool already_warned; + int cookie; if (already_warned) return; @@ -463,9 +476,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");