代码拉取完成,页面将自动刷新
同步操作将从 OpenCloudOS Stream/kexec-tools 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 1a4d3380e47de7959ac13baa99100ec92041f0de Mon Sep 17 00:00:00 2001
From: Pengda Dou <doupengda@loongson.cn>
Date: Mon, 25 Mar 2024 14:54:02 +0800
Subject: [PATCH] loongarch64 fix some functional issues and compilation
---
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..40e84e8 100644
--- a/kexec/kexec-syscall.h
+++ b/kexec/kexec-syscall.h
@@ -59,7 +59,7 @@
#endif
#endif /*ifndef __NR_kexec_load*/
-#ifdef __arm__
+#ifdef __arm__ || defined(__loongarch__)
#undef __NR_kexec_file_load
#endif
--
2.38.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。