Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] Kexec-tools: Improve RISC-V port
@ 2023-09-15  3:50 Song Shuai
  2023-09-15  3:50 ` [PATCH 1/7] RISC-V: Use linux,usable-memory-range for crash kernel Song Shuai
                   ` (8 more replies)
  0 siblings, 9 replies; 17+ messages in thread
From: Song Shuai @ 2023-09-15  3:50 UTC (permalink / raw)
  To: lizhengyu3, liaochang1, xianting.tian, guoren, horms, horms,
	huanyi.xj, mick, yixun.lan
  Cc: kexec, Song Shuai

Hi,

This series is created to improve RISC-V port of kexec-tools,
and is based on the horms/kexec-tools:build-test-riscv-v2 branch.

For your convenience, here is my Github branch for kexec-tools:
https://github.com/sugarfillet/kexec-tools/commits/rv-Image

The first four patches fixes some build or runtime issues:  

  RISC-V: Use linux,usable-memory-range for crash kernel
  RISC-V: Fix the undeclared ‘EM_RISCV’ build failure
  RISC-V: Get memory ranges from iomem
  RISC-V: Correct the usage of command line option

The last three patches enable the kexec_file_load syscall to load
vmlinux and support loading Image binary file for two syscalls.

  RISC-V: Enable kexe_file_load
  RISC-V: Separate elf_riscv_find_pbase out
  RISC-V: Support loading Image binary file

Note that: 

RISC-V Linux kexec_load_file's support for Image file has been sent out but not merged [1].

[1]: https://lore.kernel.org/linux-riscv/20230914020044.1397356-1-songshuaishuai@tinylab.org/T/#t 

Li Zhengyu (1):
  RISC-V: Enable kexe_file_load

Song Shuai (6):
  RISC-V: Use linux,usable-memory-range for crash kernel
  RISC-V: Fix the undeclared ‘EM_RISCV’ build failure
  RISC-V: Get memory ranges from iomem
  RISC-V: Correct the usage of command line option
  RISC-V: Separate elf_riscv_find_pbase out
  RISC-V: Support loading Image binary file

 kexec/arch/riscv/Makefile            |   2 +
 kexec/arch/riscv/crashdump-riscv.c   |   2 +-
 kexec/arch/riscv/image-header.h      |  88 ++++++++++++++
 kexec/arch/riscv/iomem.h             |  10 ++
 kexec/arch/riscv/kexec-elf-riscv.c   |  77 +-----------
 kexec/arch/riscv/kexec-image-riscv.c |  95 +++++++++++++++
 kexec/arch/riscv/kexec-riscv.c       | 176 ++++++++++++++++++++++-----
 kexec/arch/riscv/kexec-riscv.h       |  21 ++++
 kexec/kexec-syscall.h                |   3 +
 9 files changed, 368 insertions(+), 106 deletions(-)
 create mode 100644 kexec/arch/riscv/image-header.h
 create mode 100644 kexec/arch/riscv/iomem.h
 create mode 100644 kexec/arch/riscv/kexec-image-riscv.c

-- 
2.20.1


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/7] RISC-V: Use linux,usable-memory-range for crash kernel
  2023-09-15  3:50 [PATCH 0/7] Kexec-tools: Improve RISC-V port Song Shuai
@ 2023-09-15  3:50 ` Song Shuai
  2023-09-15  3:50 ` [PATCH 2/7] RISC-V: Fix the undeclared ‘EM_RISCV’ build failure Song Shuai
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Song Shuai @ 2023-09-15  3:50 UTC (permalink / raw)
  To: lizhengyu3, liaochang1, xianting.tian, guoren, horms, horms,
	huanyi.xj, mick, yixun.lan
  Cc: kexec, Song Shuai

Now we use "memeory::linux,usable-memory" to indicate the available
memory for the crash kernel.

While booting with UEFI, the crash kernel would use efi.memmap to
re-populate memblock and then first kernel's memory would be corrputed.
Consequently, the /proc/vmcore file failed to create in my local test.

And according to "chosen" dtschema [1], the available memory for the
crash kernel should be held via "chosen::linux,usable-memory-range"
property which will re-cap memblock even after UEFI's re-population.

[1]:
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/chosen.yaml

Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
 kexec/arch/riscv/kexec-riscv.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kexec/arch/riscv/kexec-riscv.c b/kexec/arch/riscv/kexec-riscv.c
index fe5dd2d..5aea035 100644
--- a/kexec/arch/riscv/kexec-riscv.c
+++ b/kexec/arch/riscv/kexec-riscv.c
@@ -79,20 +79,20 @@ int load_extra_segments(struct kexec_info *info, uint64_t kernel_base,
 		}
 
 		ret = dtb_add_range_property(&fdt->buf, &fdt->size, start, end,
-					     "memory", "linux,usable-memory");
+					     "chosen", "linux,usable-memory-range");
 		if (ret) {
-			fprintf(stderr, "Couldn't add usable-memory to fdt\n");
+			fprintf(stderr, "Couldn't add usable-memory-range to fdt\n");
 			return ret;
 		}
 
 		max_usable = end;
 	} else {
 		/*
-		 * Make sure we remove elfcorehdr and usable-memory
+		 * Make sure we remove elfcorehdr and usable-memory-range
 		 * when switching from crash kernel to a normal one.
 		 */
 		dtb_delete_property(fdt->buf, "chosen", "linux,elfcorehdr");
-		dtb_delete_property(fdt->buf, "memory", "linux,usable-memory");
+		dtb_delete_property(fdt->buf, "chosen", "linux,usable-memory-range");
 	}
 
 	/* Do we need to include an initrd image ? */
-- 
2.20.1


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/7] RISC-V: Fix the undeclared ‘EM_RISCV’ build failure
  2023-09-15  3:50 [PATCH 0/7] Kexec-tools: Improve RISC-V port Song Shuai
  2023-09-15  3:50 ` [PATCH 1/7] RISC-V: Use linux,usable-memory-range for crash kernel Song Shuai
@ 2023-09-15  3:50 ` Song Shuai
  2023-09-15  3:50 ` [PATCH 3/7] RISC-V: Get memory ranges from iomem Song Shuai
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Song Shuai @ 2023-09-15  3:50 UTC (permalink / raw)
  To: lizhengyu3, liaochang1, xianting.tian, guoren, horms, horms,
	huanyi.xj, mick, yixun.lan
  Cc: kexec, Song Shuai

Use local `elf.h` instead of `linux/elf.h` to fix this build error:

```
kexec/arch/riscv/crashdump-riscv.c:17:13: error: ‘EM_RISCV’ undeclared here (not in a function); did you mean ‘EM_CRIS’?
  .machine = EM_RISCV,
             ^~~~~~~~
             EM_CRIS
