Skip to content

Commit 54a519e

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
riscv: Dump out kernel offset information on panic
Dump out the KASLR virtual kernel offset when panic to help debug kernel. Signed-off-by: Zong Li <zong.li@sifive.com> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Tested-by: Conor Dooley <conor.dooley@microchip.com> Tested-by: Song Shuai <songshuaishuai@tinylab.org> Reviewed-by: Sami Tolvanen <samitolvanen@google.com> Tested-by: Sami Tolvanen <samitolvanen@google.com> Link: https://lore.kernel.org/r/20230722123850.634544-3-alexghiti@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 84fe419 commit 54a519e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

arch/riscv/kernel/setup.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/smp.h>
2222
#include <linux/efi.h>
2323
#include <linux/crash_dump.h>
24+
#include <linux/panic_notifier.h>
2425

2526
#include <asm/acpi.h>
2627
#include <asm/alternative.h>
@@ -341,3 +342,27 @@ void free_initmem(void)
341342

342343
free_initmem_default(POISON_FREE_INITMEM);
343344
}
345+
346+
static int dump_kernel_offset(struct notifier_block *self,
347+
unsigned long v, void *p)
348+
{
349+
pr_emerg("Kernel Offset: 0x%lx from 0x%lx\n",
350+
kernel_map.virt_offset,
351+
KERNEL_LINK_ADDR);
352+
353+
return 0;
354+
}
355+
356+
static struct notifier_block kernel_offset_notifier = {
357+
.notifier_call = dump_kernel_offset
358+
};
359+
360+
static int __init register_kernel_offset_dumper(void)
361+
{
362+
if (IS_ENABLED(CONFIG_RANDOMIZE_BASE))
363+
atomic_notifier_chain_register(&panic_notifier_list,
364+
&kernel_offset_notifier);
365+
366+
return 0;
367+
}
368+
device_initcall(register_kernel_offset_dumper);

0 commit comments

Comments
 (0)