diff mbox series

[v6,2/5] riscv: Dump out kernel offset information on panic

Message ID 20230722123850.634544-3-alexghiti@rivosinc.com (mailing list archive)
State Changes Requested, archived
Headers show
Series riscv: Introduce KASLR | expand

Checks

Context Check Description
conchuod/cover_letter success Series has a cover letter
conchuod/tree_selection success Guessed tree name to be for-next at HEAD 471aba2e4760
conchuod/fixes_present success Fixes tag not required for -next series
conchuod/maintainers_pattern success MAINTAINERS pattern errors before the patch: 4 and now 4
conchuod/verify_signedoff success Signed-off-by tag matches author and committer
conchuod/kdoc success Errors and warnings before: 0 this patch: 0
conchuod/build_rv64_clang_allmodconfig success Errors and warnings before: 9 this patch: 9
conchuod/module_param success Was 0 now: 0
conchuod/build_rv64_gcc_allmodconfig success Errors and warnings before: 9 this patch: 9
conchuod/build_rv32_defconfig success Build OK
conchuod/dtb_warn_rv64 success Errors and warnings before: 3 this patch: 3
conchuod/header_inline success No static functions without inline keyword in header files
conchuod/checkpatch success total: 0 errors, 0 warnings, 0 checks, 34 lines checked
conchuod/build_rv64_nommu_k210_defconfig success Build OK
conchuod/verify_fixes success No Fixes tag
conchuod/build_rv64_nommu_virt_defconfig success Build OK

Commit Message

Alexandre Ghiti July 22, 2023, 12:38 p.m. UTC
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>
---
 arch/riscv/kernel/setup.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Conor Dooley July 24, 2023, 2:19 p.m. UTC | #1
Hey Alex,

On Sat, Jul 22, 2023 at 02:38:47PM +0200, Alexandre Ghiti wrote:
> Dump out the KASLR virtual kernel offset when panic to help debug kernel.
> 
> Signed-off-by: Zong Li <zong.li@sifive.com>

Either you're missing a Co-developed-by: or the author of this patch is
incorrect.

> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Alexandre Ghiti July 25, 2023, 7:05 a.m. UTC | #2
Hi Conor,

On Mon, Jul 24, 2023 at 4:20 PM Conor Dooley <conor.dooley@microchip.com> wrote:
>
> Hey Alex,
>
> On Sat, Jul 22, 2023 at 02:38:47PM +0200, Alexandre Ghiti wrote:
> > Dump out the KASLR virtual kernel offset when panic to help debug kernel.
> >
> > Signed-off-by: Zong Li <zong.li@sifive.com>
>
> Either you're missing a Co-developed-by: or the author of this patch is
> incorrect.

Ok, I thought it would work this way, Zong first did something similar
a few years ago, so we need his name here. @Palmer Dabbelt if no other
changes are needed, do you mind replacing the SoB with a
Co-developed-by?

Thanks,

Alex

>
> > Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Conor Dooley July 25, 2023, 7:11 a.m. UTC | #3
On Tue, Jul 25, 2023 at 09:05:37AM +0200, Alexandre Ghiti wrote:
> Hi Conor,
> 
> On Mon, Jul 24, 2023 at 4:20 PM Conor Dooley <conor.dooley@microchip.com> wrote:
> >
> > Hey Alex,
> >
> > On Sat, Jul 22, 2023 at 02:38:47PM +0200, Alexandre Ghiti wrote:
> > > Dump out the KASLR virtual kernel offset when panic to help debug kernel.
> > >
> > > Signed-off-by: Zong Li <zong.li@sifive.com>
> >
> > Either you're missing a Co-developed-by: or the author of this patch is
> > incorrect.
> 
> Ok, I thought it would work this way, Zong first did something similar
> a few years ago, so we need his name here. @Palmer Dabbelt if no other
> changes are needed, do you mind replacing the SoB with a
> Co-developed-by?

You can't have a Co-developed-by without a SoB, so both are needed :)
diff mbox series

Patch

diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 971fe776e2f8..0fb5a26ca4cc 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -21,6 +21,7 @@ 
 #include <linux/smp.h>
 #include <linux/efi.h>
 #include <linux/crash_dump.h>
+#include <linux/panic_notifier.h>
 
 #include <asm/acpi.h>
 #include <asm/alternative.h>
@@ -341,3 +342,27 @@  void free_initmem(void)
 
 	free_initmem_default(POISON_FREE_INITMEM);
 }
+
+static int dump_kernel_offset(struct notifier_block *self,
+			      unsigned long v, void *p)
+{
+	pr_emerg("Kernel Offset: 0x%lx from 0x%lx\n",
+		 kernel_map.virt_offset,
+		 KERNEL_LINK_ADDR);
+
+	return 0;
+}
+
+static struct notifier_block kernel_offset_notifier = {
+	.notifier_call = dump_kernel_offset
+};
+
+static int __init register_kernel_offset_dumper(void)
+{
+	if (IS_ENABLED(CONFIG_RANDOMIZE_BASE))
+		atomic_notifier_chain_register(&panic_notifier_list,
+					       &kernel_offset_notifier);
+
+	return 0;
+}
+device_initcall(register_kernel_offset_dumper);