From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63912C2BD09 for ; Fri, 12 Jul 2024 09:59:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:To:Subject:MIME-Version: Date:Message-ID:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gBn5QUr1tggj4gcQYlA7ijuh9zWUBoKGbgJlSwCMea4=; b=ofVFSyPk40q31O3wjiftP87j1R nCUBW4QQ5eVVyvTytXIj9ViviuWsH+mjtTl7PcjOooPuLQnRvwpqWQcsNZdOH9sCUFMsDry1gzyeY 2DfQNIWqsUWLe5hCRU/000RQLorABU23L2GQ2+UO5LvYYb9rvPFfZ3HUnDgN6FgkxrfOnxYZuqQQI VLxakDiQlsUGL2YDkRZtGC7Q60DDMd5EFSLRasgbFdrA6asnYuyed2qdVWpmD4masXGPMoOrQWHds UkNMSTlmxJNY/ZvMHc1ucaYuQZQzr8V3Kgox6NXzrgpd64Ja8i3UWNh73c7GTeAgrxEmh/ouFggMz ySGGMZlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sSD44-0000000HDLg-0Hyu; Fri, 12 Jul 2024 09:59:44 +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 1sSD40-0000000HDKf-2DCB for linux-mtd@lists.infradead.org; Fri, 12 Jul 2024 09:59:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720778376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yNK2WNYT4hz6xvV+XWZB4439w5KRVL9zrlSdvQd6Wt8=; b=C2b6stVMh0sFX/L8o3ET/YM9pT5qXTqCNGrleOgFXPx8sR/3mE4jaqKa0BrxX0YC4C1kOB apaUEvjLGVkSiUiW80ldnmhGLD08baZBj9wAIb8HlvR8ksC0T6lZpsYKRc0iaWkRGOrRBj MUusPfbpzQ/bvy5T8iNHkQDUT3aUMYk= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-226-1cSAPNRZP0O97jc0zYM7yQ-1; Fri, 12 Jul 2024 05:59:34 -0400 X-MC-Unique: 1cSAPNRZP0O97jc0zYM7yQ-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-36787ba7ad4so1319017f8f.3 for ; Fri, 12 Jul 2024 02:59:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720778373; x=1721383173; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yNK2WNYT4hz6xvV+XWZB4439w5KRVL9zrlSdvQd6Wt8=; b=LVEhv8bXSKj9L5iPa5lZg3YQVUynMFtGZ7ghPeFr6kklg9amjHewdonarDNyWOpDEs Tx6NhegTHh43FuNVZAWFpzMEz9qDtLPE+Rd59Ws5aXse0cYOPs+vLePOoM/JvMzfnd4V ubVirDlqawkyal4Q5MnLjnnRFhY25b8N/RaKbp13uJPEHO1hn71WU0YWIGX2BaGoKt2Q bS3O0c6hELnIZMcp9jjgmr1lHV8bM6EM6RVwiUMqZiilPKvq6sX3kud/awN7VZAZOHRk lRkLcnNv8MuvuannLfl8XLk1rNccl8xeMDX6uOPWswd3wtzHjnyC+5oAiCAW5N346h65 JSTQ== X-Forwarded-Encrypted: i=1; AJvYcCVUGaPO8AA88UN+mjCIqi0kpypbu0ENvsfRWiCGCQlC+E3SR5DCEHgAxprGU3xCM0HHZCdjmXiwx8DXGgy8V7IftNkK7dvkz0AAqGgs4A== X-Gm-Message-State: AOJu0YwxCHesdf28mxJZHN6+/3qjDnKzPhpZAG25772QbEFNXEcM8rvQ mjjDya/+/jOPQqsNxcswdzBXNWB4EnaWfDWOsNKVJ062UqBgdkQxEqi6mh0A0nBcoJEkyslb1Ve 8P8U45uXSwIql79fagUpXtHM6oS2Ves6jlzCCMWdPvJWKNZozePO2lo10wrn5L3M= X-Received: by 2002:a5d:4c46:0:b0:367:437f:177f with SMTP id ffacd0b85a97d-367cead1d0fmr6978776f8f.55.1720778373321; Fri, 12 Jul 2024 02:59:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7RTJBpoqr/TIMIUkrbE+vKpQ5fn0lcejVvLygeHOHW187lQxQdEmkBo0UptM3swvND74cmQ== X-Received: by 2002:a5d:4c46:0:b0:367:437f:177f with SMTP id ffacd0b85a97d-367cead1d0fmr6978747f8f.55.1720778372819; Fri, 12 Jul 2024 02:59:32 -0700 (PDT) Received: from ?IPV6:2a01:e0a:c:37e0:ced3:55bd:f454:e722? ([2a01:e0a:c:37e0:ced3:55bd:f454:e722]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cde7e187sm9900714f8f.21.2024.07.12.02.59.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 02:59:32 -0700 (PDT) Message-ID: <2d886ba5-950b-4dff-81ea-8748d7d67c55@redhat.com> Date: Fri, 12 Jul 2024 11:59:30 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] printk: Add a short description string to kmsg_dump() 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 , 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 References: <20240702122639.248110-1-jfalempe@redhat.com> From: Jocelyn Falempe In-Reply-To: <20240702122639.248110-1-jfalempe@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US, fr X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240712_025940_754242_2DE46537 X-CRM114-Status: GOOD ( 36.46 ) 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: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org On 02/07/2024 14:26, Jocelyn Falempe wrote: > kmsg_dump doesn't forward the panic reason string to the kmsg_dumper > callback. > This patch adds a new struct kmsg_dump_detail, that will hold the > reason and description, and pass it to the dump() callback. > > 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. > > v2: > * Use a struct kmsg_dump_detail to hold the reason and description > pointer, for more flexibility if we want to add other parameters. > (Kees Cook) > * Fix powerpc/nvram_64 build, as I didn't update the forward > declaration of oops_to_nvram() > > Signed-off-by: Jocelyn Falempe > --- > arch/powerpc/kernel/nvram_64.c | 8 ++++---- > arch/powerpc/platforms/powernv/opal-kmsg.c | 4 ++-- > arch/um/kernel/kmsg_dump.c | 2 +- > drivers/gpu/drm/drm_panic.c | 4 ++-- > drivers/hv/hv_common.c | 4 ++-- > drivers/mtd/mtdoops.c | 2 +- > fs/pstore/platform.c | 10 +++++----- > include/linux/kmsg_dump.h | 22 +++++++++++++++++++--- > kernel/panic.c | 2 +- > kernel/printk/printk.c | 11 ++++++++--- > 10 files changed, 45 insertions(+), 24 deletions(-) > > diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c > index e385d3164648..f9c6568a9137 100644 > --- a/arch/powerpc/kernel/nvram_64.c > +++ b/arch/powerpc/kernel/nvram_64.c > @@ -73,7 +73,7 @@ static const char *nvram_os_partitions[] = { > }; > > static void oops_to_nvram(struct kmsg_dumper *dumper, > - enum kmsg_dump_reason reason); > + struct kmsg_dump_detail *detail); > > static struct kmsg_dumper nvram_kmsg_dumper = { > .dump = oops_to_nvram > @@ -643,7 +643,7 @@ 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) > + struct kmsg_dump_detail *detail) > { > struct oops_log_info *oops_hdr = (struct oops_log_info *)oops_buf; > static unsigned int oops_count = 0; > @@ -655,7 +655,7 @@ static void oops_to_nvram(struct kmsg_dumper *dumper, > unsigned int err_type = ERR_TYPE_KERNEL_PANIC_GZ; > int rc = -1; > > - switch (reason) { > + switch (detail->reason) { > case KMSG_DUMP_SHUTDOWN: > /* These are almost always orderly shutdowns. */ > return; > @@ -671,7 +671,7 @@ static void oops_to_nvram(struct kmsg_dumper *dumper, > break; > default: > pr_err("%s: ignoring unrecognized KMSG_DUMP_* reason %d\n", > - __func__, (int) reason); > + __func__, (int) detail->reason); > return; > } > > diff --git a/arch/powerpc/platforms/powernv/opal-kmsg.c b/arch/powerpc/platforms/powernv/opal-kmsg.c > index 6c3bc4b4da98..bb4218fa796e 100644 > --- a/arch/powerpc/platforms/powernv/opal-kmsg.c > +++ b/arch/powerpc/platforms/powernv/opal-kmsg.c > @@ -20,13 +20,13 @@ > * 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) > + struct kmsg_dump_detail *detail) > { > /* > * Outside of a panic context the pollers will continue to run, > * so we don't need to do any special flushing. > */ > - if (reason != KMSG_DUMP_PANIC) > + if (detail->reason != KMSG_DUMP_PANIC) > return; > > opal_flush_console(0); > diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c > index 4382cf02a6d1..419021175272 100644 > --- a/arch/um/kernel/kmsg_dump.c > +++ b/arch/um/kernel/kmsg_dump.c > @@ -8,7 +8,7 @@ > #include > > static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, > - enum kmsg_dump_reason reason) > + struct kmsg_dump_detail *detail) > { > static struct kmsg_dump_iter iter; > static DEFINE_SPINLOCK(lock); > diff --git a/drivers/gpu/drm/drm_panic.c b/drivers/gpu/drm/drm_panic.c > index 948aed00595e..8794c7f6c0ee 100644 > --- a/drivers/gpu/drm/drm_panic.c > +++ b/drivers/gpu/drm/drm_panic.c > @@ -655,11 +655,11 @@ 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, struct kmsg_dump_detail *detail) > { > struct drm_plane *plane = to_drm_plane(dumper); > > - if (reason == KMSG_DUMP_PANIC) > + if (detail->reason == KMSG_DUMP_PANIC) > draw_panic_plane(plane); > } > > diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c > index 9c452bfbd571..7a35c82976e0 100644 > --- a/drivers/hv/hv_common.c > +++ b/drivers/hv/hv_common.c > @@ -207,13 +207,13 @@ 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) > + struct kmsg_dump_detail *detail) > { > struct kmsg_dump_iter iter; > size_t bytes_written; > > /* We are only interested in panics. */ > - if (reason != KMSG_DUMP_PANIC || !sysctl_record_panic_msg) > + if (detail->reason != KMSG_DUMP_PANIC || !sysctl_record_panic_msg) > return; > > /* > diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c > index 2f11585b5613..86d49db9196d 100644 > --- a/drivers/mtd/mtdoops.c > +++ b/drivers/mtd/mtdoops.c > @@ -298,7 +298,7 @@ static void find_next_position(struct mtdoops_context *cxt) > } > > static void mtdoops_do_dump(struct kmsg_dumper *dumper, > - enum kmsg_dump_reason reason) > + struct kmsg_dump_detail *detail) > { > struct mtdoops_context *cxt = container_of(dumper, > struct mtdoops_context, dump); > diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c > index 3497ede88aa0..9c6b7c97fa3c 100644 > --- a/fs/pstore/platform.c > +++ b/fs/pstore/platform.c > @@ -275,7 +275,7 @@ 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) > + struct kmsg_dump_detail *detail) > { > struct kmsg_dump_iter iter; > unsigned long total = 0; > @@ -285,9 +285,9 @@ static void pstore_dump(struct kmsg_dumper *dumper, > int saved_ret = 0; > int ret; > > - why = kmsg_dump_reason_str(reason); > + why = kmsg_dump_reason_str(detail->reason); > > - if (pstore_cannot_block_path(reason)) { > + if (pstore_cannot_block_path(detail->reason)) { > if (!spin_trylock_irqsave(&psinfo->buf_lock, flags)) { > pr_err("dump skipped in %s path because of concurrent dump\n", > in_nmi() ? "NMI" : why); > @@ -311,7 +311,7 @@ static void pstore_dump(struct kmsg_dumper *dumper, > pstore_record_init(&record, psinfo); > record.type = PSTORE_TYPE_DMESG; > record.count = oopscount; > - record.reason = reason; > + record.reason = detail->reason; > record.part = part; > record.buf = psinfo->buf; > > @@ -352,7 +352,7 @@ static void pstore_dump(struct kmsg_dumper *dumper, > } > > ret = psinfo->write(&record); > - if (ret == 0 && reason == KMSG_DUMP_OOPS) { > + if (ret == 0 && detail->reason == KMSG_DUMP_OOPS) { > pstore_new_entry = 1; > pstore_timer_kick(); > } else { > diff --git a/include/linux/kmsg_dump.h b/include/linux/kmsg_dump.h > index 906521c2329c..65f5a47727bc 100644 > --- a/include/linux/kmsg_dump.h > +++ b/include/linux/kmsg_dump.h > @@ -39,6 +39,17 @@ struct kmsg_dump_iter { > u64 next_seq; > }; > > +/** > + *struct kmsg_dump_detail - kernel crash detail > + * @reason: reason for the crash, see kmsg_dump_reason. > + * @description: optional short string, to provide additional information. > + */ > + > +struct kmsg_dump_detail { > + enum kmsg_dump_reason reason; > + const char *description; > +}; > + > /** > * struct kmsg_dumper - kernel crash message dumper structure > * @list: Entry in the dumper list (private) > @@ -49,13 +60,13 @@ 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, struct kmsg_dump_detail *detail); > 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 +82,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 +118,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 0843a275531a..0a8b29c44f3c 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 5dcc05e1aa56..19bc414be5f0 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -4272,16 +4272,21 @@ 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; > + struct kmsg_dump_detail detail = { > + .reason = reason, > + .description = desc}; > > rcu_read_lock(); > list_for_each_entry_rcu(dumper, &dump_list, list) { > @@ -4299,7 +4304,7 @@ void kmsg_dump(enum kmsg_dump_reason reason) > continue; > > /* invoke dumper which will iterate over records */ > - dumper->dump(dumper, reason); > + dumper->dump(dumper, &detail); > } > rcu_read_unlock(); > } > > base-commit: 82e4255305c554b0bb18b7ccf2db86041b4c8b6e Gentle ping, I need reviews from powerpc, usermod linux, mtd, pstore and hyperv, to be able to push it in the drm-misc tree. Best regards, -- Jocelyn ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/