]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
printk: Add a short description string to kmsg_dump()
authorJocelyn Falempe <jfalempe@redhat.com>
Tue, 2 Jul 2024 12:26:04 +0000 (14:26 +0200)
committerJocelyn Falempe <jfalempe@redhat.com>
Wed, 17 Jul 2024 10:35:24 +0000 (12:35 +0200)
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 <jfalempe@redhat.com>
Acked-by: Petr Mladek <pmladek@suse.com>
Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Acked-by: Kees Cook <kees@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240702122639.248110-1-jfalempe@redhat.com
arch/powerpc/kernel/nvram_64.c
arch/powerpc/platforms/powernv/opal-kmsg.c
arch/um/kernel/kmsg_dump.c
drivers/gpu/drm/drm_panic.c
drivers/hv/hv_common.c
drivers/mtd/mtdoops.c
fs/pstore/platform.c
include/linux/kmsg_dump.h
kernel/panic.c
kernel/printk/printk.c

index e385d3164648ce84461b09069a53845c903eb520..f9c6568a91370eb6875680f9054fd4da7442a09d 100644 (file)
@@ -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;
        }
 
index 6c3bc4b4da9834966f7fd19eb28454ac33988b9e..bb4218fa796e5e574a0592b728776a74b5600f36 100644 (file)
  * 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);
index 4382cf02a6d14d3aa7520e65fadacc0d109997ab..4190211752726593dd2847f66efd9d3a61cea982 100644 (file)
@@ -8,7 +8,7 @@
 #include <os.h>
 
 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);
index 948aed00595eb6dd9828a5823e7f7baa42ba9871..8794c7f6c0eef0230a96909d51dbb56ed702beb1 100644 (file)
@@ -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);
 }
 
index 9c452bfbd5719d78bda1b3c47d0e41676b1deef6..7a35c82976e0ff8cad6ab37d1a18b2c21c78c28b 100644 (file)
@@ -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;
 
        /*
index 2f11585b5613eeb24c0a15bbbc7e4caea3ca22e5..86d49db9196d8f16d54eb675b72f827f1a9c267a 100644 (file)
@@ -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);
index 03425928d2fb3cbba146fc775280427e5bf2abec..7f5810589a26aa9d758fdfaf32ec1a3ab1d68a20 100644 (file)
@@ -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 {
index 906521c2329caaeb8044ef6b6858a3527b4547c2..6055fc9698776eee9396b93aab5e5f7cecdf4b4a 100644 (file)
@@ -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 */
index 8bff183d6180e752a0a7ba0ea9ed1617322fb02a..d6219841f491d595210e51aedc8dec82729c182c 100644 (file)
@@ -375,7 +375,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,
index 420fd310129d4b2a05612c57c7c8b4b9605bee99..4310ff3f23e54a586cf4a28759714761ec7bc5d6 100644 (file)
@@ -4126,16 +4126,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) {
@@ -4153,7 +4158,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();
 }