From nobody Tue Jul 14 14:06:43 2026 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) (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 8974E39AC5; Wed, 13 Mar 2024 10:27:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710325673; cv=fail; b=pu76oVgU93x9uetydXV+4vOmqOk8AHsR9ABmTVxilonC2QE8fKwYkW3XCTO2glOk+wx6WN41wTT4YTGgzhU8eRpaIuR8RcnnnRVfYsLfWw4sQdbMvX4AaePHsCtkVctgwPPNnCqdWclBqt91U3cqF/NNSpEcLzEBMpzgdUutk+g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710325673; c=relaxed/simple; bh=7mdZEdyEmhu0MA4svxfOF9RPnqI4uFsajLyI2vgMrTE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hAKN7Abd14ZgmtueAi0GXE2Ba5P58tZYKeCH6hy0W+jb4RQp8ehplRxKEZZYOi++HxPzE9F/W1gOOlBsrioarITe9UJe7YJNCXsvay9/iiVsxlvKpHb17DaINfQbVMD/YmpLAw6j2npjqDqCIR4mcfDvKwi35rPq0ZjlYwKClVY= 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=O2PI34iR; arc=fail smtp.client-ip=40.107.236.41 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="O2PI34iR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nc1js9j4M4jA8u9OEvgM87/3F5xsgkD6j0zp5tG6Cdmfoljp2RUskZ2kRePske6a7EEg2iEb7SiNex7P9X5buKHZtpw8jEEe4e36w8U5jPquNNDEb2gOX05DKOqM/MqHGkSmLXkdLkkewomey5hDABxUMr8htEDJjlo4Bsbn9aBjN61z9tzPnUgdngTJgEs7Q2rW4uLWoRBEK4Xqp/X2D+aly5uSwRUgf7Zb2IHem0CdLiLcvX3sdaD1hYBtRhPVvp+XdLvnsrFQPtms7dXa6zLsduPhWUuYghqJe5Jg8SAsPcH2nhOxQoWDJzbMvQ0TCvOMjGNuS3Mn6MHwGNwbfQ== 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=xkGjXogb3y/OurZ8HVAGup2vwhLqTcg2P0uDSDdk1ZY=; b=M2QF8Tmg4sTOjgCsuhzvEJg+LnadL3P9SsWQT/d/9p2GULOsK8Yj1NXj9+7TfYlcWXv8tWIzxNRMXN4JiONTjhQV7YhQgXbfCiHEddrnZ1iJmfdRdzxRgFOm6hTyUGVJddQMU+FjIR4HW9sX+ukgYiBucxfYcj/0Gsx4PRNMSirjsuMxkPEyInpvHhLF45BaXsBF3gLzfu4DPilwil/hMGjoeez8qmDS2BHYOnapY36uPxGkqttrPVzYu3JdDyu0KvUF/Rlsoa+EPogRzKKadx8U4h5IG8bVLz8AoS7yHUBTmnYO24trG/SMy9IlaSsSoG6PrZO+44VE/HjLm/tZSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 121.100.38.196) 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=xkGjXogb3y/OurZ8HVAGup2vwhLqTcg2P0uDSDdk1ZY=; b=O2PI34iRrDryfpDFY7GifLrpp5k0TE0qharsD9QJhDnINy+dz+l38PyI1W8AxkmlGAKDd9tgA17bFxQhoSZnaRNk2oOCvc59SD4UpDcgTKtacZr25RTZPm83bLXdWSIt6wUtmbmyly3XXRdSWu3/tY0t6zVUjQLVMMnsKqOtRPE= Received: from SJ0PR03CA0102.namprd03.prod.outlook.com (2603:10b6:a03:333::17) by PH7PR13MB6512.namprd13.prod.outlook.com (2603:10b6:510:2f2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.19; Wed, 13 Mar 2024 10:27:48 +0000 Received: from SJ1PEPF00001CE2.namprd05.prod.outlook.com (2603:10b6:a03:333:cafe::b9) by SJ0PR03CA0102.outlook.office365.com (2603:10b6:a03:333::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36 via Frontend Transport; Wed, 13 Mar 2024 10:27:48 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 121.100.38.196) 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.196 as permitted sender) receiver=protection.outlook.com; client-ip=121.100.38.196; helo=gepdcl07.sg.gdce.sony.com.sg; Received: from gepdcl07.sg.gdce.sony.com.sg (121.100.38.196) by SJ1PEPF00001CE2.mail.protection.outlook.com (10.167.242.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.12 via Frontend Transport; Wed, 13 Mar 2024 10:27:47 +0000 Received: from gepdcl02.s.gdce.sony.com.sg (SGGDCSE1NS07.sony.com.sg [146.215.123.196]) by gepdcl07.sg.gdce.sony.com.sg (8.14.7/8.14.4) with ESMTP id 42DARHuY022307 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 13 Mar 2024 18:27:30 +0800 Received: from mail.sony.com ([43.88.80.246]) by gepdcl02.s.gdce.sony.com.sg (8.14.7/8.14.4) with ESMTP id 42DARGvN018463; Wed, 13 Mar 2024 18:27:16 +0800 Received: by mail.sony.com (Postfix, from userid 1000) id 3FDE520C069A; Wed, 13 Mar 2024 15:50:52 +0530 (IST) Date: Wed, 13 Mar 2024 15:50:52 +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 v6 1/2] printk: Add function to replay kernel log on consoles Message-ID: <90ee131c643a5033d117b556c0792de65129d4c3.1710220326.git.sreenath.vijayan@sony.com> References: Precedence: bulk X-Mailing-List: linux-kernel@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: SJ1PEPF00001CE2:EE_|PH7PR13MB6512:EE_ X-MS-Office365-Filtering-Correlation-Id: 70bf26e7-99e6-41c8-17df-08dc43483ad1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P/4TyA7yZ6NKDw4dV15sGT8uG86OpBp8FC9KR8wV0E2eXQi90hlzRd7jlLV7bCwPZR9xlBfEMojGsDU/BazouXCbk/MDWKoGxiC9Dql1lhjxvsJHI1My6sZM/BZcPMwOuaGflTrmsGMp82tDneQvUuCtcY+fx/4PGu5v++m4waagP3T+P8OvFt3/2IgxOoX02G0XLb9N6/fEwRs86194CrOsz0w4HPxo4dru4qq98lWrc7OZfL3Y8BdgVzVD47sijXg7zb4vpNaf/wvIHGhZzZFqMXfQnuENnmMQPRUENYLInj7OgPWPw8FV2WPr0lFepuvb0mLibGh6kIwcA9n+zrqd089x8juntYH4yoQMKiKP2bD15Cbmd8W2IAVsZ12cESj/rRd31gKD8GvotHg6P8TMwAhg+7A7yHibYq29VJbaKs1mykSImkybMDS2NhbzOwFgrbKi2XYXYImtHqajSan4ehAj1YPlFieRx2+nxw/wUeURvyqOhPaGKWsGYTAELOR3YjKHhchsgsMLUQUe49YFKpgth/blC/D1Rd0HvNkauI+uEZeo1LMgq+XRcWqPwK3fvwvGkxN9BsXWykXCyVmVpk3+hl2o2Get1fCPU+NQov8CUlNQRZrMQTeNW+7vWi9Hs6IobO5XvEGrqWI/jGUL0XB/RxDAjGF0svZFo0QHRakdLu+QdY4xnT/xWoUxK49RsU4BRQwoVmcZ+peRNbR9WMLTpxExVObegwNUmP8iQT2Y9LPlCjAG6EmakRg3 X-Forefront-Antispam-Report: CIP:121.100.38.196;CTRY:SG;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:gepdcl07.sg.gdce.sony.com.sg;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(1800799015)(376005)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2024 10:27:47.7474 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 70bf26e7-99e6-41c8-17df-08dc43483ad1 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.196];Helo=[gepdcl07.sg.gdce.sony.com.sg] X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: TreatMessagesAsInternal-SJ1PEPF00001CE2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR13MB6512 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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: Shimoyashiki Taichi Reviewed-by: John Ogness Signed-off-by: Sreenath Vijayan Reviewed-by: Petr Mladek --- 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 =20 #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); } =20 +/* + * 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 =3D prb_first_valid_seq(prb); + + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(c) { + flags =3D 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 =3D 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 =3D 0; =20 - if (mode =3D=3D CONSOLE_REPLAY_ALL) { - struct console *c; - short flags; - int cookie; - u64 seq; - - seq =3D prb_first_valid_seq(prb); - - cookie =3D console_srcu_read_lock(); - for_each_console_srcu(c) { - flags =3D 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 =3D seq; - } - } - console_srcu_read_unlock(cookie); - } + if (mode =3D=3D CONSOLE_REPLAY_ALL) + __console_rewind_all(); =20 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); =20 +/** + * 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 =20 #ifdef CONFIG_SMP --=20 2.25.1 From nobody Tue Jul 14 14:06:43 2026 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2045.outbound.protection.outlook.com [40.107.92.45]) (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 838253CF74; Wed, 13 Mar 2024 10:29:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710325794; cv=fail; b=F7y7NSmvlKXOg9R+TipmxrYIl9hL6obRZlltV+w8Yw13at9YK+UEWsYSLzHcV3NZHokSQ77fAoBASHxYcgdzvvZPx7Za5kyLTf/rCDtIg6CMj/VE3lyRTV/Q+q/nqAVFPpNE2oJYFtPp8eDphbM6OXbu4xL0LM4chIxjObcplHc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710325794; c=relaxed/simple; bh=f9vQ1kvdzYlX86eT32HukMAsHm7Riy/EpZNOFvW8nO8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JM5PA1H9nBXqIRRFnonhFiZY2wFRFLAf8VY7i8eU9qlv/nqbb3EbKNfLPo6Y5o8RYgiscyadOuDCFiKa6IqEJE6kqpR5f6eS3FHEQF20JRWv29UhRhKqEs20DUGZzYUcLjlX5l1evG290+rFJSJwNfp0r7KTwOcvw8R5+08l8jE= 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=gjbC+ovf; arc=fail smtp.client-ip=40.107.92.45 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="gjbC+ovf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TZ73/xdKklfady8sTHarSDBYP77DKnI6XlPPIpbPCDfsUumQorXEUpfLDR5NyZ3B/0WjFZ+AMv7AEs0JItInbi+xGKBOCZh53IbzuIMI413MyQueG6Gg5Sg18TCiM1XbESIwWvgaMzJkw4b8NlIf6SB0TntfRZz5Kw3pDj/q7Ah++kmai7I4EFc5FS6beFNwR5SRERvAp6ro/rrO53zo/kb4uOYfmNVQq93vGkD8qjC0epYyQqpajn0icn6Tji+b/2dJ/4gjJZKe5c/LMMxLTJ8FcpqEhdJK8D31y5JNM4AOuXOf7DNvTzOc1Xl6xZ2fpPpWi9VnMY+rp2VbyJCZPA== 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=suUxxneNxNn8KC5bW0kgNjnqDzTwMTG0WXtpd7dvX1I=; b=lGJorNlsSNAD0WvwCEVbZna8NIOroijqalKmmjhzlezfctleKIq4uGguYwetR6P4gES/zpfRA7WQK33yk4Q2CYUk2MCV2YWodNFUkcynqW7r+DVj9EUhhRD5C2mo/E2j9vLciLgxSlVqo6bFiXXvLIusi3BkygTg56fxJrMhWaxNwG7j52shUjsDpg/NqH/gAaWfOHni9ZCjaJ0MYRbdq4eVDHEhYlQwfC5pVju4wz/8MREpE3BbZVoItV+wS/jF8tclTT9Oaw609BFSxn84hkqfkgvlzK52u3+jOtCukvkN0tShjzvFCpvn6HEiz/jeSoZVNN1dIU/qxGaIqw61bA== 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=suUxxneNxNn8KC5bW0kgNjnqDzTwMTG0WXtpd7dvX1I=; b=gjbC+ovfgukReyFZ5WAnrDZ7WhBF9c8B5khSANCjhIFdGI2zA1ujtIPxTKstmcouQEHgFYb1V1vMfVzbaxXeevw37mnQjmaloZ9TynXl0fsdSgm639XL7U53wO2XKLPXY2nNiz+kDpzkT0Zjq1qZTP3yR8mmFCMPoT6oufdo4Dg= Received: from BLAPR03CA0100.namprd03.prod.outlook.com (2603:10b6:208:32a::15) by DM6PR13MB4034.namprd13.prod.outlook.com (2603:10b6:5:2af::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.19; Wed, 13 Mar 2024 10:29:49 +0000 Received: from BL6PEPF0001AB74.namprd02.prod.outlook.com (2603:10b6:208:32a:cafe::15) by BLAPR03CA0100.outlook.office365.com (2603:10b6:208:32a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.20 via Frontend Transport; Wed, 13 Mar 2024 10:29:48 +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 BL6PEPF0001AB74.mail.protection.outlook.com (10.167.242.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.12 via Frontend Transport; Wed, 13 Mar 2024 10:29:48 +0000 Received: from gepdcl02.s.gdce.sony.com.sg (SGGDCSE1NS07.sony.com.sg [146.215.123.196]) by gepdcl09.sg.gdce.sony.com.sg (8.14.7/8.14.4) with ESMTP id 42DATHsH005627; Wed, 13 Mar 2024 18:29:30 +0800 Received: from mail.sony.com ([43.88.80.246]) by gepdcl02.s.gdce.sony.com.sg (8.14.7/8.14.4) with ESMTP id 42DATGrZ019079; Wed, 13 Mar 2024 18:29:16 +0800 Received: by mail.sony.com (Postfix, from userid 1000) id 689E720C069B; Wed, 13 Mar 2024 15:52:52 +0530 (IST) Date: Wed, 13 Mar 2024 15:52:52 +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 v6 2/2] tty/sysrq: Replay kernel log messages on consoles via sysrq Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@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: BL6PEPF0001AB74:EE_|DM6PR13MB4034:EE_ X-MS-Office365-Filtering-Correlation-Id: 97dcc7e3-b661-4e21-2921-08dc434882a1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fnMgTi4eM6wXnTTZwcLa5dsPfhJYADE6bGRV28V+QdOrVYS0SCXUV2iiagkvOoDPToUdtLnxScNMJTVudR8fPNxkxTAifnm2iogxkP3wXyKvAL4EchVogXgGdqv7TawoXCDpt/OvKZlCz9Aj8FGWq5Zldt8lbl1MmqVd9gMDQzIT7ej7Yvt9hwBpUGLWQmYgrol32mCArTo9DloQG8cK4O3mymB1GlyG7W+jMYSI2vDN+zDxRfnJR8zG8NjQO/MpqoYiThGq9db1Q3dp5DzFoKxP2QNok/BWhzHvFtgTjyYopkkL4ugxjTAxT0xbAPM4EV3d1F2PWeAV8JuP2OVIgYbzPKsFDcKhEjOXeNhQCfjae0iK2zdIRYIhBbOuzY39fIZZwffjb6raI6+qFnaw0McpHoB2jhUHTlw7CFTVORrO+GVQJVyuhL6r7jM6D5ZCpDy1nv6sR2Q18rJlVAea4kjFQ76h//bU30QcFVPdhlF9iPKS0ExEw7Jar+qHmT7BcAmnnQfmaVfnlMTJObDtD5hxygOOy4wt61hYuwrIpxADUmWU+Gviy9wKw0muh/KBbQBNGL80VpWBKY1NkxFLkBk07as7BnaKtW6L6YRRCEgYJriGSicFCo9pfYSuQnOrnIVMY/4hKeQ3/ZC3AEgRVWThP1yDnF6HcougzdgmcTvtQAvKLH1Fu66vdK55eoJITGnfBDFJ9vbMeGfL1owFpsILZoC6UqRE3S13OVQvgQiyoVQPtpz7hjrkE04/ROab 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)(36860700004)(1800799015)(376005)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2024 10:29:48.0886 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 97dcc7e3-b661-4e21-2921-08dc434882a1 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-BL6PEPF0001AB74.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR13MB4034 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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: Shimoyashiki Taichi Reviewed-by: John Ogness Signed-off-by: Sreenath Vijayan Reviewed-by: Petr Mladek --- Documentation/admin-guide/sysrq.rst | 9 +++++++++ drivers/tty/sysrq.c | 13 ++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/sysrq.rst b/Documentation/admin-guid= e/sysrq.rst index 2f2e5bd440f9..a85b3384d1e7 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. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D =20 Okay, so what can I use them for? @@ -211,6 +213,13 @@ processes. "just thaw ``it(j)``" is useful if your system becomes unresponsive due to= a frozen (probably root) filesystem via the FIFREEZE ioctl. =20 +``Replay logs(R)`` is useful to view the kernel log messages when system i= s hung +or you are not able to use dmesg command to view the messages in printk bu= ffer. +User may have to press the key combination multiple times if console syste= m is +busy. If it is completely locked up, then messages won't be printed. Output +messages depend on current console loglevel, which can be modified using +sysrq[0-9] (see above). + Sometimes SysRq seems to get 'stuck' after using it, what can I do? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ =20 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 02217e3c916b..e5974b8239c9 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -450,6 +450,17 @@ static const struct sysrq_key_op sysrq_unrt_op =3D { .enable_mask =3D SYSRQ_ENABLE_RTNICE, }; =20 +static void sysrq_handle_replay_logs(u8 key) +{ + console_replay_all(); +} +static struct sysrq_key_op sysrq_replay_logs_op =3D { + .handler =3D sysrq_handle_replay_logs, + .help_msg =3D "replay-kernel-logs(R)", + .action_msg =3D "Replay kernel logs on consoles", + .enable_mask =3D SYSRQ_ENABLE_DUMP, +}; + /* Key Operations table and lock */ static DEFINE_SPINLOCK(sysrq_key_table_lock); =20 @@ -519,7 +530,7 @@ static const struct sysrq_key_op *sysrq_key_table[62] = =3D { NULL, /* O */ NULL, /* P */ NULL, /* Q */ - NULL, /* R */ + &sysrq_replay_logs_op, /* R */ NULL, /* S */ NULL, /* T */ NULL, /* U */ --=20 2.25.1