From patchwork Tue Jun 25 12:39:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jocelyn Falempe X-Patchwork-Id: 1952107 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=v5l6mVkJ; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bcz2ZO74; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W7kxg0v3mz20Z9 for ; Tue, 25 Jun 2024 22:42:28 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=o8f3z+tJOc1bCVguOYzycWHkLLga2N8u43hTQLGITQc=; b=v5l6mVkJylSVtN RDJEQTQKQehWiIRANn31D0uPiROWSE0T2X6wLpZK3q8rcAjyMfC3SYyntlbmbMV285FCilFKL7hrB M/hOsihEkrJt9HQaxXOTTeGa3tedhl5swzHDN/9n+4NO4xIgPWxjSkpd2zwoOnwHIl+DA1uvgRiUL Yjgr3m0vxe7x2aPmJkV5R1UyrMZ4mfu12OHANJSewTyrkdI2yVpJ4X+MRoJtrwU1OV+DG9eVFBno9 1u0YcWH8Azdhnbi6P0E/S4Di95PzAzw1xYoTgllLy686ZqZCUeDPu4U661tGygi3us9rRTt4dBSeA dlao3U33LqXUa5nD7GTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Ur-00000002plW-1GAD; Tue, 25 Jun 2024 12:42:05 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Up-00000002pjn-0b72 for linux-mtd@lists.infradead.org; Tue, 25 Jun 2024 12:42:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719319321; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=7EWz1vItROBUOYp6sdJspiDZ8uU1laai0jDHb5Vv+x0=; b=bcz2ZO74XTpPmuwteaSHPlbXpyKcmerHBKjWMd0xiSHOnbRnzGNBJoigvscKbkIsDfxpMM ywCzTf5cUkS2RkGcFUYpjcB/IVB+ttJHJc8rCfVdUokegq0SmNjUndT5Tmbn5kHCd8kVKu Kqc5wxbimUV7R/1nD3IiwW0xJr8pRsg= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-460-RCkWgWX_Nm-SSEzUrXPwMA-1; Tue, 25 Jun 2024 08:40:23 -0400 X-MC-Unique: RCkWgWX_Nm-SSEzUrXPwMA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9D4051956096; Tue, 25 Jun 2024 12:40:17 +0000 (UTC) Received: from hydra.redhat.com (unknown [10.39.192.194]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DCA1319560B2; Tue, 25 Jun 2024 12:40:06 +0000 (UTC) From: Jocelyn Falempe To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Naveen N. Rao" , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Kees Cook , Tony Luck , "Guilherme G. Piccoli" , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Jocelyn Falempe , Andrew Morton , Jani Nikula , Greg Kroah-Hartman , Kefeng Wang , Thomas Gleixner , Uros Bizjak , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-hyperv@vger.kernel.org, linux-mtd@lists.infradead.org, linux-hardening@vger.kernel.org Subject: [PATCH] printk: Add a short description string to kmsg_dump() Date: Tue, 25 Jun 2024 14:39:29 +0200 Message-ID: <20240625123954.211184-1-jfalempe@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_054203_411174_26F222FD X-CRM114-Status: GOOD ( 21.49 ) X-Spam-Score: 3.2 (+++) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: kmsg_dump doesn't forward the panic reason string to the kmsg_dumper callback. This patch adds a new parameter "const char *desc" to the kmsg_dumper dump() callback, and update all drivers that are us [...] Content analysis details: (3.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [170.10.133.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 3.6 RCVD_IN_SBL_CSS RBL: Received via a relay in Spamhaus SBL-CSS [54.186.198.63 listed in zen.spamhaus.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [170.10.133.124 listed in wl.mailspike.net] 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders -0.2 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org kmsg_dump doesn't forward the panic reason string to the kmsg_dumper callback. This patch adds a new parameter "const char *desc" to the kmsg_dumper dump() callback, and update all drivers that are using it. To avoid updating all kmsg_dump() call, it adds a kmsg_dump_desc() function and a macro for backward compatibility. I've written this for drm_panic, but it can be useful for other kmsg_dumper. It allows to see the panic reason, like "sysrq triggered crash" or "VFS: Unable to mount root fs on xxxx" on the drm panic screen. Signed-off-by: Jocelyn Falempe --- arch/powerpc/kernel/nvram_64.c | 3 ++- arch/powerpc/platforms/powernv/opal-kmsg.c | 3 ++- drivers/gpu/drm/drm_panic.c | 3 ++- drivers/hv/hv_common.c | 3 ++- drivers/mtd/mtdoops.c | 3 ++- fs/pstore/platform.c | 3 ++- include/linux/kmsg_dump.h | 13 ++++++++++--- kernel/panic.c | 2 +- kernel/printk/printk.c | 8 +++++--- 9 files changed, 28 insertions(+), 13 deletions(-) base-commit: f76698bd9a8ca01d3581236082d786e9a6b72bb7 diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c index e385d3164648c..6b3a80d8cfa64 100644 --- a/arch/powerpc/kernel/nvram_64.c +++ b/arch/powerpc/kernel/nvram_64.c @@ -643,7 +643,8 @@ void __init nvram_init_oops_partition(int rtas_partition_exists) * partition. If that's too much, go back and capture uncompressed text. */ static void oops_to_nvram(struct kmsg_dumper *dumper, - enum kmsg_dump_reason reason) + enum kmsg_dump_reason reason, + const char *desc) { struct oops_log_info *oops_hdr = (struct oops_log_info *)oops_buf; static unsigned int oops_count = 0; diff --git a/arch/powerpc/platforms/powernv/opal-kmsg.c b/arch/powerpc/platforms/powernv/opal-kmsg.c index 6c3bc4b4da983..49b60de6feb04 100644 --- a/arch/powerpc/platforms/powernv/opal-kmsg.c +++ b/arch/powerpc/platforms/powernv/opal-kmsg.c @@ -20,7 +20,8 @@ * message, it just ensures that OPAL completely flushes the console buffer. */ static void kmsg_dump_opal_console_flush(struct kmsg_dumper *dumper, - enum kmsg_dump_reason reason) + enum kmsg_dump_reason reason, + const char *desc) { /* * Outside of a panic context the pollers will continue to run, diff --git a/drivers/gpu/drm/drm_panic.c b/drivers/gpu/drm/drm_panic.c index 293d4dcbc80da..88e9359fe6d78 100644 --- a/drivers/gpu/drm/drm_panic.c +++ b/drivers/gpu/drm/drm_panic.c @@ -604,7 +604,8 @@ static struct drm_plane *to_drm_plane(struct kmsg_dumper *kd) return container_of(kd, struct drm_plane, kmsg_panic); } -static void drm_panic(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason) +static void drm_panic(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason, + const char *desc) { struct drm_plane *plane = to_drm_plane(dumper); diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index 9c452bfbd5719..b0786ee9c94e3 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -207,7 +207,8 @@ static int hv_die_panic_notify_crash(struct notifier_block *self, * buffer and call into Hyper-V to transfer the data. */ static void hv_kmsg_dump(struct kmsg_dumper *dumper, - enum kmsg_dump_reason reason) + enum kmsg_dump_reason reason, + const char *desc) { struct kmsg_dump_iter iter; size_t bytes_written; diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 2f11585b5613e..c618999a96832 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -298,7 +298,8 @@ static void find_next_position(struct mtdoops_context *cxt) } static void mtdoops_do_dump(struct kmsg_dumper *dumper, - enum kmsg_dump_reason reason) + enum kmsg_dump_reason reason, + const char *desc) { struct mtdoops_context *cxt = container_of(dumper, struct mtdoops_context, dump); diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 3497ede88aa01..a6ed5d56021ef 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -275,7 +275,8 @@ void pstore_record_init(struct pstore_record *record, * end of the buffer. */ static void pstore_dump(struct kmsg_dumper *dumper, - enum kmsg_dump_reason reason) + enum kmsg_dump_reason reason, + const char *desc) { struct kmsg_dump_iter iter; unsigned long total = 0; diff --git a/include/linux/kmsg_dump.h b/include/linux/kmsg_dump.h index 906521c2329ca..a8f8a6204542d 100644 --- a/include/linux/kmsg_dump.h +++ b/include/linux/kmsg_dump.h @@ -49,13 +49,15 @@ struct kmsg_dump_iter { */ struct kmsg_dumper { struct list_head list; - void (*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason); + void (*dump)(struct kmsg_dumper *dumper, + enum kmsg_dump_reason reason, + const char *desc); enum kmsg_dump_reason max_reason; bool registered; }; #ifdef CONFIG_PRINTK -void kmsg_dump(enum kmsg_dump_reason reason); +void kmsg_dump_desc(enum kmsg_dump_reason reason, const char *desc); bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog, char *line, size_t size, size_t *len); @@ -71,7 +73,7 @@ int kmsg_dump_unregister(struct kmsg_dumper *dumper); const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason); #else -static inline void kmsg_dump(enum kmsg_dump_reason reason) +static inline void kmsg_dump_desc(enum kmsg_dump_reason reason, const char *desc) { } @@ -107,4 +109,9 @@ static inline const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason) } #endif +static inline void kmsg_dump(enum kmsg_dump_reason reason) +{ + kmsg_dump_desc(reason, NULL); +} + #endif /* _LINUX_KMSG_DUMP_H */ diff --git a/kernel/panic.c b/kernel/panic.c index 0843a275531a7..0a8b29c44f3c1 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -378,7 +378,7 @@ void panic(const char *fmt, ...) panic_print_sys_info(false); - kmsg_dump(KMSG_DUMP_PANIC); + kmsg_dump_desc(KMSG_DUMP_PANIC, buf); /* * If you doubt kdump always works fine in any situation, diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index d0bff0b0abfdb..2e7195894e41a 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4287,14 +4287,16 @@ const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason) EXPORT_SYMBOL_GPL(kmsg_dump_reason_str); /** - * kmsg_dump - dump kernel log to kernel message dumpers. + * kmsg_dump_desc - dump kernel log to kernel message dumpers. * @reason: the reason (oops, panic etc) for dumping + * @desc: a short string to describe what caused the panic or oops. Can be NULL + * if no additional description is available. * * Call each of the registered dumper's dump() callback, which can * retrieve the kmsg records with kmsg_dump_get_line() or * kmsg_dump_get_buffer(). */ -void kmsg_dump(enum kmsg_dump_reason reason) +void kmsg_dump_desc(enum kmsg_dump_reason reason, const char *desc) { struct kmsg_dumper *dumper; @@ -4314,7 +4316,7 @@ void kmsg_dump(enum kmsg_dump_reason reason) continue; /* invoke dumper which will iterate over records */ - dumper->dump(dumper, reason); + dumper->dump(dumper, reason, desc); } rcu_read_unlock(); }