Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1860007rwb; Mon, 7 Nov 2022 06:38:45 -0800 (PST) X-Google-Smtp-Source: AMsMyM79cuNH1telx0YcN1RJUc+ioiz5GILCVyJoZoePkZNeWAs7faO9YzHQdY5yuFVw4Y20uOZk X-Received: by 2002:a17:907:2c47:b0:7a4:7673:d6ee with SMTP id hf7-20020a1709072c4700b007a47673d6eemr48774231ejc.397.1667831925355; Mon, 07 Nov 2022 06:38:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667831925; cv=none; d=google.com; s=arc-20160816; b=Ir5ohpKmVNC+3209uhf+Mva8zsnYJogWLEavFdPZicsX8y7/qk9WnzIheYA8RFEerd yVzFwgnkUZQKLk6Qqv1Ugglx7G5PUOWKKGNT4qjXaKrqFanJvXoR2dCFQ2nHCjor9+8D hLiy7pMQqSJA5cOBAglIxmRA1PAcbic+AI47EXnNxULRZ+5mcORBagF8Ijp1ybgjpDk6 a6xpCYDipGcrqU9wo7rbr3aRtxK+/1XGMmKTnEjW3j63HyC1dvCV0X7NIxE8fGLLeq3t 2gbARdUSWqHEkPO5naDxM6pHriC6CDihw6hD0mhbPOvTwvDs9JnJ227ffYmfS2vAJPBT QYHw== 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 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp8-20020a1709071b0800b0078d4b605b71si9911214ejc.338.2022.11.07.06.38.21; Mon, 07 Nov 2022 06: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=quYSkn0H; 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 S232142AbiKGOT3 (ORCPT + 93 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 ); 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 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 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 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 -- 2.30.2