From patchwork Mon Nov 7 14:16:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 622598 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE189C4321E for ; Mon, 7 Nov 2022 14:18:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231376AbiKGOSR (ORCPT ); Mon, 7 Nov 2022 09:18:17 -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 Precedence: bulk List-ID: X-Mailing-List: linux-serial@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