Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1877323lqb; Sun, 26 May 2024 23:42:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXKzffbLZq6nAtl8igAEaEIAng5bNPL7DvJkfD0fKSkvVAbgguv51FVDTHWDp1v/GGUrMYVNbHKnbcVVbgfGNko5uSMZR2wlDnUGS8A7A== X-Google-Smtp-Source: AGHT+IEcZJC94/m+vcXmqP4b5lNlZnkKHMcW0Noye+P5YRff69tAYG8fePWxiJwoTxyXfLdocCQ5 X-Received: by 2002:a05:6870:3b85:b0:24c:b3c0:6cc3 with SMTP id 586e51a60fabf-24cb3c14d24mr8074402fac.38.1716792151586; Sun, 26 May 2024 23:42:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716792151; cv=pass; d=google.com; s=arc-20160816; b=nAnVCVrhM+K+Zjn1PTxhYmXy1fYUJv5KTy8g6eyOC07x2ueOOwZPSJhZqzytEmZ/uS iWHFLhclyhRSQQ+wcGpEfSLbYrAJEoB3IZzxAYP7Z00oy55c6GEn4235FoQ21QLgx/kE 7R2MTVtGMlgMAIt8WyFjtq7hqJCvr/sDfsS8qJs7pD6XZHjXeRswoo6kpT2PtAeiCBil dZNDyDryp7vNbI84d02m1YNxuWoWNqT/RuskKgtMZnl5ETEwCJjlawKngJYpBdZ1lxfW Zf/iPPH24uFDzjH0fNAzx+a202J1XthcmRF53BU05keR2nKHaj4NDUqI00Rao57c26SO hYFw== 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=0n6uVNwgqq5puIfDGgLjiBT2iercsin9z76FjHNuAQY=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=LLNfeP6JV4pqeNmPi3FFQJKiBybLDcAeOJ3SpkySLnYAvPZUByOwkpRF0k6nIE2ad/ 4Gn4p/r2jcZp42nIoNTrBTNZiaNrDwf54ptcyHWlu0JnctynmlW/ErHlHj13RUC5Gpem /cUyolKB9/AhrtUQ95zwYAWiroE6VdoA7gLl3sjbhEYdSGeWdvOa3cRdnrwJ4ObnIOQj 8KWsqBWuEQQ4xpjjBF0Q6qxLz8yoFEjzbmdJkUDXK6O6naF4zlCYSwW+fb1RhJsERucX yNfItENjhQ1EN09FR/eFe9QBa8PAw0FK9SkxiutHQixmpAfxTZZjM1GcHBNZMOYOJ4RQ jCxg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=KZNl70bT; 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-190093-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190093-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f8fcfd7cf1si5678947b3a.219.2024.05.26.23.42.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 23:42:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190093-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=KZNl70bT; 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-190093-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190093-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D9E97281ACB for ; Mon, 27 May 2024 06:41:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2679D13BACE; Mon, 27 May 2024 06:38:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KZNl70bT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JNIciXcu" 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 8D18D4D59F for ; Mon, 27 May 2024 06:38:25 +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=1716791907; cv=none; b=pLOJTiBpSCZqnuWtIVlCQtbondFeszO3ejVOD6VkIaHRDqCiBUgSxLw1/Bug8XOGJCssi5KciM5+A9Gl3TXE11Ux6LgPj/IohVTazuzlRAJRUwf+ItgswGQb6Mx+d5Fz+q2YfOPYFEZ9QfongnoEGSa16Am812D7kGAatm9YDuk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716791907; c=relaxed/simple; bh=DV9ePIcY234r7QPwO7jt9B0pkqMHFxrafa8XBXbKkPg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=naYBRB8ro1MXhQThpkIN66NmpKUxh8BB7HGc7YO6klW5qnzid0kwegTQaU6MgNkS5V0TaP08Lqd7IU702GBrqj2d3U3BDnWiPx22IUCm4djfvfW3pncIZ5eA/nXGVC8Qg4Ga5o/RQ00SJEuFhQKTF4nfKT0Weron2GoQGLkefuc= 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=KZNl70bT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JNIciXcu; 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=1716791904; 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=0n6uVNwgqq5puIfDGgLjiBT2iercsin9z76FjHNuAQY=; b=KZNl70bTXp3m5cAe4kEfJH3PCw5hX0Q2wMhL7Zf0gm0JtHOdurXk8hEaou0OLQJpFNpV9O sLfmU5igFuVN2udrqNtgbvXyiSAu0gmKheimHZqfuoXbHy9dzQZRJoYRO8r0CcDLts4twE jefpNob5YvXlBW2aMVQRc4qeMvVI0LJmT2HRQJND+RYnLKd7zKZekcPgKwGcMOxEe1tdmU jUf6qs4B0jIV/SEdvyLskU1+Y9C42bSE9iqC1i74q97MKFIL4udoMjbJsAL4L86019Emeg +3pXeqIPGayKMcaufJjvND+sY+hY3qbLct+QL0KQjYkC7P4bYkGNk55lULNY1A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1716791904; 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=0n6uVNwgqq5puIfDGgLjiBT2iercsin9z76FjHNuAQY=; b=JNIciXcukcyoUBLMA80RT7SOX69DQH+bX7og5NEQJRhSR3LcOgqb2w+6N7ijbLOcwJ7O0j veNZzIXA3a70DIDQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v6 20/30] printk: Track registered boot consoles Date: Mon, 27 May 2024 08:43:39 +0206 Message-Id: <20240527063749.391035-21-john.ogness@linutronix.de> In-Reply-To: <20240527063749.391035-1-john.ogness@linutronix.de> References: <20240527063749.391035-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 56d2377fc97f..d81d541558fd 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. */ @@ -3512,6 +3520,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 @@ -3582,7 +3593,9 @@ EXPORT_SYMBOL(register_console); static int unregister_console_locked(struct console *console) { bool use_device_lock = (console->flags & CON_NBCON) && console->write_atomic; + bool found_boot_con = false; unsigned long flags; + struct console *c; int res; lockdep_assert_console_list_lock_held(); @@ -3640,6 +3653,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