Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2356313lqz; Tue, 2 Apr 2024 15:12:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXjw/kf09FkxlxnV6O8EjsxYMMy/ZU4m1V3MoRNlFmZpIfc4gvMdpp1rECilBKIdfpLHVms4Xr7awfMSDBe1vFJVb+41L9iek11yGULbg== X-Google-Smtp-Source: AGHT+IFgTvK/9fbEgWnpU5szuwfvHOHUhy1cLzgqnzmTEFxJ+SJ35xTURGJ+56aHQ4bxxapN7EtN X-Received: by 2002:aa7:88cc:0:b0:6e7:f4:3661 with SMTP id k12-20020aa788cc000000b006e700f43661mr17595155pff.13.1712095921745; Tue, 02 Apr 2024 15:12:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712095921; cv=pass; d=google.com; s=arc-20160816; b=s4S7BflmeYZSUDh2Iwh5C1ysVYpRfIMd+ZlOz2FiSGDpEiht+Dz4PL9V4fwfMTyF0t zvqrbf1a63NCsR0Z7n9S1iXmz7wCw1UyX5FUHRz18loPGaS2MWidBb5qwOOF09/6C9mK QFLBYcNYnubyPRVXuxzkG539bddr5VR31OKwktobuZz1H2ICHE+A5zl1ik7B5qTrb3N9 zzK0rDwvZuQ10EbFw0MF95O5zPKCU5t82kMOT/AAuIgWdwrbS2GFKfpJJdoIddJtTIry wjGY8uqWVbjb/IOwRuO3SHLmIKIDJUMM1iE5nFw2rDqjgDkSNnQ5jMZYj/A0ZZkJzeco TJHg== 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=n1EYqYl1VILTOnAmYtkPUlJcJLURjvYBzwQ0+VVa1NY=; fh=5gFRMJUFyxAqMLr0DeT5ou63avcr0R4v6d772hc27RE=; b=Digpuq1ZCjHGP+nttsrHRGzneAiLKzi/m5sM2dcS0O1OQzUq6Q13GrAhm30UrptsQ5 gZ9TsOaFstc4qQ4FTnI/ExBDHGd1GTsFvErJ47kjRTE/38oRvCCxfBz6qzB9z6PHf2IJ JASK+WaTxgucCUw1/gUZ1ScYJeI2dvEp5/IroDYORCnmj+Fzz2HklNUl5uvMVHaIkU6F pjusss0wKjPZOY+DdfKCXysC3CcXPiT25ew1Q0miYY0L7IYpxPAnVc8jFfOFpY0XOtJz AkT8oTnMCL20Y7u5xbftSNs51NdJhyleXBgT/MqtgnqrLbGy6z3dW4DCSQBa7MB8iOaz TayQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HeHCXLiq; 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-128761-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128761-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id r1-20020a632041000000b005d7b75a5df9si11528921pgm.669.2024.04.02.15.12.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 15:12:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128761-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HeHCXLiq; 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-128761-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128761-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 64418287529 for ; Tue, 2 Apr 2024 22:12:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E4E615ECF9; Tue, 2 Apr 2024 22:11:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HeHCXLiq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8p/dtOQs" 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 3468815ECC7; Tue, 2 Apr 2024 22:11:34 +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=1712095897; cv=none; b=ZayNl5t9PkfuTVd9BNBBTMT/OgZks3LYo2E9slY/x6WrPT5GZm78sptf9PbGENuokH0qqWjEoP7RpmfmGWgnvs5pevFhiIujfC5nhPrZonvAn1VfDdv76QD806si0hJ1diKn8MOhM5+K8HEGb2O5cRvI8PgnJPBSwy0L1tPkjow= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712095897; c=relaxed/simple; bh=WcGs7QqdClY2g/akA/3zzEMa5j0Wj8Vi0pMUqDvxJUk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=VvfnWTafJuBfc8hW/hmT8LjB+nAced2l5uRDV5yS5rRzgbqyZjm6Oodv0LKx0U2y4VBZ/5iJVnkXQmjzFbpzkTCXdktdPMK1/awINBYA28PHTvXE0lKs6RsRSwMdSWpB1Z2TuKVbT2e1BGZ7gM4QaYqk7gWTxxoH4gWe+AySbwQ= 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=HeHCXLiq; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8p/dtOQs; 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=1712095892; 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; bh=n1EYqYl1VILTOnAmYtkPUlJcJLURjvYBzwQ0+VVa1NY=; b=HeHCXLiq/3v6LxcBfUISNdCNNfF+uX92ZJlh7W+5dOeqmsmYQ6IjVPriaRA4XdIeihWyjs w8qJcyRiATpmBt2pJYtceZHqSfLZU+mc/3fyABZEetZFIsXbWtgd/0MluSY5ITeRghu6WY 5BhDyq5TCsHC+1EB0xonsTSbRa381NEKkcqOnUy9fIEoZfJojaYGYxnBc/LuPanXG+owxC re5zoa//6gaDEJiwvrcsDRlH1LEatALqE0pjAp3HAtVLCftFxKU1X3uJGqjCorJ6djtLqy kZSWa8sTg4PCCIEuK0FP0wLIt5cW23XlI8crBgVfA6OEICmTG10z3Mt826tCZQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712095892; 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; bh=n1EYqYl1VILTOnAmYtkPUlJcJLURjvYBzwQ0+VVa1NY=; b=8p/dtOQseY5otBLN11Aqf9RyrQTxlvM9ffUiNh8k8CsPQ46I/PhKhk0vpiAWFSQFOQjCzP CmUMf1f8nDlDOrCA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, "Paul E. McKenney" , Miguel Ojeda , Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, Russell King , Tony Lindgren , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andy Shevchenko , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , =?UTF-8?q?Th=C3=A9o=20Lebrun?= , Linus Walleij , Lino Sanfilippo , Fabio Estevam , Arnd Bergmann , Andrew Morton , Josh Poimboeuf , "Peter Zijlstra (Intel)" , Lukas Wunner , Uros Bizjak , 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 v4 00/27] wire up write_atomic() printing Date: Wed, 3 Apr 2024 00:17:02 +0206 Message-Id: <20240402221129.2613843-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 Hi, This is v4 of a series to wire up the nbcon consoles so that they actually perform printing using their write_atomic() callback. v3 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, nbcon consoles are flushed directly and legacy 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. Note: With this series, a system with _only_ nbcon consoles registered will not perform console printing unless the console lock is used (for synchronization), or when exiting emergency sections, or on panic. This is on purpose. When nbcon kthreads are introduced, they will fill the gaps. The changes since v3: - Modify the documentation of console_srcu_read_flags() to clarify that it is needed anytime a console _might_ be registered and the caller is not holding the console_list_lock. Hopefully this makes it clear when this helper function is needed. - Create a function uart_port_set_cons() for setting @cons of struct uart_port. It modifies @cons under the port lock to avoid possible races within the port lock wrapper. All (5) code sites are modified to use the new function. - Introduce 2 new required nbcon console callbacks device_lock()/device_unlock() to implement any internal locking required by the driver. (For example, for uart serial consoles it is locking/unlocking the port lock.) This is used during console registration to ensure that the hardware is not in use while the console transitions to registered. This avoids the risk that the port lock wrappers do not lock the nbcon console lock while the console was being registered on another CPU. These callbacks also will be used later by the printing kthreads. - Introduce struct nbcon_drvdata to track ownership state when using the port lock wrappers. This provides a race-free alternative to the @nbcon_locked_port flag used in v3. - Split the functionality of uart_nbcon_acquire() and uart_nbcon_release() into driver-specific and generic parts. The generic functions are named nbcon_driver_acquire() and nbcon_driver_release(). The driver-specific part is moved into serial_core.h into the new helper functions __uart_port_nbcon_acquire() and __uart_port_nbcon_release(). - Rename nbcon_atomic_flush_all() to nbcon_atomic_flush_pending() to emphasize that it only prints up to the latest record at the time of the call. Also, flush all the pending records of a console (without releasing ownership in between) before flushing the next nbcon console. This allows the full emergency block to be printed on at least one atomic console before trying the next. - Flush nbcon consoles directly in the caller context when exiting an emergency section. - If a CPU is in EMERGENCY context, do not trigger printing of legacy consoles via irq_work. - In panic, allow synchronous legacy printing before calling the panic handlers. Attempt to flush there in the panic context as well. - Remove the return value for the nbcon console atomic_write() callback. If ownership has not been lost, it is assumed the printing was successful. - Add a WARN_ON_ONCE if nbcon_emit_next_record() is called for a console that has not provided a write_atomic() callback. - Change the meaning of the return value of nbcon_atomic_emit_one() to allow nbcon_legacy_emit_next_record() to have the same return value meaning as console_emit_next_record(). - Remove all legacy @seq handling from nbcon.c. For nbcon consoles, printk.c handles the transfer and resetting of the legacy @seq value to @nbcon_seq. - Add a compiler barrier in __pr_flush() to ensure the compiler does not optimize out a local variable by replacing it with a racy read of multiple global variables. - Let __wake_up_klogd() remove unnecessary flags before possibly queuing irq_work. - Eliminate header proxying in nbcon.c. - Mark _all_ lockdep output blocks as emergency sections. - Mark _all_ rcu stall blocks as emergency sections. - Remove "(Optional)" in the documentation of the write_atomic() callback. Once threads are available, it will be optional. But at this point in the rework it is not. John Ogness [0] https://lore.kernel.org/lkml/20240218185726.1994771-1-john.ogness@linutronix.de [1] https://lore.kernel.org/lkml/20230302195618.156940-1-john.ogness@linutronix.de John Ogness (23): printk: Add notation to console_srcu locking printk: Properly deal with nbcon consoles on seq init printk: nbcon: Remove return value for write_atomic() printk: nbcon: Add detailed doc for write_atomic() printk: nbcon: Add callbacks to synchronize with driver printk: nbcon: Use driver synchronization while registering serial: core: Provide low-level functions to lock port printk: nbcon: Implement processing in port->lock wrapper printk: nbcon: Do not rely on proxy headers 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 sections in lockdep splats Sebastian Andrzej Siewior (1): printk: Check printk_deferred_enter()/_exit() usage Thomas Gleixner (3): 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_core.c | 6 +- drivers/tty/serial/amba-pl011.c | 2 +- drivers/tty/serial/serial_core.c | 2 +- include/linux/console.h | 138 ++++++++-- include/linux/printk.h | 32 ++- include/linux/serial_core.h | 116 ++++++++- kernel/locking/lockdep.c | 91 ++++++- kernel/panic.c | 9 + kernel/printk/internal.h | 56 +++- kernel/printk/nbcon.c | 382 ++++++++++++++++++++++++++-- kernel/printk/printk.c | 287 ++++++++++++++++----- kernel/printk/printk_ringbuffer.h | 2 + kernel/printk/printk_safe.c | 12 + kernel/rcu/tree_exp.h | 7 + kernel/rcu/tree_stall.h | 9 + 15 files changed, 1038 insertions(+), 113 deletions(-) base-commit: a2b4cab9da7746c42f87c13721d305baf0085a20 -- 2.39.2