[printk,v3,37/40] tty: serial: kgdboc: synchronize tty_find_polling_driver() and register_console()
Message ID | 20221107141638.3790965-38-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 l7csp2079477wru; Mon, 7 Nov 2022 06:22:25 -0800 (PST) X-Google-Smtp-Source: AMsMyM4p4/kNxUWvdzWkB6/wvCK8p+uNXiQwo8away1CfT9FoQ78PvGOHQrIaO91Ko66y5rQS4nw X-Received: by 2002:a63:ec51:0:b0:46f:ed8d:7089 with SMTP id r17-20020a63ec51000000b0046fed8d7089mr28226421pgj.469.1667830944813; Mon, 07 Nov 2022 06:22:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830944; cv=none; d=google.com; s=arc-20160816; b=pCee4U7kopeTIOrHu2+1/N7+MBQD262Jekt5aINu2aXh+Q4cxDQr/r8+Hq/GqoEQbF y1qI6T+gU7DcmMPQ3PVlXWIfyHm7kLlUNlsCc17H9gyh94rRQVhGaI8QrB4mecUaSCUD 4LnZY8UusAL5EMNlTHfgD4lsKbSPfJ16U9PZaZt+oBPj81Lg/TTOatwul8A2t2y34Sk4 jgSDt+8CtqgtMuKsDnE0jUN6Ews6XydC6V8+C/XW1ZVnSfh8byKGGpS5MWRpruWixyL/ 1hjHIx9+/BlMTZJbxUkErvsrwskmm3c9sCkj6J92cY7AJb1666AGchW6w2qtcrkyZlQJ TcVQ== 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=ABDFtrgjV5x8uGkolXUUesJdZpQfr7BwwBr7iTObU1k=; b=cUai3pdIKdcuUClSwSR4vMEb5FhU5IcIc606U2/UXdH46CT/6cWE+QdIrNp3B5ZDBt PFl6LwGQAvC6lNr006GmdQavqd4BQQmr7IATTmO2WT1RULoHQxg9tbsDgloN+cInDhb4 OlRLtOC/FzoKfEuJhiUe+RUxYeu2InijP72IFILm/dFfnmuUGzskoI/7zn02kmkYqWO6 1fzB2ylxplHVOEyxPDWUUj0Df1B0T0cLXldLucgtWrT8m5R5hc9AcH0qWdkForiE2WbA Zt0kQyogX3RNOlemD5ZCyCE0LDm51klMZxPoEA3/IAWkActoaNMN5g8fUANQIDNuAOzK CDKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=quYSkn0H; 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-20020a170902ec0100b00179f9521d08si9489765pld.149.2022.11.07.06.22.11; Mon, 07 Nov 2022 06:22: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=quYSkn0H; 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 S232142AbiKGOT3 (ORCPT <rfc822;hjfbswb@gmail.com> + 99 others); Mon, 7 Nov 2022 09:19:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232269AbiKGORk (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 CF5231D641; 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=ABDFtrgjV5x8uGkolXUUesJdZpQfr7BwwBr7iTObU1k=; b=quYSkn0H6WS4/l0RYtMy3BDn/rK/rRzby8k7+wPwnxKordiq2TgHz8VGVPX95WuRGgwskm EtBX73KPFW0k9NtYTpUCTtC+tWMJhMww3Zvq9V2lgXuA2ShF3fqmI4g0ScS/P1sTLwetNh ExpToebi/v9WRQUmTKE5E/WcN/uuirbBRldIeX/WLOaS06fohXQ/OGszmxg1g6WSergB31 MbaozUQ59Y9Fv+G+GH08ICMAjHlm76Pco9BS188p4z7JPQKzTEx426fF2f8aER4+H6sylG CSiyN8MEZvyACLULxolUeG76LhEFYwnZoc0EQUAsjHeEZdS3ykqCDiKbXDiAqw== 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=ABDFtrgjV5x8uGkolXUUesJdZpQfr7BwwBr7iTObU1k=; b=0EsqVlG5GcPGEcsVNMZ4uy7CR5J6JcEVjcsCxd7fPEIZJDWclxknPbTwQCDjbw6tArZeef 7aUFWCYb4TEtlXBA== 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 37/40] tty: serial: kgdboc: synchronize tty_find_polling_driver() and register_console() Date: Mon, 7 Nov 2022 15:22:35 +0106 Message-Id: <20221107141638.3790965-38-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?1748847500823828086?= X-GMAIL-MSGID: =?utf-8?q?1748847500823828086?= |
Series |
reduce console_lock scope
|
|
Commit Message
John Ogness
Nov. 7, 2022, 2:16 p.m. UTC
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 <john.ogness@linutronix.de>
---
drivers/tty/serial/kgdboc.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
Comments
On Mon, Nov 07, 2022 at 03:22:35PM +0106, John Ogness wrote: > 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 <john.ogness@linutronix.de> Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org> Daniel.
On Mon 2022-11-07 15:22:35, John Ogness wrote: > 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 <john.ogness@linutronix.de> Huh, this is a maze of related calls. At least for me. But the change seems to be correct. Reviewed-by: Petr Mladek <pmladek@suse.com> Best Regards, Petr
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