From patchwork Wed Oct 19 14:55:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 5639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp379037wrs; Wed, 19 Oct 2022 08:10:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ukygA5lXSjBK+Uxtmt2Oj8ow0sP30nzRVnTzZxdosigSW6xFxA5MkyR1kTygK5XisWd3i X-Received: by 2002:a17:907:7627:b0:78d:b6f5:9f15 with SMTP id jy7-20020a170907762700b0078db6f59f15mr7207330ejc.149.1666192213768; Wed, 19 Oct 2022 08:10:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666192213; cv=none; d=google.com; s=arc-20160816; b=melsmZHQYcY160etFQIkks3XNS31aUrCrZmcblZDkoF9cvmh7QIR5jQ8QwP8aYWHte O9FhG7vHWbeBHZ/1HCYTE4ZRPZhOKXv/UVVFYGsPtWIuM+u0aAC5DSO4EcLVp58784Tb Vkd4HiqpxzgIfHu9taD3N5ioMsa3I/s54zZsJ3myxfxaR/t07o+vGVljHQfOyf4smtMW pY1W6OLecFP0n8FAm+kJwmbI03hha7EdsQnvO9x+wyxGB2nTieMK6126oE9SuhKppvcN IKkXAJTJEADPtRzuiXCTNmuL5Bfeo5rtD+kEwgDWrnuD5qHh+8O8SzGnUAWzzWUe3whi SZAw== 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=aHpEExScLzm4b3PGICcqjxP6eSShWDRVil4o7DIdRaU=; b=rwdvJ3k6h50AmF/sbI037OYy3TNMGD49rtsF86ZPVyUvsq3LKl86UrKlGlBa8VGQf/ 2d0cUskShM5QZDHtW3wPMO1k8T6Ee098IjM/91G2Ao2TTtaPBY/CwZ10OKxWMaDMpwRa nPfoHdJPlNGmhYXt6AKpTUWpFdfzmnDYF8ABRH+KIvk6UcSv3hFDyeAZQFQfFnOGende uBZiGkgxoGidC3NJrk6g9iQ/EAszfK6Im3StSkJwxD27ldlimCL8pTpePDCl74QlErxp +ZVMwqJTg6D4EPxPW3hPHJbxOcwcRG52xkAPG6+qKiG15EdpL+wXciQRS48qKVB6EREN FLxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="eDfs/FrH"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l16-20020aa7cad0000000b00459c1e64776si13018144edt.412.2022.10.19.08.09.44; Wed, 19 Oct 2022 08:10:13 -0700 (PDT) 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="eDfs/FrH"; 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 S232115AbiJSPGx (ORCPT + 99 others); Wed, 19 Oct 2022 11:06:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231892AbiJSPFm (ORCPT ); Wed, 19 Oct 2022 11:05:42 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 432F6193EE9; Wed, 19 Oct 2022 07:59:07 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191373; 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=aHpEExScLzm4b3PGICcqjxP6eSShWDRVil4o7DIdRaU=; b=eDfs/FrHZ7HvnRF4atKhYEZ/pRXno8GEGAkw6IqnyiCmO75Q9sEJ6bqLoRWApu5I/kGcQh KCTzK1MrPYWFQHFbhhZ4ddIBd7thtElTQ1FhTZSvTGr+D/NiY6ja5av6esQrgKRy3JmdV3 rrRE8vZ1b74ucDPVRwBFE1RIC+RhuKL5DdLWniGfxLfcajr60p331h+dY6KdEzGysIZMdC yATsOHK/PLnHwsUFjoxiti7aJ0XxaKU0B+KQDroX00sQ4UKCeboef9oWWEJpZprSsCboLS UQL5y2A8i38TojR6bF2UMoVPjjyV/EALMD7ITlxAjhc539biNA5Q3/A88oMp9w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191373; 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=aHpEExScLzm4b3PGICcqjxP6eSShWDRVil4o7DIdRaU=; b=ag8wipmZjScVK96FvYUT41NwW8W8jBS77tduneOJOnLYN8uLmQW8RkuO+x9sTyAf/SfPXA QV5RyDV2N62v9UBQ== 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 v2 21/38] serial: kgdboc: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:43 +0206 Message-Id: <20221019145600.1282823-22-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-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?1747129166988124279?= X-GMAIL-MSGID: =?utf-8?q?1747129166988124279?= Use srcu console list iteration for safe console list traversal. Note that configure_kgdboc() still requires the console_lock in order to ensure that no console is in its write() callback when its direct() callback is called. Add comments to clarify this. Signed-off-by: John Ogness Reviewed-by: Greg Kroah-Hartman --- drivers/tty/serial/kgdboc.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index b17aa7e49894..e9d3f8c6e3dc 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -171,6 +171,7 @@ static int configure_kgdboc(void) int err = -ENODEV; char *cptr = config; struct console *cons; + int cookie; if (!strlen(config) || isspace(config[0])) { err = 0; @@ -193,8 +194,14 @@ static int configure_kgdboc(void) if (!p) goto noconfig; + /* + * Stop console printing because the device() callback may + * assume the console is not within its write() callback. + */ console_lock(); - for_each_console(cons) { + + cookie = console_srcu_read_lock(); + for_each_console_srcu(cons) { int idx; if (cons->device && cons->device(cons, &idx) == p && idx == tty_line) { @@ -202,6 +209,8 @@ static int configure_kgdboc(void) break; } } + console_srcu_read_unlock(cookie); + console_unlock(); kgdb_tty_driver = p; @@ -451,6 +460,7 @@ static void kgdboc_earlycon_pre_exp_handler(void) { struct console *con; static bool already_warned; + int cookie; if (already_warned) return; @@ -463,9 +473,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");