From patchwork Sun Feb 18 18:57:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202844 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp912082dyc; Sun, 18 Feb 2024 11:00:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXteG2uHICAFMftJy1yjXQvhzbW1pSoVLkKmH3uifu95AQyPv0rwELiZUT29CzpMiQI7Ofb1bHF+JibqYev2RVu1Epkug== X-Google-Smtp-Source: AGHT+IEwkloKEKIascEEHxuTn4f9uWI9tmQq1VFLMwvz6gWiAjWeg00vxyCgouH4c1YKxCIHtPq/ X-Received: by 2002:a37:e20d:0:b0:787:272a:e298 with SMTP id g13-20020a37e20d000000b00787272ae298mr10721638qki.62.1708282842872; Sun, 18 Feb 2024 11:00:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282842; cv=pass; d=google.com; s=arc-20160816; b=i/zneWpKh9DmgeR0i60d8Pcy4BpPXVTmYNz6mY0bUjLPQjrL4W57HXDkrK0nXPgnTV GR06YOFK+FNS3vKmKl4/JTYywj+41svJubTWkoPZo6denUxFbizalU2NdfTOVpyY4LUY kihiJ/+YbuGmLV1nrA0Y2md5RM53NQKRpEW+iE29hl3P8w6/l1RvZYVIyacQx/mJQP3r /WUo/rh1fmOWfCm2pItNu3eJJ+CHpiBdh1q9HTu6fzMJ+NmVNuHeh2C+Zpj/KmHnuLxu gNz9ISqGfKHrVbvQ6DxmtJ4jV3DWosz6+eWyKKkkWSRHK502pdySC1OqMLeHTaHXTiBQ LIfw== 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=QA/99sNBe74Zpg0DWyhl5wv3RvxapTRr2AVbgdHNKI4=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=fGNr42y6CW9ybAaN7L9hWvkHxpEP/v7KrtG4XkLiHk0kgurQewP4oVmupCNZRhbpdu ojO0QHdvJMjYlbktq+ejNpcGegwmk2qQ9KeUmVtsp2z4zRZVn56oH1bGvgOnMlDA/ary 4LNj2VrwQa4jUK41w+sf2Qh2OVYEx2LgNiLoibOG5Te+qUkTRjD50Kfl0JsaUMAfG+ad Mo7zmE3fxAAOHUxwwG59oclYj70aT4rUx1aMQ3qLBPaICkkmjy0Chbxi8h7EAHkg10v8 5E0idukHuaxXZWIsNCKQ6r0JTya4P9FQGhrtqwz4qVcEA9tfJzkqwrcXzqxNd2QFiQ25 Y8+g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="rJ1/Wdf4"; 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-70508-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70508-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id pa10-20020a05620a830a00b007874f43dd5dsi4045760qkn.445.2024.02.18.11.00.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:00:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70508-ouuuleilei=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="rJ1/Wdf4"; 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-70508-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70508-ouuuleilei=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 A884D1C20327 for ; Sun, 18 Feb 2024 19:00:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 474AE76054; Sun, 18 Feb 2024 18:58:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rJ1/Wdf4"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="9QfHj5ew" 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 628406FB86 for ; Sun, 18 Feb 2024 18:57:55 +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=1708282677; cv=none; b=miYAzYkJaujzTcoE3WgimXqdloJ2+rC6t5E7/Osr5tjSRXu++APozVRh2SV9trmSb9RNJ/UW6FophEf9rLC3AZpz1f04QrgOJ8zLgv/C0UaAaXkbUN7EbDZNA7G/4FjqNHVGKldYwmkVOi2WjQWAwzXAbjmrvWep4TxFfPtZy/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282677; c=relaxed/simple; bh=44GMokOuhofcbVPi1PR9Ui7+7904b0FBavmkwZ/WX3M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QUBl1w3al/mN1IT1Bi2CHZxDEnuuTrCip1GDUaPAWYNmQQP1sEB5qFoet0vUoJQ70fkew6aCl8vQ0Kh15cobEhijMrcowoUpdzQ1OgghTXPLuv3Aj4u072eECXOAeNJleCoTGV9/sGcOwVSLQm7ESoENFXUX3jfMe0HCHt3+Dt0= 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=rJ1/Wdf4; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=9QfHj5ew; 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=1708282673; 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=QA/99sNBe74Zpg0DWyhl5wv3RvxapTRr2AVbgdHNKI4=; b=rJ1/Wdf4YXXUQmodc7+URL0ljrOU8z6ZTYWtKB2i5KhN1BD61MJz2T+1+1cvhlgpLJwpQO /gbCtKVFxov4Q2DsM1zr+Me+kviqt+CDoGYOgzwqqZ4Ikf9ZRJVIf6E5btxSqpX7cAZzy1 YUZy+4lQK0+3DNveay7/3XOWXQu4DgJH1QDUlDn/RoCiorZULjjdyofJq6xsjOPs3ek93L 7679/EUmaZYUedbO9bv9jXkxFlBf4yL+8OrB1fzlv8hQa+D4Pnr1jGgci8IOfHhJjA0BP7 P/uJAfRzY/GoJovcz8Umt2cb91rwFg9Kw3848oKAb+h+XsWENrq49de0SqTqsQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282673; 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=QA/99sNBe74Zpg0DWyhl5wv3RvxapTRr2AVbgdHNKI4=; b=9QfHj5ew/k0LsjwUvp0IoPme/gb2gFwSzUmf3FCspKkLClGC+ux0FPNIurkWNS3ZRu814F ocrdcs+7MlSWVvAw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 15/26] printk: Track registered boot consoles Date: Sun, 18 Feb 2024 20:03:15 +0106 Message-Id: <20240218185726.1994771-16-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264390241408817 X-GMAIL-MSGID: 1791264390241408817 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 ea170ade4d42..1b14159990ba 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. + */ +bool have_boot_console; + #ifdef CONFIG_PRINTK DECLARE_WAIT_QUEUE_HEAD(log_wait); /* All 3 protected by @syslog_lock. */ @@ -3499,6 +3507,9 @@ void register_console(struct console *newcon) if (newcon->flags & CON_NBCON) nbcon_init(newcon); + if (newcon->flags & CON_BOOT) + have_boot_console = true; + /* * Put this console in the list - keep the * preferred driver at the head of the list. @@ -3551,6 +3562,8 @@ EXPORT_SYMBOL(register_console); /* Must be called under console_list_lock(). */ static int unregister_console_locked(struct console *console) { + bool found_boot_con = false; + struct console *c; int res; lockdep_assert_console_list_lock_held(); @@ -3598,6 +3611,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 = false; + return res; }