From 60585243100fda966076618a80baf9040cc9f421 Mon Sep 17 00:00:00 2001 From: Bin Wang Date: Wed, 23 Feb 2022 17:24:47 +0800 Subject: [PATCH] arm64/crashdump: deduce paddr of _text based on kernel code size vmcore-dmesg shows bug: No program header covering vaddr 0x45524f44300000001found kexec bug? And kdump cannot dump vmcore-dmesg.txt correctly. Add patch to fix this. Signed-off-by: Bin Wang --- ...deduce-paddr-of-_text-based-on-kerne.patch | 65 +++++++++++++++++++ kexec-tools.spec | 8 ++- 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 arm64-crashdump-deduce-paddr-of-_text-based-on-kerne.patch diff --git a/arm64-crashdump-deduce-paddr-of-_text-based-on-kerne.patch b/arm64-crashdump-deduce-paddr-of-_text-based-on-kerne.patch new file mode 100644 index 0000000..80c38ef --- /dev/null +++ b/arm64-crashdump-deduce-paddr-of-_text-based-on-kerne.patch @@ -0,0 +1,65 @@ +From 1614959f2f0d79b5f7fdc57d6aa42da1a0298153 Mon Sep 17 00:00:00 2001 +From: Pingfan Liu +Date: Fri, 10 Dec 2021 10:57:33 +0800 +Subject: [PATCH] arm64/crashdump: deduce paddr of _text based on kernel code + size + +kexec-tools commit 61b8c79b0fb7 ("arm64/crashdump-arm64: deduce the +paddr of _text") tries to deduce the paddr of _text, but turns out +partially. + +That commit is based on "The Image must be placed text_offset bytes from +a 2MB aligned base address anywhere in usable system RAM and called +there" in linux/Documentation/arm64/booting.rst, plus text_offset field +is zero. + +But in practice, some boot loaders does not obey the convention, and +still boots up the kernel successfully. + +Revisiting kernel commit e2a073dde921 ("arm64: omit [_text, _stext) from +permanent kernel mapping"), the kernel code size changes from (unsigned +long)__init_begin - (unsigned long)_text to (unsigned long)__init_begin +- (unsigned long)_stext + +And it should be a better factor to decide which label starts the +"Kernel code" in /proc/iomem. + +Signed-off-by: Pingfan Liu +Signed-off-by: Simon Horman +--- + kexec/arch/arm64/crashdump-arm64.c | 14 +++++++++++--- + 1 file changed, 11 insertions(+), 3 deletions(-) + +diff --git a/kexec/arch/arm64/crashdump-arm64.c b/kexec/arch/arm64/crashdump-arm64.c +index 03d6204..a02019a 100644 +--- a/kexec/arch/arm64/crashdump-arm64.c ++++ b/kexec/arch/arm64/crashdump-arm64.c +@@ -91,14 +91,22 @@ static int iomem_range_callback(void *UNUSED(data), int UNUSED(nr), + return mem_regions_alloc_and_add(&system_memory_rgns, + base, length, RANGE_RAM); + else if (strncmp(str, KERNEL_CODE, strlen(KERNEL_CODE)) == 0) { ++ ++ unsigned long long kva_text = get_kernel_sym("_text"); ++ unsigned long long kva_stext = get_kernel_sym("_stext"); ++ unsigned long long kva_text_end = get_kernel_sym("__init_begin"); ++ + /* + * old: kernel_code.start = __pa_symbol(_text); + * new: kernel_code.start = __pa_symbol(_stext); + * +- * By utilizing the fact that paddr(_text) should align on 2MB, plus +- * _stext - _text <= 64K. ++ * For compatibility, deduce by comparing the gap "__init_begin - _stext" ++ * and the res size of "Kernel code" in /proc/iomem + */ +- elf_info.kern_paddr_start = base & ((0xffffffffffffffffUL) << 21); ++ if (kva_text_end - kva_stext == length) ++ elf_info.kern_paddr_start = base - (kva_stext - kva_text); ++ else ++ elf_info.kern_paddr_start = base; + } + else if (strncmp(str, KERNEL_DATA, strlen(KERNEL_DATA)) == 0) + elf_info.kern_size = base + length - elf_info.kern_paddr_start; +-- +1.8.3.1 + diff --git a/kexec-tools.spec b/kexec-tools.spec index d58fc4d..d571ede 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -4,7 +4,7 @@ Name: kexec-tools Version: 2.0.23 -Release: 2 +Release: 3 License: GPLv2 Summary: The kexec/kdump userspace component URL: https://www.kernel.org/ @@ -73,6 +73,7 @@ Patch0001: arm64-support-more-than-one-crash-kernel-regions.patch Patch0002: add-secure-compile-options-for-makedumpfile.patch Patch0003: kexec-Add-quick-kexec-support.patch Patch0004: kexec-Quick-kexec-implementation-for-arm64.patch +Patch0005: arm64-crashdump-deduce-paddr-of-_text-based-on-kerne.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -105,7 +106,7 @@ tar -z -x -v -f %{SOURCE19} %ifarch aarch64 %patch0004 -p1 %endif - +%patch0005 -p1 %build autoreconf @@ -291,6 +292,9 @@ done %endif %changelog +* Wed Feb 23 2022 wangbin - 2.0.23-3 +- arm64/crashdump: deduce paddr of _text based on kernel code size + * Wed Feb 23 2022 snoweay - 2.0.23-2 - Fix conflicts between quick kexec and load-live-update with xen. -- Gitee