From 8c005fbbbf72781862c01bd6290f9b8e36db5097 Mon Sep 17 00:00:00 2001 From: Ming Wang Date: Tue, 8 Aug 2023 18:55:03 +0800 Subject: [PATCH] loongarch64: add loongarch64 support. This patch fix some functional issues and some compilation errors. 1. kexec: __NR_kexec_file_load is set to undefined on LoongArch 2. Set up kernel image segment 3. Add 4.19 kernel handling 4. Add kexec-tools-2.0.26 kernel.org missing file(iomem.h). 5. Adjust kernel position alignment rules Signed-off-by: Ming Wang --- kdump.sysconfig.loongarch64 | 37 ++++ kexec-tools.spec | 16 +- ...some-functional-issues-and-compilati.patch | 185 ++++++++++++++++++ 3 files changed, 234 insertions(+), 4 deletions(-) create mode 100755 kdump.sysconfig.loongarch64 create mode 100644 loongarch64-fix-some-functional-issues-and-compilati.patch diff --git a/kdump.sysconfig.loongarch64 b/kdump.sysconfig.loongarch64 new file mode 100755 index 0000000..e2a2d7b --- /dev/null +++ b/kdump.sysconfig.loongarch64 @@ -0,0 +1,37 @@ +# Kernel Version string for the -kdump kernel, such as 2.6.13-1544.FC5kdump +# If no version is specified, then the init script will try to find a +# kdump kernel with the same version number as the running kernel. +KDUMP_KERNELVER="" + +# The kdump commandline is the command line that needs to be passed off to +# the kdump kernel. This will likely match the contents of the grub kernel +# line. For example: +# KDUMP_COMMANDLINE="ro root=LABEL=/" +# Dracut depends on proper root= options, so please make sure that appropriate +# root= options are copied from /proc/cmdline. In general it is best to append +# command line options using "KDUMP_COMMANDLINE_APPEND=". +# If a command line is not specified, the default will be taken from +# /proc/cmdline +KDUMP_COMMANDLINE="" + +# This variable lets us remove arguments from the current kdump commandline +# as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline +# NOTE: some arguments such as crashkernel will always be removed +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len rd_start rd_size initrd" + +# This variable lets us append arguments to the current kdump commandline +# after processed by KDUMP_COMMANDLINE_REMOVE +KDUMP_COMMANDLINE_APPEND="init 3 irqpoll reset_devices cgroup_disable=memory udev.children-max=2 panic=10 novmcoredd" + +# Any additional kexec arguments required. In most situations, this should +# be left empty +# +# Example: +# KEXEC_ARGS="--elf32-core-headers" +KEXEC_ARGS="" + +#Where to find the boot image +#KDUMP_BOOTDIR="/boot" + +#What is the image type used for kdump +KDUMP_IMG="vmlinuz" diff --git a/kexec-tools.spec b/kexec-tools.spec index 68fff19..597893f 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -3,7 +3,7 @@ %global mkdf_ver 1.7.2 %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) -%define anolis_release 1 +%define anolis_release 2 Name: kexec-tools Version: 2.0.26 @@ -41,6 +41,7 @@ Source33: 92-crashkernel.install Source34: crashkernel-howto.txt Source35: kdump-migrate-action.sh Source36: kdump-restart.sh +Source37: kdump.sysconfig.loongarch64 ####################################### # These are sources for mkdumpramfs @@ -88,6 +89,8 @@ BuildRequires: libtool Obsoletes: diskdumputils netdump kexec-tools-eppic %endif +Patch0001: loongarch64-fix-some-functional-issues-and-compilati.patch + %description kexec-tools provides /sbin/kexec binary that facilitates a new kernel to boot using the kernel's kexec feature either on a @@ -110,6 +113,8 @@ mkdir -p -m755 kcp tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} +%patch0001 -p1 + %build autoreconf %configure \ @@ -124,7 +129,7 @@ cp %{SOURCE27} . cp %{SOURCE34} . make -%ifarch x86_64 aarch64 +%ifarch x86_64 aarch64 loongarch64 make -C eppic-%{eppic_ver}/libeppic make -C makedumpfile-%{mkdf_ver} LINKTYPE=dynamic USELZO=on USESNAPPY=on USEZSTD=on make -C makedumpfile-%{mkdf_ver} LDFLAGS="$LDFLAGS -I../eppic-%{eppic_ver}/libeppic -L../eppic-%{eppic_ver}/libeppic" eppic_makedumpfile.so @@ -173,7 +178,7 @@ install -m 755 -D %{SOURCE22} $RPM_BUILD_ROOT%{_prefix}/lib/systemd/system-gener install -m 755 -D %{SOURCE30} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/60-kdump.install install -m 755 -D %{SOURCE33} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/92-crashkernel.install -%ifarch x86_64 aarch64 +%ifarch x86_64 aarch64 loongarch64 install -m 755 makedumpfile-%{mkdf_ver}/makedumpfile $RPM_BUILD_ROOT/usr/sbin/makedumpfile install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.8 $RPM_BUILD_ROOT/%{_mandir}/man8/makedumpfile.8 install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.conf.5 $RPM_BUILD_ROOT/%{_mandir}/man5/makedumpfile.conf.5 @@ -323,7 +328,7 @@ done %doc kdump-in-cluster-environment.txt %doc live-image-kdump-howto.txt %doc crashkernel-howto.txt -%ifarch x86_64 aarch64 +%ifarch x86_64 aarch64 loongarch64 %{_libdir}/eppic_makedumpfile.so %{abidir}/eppic_makedumpfile.dump %{abidir}/kexec-option.list @@ -337,6 +342,9 @@ done %doc TODO AUTHORS %changelog +* Tue Aug 08 2023 Ming Wang - 2.0.26-2 +- Fix some LoongArch64 functional issues and compilation errors. + * Fri Feb 03 2023 Xuchun Shang - 2.0.26-1 - Update to version 2.0.26 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 0000000..29719f2 --- /dev/null +++ b/loongarch64-fix-some-functional-issues-and-compilati.patch @@ -0,0 +1,185 @@ +From 2ad76a98b6c100d324da149d5deaf0e813c67b92 Mon Sep 17 00:00:00 2001 +From: Youling Tang +Date: Fri, 24 Feb 2023 09:29:38 +0800 +Subject: [PATCH] loongarch64: fix some functional issues and compilation + errors. + +1. kexec: __NR_kexec_file_load is set to undefined on LoongArch +2. Set up kernel image segment +3. Add 4.19 kernel handling +4. Add kexec-tools-2.0.26 kernel.org missing file(iomem.h). +5. Adjust kernel position alignment rules + +Signed-off-by: Ming Wang +--- + kexec/arch/loongarch/crashdump-loongarch.c | 22 ++++++++++++++++++++++ + kexec/arch/loongarch/crashdump-loongarch.h | 1 + + kexec/arch/loongarch/iomem.h | 10 ++++++++++ + kexec/arch/loongarch/kexec-elf-loongarch.c | 12 ++++++++++++ + kexec/arch/loongarch/kexec-loongarch.c | 11 ++++++++--- + kexec/arch/loongarch/kexec-pei-loongarch.c | 7 +++++++ + kexec/kexec-syscall.h | 2 +- + 7 files changed, 61 insertions(+), 4 deletions(-) + create mode 100644 kexec/arch/loongarch/iomem.h + +diff --git a/kexec/arch/loongarch/crashdump-loongarch.c b/kexec/arch/loongarch/crashdump-loongarch.c +index aaf6cf3..81250e4 100644 +--- a/kexec/arch/loongarch/crashdump-loongarch.c ++++ b/kexec/arch/loongarch/crashdump-loongarch.c +@@ -183,6 +183,28 @@ int load_crashdump_segments(struct kexec_info *info) + 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 --git a/kexec/arch/loongarch/crashdump-loongarch.h b/kexec/arch/loongarch/crashdump-loongarch.h +index 3eb4e0a..25ff24b 100644 +--- a/kexec/arch/loongarch/crashdump-loongarch.h ++++ b/kexec/arch/loongarch/crashdump-loongarch.h +@@ -8,6 +8,7 @@ extern struct memory_range elfcorehdr_mem; + + 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 --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 +diff --git a/kexec/arch/loongarch/kexec-elf-loongarch.c b/kexec/arch/loongarch/kexec-elf-loongarch.c +index 2bf128f..0ac451e 100644 +--- a/kexec/arch/loongarch/kexec-elf-loongarch.c ++++ b/kexec/arch/loongarch/kexec-elf-loongarch.c +@@ -90,6 +90,14 @@ int elf_loongarch_load(int argc, char **argv, const char *kernel_buf, + } + } + ++ /* 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 @@ int elf_loongarch_load(int argc, char **argv, const char *kernel_buf, + 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 --git a/kexec/arch/loongarch/kexec-loongarch.c b/kexec/arch/loongarch/kexec-loongarch.c +index 4c7361c..51f334a 100644 +--- a/kexec/arch/loongarch/kexec-loongarch.c ++++ b/kexec/arch/loongarch/kexec-loongarch.c +@@ -221,6 +221,10 @@ int arch_process_options(int argc, char **argv) + 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 loongarch_locate_kernel_segment(struct kexec_info *info) + 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 @@ unsigned long loongarch_locate_kernel_segment(struct kexec_info *info) + } 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 --git a/kexec/arch/loongarch/kexec-pei-loongarch.c b/kexec/arch/loongarch/kexec-pei-loongarch.c +index f86ac61..1a11103 100644 +--- a/kexec/arch/loongarch/kexec-pei-loongarch.c ++++ b/kexec/arch/loongarch/kexec-pei-loongarch.c +@@ -66,6 +66,13 @@ int pei_loongarch_load(int argc, char **argv, const char *buf, + + 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 --git a/kexec/kexec-syscall.h b/kexec/kexec-syscall.h +index be6ccd5..1e2d12f 100644 +--- a/kexec/kexec-syscall.h ++++ b/kexec/kexec-syscall.h +@@ -59,7 +59,7 @@ + #endif + #endif /*ifndef __NR_kexec_load*/ + +-#ifdef __arm__ ++#if defined(__arm__) || defined(__loongarch__) + #undef __NR_kexec_file_load + #endif + +-- +2.34.1 + -- Gitee