From patchwork Thu Mar 7 12:55:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sreenath Vijayan X-Patchwork-Id: 779101 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2066.outbound.protection.outlook.com [40.107.94.66]) (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 E2FEA1D680; Thu, 7 Mar 2024 13:04:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709816646; cv=fail; b=LKGvSPNmQOvqiTYyQVghFkki7t/h3RzxTxl1HTq5lkTuFXmimdNQTVV6TFa2f3SmhHOoGEmntooHzVF1gFMQFDOFrbTXD2MHZvOa/txTkk95htc+qGB6VDh5W8GRBCE7WxnsV0EIXrp7pJ8YUBG4e68AYqlXQrhHUoUbmWa262c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709816646; c=relaxed/simple; bh=Xh/c9RjmLyxJvBnciLI+8V/U4PdTzrLWNH6fbTg7OxQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CTgVhB1loMmGcWnpXXdxitbgrRil0DCOFFSCZjPnCwQxaGoGVxsB2sXr4Cx0E9tDMSOqbWcKPmskEWP1Kblyj45dGtE3a4AhWgmp0ywpsiRYRHhSZhGILoUeEubqXhnhcAPsu80+DsAB/BYUXMs1ozzTYLGYE6PEuB3kZt9vLMw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com; spf=pass smtp.mailfrom=sony.com; dkim=pass (1024-bit key) header.d=Sony.onmicrosoft.com header.i=@Sony.onmicrosoft.com header.b=TN8Au/bg; arc=fail smtp.client-ip=40.107.94.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sony.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=Sony.onmicrosoft.com header.i=@Sony.onmicrosoft.com header.b="TN8Au/bg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DFkXXUF3Jo1FjMOQfhBpnL3XXti66q0uzVZlG9DLojEsYox6/T0k1FNjXko6ZnvJZE3Ck5uTymqOAqM2w2Hj+jgaFboD0g7kCvZKFFAB0XwgGp+JR6xqR1HWgA1K1OklWOB5xHKz/PTAutRiu0JSleveBZQudhps8lT12OYHUYd+Cd4quClDEoaQnvfQ58SAgkaklSReRqJ+lWkm2nHaCmQOkpcFbBz8VBf5uhyQUnGktGMesYVJLeQXBhILEAkGE+r+OVB/wCP3WCDNxQJfc+3d/v3URHg3FymcuuQjnHLBwL2eE1nxpqGjh0tY08WPz5l1W99Ad9D37Xx++3pcaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=41uFhNyJnV5dNdTqvnpQsAPsEhpYnin366tB4YwVud0=; b=QzJZl5v1Ki1We2YLspmGA+rpzFBxnp909EdYug8tmRx1/YOOvw0MFMmziKJsUT9gOSoglfBlDF2Xg3MXj6ZYZXShR6mLll6b3pRpwCjFF90snVyAxwYdwHr9aPGMQq2AXl2CWWnrLvb3uHlJLLerGhRRYIuxyacun9FClZxrEITiVgZWmoWq+qM/G2NjaIxIVB2hjPuqY8kjHSdvZYPNf5t3xBbixbDmhrR0cCzXr7o9jmaGM6drDuAcCzfM/EtPdzkw06Z8ZvrKyNyTW9Q+zbJw25wHso4EBb5pBNoCfzLx7M5JipJzWSAZapJ4D0+74lDSIpjHsOaywxibJJV3cw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 121.100.38.198) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=sony.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=sony.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Sony.onmicrosoft.com; s=selector2-Sony-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=41uFhNyJnV5dNdTqvnpQsAPsEhpYnin366tB4YwVud0=; b=TN8Au/bgSIWGrCft63simGS8ITEDFpGOQNej6hgK+2r083vjG9d9Vdg8MxrzHb9eI1/ikh+gXN6ux0dqzJqD+pNwnxAkS0R4jjW5Jn1BIQgLoDUwV5YYn+Q3C72LWRBoSz8wcnpgZU+N0Lj79WWaS5xYRPAPby/Xq7aVDbiplfM= Received: from SJ0PR05CA0008.namprd05.prod.outlook.com (2603:10b6:a03:33b::13) by SJ0PR13MB5845.namprd13.prod.outlook.com (2603:10b6:a03:431::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.24; Thu, 7 Mar 2024 13:04:00 +0000 Received: from SJ5PEPF000001CD.namprd05.prod.outlook.com (2603:10b6:a03:33b:cafe::40) by SJ0PR05CA0008.outlook.office365.com (2603:10b6:a03:33b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.8 via Frontend Transport; Thu, 7 Mar 2024 13:03:59 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 121.100.38.198) smtp.mailfrom=sony.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=sony.com; Received-SPF: Fail (protection.outlook.com: domain of sony.com does not designate 121.100.38.198 as permitted sender) receiver=protection.outlook.com; client-ip=121.100.38.198; helo=gepdcl09.sg.gdce.sony.com.sg; Received: from gepdcl09.sg.gdce.sony.com.sg (121.100.38.198) by SJ5PEPF000001CD.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 via Frontend Transport; Thu, 7 Mar 2024 13:03:58 +0000 Received: from gepdcl04.s.gdce.sony.com.sg (SGGDCSE1NS08.sony.com.sg [146.215.123.198]) by gepdcl09.sg.gdce.sony.com.sg (8.14.7/8.14.4) with ESMTP id 427D2A7x004570; Thu, 7 Mar 2024 21:03:41 +0800 Received: from mail.sony.com ([43.88.80.246]) by gepdcl04.s.gdce.sony.com.sg (8.14.7/8.14.4) with ESMTP id 427D1b5v032552; Thu, 7 Mar 2024 21:01:37 +0800 Received: by mail.sony.com (Postfix, from userid 1000) id 255EA20C0687; Thu, 7 Mar 2024 18:25:11 +0530 (IST) Date: Thu, 7 Mar 2024 18:25:11 +0530 From: Sreenath Vijayan To: pmladek@suse.com, john.ogness@linutronix.de, corbet@lwn.net, gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: rdunlap@infradead.org, rostedt@goodmis.org, senozhatsky@chromium.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, taichi.shimoyashiki@sony.com, daniel.palmer@sony.com, anandakumar.balasubramaniam@sony.com, sreenath.vijayan@sony.com Subject: [PATCH v5 1/2] printk: Add function to replay kernel log on consoles Message-ID: <7ca188a59ef016c7730031c10f072d478434c04a.1709277332.git.sreenath.vijayan@sony.com> References: Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001CD:EE_|SJ0PR13MB5845:EE_ X-MS-Office365-Filtering-Correlation-Id: fa40011f-0ce7-4e72-b4e8-08dc3ea70df0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dUMNtcmIOG8+N69cut2u8HwkMyUocD/APPtQIssSJE8AvbXymzL/SxibhRgc5qp8GV45gp+HfhPBbGHaz7hh7SjFM8HhCu3ehmsMtdGrKI272u7mIY0XDJ11jvKcKYrCiV9xP9qc/vyKI77KBhyONZOxX4XwL+7TcadVb9Sm6pRg0yaeZ4TgVp1bq7Idqg0bLd3Osdhy3zh0ve819h6VnRwDs1qnA+eTW2+sXdu84qBGyOlp8o9AsCBoWigtlzN8UGFt1Sjf8W2EzlSG74egC/jY1UNCrpBB9+AuA3hz2ijCLB9e+DA5OlDhQv95AEUiCDsGe++SiTWQuVeei4dFfSwYcdoN8dFpDR8Lj+zdVfYa5oGEXtLmCILs9K+oYCICGtKz0ATzJQLsz7XU/Uj4BNZW1KB/d0G2MbaupOb/V1wpJxJmEousHfhGKRTfYHln3opiUR7LTXP5mBlbnf7WPZXtggde5JElMZKM3ihmWN9RgOYLj1dnZUnE9n2vxXptrkCj0S9mTEWTlyCo1n4Gekg49lFST9yDZ5TKq8G1IJgtAjlhsqL72TeKKspWCazEcjmKY7nXc5UiOLM1LapYzph3OaDAsyjbsu99W79T4buwnAo7/L+FuvjAoRgUThSKztES2S4UaXc1TYvzOuJUaf0cE58iomGVEv6cf3zScYwXiV8HS5+nYhhUhe572tou+BkQkC0jDG/VA96fnHwpNmy3c2B0YIFiF4wdpm80i/WBdnU6VBJepkMMHD2To6LO X-Forefront-Antispam-Report: CIP:121.100.38.198; CTRY:SG; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:gepdcl09.sg.gdce.sony.com.sg; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(82310400014)(36860700004)(376005); DIR:OUT; SFP:1101; X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2024 13:03:58.8638 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fa40011f-0ce7-4e72-b4e8-08dc3ea70df0 X-MS-Exchange-CrossTenant-Id: 66c65d8a-9158-4521-a2d8-664963db48e4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=66c65d8a-9158-4521-a2d8-664963db48e4; Ip=[121.100.38.198]; Helo=[gepdcl09.sg.gdce.sony.com.sg] X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: TreatMessagesAsInternal-SJ5PEPF000001CD.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR13MB5845 Add a generic function console_replay_all() for replaying the kernel log on consoles, in any context. It would allow viewing the logs on an unresponsive terminal via sysrq. Reuse the existing code from console_flush_on_panic() for resetting the sequence numbers, by introducing a new helper function __console_rewind_all(). It is safe to be called under console_lock(). Try to acquire lock on the console subsystem without waiting. If successful, reset the sequence number to oldest available record on all consoles and call console_unlock() which will automatically flush the messages to the consoles. Suggested-by: John Ogness Suggested-by: Petr Mladek Signed-off-by: Sreenath Vijayan Signed-off-by: Shimoyashiki Taichi --- include/linux/printk.h | 4 +++ kernel/printk/printk.c | 77 +++++++++++++++++++++++++++++------------- 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/include/linux/printk.h b/include/linux/printk.h index 8ef499ab3c1e..8df2ac6c0e1f 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -192,6 +192,7 @@ void show_regs_print_info(const char *log_lvl); extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; extern asmlinkage void dump_stack(void) __cold; void printk_trigger_flush(void); +void console_replay_all(void); #else static inline __printf(1, 0) int vprintk(const char *s, va_list args) @@ -271,6 +272,9 @@ static inline void dump_stack(void) static inline void printk_trigger_flush(void) { } +static inline void console_replay_all(void) +{ +} #endif #ifdef CONFIG_SMP diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index f2444b581e16..9e38cf0c1002 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3134,6 +3134,40 @@ void console_unblank(void) pr_flush(1000, true); } +/* + * Rewind all consoles to the oldest available record. + * + * IMPORTANT: The function is safe only when called under + * console_lock(). It is not enforced because + * it is used as a best effort in panic(). + */ +static void __console_rewind_all(void) +{ + struct console *c; + short flags; + int cookie; + u64 seq; + + seq = prb_first_valid_seq(prb); + + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { + flags = console_srcu_read_flags(c); + + if (flags & CON_NBCON) { + nbcon_seq_force(c, seq); + } else { + /* + * This assignment is safe only when called under + * console_lock(). On panic, legacy consoles are + * only best effort. + */ + c->seq = seq; + } + } + console_srcu_read_unlock(cookie); +} + /** * console_flush_on_panic - flush console content on panic * @mode: flush all messages in buffer or just the pending ones @@ -3162,30 +3196,8 @@ void console_flush_on_panic(enum con_flush_mode mode) */ console_may_schedule = 0; - if (mode == CONSOLE_REPLAY_ALL) { - struct console *c; - short flags; - int cookie; - u64 seq; - - seq = prb_first_valid_seq(prb); - - cookie = console_srcu_read_lock(); - for_each_console_srcu(c) { - flags = console_srcu_read_flags(c); - - if (flags & CON_NBCON) { - nbcon_seq_force(c, seq); - } else { - /* - * This is an unsynchronized assignment. On - * panic legacy consoles are only best effort. - */ - c->seq = seq; - } - } - console_srcu_read_unlock(cookie); - } + if (mode == CONSOLE_REPLAY_ALL) + __console_rewind_all(); console_flush_all(false, &next_seq, &handover); } @@ -4259,6 +4271,23 @@ void kmsg_dump_rewind(struct kmsg_dump_iter *iter) } EXPORT_SYMBOL_GPL(kmsg_dump_rewind); +/** + * console_replay_all - replay kernel log on consoles + * + * Try to obtain lock on console subsystem and replay all + * available records in printk buffer on the consoles. + * Does nothing if lock is not obtained. + * + * Context: Any context. + */ +void console_replay_all(void) +{ + if (console_trylock()) { + __console_rewind_all(); + /* Consoles are flushed as part of console_unlock(). */ + console_unlock(); + } +} #endif #ifdef CONFIG_SMP From patchwork Thu Mar 7 12:59:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sreenath Vijayan X-Patchwork-Id: 778784 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2044.outbound.protection.outlook.com [40.107.94.44]) (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 BBB5F12B141; Thu, 7 Mar 2024 13:08:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709816887; cv=fail; b=E1HRvtANwIHqJ8Ga5LMJEMzattYWi27vy5cXW7uwED9evpKLVtDacFamQ9Ia03FnhLNqcZIwGmu0EaUNk7Noc9Ln4R2SKqSF7Kv8EzSb9GBm8POwMNckhgJj4bFAyfU7NVALjDvpu/WIZOJdCOGbpCDGHqDdSrImPNeEc6jdbjA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709816887; c=relaxed/simple; bh=fXYwY8E4kjwRMfO5iYy9stk+qoWzPJKSXKg4B/4wtOI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=s7iJMa/1u29TFGKhJ5g+H74Sh3XoPdyrXFI8mFqbdcAISFn/lnriQfGUlSDcuc3xHHxvsEAJtMW9SJiZp3W8EWtu4I6ED/b/KYyDyxvEDaTPNmfRB0QHBlFqhgKavYOaB32DVpB6Q3lcphHCRpONj6ltv6Tx4YgvLw4ZfcQi8/s= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com; spf=pass smtp.mailfrom=sony.com; dkim=pass (1024-bit key) header.d=Sony.onmicrosoft.com header.i=@Sony.onmicrosoft.com header.b=cJ3HZVCa; arc=fail smtp.client-ip=40.107.94.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sony.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=Sony.onmicrosoft.com header.i=@Sony.onmicrosoft.com header.b="cJ3HZVCa" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O6s77I6XgKZLmEMz49ZG7Uwq+nwgSx4FgOS+beDd6Ry1yUVPuQU+EFs6Blgl/1VJBfctzll2D9ALf7OuO5lRLJ9YQv2lFW5pR2poKLf1F1OfMqTM9gFIfnavr8MspYLLsuketjKtwgLxQp/TLHaoa8KsRBpyJdGCHZ1EXwkUDMrD17VF6H+NeYSWBPYEmrGvbYzVmJCUwSiIJt6SBRoY0z2OFa5HurudF0316O2l+EeC+GOrgeT6d3aR3/zlv8vKW95Z+BWsD7e8sLTbb4xcSCFhHvwZ33pmMcCJP8ni3e0xIgTe7iPQ7Tk/mS7MnsHs+o3mPQ3h1WvyO2I1KDiFQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ij4iF5rOPAZzFwjp7vIZA1hf4Y/j5ioiegmA69B8UZk=; b=JDSGWZCWwy1wNpXGfaXiKxFs2xgJ3lpxHEE041x24sFoNBsn9xWHME4hOxQ3dqT4hA4W2C0ZnsEdrvwhgL519HUE4CsDG/m2AcyZ2eGJ6L9TFoZ1yqGIY4e4QY2Pe4KIkllVzRRawjatbMXi0pisIDTO4yActjLMi5ZO0faeYrvTn4S46NwiEe0SQvDVDoqo4nLEBp6bV2uaDI6YkGKqD1BeoxtgLgEmyf6l66lL2gys3aOVKS73WGk02v/GE/fXEUy3POKlIDJMjqrdH8wUX/v3K4lRHJBbV25tp2QrVX1NXO/wZMldFyM3gjEk35G6bYkkRpuPbpSbZ1AVHIF0Eg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 121.100.38.198) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=sony.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=sony.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Sony.onmicrosoft.com; s=selector2-Sony-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ij4iF5rOPAZzFwjp7vIZA1hf4Y/j5ioiegmA69B8UZk=; b=cJ3HZVCaHJ+JoIrttbQcuFsvZNzmRSvtH6clATk4wb/shsk6lzQ6ebR+dMJOXBPPhaNcG4NxjP3BEx5DDuyQS/CPoEMqE1ZRv87r5+9pn2Vtosn6DRbaT+qts55wSMY32Zz8krvKv4cNVIBn6tjU8U1HPJhpAAg7ZJW6pHDhxqo= Received: from BYAPR05CA0015.namprd05.prod.outlook.com (2603:10b6:a03:c0::28) by DM6PR13MB4445.namprd13.prod.outlook.com (2603:10b6:5:1b6::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.26; Thu, 7 Mar 2024 13:08:00 +0000 Received: from SJ5PEPF000001CA.namprd05.prod.outlook.com (2603:10b6:a03:c0:cafe::31) by BYAPR05CA0015.outlook.office365.com (2603:10b6:a03:c0::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.24 via Frontend Transport; Thu, 7 Mar 2024 13:07:59 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 121.100.38.198) smtp.mailfrom=sony.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=sony.com; Received-SPF: Fail (protection.outlook.com: domain of sony.com does not designate 121.100.38.198 as permitted sender) receiver=protection.outlook.com; client-ip=121.100.38.198; helo=gepdcl09.sg.gdce.sony.com.sg; Received: from gepdcl09.sg.gdce.sony.com.sg (121.100.38.198) by SJ5PEPF000001CA.mail.protection.outlook.com (10.167.242.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 via Frontend Transport; Thu, 7 Mar 2024 13:07:59 +0000 Received: from gepdcl04.s.gdce.sony.com.sg (SGGDCSE1NS08.sony.com.sg [146.215.123.198]) by gepdcl09.sg.gdce.sony.com.sg (8.14.7/8.14.4) with ESMTP id 427D6A3t005712; Thu, 7 Mar 2024 21:07:41 +0800 Received: from mail.sony.com ([43.88.80.246]) by gepdcl04.s.gdce.sony.com.sg (8.14.7/8.14.4) with ESMTP id 427D5bRn001636; Thu, 7 Mar 2024 21:05:37 +0800 Received: by mail.sony.com (Postfix, from userid 1000) id 7CE2720C0688; Thu, 7 Mar 2024 18:29:11 +0530 (IST) Date: Thu, 7 Mar 2024 18:29:11 +0530 From: Sreenath Vijayan To: pmladek@suse.com, john.ogness@linutronix.de, corbet@lwn.net, gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: rdunlap@infradead.org, rostedt@goodmis.org, senozhatsky@chromium.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, taichi.shimoyashiki@sony.com, daniel.palmer@sony.com, anandakumar.balasubramaniam@sony.com, sreenath.vijayan@sony.com Subject: [PATCH v5 2/2] tty/sysrq: Replay kernel log messages on consoles via sysrq Message-ID: References: Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001CA:EE_|DM6PR13MB4445:EE_ X-MS-Office365-Filtering-Correlation-Id: 4cd797d4-4c5c-43b4-b437-08dc3ea79d3d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: osa+gW/U++IgEtF4D6Rx5TEgfJJg9KDeUoOL39b32B7R2KclV9annTPpkBTy0TAVSinyah3CulSM132CCkVK+pwjktCtj7x7dfn8LTHLHs4wgQvfi+n3c/6kRZi+k9MypRlOLgrNNd4IQN8LhTOUwNl8ONwf3UkDcvmj26scIgkTAjZvlYtGGp1Oi/2AIW/VewCptoddOCeQ0FhrALdXm44Jcn5yJMzrEbqALKVyzXmc8POA3cAWds1vGiq/+2SB5+fBam2bIxUnKFwf/jrPFPH93iltYUqwb6q4OIHfnG4YSQcf/HIIPEAOGTKVhal5jWWm3A50D93981Ce3xQVrnli8ma6P5NNXvNXkBorvCkqEPGYDDImG8RaXLhhPSDgg6D3kbLZ4dvX1Xcjq8E3uQOP2W3lwl5Z2DdT7itTg4DgJNH+CTyYSDGFuUb/2Ra7FaXBSdVyoSV6B/t0CjhB7A9rb0QCcPCBR8vTeuCNfHD2CmFHnr9EAvd3UMUlpf+bZC9phll1XLwIUwCCbkZb+MvlsQuO93X8fEA7DQS93dkd64kDh9DbumlJB/oph3HLrSkyXNNNiVMERQUy87tXQRPLc/QgzRPBCDH3VGSSJGEcxhg4YNDuzqFAOitZwmn4XFu7wdhV7J4KfZXhGfb4RrP4HqoRa19x+BCUwuB2jMnQxz0dNat8Z2AW70Kyd0XXuxAdLSnX+Xi5x0ssX1U3jT/Er7efgUf4rR8CtR0Y+fv43uNwbSpk7K5YuiUEhGMu X-Forefront-Antispam-Report: CIP:121.100.38.198; CTRY:SG; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:gepdcl09.sg.gdce.sony.com.sg; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(376005)(36860700004)(82310400014); DIR:OUT; SFP:1101; X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2024 13:07:59.2513 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4cd797d4-4c5c-43b4-b437-08dc3ea79d3d X-MS-Exchange-CrossTenant-Id: 66c65d8a-9158-4521-a2d8-664963db48e4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=66c65d8a-9158-4521-a2d8-664963db48e4; Ip=[121.100.38.198]; Helo=[gepdcl09.sg.gdce.sony.com.sg] X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: TreatMessagesAsInternal-SJ5PEPF000001CA.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR13MB4445 When terminal is unresponsive, one cannot use dmesg to view the printk ring buffer messages. Also, syslog services may be disabled, especially on embedded systems, to check the messages after a reboot. In this scenario, replay the messages in printk ring buffer on consoles via sysrq by pressing sysrq+R. The console loglevel will determine which all kernel log messages are displayed. The messages will be displayed only when console_trylock() succeeds. Users could repeat the sysrq key when it fails. If the owner of console subsystem lock is stuck, repeating the key won't work. Suggested-by: Petr Mladek Signed-off-by: Sreenath Vijayan Signed-off-by: Shimoyashiki Taichi Reviewed-by: John Ogness --- Documentation/admin-guide/sysrq.rst | 8 ++++++++ drivers/tty/sysrq.c | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/sysrq.rst b/Documentation/admin-guide/sysrq.rst index 2f2e5bd440f9..8098a1b4908d 100644 --- a/Documentation/admin-guide/sysrq.rst +++ b/Documentation/admin-guide/sysrq.rst @@ -161,6 +161,8 @@ Command Function will be printed to your console. (``0``, for example would make it so that only emergency messages like PANICs or OOPSes would make it to your console.) + +``R`` Replay the kernel log messages on consoles. =========== =================================================================== Okay, so what can I use them for? @@ -211,6 +213,12 @@ processes. "just thaw ``it(j)``" is useful if your system becomes unresponsive due to a frozen (probably root) filesystem via the FIFREEZE ioctl. +``Replay logs(R)`` is useful to view the kernel log messages when system is hung +or you are not able to use dmesg command to view the messages in printk buffer. +User may have to press the key combination multiple times if console system is +busy. If it is completely locked up, then messages won't be printed. Output +messages depend on current console loglevel. + Sometimes SysRq seems to get 'stuck' after using it, what can I do? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 02217e3c916b..c4deea41a8b5 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -450,6 +450,17 @@ static const struct sysrq_key_op sysrq_unrt_op = { .enable_mask = SYSRQ_ENABLE_RTNICE, }; +static void sysrq_handle_replay_logs(u8 key) +{ + console_replay_all(); +} +static struct sysrq_key_op sysrq_replay_logs_op = { + .handler = sysrq_handle_replay_logs, + .help_msg = "replay-kernel-logs(R)", + .action_msg = "replay kernel logs on consoles", + .enable_mask = SYSRQ_ENABLE_DUMP, +}; + /* Key Operations table and lock */ static DEFINE_SPINLOCK(sysrq_key_table_lock); @@ -519,7 +530,7 @@ static const struct sysrq_key_op *sysrq_key_table[62] = { NULL, /* O */ NULL, /* P */ NULL, /* Q */ - NULL, /* R */ + &sysrq_replay_logs_op, /* R */ NULL, /* S */ NULL, /* T */ NULL, /* U */