Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp775726rdb; Sun, 18 Feb 2024 11:06:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVC9qL0yxGjcquic5Fobc+PCDWqbWVNHti9bnvSFkg1Rien+SNbcyrckEpuZCClT3qMCvv/4cBkDqinHF14XNHR6rHv1YpZiWi4ZqzyYw== X-Google-Smtp-Source: AGHT+IH/RD5g6y/ECS2iCyVWg378cXC/OpYtTabylcsr1t9ORZ7/S5qX0mehA0guvhQAybXETV09 X-Received: by 2002:a05:622a:1193:b0:42e:60f:6338 with SMTP id m19-20020a05622a119300b0042e060f6338mr3348010qtk.5.1708283162983; Sun, 18 Feb 2024 11:06:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708283162; cv=pass; d=google.com; s=arc-20160816; b=G7Cx1NdVCyAsTeeLplQjzww2D/kGls63YWrdQZ3wIYljNbM8y2AN/NKz3ywMKF90pV Hfmwr5MQuyyaHvGmK0D+8qUOl4EZ1kYW2/EicWzHpbsYvZNMB0bi2wGwVyz4lpBF9V4h QTrZzhg2heLVBR2xfZvCm52UKhqMU1DNV7QSlxsPLHXj2gcTFadXxLqB4U3ByyI6GfS5 X2Mx1Fr62oW8SXxjqUnFQRfvf6hRgm4eRFtL1Za5dkhhJgqi50clBVINbeH1uuFIlt2B 8R6PL1yhOnK45TlDJHuQauysuKB58LGgzfLPV8bdEK85gj4uUkHL6OAPsr3ZF3vaIBDT peYQ== 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:message-id:date:subject:cc:to :dkim-signature:dkim-signature:from; bh=CxyZZWvhSzq+VD25dSHunC8XqF+HGYq257sbHrx7tVc=; fh=xq/LRUboAYW7AEDWIcgjw46cEnj1KugHU1TskbEQXnQ=; b=sRs80GXC1MxL0xzQXidMRnqcjub7WPvilGUP1vKty1HLXPRj2DAsoWV5WRByVL8q4I gkGCT3w0zmt4hu/Ky3Y5sJ3AcqVtLp0g16t3mehoSG6n1sQHj6fsklV2gnvmNTQrQXSQ jwyxcHlyuLQVH8z2d+Iu3ngG1AHm1sXg+Bt4GEbVpBB9ITtI5Kufx85r/dEgDgrWGQfZ /3eZ1wYQIhxf59f5OpRFGJov26FVXOq9Dq/fZC/JqXs4/khd9oMSRYSgfLMbw4yA43v7 HqRUCTYorFZyjswSnP+vAz5CaBdurH4n7xjusLhXlgUe6kB4hEFiQfgwJIjk6kTtxEVK 3Ofw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UbYkC9+r; 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-70532-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70532-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 d10-20020ac8668a000000b0042c59340e59si4209709qtp.598.2024.02.18.11.06.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:06:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70532-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=UbYkC9+r; 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-70532-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70532-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 ABD4A1C20A79 for ; Sun, 18 Feb 2024 19:06:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A84777317A; Sun, 18 Feb 2024 19:04:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UbYkC9+r"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Swz/Gol/" 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 A85EA71B33; Sun, 18 Feb 2024 19:04:33 +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=1708283075; cv=none; b=t0aod+SKS5KVr4bVOmVGdEl9LPHubvq8rDXkerJaIkQ2/Zy0lcwIG3d3ySKw26TKn8kaCG7dtaWGGAcKqjvTJ40+7GvzcQBEwxNHpz7vHV8kv/FlWLgvlxkBJ+Fb4ljT8vhSXhfGyCvxqqOViufo9k+FTeA58rdSppEOIzQb3BU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708283075; c=relaxed/simple; bh=uAuIZ9HfSiY/A0IYD728MeRHnJcUIl43QTwSldu9Elo=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=i4p5L6UjtHmN61ubE3oBlgNR3LTW+Nb8UW0YeyPL3PIxDOYSFAuAWZslsRi7FUzDUOZKskDrW4DBqoEXL2AeB5+4C6Yh4cbPMRmahfAToQvC9NIdJJIBcVQvIdh/GgASpOG5I+XGX1d0X9jchhWP0/LqdSopCA8J0qF/rK69Mp8= 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=UbYkC9+r; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Swz/Gol/; 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=1708282668; 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: content-transfer-encoding:content-transfer-encoding; bh=CxyZZWvhSzq+VD25dSHunC8XqF+HGYq257sbHrx7tVc=; b=UbYkC9+rrnE2knx+Jpd7AAc/5FGkoofSX8NvdgBLECyH65gS9y2IMZwsCGi9Dvfuis4YUb 4hqu9ybDvUNRUb2SHmUmjDIxTjbRSq0ej9qeFJm4FYb+eGKMAK+st5+fWH98ZmghdAqtRp ukYxcAZelMhaPImfh49FsJ33pUn12UGsKtF0j5ZHmlNkkUJdip8vARJ03CcsGYiJXrwPEv 5GciViV2WooJ7PGufsROG6tJx5enDqphT3XZd7EnfzBANQVl1Y9W+jIEiBx4jImTeUjBjK F18lnwmKmlPF0bOoM7kTHhmOB1wuPYYQeXz3EsjCKXX5iz2gSePSZL6lwxu9Xw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282668; 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: content-transfer-encoding:content-transfer-encoding; bh=CxyZZWvhSzq+VD25dSHunC8XqF+HGYq257sbHrx7tVc=; b=Swz/Gol/1XZ9DEDonZSnv+eU/L3nfcDuegYEDQ9P3zYWgXm813efE7f8j3rg9YxE2XShrb YKl1rpgrb5KjBxCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , "Paul E. McKenney" , Miguel Ojeda , Andy Shevchenko , Tony Lindgren , Geert Uytterhoeven , Justin Chen , Jiaqing Zhao , Andrew Morton , Josh Poimboeuf , "Peter Zijlstra (Intel)" , Uros Bizjak , "Guilherme G. Piccoli" , Lukas Wunner , Arnd Bergmann , Kefeng Wang , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Mathieu Desnoyers , Lai Jiangshan , Zqiang , rcu@vger.kernel.org, Ingo Molnar , Will Deacon , Waiman Long Subject: [PATCH printk v2 00/26] wire up write_atomic() printing Date: Sun, 18 Feb 2024 20:03:00 +0106 Message-Id: <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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi, This is v3 of a series to wire up the nbcon consoles so that they actually perform printing using their write_atomic() callback. v2 is here [0]. For information about the motivation of the atomic consoles, please read the cover letter of v1 [1]. The main focus of this series: - For nbcon consoles, always call write_atomic() directly from printk() caller context for the panic CPU. - For nbcon consoles, call write_atomic() when unlocking the console lock. - Only perform the console_lock()/_unlock() dance if legacy or boot consoles are registered. - For legacy consoles, if nbcon consoles are registered, do not attempt to print from printk() caller context for the panic CPU until nbcon consoles have had a chance to print the most significant messages. - Mark emergency sections. In these sections printk() calls will only store the messages. Upon exiting the emergency section, console flushing is triggered via irq_work. This series does _not_ include threaded printing or nbcon drivers. Those features will be added in separate follow-up series. Note1: With this series, a system with _only_ nbcon consoles registered will not have any console printing except on panic. This is on purpose. When nbcon kthreads are introduced, they will fill this gap. Note2: Patches 1-3 are already mainline, but not yet in the printk/for-next tree. They are included for completeness, but are not actually part of this series. The changes since v2: - Eliminate CPU states (normal, emergency, panic) and instead just track per-cpu emergency nesting. - Instead of talking about "atomic mode", talk about "using the write_atomic() callback". This avoids confusion about what "atomic mode" means (i.e. "atomic" always means the write_atomic() callback is used). - Rename atomic_enter()/_exit() to cpu_emergency_enter()/_exit(). - When entering emergency mode for a CPU, disable preemption rather than just migration to allow the warning to be completely handled before permitting rescheduling. - Implement nbcon locking within the uart port lock wrappers. This provides synchronization between write_atomic() and non-printing driver activities (such as changing the baud rate.) - Implement a one-way trigger printk_legacy_allow_panic_sync() to allow legacy consoles to print from the printk() caller context for the panic CPU. This allows the safe nbcon consoles to print before falling back to legacy consoles. Note that if no nbcon consoles are registered, legacy consoles are always allowed to print from the printk() caller context. - Perform unsafe nbcon flushing at the very end of panic before going into the infinite loop. - Add nbcon_get_default_prio() helper to return the appropriate prio for the current CPU. - Do not assume that if write_atomic() returns false that the console has been released. - For nbcon_atomic_emit_one(), rely on @ctxt->backlog rather than trying to read the next record. - Rename nbcon_console_emit_next_record() to nbcon_legacy_emit_next_record() and have it use the same procedure as console_emit_next_record() (enter printk_safe, enable console_lock spinning, stop critical timings). - Add nbcon_atomic_flush_unsafe() to allow flushing nbcon consoles in an unsafe manner. - For nbcon flushing, add @stop_seq argument limit how much to print. This avoids a CPU getting stuck printing endlessly. - For nbcon flushing, disable irqs to avoid an interrupt possibly calling into console code and deadlocking on nbcon ownership. - The rules for allowing printing from the printk() caller context are getting quite complex. Move all this logic into vprintk_emit(). - For console_init_seq(), also consider nbcon consoles. - For __pr_flush(), only take the console_lock if legacy or boot consoles are registered. - For printk_trigger_flush(), do not flush nbcon consoles directly. - For defer_console_output(), only trigger console_lock()/unlock() if legacy or boot consoles are registered. - Add detailed kerneldoc for the write_atomic() callback. - Fix kerneldoc for enum types (cons_flags, nbcon_prio). - Add extra check to printk_deferred_enter()/_exit() to ensure it is called with migration disabled. [0] https://lore.kernel.org/lkml/20230919230856.661435-1-john.ogness@linutronix.de [1] https://lore.kernel.org/lkml/20230302195618.156940-1-john.ogness@linutronix.de John Ogness (19): printk: Consider nbcon boot consoles on seq init printk: Add notation to console_srcu locking printk: nbcon: Ensure ownership release on failed emit printk: nbcon: Implement processing in port->lock wrapper printk: nbcon: Add detailed doc for write_atomic() printk: nbcon: Fix kerneldoc for enums printk: Make console_is_usable() available to nbcon printk: Let console_is_usable() handle nbcon printk: Add @flags argument for console_is_usable() printk: Track registered boot consoles printk: nbcon: Use nbcon consoles in console_flush_all() printk: nbcon: Assign priority based on CPU state printk: nbcon: Add unsafe flushing on panic printk: Avoid console_lock dance if no legacy or boot consoles printk: Track nbcon consoles printk: Coordinate direct printing in panic panic: Mark emergency section in oops rcu: Mark emergency section in rcu stalls lockdep: Mark emergency section in lockdep splats Randy Dunlap (1): serial: core: fix kernel-doc for uart_port_unlock_irqrestore() Sebastian Andrzej Siewior (1): printk: Check printk_deferred_enter()/_exit() usage Thomas Gleixner (5): serial: core: Provide port lock wrappers serial: core: Use lock wrappers printk: nbcon: Provide function to flush using write_atomic() printk: nbcon: Implement emergency sections panic: Mark emergency section in warn drivers/tty/serial/8250/8250_port.c | 1 + include/linux/console.h | 42 +++- include/linux/printk.h | 30 ++- include/linux/serial_core.h | 106 +++++++- kernel/locking/lockdep.c | 5 + kernel/panic.c | 9 + kernel/printk/internal.h | 57 +++++ kernel/printk/nbcon.c | 362 +++++++++++++++++++++++++++- kernel/printk/printk.c | 248 +++++++++++++------ kernel/printk/printk_safe.c | 12 + kernel/rcu/tree_stall.h | 5 + 11 files changed, 784 insertions(+), 93 deletions(-) base-commit: e7081d5a9d976b84f61f497316d7c940a4a2e67a -- 2.39.2