Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1834735rwb; Mon, 7 Nov 2022 06:23:26 -0800 (PST) X-Google-Smtp-Source: AMsMyM4zfMp/eb/GcsD13qWU/Q0nZ8TyvB5JDRdRXiRPdU0HRwB5OLd8HYEifv1IMwhdgX49TAtT X-Received: by 2002:a17:907:8a09:b0:7ad:adff:ddf6 with SMTP id sc9-20020a1709078a0900b007adadffddf6mr49422467ejc.320.1667831005745; Mon, 07 Nov 2022 06:23:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667831005; cv=none; d=google.com; s=arc-20160816; b=wfmlT2x6ET1GGbqhcvAh941RDSvzwpEXIMmEopa+GmBQSnR82p2lq+iIvrRy9vs26s BqilBQ+9Yw3FkadNR2EqHWwghMO8nDkbMFopl3MXk1JYqsTkpc49KnTVap9sia+ENHAJ a+pXmOMwCr4hBzUVI3RGSkwy+L2A0X52K/S8jazVn/HQpwI5oDo65ad1PY8JdsXRx3fE BNb78fnEMHHLSrtMqw98gpq52DOn+4SY6QFENAVJsI66N5Y+4EDEZqoPBRj/VOa8U0Qh jC4FdonYdPAdDv/YCXvt0TiK8LBJKRq1zC5I5ZxObPW/ZjUux/jy8EQ+DNaF30pCxVP4 CxjQ== 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=SVseywoielHQsdgFj4SQ2wUZa0m9RxiqWqQHkSQjPis=; b=MzQ18CbWCTXFhWm04SkwyZ25tmQRyL0RsW4C4LxROfa8i1Flz4FQwbWss+ocApwhUr tyY0+6+9h0bU3/hCo4xOChMA3K67aY3SKEq5HOBeKis0/80I7/P5yCrJj0uMn3hwTwnh xHug286JeqJMUA14dgTPTgvy3cPiDlmeSuTffkzqY/SkgRvIDpmGwqCrN1iZyJ045lvL W2NpAQ49LMtycCprUUUWZLwEVsMsA7w0MmXm9csrgXFrnEQ5bZG+wpRNJsxlOVxmZN8I pNngQUUKVVSa4Nx6vyYj2/kuDVqFjqn9H00i4fDuwj8WQexUeGrBFdzumGeNIDQ3r0vy KN3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=gqAyq8wc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Z547tJz8; 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 ca2-20020a170906a3c200b0078d3b940ec5si7395695ejb.373.2022.11.07.06.23.02; Mon, 07 Nov 2022 06:23:25 -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=gqAyq8wc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Z547tJz8; 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 S232446AbiKGOTT (ORCPT + 94 others); Mon, 7 Nov 2022 09:19:19 -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 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 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