Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1425289lqm; Thu, 2 May 2024 14:40:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUWeZBmRKvdy7Hq1X5EXAk/fIi6V0ZhgdB4qVwvMgmskt72ylP9LiCFf3LYTRq7Pnn8T9EV41R0kO3kbSu4HhiVxiKYnAYNouy3s8EHzw== X-Google-Smtp-Source: AGHT+IFz7Pzd3waX6+ttd9F98CDni6KGjhnVRp0UVfAxIagd6I9NEnEaZL2AIZfpi8tOnKmFDDOp X-Received: by 2002:a05:6214:d48:b0:6a0:8da7:3267 with SMTP id 8-20020a0562140d4800b006a08da73267mr2016490qvr.7.1714686032073; Thu, 02 May 2024 14:40:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714686032; cv=pass; d=google.com; s=arc-20160816; b=lELX/5cvswHFjfMzCO+iJhDzl748aGLAQ0clHwVzN75ZNdsc7icZXgN+A2BKCGWjyR JoIb093i7sCrrp4rLbTlEcWANplEIWbjm3yIU+m7boLAJeah9gKA++oATM48oNny3/u0 kF7kfbJzB67RND5mQ72d7NeEFKX4BGcLn8iJ/yv+Me19jYbUU6QtPj6Q1l8GsA8QR/GJ zXarhNTgz6XbclZV/FfdE0Ijrr/bB6FrlIw/nuW/UXURDb7+/QACUX+TNM8SBnkjxo2M GMS0PPgSQ04cqs5cOA+45RpNw1F57VsvZ8CuA5tyj89U9PUehZ0P0eYROTn3ZpKIgO9M GI8w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=SspE94wEVwK1yFu/e9otElRRg8AlYMKwqViOUc8d8w4=; fh=/NZX815RJy/ecOe1WbZ023sSZUJKZnpaeIZwQG5Ym7U=; b=xbPdBRRqH1R0O4QBJP9af/WtcmYXnYP0CIsIn0T4c4o8pcl4nlw1xPmaX7dYUP7elt TtwdNWD4g52bRdq9a0836tzbwIIXuQ14Ri929cVbZv/xkW6pE5ilI/Gj1TSWd79Lw0WG 6/5MmVLbpSK3AldfDEjpJ3cL2gV0Dvk5HcwQpIjSjVWaGEBWBNmqnqWg3N/5B3gUKm7n momSWO/fmrqwUYPXQM/M6F9xsI8Pmlln1X82z//CzwOwNoqzbnWYf4vVHyA0Q+cLDQst ydx3+wo1WtAXzM/NNwDueCkUbZfI4MF7QwKVR4Vfu0TXx7oh0nckkG1+/J0G5opSGWpk L03A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mJfuKLmN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-166961-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166961-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gy4-20020a056214242400b006a0cad19b3esi1844369qvb.43.2024.05.02.14.40.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 14:40:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166961-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mJfuKLmN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-166961-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166961-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CA02C1C20C5E for ; Thu, 2 May 2024 21:40:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5F8E21C6895; Thu, 2 May 2024 21:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mJfuKLmN"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xTqSDxmT" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DE6A1BED8F for ; Thu, 2 May 2024 21:38:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714685931; cv=none; b=d23DjOjbR+bOktP3AedJP1XfA65Z+9uNS2fGNwoP3yN4RFCJ51wpOCpuv4zRCMj9u+Q5cvboyVwFEkGVVWUKB6unpq8aq/+QJaePhzeKPTWLZ13/HS82HZYvhCXi55t+mtu/mpEi3a35DNJv0Mn4t7Sc1pu22u6NxWBSSx8V4cg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714685931; c=relaxed/simple; bh=nzXHdmgGHM2QSq1RQgJ659dlvXdtfhLYf/m9dCbBats=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s+i/ng6coSUcfk5XMcJLA7S/cZZaQn1t0DUWniyHceGUFj39Yyk4Xvj5nGeSInYdlY9phsD+kF4FA4zjjpqh//8Si5tg99NtR0xCrldNQYQAHg2KPz10c2MY76HwU9vERAB9ho5XqQJ4vNYowUVHE9ytjRjzpc+s7632GQP/uog= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mJfuKLmN; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xTqSDxmT; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1714685928; 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=SspE94wEVwK1yFu/e9otElRRg8AlYMKwqViOUc8d8w4=; b=mJfuKLmNTjK4pgFYAss3hLTLyB1zfj0nHGCUtoj+5jSLaBgG1ZbNN6BDxiPwaKjfnruNob ivrP0+5Y+gl+pMBdAkhN6sGmwy+3lZ5l3YT+TWm5rRY9z1Am8gPua72Wj+raTXrTr+9sNu Wajxvhlh+uNeNMWfw0owhevElikx5/Y121AURJkciqxuYhYmnPIMigmht+FODetBhM2oKd ac4RnvhmIJLYWxOLPFj8tibSx4ZHb8KHQ2XgWWm1jTmGWECdxkigixb6ImEWicdHgXYNsd xMO0rvUWe93Ds5u2Bcg2n0Ioh/UXZ0BleyqglqQGrQJNVXVzFTWmIoT8OqFCuw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1714685928; 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=SspE94wEVwK1yFu/e9otElRRg8AlYMKwqViOUc8d8w4=; b=xTqSDxmTEAdynqiThYO1tnJXr3Gh2+hDN/rIFMuwWIG0OWlukLMQhpnBPXn6XkDhZnxAS/ 3ocP/2usEwamLiDw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v5 10/30] console: Improve console_srcu_read_flags() comments Date: Thu, 2 May 2024 23:44:19 +0206 Message-Id: <20240502213839.376636-11-john.ogness@linutronix.de> In-Reply-To: <20240502213839.376636-1-john.ogness@linutronix.de> References: <20240502213839.376636-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit It was not clear when exactly console_srcu_read_flags() must be used vs. directly reading @console->flags. Refactor and clarify that console_srcu_read_flags() is only needed if the console is registered or the caller is in a context where the registration status of the console may change (due to another context). The function requires the caller holds @console_srcu, which will ensure that the caller sees an appropriate @flags value for the registered console and that exit/cleanup routines will not run if the console is in the process of unregistration. Signed-off-by: John Ogness --- include/linux/console.h | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 33a029d976c3..aea4f5aa4a45 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -428,28 +428,34 @@ extern void console_list_unlock(void) __releases(console_mutex); extern struct hlist_head console_list; /** - * console_srcu_read_flags - Locklessly read the console flags + * console_srcu_read_flags - Locklessly read flags of a possibly registered + * console * @con: struct console pointer of console to read flags from * - * This function provides the necessary READ_ONCE() and data_race() - * notation for locklessly reading the console flags. The READ_ONCE() - * in this function matches the WRITE_ONCE() when @flags are modified - * for registered consoles with console_srcu_write_flags(). + * Locklessly reading @con->flags provides a consistent read value because + * there is at most one CPU modifying @con->flags and that CPU is using only + * read-modify-write operations to do so. * - * Only use this function to read console flags when locklessly - * iterating the console list via srcu. + * 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 the console state is valid (CON_SUSPENDED/CON_ENABLED) + * and 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: The current value of the @con->flags field. */ static inline short console_srcu_read_flags(const struct console *con) { WARN_ON_ONCE(!console_srcu_read_lock_is_held()); /* - * Locklessly reading console->flags provides a consistent - * read value because there is at most one CPU modifying - * console->flags and that CPU is using only read-modify-write - * operations to do so. + * The READ_ONCE() matches the WRITE_ONCE() when @flags are modified + * for registered consoles with console_srcu_write_flags(). */ return data_race(READ_ONCE(con->flags)); } -- 2.39.2