Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1833479rwb; Mon, 7 Nov 2022 06:22:36 -0800 (PST) X-Google-Smtp-Source: AMsMyM4EAgh2Lg/ExMgUX+kdQrUaXfwElOeMlOYuwALchiJzaAmcz7GAf+EglSVRHSGvFm9WYa/S X-Received: by 2002:a17:907:78a:b0:78d:9ac7:b697 with SMTP id xd10-20020a170907078a00b0078d9ac7b697mr47397808ejb.457.1667830956607; Mon, 07 Nov 2022 06:22:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830956; cv=none; d=google.com; s=arc-20160816; b=ZRY5rkHmtCkjJKbm90TjFvqOTV7/YhmhW5+hMxwXdFXfBzULSyjNLTzgLDQZ/MUxm1 ddpHaKKVZ0//nYu9pTEBoW+gKhj3VOxfaYYTxbenkVA8joBZUqQ7i3GXyNhjYIfXLAZh nzjiISABWV2FMSQo0AO2vu+Pp8TsAkX2PvQgKoS3GKtPqAYuAEkUhS2nA1YuBF98UGgb 0NkaHVm98WJfIvhUCOS4MIKA1AqZt84CJJCJJycS4RTQidnfyFFKvfxIO8+84hYdXUnC SRnB6Tm+Cs98oNndSEzFaHFGFiPMixxhDi1WLGUHTPjkVponGKZUuBhmo66xeKs2UEFc j13g== 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=q25D/fbee4emclBCuLkXnvDp43ljaWTdETeJZi0ldYg=; b=U2GPFpr2f/EgmHJQ1BEIEBV2khJXpGWa1ibt3AAyHTmaN4vTdHPb9fBt3KFZVKPf3h NHeHlpd/eDPlk6WZWFNKkUsInCn5jyskhiAfH6dY7xWuedh5oT7UtXBMv8b9E04AzqgK hMLyocSiVgV86WzgtKRqyS0HHkCaq+iQHDCoNy2uL1ntmfBNdml/fuxa4k+JhrLu7qz2 zw/vebSHf/0sNCCmS5xH4ntMfF5ols8h3P3TvdmwCYPb1dFzHM/x0t7XWCA/3aQQGrUS VhxEA/8HT8klpsAM174Vgk1r7hkWviWka2y85t7RtIwQkQA06UNSaJpX5+1V/YFlxpst ZHHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=O454Lsii; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="SK8wtl/k"; 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 f24-20020a50fe18000000b004596db363c4si8694329edt.264.2022.11.07.06.22.14; Mon, 07 Nov 2022 06:22:36 -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=O454Lsii; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="SK8wtl/k"; 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 S231635AbiKGORl (ORCPT + 93 others); Mon, 7 Nov 2022 09:17:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232155AbiKGOQu (ORCPT ); Mon, 7 Nov 2022 09:16:50 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1B301D30C for ; Mon, 7 Nov 2022 06:16:48 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667830607; 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=q25D/fbee4emclBCuLkXnvDp43ljaWTdETeJZi0ldYg=; b=O454Lsiiz5kJngn+Di+jISdQqtthm9fMBo/qd09UHoJIP7fLkelSV+ixhOpLNJXHV7Mttq 4TLbFkmtL0Veo/xxWJ2Bmrg4+CnHd17YN8fNg8mNLvgdi/6EhGHArF+ZhnRQzr3fEE7Nmm GbTzv8SCm7paAxm0xNbxBqgHL/zrwCwfEdB1FVlcstzlumqZSXfwBX3uFiNjKqRqQDl3L2 vzay5KqNRDePj6PPYPtFXCOQFV5nRiemPTvZQ5XQ3F/2xXpq9zrCm18mG3kr5/w8GEsPMV DcZoEV0ZuTMkTu2GPrrzuDLeIZNuK6d3H3h3F1LtgkaRT/U/vnGhM9IYpHGuGA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830607; 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=q25D/fbee4emclBCuLkXnvDp43ljaWTdETeJZi0ldYg=; b=SK8wtl/kZYl5l8mJdOCBSFTMjd4QjXMFsXwUjuDGL17ezsD45pR6VKM5rHUjSYtgNFT7We be38PD4HSzVHtJDQ== 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 Subject: [PATCH printk v3 15/40] kdb: use srcu console list iterator Date: Mon, 7 Nov 2022 15:22:13 +0106 Message-Id: <20221107141638.3790965-16-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 Guarantee safe iteration of the console list by using SRCU. Signed-off-by: John Ogness --- kernel/debug/kdb/kdb_io.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 550fe8b456ec..ed8289ce4fcb 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,7 +559,15 @@ static void kdb_msg_write(const char *msg, int msg_len) cp++; } - for_each_console(c) { + /* + * 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. (Note that there + * is no guarantee for either criteria.) + */ + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { if (!console_is_enabled(c)) continue; if (c == dbg_io_ops->cons) @@ -577,6 +586,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