Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1426140lqm; Thu, 2 May 2024 14:42:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU5B8SS1tamMxXa88q31uZzrpGw0GH53L192GH/aRVdjIp7ZKJvsftzfNCFGgijJ3JyicJ4GMac1uck16V7QislHR3FIwRUhvyTY7B00Q== X-Google-Smtp-Source: AGHT+IGML/jhS1HaMW7Dzgcg41BGMUMJf5tNZNXb3S+8Rl45wPqeSf3Fkh6JxxR7yVJdJCZ9uAnW X-Received: by 2002:a05:620a:1091:b0:78e:d537:37db with SMTP id g17-20020a05620a109100b0078ed53737dbmr714064qkk.71.1714686158391; Thu, 02 May 2024 14:42:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714686158; cv=pass; d=google.com; s=arc-20160816; b=Z4Oa18zfaWvSDaaGMje+9lNBcDuJUL6Tz+i4rW9TV7z50ApcPT4GpgQd78xSpewZnr vNyMuOlnkxCBBgRZUXLOrUMFkNy0IV4cO5LjXKeVeWL6QKySTWPhPjKcKhgzkmQEIt7z A0H/yHuQA8wi5bkXQ73JRAHr0+DEbfbHhRxneH7vfm0g8ajgC8aDBLRNIBoeCE68eT7g zSYdWWJdqjCnSu8NFLUAJUoIUbSCGSFmBUjxqxK9rG2PY7d8lr5JRLNgAKEXJO3ynB2Y mxTsXws+ZqXwKLq3+aH1dH0x5QVvVQyR/p+MYBgM4cJNoKFktkfV4AZ/h7EkVxe2bIaK Aq2Q== 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=B5pjl5Q+p+FjfYSMKXRHKDtD1jLA4O0osbygvWzIAZM=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=natcf4xy69H55ULyhFluq2T+YQvSsWWJ8eZqI8BLnHcmd43A0CN0VZy/x0asMKdJht ZOwNbhlcNUpHsfSBjAikElolD8tOw3FOhoShSLorv1yxuHc/X67viZIpp2hWmXnIxqqY ReetavucEcmqgWRweSjvKTSHROrllC3mau7SqtGRF2dM0lsfrEgsFUH+fIryUgyFuaz9 Lr2tA7a5g0L0mYv9qcSGp3KNS1rI9Glrn7Hzc8DuHVrbUOtaQlGZhVrvizWLCgYQyhuD 6vodMmwaGk7HPiEf5xSd4OA5uueq15mp8vF6IKuYUJL6LJCJUFh+xCGuRBvoUicEUEaL xPtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=KWmd+jZE; 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-166970-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166970-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l6-20020a05620a0c0600b0078eb967b9d3si1757308qki.369.2024.05.02.14.42.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 14:42:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166970-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=KWmd+jZE; 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-166970-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166970-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 223021C21BB8 for ; Thu, 2 May 2024 21:42:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 326BC20126E; Thu, 2 May 2024 21:38:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KWmd+jZE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dhE/TxHH" 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 67F9B1C6898 for ; Thu, 2 May 2024 21:38:53 +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=1714685935; cv=none; b=o/7oWtLGbhTQZdSQtx0bNQ4AyyEJmfybXHEa1zbzK2ETj2QgW+bHPWaVNT09YxS6X3I0JsHPpe0Ie+Ih7T4DC4ShkvRXvlOysUGguduojIkAIzcPwDnMiT0RNKZN3eihlKLL3SVEchicOB3Z0//XjDehQjO/i55siwmSudqC9Go= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714685935; c=relaxed/simple; bh=eBpAe0m3jkrciUtpy/gK/+A8yIKAuwbXb+fVieGeCys=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qr2kuATVtuhxsO/l1MMkpWfHDMQfcyYZWDa8ekMQt/NP15H1VtLHFp5o1YYeyeo5yjclQwkgAQecSl2/vXTcQHImLhW8JHXObf9PfaChLa3AqKS610yiC1W4fnq18TRJ9AGigjRdr8Un7Uc/jYYNy8GrQk63BlJyzmyvNmp2MVk= 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=KWmd+jZE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dhE/TxHH; 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=1714685932; 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=B5pjl5Q+p+FjfYSMKXRHKDtD1jLA4O0osbygvWzIAZM=; b=KWmd+jZEX4WhqnFPiNK65pGiYeOZgEKMu5AN/162/WiCwuXYdbqJKLQD/QnKltRlnnAij0 izyHNlaCOX6J915DvELmtYN0aAR676WhEdcNF1vwDsQkUxG9eEXqCsrT+zboj5k1lsWarH dnMdcnUDhHxYGyKMuPareTD3HevuWnine+dmb/QpmGVuEyJ8Z9EAkqxki9Ok1tnQ7XJCGk MkJoAPw50nUdDLYQfJeB9tVboRhG3gyrjcRnzLtsRNtg3jAv15QCjm+MpeYuRUuZD2fZcE MbJRD3xxDzsOfELsOpPn/67uCARkb2ZaeuV7jMpV2CPfSTG1Cc56EuzgsU55gg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1714685932; 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=B5pjl5Q+p+FjfYSMKXRHKDtD1jLA4O0osbygvWzIAZM=; b=dhE/TxHHWlXSAOSf/vIr/B7q/57V05gpNTEy9NIuwTae6RV1k1g+RjVvd3jXRhhcwMV59k yweaT8HI61w/T1Bw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v5 20/30] printk: Track registered boot consoles Date: Thu, 2 May 2024 23:44:29 +0206 Message-Id: <20240502213839.376636-21-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 Unfortunately it is not known if a boot console and a regular (legacy or nbcon) console use the same hardware. For this reason they must not be allowed to print simultaneously. For legacy consoles this is not an issue because they are already synchronized with the boot consoles using the console lock. However nbcon consoles can be triggered separately. Add a global flag @have_boot_console to identify if any boot consoles are registered. This will be used in follow-up commits to ensure that boot consoles and nbcon consoles cannot print simultaneously. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 8c93ef6292ac..e1cf0f7d6ff2 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -463,6 +463,14 @@ static int console_msg_format = MSG_FORMAT_DEFAULT; /* syslog_lock protects syslog_* variables and write access to clear_seq. */ static DEFINE_MUTEX(syslog_lock); +/* + * Specifies if a boot console is registered. If boot consoles are present, + * nbcon consoles cannot print simultaneously and must be synchronized by + * the console lock. This is because boot consoles and nbcon consoles may + * have mapped the same hardware. + */ +static bool have_boot_console; + #ifdef CONFIG_PRINTK DECLARE_WAIT_QUEUE_HEAD(log_wait); /* All 3 protected by @syslog_lock. */ @@ -3511,6 +3519,9 @@ void register_console(struct console *newcon) newcon->seq = init_seq; } + if (newcon->flags & CON_BOOT) + have_boot_console = true; + /* * If another context is actively using the hardware of this new * console, it will not be aware of the nbcon synchronization. This @@ -3580,7 +3591,9 @@ EXPORT_SYMBOL(register_console); /* Must be called under console_list_lock(). */ static int unregister_console_locked(struct console *console) { + bool found_boot_con = false; unsigned long flags; + struct console *c; int res; lockdep_assert_console_list_lock_held(); @@ -3638,6 +3651,17 @@ static int unregister_console_locked(struct console *console) if (console->exit) res = console->exit(console); + /* + * With this console gone, the global flags tracking registered + * console types may have changed. Update them. + */ + for_each_console(c) { + if (c->flags & CON_BOOT) + found_boot_con = true; + } + if (!found_boot_con) + have_boot_console = found_boot_con; + return res; } -- 2.39.2