Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1690809rwb; Fri, 23 Sep 2022 17:20:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ZAHjiWwze/+GGQIJfAoYiqaTCQaRtEUPJQf6x9azCGtHGpkzOH5Dxco3ih6NwwCYhdhhF X-Received: by 2002:a05:6402:268d:b0:451:d6e9:5572 with SMTP id w13-20020a056402268d00b00451d6e95572mr10979453edd.390.1663978803243; Fri, 23 Sep 2022 17:20:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663978803; cv=none; d=google.com; s=arc-20160816; b=eD2363QhPqJ+6/XXVwjHVtbLPW5LkHCgSmfSdjKoN4HVe7vE21Zo6N/Nk3zp1jHKd1 1JdrhijewobxJj8kuCLrT/VnHqviWFrl0PSZgyvQFWoaJZX+A3OP1R40AgEA9Pk3bHjw wmfnYm/n4paQ1oiOP+RVQqgNLqfP/ovmEW4nmg52x9SrtuBb31jdwbdzk0gAicYN1Oh5 oNEXIvFcjd1h5wZYD8ih26mG0Uuvzoqqw1bLxNbT/L02+ikunMoM/CctL4Rt895FPPKo wV5/T1bsQCtFQ83m0p+n6wHbT3uWGLpvBh8qa5HSuVgpPQbqM3jYFrEyTTXfd1mXlg2k 6W3A== 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=wmQTrIsrazpPIyD8N/ImSAVVwbH1mqHErna9k27Vvaw=; b=tVtYvOt8rNY1IiixDqtZw69MYvvHy9R5SuVQ7a2aaoldjSNehD5YtasZmTu5qTR4Nv RtOOdLo90ANF+TLF08l3bR8GseIJjBROJQD/DTuVS5hyEAmiDK/wOlaatY2JClwQ789H NWG411AywIFaSIUjejmbvYeTs1DkhGwSJv+JztOjEpJi7q9n2KkYnYuEDpT+2zbfzmEO XumJzCaOIcLviHZwbgz9fcoCLhI30PcKleSpOEP1C4P80aPo1PgZughIfSG99z6JoaMD nvjygCN3dNca3gZFIqyJPVL1WXOysWX/CmaeNNthI9Aj59vOL/+6zcOTNuaqdrBRPH5S ksng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=e0HL7iVS; dkim=neutral (no key) header.i=@linutronix.de; 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 ey4-20020a0564022a0400b004513abe8f74si9359863edb.249.2022.09.23.17.19.37; Fri, 23 Sep 2022 17:20:03 -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=e0HL7iVS; dkim=neutral (no key) header.i=@linutronix.de; 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 S233044AbiIXAGD (ORCPT + 99 others); Fri, 23 Sep 2022 20:06:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233002AbiIXAFM (ORCPT ); Fri, 23 Sep 2022 20:05:12 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A97DB02B9; Fri, 23 Sep 2022 17:05:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663977901; 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=wmQTrIsrazpPIyD8N/ImSAVVwbH1mqHErna9k27Vvaw=; b=e0HL7iVSFrWDEyWd93pKTysu+f2PtjV3UFX2E17ouIqnFgtgYHj2JwYv2DJpGHFeLeQ3ld MCM414BiK2Y3yDjf149S6h7A2iKBukElbmL8Fx+8e0sPzdpxSUabOQYTK4KjD2bSusFYnP //N/XuNoVWXLv6GGGBV6UOQkBD+XfX0rptum628w3mUuvC8YGt0WaymrGmYMZDiBqax5Me Rggwzu8njK/aSMcmvP10yWtRrHV4bUJBQdZnWnzqiXp9tAjhEgNDoHxBmN+uFi/uXa+Mos JdYY7EdmpHm6MrGtdgVzyLDiJyHObnss252/czGO/8zUHjIBcIgYIQW0F8EU1g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663977901; 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=wmQTrIsrazpPIyD8N/ImSAVVwbH1mqHErna9k27Vvaw=; b=b9MI9BO/qiKg/DT4XFHp9Pb+3i4omPO4qdqEr0ElztkwrozUgg0NcEq8KTBgK/v0k0uPW1 l2r6ueyffq6bMOAw== 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 , Aaron Tomlin , Luis Chamberlain , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH printk 10/18] kgbd: Pretend that console list walk is safe Date: Sat, 24 Sep 2022 02:10:46 +0206 Message-Id: <20220924000454.3319186-11-john.ogness@linutronix.de> In-Reply-To: <20220924000454.3319186-1-john.ogness@linutronix.de> References: <20220924000454.3319186-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 From: Thomas Gleixner Provide a special list iterator macro for KGDB to allow unprotected list walks and add a few comments to explain the hope based approach. Preperatory change for changing the console list to hlist and adding lockdep asserts to regular list walks. Signed-off-by: Thomas Gleixner Signed-off-by: John Ogness Reviewed-by: Sergey Senozhatsky --- drivers/tty/serial/kgdboc.c | 5 ++++- include/linux/console.h | 10 ++++++++++ kernel/debug/kdb/kdb_io.c | 7 ++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c index af2aa76bae15..57a5fd27dffe 100644 --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -462,10 +462,13 @@ static void kgdboc_earlycon_pre_exp_handler(void) * we have no other choice so we keep using it. Since not all * serial drivers might be OK with this, print a warning once per * boot if we detect this case. + * + * Pretend that walking the console list is safe... */ - for_each_console(con) + for_each_console_kgdb(con) { if (con == kgdboc_earlycon_io_ops.cons) return; + } already_warned = true; pr_warn("kgdboc_earlycon is still using bootconsole\n"); diff --git a/include/linux/console.h b/include/linux/console.h index 24344f9b0bc1..86a6125512b9 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -187,6 +187,16 @@ extern void console_list_unlock(void) __releases(console_mutex); #define for_each_console(con) \ for (con = console_drivers; con != NULL; con = con->next) +/** + * for_each_console_kgdb() - Iterator over registered consoles for KGDB + * @con: struct console pointer used as loop cursor + * + * Has no serialization requirements and KGDB pretends that this is safe. + * Don't use outside of the KGDB fairy tale land! + */ +#define for_each_console_kgdb(con) \ + for (con = console_drivers; con != NULL; con = con->next) + extern int console_set_on_cmdline; extern struct console *early_console; diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 67d3c48a1522..fb3775e61a3b 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -558,7 +558,12 @@ static void kdb_msg_write(const char *msg, int msg_len) cp++; } - for_each_console(c) { + /* + * This is a completely unprotected list walk designed by the + * wishful thinking department. See the oops_in_progress comment + * below - especially the encourage section... + */ + for_each_console_kgdb(c) { if (!(c->flags & CON_ENABLED)) continue; if (c == dbg_io_ops->cons) -- 2.30.2