diff --git a/Add-loongarch-iomem.h.patch b/Add-loongarch-iomem.h.patch deleted file mode 100644 index 137ed9b2969ca19d2ed63c020e6816008f457a7a..0000000000000000000000000000000000000000 --- a/Add-loongarch-iomem.h.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 7a26c60ffa31f54606063855348a4c6aaeabfe13 Mon Sep 17 00:00:00 2001 -From: huangwenhua -Date: Mon, 13 May 2024 11:43:20 +0800 -Subject: [PATCH] Add loongarch/iomem.h - ---- - kexec/arch/loongarch/iomem.h | 10 ++++++++++ - 1 file changed, 10 insertions(+) - create mode 100644 kexec/arch/loongarch/iomem.h - -diff --git a/kexec/arch/loongarch/iomem.h b/kexec/arch/loongarch/iomem.h -new file mode 100644 -index 0000000..7671e26 ---- /dev/null -+++ b/kexec/arch/loongarch/iomem.h -@@ -0,0 +1,10 @@ -+#ifndef IOMEM_H -+#define IOMEM_H -+ -+#define SYSTEM_RAM "System RAM\n" -+#define KERNEL_CODE "Kernel code\n" -+#define KERNEL_DATA "Kernel data\n" -+#define CRASH_KERNEL "Crash kernel\n" -+#define IOMEM_RESERVED "Reserved\n" -+ -+#endif --- -2.43.0 - diff --git a/kexec-tools-Add-riscv-support.patch b/kexec-tools-Add-riscv-support.patch index 2411292f123681ed5b4d2a213ac2cf89b24610bd..1b51c04fbe7f5e511260cb218050f2594569a61c 100644 --- a/kexec-tools-Add-riscv-support.patch +++ b/kexec-tools-Add-riscv-support.patch @@ -207,16 +207,16 @@ Signed-off-by: Mingzheng Xing create mode 100644 purgatory/arch/riscv/Makefile diff --git a/configure.ac b/configure.ac -index 767574e..a3e4e88 100644 +index e4c3b78..eff2f6a 100644 --- a/configure.ac +++ b/configure.ac -@@ -61,6 +61,9 @@ case $target_cpu in - loongarch*) - ARCH="loongarch" - ;; -+ riscv32|riscv64) -+ ARCH="riscv" -+ ;; +@@ -64,6 +64,9 @@ case $target_cpu in + sw_64*) + ARCH="sw_64" + ;; ++ riscv32|riscv64) ++ ARCH="riscv" ++ ;; * ) AC_MSG_ERROR([unsupported architecture $target_cpu]) ;; diff --git a/kexec-tools.spec b/kexec-tools.spec index aed1acc34d93cd8a562f1b86241fe0ceaeb1dffc..5365ded1548367d7c6a331c3ac9a0dba9adce61d 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -4,7 +4,7 @@ Name: kexec-tools Version: 2.0.26 -Release: 8 +Release: 9 License: GPLv2 Summary: The kexec/kdump userspace component URL: https://www.kernel.org/ @@ -73,20 +73,12 @@ Requires: systemd-udev%{?_isa} Patch0001: add-secure-compile-options-for-makedumpfile.patch Patch0002: kexec-Add-quick-kexec-support.patch Patch0003: kexec-Quick-kexec-implementation-for-arm64.patch - -%ifarch sw_64 Patch0004: sw_64.patch -Patch0005: makedumpfile-1.7.2-sw.patch -%endif - -%ifarch riscv64 +Patch0005: makedumpfile-1.7.4-sw.patch Patch0006: kexec-tools-Add-riscv-support.patch Patch0007: kexec-tools-fix-riscv-support.patch -%endif - -%ifarch loongarch64 -Patch0008: Add-loongarch-iomem.h.patch -%endif +Patch0008: loongarch64-fix-some-functional-issues-and-compilati.patch +Patch0009: loongarch64-fix-kernel-image-size-error.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -295,6 +287,10 @@ done %endif %changelog +* Wed Nov 27 2024 Yangzhenyu - 2.0.26-9 +- fix some functional issues and compilation in loongarch64 +- fix kernel image size error in loongarch64 + * Fri Sep 20 2024 chenguokai - 2.0.26-8 - Fix multiple issues of riscv image format & initrd support diff --git a/loongarch64-fix-kernel-image-size-error.patch b/loongarch64-fix-kernel-image-size-error.patch new file mode 100644 index 0000000000000000000000000000000000000000..20ecad17f0956458d3a26155c063c3060f1f384f --- /dev/null +++ b/loongarch64-fix-kernel-image-size-error.patch @@ -0,0 +1,88 @@ +diff -ruN kexec-tools-2.0.26-org/kexec/arch/loongarch/kexec-elf-loongarch.c kexec-tools-2.0.26/kexec/arch/loongarch/kexec-elf-loongarch.c +--- kexec-tools-2.0.26-org/kexec/arch/loongarch/kexec-elf-loongarch.c 2024-12-08 04:23:07.366053586 +0800 ++++ kexec-tools-2.0.26/kexec/arch/loongarch/kexec-elf-loongarch.c 2024-12-08 04:25:25.716019119 +0800 +@@ -54,6 +54,7 @@ + unsigned long kernel_segment; + struct mem_ehdr ehdr; + int result; ++ int i; + + result = build_elf_exec_info(kernel_buf, kernel_size, &ehdr, 0); + +@@ -61,6 +62,26 @@ + dbgprintf("%s: build_elf_exec_info failed\n", __func__); + goto exit; + } ++ ++ /* Find and process the loongarch image header. */ ++ for (i = 0; i < ehdr.e_phnum; i++) { ++ struct mem_phdr *phdr = &ehdr.e_phdr[i]; ++ ++ if (phdr->p_type != PT_LOAD) ++ continue; ++ ++ header = (const struct loongarch_image_header *)( ++ kernel_buf + phdr->p_offset); ++ ++ if (!loongarch_process_image_header(header)) ++ break; ++ } ++ ++ if (i == ehdr.e_phnum) { ++ dbgprintf("%s: Valid loongarch image header not found\n", __func__); ++ result = EFAILED; ++ goto exit; ++ } + + kernel_segment = loongarch_locate_kernel_segment(info); + +@@ -72,13 +93,12 @@ + + dbgprintf("%s: kernel_segment: %016lx\n", __func__, kernel_segment); + dbgprintf("%s: image_size: %016lx\n", __func__, +- kernel_size); ++ loongarch_mem.image_size); + dbgprintf("%s: text_offset: %016lx\n", __func__, + loongarch_mem.text_offset); + dbgprintf("%s: phys_offset: %016lx\n", __func__, + loongarch_mem.phys_offset); +- dbgprintf("%s: PE format: %s\n", __func__, +- (loongarch_header_check_pe_sig(header) ? "yes" : "no")); ++ dbgprintf("%s: PE format: %s\n", __func__); + + /* create and initialize elf core header segment */ + if (info->kexec_flags & KEXEC_ON_CRASH) { +@@ -112,7 +132,7 @@ + kernel_size = MiB(64); + + /* load additional data */ +- result = loongarch_load_other_segments(info, kernel_segment + kernel_size); ++ result = loongarch_load_other_segments(info, kernel_segment + loongarch_mem.image_size); + + exit: + free_elf_info(&ehdr); +diff -ruN kexec-tools-2.0.26-org/kexec/arch/loongarch/kexec-loongarch.c kexec-tools-2.0.26/kexec/arch/loongarch/kexec-loongarch.c +--- kexec-tools-2.0.26-org/kexec/arch/loongarch/kexec-loongarch.c 2024-12-08 04:23:07.366053586 +0800 ++++ kexec-tools-2.0.26/kexec/arch/loongarch/kexec-loongarch.c 2024-12-08 04:26:49.265997859 +0800 +@@ -325,15 +325,17 @@ + cmdline_add_elfcorehdr(cmdline, elfcorehdr_mem.start, + elfcorehdr_mem.end - elfcorehdr_mem.start + 1); + +- cmdline_add_mem(cmdline, crash_reserved_mem[usablemem_rgns.size - 1].start, +- crash_reserved_mem[usablemem_rgns.size - 1].end - +- crash_reserved_mem[usablemem_rgns.size - 1].start + 1); ++ for(i = 0;i < usablemem_rgns.size; i++) { ++ cmdline_add_mem(cmdline, crash_reserved_mem[i].start, ++ crash_reserved_mem[i].end - ++ crash_reserved_mem[i].start + 1); ++ } + } + + cmdline[sizeof(cmdline) - 1] = 0; + add_buffer(info, cmdline, sizeof(cmdline), sizeof(cmdline), + sizeof(void *), _ALIGN_UP(hole_min, getpagesize()), +- 0xffffffff, 1); ++ hole_max, 1); + + dbgprintf("%s:%d: command_line: %s\n", __func__, __LINE__, cmdline); + diff --git a/loongarch64-fix-some-functional-issues-and-compilati.patch b/loongarch64-fix-some-functional-issues-and-compilati.patch new file mode 100644 index 0000000000000000000000000000000000000000..9d15b051ff07b3f5c2d82f9c86148c0447a3bde2 --- /dev/null +++ b/loongarch64-fix-some-functional-issues-and-compilati.patch @@ -0,0 +1,151 @@ +diff -ruN kexec-tools-2.0.26/kexec/arch/loongarch/crashdump-loongarch.c kexec-tools-2.0.26-org/kexec/arch/loongarch/crashdump-loongarch.c +--- kexec-tools-2.0.26/kexec/arch/loongarch/crashdump-loongarch.c 2022-11-18 23:11:40.000000000 +0800 ++++ kexec-tools-2.0.26-org/kexec/arch/loongarch/crashdump-loongarch.c 2024-12-08 01:32:24.968632788 +0800 +@@ -183,6 +183,28 @@ + return 0; + } + ++/* ++ * e_entry and p_paddr are actually in virtual address space. ++ * Those values will be translated to physcal addresses by using ++ * virt_to_phys() in add_segment(). ++ * So let's fix up those values for later use so the memory base will be ++ * correctly replaced with crash_reserved_mem[usablemem_rgns.size - 1].start. ++ */ ++void fixup_elf_addrs(struct mem_ehdr *ehdr) ++{ ++ struct mem_phdr *phdr; ++ int i; ++ ++ ehdr->e_entry += crash_reserved_mem[usablemem_rgns.size - 1].start; ++ ++ for (i = 0; i < ehdr->e_phnum; i++) { ++ phdr = &ehdr->e_phdr[i]; ++ if (phdr->p_type != PT_LOAD) ++ continue; ++ phdr->p_paddr += crash_reserved_mem[usablemem_rgns.size - 1].start; ++ } ++} ++ + int get_crash_kernel_load_range(uint64_t *start, uint64_t *end) + { + if (!usablemem_rgns.size) +diff -ruN kexec-tools-2.0.26/kexec/arch/loongarch/crashdump-loongarch.h kexec-tools-2.0.26-org/kexec/arch/loongarch/crashdump-loongarch.h +--- kexec-tools-2.0.26/kexec/arch/loongarch/crashdump-loongarch.h 2022-11-18 23:11:40.000000000 +0800 ++++ kexec-tools-2.0.26-org/kexec/arch/loongarch/crashdump-loongarch.h 2024-12-08 01:32:24.968632788 +0800 +@@ -8,6 +8,7 @@ + + int load_crashdump_segments(struct kexec_info *info); + int is_crashkernel_mem_reserved(void); ++void fixup_elf_addrs(struct mem_ehdr *ehdr); + int get_crash_kernel_load_range(uint64_t *start, uint64_t *end); + + #define PAGE_OFFSET 0x9000000000000000ULL +diff -ruN kexec-tools-2.0.26/kexec/arch/loongarch/iomem.h kexec-tools-2.0.26-org/kexec/arch/loongarch/iomem.h +--- kexec-tools-2.0.26/kexec/arch/loongarch/iomem.h 1970-01-01 08:00:00.000000000 +0800 ++++ kexec-tools-2.0.26-org/kexec/arch/loongarch/iomem.h 2024-12-08 01:32:24.968632788 +0800 +@@ -0,0 +1,11 @@ ++#ifndef IOMEM_H ++#define IOMEM_H ++ ++#define SYSTEM_RAM "System RAM\n" ++#define KERNEL_CODE "Kernel code\n" ++#define KERNEL_DATA "Kernel data\n" ++#define CRASH_KERNEL "Crash kernel\n" ++#define IOMEM_RESERVED "Reserved\n" ++ ++#endif ++ +diff -ruN kexec-tools-2.0.26/kexec/arch/loongarch/kexec-elf-loongarch.c kexec-tools-2.0.26-org/kexec/arch/loongarch/kexec-elf-loongarch.c +--- kexec-tools-2.0.26/kexec/arch/loongarch/kexec-elf-loongarch.c 2022-11-18 23:11:40.000000000 +0800 ++++ kexec-tools-2.0.26-org/kexec/arch/loongarch/kexec-elf-loongarch.c 2024-12-08 01:32:24.968632788 +0800 +@@ -90,6 +90,14 @@ + } + } + ++ /* load the kernel */ ++ if (info->kexec_flags & KEXEC_ON_CRASH) ++ /* ++ * offset addresses in elf header in order to load ++ * vmlinux (elf_exec) into crash kernel's memory. ++ */ ++ fixup_elf_addrs(&ehdr); ++ + info->entry = (void *)virt_to_phys(ehdr.e_entry); + + result = elf_exec_load(&ehdr, info); +@@ -99,6 +107,10 @@ + goto exit; + } + ++ /* for vmlinuz kernel image */ ++ if (kernel_size < MiB(16)) ++ kernel_size = MiB(64); ++ + /* load additional data */ + result = loongarch_load_other_segments(info, kernel_segment + kernel_size); + +diff -ruN kexec-tools-2.0.26/kexec/arch/loongarch/kexec-loongarch.c kexec-tools-2.0.26-org/kexec/arch/loongarch/kexec-loongarch.c +--- kexec-tools-2.0.26/kexec/arch/loongarch/kexec-loongarch.c 2022-11-18 23:11:40.000000000 +0800 ++++ kexec-tools-2.0.26-org/kexec/arch/loongarch/kexec-loongarch.c 2024-12-08 01:32:24.968632788 +0800 +@@ -221,6 +221,10 @@ + cmdline = get_command_line(); + remove_parameter(cmdline, "kexec"); + remove_parameter(cmdline, "initrd"); ++ remove_parameter(cmdline, "rd_start"); ++ remove_parameter(cmdline, "rd_size"); ++ remove_parameter(cmdline, "vfio_iommu_type1.allow_unsafe_interrupts"); ++ remove_parameter(cmdline, "nokaslr"); + break; + case OPT_INITRD: + arch_options.initrd_file = optarg; +@@ -253,8 +257,9 @@ + unsigned long hole_end; + + hole = (crash_reserved_mem[usablemem_rgns.size - 1].start < mem_min ? +- mem_min : crash_reserved_mem[usablemem_rgns.size - 1].start); +- hole = _ALIGN_UP(hole, MiB(1)); ++ mem_min : crash_reserved_mem[usablemem_rgns.size - 1].start) + ++ loongarch_mem.text_offset; ++ hole = _ALIGN_UP(hole, MiB(16)); + hole_end = hole + loongarch_mem.text_offset + loongarch_mem.image_size; + + if ((hole_end > mem_max) || +@@ -265,7 +270,7 @@ + } else { + hole = locate_hole(info, + loongarch_mem.text_offset + loongarch_mem.image_size, +- MiB(1), 0, ULONG_MAX, 1); ++ MiB(16), 0, ULONG_MAX, 1); + + if (hole == ULONG_MAX) + dbgprintf("%s: locate_hole failed\n", __func__); +diff -ruN kexec-tools-2.0.26/kexec/arch/loongarch/kexec-pei-loongarch.c kexec-tools-2.0.26-org/kexec/arch/loongarch/kexec-pei-loongarch.c +--- kexec-tools-2.0.26/kexec/arch/loongarch/kexec-pei-loongarch.c 2022-11-18 23:11:40.000000000 +0800 ++++ kexec-tools-2.0.26-org/kexec/arch/loongarch/kexec-pei-loongarch.c 2024-12-08 01:32:24.968632788 +0800 +@@ -66,6 +66,13 @@ + + kernel_entry = virt_to_phys(loongarch_header_kernel_entry(header)); + ++ if (info->kexec_flags & KEXEC_ON_CRASH) ++ /* ++ * offset addresses in order to load vmlinux.efi into ++ * crash kernel's memory. ++ */ ++ kernel_entry += crash_reserved_mem[usablemem_rgns.size - 1].start; ++ + dbgprintf("%s: kernel_segment: %016lx\n", __func__, kernel_segment); + dbgprintf("%s: kernel_entry: %016lx\n", __func__, kernel_entry); + dbgprintf("%s: image_size: %016lx\n", __func__, +diff -ruN kexec-tools-2.0.26/kexec/kexec-syscall.h kexec-tools-2.0.26-org/kexec/kexec-syscall.h +--- kexec-tools-2.0.26/kexec/kexec-syscall.h 2024-12-08 01:32:45.338627715 +0800 ++++ kexec-tools-2.0.26-org/kexec/kexec-syscall.h 2024-12-08 01:32:24.968632788 +0800 +@@ -59,7 +59,7 @@ + #endif + #endif /*ifndef __NR_kexec_load*/ + +-#ifdef __arm__ ++#ifdef __arm__ || defined(__loongarch__) + #undef __NR_kexec_file_load + #endif + diff --git a/makedumpfile-1.7.2-sw.patch b/makedumpfile-1.7.4-sw.patch similarity index 90% rename from makedumpfile-1.7.2-sw.patch rename to makedumpfile-1.7.4-sw.patch index 1d14df279d692f8f6569a302b764d5033db8689b..def1f6ff9ef8179cc6355f85c1ace94c7ed63775 100644 --- a/makedumpfile-1.7.2-sw.patch +++ b/makedumpfile-1.7.4-sw.patch @@ -1,6 +1,6 @@ -diff -Naru ./makedumpfile-1.7.2/arch/sw_64.c ./makedumpfile-1.7.2-sw/arch/sw_64.c ---- ./makedumpfile-1.7.2/arch/sw_64.c 1970-01-01 00:00:00.000000000 +0000 -+++ ./makedumpfile-1.7.2-sw/arch/sw_64.c 2022-08-19 06:54:24.938438551 +0000 +diff -Naru ./makedumpfile-1.7.4/arch/sw_64.c ./makedumpfile-1.7.4-sw/arch/sw_64.c +--- ./makedumpfile-1.7.4/arch/sw_64.c 1970-01-01 00:00:00.000000000 +0000 ++++ ./makedumpfile-1.7.4-sw/arch/sw_64.c 2022-08-19 06:54:24.938438551 +0000 @@ -0,0 +1,126 @@ +/* + * sw_64.c @@ -128,9 +128,9 @@ diff -Naru ./makedumpfile-1.7.2/arch/sw_64.c ./makedumpfile-1.7.2-sw/arch/sw_64. +} + +#endif /* sw_64 */ -diff -Naru ./makedumpfile-1.7.2/makedumpfile.h ./makedumpfile-1.7.2-sw/makedumpfile.h ---- ./makedumpfile-1.7.2/makedumpfile.h 2021-11-08 00:36:15.000000000 +0000 -+++ ./makedumpfile-1.7.2-sw/makedumpfile.h 2022-08-19 07:46:43.093698825 +0000 +diff -Naru ./makedumpfile-1.7.4/makedumpfile.h ./makedumpfile-1.7.4-sw/makedumpfile.h +--- ./makedumpfile-1.7.4/makedumpfile.h 2021-11-08 00:36:15.000000000 +0000 ++++ ./makedumpfile-1.7.4-sw/makedumpfile.h 2022-08-19 07:46:43.093698825 +0000 @@ -963,7 +963,7 @@ #endif /* sparc64 */ @@ -219,15 +219,15 @@ diff -Naru ./makedumpfile-1.7.2/makedumpfile.h ./makedumpfile-1.7.2-sw/makedumpf #ifdef __loongarch64__ /* loongarch64 */ #define kvtop_xen(X) FALSE #define get_xen_basic_info_arch(X) FALSE -diff -Naru ./makedumpfile-1.7.2/Makefile ./makedumpfile-1.7.2-sw/Makefile ---- ./makedumpfile-1.7.2/Makefile 2021-11-08 00:36:15.000000000 +0000 -+++ ./makedumpfile-1.7.2-sw/Makefile 2022-08-19 06:55:54.538591123 +0000 -@@ -47,7 +47,7 @@ +diff -Naru ./makedumpfile-1.7.4/Makefile ./makedumpfile-1.7.4-sw/Makefile +--- ./makedumpfile-1.7.4/Makefile 2021-11-08 00:36:15.000000000 +0000 ++++ ./makedumpfile-1.7.4-sw/Makefile 2022-08-19 06:55:54.538591123 +0000 +@@ -48,7 +48,7 @@ SRC_BASE = makedumpfile.c makedumpfile.h diskdump_mod.h sadump_mod.h sadump_info.h SRC_PART = print_info.c dwarf_info.c elf_info.c erase_info.c sadump_info.c cache.c tools.c printk.c detect_cycle.c OBJ_PART=$(patsubst %.c,%.o,$(SRC_PART)) --SRC_ARCH = arch/arm.c arch/arm64.c arch/x86.c arch/x86_64.c arch/ia64.c arch/ppc64.c arch/s390x.c arch/ppc.c arch/sparc64.c arch/mips64.c arch/loongarch64.c -+SRC_ARCH = arch/arm.c arch/arm64.c arch/x86.c arch/x86_64.c arch/ia64.c arch/ppc64.c arch/s390x.c arch/ppc.c arch/sparc64.c arch/mips64.c arch/loongarch64.c arch/sw_64.c +-SRC_ARCH = arch/arm.c arch/arm64.c arch/x86.c arch/x86_64.c arch/ia64.c arch/ppc64.c arch/s390x.c arch/ppc.c arch/sparc64.c arch/mips64.c arch/loongarch64.c arch/riscv64.c ++SRC_ARCH = arch/arm.c arch/arm64.c arch/x86.c arch/x86_64.c arch/ia64.c arch/ppc64.c arch/s390x.c arch/ppc.c arch/sparc64.c arch/mips64.c arch/loongarch64.c arch/riscv64.c arch/sw_64.c OBJ_ARCH=$(patsubst %.c,%.o,$(SRC_ARCH)) - + LIBS = -ldw -lbz2 -ldl -lelf -lz