Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp912005rwi; Mon, 31 Oct 2022 09:00:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lmmeZCTWTPd3E2DBpdZTPrkL3XLgfAaY8bE2j5pJ/3vtfN7JR+w1U/Dvwz/nmR1Rjmdh3 X-Received: by 2002:a17:907:a059:b0:78d:1a16:fc5c with SMTP id gz25-20020a170907a05900b0078d1a16fc5cmr13905102ejc.31.1667232031051; Mon, 31 Oct 2022 09:00:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667232031; cv=none; d=google.com; s=arc-20160816; b=McrzZ3xLTk33SYvQDgKj0ubQognnGYYnfkfm25tdr+SM1a1OPTt27rspiBoB5IPWz9 OD/UotAQsPvTSgmRN5S0ZqlEgZOCqZCU0XnsZLEL9XvYxQTzqBnVPnTbHvCEUIM5iExC dHtLrNqvQLKUB/ZVDyJxT2LbCqRNgISgCoiZfrBPekJ+6d1mj03bgwGaDrY282VbN9pA NFpvgGqF4QXvzGGi2EtfYlwRWhT+OTAySJDBySItECyfruSDrzvv9hBpktrrQU4lMepC xrQCOObduj/+2muK5CsDWGqWqTbRR6B8Wfeb6YKkGOyFpq7yJcdlyfCcgQK14Mnpd8Yu 0KuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=oIPJ91nyWm33HO4GBNncrIzLvJk3C6XXN8kbJVT6Als=; b=dHLaY6x14a3lSMhtijv+/KwClBT3OYojLrzS9gfoDkL3VDXmuKlfxHzf5G8zBZ7yNa Eg3Tl0e8jzVwWY92R8WjamYsnEyGoIQd5gQwMJkQumm+94tRqIpf3ziLCU+o73X/RME8 G7JCvM2Ao7GKvYmbFH2J7uH/xZMJ9Is2J8hY67L9UobyBB+iZZnWqjSDTTcu3AGoYIVg Si/o6sn9k/zV7B5mNL/qJHf02Jakeow9CjpVztoFzWs/RGZN9/ibUuJeleCBg4CLzDeB YE+nIlbPKCtEZ+5ZKYl3BddoDWyNWtKp9HOaK1VIXWmKuzYu8VLPddK7mVowG6JTHZtK /AZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kB0l6adN; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp18-20020a170906c15200b007a7424836d5si9805254ejc.234.2022.10.31.09.00.06; Mon, 31 Oct 2022 09:00: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=kB0l6adN; 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 S230416AbiJaPjH (ORCPT + 98 others); Mon, 31 Oct 2022 11:39:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231871AbiJaPjD (ORCPT ); Mon, 31 Oct 2022 11:39:03 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37B9CBA0 for ; Mon, 31 Oct 2022 08:39:02 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667230740; 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=oIPJ91nyWm33HO4GBNncrIzLvJk3C6XXN8kbJVT6Als=; b=kB0l6adN1LX8PDBUlXlrjidw1Q1RbCi4wPf1JQSFrQeQPd0uIJkfAEL9D7c5tMgkAs/36z job5Ow7WH+O0TUZ+uxnEVsjIis3KVeJkA/Q1IcC/XR65cGnNtuNFIPWrrkjeftc+nI83xl NAYWFzitkeZENUTgQI1PHaicyvHrxssfcFG0KQ5R6j22TPESblmieeqKAb2jayMK+Xfeiz njghTgA2P54+0jnh4wHdJFBWzZCWwlBVwtzQl/KEKaoPzHVmCurLYZ5UBnf5IAcLypIFVY tHWLmTTflh+WgonNbOISTsa8ry07x1UBki/YLaq+RjcvNNc3SjXkAayeneScTg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667230740; 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=oIPJ91nyWm33HO4GBNncrIzLvJk3C6XXN8kbJVT6Als=; b=oNuuyuAUxFHbKSQ87M/jZjiv41v/VqtmL43Qr6YyI875wpMWQ9O7ZoQ8DJPXKzw4UZ4N/F gIQQvd+IzyELeQCQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH printk v2 05/38] printk: use console_is_enabled() In-Reply-To: References: <20221019145600.1282823-1-john.ogness@linutronix.de> <20221019145600.1282823-6-john.ogness@linutronix.de> Date: Mon, 31 Oct 2022 16:45:00 +0106 Message-ID: <87ilk09f57.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain 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: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-10-21, Petr Mladek 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