From patchwork Mon Nov 7 14:16:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 16452 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2078885wru; Mon, 7 Nov 2022 06:21:23 -0800 (PST) X-Google-Smtp-Source: AMsMyM4VAmqxRhbYpt8+y+2ajVljc2w5GK1G+77F3uj2qC9ogVyVGtTGy8HCuhFyguaciprCYCg4 X-Received: by 2002:a50:c21a:0:b0:463:c2ac:95f6 with SMTP id n26-20020a50c21a000000b00463c2ac95f6mr33060364edf.398.1667830883457; Mon, 07 Nov 2022 06:21:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830883; cv=none; d=google.com; s=arc-20160816; b=EDkFxvpmfWic+mOgxOHwD+JVqJ+de0dRIsDv5UJgvnt0wqCGMsTKV8TBkWjxlzxuki ttOgc6PtWed62IIs9/5gRCeN42KECVOhG+1aOZEq3BHdBLwJuZimQeKGZXmrsgXURvTy EMCdjPFb3kzCxWmGzjCokdfcBqVufwskGSoJTaZdAorLLTGfAPSUZR+JPsCRWIYMs7hi 1Wrw5XOu7FSCwFc4Y8JDH0EdNS/JVbfq7tx4USxfxTVEUy7L5anDDHfOi7ovxLIHKaCT QXD8NOrf1cyViCEG3FjAQw8IhsRTkp1ZEYFzWJlwEFeMAuLctagwPScraEeBBoakrXRI CZ2w== 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; 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 f24-20020a50fe18000000b004596db363c4si8694329edt.264.2022.11.07.06.20.58; Mon, 07 Nov 2022 06:21:23 -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; 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 + 99 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 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?1748847436705614979?= X-GMAIL-MSGID: =?utf-8?q?1748847436705614979?= Guarantee safe iteration of the console list by using SRCU. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- 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)