Message ID | 20221019145600.1282823-27-john.ogness@linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp379238wrs; Wed, 19 Oct 2022 08:10:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM60g77yr4+7+1R/xo+QUd6C61M1E99+X7OdSSBB/vyL0As/869OfR+4ClUp5goWCioM7hDe X-Received: by 2002:a17:906:7952:b0:787:a14d:65a7 with SMTP id l18-20020a170906795200b00787a14d65a7mr7361738ejo.108.1666192232004; Wed, 19 Oct 2022 08:10:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666192231; cv=none; d=google.com; s=arc-20160816; b=ll4BwM//OuL+Hgp8qFh22LwUqFXNv/kJhAax05UqtY77D8W9V+FY+G9Q06JxZ/2dgS kE070J2QZy64w/kzO/0aJgNUGe+wGZ85QsTJFotA2mr/8ia6i8NG6/lgRwzs2rIloq4D EhEHa6pInxvzqrzP8oIailYo6p2LpnzF4cWNOOo2GWAuFwiLq/V6jZrR8u+OKXt3y2S/ KSABeIHggeIrPnVEKhcy6ffjez+CcfSOUPth6mj2HJcJxNDDGGNh49aqj2Y1dVTguPYp FqE70Tcg7UMVt5STEpL1jffMsMDNOfC6xKVIibdJSnIBzvKgAZkzNVjyEe27UGk0K+44 R31w== 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=l6JL8Q05OijoTEvKKyIiYa7K6VvZeDLREPexuqG68w4=; b=eRzv+KaEEOoM6LAsH06m4fIZjwB7RmtrSpJp6S2Awkx9n7V+2iPsFsmeyIwB93YwjP x4Jtvt8HL0Jcf1siMK89tzRj4RmO7T8AQZ2wlCUau/IuxtzLraQM0R6zdAkgFq+LSoQy uGBgrVQufYsRBJ66HTNRNkWH9ABz8EkEqkoo0lYDuu9iIda1GjfHZ/cBnsY6IHcsKcUv 1OWcBcVBvhlJgS66LECJCZRfQ+xcY6C1cBrBwSpD45VcX8EAJ6D9iZCymgdbw8HswLGM 169nwfpKkDOpDcB0yKAIiqJiDVxbxfJ/A9e6Yxh8SaDLLOBZP0aBlUFS2YQTu3QgWV0P s3EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2lE2ZSVv; 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 n11-20020a05640205cb00b00452697eda4csi17237808edx.58.2022.10.19.08.09.44; Wed, 19 Oct 2022 08:10:31 -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=2lE2ZSVv; 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 S231931AbiJSPHD (ORCPT <rfc822;samuel.l.nystrom@gmail.com> + 99 others); Wed, 19 Oct 2022 11:07:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbiJSPFp (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 19 Oct 2022 11:05:45 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9DCD6573 for <linux-kernel@vger.kernel.org>; Wed, 19 Oct 2022 07:59:25 -0700 (PDT) From: John Ogness <john.ogness@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191376; 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=l6JL8Q05OijoTEvKKyIiYa7K6VvZeDLREPexuqG68w4=; b=2lE2ZSVvaLYxX/mxts/imwzBNHAp8IFSDC/ai7lkxP1zyF6vpMFV8KAaG0pwB+zKzWkutn BNZQsjhTA+fE9mUGf/9zLZQuPNRIBu0owJpd7GDzfuULoEKri5Ic8olH4bE1eI5Rf1CKGy vTs3ThAfna4xN6EPjQmcBVcPNNwb7z99UsM+MaDiSMsHRWQQdQDukhcxIu7T4tOZ2TYmxg Bfdt5cy+/S+IRAvC/LS6NYxQYe0e79/FQQRYb/Mcd8jS8qxWB1iuXQe85SqXEhXYqiH8j4 +8mgUokSmCQOtAKhWeO3fUlqU5Flbi2cC2akX0Xw1B69Gv1ldKxWWm+8ITOUfQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191376; 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=l6JL8Q05OijoTEvKKyIiYa7K6VvZeDLREPexuqG68w4=; b=CQZkI2DXDnPwDZmhG2PVbvPciqqo6PQ6K7EPwjaFXRMKTNR/ZrE840g4rZSpD8aFVitZok a6Wx9DhxTm9LofBg== To: Petr Mladek <pmladek@suse.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org>, Steven Rostedt <rostedt@goodmis.org>, Thomas Gleixner <tglx@linutronix.de>, linux-kernel@vger.kernel.org, Jason Wessel <jason.wessel@windriver.com>, Daniel Thompson <daniel.thompson@linaro.org>, Douglas Anderson <dianders@chromium.org>, Luis Chamberlain <mcgrof@kernel.org>, Aaron Tomlin <atomlin@redhat.com>, kgdb-bugreport@lists.sourceforge.net Subject: [PATCH printk v2 26/38] kdb: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:48 +0206 Message-Id: <20221019145600.1282823-27-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 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747129185982216029?= X-GMAIL-MSGID: =?utf-8?q?1747129185982216029?= |
Series |
reduce console_lock scope
|
|
Commit Message
John Ogness
Oct. 19, 2022, 2:55 p.m. UTC
Guarantee safe iteration of the console list by using SRCU.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
kernel/debug/kdb/kdb_io.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
Hi, On Wed, Oct 19, 2022 at 7:56 AM John Ogness <john.ogness@linutronix.de> wrote: > > Guarantee safe iteration of the console list by using SRCU. > > Signed-off-by: John Ogness <john.ogness@linutronix.de> > --- > kernel/debug/kdb/kdb_io.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c > index 550fe8b456ec..5c0bd93c3574 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,8 @@ static void kdb_msg_write(const char *msg, int msg_len) > cp++; > } > > - for_each_console(c) { > + cookie = console_srcu_read_lock(); > + for_each_console_srcu(c) { Maybe it wouldn't hurt to also have a comment saying that normally the console_srcu_read_lock() wouldn't be enough given that we're poking into each individual console and calling ->write() but that we're relying on the fact that all the other CPUs are stopped at the moment and thus we should be safe. -Doug
On Mon 2022-10-24 17:47:25, Doug Anderson wrote: > Hi, > > On Wed, Oct 19, 2022 at 7:56 AM John Ogness <john.ogness@linutronix.de> wrote: > > > > Guarantee safe iteration of the console list by using SRCU. > > > > Signed-off-by: John Ogness <john.ogness@linutronix.de> > > --- > > kernel/debug/kdb/kdb_io.c | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c > > index 550fe8b456ec..5c0bd93c3574 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,8 @@ static void kdb_msg_write(const char *msg, int msg_len) > > cp++; > > } > > > > - for_each_console(c) { > > + cookie = console_srcu_read_lock(); > > + for_each_console_srcu(c) { > > Maybe it wouldn't hurt to also have a comment saying that normally the > console_srcu_read_lock() wouldn't be enough given that we're poking > into each individual console and calling ->write() but that we're > relying on the fact that all the other CPUs are stopped at the moment > and thus we should be safe. True. I guess that the SRCU lock is not really needed from the same reason. Well, the SRCU walk makes sense. It makes sure that the list can be safely traversed. I mean that pointers are updated and read in the right order with the right barriers. Yes, it would be nice to add a comment. Best Regards, Petr
diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 550fe8b456ec..5c0bd93c3574 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,8 @@ static void kdb_msg_write(const char *msg, int msg_len) cp++; } - for_each_console(c) { + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { if (!console_is_enabled(c)) continue; if (c == dbg_io_ops->cons) @@ -577,6 +579,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)