Message ID | 20221019145600.1282823-21-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 y7csp379689wrs; Wed, 19 Oct 2022 08:11:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5UVDBEbpXA1IF8pYiLQo4flYAbmKBViWpYN56WxkhWta/QtGim49s70lD7lU89WZWdNkqj X-Received: by 2002:a05:6402:1587:b0:458:fbea:436c with SMTP id c7-20020a056402158700b00458fbea436cmr7956464edv.407.1666192285084; Wed, 19 Oct 2022 08:11:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666192285; cv=none; d=google.com; s=arc-20160816; b=Kyfie8oQHT5dWHIGU7jIiYssUq28MpSBQDTa8fnbZ2sVeWrIuqC1vZxKlXVD8aRANr M7cPMD1mUrwKLYAmCrdZGrspkmJAEK0SYtaOwV0nMbgaKXDir6YFaODwKb5FoOCwOTLU bqrbsoW8nXi4kVOhDfXpF18+cp1Yr3nCgY+tDusXMDVSeHIimGVaPOcAGCpi99NCHoOw EIn3swXRTZnVsYwESh3C38Ob88lR3zQvjDJaSbxB9aTg9T3ni9fNNIqJFqOOgW4vhOYe Xk8vunLfA+10q5BKzpSxemSWWJKUvqqqbRF9AbWaqgmgGNgbMR0vL+HSIikrwlHX9oER WetQ== 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=2RcyNuvhxtc3XAp6KUXXBEZGfBTKoyRNmah0KdJRqUM=; b=fXG4pjRv22aV4vvGjJqMDFip2QO4hZceEUux1K5WKb4ZuynUxLOc5mjS8Vz3zAenqW mbqy1I4cPcgqAEnYWSYaMtit/APyrhhmI1TTiIXPe0ydmyzJ0MjzvRwlTF9Y2bxs4zX6 TUqoMac8ySqkWWgWegjXk1iL7xFyxQlcXf1tmkmI5BJaPj0+DwW1TqMTZGk3oylb8XP2 CajcOMj75f+P/k/afEP9cSsDEptCYAX1Iy1AFsnLq5o/G+z+Wj5ZtgSyW9n56/t0bDv9 15y8yECKuoDz+yXCPb+kv9Rl4BwkNuavY1lhPlKl/K+0BR2FGMP7NBW7pJ6UCFLVNEzR 6IjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=s+uK2CVy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=o+Tf43pK; 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 dz10-20020a0564021d4a00b00457fb8f2a64si16572055edb.563.2022.10.19.08.10.58; Wed, 19 Oct 2022 08:11:25 -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=s+uK2CVy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=o+Tf43pK; 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 S230154AbiJSPGR (ORCPT <rfc822;samuel.l.nystrom@gmail.com> + 99 others); Wed, 19 Oct 2022 11:06:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231617AbiJSPFF (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 19 Oct 2022 11:05:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50FEB17A023 for <linux-kernel@vger.kernel.org>; Wed, 19 Oct 2022 07:59:04 -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=1666191373; 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=2RcyNuvhxtc3XAp6KUXXBEZGfBTKoyRNmah0KdJRqUM=; b=s+uK2CVyfeRWS2SM8ONtEm3ezF4TKCfBKPBHIwbQeW7/3EKdt2DXK8Se8xiredxeNeCSkY ZKidWJ9kOFMnJ+GDRhqzajlfU0p4AFkX17OY/4V8RDFxWqEJS/1ZvxtBmCOcbU/4l2IV5+ uARnYyoVv6Nyvh9wOtzsxW1T3vJw5LOkY1LuXAHyxPLMVW6YaxF14EZEX4gyzIy+5CXUjS vS1F3O108Xc1xgSipOJuPxZcLQ/qV1jeZloh/cC1xGCqj2wAIwT9zN8nuby6knA2dC3umy BQvb2BMGIRylFs6NDquzoIBMVcnZI7H6sM7m8P0T/FddSctNfiRBDKDOqpiRPg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191373; 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=2RcyNuvhxtc3XAp6KUXXBEZGfBTKoyRNmah0KdJRqUM=; b=o+Tf43pKW3jb3K3SYt/Uyhx64JMO0G2cG8/ulnFuahJncjT6ev9pQxCcwgJEpI8Oeo5SuX YSUluQ/obMklGtAg== 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, Richard Weinberger <richard@nod.at>, Anton Ivanov <anton.ivanov@cambridgegreys.com>, Johannes Berg <johannes@sipsolutions.net>, linux-um@lists.infradead.org Subject: [PATCH printk v2 20/38] um: kmsg_dumper: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:42 +0206 Message-Id: <20221019145600.1282823-21-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?1747129241497581372?= X-GMAIL-MSGID: =?utf-8?q?1747129241497581372?= |
Series |
reduce console_lock scope
|
|
Commit Message
John Ogness
Oct. 19, 2022, 2:55 p.m. UTC
Rather than using the console_lock to guarantee safe console list
traversal, use srcu console list iteration.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
arch/um/kernel/kmsg_dump.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
Comments
On Wed 2022-10-19 17:01:42, John Ogness wrote: > Rather than using the console_lock to guarantee safe console list > traversal, use srcu console list iteration. > > Signed-off-by: John Ogness <john.ogness@linutronix.de> > --- > arch/um/kernel/kmsg_dump.c | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) > > diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c > index 3a3bbbb22090..44a418dec919 100644 > --- a/arch/um/kernel/kmsg_dump.c > +++ b/arch/um/kernel/kmsg_dump.c > @@ -16,20 +16,17 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, > struct console *con; > unsigned long flags; > size_t len = 0; > + int cookie; > > /* only dump kmsg when no console is available */ I agree that it is perfectly fine to use RCU here. The previous code was just a best effort. The kdump was done without console_lock() so that the console might get available in the meantime. I guess that it is not a big deal. The dumper is called typically only during panic() where new consoles are not added. > - if (!console_trylock()) > - return; > - > - for_each_console(con) { > + cookie = console_srcu_read_lock(); > + for_each_console_srcu(con) { > if (strcmp(con->name, "tty") == 0 && > (console_is_enabled(con) || (con->flags & CON_CONSDEV))) { This is slightly more racy than the previous code. Only one console could have CON_CONSDEV. It might be moved to another console when the list is manipulated. As a result, rcu walk might see zero, one, or two consoles with this flag unless the flag is moved carefully. Anyway, this check does not match the comment and does not make much sense to me. It is true that CON_CONSDEV flag is used only for registered consoles. But messages are printed on the console only when CON_ENABLED flag is set. IMHO, we should check only console_is_enabled() here. Adding Thomas Meyer and Richard Weinberger <richard@nod.at> into Cc. Thomas added this check in the commit e23fe90dec286cd77e90 ("um: kmsg_dumper: always dump when not tty console") and Richard pushed it. > break; > } > } > - > - console_unlock(); > - > + console_srcu_read_unlock(cookie); > > if (con) > return; Best Regards, Petr
diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c index 3a3bbbb22090..44a418dec919 100644 --- a/arch/um/kernel/kmsg_dump.c +++ b/arch/um/kernel/kmsg_dump.c @@ -16,20 +16,17 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, struct console *con; unsigned long flags; size_t len = 0; + int cookie; /* only dump kmsg when no console is available */ - if (!console_trylock()) - return; - - for_each_console(con) { + cookie = console_srcu_read_lock(); + for_each_console_srcu(con) { if (strcmp(con->name, "tty") == 0 && (console_is_enabled(con) || (con->flags & CON_CONSDEV))) { break; } } - - console_unlock(); - + console_srcu_read_unlock(cookie); if (con) return;