From mboxrd@z Thu Jan 1 00:00:00 1970 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 5C2F6C433FE for ; Mon, 7 Nov 2022 14:19:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232449AbiKGOTW (ORCPT ); Mon, 7 Nov 2022 09:19:22 -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 ); 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 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 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 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 @@ -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"); -- 2.30.2