Skip to content

Commit 04a4184

Browse files
thomasmeyrichardweinberger
authored andcommitted
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>
1 parent fc9bea0 commit 04a4184

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎arch/um/kernel/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ clean-files :=
1313
obj-y = config.o exec.o exitcode.o irq.o ksyms.o mem.o \
1414
physmem.o process.o ptrace.o reboot.o sigio.o \
1515
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/
1717

1818
obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o
1919
obj-$(CONFIG_GPROF) += gprof_syms.o

‎arch/um/kernel/kmsg_dump.c‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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);

‎arch/um/kernel/um_arch.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/string.h>
1212
#include <linux/utsname.h>
1313
#include <linux/sched.h>
14+
#include <linux/kmsg_dump.h>
1415
#include <asm/pgtable.h>
1516
#include <asm/processor.h>
1617
#include <asm/sections.h>
@@ -211,6 +212,7 @@ static void __init uml_postsetup(void)
211212
static int panic_exit(struct notifier_block *self, unsigned long unused1,
212213
void *unused2)
213214
{
215+
kmsg_dump(KMSG_DUMP_PANIC);
214216
bust_spinlocks(1);
215217
bust_spinlocks(0);
216218
uml_exitcode = 1;

0 commit comments

Comments
 (0)