```

Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
 kexec/arch/riscv/crashdump-riscv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kexec/arch/riscv/crashdump-riscv.c b/kexec/arch/riscv/crashdump-riscv.c
index 3ed4fe3..336d7a7 100644
--- a/kexec/arch/riscv/crashdump-riscv.c
+++ b/kexec/arch/riscv/crashdump-riscv.c
@@ -1,5 +1,5 @@
 #include <errno.h>
-#include <linux/elf.h>
+#include <elf.h>
 #include <unistd.h>
 
 #include "kexec.h"
-- 
2.20.1


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/7] RISC-V: Get memory ranges from iomem
  2023-09-15  3:50 [PATCH 0/7] Kexec-tools: Improve RISC-V port Song Shuai
  2023-09-15  3:50 ` [PATCH 1/7] RISC-V: Use linux,usable-memory-range for crash kernel Song Shuai
  2023-09-15  3:50 ` [PATCH 2/7] RISC-V: Fix the undeclared ‘EM_RISCV’ build failure Song Shuai
@ 2023-09-15  3:50 ` Song Shuai
  2023-09-15  3:50 ` [PATCH 4/7] RISC-V: Correct the usage of command line option Song Shuai
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Song Shuai @ 2023-09-15  3:50 UTC (permalink / raw)
  To: lizhengyu3, liaochang1, xianting.tian, guoren, horms, horms,
	huanyi.xj, mick, yixun.lan
  Cc: kexec, Song Shuai

When booting with UEFI, Linux marks the Runtime Code/Data memory
as no-map and then exports it to "Reserved" iomem_resource.

Kexc-tools uses dtb_get_memory_ranges() function to get memory ranges
via parsing dtb, but it can't see the Reserved EFI Runtime memory.
That would corrupt EFI Runtime memory and fail the kexeced kernel to
deal EFI stuff.

In my test, the kexeced kernel warned "efi: System table signature incorrect!"
and then paniced at efi_call_rts() due to the null efi.runtime.

So we should use /proc/iomem to get memory ranges.

Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
 kexec/arch/riscv/iomem.h       | 10 +++++
 kexec/arch/riscv/kexec-riscv.c | 69 +++++++++++++++++++++-------------
 2 files changed, 53 insertions(+), 26 deletions(-)
 create mode 100644 kexec/arch/riscv/iomem.h

diff --git a/kexec/arch/riscv/iomem.h b/kexec/arch/riscv/iomem.h
new file mode 100644
index 0000000..7671e26
--- /dev/null
+++ b/kexec/arch/riscv/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/riscv/kexec-riscv.c b/kexec/arch/riscv/kexec-riscv.c
index 5aea035..a6f1b6f 100644
--- a/kexec/arch/riscv/kexec-riscv.c
+++ b/kexec/arch/riscv/kexec-riscv.c
@@ -15,6 +15,7 @@
 #include <errno.h>		/* For EINVAL */
 #include <libfdt.h>		/* For DeviceTree handling */
 #include "kexec-riscv.h"
+#include "iomem.h"
 
 const struct arch_map_entry arches[] = {
 	{ "riscv32", KEXEC_ARCH_RISCV },
@@ -37,7 +38,6 @@ static const char riscv_opts_usage[] =
 
 static struct riscv_opts arch_options = {0};
 static struct fdt_image provided_fdt = {0};
-static struct memory_ranges sysmem_ranges = {0};
 
 /****************\
 * COMMON HELPERS *
@@ -313,40 +313,57 @@ void arch_reuse_initrd(void)
 int get_memory_ranges(struct memory_range **range, int *num_ranges,
 		      unsigned long kexec_flags)
 {
-	const struct fdt_image *fdt = &provided_fdt;
-	struct memory_ranges *extra_ranges = NULL;
-	int i = 0;
+	struct memory_ranges sysmem_ranges = {0};
 	int ret = 0;
 
-	if (arch_options.initrd_start && arch_options.initrd_end) {
-		int initrd_size = arch_options.initrd_end - arch_options.initrd_start;
-		dbgprintf("Marking current intird image as reserved\n");
-		ret = mem_regions_alloc_and_add(extra_ranges,
-						arch_options.initrd_start,
-						initrd_size,
-						RANGE_RESERVED);
-		if (ret)
-			return ret;
+	const char *iomem = proc_iomem();
+	char line[MAX_LINE], *str;
+	FILE *fp;
+	unsigned long long start, end;
+	int consumed, count;
+
+	fp = fopen(iomem, "r");
+	if (!fp) {
+		fprintf(stderr, "Cannot open %s: %s\n", iomem, strerror(errno));
+		return -1;
 	}
 
-	ret = dtb_get_memory_ranges(fdt->buf, &sysmem_ranges, extra_ranges);
-	if (ret) {
-		fprintf(stderr, "Could not get memory ranges from device tree (%i) !\n", ret);
-		return ret;
+	while (fgets(line, sizeof(line), fp) != 0) {
+		count = sscanf(line, "%llx-%llx : %n", &start, &end, &consumed);
+		if (count != 2)
+			continue;
+		str = line + consumed;
+
+		if (!strncmp(str, SYSTEM_RAM, strlen(SYSTEM_RAM))){
+			ret = mem_regions_alloc_and_add(&sysmem_ranges,
+					start, end - start + 1, RANGE_RAM);
+			if (ret) {
+				fprintf(stderr,
+					"Cannot allocate memory for ranges\n");
+				fclose(fp);
+				return -ENOMEM;
+			}
+
+		} else if (!strncmp(str, IOMEM_RESERVED, strlen(IOMEM_RESERVED))){
+			ret = mem_regions_alloc_and_add(&sysmem_ranges,
+					start, end - start + 1, RANGE_RESERVED);
+			if (ret) {
+				fprintf(stderr,
+					"Cannot allocate memory for ranges\n");
+				fclose(fp);
+				return -ENOMEM;
+			}
+		} else
+			continue;
 	}
 
+	fclose(fp);
+
 	*range = sysmem_ranges.ranges;
 	*num_ranges = sysmem_ranges.size;
 
-	dbgprintf("Memory regions:\n");
-	for (i = 0; i < sysmem_ranges.size; i++) {
-		dbgprintf("\t0x%llx - 0x%llx : %s (%i)\n",
-			  sysmem_ranges.ranges[i].start,
-			  sysmem_ranges.ranges[i].end,
-			  sysmem_ranges.ranges[i].type == RANGE_RESERVED ?
-			  "RANGE_RESERVED" : "RANGE_RAM",
-			  sysmem_ranges.ranges[i].type);
-	}
+	dbgprint_mem_range("System RAM ranges;",
+				sysmem_ranges.ranges, sysmem_ranges.size);
 
 	return 0;
 }
-- 
2.20.1


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 4/7] RISC-V: Correct the usage of command line option
  2023-09-15  3:50 [PATCH 0/7] Kexec-tools: Improve RISC-V port Song Shuai
                   ` (2 preceding siblings ...)
  2023-09-15  3:50 ` [PATCH 3/7] RISC-V: Get memory ranges from iomem Song Shuai
@ 2023-09-15  3:50 ` Song Shuai
  2023-09-15  3:50 ` [PATCH 5/7] RISC-V: Enable kexe_file_load Song Shuai
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Song Shuai @ 2023-09-15  3:50 UTC (permalink / raw)
  To: lizhengyu3, liaochang1, xianting.tian, guoren, horms, horms,
	huanyi.xj, mick, yixun.lan
  Cc: kexec, Song Shuai

RISC-V process OPT_CMDLINE with the "command-line" partten,
but the riscv_opts_usage shows the "cmdline" option.
So correct the usage's output.

Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
 kexec/arch/riscv/kexec-riscv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kexec/arch/riscv/kexec-riscv.c b/kexec/arch/riscv/kexec-riscv.c
index a6f1b6f..00ae869 100644
--- a/kexec/arch/riscv/kexec-riscv.c
+++ b/kexec/arch/riscv/kexec-riscv.c
@@ -33,7 +33,7 @@ static const char riscv_opts_usage[] =
 "	--append=STRING		Append STRING to the kernel command line.\n"
 "	--dtb=FILE		Use FILE as the device tree blob.\n"
 "	--initrd=FILE		Use FILE as the kernel initial ramdisk.\n"
-"	--cmdline=STRING	Use STRING as the kernel's command line.\n"
+"	--command-line=STRING	Use STRING as the kernel's command line.\n"
 "	--reuse-cmdline		Use kernel command line from running system.\n";
 
 static struct riscv_opts arch_options = {0};
-- 
2.20.1


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 5/7] RISC-V: Enable kexe_file_load
  2023-09-15  3:50 [PATCH 0/7] Kexec-tools: Improve RISC-V port Song Shuai
                   ` (3 preceding siblings ...)
  2023-09-15  3:50 ` [PATCH 4/7] RISC-V: Correct the usage of command line option Song Shuai
@ 2023-09-15  3:50 ` Song Shuai
  2023-09-15  3:50 ` [PATCH 6/7] RISC-V: Separate elf_riscv_find_pbase out Song Shuai
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Song Shuai @ 2023-09-15  3:50 UTC (permalink / raw)
  To: lizhengyu3, liaochang1, xianting.tian, guoren, horms, horms,
	huanyi.xj, mick, yixun.lan
  Cc: kexec, Song Shuai

From: Li Zhengyu <lizhengyu3@huawei.com>

Create prepare_kexec_file_options() function to prepare the options
to kexec_file_load syscall, and it would be used in elf_riscv_load()
or the future image_riscv_load().

The patch comes from the RISC-V Linux kernel_file_load support[1],
So its author should be Li Zhengyu.

[1]: https://lore.kernel.org/all/20220408100914.150110-1-lizhengyu3@huawei.com/

Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
 kexec/arch/riscv/kexec-elf-riscv.c |  5 ++--
 kexec/arch/riscv/kexec-riscv.c     | 41 ++++++++++++++++++++++++++++++
 kexec/arch/riscv/kexec-riscv.h     |  1 +
 kexec/kexec-syscall.h              |  3 +++
 4 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/kexec/arch/riscv/kexec-elf-riscv.c b/kexec/arch/riscv/kexec-elf-riscv.c
index f3c011c..2b9f66d 100644
--- a/kexec/arch/riscv/kexec-elf-riscv.c
+++ b/kexec/arch/riscv/kexec-elf-riscv.c
@@ -112,6 +112,7 @@ void elf_riscv_usage(void)
 {
 }
 
+
 int elf_riscv_load(int argc, char **argv, const char *buf, off_t len,
 		   struct kexec_info *info)
 {
@@ -127,9 +128,7 @@ int elf_riscv_load(int argc, char **argv, const char *buf, off_t len,
 	int ret = 0;
 
 	if (info->file_mode) {
-		fprintf(stderr, "kexec_file not supported on this "
-				"architecture\n");
-		return -EINVAL;
+		return prepare_kexec_file_options(info);
 	}
 
 	/* Parse the ELF file */
diff --git a/kexec/arch/riscv/kexec-riscv.c b/kexec/arch/riscv/kexec-riscv.c
index 00ae869..4500aa9 100644
--- a/kexec/arch/riscv/kexec-riscv.c
+++ b/kexec/arch/riscv/kexec-riscv.c
@@ -16,6 +16,14 @@
 #include <libfdt.h>		/* For DeviceTree handling */
 #include "kexec-riscv.h"
 #include "iomem.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#ifndef _O_BINARY
+#define _O_BINARY 0
+#endif
+
+
 
 const struct arch_map_entry arches[] = {
 	{ "riscv32", KEXEC_ARCH_RISCV },
@@ -141,6 +149,39 @@ void arch_usage(void)
 	printf(riscv_opts_usage);
 }
 
+int prepare_kexec_file_options(struct kexec_info *info)
+{
+	int fd;
+	ssize_t result;
+	struct stat stats;
+
+	if (arch_options.cmdline) {
+		info->command_line = (char *)arch_options.cmdline;
+		info->command_line_len = strlen(info->command_line) + 1;
+	}
+
+	if (!arch_options.initrd_path) {
+		info->initrd_fd = -1;
+		return 0;
+	}
+
+	fd = open(arch_options.initrd_path, O_RDONLY | _O_BINARY);
+	if (fd < 0) {
+		fprintf(stderr, "Cannot open `%s': %s\n", arch_options.initrd_path,
+				strerror(errno));
+		return -EINVAL;
+	}
+	result = fstat(fd, &stats);
+	if (result < 0) {
+		close(fd);
+		fprintf(stderr, "Cannot stat: %s: %s\n", arch_options.initrd_path,
+				strerror(errno));
+		return -EINVAL;
+	}
+	info->initrd_fd = fd;
+	return 0;
+}
+
 int arch_process_options(int argc, char **argv)
 {
 	static const struct option options[] = {
diff --git a/kexec/arch/riscv/kexec-riscv.h b/kexec/arch/riscv/kexec-riscv.h
index c4323a6..f136c7e 100644
--- a/kexec/arch/riscv/kexec-riscv.h
+++ b/kexec/arch/riscv/kexec-riscv.h
@@ -23,6 +23,7 @@ extern struct memory_range elfcorehdr_mem;
 int load_elfcorehdr(struct kexec_info *info);
 
 /* kexec-riscv.c */
+int prepare_kexec_file_options(struct kexec_info *info);
 int load_extra_segments(struct kexec_info *info, uint64_t kernel_base,
 			uint64_t kernel_size, uint64_t max_addr);
 
diff --git a/kexec/kexec-syscall.h b/kexec/kexec-syscall.h
index 4cdae84..2310b98 100644
--- a/kexec/kexec-syscall.h
+++ b/kexec/kexec-syscall.h
@@ -80,6 +80,9 @@
 #ifdef __hppa__
 #define __NR_kexec_file_load	355
 #endif
+#if defined(__riscv__) || defined(__riscv)
+#define __NR_kexec_file_load	294
+#endif
 
 #ifndef __NR_kexec_file_load
 /* system call not available for the arch */
-- 
2.20.1


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 6/7] RISC-V: Separate elf_riscv_find_pbase out
  2023-09-15  3:50 [PATCH 0/7] Kexec-tools: Improve RISC-V port Song Shuai
                   ` (4 preceding siblings ...)
  2023-09-15  3:50 ` [PATCH 5/7] RISC-V: Enable kexe_file_load Song Shuai
@ 2023-09-15  3:50 ` Song Shuai
  2023-09-15  3:50 ` [PATCH 7/7] RISC-V: Support loading Image binary file Song Shuai
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Song Shuai @ 2023-09-15  3:50 UTC (permalink / raw)
  To: lizhengyu3, liaochang1, xianting.tian, guoren, horms, horms,
	huanyi.xj, mick, yixun.lan
  Cc: kexec, Song Shuai

The is the preparative patch for RISC-V kexec Image file support.

Separate the elf_riscv_find_pbase() function out to
allow kernel_load syscall load Image binary file.

Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
 kexec/arch/riscv/kexec-elf-riscv.c | 72 +-----------------------------
 kexec/arch/riscv/kexec-riscv.c     | 55 +++++++++++++++++++++++
 kexec/arch/riscv/kexec-riscv.h     | 13 ++++++
 3 files changed, 69 insertions(+), 71 deletions(-)

diff --git a/kexec/arch/riscv/kexec-elf-riscv.c b/kexec/arch/riscv/kexec-elf-riscv.c
index 2b9f66d..49deedb 100644
--- a/kexec/arch/riscv/kexec-elf-riscv.c
+++ b/kexec/arch/riscv/kexec-elf-riscv.c
@@ -12,76 +12,6 @@
 #include "kexec-syscall.h"	/* For KEXEC_ON_CRASH */
 #include "kexec-riscv.h"
 
-
-/*********\
-* HELPERS *
-\*********/
-
-/*
- * Go through the available physical memory regions and
- * find one that can hold an image of the specified size.
- * Note: This is called after get_memory_ranges so
- * info->memory_range[] should be populated. Also note that
- * memory ranges are sorted, so we'll return the first region
- * that's big enough for holding the image.
- */
-static int elf_riscv_find_pbase(struct kexec_info *info, off_t *addr,
-				off_t size)
-{
-	int i = 0;
-	off_t start = 0;
-	off_t end = 0;
-	int ret = 0;
-
-	/*
-	 * If this image is for a crash kernel, use the region
-	 * the primary kernel has already reserved for us.
-	 */
-	if (info->kexec_flags & KEXEC_ON_CRASH) {
-		ret = get_crash_kernel_load_range((uint64_t *) &start,
-						  (uint64_t *) &end);
-		if (!ret) {
-			/*
-			 * Kernel should be aligned to the nearest
-			 * hugepage (2MB for RV64, 4MB for RV32).
-			 */
-#if __riscv_xlen == 64
-			start = _ALIGN_UP(start, 0x200000);
-#else
-			start = _ALIGN_UP(start, 0x400000);
-#endif
-			if (end > start && ((end - start) >= size)) {
-				*addr = start;
-				return 0;
-			}
-
-			return -EFBIG;
-		} else
-			return ENOCRASHKERNEL;
-	}
-
-	for (i = 0; i < info->memory_ranges; i++) {
-		if (info->memory_range[i].type != RANGE_RAM)
-			continue;
-
-		start = info->memory_range[i].start;
-		end = info->memory_range[i].end;
-
-#if __riscv_xlen == 64
-		start = _ALIGN_UP(start, 0x200000);
-#else
-		start = _ALIGN_UP(start, 0x400000);
-#endif
-
-		if (end > start && ((end - start) >= size)) {
-			*addr = start;
-			return 0;
-		}
-	}
-
-	return -EFBIG;
-}
-
 /**************\
 * ENTRY POINTS *
 \**************/
@@ -182,7 +112,7 @@ int elf_riscv_load(int argc, char **argv, const char *buf, off_t len,
 		  kernel_size / 1024, old_base_addr, old_start_addr);
 
 	/* Get a continuous physical region that can hold the kernel */
-	ret = elf_riscv_find_pbase(info, &new_base_addr, kernel_size);
+	ret = elf_riscv_find_pbase(info, &new_base_addr, kernel_size, KERNEL_ALIGN);
 	if (ret < 0) {
 		fprintf(stderr, "Could not find a memory region for the "
 				"provided ELF image\n");
diff --git a/kexec/arch/riscv/kexec-riscv.c b/kexec/arch/riscv/kexec-riscv.c
index 4500aa9..74feef2 100644
--- a/kexec/arch/riscv/kexec-riscv.c
+++ b/kexec/arch/riscv/kexec-riscv.c
@@ -51,6 +51,61 @@ static struct fdt_image provided_fdt = {0};
 * COMMON HELPERS *
 \****************/
 
+/*
+ * Go through the available physical memory regions and
+ * find one that can hold an image of the specified size
+ * and start address should be aligned up with `align`.
+ * Note: This is called after get_memory_ranges so
+ * info->memory_range[] should be populated. Also note that
+ * memory ranges are sorted, so we'll return the first region
+ * that's big enough for holding the image.
+ */
+int elf_riscv_find_pbase(struct kexec_info *info, off_t *addr,
+				off_t size, off_t align)
+{
+	int i = 0;
+	off_t start = 0;
+	off_t end = 0;
+	int ret = 0;
+
+	/*
+	 * If this image is for a crash kernel, use the region
+	 * the primary kernel has already reserved for us.
+	 */
+	if (info->kexec_flags & KEXEC_ON_CRASH) {
+		ret = get_crash_kernel_load_range((uint64_t *) &start,
+						  (uint64_t *) &end);
+		if (!ret) {
+			start = _ALIGN_UP(start, align);
+
+			if (end > start && ((end - start) >= size)) {
+				*addr = start;
+				return 0;
+			}
+
+			return -EFBIG;
+		} else
+			return ENOCRASHKERNEL;
+	}
+
+	for (i = 0; i < info->memory_ranges; i++) {
+		if (info->memory_range[i].type != RANGE_RAM)
+			continue;
+
+		start = info->memory_range[i].start;
+		end = info->memory_range[i].end;
+
+		start = _ALIGN_UP(start, align);
+
+		if (end > start && ((end - start) >= size)) {
+			*addr = start;
+			return 0;
+		}
+	}
+
+	return -EFBIG;
+}
+
 int load_extra_segments(struct kexec_info *info, uint64_t kernel_base,
 			uint64_t kernel_size, uint64_t max_addr)
 {
diff --git a/kexec/arch/riscv/kexec-riscv.h b/kexec/arch/riscv/kexec-riscv.h
index f136c7e..233b137 100644
--- a/kexec/arch/riscv/kexec-riscv.h
+++ b/kexec/arch/riscv/kexec-riscv.h
@@ -4,6 +4,17 @@
  *              Nick Kossifidis <mick@ics.forth.gr>
  */
 
+/*
+ * Kernel should be aligned to the nearest
+ * hugepage (2MB for RV64, 4MB for RV32).
+ */
+
+#if __riscv_xlen == 64
+#define KERNEL_ALIGN 0x200000
+#else
+#define KERNEL_ALIGN 0x400000
+#endif
+
 struct fdt_image {
 	char	*buf;
 	off_t	size;
@@ -26,6 +37,8 @@ int load_elfcorehdr(struct kexec_info *info);
 int prepare_kexec_file_options(struct kexec_info *info);
 int load_extra_segments(struct kexec_info *info, uint64_t kernel_base,
 			uint64_t kernel_size, uint64_t max_addr);
+int elf_riscv_find_pbase(struct kexec_info *info, off_t *addr,
+				off_t size, off_t align);
 
 int elf_riscv_probe(const char *buf, off_t len);
 void elf_riscv_usage(void);
-- 
2.20.1


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 7/7] RISC-V: Support loading Image binary file
  2023-09-15  3:50 [PATCH 0/7] Kexec-tools: Improve RISC-V port Song Shuai
                   ` (5 preceding siblings ...)
  2023-09-15  3:50 ` [PATCH 6/7] RISC-V: Separate elf_riscv_find_pbase out Song Shuai
@ 2023-09-15  3:50 ` Song Shuai
  2023-09-20 11:56 ` [PATCH 0/7] Kexec-tools: Improve RISC-V port Simon Horman
  2023-09-20 13:47 ` Nick Kossifidis
  8 siblings, 0 replies; 17+ messages in thread
From: Song Shuai @ 2023-09-15  3:50 UTC (permalink / raw)
  To: lizhengyu3, liaochang1, xianting.tian, guoren, horms, horms,
	huanyi.xj, mick, yixun.lan
  Cc: kexec, Song Shuai

Add image-riscv file_type to probe/load Image file type,

As for kexec_load, find the pbase aligned text_offset from image header
and prepare segments for this syscall.

for kexec_file_load, setup the related options and let kernel part to
deal with the Image.

Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
 kexec/arch/riscv/Makefile            |  2 +
 kexec/arch/riscv/image-header.h      | 88 ++++++++++++++++++++++++++
 kexec/arch/riscv/kexec-image-riscv.c | 95 ++++++++++++++++++++++++++++
 kexec/arch/riscv/kexec-riscv.c       |  1 +
 kexec/arch/riscv/kexec-riscv.h       |  7 ++
 5 files changed, 193 insertions(+)
 create mode 100644 kexec/arch/riscv/image-header.h
 create mode 100644 kexec/arch/riscv/kexec-image-riscv.c

diff --git a/kexec/arch/riscv/Makefile b/kexec/arch/riscv/Makefile
index f26cc90..37ef760 100644
--- a/kexec/arch/riscv/Makefile
+++ b/kexec/arch/riscv/Makefile
@@ -3,6 +3,7 @@
 #
 riscv_KEXEC_SRCS =  kexec/arch/riscv/kexec-riscv.c
 riscv_KEXEC_SRCS += kexec/arch/riscv/kexec-elf-riscv.c
+riscv_KEXEC_SRCS += kexec/arch/riscv/kexec-image-riscv.c
 riscv_KEXEC_SRCS += kexec/arch/riscv/crashdump-riscv.c
 
 riscv_MEM_REGIONS = kexec/mem_regions.c
@@ -15,6 +16,7 @@ riscv_CPPFLAGS += -I $(srcdir)/kexec/
 
 dist += kexec/arch/riscv/Makefile $(riscv_KEXEC_SRCS)			\
 	kexec/arch/riscv/kexec-riscv.h					\
+	kexec/arch/riscv/image-header.h					\
 	kexec/arch/riscv/include/arch/options.h
 
 ifdef HAVE_LIBFDT
diff --git a/kexec/arch/riscv/image-header.h b/kexec/arch/riscv/image-header.h
new file mode 100644
index 0000000..a677546
--- /dev/null
+++ b/kexec/arch/riscv/image-header.h
@@ -0,0 +1,88 @@
+/*
+ * RISCV64 binary image header.
+ * token from arm64/image-header.h
+ */
+
+#if !defined(__RISCV_IMAGE_HEADER_H)
+#define __RISCV_IMAGE_HEADER_H
+
+#include <endian.h>
+#include <stdint.h>
+
+/**
+ * struct riscv_image_header - riscv kernel image header.
+ *
+ **/
+struct riscv_image_header {
+        uint32_t code0;
+        uint32_t code1;
+        uint64_t text_offset;
+        uint64_t image_size;
+        uint64_t flags;
+        uint32_t version;
+        uint32_t res1;
+        uint64_t res2;
+        uint64_t magic;
+        uint32_t magic2;
+        uint32_t res3;
+};
+
+#define RISCV_IMAGE_MAGIC       0x5643534952
+#define RISCV_IMAGE_MAGIC2      0x05435352
+
+#define RISCV_HEADER_VERSION_MAJOR 0
+#define RISCV_HEADER_VERSION_MINOR 2
+
+#define RISCV_HEADER_VERSION (RISCV_HEADER_VERSION_MAJOR << 16 | \
+		                              RISCV_HEADER_VERSION_MINOR)
+
+
+static const uint64_t riscv_image_flag_be = (1UL << 0);
+
+/**
+ * riscv_header_check_magic - Helper to check the riscv image header.
+ *
+ * Returns non-zero if header is OK.
+ */
+
+static inline int riscv_header_check_magic(const struct riscv_image_header *h)
+{
+	if (!h)
+		return 0;
+
+	return (h->version >= RISCV_HEADER_VERSION && h->magic2 == RISCV_IMAGE_MAGIC2);
+}
+
+/**
+ * riscv_header_check_endiannes - Helper to check the riscv image header.
+ *
+ * Returns non-zero if the image was built as big endian.
+ */
+
+static inline int riscv_header_check_endiannes(const struct riscv_image_header *h)
+{
+	if (!h)
+		return 0;
+
+	return (le64toh(h->flags) & riscv_image_flag_be) >> 0;
+}
+
+
+
+static inline uint64_t riscv_header_text_offset(const struct riscv_image_header *h)
+{
+	if (!h)
+		return 0;
+
+	return le64toh(h->text_offset);
+}
+
+static inline uint64_t riscv_header_image_size(const struct riscv_image_header *h)
+{
+	if (!h)
+		return 0;
+
+	return le64toh(h->image_size);
+}
+
+#endif
diff --git a/kexec/arch/riscv/kexec-image-riscv.c b/kexec/arch/riscv/kexec-image-riscv.c
new file mode 100644
index 0000000..8e0654c
--- /dev/null
+++ b/kexec/arch/riscv/kexec-image-riscv.c
@@ -0,0 +1,95 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * RISC-V kexec binary image support.
+ *
+ * Author: Song Shuai <songhshuaishuai@tinylab.org>
+ */
+
+#define _GNU_SOURCE
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include "image-header.h"
+#include "kexec.h"
+#include "kexec-riscv.h"
+#include "kexec-syscall.h"
+#include "arch/options.h"
+
+int image_riscv_probe(const char *kernel_buf, off_t kernel_size)
+{
+	const struct riscv_image_header *h;
+
+	if (kernel_size < sizeof(struct riscv_image_header)) {
+		dbgprintf("%s: No riscv image header.\n", __func__);
+		return -1;
+	}
+
+	h = (const struct riscv_image_header *)(kernel_buf);
+
+	if (!riscv_header_check_magic(h)) {
+		dbgprintf("%s: Bad riscv image header.\n", __func__);
+		return -1;
+	}
+
+	return 0;
+}
+
+int image_riscv_load(int argc, char **argv, const char *kernel_buf,
+	off_t kernel_size, struct kexec_info *info)
+{
+	const struct riscv_image_header *h;
+	unsigned long text_offset, image_size;
+	off_t new_base_addr = 0;
+
+	int ret;
+
+	if (info->file_mode) {
+		return prepare_kexec_file_options(info);
+	}
+
+	h = (const struct riscv_image_header *)(kernel_buf);
+
+	/* Check header */
+	if (!h->image_size){
+		dbgprintf("Kernel image size is NULL\n");
+		ret = EFAILED;
+		goto exit;
+	}
+
+	if(riscv_header_check_endiannes(h)){
+		dbgprintf("Kernel image was built as big endian\n");
+		ret = EFAILED;
+		goto exit;
+	}
+
+	text_offset = riscv_header_text_offset(h);
+	image_size = riscv_header_image_size(h);
+
+	/* Setup the entry and segments */
+
+	ret = elf_riscv_find_pbase(info, &new_base_addr, image_size, text_offset);
+	if (ret < 0) {
+		fprintf(stderr, "Could not find a memory region for the "
+				"provided Image\n");
+		goto exit;
+	}
+
+	info->entry = (void *) new_base_addr;
+	dbgprintf("Entry point for the Image: 0x%lX\n", new_base_addr);
+
+	add_segment(info, kernel_buf, kernel_size, new_base_addr, image_size);
+
+	ret = load_extra_segments(info, text_offset, image_size, ULONG_MAX);
+exit:
+        if (ret)
+                fprintf(stderr, "kexec: load failed.\n");
+        return ret;
+}
+
+void image_riscv_usage(void)
+{
+	printf(
+"     An RISC-V binary image, uncompressed, little endian.\n"
+"     Typically an Image file.\n\n");
+}
diff --git a/kexec/arch/riscv/kexec-riscv.c b/kexec/arch/riscv/kexec-riscv.c
index 74feef2..9536a95 100644
--- a/kexec/arch/riscv/kexec-riscv.c
+++ b/kexec/arch/riscv/kexec-riscv.c
@@ -34,6 +34,7 @@ const struct arch_map_entry arches[] = {
 
 struct file_type file_type[] = {
 	{"elf-riscv", elf_riscv_probe, elf_riscv_load, elf_riscv_usage},
+	{"image-riscv", image_riscv_probe, image_riscv_load, image_riscv_usage},
 };
 int file_types = sizeof(file_type) / sizeof(file_type[0]);
 
diff --git a/kexec/arch/riscv/kexec-riscv.h b/kexec/arch/riscv/kexec-riscv.h
index 233b137..324a251 100644
--- a/kexec/arch/riscv/kexec-riscv.h
+++ b/kexec/arch/riscv/kexec-riscv.h
@@ -40,7 +40,14 @@ int load_extra_segments(struct kexec_info *info, uint64_t kernel_base,
 int elf_riscv_find_pbase(struct kexec_info *info, off_t *addr,
 				off_t size, off_t align);
 
+/* kexec-elf-riscv.c */
 int elf_riscv_probe(const char *buf, off_t len);
 void elf_riscv_usage(void);
 int elf_riscv_load(int argc, char **argv, const char *buf, off_t len,
 		   struct kexec_info *info);
+
+/* kexec-image-riscv.c */
+int image_riscv_probe(const char *buf, off_t len);
+void image_riscv_usage(void);
+int image_riscv_load(int argc, char **argv, const char *buf, off_t len,
+		   struct kexec_info *info);
-- 
2.20.1


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/7] Kexec-tools: Improve RISC-V port
  2023-09-15  3:50 [PATCH 0/7] Kexec-tools: Improve RISC-V port Song Shuai
                   ` (6 preceding siblings ...)
  2023-09-15  3:50 ` [PATCH 7/7] RISC-V: Support loading Image binary file Song Shuai
@ 2023-09-20 11:56 ` Simon Horman
  2023-10-11  5:22   ` Song Shuai
  2023-09-20 13:47 ` Nick Kossifidis
  8 siblings, 1 reply; 17+ messages in thread
From: Simon Horman @ 2023-09-20 11:56 UTC (permalink / raw)
  To: Song Shuai
  Cc: lizhengyu3, liaochang1, xianting.tian, guoren, huanyi.xj, mick,
	yixun.lan, kexec

On Fri, Sep 15, 2023 at 11:50:06AM +0800, Song Shuai wrote:
> Hi,
> 
> This series is created to improve RISC-V port of kexec-tools,
> and is based on the horms/kexec-tools:build-test-riscv-v2 branch.

In my mind the big question is how to move RISC-V support
from that branch, to being merged into main.

IIRC there were some issues that needed to be addressed.
Perhaps they are all addressed by this series, and with
some appropriate squashing we can move forwards with a series
based on main?

> 
> For your convenience, here is my Github branch for kexec-tools:
> https://github.com/sugarfillet/kexec-tools/commits/rv-Image
> 
> The first four patches fixes some build or runtime issues:  
> 
>   RISC-V: Use linux,usable-memory-range for crash kernel
>   RISC-V: Fix the undeclared ‘EM_RISCV’ build failure
>   RISC-V: Get memory ranges from iomem
>   RISC-V: Correct the usage of command line option
> 
> The last three patches enable the kexec_file_load syscall to load
> vmlinux and support loading Image binary file for two syscalls.
> 
>   RISC-V: Enable kexe_file_load
>   RISC-V: Separate elf_riscv_find_pbase out
>   RISC-V: Support loading Image binary file
> 
> Note that: 
> 
> RISC-V Linux kexec_load_file's support for Image file has been sent out but not merged [1].
> 
> [1]: https://lore.kernel.org/linux-riscv/20230914020044.1397356-1-songshuaishuai@tinylab.org/T/#t 
> 
> Li Zhengyu (1):
>   RISC-V: Enable kexe_file_load
> 
> Song Shuai (6):
>   RISC-V: Use linux,usable-memory-range for crash kernel
>   RISC-V: Fix the undeclared ‘EM_RISCV’ build failure
>   RISC-V: Get memory ranges from iomem
>   RISC-V: Correct the usage of command line option
>   RISC-V: Separate elf_riscv_find_pbase out
>   RISC-V: Support loading Image binary file
> 
>  kexec/arch/riscv/Makefile            |   2 +
>  kexec/arch/riscv/crashdump-riscv.c   |   2 +-
>  kexec/arch/riscv/image-header.h      |  88 ++++++++++++++
>  kexec/arch/riscv/iomem.h             |  10 ++
>  kexec/arch/riscv/kexec-elf-riscv.c   |  77 +-----------
>  kexec/arch/riscv/kexec-image-riscv.c |  95 +++++++++++++++
>  kexec/arch/riscv/kexec-riscv.c       | 176 ++++++++++++++++++++++-----
>  kexec/arch/riscv/kexec-riscv.h       |  21 ++++
>  kexec/kexec-syscall.h                |   3 +
>  9 files changed, 368 insertions(+), 106 deletions(-)
>  create mode 100644 kexec/arch/riscv/image-header.h
>  create mode 100644 kexec/arch/riscv/iomem.h
>  create mode 100644 kexec/arch/riscv/kexec-image-riscv.c
> 
> -- 
> 2.20.1
> 

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/7] Kexec-tools: Improve RISC-V port
  2023-09-15  3:50 [PATCH 0/7] Kexec-tools: Improve RISC-V port Song Shuai
                   ` (7 preceding siblings ...)
  2023-09-20 11:56 ` [PATCH 0/7] Kexec-tools: Improve RISC-V port Simon Horman
@ 2023-09-20 13:47 ` Nick Kossifidis
  8 siblings, 0 replies; 17+ messages in thread
From: Nick Kossifidis @ 2023-09-20 13:47 UTC (permalink / raw)
  To: Song Shuai, lizhengyu3, liaochang1, xianting.tian, guoren, horms,
	horms, huanyi.xj, yixun.lan
  Cc: kexec

On 9/15/23 06:50, Song Shuai wrote:
> Hi,
> 
> This series is created to improve RISC-V port of kexec-tools,
> and is based on the horms/kexec-tools:build-test-riscv-v2 branch.
> 
> For your convenience, here is my Github branch for kexec-tools:
> https://github.com/sugarfillet/kexec-tools/commits/rv-Image
> 
> The first four patches fixes some build or runtime issues:
> 
>    RISC-V: Use linux,usable-memory-range for crash kernel
>    RISC-V: Fix the undeclared ‘EM_RISCV’ build failure
>    RISC-V: Get memory ranges from iomem
>    RISC-V: Correct the usage of command line option
> 
> The last three patches enable the kexec_file_load syscall to load
> vmlinux and support loading Image binary file for two syscalls.
> 
>    RISC-V: Enable kexe_file_load
>    RISC-V: Separate elf_riscv_find_pbase out
>    RISC-V: Support loading Image binary file
> 

A few years back I did the initial work for kexec on riscv, and the idea 
was to work on the kexec-tools repo on riscv github:

https://github.com/riscv-collab/kexec-tools/tree/riscv

and then when we have something in a good shape, to push our work 
upstream. People keep sending patches to the kexec mailing list (the 
riscv port of kexec-tools is not upstream so this patch series won't 
apply), instead of pull requests to the above repo.

You have an X set of updates, some other people have posted another set 
of fixes (e.g. I rememver a fix for initramfs/initrd), please let's work 
on the github repo, get something that looks ok and then push our work 
upstream. If you want access to the github repo instead of doing pull 
requests etc let me know.

I'm sorry I didn't have the time to work on this further.

Regards,
Nick

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/7] Kexec-tools: Improve RISC-V port
  2023-09-20 11:56 ` [PATCH 0/7] Kexec-tools: Improve RISC-V port Simon Horman
@ 2023-10-11  5:22   ` Song Shuai
  2024-05-18  3:39     ` Dave Young
  0 siblings, 1 reply; 17+ messages in thread
From: Song Shuai @ 2023-10-11  5:22 UTC (permalink / raw)
  To: Simon Horman, mick
  Cc: lizhengyu3, liaochang1, xianting.tian, guoren, huanyi.xj,
	yixun.lan, kexec



在 2023/9/20 19:56, Simon Horman 写道:
> On Fri, Sep 15, 2023 at 11:50:06AM +0800, Song Shuai wrote:
>> Hi,
>>
>> This series is created to improve RISC-V port of kexec-tools,
>> and is based on the horms/kexec-tools:build-test-riscv-v2 branch.
> 
> In my mind the big question is how to move RISC-V support
> from that branch, to being merged into main.
> 
> IIRC there were some issues that needed to be addressed.
> Perhaps they are all addressed by this series, and with
> some appropriate squashing we can move forwards with a series
> based on main?

Hi, Simon and Nick:

I squashed the first four patches as a "RISC-V: Some fixes for riscv 
port" patch and then took the horms/main as the base to collect the 2 
patches from horms/build-test-riscv-v2 branch and this series togother. 
These are the Github link and all commits for RISC-V.

https://github.com/sugarfillet/kexec-tools/commits/main_rv

5dc133e RISC-V: Support loading Image binary file
b042f6d RISC-V: Separate elf_riscv_find_pbase out
8f344c7 RISC-V: Enable kexec_file_load syscall
7d4b982 RISC-V: Some fixes for riscv port
3205c1c local: RISC-V: distribute purgatory/riscv/Makefile
54f9daf RISC-V: Add support for riscv kexec/kdump on kexec-tools

Since I didn't found the issues/fixes as Nick mentioned with these 
commits, I prefer to merge them into horms/main and let more kexec/kdump 
users to help improve/fixup RISC-V port.

I would like to listen to your advice.

> 
>>
>> For your convenience, here is my Github branch for kexec-tools:
>> https://github.com/sugarfillet/kexec-tools/commits/rv-Image
>>
>> The first four patches fixes some build or runtime issues:
>>
>>    RISC-V: Use linux,usable-memory-range for crash kernel
>>    RISC-V: Fix the undeclared ‘EM_RISCV’ build failure
>>    RISC-V: Get memory ranges from iomem
>>    RISC-V: Correct the usage of command line option
>>
>> The last three patches enable the kexec_file_load syscall to load
>> vmlinux and support loading Image binary file for two syscalls.
>>
>>    RISC-V: Enable kexe_file_load
>>    RISC-V: Separate elf_riscv_find_pbase out
>>    RISC-V: Support loading Image binary file
>>
>> Note that:
>>
>> RISC-V Linux kexec_load_file's support for Image file has been sent out but not merged [1].
>>
>> [1]: https://lore.kernel.org/linux-riscv/20230914020044.1397356-1-songshuaishuai@tinylab.org/T/#t
>>
>> Li Zhengyu (1):
>>    RISC-V: Enable kexe_file_load
>>
>> Song Shuai (6):
>>    RISC-V: Use linux,usable-memory-range for crash kernel
>>    RISC-V: Fix the undeclared ‘EM_RISCV’ build failure
>>    RISC-V: Get memory ranges from iomem
>>    RISC-V: Correct the usage of command line option
>>    RISC-V: Separate elf_riscv_find_pbase out
>>    RISC-V: Support loading Image binary file
>>
>>   kexec/arch/riscv/Makefile            |   2 +
>>   kexec/arch/riscv/crashdump-riscv.c   |   2 +-
>>   kexec/arch/riscv/image-header.h      |  88 ++++++++++++++
>>   kexec/arch/riscv/iomem.h             |  10 ++
>>   kexec/arch/riscv/kexec-elf-riscv.c   |  77 +-----------
>>   kexec/arch/riscv/kexec-image-riscv.c |  95 +++++++++++++++
>>   kexec/arch/riscv/kexec-riscv.c       | 176 ++++++++++++++++++++++-----
>>   kexec/arch/riscv/kexec-riscv.h       |  21 ++++
>>   kexec/kexec-syscall.h                |   3 +
>>   9 files changed, 368 insertions(+), 106 deletions(-)
>>   create mode 100644 kexec/arch/riscv/image-header.h
>>   create mode 100644 kexec/arch/riscv/iomem.h
>>   create mode 100644 kexec/arch/riscv/kexec-image-riscv.c
>>
>> -- 
>> 2.20.1
>>
> 

-- 
Thanks
Song Shuai

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/7] Kexec-tools: Improve RISC-V port
  2023-10-11  5:22   ` Song Shuai
@ 2024-05-18  3:39     ` Dave Young
  2024-05-18  8:33       ` Simon Horman
  0 siblings, 1 reply; 17+ messages in thread
From: Dave Young @ 2024-05-18  3:39 UTC (permalink / raw)
  To: Song Shuai
  Cc: Simon Horman, mick, lizhengyu3, liaochang1, xianting.tian, guoren,
	huanyi.xj, yixun.lan, kexec, hursand

On Wed, 11 Oct 2023 at 13:24, Song Shuai <songshuaishuai@tinylab.org> wrote:
>
>
>
> 在 2023/9/20 19:56, Simon Horman 写道:
> > On Fri, Sep 15, 2023 at 11:50:06AM +0800, Song Shuai wrote:
> >> Hi,
> >>
> >> This series is created to improve RISC-V port of kexec-tools,
> >> and is based on the horms/kexec-tools:build-test-riscv-v2 branch.
> >
> > In my mind the big question is how to move RISC-V support
> > from that branch, to being merged into main.
> >
> > IIRC there were some issues that needed to be addressed.
> > Perhaps they are all addressed by this series, and with
> > some appropriate squashing we can move forwards with a series
> > based on main?
>
> Hi, Simon and Nick:
>
> I squashed the first four patches as a "RISC-V: Some fixes for riscv
> port" patch and then took the horms/main as the base to collect the 2
> patches from horms/build-test-riscv-v2 branch and this series togother.
> These are the Github link and all commits for RISC-V.
>
> https://github.com/sugarfillet/kexec-tools/commits/main_rv
>
> 5dc133e RISC-V: Support loading Image binary file
> b042f6d RISC-V: Separate elf_riscv_find_pbase out
> 8f344c7 RISC-V: Enable kexec_file_load syscall
> 7d4b982 RISC-V: Some fixes for riscv port
> 3205c1c local: RISC-V: distribute purgatory/riscv/Makefile
> 54f9daf RISC-V: Add support for riscv kexec/kdump on kexec-tools
>
> Since I didn't found the issues/fixes as Nick mentioned with these
> commits, I prefer to merge them into horms/main and let more kexec/kdump
> users to help improve/fixup RISC-V port.

Hi,  I noticed another pr for Fedora kexec-tools:
https://src.fedoraproject.org/rpms/kexec-tools/pull-request/24

It is bad to take it as Fedora only,   I would suggest posting all the
refreshed patches together here again for review.

If no enough reviewers can review them my another suggestion is to
drop the kexec_load support code for the time being, and only enable
the kexec_file_load support code in kexec-tools, and I assume below
kernel commit make the kexec_file_load kernel piece of work done.
Then it will be easier to review and make something working at least.
commit 6261586e0c91db14c34f894f4bc48f2300cff1d4
Author: Liao Chang <liaochang1@huawei.com>
Date:   Fri Apr 8 18:09:11 2022 +0800

    RISC-V: Add kexec_file support

Thanks
Dave


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/7] Kexec-tools: Improve RISC-V port
  2024-05-18  3:39     ` Dave Young
@ 2024-05-18  8:33       ` Simon Horman
  2024-08-12 14:36         ` Petr Tesarik
  0 siblings, 1 reply; 17+ messages in thread
From: Simon Horman @ 2024-05-18  8:33 UTC (permalink / raw)
  To: Dave Young
  Cc: Song Shuai, mick, lizhengyu3, liaochang1, xianting.tian, guoren,
	huanyi.xj, yixun.lan, kexec, hursand

On Sat, May 18, 2024 at 11:39:18AM +0800, Dave Young wrote:
> On Wed, 11 Oct 2023 at 13:24, Song Shuai <songshuaishuai@tinylab.org> wrote:
> >
> >
> >
> > 在 2023/9/20 19:56, Simon Horman 写道:
> > > On Fri, Sep 15, 2023 at 11:50:06AM +0800, Song Shuai wrote:
> > >> Hi,
> > >>
> > >> This series is created to improve RISC-V port of kexec-tools,
> > >> and is based on the horms/kexec-tools:build-test-riscv-v2 branch.
> > >
> > > In my mind the big question is how to move RISC-V support
> > > from that branch, to being merged into main.
> > >
> > > IIRC there were some issues that needed to be addressed.
> > > Perhaps they are all addressed by this series, and with
> > > some appropriate squashing we can move forwards with a series
> > > based on main?
> >
> > Hi, Simon and Nick:
> >
> > I squashed the first four patches as a "RISC-V: Some fixes for riscv
> > port" patch and then took the horms/main as the base to collect the 2
> > patches from horms/build-test-riscv-v2 branch and this series togother.
> > These are the Github link and all commits for RISC-V.
> >
> > https://github.com/sugarfillet/kexec-tools/commits/main_rv
> >
> > 5dc133e RISC-V: Support loading Image binary file
> > b042f6d RISC-V: Separate elf_riscv_find_pbase out
> > 8f344c7 RISC-V: Enable kexec_file_load syscall
> > 7d4b982 RISC-V: Some fixes for riscv port
> > 3205c1c local: RISC-V: distribute purgatory/riscv/Makefile
> > 54f9daf RISC-V: Add support for riscv kexec/kdump on kexec-tools
> >
> > Since I didn't found the issues/fixes as Nick mentioned with these
> > commits, I prefer to merge them into horms/main and let more kexec/kdump
> > users to help improve/fixup RISC-V port.
> 
> Hi,  I noticed another pr for Fedora kexec-tools:
> https://src.fedoraproject.org/rpms/kexec-tools/pull-request/24
> 
> It is bad to take it as Fedora only,   I would suggest posting all the
> refreshed patches together here again for review.
> 
> If no enough reviewers can review them my another suggestion is to
> drop the kexec_load support code for the time being, and only enable
> the kexec_file_load support code in kexec-tools, and I assume below
> kernel commit make the kexec_file_load kernel piece of work done.
> Then it will be easier to review and make something working at least.
> commit 6261586e0c91db14c34f894f4bc48f2300cff1d4
> Author: Liao Chang <liaochang1@huawei.com>
> Date:   Fri Apr 8 18:09:11 2022 +0800
> 
>     RISC-V: Add kexec_file support

Hi,

I would gladly take a patchset for kexec-tools that adds RISC-V support in
a coherent manner.


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/7] Kexec-tools: Improve RISC-V port
  2024-05-18  8:33       ` Simon Horman
@ 2024-08-12 14:36         ` Petr Tesarik
  2024-08-13 14:26           ` Simon Horman
  2024-08-14  8:23           ` Dave Young
  0 siblings, 2 replies; 17+ messages in thread
