Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6284315rdb; Thu, 14 Dec 2023 13:42:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZ1EvDJMDnprlU6u7xNvo76dwwSZasm2i6t+aS49bHzy1+g0X82QPET4k/BpqvRODcG4D1 X-Received: by 2002:a17:907:7b8c:b0:a01:b8c6:7724 with SMTP id ne12-20020a1709077b8c00b00a01b8c67724mr5991734ejc.73.1702590143525; Thu, 14 Dec 2023 13:42:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702590143; cv=none; d=google.com; s=arc-20160816; b=SE9DBu3VUc6sqMcuiUE0YvjrXZ41evyS+JWrmNECMwRue/yidg8rRp7Fy6UZILWB9N uZL1QWCSDcPuw5/Q/bH95PM06vqyiy0I6aa5SG3LcVKWfXDF9EOqwdi1RiWRSWdTBJNp 15BeEF/excDdR4W4WJBfS4SIBapmf01qig3GXshAuGkMuotLNZPw584JgRU/rtEZPl20 9uifKgPvCoqYpRDr6ZRM/HDeIrhBh0ER3sBrtKWIcIlalBNC1StmdLyuHzves3aOA9Gs TjlGB8N2cqofj7J4QxY+jdNRAlOZa+JcvEJyXpGtfFz8Wib/HTa0qe8l7juM2dog5/ty /ZFQ== ARC-Message-Signature: i=1; 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=q5UpXrYvC+OmHxP4VbWiXKHrbItq+dkK5XTs3sO98Lo=; fh=AzI7JRxDqjCqHSoQzs8ZAMEWB61jJAtAhQS+AdrX8bk=; b=sG+UMPnw5uw4WkaFh5zm5Crmt29tU17QaugJuz6MvGSnh1HmEjujuHOoY+r91uxRuH 6eEdyWOUeECphr6RR8E8Zie4ilPm1/mJGC29fRE2sWpUwivKweIP7YhnZY+fXtkD9hxA m8Jayn17HXc820MOWNObfGtbqoXKint2quFHcDtd5dHa5hMUUKLMXcVFNMmsNvzjaa0u DQpP/MM1kzYafusOCPypHNUSXYvby7gzM5/5KWqIge3VfGxStIEkwQmuOahx69xiZZ8P sMnbVRX8S3i5whwyAC1o0iVD9N2yw3w+UGN7fzT95vuKf0pujzwxJITZvNsDXJy9WQOz 0PRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=YAQcBB6+; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-143-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id xo11-20020a170907bb8b00b00a1cf505be01si6507317ejc.66.2023.12.14.13.42.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:42:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=YAQcBB6+; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-143-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4AE721F227DB for ; Thu, 14 Dec 2023 21:42:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 116666DD05; Thu, 14 Dec 2023 21:42:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YAQcBB6+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rtghYq2O" X-Original-To: linux-kernel@vger.kernel.org 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 840A56ABA3 for ; Thu, 14 Dec 2023 21:42:06 +0000 (UTC) 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=1702590124; 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=q5UpXrYvC+OmHxP4VbWiXKHrbItq+dkK5XTs3sO98Lo=; b=YAQcBB6+SKezc5n4mwrblZvnczyYQJVtyVCUuKwcU4H+1i7SYWED+9ZhBXQ2Q6bJPHsF3f Z8Vxgp60GPsOLRKhoncbb93Fxboxmjk/0wGzgQJNdLTwQVFMhsAQuhnwVPwnuHBVhrdVzO HCa7Im3o+Q7wYlBXQcVPKMwUEcR6u+l+jiz84dHGBg25vMviNj6Es75GFSHtEB2SaGSnWn olJBDulw2KuSaWNvA228nPGKnBKxUUrRjEa1lcJVhOHUWemlTGrd6ZE7wjtFKA7OESZkFB zlHhMWVudN+yQiZhoxWmi8Tgmwdp4fUAC//yjMDmMYsAhDZC5TPqxYMkAXWlDA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702590124; 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=q5UpXrYvC+OmHxP4VbWiXKHrbItq+dkK5XTs3sO98Lo=; b=rtghYq2OFGcUHAYJkfLGyscitrRxh/RGQKuMsb0J3KwzyYa+ZgtnmUwN1UNPxrJy5hPknI dpGE3egiK7Ig/3Dw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Mukesh Ojha , Andrew Morton , Peter Zijlstra , Josh Poimboeuf , Ingo Molnar , "Guilherme G. Piccoli" , Kefeng Wang , Kees Cook , Uros Bizjak , Arnd Bergmann Subject: [PATCH printk v3 00/14] fix console flushing Date: Thu, 14 Dec 2023 22:47:47 +0106 Message-Id: <20231214214201.499426-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, While testing various flushing scenarios, I stumbled on a few issues that cause console flushing to fail. While at LPC2023 in Richmond, I sat down with Petr Mladek and we reviewed the v2 [0] series. This v3 series is the result of that offline discussion. This series addresses the following issues: 1. The prb_next_seq() optimization caused inconsistent return values. Fix prb_next_seq() to the originally intended behavior but keep an optimization. 2. pr_flush() might not wait until the most recently stored printk() message if non-finalized records precede it. Fix pr_flush() to wait for all records to print that are at least reserved at the time of the call. 3. In panic, the panic messages will not print if non-finalized records precede them. Add a special condition so that readers on the panic CPU will drop records that are not in a consistent state. 4. It is possible (and easy to reproduce) a scenario where the console on the panic CPU hands over to a waiter of a stopped CPU. Do not use the handover feature in panic. 5. If messages are being dropped during panic, non-panic CPUs are silenced. But by then it is already too late and most likely the panic messages have been dropped. Change the non-panic CPU silencing logic to _immediately_ silence non-panic CPUs during panic. This also leads to clean panic output when many CPUs are blasting the kernel log. 6. If a panic occurs in a context where printk() calls defer printing (NMI or printk_safe section), the printing of the final panic messages rely on irq_work. If that mechanism is not available, the final panic messages are not seen (even though they are finalized in the ringbuffer). Add one last explicit flush after all printk() calls are finished to ensure all available messages in the kernel log are printed. This series also performs some minor cleanups to remove open coded checks about the panic context and improve documentation language regarding data-less records. Because of multiple refactoring done in recent history, it would be helpful to provide the LTS maintainers with the proper backported patches. I am happy to do this. The changes since v2: - When on the panic CPU, allow desc_read_finalized_seq() to read records in the committed state. - Fix the off-by-one return value of the new function prb_next_reserve_seq(). [1] - Remove the suppress_panic_printk feature and instead simply silently drop all printk() messages from non-panic CPUs. - Remove the __seq_to_nbcon_seq()/__nbcon_seq_to_seq() macros and use the new __u64seq_to_ulseq()/__ulseq_to_u64seq() macros for nbcon as well. - Adjust the new __u64seq_to_ulseq()/__ulseq_to_u64seq() macros to support seq values above the base value. This is necessary for the new last_finalized_seq feature. [2] - Relocate the new __u64seq_to_ulseq()/__ulseq_to_u64seq() macros to printk_ringbuffer.h so they can be shared by the printk_ringbuffer and nbcon code. - Call console_flush_on_panic() one more time at the end of panic(). - Add and cleanup many comments and commit messages to clarify reasoning and variable meanings. John Ogness [0] https://lore.kernel.org/lkml/20231106210730.115192-1-john.ogness@linutronix.de [1] https://lore.kernel.org/lkml/87h6lwcxix.fsf@jogness.linutronix.de [2] https://lore.kernel.org/lkml/87lear2i8w.fsf@jogness.linutronix.de John Ogness (13): printk: nbcon: Relocate 32bit seq macros printk: Adjust mapping for 32bit seq macros printk: Use prb_first_seq() as base for 32bit seq macros printk: ringbuffer: Do not skip non-finalized records with prb_next_seq() printk: ringbuffer: Clarify special lpos values printk: For @suppress_panic_printk check for other CPU in panic printk: Add this_cpu_in_panic() printk: ringbuffer: Cleanup reader terminology printk: Wait for all reserved records with pr_flush() printk: ringbuffer: Skip non-finalized records in panic printk: ringbuffer: Consider committed as finalized in panic printk: Avoid non-panic CPUs writing to ringbuffer panic: Flush kernel log buffer at the end Petr Mladek (1): printk: Disable passing console lock owner completely during panic() kernel/panic.c | 8 + kernel/printk/internal.h | 1 + kernel/printk/nbcon.c | 41 +--- kernel/printk/printk.c | 101 +++++---- kernel/printk/printk_ringbuffer.c | 360 +++++++++++++++++++++++++----- kernel/printk/printk_ringbuffer.h | 54 ++++- 6 files changed, 427 insertions(+), 138 deletions(-) base-commit: 6c3a34e38436a2a3f7a1fa764c108ee19b05b893 -- 2.39.2