From e7c201f56a538f06cbc4ef93a028872ecc6d1152 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Mon, 28 Feb 2022 10:49:16 +0800 Subject: [PATCH] arm64: deduce the start address of kernel code, based on kernel version Resolves: bz2031738 Upstream: crash-utils Conflict: None Signed-off-by: Pingfan Liu --- ..._ARM64_VA_BITS-to-initialize-VA_BITS.patch | 34 +++++++++ ...-start-address-of-kernel-code-based-.patch | 69 +++++++++++++++++++ crash.spec | 4 ++ 3 files changed, 107 insertions(+) create mode 100644 0001-arm64-Use-CONFIG_ARM64_VA_BITS-to-initialize-VA_BITS.patch create mode 100644 0001-arm64-deduce-the-start-address-of-kernel-code-based-.patch diff --git a/0001-arm64-Use-CONFIG_ARM64_VA_BITS-to-initialize-VA_BITS.patch b/0001-arm64-Use-CONFIG_ARM64_VA_BITS-to-initialize-VA_BITS.patch new file mode 100644 index 0000000..ffc3f85 --- /dev/null +++ b/0001-arm64-Use-CONFIG_ARM64_VA_BITS-to-initialize-VA_BITS.patch @@ -0,0 +1,34 @@ +From 6ecb8a23ca294de5ef92726c782f4c92fcb39d92 Mon Sep 17 00:00:00 2001 +From: Huang Shijie +Date: Fri, 11 Feb 2022 09:46:42 +0000 +Subject: [PATCH] arm64: Use CONFIG_ARM64_VA_BITS to initialize VA_BITS_ACTUAL + +We can get VA_BITS_ACTUAL from CONFIG_ARM64_VA_BITS by guess. + +Without this patch, we may need to use "--machdep vabits_actual=48" to +set the VA_BITS_ACTUAL. + +Signed-off-by: Huang Shijie +--- + arm64.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/arm64.c b/arm64.c +index 4f2c2b5..de1038a 100644 +--- a/arm64.c ++++ b/arm64.c +@@ -4170,6 +4170,11 @@ arm64_calc_VA_BITS(void) + } else if (machdep->machspec->VA_BITS_ACTUAL) { + machdep->machspec->VA_BITS = machdep->machspec->VA_BITS_ACTUAL; + machdep->machspec->VA_START = _VA_START(machdep->machspec->VA_BITS_ACTUAL); ++ } else if (machdep->machspec->CONFIG_ARM64_VA_BITS) { ++ /* guess */ ++ machdep->machspec->VA_BITS_ACTUAL = machdep->machspec->CONFIG_ARM64_VA_BITS; ++ machdep->machspec->VA_BITS = machdep->machspec->CONFIG_ARM64_VA_BITS; ++ machdep->machspec->VA_START = _VA_START(machdep->machspec->VA_BITS_ACTUAL); + } else + error(FATAL, "cannot determine VA_BITS_ACTUAL\n"); + } +-- +2.31.1 + diff --git a/0001-arm64-deduce-the-start-address-of-kernel-code-based-.patch b/0001-arm64-deduce-the-start-address-of-kernel-code-based-.patch new file mode 100644 index 0000000..0454be6 --- /dev/null +++ b/0001-arm64-deduce-the-start-address-of-kernel-code-based-.patch @@ -0,0 +1,69 @@ +From e3bdc32aab5d8fe09b679cf394da8ba8826e207f Mon Sep 17 00:00:00 2001 +From: Pingfan Liu +Date: Thu, 24 Feb 2022 11:52:12 +0800 +Subject: [PATCH] arm64: deduce the start address of kernel code, based on + kernel version + +After kernel commit e2a073dde921 ("arm64: omit [_text, _stext) from +permanent kernel mapping"), the range [_text, _stext] is reclaimed. But +the current crash code still assumes kernel starting from "_text". + +This change only affects the vmalloced area on arm64 and may result a +false in arm64_IS_VMALLOC_ADDR(). + +Since vmcore has no extra information about this trival change, it can +only be deduced from kernel version, which means ms->kimage_text can not +be correctly initialized until kernel_init() finishes. Here on arm64, it +can be done at the point machdep_init(POST_GDB). This is fine +since there is no access to vmalloced area at this stage. + +Signed-off-by: Pingfan Liu +--- + arm64.c | 17 +++++++++++++++++ + 1 file changed, 17 insertions(+) + +diff --git a/arm64.c b/arm64.c +index de1038a..3ab8489 100644 +--- a/arm64.c ++++ b/arm64.c +@@ -92,6 +92,20 @@ static void arm64_calc_VA_BITS(void); + static int arm64_is_uvaddr(ulong, struct task_context *); + static void arm64_calc_KERNELPACMASK(void); + ++static void arm64_calc_kernel_start(void) ++{ ++ struct machine_specific *ms = machdep->machspec; ++ struct syment *sp; ++ ++ if (THIS_KERNEL_VERSION >= LINUX(5,11,0)) ++ sp = kernel_symbol_search("_stext"); ++ else ++ sp = kernel_symbol_search("_text"); ++ ++ ms->kimage_text = (sp ? sp->value : 0); ++ sp = kernel_symbol_search("_end"); ++ ms->kimage_end = (sp ? sp->value : 0); ++} + + /* + * Do all necessary machine-specific setup here. This is called several times +@@ -241,6 +255,7 @@ arm64_init(int when) + if (machdep->flags & NEW_VMEMMAP) { + struct syment *sp; + ++ /* It is finally decided in arm64_calc_kernel_start() */ + sp = kernel_symbol_search("_text"); + ms->kimage_text = (sp ? sp->value : 0); + sp = kernel_symbol_search("_end"); +@@ -387,6 +402,8 @@ arm64_init(int when) + break; + + case POST_GDB: ++ /* Rely on kernel version to decide the kernel start address */ ++ arm64_calc_kernel_start(); + arm64_calc_virtual_memory_ranges(); + arm64_get_section_size_bits(); + +-- +2.31.1 + diff --git a/crash.spec b/crash.spec index d9a5ff4..480b4e4 100644 --- a/crash.spec +++ b/crash.spec @@ -34,6 +34,8 @@ Patch13: 0007-GDB-fix-completion-related-libstdc-assert.patch Patch14: 0008-Improve-the-ps-performance-for-vmcores-with-large-nu.patch Patch15: 0009-arm64-Fix-segfault-by-bt-command-with-offline-cpus.patch Patch16: 0010-Fix-for-kmem-s-S-and-bt-F-F-on-Linux-5.17-rc1.patch +Patch17: 0001-arm64-Use-CONFIG_ARM64_VA_BITS-to-initialize-VA_BITS.patch +Patch18: 0001-arm64-deduce-the-start-address-of-kernel-code-based-.patch %description The core analysis suite is a self-contained tool that can be used to @@ -70,6 +72,8 @@ offered by Mission Critical Linux, or the LKCD kernel patch. %patch14 -p1 %patch15 -p1 %patch16 -p1 +%patch17 -p1 +%patch18 -p1 %build