From: Petr Tesarik @ 2024-08-12 14:36 UTC (permalink / raw)
  To: Simon Horman, Song Shuai
  Cc: Dave Young, mick, lizhengyu3, liaochang1, xianting.tian, guoren,
	huanyi.xj, yixun.lan, kexec, hursand

Hi,

On Sat, 18 May 2024 09:33:04 +0100
Simon Horman <horms@kernel.org> wrote:

> On Sat, May 18, 2024 at 11:39:18AM +0800, Dave Young wrote:
> > On Wed, 11 Oct 2023 at 13:24, Song Shuai <songshuaishuai@tinylab.org> wrote:  
> > >
> > >
> > >
> > > 在 2023/9/20 19:56, Simon Horman 写道:  
> > > > On Fri, Sep 15, 2023 at 11:50:06AM +0800, Song Shuai wrote:  
> > > >> Hi,
> > > >>
> > > >> This series is created to improve RISC-V port of kexec-tools,
> > > >> and is based on the horms/kexec-tools:build-test-riscv-v2 branch.  
> > > >
> > > > In my mind the big question is how to move RISC-V support
> > > > from that branch, to being merged into main.
> > > >
> > > > IIRC there were some issues that needed to be addressed.
> > > > Perhaps they are all addressed by this series, and with
> > > > some appropriate squashing we can move forwards with a series
> > > > based on main?  
> > >
> > > Hi, Simon and Nick:
> > >
> > > I squashed the first four patches as a "RISC-V: Some fixes for riscv
> > > port" patch and then took the horms/main as the base to collect the 2
> > > patches from horms/build-test-riscv-v2 branch and this series togother.
> > > These are the Github link and all commits for RISC-V.
> > >
> > > https://github.com/sugarfillet/kexec-tools/commits/main_rv
> > >
> > > 5dc133e RISC-V: Support loading Image binary file
> > > b042f6d RISC-V: Separate elf_riscv_find_pbase out
> > > 8f344c7 RISC-V: Enable kexec_file_load syscall
> > > 7d4b982 RISC-V: Some fixes for riscv port
> > > 3205c1c local: RISC-V: distribute purgatory/riscv/Makefile
> > > 54f9daf RISC-V: Add support for riscv kexec/kdump on kexec-tools
> > >
> > > Since I didn't found the issues/fixes as Nick mentioned with these
> > > commits, I prefer to merge them into horms/main and let more kexec/kdump
> > > users to help improve/fixup RISC-V port.  
> > 
> > Hi,  I noticed another pr for Fedora kexec-tools:
> > https://src.fedoraproject.org/rpms/kexec-tools/pull-request/24
> > 
> > It is bad to take it as Fedora only,   I would suggest posting all the
> > refreshed patches together here again for review.
> > 
> > If no enough reviewers can review them my another suggestion is to
> > drop the kexec_load support code for the time being, and only enable
> > the kexec_file_load support code in kexec-tools, and I assume below
> > kernel commit make the kexec_file_load kernel piece of work done.
> > Then it will be easier to review and make something working at least.
> > commit 6261586e0c91db14c34f894f4bc48f2300cff1d4
> > Author: Liao Chang <liaochang1@huawei.com>
> > Date:   Fri Apr 8 18:09:11 2022 +0800
> > 
> >     RISC-V: Add kexec_file support  
> 
> Hi,
> 
> I would gladly take a patchset for kexec-tools that adds RISC-V support in
> a coherent manner.

