From patchwork Wed Jan 17 10:12:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sreenath Vijayan X-Patchwork-Id: 763584 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2100.outbound.protection.outlook.com [40.107.101.100]) (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 46E3114270; Wed, 17 Jan 2024 10:21:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.100 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705486908; cv=fail; b=DMXusaqTBq6lttXnBGVfAd9E1XF++5WN7xiP4b6NSt26GfDeg4R6pZVEWgwXQnpLZHqQotChA8CYhBhXfgHnF+idw7t7RzvYE48lXxxz67sQdqtbs8RRm/VVfdv4HOwvDN13p08TWLg1iaQhW9qotC9eTd8yQ4AhRzv2bCr6n8E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705486908; c=relaxed/simple; bh=Ip745+jKQOduPpa1h3pQUG6ekwSEArSKen2XXkiJWdQ=; h=ARC-Message-Signature:ARC-Authentication-Results:DKIM-Signature: Received:Received:X-MS-Exchange-Authentication-Results: Received-SPF:Received:Received:Received:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic:Content-Type: X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; b=ToBewa8OWWXfhyqq41jvgZgiOjuVV4RpJfa/iOo1Lp6pk9RUK7hg6aMY1MXXRGdPwxCRub+Z6WxtidZXvmxR/dbM/5B1jIS0TdlHA0mSGrYR7MDZiIrfXukCZQB7NY78m1YhfdFCYvMfz1hknpbQ8aW4GOQxU0a//2drusI4NKQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=sony.com; spf=pass smtp.mailfrom=Sony.onmicrosoft.com; dkim=pass (1024-bit key) header.d=Sony.onmicrosoft.com header.i=@Sony.onmicrosoft.com header.b=mIPqLgtV; arc=fail smtp.client-ip=40.107.101.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=sony.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=Sony.onmicrosoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=Sony.onmicrosoft.com header.i=@Sony.onmicrosoft.com header.b="mIPqLgtV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bty2fmnZ/IlItp40ApG1JdP92abIXeGaGTviZRRrz7AySCzRDRoGmRfIK3gRZLDZHPKk+FaIJauLyoXVkjtpfZ5p9PmKXQ2a7ViBQ3XcmWRVVjPW26t9Xjv3JI5uzy3lt3T3bv3W6OYRXuEa5ayWTZadj6ZpmkYKp6hsK91chVpaF5AZroeQfvMDVAiIA+1Xf7i2VnUvuSTWLDJUupFJhnzA7dRBW6TYx3kP8ygshcwiBO0NW9m3UWfxYZ/i431beZfNAlhdGwn+iIZkQxSbho95GHqEbIvE+POBcxm46hjis7LT2j6B1xh2BHYvzriVJcQcxyJ2CE9sa4i1JCDpRQ== 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=TlcEPjK8Ca5MkZR390lVLeD6cQTAH0CTXgHAYgBtID0=; b=R49fZ12K7qJNq1OPmTMsNp3yV7DeevNXYYxhPVm7zoSZJzghQHCrWbbySujLfEuPSMpTOscpObW1t/EnBtrqYkVpncbuljC3j+ve51isfOIDJwBsmnc9AhHC6W5WLqTqdXBn0pWJgQDIV43Zm+it07R9YR1P5sJCtPBXst2ChJYdLF4/df2oBWDWBw4fOQIXP1MmVskm9hCwR0UvvDFEeJaZTJ2WW9wqMYwCZjrwVCiyd2A2fcFoYacir/LckehwczDEQvVDKKLKrgtZjRMa0Wq6ZsbPdukwMGHr5s7wQWustcFZw/yYaXyvVGQ65bJHOl/Zb411GDvpOKf+Kbzgbw== 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=mail.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=TlcEPjK8Ca5MkZR390lVLeD6cQTAH0CTXgHAYgBtID0=; b=mIPqLgtVXfj/EZ48tkOsUrrqi0frgGV43j2jm4izR34oVIAn7QXKVSemcJAoGYESvfOqC5S6j1rbM32qX7VC4haekAv+OqF4Mikj+Jbyu6racKHC6kydiCphXaI2MeMuRfbR+PpCRS9GE9mnHRzOVWdETiC1OkalA83yXtN7+Cc= Received: from DM6PR01CA0003.prod.exchangelabs.com (2603:10b6:5:296::8) by PH0PR13MB5568.namprd13.prod.outlook.com (2603:10b6:510:12b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.24; Wed, 17 Jan 2024 10:21:44 +0000 Received: from DS1PEPF00017099.namprd05.prod.outlook.com (2603:10b6:5:296:cafe::61) by DM6PR01CA0003.outlook.office365.com (2603:10b6:5:296::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.23 via Frontend Transport; Wed, 17 Jan 2024 10:21:43 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 121.100.38.196) smtp.mailfrom=mail.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 mail.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 DS1PEPF00017099.mail.protection.outlook.com (10.167.18.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Wed, 17 Jan 2024 10:21:42 +0000 Received: from gepdcl04.s.gdce.sony.com.sg (SGGDCSE1NS08.sony.com.sg [146.215.123.198]) by gepdcl07.sg.gdce.sony.com.sg (8.14.7/8.14.4) with ESMTP id 40HALPWP007416 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 17 Jan 2024 18:21:25 +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 40HAF09m007720; Wed, 17 Jan 2024 18:15:00 +0800 Received: by mail.sony.com (Postfix, from userid 1000) id CE1DF20C0302; Wed, 17 Jan 2024 15:43:19 +0530 (IST) From: Sreenath Vijayan To: john.ogness@linutronix.de, corbet@lwn.net, gregkh@linuxfoundation.org, jirislaby@kernel.org, rdunlap@infradead.org, pmladek@suse.com Cc: 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 v3 1/2] printk: Add function to dump printk buffer directly to consoles Date: Wed, 17 Jan 2024 15:42:19 +0530 Message-ID: <402f0cbc3a573503c7cc794113aa5137ed7f276c.1705331453.git.sreenath.vijayan@sony.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017099:EE_|PH0PR13MB5568:EE_ X-MS-Office365-Filtering-Correlation-Id: d998aa4a-c815-44dc-5434-08dc17461a74 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XicujhM4rs68CqLh6NTLjYjD5LqjspE3Geeou+n56Ejw7GSNBPKt1y0nefnsDEjKlqlqQIzQZot1bHwme2Nl/PNfoQm9lH7APY+9PZhiq1clo1VEH3OAJd0UYZ17ax78i6eu24Le1W5PrSBQyZCvW2RuT7HhiW/md7Xbw/b6ryzH5xiWpeCt86BYFpIMsQVqP/V5S5BDGGXBhLdahsRx6q60JhP3S2ANqF3pI6G5OPAtJSfipfb2ylqideeg3XzGVFEALVWk/0byOJHeS3O/XNJrlpvLwqppfRLNSHIRlBBHpzXvMTlKKJjjSobIYPKqAua2SrCbtRASogEiPabMGvZien75Upkod1UqIoKGmQ6GXAEpr9H70jKP+R6KatfNdMyE8aFhjMv1+tknItr3NOb27H34im9y/Y6wpNiPnfa8KUKwZGyM2/Xgje9KIEx7DkpRr9U67lHG/flekyRdYZbGVVmvxj7bcY0YqLWMaswgJmyzK88UiE3lfVP4WkwDGMEkfCf3aWSmtJC7wi5BLzXwg7+JKQ6G9aQBK5k2CNIs4H/lQhA+AVKC4EkEPLy+OxItdN64zvoMx1eHKqFaLE89BPDbKBU14NPYdN6hOFNlRkAdiO1ZOUwh3oCTvNp974LPoo4pkRXCKAi/UD1mqtYWZD1tsRJbMC9LQql4GSBH5KYuqt03s+at/435+zmtFpwVHPPO4/LVAQUEH90RCYSD2LlqFdFBhQhM/pv3tEfaAulY02bH4Jfd4LHM4Jxw 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)(4636009)(39860400002)(396003)(346002)(136003)(376002)(230922051799003)(1800799012)(451199024)(64100799003)(82310400011)(46966006)(40470700004)(82960400001)(40460700003)(40480700001)(35950700001)(82740400003)(81166007)(83170400001)(356005)(70206006)(70586007)(450100002)(316002)(42186006)(41300700001)(4326008)(8676002)(8936002)(44832011)(6266002)(426003)(336012)(5660300002)(498600001)(2616005)(26005)(107886003)(2906002)(83380400001)(36756003)(47076005); DIR:OUT; SFP:1102; X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2024 10:21:42.7655 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d998aa4a-c815-44dc-5434-08dc17461a74 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-AuthSource: DS1PEPF00017099.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB5568 It is useful to be able to dump the printk buffer directly to consoles in some situations so as to not flood the buffer. This needs access to private items of printk like PRINTK_MESSAGE_MAX. Add function in printk.c to accomplish this. Suggested-by: John Ogness Signed-off-by: Sreenath Vijayan Signed-off-by: Shimoyashiki Taichi --- include/linux/printk.h | 4 ++++ kernel/printk/printk.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/linux/printk.h b/include/linux/printk.h index 8ef499ab3c1e..0896745f31e2 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 dump_printk_buffer(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 dump_printk_buffer(void) +{ +} #endif #ifdef CONFIG_SMP diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index f2444b581e16..5b11fb377f8f 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4259,6 +4259,39 @@ void kmsg_dump_rewind(struct kmsg_dump_iter *iter) } EXPORT_SYMBOL_GPL(kmsg_dump_rewind); +/** + * Dump the printk ring buffer directly to consoles + */ +void dump_printk_buffer(void) +{ + struct kmsg_dump_iter iter; + struct console *con; + char *buf; + size_t len; + int cookie; + + buf = kmalloc(PRINTK_MESSAGE_MAX, GFP_KERNEL); + if (!buf) + return; + + kmsg_dump_rewind(&iter); + while (kmsg_dump_get_line(&iter, 1, buf, PRINTK_MESSAGE_MAX, &len)) { + /* + * Since using printk() or pr_*() will append the message to the + * printk ring buffer, they cannot be used to display the retrieved + * message. Hence console_write() of serial drivers is used. + */ + console_lock(); + cookie = console_srcu_read_lock(); + for_each_console_srcu(con) { + if ((console_srcu_read_flags(con) & CON_ENABLED) && con->write) + con->write(con, buf, len); + } + console_srcu_read_unlock(cookie); + console_unlock(); + } + kfree(buf); +} #endif #ifdef CONFIG_SMP From patchwork Wed Jan 17 11:13:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sreenath Vijayan X-Patchwork-Id: 763583 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2121.outbound.protection.outlook.com [40.107.100.121]) (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 1EFE11D697; Wed, 17 Jan 2024 11:21:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.121 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705490489; cv=fail; b=UDq/7wkJYAdCQabe1rnsf5tGBMTc4zJQyrYXh+zeaCm/YC9bTYXUL+ql79+3lLrWHLB/wun2gQAFyhCMv58h/GpF5dIxryKBR7xHnMOB/d1X4OiIxCpfKrccMMY7p7FnhYRoKEeDvHro15eG2/UaYax2gfnHIdBF0+Vw8F/CVlA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705490489; c=relaxed/simple; bh=BCh2q5Tk2/R59h3MSewVzFJoLeEuMsWynLM8dyMpfA8=; h=ARC-Message-Signature:ARC-Authentication-Results:DKIM-Signature: Received:Received:X-MS-Exchange-Authentication-Results: Received-SPF:Received:Received:Received:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic:Content-Type: X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; b=jxws8FON25ydWeT8+YStNdeUqxXVIAkAw635cxRzsAvZpSuKV3Z+1tnuq2PSVrdQb1qp1yVwF0HQCfGDJaaGQa86247C2+iVfEoMXKhW0QAvyG5nMmFwLuutyJtr/fPobhMAdOhJ9/A08Nsdipflu8zXQdRZrEfUrRmZ51D/xpE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=sony.com; spf=pass smtp.mailfrom=Sony.onmicrosoft.com; dkim=pass (1024-bit key) header.d=Sony.onmicrosoft.com header.i=@Sony.onmicrosoft.com header.b=W742/1UG; arc=fail smtp.client-ip=40.107.100.121 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=sony.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=Sony.onmicrosoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=Sony.onmicrosoft.com header.i=@Sony.onmicrosoft.com header.b="W742/1UG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X53tbEx631u30xHyXgdcMcUg1s80YZwVEwNg/0yHIkitumL6RqGnZSUZ7Yr26h/WcmpUnV0rQsUx/hnolbTrpzOWbG1ECzWdMXvVGjKrDll0AqkBgMzaROS5cUDeZzJPSFhT3KsPnpGCQHgRt5C0p501GSoaZ2iNLVlaCDFCbl/ON69SLjOrCMoqInx5Dl2pLj13GxXpRKuoUkaZDEWwJK9RKv/yU/V7/Gv4eBt65eN8q39ulnSyfj3ibztC8IakywgSEgMCoGfR6SrG9MNKXf8qchmST2+SYplqN43gY8por/VwPXDi5zRo6EpNz7PWFP27mKa8su8aI3DxckA3sQ== 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=HLRaZ2XnB9Rpbe5Pr/xd1PmmB0yRDEZ04eKbHFb+Ibo=; b=KiDoYUbQTlaGsj0bNxchPVHqfdvgAcjX56aH1Hxk2rLXJdR7TjEwTT9w29WeFuLdVSmH6adG9taMy3DQQEgzw+06q1OgiY6LtV5Z/VHUsI5gwDZNxY4iDYmCS6yXzKIEUoR6t0+914E1/rlbRfQPCOiT0YEghMqPLW6Cqt7m5z1rDbdJqwCrr5VXQiqCIugSujYgfZ3fnc+qdtaKs2q1VideaAWPQl8AYiTWAo597ekHBJE1KgbsLPcq2zG3gwAEBT72I4wTMF+bjPwBIWMlk8dGBB9lUQJy6tcl0DFBptU7G31gvRpbK7+ESkcCvTab90TPsneBdMyEF5Mq2D8yxA== 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=mail.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=HLRaZ2XnB9Rpbe5Pr/xd1PmmB0yRDEZ04eKbHFb+Ibo=; b=W742/1UGxuSsmI88dqxEgWVa+AAHgjwyMVtXYVLI+xnn8doOBzz8BI3Zx8A3utglx1rsImabz1n7szM2P15dbcgA6m/CTqI++SOv62KZxWiNzj0MbvUWWgRLB7tVER4c1bDR6Ln0U7T4G/acVw6EXt5VsEgV+uGcHh2OM8WF0/Y= Received: from CY5PR22CA0061.namprd22.prod.outlook.com (2603:10b6:930:80::6) by SA1PR13MB4878.namprd13.prod.outlook.com (2603:10b6:806:1a2::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.23; Wed, 17 Jan 2024 11:21:23 +0000 Received: from CY4PEPF0000E9D6.namprd05.prod.outlook.com (2603:10b6:930:80:cafe::b9) by CY5PR22CA0061.outlook.office365.com (2603:10b6:930:80::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.23 via Frontend Transport; Wed, 17 Jan 2024 11:21:23 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 121.100.38.196) smtp.mailfrom=mail.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 mail.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 CY4PEPF0000E9D6.mail.protection.outlook.com (10.167.241.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.14 via Frontend Transport; Wed, 17 Jan 2024 11:21:23 +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 40HBL5YJ004733 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 17 Jan 2024 19:21:05 +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 40HBFsxD021765; Wed, 17 Jan 2024 19:15:54 +0800 Received: by mail.sony.com (Postfix, from userid 1000) id C59B920C0300; Wed, 17 Jan 2024 16:44:13 +0530 (IST) From: Sreenath Vijayan To: john.ogness@linutronix.de, corbet@lwn.net, gregkh@linuxfoundation.org, jirislaby@kernel.org, rdunlap@infradead.org, pmladek@suse.com Cc: 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 v3 2/2] tty/sysrq: Dump printk ring buffer messages via sysrq Date: Wed, 17 Jan 2024 16:43:52 +0530 Message-ID: <57daf43c5270f7532b269b9f0e90d126ca012354.1705331453.git.sreenath.vijayan@sony.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D6:EE_|SA1PR13MB4878:EE_ X-MS-Office365-Filtering-Correlation-Id: 43f05b76-3282-4d73-3a1d-08dc174e703e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /Q4fOTTI5kIXPzkJhxQMN/W+/70PFScFTjillhpY5FshjnSONS/w7Xp3BI+vOHAuh0+oXvC3yaucl07M8UywIqUsWWvssOODQ0tONzzBlovcfK7BDM2wjbohMNJ8TBwxgdeJtes/z75qMaJS6HoE3wNkMTUp/x0btUmGb++nv5FKCQwnv6DRUoOyP9vBBkJM0AlyrqrGMbK2l69zLEHexk1ldTPA9B4kDDB2erSXqL75c01hh90rHU214kBT0AJXOTSRbLCiwBaF6VPv43UzlV2TPtSs8qng9mb4beJlHsdtw2GG9dpUmSvXH3VwYWo/aX8DVT9pqeBiVrHNC+LY5y025E7DGVIHGOdogin9i0Gkuyo5Fcl0ZokFsg8ST1WvmQRUgZt8wkf6bGQ66CA6Crysgj1OiT4O5u9XA+9CPQBoxdSaMkd2ADQJElawmPNhEq9oytte7jM5xUa9/eO5swo+Lo4Vr0FZ+LF/ew/tJlBnJr8pDkBrond1r7TVeye1eHrIH0q9K/xFwRIyrwWECtzDy2yUNIjaRE8Wa5CfK3e4sD+OrZN+LjHdY++LaI8n3Bedz+SXWXhdm6mV1aIxVmafI7n44gERZOMhggnkT+KeBLvzzU7P0VVvzL8a+dVsBOuJOGP4FoYkfKLMOsunsek4/kHBPmSROLC7hkVjinp7nNCmHCfcVIUrDOoWb6Dv+BBLCpRwzvuf9oB9qwiR1mtzc4T9tohiu2Iw6mRs6fYTqChOFqAglDrq3UB8ZNqU 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)(4636009)(346002)(136003)(376002)(396003)(39860400002)(230922051799003)(451199024)(1800799012)(64100799003)(82310400011)(40470700004)(46966006)(336012)(426003)(6266002)(26005)(83380400001)(107886003)(6666004)(2616005)(47076005)(35950700001)(5660300002)(44832011)(4326008)(8676002)(15650500001)(41300700001)(2906002)(8936002)(498600001)(316002)(450100002)(42186006)(70206006)(70586007)(36756003)(83170400001)(82740400003)(81166007)(356005)(82960400001)(40480700001)(40460700003); DIR:OUT; SFP:1102; X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2024 11:21:23.0594 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 43f05b76-3282-4d73-3a1d-08dc174e703e 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-AuthSource: CY4PEPF0000E9D6.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR13MB4878 When terminal is unresponsive, one cannot use dmesg to view printk ring buffer messages. Also, syslog services may be disabled, to check the messages after a reboot, especially on embedded systems. In this scenario, dump the printk ring buffer messages via sysrq by pressing sysrq+D. Signed-off-by: Sreenath Vijayan Signed-off-by: Shimoyashiki Taichi --- Documentation/admin-guide/sysrq.rst | 2 ++ drivers/tty/sysrq.c | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/sysrq.rst b/Documentation/admin-guide/sysrq.rst index 51906e47327b..246a7b61a0eb 100644 --- a/Documentation/admin-guide/sysrq.rst +++ b/Documentation/admin-guide/sysrq.rst @@ -152,6 +152,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.) + +``D`` Dump the printk ring buffer =========== =================================================================== Okay, so what can I use them for? diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 6b4a28bcf2f5..1976412706a4 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -450,6 +450,24 @@ static const struct sysrq_key_op sysrq_unrt_op = { .enable_mask = SYSRQ_ENABLE_RTNICE, }; +static void dmesg_dump_callback(struct work_struct *work) +{ + dump_printk_buffer(); +} + +static DECLARE_WORK(sysrq_dmesg_work, dmesg_dump_callback); + +static void sysrq_handle_dmesg_dump(u8 key) +{ + queue_work(system_unbound_wq, &sysrq_dmesg_work); +} +static struct sysrq_key_op sysrq_dmesg_dump_op = { + .handler = sysrq_handle_dmesg_dump, + .help_msg = "dump-dmesg(D)", + .action_msg = "Dump dmesg", + .enable_mask = SYSRQ_ENABLE_DUMP, +}; + /* Key Operations table and lock */ static DEFINE_SPINLOCK(sysrq_key_table_lock); @@ -505,7 +523,7 @@ static const struct sysrq_key_op *sysrq_key_table[62] = { NULL, /* A */ NULL, /* B */ NULL, /* C */ - NULL, /* D */ + &sysrq_dmesg_dump_op, /* D */ NULL, /* E */ NULL, /* F */ NULL, /* G */