Message ID | 20221019145600.1282823-24-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 y7csp379748wrs; Wed, 19 Oct 2022 08:11:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6WjZjGMbLPTEny88Gjx4E36h2t02wgEpuph+0H4rk8uphPfZ5c+uYMJ2rlJ0UDaa9flMw9 X-Received: by 2002:a17:907:96a3:b0:790:65a:3a0a with SMTP id hd35-20020a17090796a300b00790065a3a0amr7441041ejc.728.1666192290836; Wed, 19 Oct 2022 08:11:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666192290; cv=none; d=google.com; s=arc-20160816; b=gGNGnBTXfVLo4Gdl6Ry4PySL2+hPazILhvN7/bn8TBbTMXGTkcxadUovK1M2QR50xb 9iQ+ABpr4DhmmEpcLsWrtqzFXUYGxWqOf8oOYxjSoyqrSufV7Cs9Wx1o5TAc6w4GoZdA OEMfdJiQ5aSg6RndERxsSoZ4bP6IU7ZMnjRqA2JaSCIJWyK20eD5NEkhZ8sl5CJP/0ap p/pebry7+BeYReZZJ+VFjzvBumT3KvoEoP5pijPpv1XrxJceBPr+WjY+eur+fsIJhvs1 WayBCztrFK3L+zF9Zpl+RKJ3iAR7B3jto9wIiU5SSze0ZGyG6bVxlq6OghVqN01tMHk3 p4Rw== 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=Rxx7a00tnCHfnWXA978Xi0IL/mfHFWoLJumPfZjxuVQ=; b=IdB2bEluVJWdDatBRIh2rxAIFlLyjzFHxI5+PvxTwSMTQicEEblaq/ukmAeucX/nC5 3o/BPd99hk5cJJHwReK+AE7HZWVEqOLDDMwB+6VLhXIsWpkkzdxTsDJf230ZKRw6so0C mnqIknumkdhwp00NHmjr0kq/SDGpgS1U0jTmIkswMBPp6qR4sTQD7IXfimnDrw308qLW Zs43wkYIEZj0/0nsuHTbzaMh4xQlmnVtS49ZxASpnS4hIW3JdDioG40Ntb1fBp/IRtTq MQDZHCkiULeuIhDBr1t+uBzCcspxRNS55oExevpZ130C+bljanWyOWJRL8204LRVZqNh dFsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=odMAd6jZ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 q14-20020a056402040e00b0045d8bff7b1asi7003968edv.403.2022.10.19.08.11.04; Wed, 19 Oct 2022 08:11:30 -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=odMAd6jZ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S231927AbiJSPGf (ORCPT <rfc822;samuel.l.nystrom@gmail.com> + 99 others); Wed, 19 Oct 2022 11:06:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231835AbiJSPFk (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 19 Oct 2022 11:05:40 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EB4B13D0F for <linux-kernel@vger.kernel.org>; Wed, 19 Oct 2022 07:59:09 -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=1666191375; 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=Rxx7a00tnCHfnWXA978Xi0IL/mfHFWoLJumPfZjxuVQ=; b=odMAd6jZuExx16Yi0L8xd1hm9Jh9VTjUOvjUUgrX8qFZQuCWOzfAaZvh89StL/uY5ZVjZ4 7F0py/hns3GzhNljNb4CSr+P5RvwEKeVFVSo7ucX0apDwGWsb+zxnCp4263f8YKJ9a5ej1 2rV6t+eru8+PT568/dvEv0WiF4bn/adCAwyLxplBuLF8aZHWoHD+n5evDi2JVgnqY8rjNr Pt3sSFfwb1FV+WRk5mWlhtAOGR/p0dm76Sw3rc+OGGbhM33YJGS18mUoUTGARbsvXP77z4 CFsQZ+FmootigSKYJ31Vjh5hqGF6+j1S9tpl8U4eAuAup1tordjr0REfQ7pl7A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191375; 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=Rxx7a00tnCHfnWXA978Xi0IL/mfHFWoLJumPfZjxuVQ=; b=q9rIFA276lgWZLXV5mkpOktuUZD6YWke7bg19dKAJViyJu9A6OrFIkzYrQzLJ2n8EtnLIQ id3MWXWGrsWj0ZDA== 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, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jiri Slaby <jirislaby@kernel.org> Subject: [PATCH printk v2 23/38] tty: tty_io: document console_lock usage Date: Wed, 19 Oct 2022 17:01:45 +0206 Message-Id: <20221019145600.1282823-24-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?1747129247991016914?= X-GMAIL-MSGID: =?utf-8?q?1747129247991016914?= |
Series |
reduce console_lock scope
|
|
Commit Message
John Ogness
Oct. 19, 2022, 2:55 p.m. UTC
show_cons_active() uses the console_lock to gather information
on registered consoles. Since the console_lock is being used for
multiple reasons, explicitly document these reasons. This will
be useful when the console_lock is split into fine-grained
locking.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
drivers/tty/tty_io.c | 8 ++++++++
1 file changed, 8 insertions(+)
Comments
On Wed, Oct 19, 2022 at 05:01:45PM +0206, John Ogness wrote: > show_cons_active() uses the console_lock to gather information > on registered consoles. Since the console_lock is being used for > multiple reasons, explicitly document these reasons. This will > be useful when the console_lock is split into fine-grained > locking. > > Signed-off-by: John Ogness <john.ogness@linutronix.de> > --- > drivers/tty/tty_io.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c > index 2050e63963bb..333579bfa335 100644 > --- a/drivers/tty/tty_io.c > +++ b/drivers/tty/tty_io.c > @@ -3526,6 +3526,14 @@ static ssize_t show_cons_active(struct device *dev, > struct console *c; > ssize_t count = 0; > > + /* > + * Hold the console_lock to guarantee that no consoles are > + * unregistered until all console processing is complete. > + * This also allows safe traversal of the console list. > + * > + * Stop console printing because the device() callback may > + * assume the console is not within its write() callback. > + */ > console_lock(); > for_each_console(c) { > if (!c->device) > -- > 2.30.2 > Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
On Wed 2022-10-19 17:01:45, John Ogness wrote: > show_cons_active() uses the console_lock to gather information > on registered consoles. Since the console_lock is being used for > multiple reasons, explicitly document these reasons. This will > be useful when the console_lock is split into fine-grained > locking. > > Signed-off-by: John Ogness <john.ogness@linutronix.de> > --- > drivers/tty/tty_io.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c > index 2050e63963bb..333579bfa335 100644 > --- a/drivers/tty/tty_io.c > +++ b/drivers/tty/tty_io.c > @@ -3526,6 +3526,14 @@ static ssize_t show_cons_active(struct device *dev, > struct console *c; > ssize_t count = 0; > > + /* > + * Hold the console_lock to guarantee that no consoles are > + * unregistered until all console processing is complete. > + * This also allows safe traversal of the console list. This is more or less clear. show_cons_active() reads a lot of information from the registered consoles. > + * > + * Stop console printing because the device() callback may > + * assume the console is not within its write() callback. I wonder if this is based on some real example or if you just want to stay on the safe side. It is perfectly fine to stay on the safe side. But we should make it clear if the dependency really exists or if it has to be investigated later during the clean up. > + */ > console_lock(); > for_each_console(c) { > if (!c->device) Anyway, thanks for adding the comment. Best Regards, Petr
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 2050e63963bb..333579bfa335 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3526,6 +3526,14 @@ static ssize_t show_cons_active(struct device *dev, struct console *c; ssize_t count = 0; + /* + * Hold the console_lock to guarantee that no consoles are + * unregistered until all console processing is complete. + * This also allows safe traversal of the console list. + * + * Stop console printing because the device() callback may + * assume the console is not within its write() callback. + */ console_lock(); for_each_console(c) { if (!c->device)