From: "Björn Töpel" <bjorn@kernel.org>
To: Simon Horman <horms@kernel.org>,
Simon Horman <horms@verge.net.au>,
Nick Kossifidis <mick@ics.forth.gr>,
Song Shuai <songshuaishuai@tinylab.org>,
Li Zhengyu <lizhengyu3@huawei.com>,
kexec@lists.infradead.org
Cc: Dave Young <dyoung@redhat.com>, Yixun Lan <yixun.lan@gmail.com>,
Xianting Tian <xianting.tian@linux.alibaba.com>,
linux-riscv@lists.infradead.org
Subject: [PATCH 2/4] RISC-V: Enable kexec_file_load syscall
Date: Wed, 9 Apr 2025 22:14:24 +0200 [thread overview]
Message-ID: <20250409201428.648717-3-bjorn@kernel.org> (raw)
In-Reply-To: <20250409201428.648717-1-bjorn@kernel.org>
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 | 39 ++++++++++++++++++++++++++++++
kexec/arch/riscv/kexec-riscv.h | 1 +
kexec/kexec-syscall.h | 3 +++
4 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/kexec/arch/riscv/kexec-elf-riscv.c b/kexec/arch/riscv/kexec-elf-riscv.c
index f3c011c4c1dc..2b9f66d782af 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 38d9a394aadd..bbc25c5cba41 100644
--- a/kexec/arch/riscv/kexec-riscv.c
+++ b/kexec/arch/riscv/kexec-riscv.c
@@ -17,6 +17,12 @@
#include "kexec-riscv.h"
#include "iomem.h"
#include <stdbool.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 +147,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 c4323a65dacf..f136c7eab561 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 89591ad17e7d..9b1757877a85 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.45.2
WARNING: multiple messages have this Message-ID (diff)
From: "Björn Töpel" <bjorn@kernel.org>
To: Simon Horman <horms@kernel.org>,
Simon Horman <horms@verge.net.au>,
Nick Kossifidis <mick@ics.forth.gr>,
Song Shuai <songshuaishuai@tinylab.org>,
Li Zhengyu <lizhengyu3@huawei.com>,
kexec@lists.infradead.org
Cc: Dave Young <dyoung@redhat.com>, Yixun Lan <yixun.lan@gmail.com>,
Xianting Tian <xianting.tian@linux.alibaba.com>,
linux-riscv@lists.infradead.org
Subject: [PATCH 2/4] RISC-V: Enable kexec_file_load syscall
Date: Wed, 9 Apr 2025 22:14:24 +0200 [thread overview]
Message-ID: <20250409201428.648717-3-bjorn@kernel.org> (raw)
In-Reply-To: <20250409201428.648717-1-bjorn@kernel.org>
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 | 39 ++++++++++++++++++++++++++++++
kexec/arch/riscv/kexec-riscv.h | 1 +
kexec/kexec-syscall.h | 3 +++
4 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/kexec/arch/riscv/kexec-elf-riscv.c b/kexec/arch/riscv/kexec-elf-riscv.c
index f3c011c4c1dc..2b9f66d782af 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 38d9a394aadd..bbc25c5cba41 100644
--- a/kexec/arch/riscv/kexec-riscv.c
+++ b/kexec/arch/riscv/kexec-riscv.c
@@ -17,6 +17,12 @@
#include "kexec-riscv.h"
#include "iomem.h"
#include <stdbool.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 +147,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 c4323a65dacf..f136c7eab561 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 89591ad17e7d..9b1757877a85 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.45.2
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-04-09 20:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 20:14 [PATCH 0/4] kexec-tools RISC-V port Björn Töpel
2025-04-09 20:14 ` Björn Töpel
2025-04-09 20:14 ` [PATCH 1/4] RISC-V: Add support for riscv kexec/kdump on kexec-tools Björn Töpel
2025-04-09 20:14 ` Björn Töpel
2025-04-22 10:48 ` Simon Horman
2025-04-22 10:48 ` Simon Horman
2025-04-22 12:07 ` Björn Töpel
2025-04-22 12:07 ` Björn Töpel
2025-04-22 13:54 ` Simon Horman
2025-04-22 13:54 ` Simon Horman
2025-04-09 20:14 ` Björn Töpel [this message]
2025-04-09 20:14 ` [PATCH 2/4] RISC-V: Enable kexec_file_load syscall Björn Töpel
2025-04-09 20:14 ` [PATCH 3/4] RISC-V: Separate elf_riscv_find_pbase out Björn Töpel
2025-04-09 20:14 ` Björn Töpel
2025-04-09 20:14 ` [PATCH 4/4] RISC-V: Support loading Image binary file Björn Töpel
2025-04-09 20:14 ` Björn Töpel
2025-04-14 8:40 ` [PATCH 0/4] kexec-tools RISC-V port Simon Horman
2025-04-14 8:40 ` Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250409201428.648717-3-bjorn@kernel.org \
--to=bjorn@kernel.org \
--cc=dyoung@redhat.com \
--cc=horms@kernel.org \
--cc=horms@verge.net.au \
--cc=kexec@lists.infradead.org \
--cc=linux-riscv@lists.infradead.org \
--cc=lizhengyu3@huawei.com \
--cc=mick@ics.forth.gr \
--cc=songshuaishuai@tinylab.org \
--cc=xianting.tian@linux.alibaba.com \
--cc=yixun.lan@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.