Have I missed some progress on this topic? FWIW I can take care of
RISC-V support in kexec-tools, I even received a VisionFive 2 board
from RVI last year specifically to help with kexec.

I merely don't want to duplicate efforts or "steal" someone else's
project. Is RISC-V support in kexec-tools an orphaned project now?

Petr T

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/7] Kexec-tools: Improve RISC-V port
  2024-08-12 14:36         ` Petr Tesarik
@ 2024-08-13 14:26           ` Simon Horman
  2024-08-14  8:23           ` Dave Young
  1 sibling, 0 replies; 17+ messages in thread
From: Simon Horman @ 2024-08-13 14:26 UTC (permalink / raw)
  To: Petr Tesarik
  Cc: Song Shuai, Dave Young, mick, lizhengyu3, liaochang1,
	xianting.tian, guoren, huanyi.xj, yixun.lan, kexec, hursand

On Mon, Aug 12, 2024 at 04:36:33PM +0200, Petr Tesarik wrote:
> Hi,
> 
> On Sat, 18 May 2024 09:33:04 +0100
> Simon Horman <horms@kernel.org> wrote:
> 
> > On Sat, May 18, 2024 at 11:39:18AM +0800, Dave Young wrote:
> > > On Wed, 11 Oct 2023 at 13:24, Song Shuai <songshuaishuai@tinylab.org> wrote:  
> > > >
> > > >
> > > >
> > > > 在 2023/9/20 19:56, Simon Horman 写道:  
> > > > > On Fri, Sep 15, 2023 at 11:50:06AM +0800, Song Shuai wrote:  
> > > > >> Hi,
> > > > >>
> > > > >> This series is created to improve RISC-V port of kexec-tools,
> > > > >> and is based on the horms/kexec-tools:build-test-riscv-v2 branch.  
> > > > >
> > > > > In my mind the big question is how to move RISC-V support
> > > > > from that branch, to being merged into main.
> > > > >
> > > > > IIRC there were some issues that needed to be addressed.
> > > > > Perhaps they are all addressed by this series, and with
> > > > > some appropriate squashing we can move forwards with a series
> > > > > based on main?  
> > > >
> > > > Hi, Simon and Nick:
> > > >
> > > > I squashed the first four patches as a "RISC-V: Some fixes for riscv
> > > > port" patch and then took the horms/main as the base to collect the 2
> > > > patches from horms/build-test-riscv-v2 branch and this series togother.
> > > > These are the Github link and all commits for RISC-V.
> > > >
> > > > https://github.com/sugarfillet/kexec-tools/commits/main_rv
> > > >
> > > > 5dc133e RISC-V: Support loading Image binary file
> > > > b042f6d RISC-V: Separate elf_riscv_find_pbase out
> > > > 8f344c7 RISC-V: Enable kexec_file_load syscall
> > > > 7d4b982 RISC-V: Some fixes for riscv port
> > > > 3205c1c local: RISC-V: distribute purgatory/riscv/Makefile
> > > > 54f9daf RISC-V: Add support for riscv kexec/kdump on kexec-tools
> > > >
> > > > Since I didn't found the issues/fixes as Nick mentioned with these
> > > > commits, I prefer to merge them into horms/main and let more kexec/kdump
> > > > users to help improve/fixup RISC-V port.  
> > > 
> > > Hi,  I noticed another pr for Fedora kexec-tools:
> > > https://src.fedoraproject.org/rpms/kexec-tools/pull-request/24
> > > 
> > > It is bad to take it as Fedora only,   I would suggest posting all the
> > > refreshed patches together here again for review.
> > > 
> > > If no enough reviewers can review them my another suggestion is to
> > > drop the kexec_load support code for the time being, and only enable
> > > the kexec_file_load support code in kexec-tools, and I assume below
> > > kernel commit make the kexec_file_load kernel piece of work done.
> > > Then it will be easier to review and make something working at least.
> > > commit 6261586e0c91db14c34f894f4bc48f2300cff1d4
> > > Author: Liao Chang <liaochang1@huawei.com>
> > > Date:   Fri Apr 8 18:09:11 2022 +0800
> > > 
> > >     RISC-V: Add kexec_file support  
> > 
> > Hi,
> > 
> > I would gladly take a patchset for kexec-tools that adds RISC-V support in
> > a coherent manner.
> 
> Have I missed some progress on this topic? FWIW I can take care of
> RISC-V support in kexec-tools, I even received a VisionFive 2 board
> from RVI last year specifically to help with kexec.
> 
> I merely don't want to duplicate efforts or "steal" someone else's
> project. Is RISC-V support in kexec-tools an orphaned project now?

Hi Petr,

If there has been progress then I am not aware of it.
And if you would like to step up and provide a single, well structured,
patchset that adds RISC-V support then I for one would be most grateful.


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/7] Kexec-tools: Improve RISC-V port
  2024-08-12 14:36         ` Petr Tesarik
  2024-08-13 14:26           ` Simon Horman
@ 2024-08-14  8:23           ` Dave Young
  2025-01-10  9:22             ` Dave Young
  1 sibling, 1 reply; 17+ messages in thread
From: Dave Young @ 2024-08-14  8:23 UTC (permalink / raw)
  To: Petr Tesarik
  Cc: Simon Horman, Song Shuai, mick, lizhengyu3, liaochang1,
	xianting.tian, guoren, huanyi.xj, yixun.lan, kexec, hursand

On Mon, 12 Aug 2024 at 22:36, Petr Tesarik <ptesarik@suse.com> wrote:
>
> Hi,
>
> On Sat, 18 May 2024 09:33:04 +0100
> Simon Horman <horms@kernel.org> wrote:
>
> > On Sat, May 18, 2024 at 11:39:18AM +0800, Dave Young wrote:
> > > On Wed, 11 Oct 2023 at 13:24, Song Shuai <songshuaishuai@tinylab.org> wrote:
> > > >
> > > >
> > > >
> > > > 在 2023/9/20 19:56, Simon Horman 写道:
> > > > > On Fri, Sep 15, 2023 at 11:50:06AM +0800, Song Shuai wrote:
> > > > >> Hi,
> > > > >>
> > > > >> This series is created to improve RISC-V port of kexec-tools,
> > > > >> and is based on the horms/kexec-tools:build-test-riscv-v2 branch.
> > > > >
> > > > > In my mind the big question is how to move RISC-V support
> > > > > from that branch, to being merged into main.
> > > > >
> > > > > IIRC there were some issues that needed to be addressed.
> > > > > Perhaps they are all addressed by this series, and with
> > > > > some appropriate squashing we can move forwards with a series
> > > > > based on main?
> > > >
> > > > Hi, Simon and Nick:
> > > >
> > > > I squashed the first four patches as a "RISC-V: Some fixes for riscv
> > > > port" patch and then took the horms/main as the base to collect the 2
> > > > patches from horms/build-test-riscv-v2 branch and this series togother.
> > > > These are the Github link and all commits for RISC-V.
> > > >
> > > > https://github.com/sugarfillet/kexec-tools/commits/main_rv
> > > >
> > > > 5dc133e RISC-V: Support loading Image binary file
> > > > b042f6d RISC-V: Separate elf_riscv_find_pbase out
> > > > 8f344c7 RISC-V: Enable kexec_file_load syscall
> > > > 7d4b982 RISC-V: Some fixes for riscv port
> > > > 3205c1c local: RISC-V: distribute purgatory/riscv/Makefile
> > > > 54f9daf RISC-V: Add support for riscv kexec/kdump on kexec-tools
> > > >
> > > > Since I didn't found the issues/fixes as Nick mentioned with these
> > > > commits, I prefer to merge them into horms/main and let more kexec/kdump
> > > > users to help improve/fixup RISC-V port.
> > >
> > > Hi,  I noticed another pr for Fedora kexec-tools:
> > > https://src.fedoraproject.org/rpms/kexec-tools/pull-request/24
> > >
> > > It is bad to take it as Fedora only,   I would suggest posting all the
> > > refreshed patches together here again for review.
> > >
> > > If no enough reviewers can review them my another suggestion is to
> > > drop the kexec_load support code for the time being, and only enable
> > > the kexec_file_load support code in kexec-tools, and I assume below
> > > kernel commit make the kexec_file_load kernel piece of work done.
> > > Then it will be easier to review and make something working at least.
> > > commit 6261586e0c91db14c34f894f4bc48f2300cff1d4
> > > Author: Liao Chang <liaochang1@huawei.com>
> > > Date:   Fri Apr 8 18:09:11 2022 +0800
> > >
> > >     RISC-V: Add kexec_file support
> >
> > Hi,
> >
> > I would gladly take a patchset for kexec-tools that adds RISC-V support in
> > a coherent manner.
>
> Have I missed some progress on this topic? FWIW I can take care of
> RISC-V support in kexec-tools, I even received a VisionFive 2 board
> from RVI last year specifically to help with kexec.
>
> I merely don't want to duplicate efforts or "steal" someone else's
> project. Is RISC-V support in kexec-tools an orphaned project now?
>

I thought about a simple kexec_file_load only approach previously but
I have no time to work on it actually.  In theory I think a simple
kexec_file_load implementation should only share some common functions
eg. arguments parsing, file reading etc. and load the kernel and
initrd into memory, pass the fds and cmdline buffer into kernel,
that's all,  Even no need to have the arch specific file format
checking as they should have been done in the related kernel code.
But looking at the code it is not easy.  Currently the kexec_load and
kexec_file_load implementations are not logically separate in the code
and the cleanup is hard.

Thanks
Dave


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/7] Kexec-tools: Improve RISC-V port
  2024-08-14  8:23           ` Dave Young
