Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

um: add a kmsg_dumper

Add a kmsg_dumper, that dumps the kmsg buffer to stdout, when no console
is available. This an enables the printing of early panic() calls
triggered in uml_postsetup().
When a panic() call happens so early in the UML kernel no
earlyprintk/console is available yet, but with a kmsg_dumper in place
the kernel message buffer will be outputted to the user, to give a
better hint, of what the failure was.

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
Signed-off-by: Richard Weinberger <richard@nod.at>

authored by

Thomas Meyer and committed by
Richard Weinberger
04a41849 fc9bea0e

+46 -1
+1 -1
arch/um/kernel/Makefile
··· 13 13 obj-y = config.o exec.o exitcode.o irq.o ksyms.o mem.o \ 14 14 physmem.o process.o ptrace.o reboot.o sigio.o \ 15 15 signal.o syscall.o sysrq.o time.o tlb.o trap.o \ 16 - um_arch.o umid.o maccess.o skas/ 16 + um_arch.o umid.o maccess.o kmsg_dump.o skas/ 17 17 18 18 obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o 19 19 obj-$(CONFIG_GPROF) += gprof_syms.o
+43
arch/um/kernel/kmsg_dump.c
··· 1 + #include <linux/kmsg_dump.h> 2 + #include <linux/console.h> 3 + #include <shared/init.h> 4 + #include <shared/kern.h> 5 + #include <os.h> 6 + 7 + static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, 8 + enum kmsg_dump_reason reason) 9 + { 10 + static char line[1024]; 11 + 12 + size_t len = 0; 13 + bool con_available = false; 14 + 15 + /* only dump kmsg when no console is available */ 16 + if (!console_trylock()) 17 + return; 18 + 19 + if (console_drivers != NULL) 20 + con_available = true; 21 + 22 + console_unlock(); 23 + 24 + if (con_available == true) 25 + return; 26 + 27 + printf("kmsg_dump:\n"); 28 + while (kmsg_dump_get_line(dumper, true, line, sizeof(line), &len)) { 29 + line[len] = '\0'; 30 + printf("%s", line); 31 + } 32 + } 33 + 34 + static struct kmsg_dumper kmsg_dumper = { 35 + .dump = kmsg_dumper_stdout 36 + }; 37 + 38 + int __init kmsg_dumper_stdout_init(void) 39 + { 40 + return kmsg_dump_register(&kmsg_dumper); 41 + } 42 + 43 + __uml_postsetup(kmsg_dumper_stdout_init);
+2
arch/um/kernel/um_arch.c
··· 11 11 #include <linux/string.h> 12 12 #include <linux/utsname.h> 13 13 #include <linux/sched.h> 14 + #include <linux/kmsg_dump.h> 14 15 #include <asm/pgtable.h> 15 16 #include <asm/processor.h> 16 17 #include <asm/sections.h> ··· 212 211 static int panic_exit(struct notifier_block *self, unsigned long unused1, 213 212 void *unused2) 214 213 { 214 + kmsg_dump(KMSG_DUMP_PANIC); 215 215 bust_spinlocks(1); 216 216 bust_spinlocks(0); 217 217 uml_exitcode = 1;