Message ID | 20221019145600.1282823-6-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 y7csp377950wrs; Wed, 19 Oct 2022 08:08:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM74tuHhIf9I63vyGIhy8e2rIE2l3C98QGp92cXESP67fYYo71Xhzm4i9feHVrGfsp64wlbV X-Received: by 2002:a05:6402:40d0:b0:45c:d00a:82bd with SMTP id z16-20020a05640240d000b0045cd00a82bdmr7819459edb.288.1666192089047; Wed, 19 Oct 2022 08:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666192089; cv=none; d=google.com; s=arc-20160816; b=FTWlSjk0+RB0edg79bCSSM+vIXmc+SvE2K3GipnqiM1plwxiTFnsCtDJWadZG4hmW9 Bq9/f3RkF+F2FpgGLnnX4w6HcVbz+rOoRz1+6ZJSeoJVMKSTl0a9BC7xiZDLH4uPg3on /RLQXFNl/Tl2KPsFTFubREm8RADImLjJI85wISJh3fgWxPCE+6Q4Jt9vYVmmU+oBPGQ4 U++5RC6SVV2MuLEnmMvNujxDkzkphGdG8a9KA0/tD4adNmGKDCp1lNrD1AMr0GvYdGIC fTtxCbZuC7Gu0hnsS3DV5KubEYfbZUye5tCWEw/up8uP5YsaRWW+J62AfBhWUhNco08v 9CAg== 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=MP5rgFSdehBCliWVe71JQUPCb1f669tU8saiCWaIDO0=; b=r1yO8H6Io6OPmq/VoahRY0BG7DQBGtUI5i47fTugfsjGc61KbLYvQeUUG3XtYxgD9e lzyl6g64KfSYAQh7aNNYhN4kGnP63FKygrl4rRyQzKMqJe2E3JFjgQUfzjE8JNYSWfLm 0Ii20KjIbJ5JQc5C+0h/4uHBE8FLBph+o4QF6HlQ3frZUvUcrzhjYDcjUeIKKLxrZVk9 5g5Hx3t1KNV1GOy5TAa+/xMl2Wtp1TogvCN+0W7eNU/2gJqqSqMaXp3vyNfv6Jw0yTDH UqVxfHyh9Y4Qsn7pIDrKPeJ8uLBM9uFoGgJNzYVxirH7VOIvk4KGV9H+OPnFKzd8+/la taQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SLqa5Phc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=ozZhE1jN; 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 n29-20020a50935d000000b0045725a5b76csi13332411eda.294.2022.10.19.08.07.18; Wed, 19 Oct 2022 08:08:09 -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=SLqa5Phc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=ozZhE1jN; 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 S230010AbiJSPE2 (ORCPT <rfc822;samuel.l.nystrom@gmail.com> + 99 others); Wed, 19 Oct 2022 11:04:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232059AbiJSPEC (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 19 Oct 2022 11:04:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62B6A1911C2 for <linux-kernel@vger.kernel.org>; Wed, 19 Oct 2022 07:58:33 -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=1666191365; 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=MP5rgFSdehBCliWVe71JQUPCb1f669tU8saiCWaIDO0=; b=SLqa5PhcnifAXBxPjzPq8RQ5wWHDsFsKLOjJ5Bmh9ZGDeMItqEb2c5andZCY9TcUyGDIR/ dkOOQxmdmn7/PnLwAAjrGDp8lt9Uz8mAMEoOd7urbGXYVldEk8zYCa8/iAY1dVNRfX1p+J Ha+qK8DetElb0MoGktri3Xu4lx9C3kUh6AtB+1DIReSvn7JRz1gWJTFDzw08nHyTiCmChQ XP4mRnKpUirH0pvAQWYC+E4LgSbE3mXbcssJIvwElnPgdqtXfCvaf4dvjVy2e7JmBlnloB h/m+zkpsEomfdmsy9Cb/TNtCQcjleQpQn0jWgpkY1m6W6keiAq6wL/v4NRO/PQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191365; 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=MP5rgFSdehBCliWVe71JQUPCb1f669tU8saiCWaIDO0=; b=ozZhE1jNVxKFfb0xYXFWRlrgrguzkQU0rcQ9xxPUoqXcDFSb1uLSsqks/WR9QsIUMSaQe8 g5NlOPi7VRafb3CA== 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 Subject: [PATCH printk v2 05/38] printk: use console_is_enabled() Date: Wed, 19 Oct 2022 17:01:27 +0206 Message-Id: <20221019145600.1282823-6-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?1747129035844624683?= X-GMAIL-MSGID: =?utf-8?q?1747129035844624683?= |
Series |
reduce console_lock scope
|
|
Commit Message
John Ogness
Oct. 19, 2022, 2:55 p.m. UTC
Replace (console->flags & CON_ENABLED) usage with console_is_enabled().
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
kernel/printk/printk.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Comments
On Wed 2022-10-19 17:01:27, John Ogness wrote: > Replace (console->flags & CON_ENABLED) usage with console_is_enabled(). > > Signed-off-by: John Ogness <john.ogness@linutronix.de> > --- > kernel/printk/printk.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index e8a56056cd50..7ff2fc75fc3b 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -2658,7 +2658,7 @@ static bool abandon_console_lock_in_panic(void) > */ > static inline bool console_is_usable(struct console *con) > { > - if (!(con->flags & CON_ENABLED)) > + if (!console_is_enabled(con)) > return false; This allows to use console_is_usable() without synchronization against modification of the state. I guess that it will be needed for the printk kthreads. But it is not needed at the moment. We should document why it is needed and why it is safe. > > if (!con->write) > @@ -2944,7 +2944,7 @@ void console_unblank(void) > console_locked = 1; > console_may_schedule = 0; > for_each_console(c) > - if ((c->flags & CON_ENABLED) && c->unblank) > + if (console_is_enabled(c) && c->unblank) > c->unblank(); > console_unlock(); The reading of the flag is actually synchronized against modifications here. I guess that we need this because c->unblank() probably is not safe against other operations with the console, e.g. c->write(). Well, it probably does not matter if reading of CON_ENABLED flag is serialized against modifications. So, it is perfectly fine to use the "racy" function. > @@ -3098,7 +3098,7 @@ static int try_enable_preferred_console(struct console *newcon, > * without matching. Accept the pre-enabled consoles only when match() > * and setup() had a chance to be called. > */ > - if (newcon->flags & CON_ENABLED && c->user_specified == user_specified) > + if (console_is_enabled(newcon) && (c->user_specified == user_specified)) This is not racy because newcon is not in console_list at this point. So that the state can't be modified by another callers. Anyway, it is not explicitly synchronized, so we need to use console_is_enabled with data_race() annotation. > return 0; > > return -ENOENT; Best Regards, Petr
On 2022-10-21, Petr Mladek <pmladek@suse.com> wrote: >> static inline bool console_is_usable(struct console *con) >> { >> - if (!(con->flags & CON_ENABLED)) >> + if (!console_is_enabled(con)) >> return false; > > This allows to use console_is_usable() without synchronization against > modification of the state. I guess that it will be needed for the > printk kthreads. But it is not needed at the moment. It will be needed once console_lock is no longer providing the synchronization for console->flags (later in _this_ series). I will add to the commit message that this is a preparatory change for when console_lock no longer provides this synchronization. >> @@ -2944,7 +2944,7 @@ void console_unblank(void) >> console_locked = 1; >> console_may_schedule = 0; >> for_each_console(c) >> - if ((c->flags & CON_ENABLED) && c->unblank) >> + if (console_is_enabled(c) && c->unblank) >> c->unblank(); >> console_unlock(); > > The reading of the flag is actually synchronized against modifications > here. I guess that we need this because c->unblank() probably is not safe > against other operations with the console, e.g. c->write(). Again, we will need it later in this series when holding console_lock does not provide the necessary synchronization. >> @@ -3098,7 +3098,7 @@ static int try_enable_preferred_console(struct console *newcon, >> * without matching. Accept the pre-enabled consoles only when match() >> * and setup() had a chance to be called. >> */ >> - if (newcon->flags & CON_ENABLED && c->user_specified == user_specified) >> + if (console_is_enabled(newcon) && (c->user_specified == user_specified)) > > This is not racy because newcon is not in console_list at this > point. So that the state can't be modified by another callers. > > Anyway, it is not explicitly synchronized, so we need to use > console_is_enabled with data_race() annotation. For this case, it makes sense to _not_ use console_is_enabled(). This code will be synchronized against writes even after console_lock has been relieved of this responsibility. Originally I wanted to replace _all_ checks with console_is_enabled(), but since synchronization is rare, I'll keep the manual checks for those (and add a comment that it is not a data race). John
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e8a56056cd50..7ff2fc75fc3b 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2658,7 +2658,7 @@ static bool abandon_console_lock_in_panic(void) */ static inline bool console_is_usable(struct console *con) { - if (!(con->flags & CON_ENABLED)) + if (!console_is_enabled(con)) return false; if (!con->write) @@ -2944,7 +2944,7 @@ void console_unblank(void) console_locked = 1; console_may_schedule = 0; for_each_console(c) - if ((c->flags & CON_ENABLED) && c->unblank) + if (console_is_enabled(c) && c->unblank) c->unblank(); console_unlock(); @@ -3098,7 +3098,7 @@ static int try_enable_preferred_console(struct console *newcon, * without matching. Accept the pre-enabled consoles only when match() * and setup() had a chance to be called. */ - if (newcon->flags & CON_ENABLED && c->user_specified == user_specified) + if (console_is_enabled(newcon) && (c->user_specified == user_specified)) return 0; return -ENOENT;