@ 2025-01-10  9:22             ` Dave Young
  0 siblings, 0 replies; 17+ messages in thread
From: Dave Young @ 2025-01-10  9:22 UTC (permalink / raw)
  To: Petr Tesarik
  Cc: Simon Horman, Song Shuai, mick, lizhengyu3, liaochang1,
	xianting.tian, guoren, huanyi.xj, yixun.lan, kexec, hursand

On Wed, 14 Aug 2024 at 16:23, Dave Young <dyoung@redhat.com> wrote:
>
> On Mon, 12 Aug 2024 at 22:36, Petr Tesarik <ptesarik@suse.com> wrote:
> >
> > Hi,
> >
> > On Sat, 18 May 2024 09:33:04 +0100
> > Simon Horman <horms@kernel.org> wrote:
> >
> > > On Sat, May 18, 2024 at 11:39:18AM +0800, Dave Young wrote:
> > > > On Wed, 11 Oct 2023 at 13:24, Song Shuai <songshuaishuai@tinylab.org> wrote:
> > > > >
> > > > >
> > > > >
> > > > > 在 2023/9/20 19:56, Simon Horman 写道:
> > > > > > On Fri, Sep 15, 2023 at 11:50:06AM +0800, Song Shuai wrote:
> > > > > >> Hi,
> > > > > >>
> > > > > >> This series is created to improve RISC-V port of kexec-tools,
> > > > > >> and is based on the horms/kexec-tools:build-test-riscv-v2 branch.
> > > > > >
> > > > > > In my mind the big question is how to move RISC-V support
> > > > > > from that branch, to being merged into main.
> > > > > >
> > > > > > IIRC there were some issues that needed to be addressed.
> > > > > > Perhaps they are all addressed by this series, and with
> > > > > > some appropriate squashing we can move forwards with a series
> > > > > > based on main?
> > > > >
> > > > > Hi, Simon and Nick:
> > > > >
> > > > > I squashed the first four patches as a "RISC-V: Some fixes for riscv
> > > > > port" patch and then took the horms/main as the base to collect the 2
> > > > > patches from horms/build-test-riscv-v2 branch and this series togother.
> > > > > These are the Github link and all commits for RISC-V.
> > > > >
> > > > > https://github.com/sugarfillet/kexec-tools/commits/main_rv
> > > > >
> > > > > 5dc133e RISC-V: Support loading Image binary file
> > > > > b042f6d RISC-V: Separate elf_riscv_find_pbase out
> > > > > 8f344c7 RISC-V: Enable kexec_file_load syscall
> > > > > 7d4b982 RISC-V: Some fixes for riscv port
> > > > > 3205c1c local: RISC-V: distribute purgatory/riscv/Makefile
> > > > > 54f9daf RISC-V: Add support for riscv kexec/kdump on kexec-tools
> > > > >
> > > > > Since I didn't found the issues/fixes as Nick mentioned with these
> > > > > commits, I prefer to merge them into horms/main and let more kexec/kdump
> > > > > users to help improve/fixup RISC-V port.
> > > >
> > > > Hi,  I noticed another pr for Fedora kexec-tools:
> > > > https://src.fedoraproject.org/rpms/kexec-tools/pull-request/24
> > > >
> > > > It is bad to take it as Fedora only,   I would suggest posting all the
> > > > refreshed patches together here again for review.
> > > >
> > > > If no enough reviewers can review them my another suggestion is to
> > > > drop the kexec_load support code for the time being, and only enable
> > > > the kexec_file_load support code in kexec-tools, and I assume below
> > > > kernel commit make the kexec_file_load kernel piece of work done.
> > > > Then it will be easier to review and make something working at least.
> > > > commit 6261586e0c91db14c34f894f4bc48f2300cff1d4
> > > > Author: Liao Chang <liaochang1@huawei.com>
> > > > Date:   Fri Apr 8 18:09:11 2022 +0800
> > > >
> > > >     RISC-V: Add kexec_file support
> > >
> > > Hi,
> > >
> > > I would gladly take a patchset for kexec-tools that adds RISC-V support in
> > > a coherent manner.
> >
> > Have I missed some progress on this topic? FWIW I can take care of
> > RISC-V support in kexec-tools, I even received a VisionFive 2 board
> > from RVI last year specifically to help with kexec.
> >
> > I merely don't want to duplicate efforts or "steal" someone else's
> > project. Is RISC-V support in kexec-tools an orphaned project now?
> >
>
> I thought about a simple kexec_file_load only approach previously but
> I have no time to work on it actually.  In theory I think a simple
> kexec_file_load implementation should only share some common functions
> eg. arguments parsing, file reading etc. and load the kernel and
> initrd into memory, pass the fds and cmdline buffer into kernel,
> that's all,  Even no need to have the arch specific file format
> checking as they should have been done in the related kernel code.
> But looking at the code it is not easy.  Currently the kexec_load and
> kexec_file_load implementations are not logically separate in the code
> and the cleanup is hard.

Hi,

My concept is like below (an ugly draft, not polished and well tested,
also missing zboot/uki decompressing), maybe people can use it
temporarily before a full support code is ready:
https://github.com/daveyoung/kexecfile

Thanks
Dave



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2025-01-10  9:33 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-15  3:50 [PATCH 0/7] Kexec-tools: Improve RISC-V port Song Shuai
2023-09-15  3:50 ` [PATCH 1/7] RISC-V: Use linux,usable-memory-range for crash kernel Song Shuai
2023-09-15  3:50 ` [PATCH 2/7] RISC-V: Fix the undeclared ‘EM_RISCV’ build failure Song Shuai
2023-09-15  3:50 ` [PATCH 3/7] RISC-V: Get memory ranges from iomem Song Shuai
2023-09-15  3:50 ` [PATCH 4/7] RISC-V: Correct the usage of command line option Song Shuai
2023-09-15  3:50 ` [PATCH 5/7] RISC-V: Enable kexe_file_load Song Shuai
2023-09-15  3:50 ` [PATCH 6/7] RISC-V: Separate elf_riscv_find_pbase out Song Shuai
2023-09-15  3:50 ` [PATCH 7/7] RISC-V: Support loading Image binary file Song Shuai
2023-09-20 11:56 ` [PATCH 0/7] Kexec-tools: Improve RISC-V port Simon Horman
2023-10-11  5:22   ` Song Shuai
2024-05-18  3:39     ` Dave Young
2024-05-18  8:33       ` Simon Horman
2024-08-12 14:36         ` Petr Tesarik
2024-08-13 14:26           ` Simon Horman
2024-08-14  8:23           ` Dave Young
2025-01-10  9:22             ` Dave Young
2023-09-20 13:47 ` Nick Kossifidis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox