From patchwork Wed Nov 16 16:21:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 21170 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp234544wru; Wed, 16 Nov 2022 08:28:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf4wqvuzUN6ipOg+JqLRQQb6pll9u8zq1mZKAxPlbpHb7IT3QI7w0rNCCUsfAvgkMj2IHGG3 X-Received: by 2002:a17:90a:d501:b0:20d:7716:b0bd with SMTP id t1-20020a17090ad50100b0020d7716b0bdmr4453040pju.122.1668616104717; Wed, 16 Nov 2022 08:28:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616104; cv=none; d=google.com; s=arc-20160816; b=rVTuhdyunq5z6DBnQnvFBZl999HXEt0i1WynpafXKcDw9jrgy4+h/T+vjDdwHnDqhG gBfJHWd1AHxXFWXX0j1WKzV2lYUWu2i7lqUco/gV1yfW3ISzFHlecYkRLmaVas1rsJ0k tv5e239/kI2C3f1L3D8Y5nRHX5nFMZVr/kDa85VISocWp7RrGAEWkm4F6PxdiUd36KeO VX1ui5PswC9fKngZq4VnfP1ItAVp35/Q86ZAkl+WPNTOC26biNtztQY/Lpn29y+x2ZVE ZILXwabeFoVt6tSxS7Glwl51fqm8bwh+qemMThFiaxgKa4+P+jj5E34f9pneEzdIKpeE EIXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=Ekc6YsdvItEWqTtBsALAxHEjpl5Na6n2oyZUMYkLTB4=; b=Yym6v3pvG/P8jDbHWTrSu7qNKIBTuMLmiYjHw3bxtPDayFSDYy865ZOTN2wCYuaHUf YfDxTMVuwYRq1K0mU3p4QyEk26EDIYZUfeTiE9OXdMaSWXXf3IJmG2ZBpPUWkFBHm95i e8HIc8QTuvxiqCzyxdwdxDwSnRe3RybpYaPNLlw2Wk3eozQkoMETrXa/xhWSmpHtWfOa 05AWk1fBSWMgl4TpcS1vDgPEEh61gOHWHQIlcyINgCGaGVY0pe/1O1e7Nnp54hETOdMq f2f/fX2j/F76SKfe1J+VhwktFasdVxvUvAuaajXYQR1Is1MOA1NbsdbamtbTc/GycIXh ZQpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=YEIsKnrW; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z4-20020a656644000000b004706a2c7d4fsi15596265pgv.611.2022.11.16.08.28.11; Wed, 16 Nov 2022 08:28:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=YEIsKnrW; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238797AbiKPQ0C (ORCPT + 99 others); Wed, 16 Nov 2022 11:26:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238529AbiKPQXQ (ORCPT ); Wed, 16 Nov 2022 11:23:16 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABC7558BFA; Wed, 16 Nov 2022 08:22:17 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ekc6YsdvItEWqTtBsALAxHEjpl5Na6n2oyZUMYkLTB4=; b=YEIsKnrWvsEfDeMqLEWhW6CXWRSoij42e4hjpZ+1669Vh0CQIDA7UpSzm2yKlTtivfgld6 fAUyEZtmncagEKKTWslRFbM/nqbjElptv8qPMLgXLBfd3n6maJUYJzOXmKxMv94bFpP3LJ oRthfqYM02vvTa7UIH/tU0JXATfnroC4zP/w1c9d2QDPNnMBcmWrL6Dcc6yS1BTyyw9ko9 8Hh/JDRcF9lttL63XHcP00xzRrML04R8a5M/zokM9FemiYdVjP6iWiOK+LgM7Xso7y6GF5 D+SeLSgCP5+paJP3b0PiOW2tOC2LZ4hcbvGplkl5FtyJ0PAkh/nMhKow/QzbTQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ekc6YsdvItEWqTtBsALAxHEjpl5Na6n2oyZUMYkLTB4=; b=Lu8i/3DrLZMyeZDhwbNSreisjN68CvYSPVUqy5KUkBeiHdQUQjFwCwxhm3DUm6CfS8JewM lFXpVW57c/CwP/CA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk v5 37/40] tty: serial: kgdboc: synchronize tty_find_polling_driver() and register_console() Date: Wed, 16 Nov 2022 17:27:49 +0106 Message-Id: <20221116162152.193147-38-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749670800721460023?= X-GMAIL-MSGID: =?utf-8?q?1749670800721460023?= Calling tty_find_polling_driver() can lead to uart_set_options() being called (via the poll_init() callback of tty_operations) to configure the uart. But uart_set_options() can also be called by register_console() (via the setup() callback of console). Take the console_list_lock to synchronize against register_console() and also use it for console list traversal. This also ensures the console list cannot change until the polling console has been chosen. Signed-off-by: John Ogness Reviewed-by: Daniel Thompson Reviewed-by: Petr Mladek Reviewed-by: Douglas Anderson --- drivers/tty/serial/kgdboc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index 82b4b4d67823..8c2b7ccdfebf 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -189,12 +189,20 @@ static int configure_kgdboc(void) if (kgdboc_register_kbd(&cptr)) goto do_register; + /* + * tty_find_polling_driver() can call uart_set_options() + * (via poll_init) to configure the uart. Take the console_list_lock + * in order to synchronize against register_console(), which can also + * configure the uart via uart_set_options(). This also allows safe + * traversal of the console list. + */ + console_list_lock(); + p = tty_find_polling_driver(cptr, &tty_line); - if (!p) + if (!p) { + console_list_unlock(); goto noconfig; - - /* For safe traversal of the console list. */ - console_list_lock(); + } /* * Take console_lock to serialize device() callback with