Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp863498rwb; Wed, 16 Nov 2022 08:36:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf7s3ZGkudFvRIYLqmgYPCX3MLjpcxZpul2u3xBvuM5xsIXY76xmg8BWVF9o3iQF1OlxrBzo X-Received: by 2002:a05:6a00:1f06:b0:56b:f390:36f with SMTP id be6-20020a056a001f0600b0056bf390036fmr24392207pfb.2.1668616608725; Wed, 16 Nov 2022 08:36:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668616608; cv=none; d=google.com; s=arc-20160816; b=XnKfJv0XKs4OZH3jk4HsTFVA7xd2JZVPOTCz2vbfEjR9LEDg5co2s/SfM1+/aOnB33 NUeF41WCrOOValxFo/2gljmd8Xjd6FVJBPN0+oUaZHPzQKa36hm3O9LxbecC5LobuR9v hAwg50Qz+e2yJ0YAufnyKABOhPhKaawNcIPip94l6shzjOHCrXIovxTBpysWEdQXumuO V2LlmVyKPSJQyRw8ZyUnF1iUJv2Z2Xjvoq1kPP1eLWNAaiuPWHm61ChrLV/MlNglx19u kua6Hhsgo1HQsq8jqpUqERZdjmvEEl3vGqNXL6eXQfA2iiLRsLwsnVYPdnjvBD2RJfUp 1uNA== 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=/Z8Y08lU4gBzUjFFzV1bgJ9D4slaSXi2GlBsKiKXaB8=; b=IoJb2o8ffKb8jKjN92ASjuuZl+ryGOfD5gX+v/6oL8yUsm8+nyuQGBq/P5l2O+2qJw /MH8TgDmJDYnuh/MiU6+9ljYcr1AgxgdYfHbUjXrnFpJVdWJSYvE7o7qyq0KhWVtCVrM uma9vYRNQgA/ZTVaiibM378OTYMqx0uA3R/btgKDHPOXGorzL8/tzbp5+6LjhqSOuKiZ GEoyHj3G/m9GDkIBDx2rcHhWfKZtfYzReU9m87iPvdKfFyEOp2xPBINA8KZCM0pCUHhJ B7i/WYoaE/zVE/0i6yHveLMG6gvhbn/B1UQ8Rpxl3E2xHfGckJrSlPQrgaP/aD3AGShn 6mqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AlFnjhG6; dkim=neutral (no key) header.i=@linutronix.de header.b=UPIFaN5g; 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 e70-20020a636949000000b0045ff2a2f56csi13693118pgc.546.2022.11.16.08.36.37; Wed, 16 Nov 2022 08:36:48 -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=AlFnjhG6; dkim=neutral (no key) header.i=@linutronix.de header.b=UPIFaN5g; 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 S233378AbiKPQW7 (ORCPT + 91 others); Wed, 16 Nov 2022 11:22:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234366AbiKPQWH (ORCPT ); Wed, 16 Nov 2022 11:22:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B178D4AF04 for ; Wed, 16 Nov 2022 08:22:05 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668615724; 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=/Z8Y08lU4gBzUjFFzV1bgJ9D4slaSXi2GlBsKiKXaB8=; b=AlFnjhG6yoalddGZUFtJcAolOgncQCDPgISMOQ36V6hlKtWG/cSc/rczN/innYrbR/Jywt 6BvsgBT8OM0LI0Zl93AGE5DcOK1Hk6PuqLE9MA6ZMxEFV140/y9Mh5kvEiN3u+2H3AgdKK +yLeMp6/Iwq+h0Rj2BKXdtZip7O7SGTdH/pr5EM1c/UOFDnm/rWDQpxmN58Gn4s3l0jWhT iGumgzq8mY+cbvxvXW6Wg5Fr6sjE/yVmwbnkPerYdOX99Q0eOvyJBOl6ryyIUf2n5ylE35 XNUzA/3US4iPGW+at2fOIIkGxF9+2P6fccpt+a2QBG7OmpQDcRtLnBgi2WuoXA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668615724; 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=/Z8Y08lU4gBzUjFFzV1bgJ9D4slaSXi2GlBsKiKXaB8=; b=UPIFaN5gtyWRJGSpTKiuex30w225CCf2nyuT23Yek69V+hFQwIVsUK9SGiI9NihuAmA3qc np5rsSzRcXc59rDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Jason Wessel , Daniel Thompson , Douglas Anderson , Aaron Tomlin , Luis Chamberlain , kgdb-bugreport@lists.sourceforge.net, Aaron Tomlin Subject: [PATCH printk v5 14/40] kdb: use srcu console list iterator Date: Wed, 16 Nov 2022 17:27:26 +0106 Message-Id: <20221116162152.193147-15-john.ogness@linutronix.de> In-Reply-To: <20221116162152.193147-1-john.ogness@linutronix.de> References: <20221116162152.193147-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 Guarantee safe iteration of the console list by using SRCU. Signed-off-by: John Ogness Reviewed-by: Petr Mladek Reviewed-by: Aaron Tomlin --- kernel/debug/kdb/kdb_io.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 67d3c48a1522..5c7e9ba7cd6b 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -545,6 +545,7 @@ static void kdb_msg_write(const char *msg, int msg_len) { struct console *c; const char *cp; + int cookie; int len; if (msg_len == 0) @@ -558,8 +559,20 @@ static void kdb_msg_write(const char *msg, int msg_len) cp++; } - for_each_console(c) { - if (!(c->flags & CON_ENABLED)) + /* + * The console_srcu_read_lock() only provides safe console list + * traversal. The use of the ->write() callback relies on all other + * CPUs being stopped at the moment and console drivers being able to + * handle reentrance when @oops_in_progress is set. + * + * There is no guarantee that every console driver can handle + * reentrance in this way; the developer deploying the debugger + * is responsible for ensuring that the console drivers they + * have selected handle reentrance appropriately. + */ + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { + if (!(console_srcu_read_flags(c) & CON_ENABLED)) continue; if (c == dbg_io_ops->cons) continue; @@ -577,6 +590,7 @@ static void kdb_msg_write(const char *msg, int msg_len) --oops_in_progress; touch_nmi_watchdog(); } + console_srcu_read_unlock(cookie); } int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) -- 2.30.2