Commit e1a261ba authored by Jocelyn Falempe's avatar Jocelyn Falempe
Browse files

printk: Add a short description string to kmsg_dump()



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: default avatarJocelyn Falempe <jfalempe@redhat.com>
Acked-by: default avatarPetr Mladek <pmladek@suse.com>
Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Acked-by: default avatarKees Cook <kees@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240702122639.248110-1-jfalempe@redhat.com
parent a237f217
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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;
	}

+2 −2
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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);
+2 −2
Original line number Diff line number Diff line
@@ -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);
}

+2 −2
Original line number Diff line number Diff line
@@ -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;

	/*
Loading