From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CDAACE6BF1B for ; Fri, 30 Jan 2026 15:51:07 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4f2gTk1D9kz2xT4; Sat, 31 Jan 2026 02:51:06 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1769788266; cv=none; b=OXWQ9DEHv/dQeeW+4so9MtMmhVdeENuA/5fu48c87964QtguaLPF/hJYDQhm2md7liM/8ByLtZxzMDkAVtoI3JoM4HfgPLo+nht7+muBIhx2Yfgb1kJofUzTYyweRctFRaEk18/8hU4fVc5L9HE7pUU/uuAlOCqjGJsW02DeUy7bzz9AUmg6LVrWUe2mQa3xnYFTGDkCLebIptC+YDFkt6oB8JXmGtUYFzdYPcXVGyz70OZ+1txRuLQxXhuqEDSDOlxr9NnH/NVa477r+LALeQuRuoxkJx5W53CZ0lF7hWoACFFJLm1YwsSlUtNz/LvZKj0ZcnCJtFzsrgfTr43iEg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1769788266; c=relaxed/relaxed; bh=VKYYYdqumsniIC39YChzbfba4q3RKQuXPKPNETM4jMs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=Jpn3ie/E8T3IRrC6NSoaQhFIKz84bhHRVtYOIaAWghXVmfB6lFc5yRqAZrfXb2gyDNxaFDODPocayj8XTJFmqrP0xIBiNAWIPG/Bm/R50LXsWKdrDmi3bJEfs3dwXn9sKU/yCzRV6/b40l88gVaeqmFBUUH0LM1DH4y1IjlKJsvtxZcZ5lmWSr67Zl93zRrpVHYUNGhw7HJq+OTBguyrYfIf0HPLcHielAdrpf8z0qaSCrofGluDL7qC6ozu5qfZC0+nxeMEPyN3OtKVYCOLfiUJPMWSP0IxU3om1zWSdEEDBxTE7k+HSwXXTVYrY5E/+Z0m2xIO9/bgz75FmM4o+g== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; dkim=pass (2048-bit key; secure) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=vcbvqM8z; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=QdMWcBGT; dkim-atps=neutral; spf=pass (client-ip=193.142.43.55; helo=galois.linutronix.de; envelope-from=john.ogness@linutronix.de; receiver=lists.ozlabs.org) smtp.mailfrom=linutronix.de Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=vcbvqM8z; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=QdMWcBGT; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linutronix.de (client-ip=193.142.43.55; helo=galois.linutronix.de; envelope-from=john.ogness@linutronix.de; receiver=lists.ozlabs.org) Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4f2gTh2Lyyz2xPW for ; Sat, 31 Jan 2026 02:51:04 +1100 (AEDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1769788246; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VKYYYdqumsniIC39YChzbfba4q3RKQuXPKPNETM4jMs=; b=vcbvqM8zYMWsd/tMS8cM3Z8mI0EFVLj960Sgnq06Gp+EE//WNnLbcLZhAA/pMTKCGlvDfP yqke2jH0ufmQ2nSCXnCEz+Jn+XrQJzGXcBaQD7aRlFZRq53PQc5/Ez6pS9vF8H4vaE7v3p 5Os9pnShRRfDny9vUFVCUgpDJtra3pkpEpGkGFqBbqhRd67I4u4yEw2yRumLCICvxBk8BF lYslZ9n7CIZiicXU68jj736XQbVbZj259QlZ9D5cpD/hhtYKt/yvG/sW6XwJQlB9xGg1Yt 1dTW+LYZ7TXgk5cXhk98yy4erq5rCNAMT0/GW3UcnHSmpCbIxRncuJF5VzCABA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1769788246; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VKYYYdqumsniIC39YChzbfba4q3RKQuXPKPNETM4jMs=; b=QdMWcBGTcUpDPEMRRsRb8Xqv5ndFVC6eiO9zg4AEYukrcFUq2iwMVZ0Wp1FzCEeMeF0WzL p1LnaogxsATMNsAA== To: Marcos Paulo de Souza , Richard Weinberger , Anton Ivanov , Johannes Berg , Greg Kroah-Hartman , Jason Wessel , Daniel Thompson , Douglas Anderson , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Jiri Slaby , Breno Leitao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Geert Uytterhoeven , Kees Cook , Tony Luck , "Guilherme G. Piccoli" , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Andreas Larsson , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , Jacky Huang , Shan-Chun Hung , Laurentiu Tudor Cc: linux-um@lists.infradead.org, linux-kernel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org, netdev@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-hardening@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, Marcos Paulo de Souza Subject: Re: [PATCH 02/19] printk: Introduce console_is_nbcon In-Reply-To: <20251227-printk-cleanup-part3-v1-2-21a291bcf197@suse.com> References: <20251227-printk-cleanup-part3-v1-0-21a291bcf197@suse.com> <20251227-printk-cleanup-part3-v1-2-21a291bcf197@suse.com> Date: Fri, 30 Jan 2026 16:56:45 +0106 Message-ID: <875x8j3xre.fsf@jogness.linutronix.de> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 Content-Type: text/plain On 2025-12-27, Marcos Paulo de Souza wrote: > Besides checking if the current console is NBCON or not, console->flags > is also being read in order to serve as argument of the console_is_usable > function. > > But CON_NBCON flag is unique: it's set just once in the console > registration and never cleared. In this case it can be possible to read > the flag when console_srcu_lock is held (which is the case when using > for_each_console). > > This change makes possible to remove the flags argument from > console_is_usable in the next patches. Note that console_is_usable() now also checks for the flag CON_NBCON_ATOMIC_UNSAFE as well. > diff --git a/include/linux/console.h b/include/linux/console.h > index 35c03fc4ed51..dd4ec7a5bff9 100644 > --- a/include/linux/console.h > +++ b/include/linux/console.h > @@ -561,6 +561,33 @@ static inline void console_srcu_write_flags(struct console *con, short flags) > WRITE_ONCE(con->flags, flags); > } > > +/** > + * console_srcu_is_nbcon - Locklessly check whether the console is nbcon > + * @con: struct console pointer of console to check > + * > + * Requires console_srcu_read_lock to be held, which implies that @con might > + * be a registered console. The purpose of holding console_srcu_read_lock is > + * to guarantee that no exit/cleanup routines will run if the console > + * is currently undergoing unregistration. > + * > + * If the caller is holding the console_list_lock or it is _certain_ that > + * @con is not and will not become registered, the caller may read > + * @con->flags directly instead. > + * > + * Context: Any context. > + * Return: True when CON_NBCON flag is set. > + */ > +static inline bool console_is_nbcon(const struct console *con) > +{ > + WARN_ON_ONCE(!console_srcu_read_lock_is_held()); > + > + /* > + * The CON_NBCON flag is statically initialized and is never > + * set or cleared at runtime. > + */ > + return data_race(con->flags & CON_NBCON); If this flag is statically initialized and is never set or cleared at runtime, why is the console_srcu_read_lock required? Why not just: static inline bool console_is_nbcon(const struct console *con) { /* * The CON_NBCON flag is statically initialized and is never * set or cleared at runtime. */ return data_race(con->flags & CON_NBCON); } And even if you do need the console_srcu_read_lock, why copy/paste the implementation and comments of console_srcu_read_flags()? Just do: static inline bool console_is_nbcon(const struct console *con) { return console_srcu_read_flags(con) & CON_NBCON; } John Ogness