* [PATCHv5 0/8] arm64: zboot support
@ 2023-07-17 13:07 Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 1/8] arm64: Fix some issues with zImage _probe() Pingfan Liu
` (8 more replies)
0 siblings, 9 replies; 15+ messages in thread
From: Pingfan Liu @ 2023-07-17 13:07 UTC (permalink / raw)
To: kexec; +Cc: Pingfan Liu, horms, ardb, jeremy.linton
As more complicated capsule kernel format occurs like zboot, where the
compressed kernel is stored as a payload. The straight forward
decompression can not meet the demand.
As the first step, on aarch64, reading in the kernel file in a probe
method and decide how to unfold the content by the method itself.
This series introduce a new image probe interface probe2(), which
returns three factors: kernel buffer, kernel size and kernel fd through
a struct parsed_info.
-1. the parsed kernel_buf should be returned so that it can be used by
the image load method later.
-2. the final fd passed to sys_kexec_file_load, since aarch64 kernel can
only work with Image format, the outer payload should be stripped and a
temporary file of Image should be created.
To ease the review, a branch is accessable at https://github.com/pfliu/kexec-tools.git
branch zbootV5
To: kexec@lists.infradead.org
Cc: horms@verge.net.au
Cc: ardb@kernel.org
Cc: jeremy.linton@arm.com
---
v4 -> v5:
Amend label 'error' to 'err' in [4/8]
v3 -> v4:
Give up the method to change the image probe method prototype
system-wide, instead, introducing a probe2() for the affected arch
Jeremy Linton (4):
arm64: Fix some issues with zImage _probe()
kexec/zboot: Add arch independent zboot support
arm64: Add ZBOOT PE containing compressed image support
arm64: Hook up the ZBOOT support as vmlinuz
Pingfan Liu (4):
kexec: Isolate probe method
kexec: Introduce a new image probe method 'probe2'
arm64: Transfer from probe() to probe2()
kexec: Drop condition macro for aarch64
include/kexec-pe-zboot.h | 15 +++
kexec/Makefile | 1 +
kexec/arch/arm64/Makefile | 3 +-
kexec/arch/arm64/image-header.h | 1 +
kexec/arch/arm64/kexec-arm64.c | 10 +-
kexec/arch/arm64/kexec-arm64.h | 11 +-
kexec/arch/arm64/kexec-elf-arm64.c | 7 +-
kexec/arch/arm64/kexec-image-arm64.c | 16 ++-
kexec/arch/arm64/kexec-uImage-arm64.c | 15 ++-
kexec/arch/arm64/kexec-vmlinuz-arm64.c | 102 +++++++++++++++++++
kexec/arch/arm64/kexec-zImage-arm64.c | 41 ++------
kexec/kexec-pe-zboot.c | 133 +++++++++++++++++++++++++
kexec/kexec.c | 86 ++++++++++------
kexec/kexec.h | 9 ++
14 files changed, 367 insertions(+), 83 deletions(-)
create mode 100644 include/kexec-pe-zboot.h
create mode 100644 kexec/arch/arm64/kexec-vmlinuz-arm64.c
create mode 100644 kexec/kexec-pe-zboot.c
--
2.31.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCHv5 1/8] arm64: Fix some issues with zImage _probe()
2023-07-17 13:07 [PATCHv5 0/8] arm64: zboot support Pingfan Liu
@ 2023-07-17 13:07 ` Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 2/8] kexec: Isolate probe method Pingfan Liu
` (7 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Pingfan Liu @ 2023-07-17 13:07 UTC (permalink / raw)
To: kexec; +Cc: Jeremy Linton, Pingfan Liu, horms, ardb
From: Jeremy Linton <jeremy.linton@arm.com>
Current compilers note that fname will be null while
attempting to print failures from strdup().
Further fix a memory leak caused by kernel_uncompressed_buf
never being used/freed before the allocated block is replaced
by the one returned by slurp_decompress_file().
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Signed-off-by: Pingfan Liu <piliu@redhat.com>
To: kexec@lists.infradead.org
Cc: horms@verge.net.au
Cc: ardb@kernel.org
Cc: jeremy.linton@arm.com
---
kexec/arch/arm64/kexec-zImage-arm64.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/kexec/arch/arm64/kexec-zImage-arm64.c b/kexec/arch/arm64/kexec-zImage-arm64.c
index 6ee82ff..3eb1ad8 100644
--- a/kexec/arch/arm64/kexec-zImage-arm64.c
+++ b/kexec/arch/arm64/kexec-zImage-arm64.c
@@ -55,8 +55,7 @@ int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size)
}
if (!(fname = strdup(FILENAME_IMAGE))) {
- dbgprintf("%s: Can't duplicate strings %s\n", __func__,
- fname);
+ dbgprintf("%s: Can't duplicate strings\n", __func__);
return -1;
}
@@ -67,15 +66,6 @@ int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size)
goto fail_mkstemp;
}
- kernel_uncompressed_buf =
- (char *) calloc(kernel_size, sizeof(off_t));
- if (!kernel_uncompressed_buf) {
- dbgprintf("%s: Can't calloc %ld bytes\n",
- __func__, kernel_size);
- ret= -ENOMEM;
- goto fail_calloc;
- }
-
/* slurp in the input kernel */
dbgprintf("%s: ", __func__);
kernel_uncompressed_buf = slurp_decompress_file(kernel_buf,
@@ -128,7 +118,6 @@ int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size)
fail_bad_header:
free(kernel_uncompressed_buf);
-fail_calloc:
if (fd >= 0)
close(fd);
--
2.31.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCHv5 2/8] kexec: Isolate probe method
2023-07-17 13:07 [PATCHv5 0/8] arm64: zboot support Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 1/8] arm64: Fix some issues with zImage _probe() Pingfan Liu
@ 2023-07-17 13:07 ` Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 3/8] kexec: Introduce a new image probe method 'probe2' Pingfan Liu
` (6 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Pingfan Liu @ 2023-07-17 13:07 UTC (permalink / raw)
To: kexec; +Cc: Pingfan Liu, horms, ardb, jeremy.linton
Isolating the calling to the probe method, so in a later patch, a new
prototype probe2 interface can be introduced without exposure of the
change.
Signed-off-by: Pingfan Liu <piliu@redhat.com>
To: kexec@lists.infradead.org
Cc: horms@verge.net.au
Cc: ardb@kernel.org
Cc: jeremy.linton@arm.com
---
kexec/kexec.c | 81 +++++++++++++++++++++++++++++++--------------------
1 file changed, 49 insertions(+), 32 deletions(-)
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 36bb2ad..d5e6dc0 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -694,6 +694,48 @@ static void update_purgatory(struct kexec_info *info)
sizeof(digest));
}
+static int initialze_probe(const char *kern_fname,
+ char **kernel_buf, off_t *kernel_size, int *kernel_fd)
+{
+ static int probe_type = -1;
+
+ if (probe_type >= 0)
+ return probe_type;
+
+ *kernel_fd = open(kern_fname, O_RDONLY);
+ if (*kernel_fd == -1) {
+ die("Failed to open file %s:%s\n", kern_fname,
+ strerror(errno));
+ return EFAILED;
+ }
+
+ /* slurp in the input kernel */
+ *kernel_buf = slurp_decompress_file(kern_fname, kernel_size);
+ probe_type = 0;
+
+ return probe_type;
+}
+
+static int probe(struct file_type *ft, const char *kern_fname,
+ char **kernel_buf, off_t *kernel_size, int *kernel_fd)
+{
+ int ret;
+
+ initialze_probe(kern_fname, kernel_buf, kernel_size, kernel_fd);
+#ifdef __aarch64__
+ /* handle Image.gz like cases */
+ if (is_zlib_file(kern_fname, &kernel_size)) {
+ if ((ret = ft->probe(kern_fname, *kernel_size)) >= 0)
+ *kernel_fd = ret;
+ } else {
+ ret = ft->probe(*kernel_buf, *kernel_size);
+ }
+#else
+ ret = ft->probe(*kernel_buf, *kernel_size);
+#endif
+ return ret;
+}
+
/*
* Load the new kernel
*/
@@ -703,6 +745,7 @@ static int my_load(const char *type, int fileind, int argc, char **argv,
char *kernel;
char *kernel_buf;
off_t kernel_size;
+ int kernel_fd = -1;
int i = 0;
int result;
struct kexec_info info;
@@ -720,11 +763,6 @@ static int my_load(const char *type, int fileind, int argc, char **argv,
return -1;
}
kernel = argv[fileind];
- /* slurp in the input kernel */
- kernel_buf = slurp_decompress_file(kernel, &kernel_size);
-
- dbgprintf("kernel: %p kernel_size: %#llx\n",
- kernel_buf, (unsigned long long)kernel_size);
if (get_memory_ranges(&info.memory_range, &info.memory_ranges,
info.kexec_flags) < 0 || info.memory_ranges == 0) {
@@ -742,13 +780,13 @@ static int my_load(const char *type, int fileind, int argc, char **argv,
return -1;
} else {
/* make sure our file is really of that type */
- if (file_type[i].probe(kernel_buf, kernel_size) < 0)
+ if (probe(&file_type[i], kernel, &kernel_buf, &kernel_size, &kernel_fd) < 0)
guess_only = 1;
}
}
if (!type || guess_only) {
for (i = 0; i < file_types; i++) {
- if (file_type[i].probe(kernel_buf, kernel_size) == 0)
+ if (probe(&file_type[i], kernel, &kernel_buf, &kernel_size, &kernel_fd) == 0)
break;
}
if (i == file_types) {
@@ -1263,10 +1301,10 @@ static int do_kexec_file_load(int fileind, int argc, char **argv,
unsigned long flags) {
char *kernel;
- int kernel_fd, i;
+ int i, kernel_fd = -1;
struct kexec_info info;
int ret = 0;
- char *kernel_buf;
+ char *kernel_buf = NULL;
off_t kernel_size;
memset(&info, 0, sizeof(info));
@@ -1290,31 +1328,10 @@ static int do_kexec_file_load(int fileind, int argc, char **argv,
kernel = argv[fileind];
- kernel_fd = open(kernel, O_RDONLY);
- if (kernel_fd == -1) {
- fprintf(stderr, "Failed to open file %s:%s\n", kernel,
- strerror(errno));
- return EFAILED;
- }
-
- /* slurp in the input kernel */
- kernel_buf = slurp_decompress_file(kernel, &kernel_size);
-
for (i = 0; i < file_types; i++) {
-#ifdef __aarch64__
- /* handle Image.gz like cases */
- if (is_zlib_file(kernel, &kernel_size)) {
- if ((ret = file_type[i].probe(kernel, kernel_size)) >= 0) {
- kernel_fd = ret;
- break;
- }
- } else
- if (file_type[i].probe(kernel_buf, kernel_size) >= 0)
- break;
-#else
- if (file_type[i].probe(kernel_buf, kernel_size) >= 0)
+ ret = probe(&file_type[i], kernel, &kernel_buf, &kernel_size, &kernel_fd);
+ if (ret >=0)
break;
-#endif
}
if (i == file_types) {
--
2.31.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCHv5 3/8] kexec: Introduce a new image probe method 'probe2'
2023-07-17 13:07 [PATCHv5 0/8] arm64: zboot support Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 1/8] arm64: Fix some issues with zImage _probe() Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 2/8] kexec: Isolate probe method Pingfan Liu
@ 2023-07-17 13:07 ` Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 4/8] arm64: Transfer from probe() to probe2() Pingfan Liu
` (5 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Pingfan Liu @ 2023-07-17 13:07 UTC (permalink / raw)
To: kexec; +Cc: Pingfan Liu, horms, ardb, jeremy.linton
As more complicated capsule kernel format occurs like zboot, where the
compressed kernel is stored as a payload. The straight forward
decompression can not meet the demand.
So introducing a new image probe interface -- probe2, which reads in the
kernel file and decides how to unfold the content by the method itself.
The interface probe and probe2 can not coexist
Signed-off-by: Pingfan Liu <piliu@redhat.com>
To: kexec@lists.infradead.org
Cc: horms@verge.net.au
Cc: ardb@kernel.org
Cc: jeremy.linton@arm.com
---
kexec/kexec.c | 31 +++++++++++++++++++++++--------
kexec/kexec.h | 9 +++++++++
2 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/kexec/kexec.c b/kexec/kexec.c
index d5e6dc0..5f75179 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -702,6 +702,9 @@ static int initialze_probe(const char *kern_fname,
if (probe_type >= 0)
return probe_type;
+ if (!file_type[0].probe)
+ goto type_probe2;
+
*kernel_fd = open(kern_fname, O_RDONLY);
if (*kernel_fd == -1) {
die("Failed to open file %s:%s\n", kern_fname,
@@ -712,27 +715,39 @@ static int initialze_probe(const char *kern_fname,
/* slurp in the input kernel */
*kernel_buf = slurp_decompress_file(kern_fname, kernel_size);
probe_type = 0;
+ return probe_type;
+type_probe2:
+ probe_type = 1;
return probe_type;
}
static int probe(struct file_type *ft, const char *kern_fname,
char **kernel_buf, off_t *kernel_size, int *kernel_fd)
{
+ struct parsed_info info;
int ret;
- initialze_probe(kern_fname, kernel_buf, kernel_size, kernel_fd);
+ ret = initialze_probe(kern_fname, kernel_buf, kernel_size, kernel_fd);
+ if (ret == 0) {
#ifdef __aarch64__
- /* handle Image.gz like cases */
- if (is_zlib_file(kern_fname, &kernel_size)) {
- if ((ret = ft->probe(kern_fname, *kernel_size)) >= 0)
- *kernel_fd = ret;
- } else {
- ret = ft->probe(*kernel_buf, *kernel_size);
- }
+ /* handle Image.gz like cases */
+ if (is_zlib_file(kern_fname, &kernel_size)) {
+ if ((ret = ft->probe(kern_fname, *kernel_size)) >= 0)
+ *kernel_fd = ret;
+ } else {
+ ret = ft->probe(*kernel_buf, *kernel_size);
+ }
#else
ret = ft->probe(*kernel_buf, *kernel_size);
#endif
+ } else if (ret == 1) {
+ ret = ft->probe2(kern_fname, &info);
+ *kernel_buf = info.kernel_buf;
+ *kernel_size = info.kernel_size;
+ *kernel_fd = info.fd;
+ }
+
return ret;
}
diff --git a/kexec/kexec.h b/kexec/kexec.h
index 0d820ad..fbeee3d 100644
--- a/kexec/kexec.h
+++ b/kexec/kexec.h
@@ -176,6 +176,12 @@ struct arch_map_entry {
unsigned long arch;
};
+struct parsed_info {
+ char *kernel_buf;
+ off_t kernel_size;
+ int fd;
+};
+
extern const struct arch_map_entry arches[];
long physical_arch(void);
@@ -192,6 +198,7 @@ unsigned long locate_hole(struct kexec_info *info,
int hole_end);
typedef int (probe_t)(const char *kernel_buf, off_t kernel_size);
+typedef int (probe2_t)(const char *kern_fname, struct parsed_info *info);
typedef int (load_t )(int argc, char **argv,
const char *kernel_buf, off_t kernel_size,
struct kexec_info *info);
@@ -201,6 +208,8 @@ struct file_type {
probe_t *probe;
load_t *load;
usage_t *usage;
+ /* Keep it as the last one so that by default it is NULL */
+ probe2_t *probe2;
};
extern struct file_type file_type[];
--
2.31.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCHv5 4/8] arm64: Transfer from probe() to probe2()
2023-07-17 13:07 [PATCHv5 0/8] arm64: zboot support Pingfan Liu
` (2 preceding siblings ...)
2023-07-17 13:07 ` [PATCHv5 3/8] kexec: Introduce a new image probe method 'probe2' Pingfan Liu
@ 2023-07-17 13:07 ` Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 5/8] kexec: Drop condition macro for aarch64 Pingfan Liu
` (4 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Pingfan Liu @ 2023-07-17 13:07 UTC (permalink / raw)
To: kexec; +Cc: Pingfan Liu, horms, ardb, jeremy.linton
Scatter the logic of reading of kernel file into each probe
As more complicated capsule kernel format ,such as zboot, emerge, where
the compressed kernel is stored as a payload. The straight forward
decompression can not meet the demand.
Therefore, introduce a method probe2, which reads in the kernel file and
decides how to unfold the content by itself.
At present, only aarch64 supports zboot image and implements probe2().
Signed-off-by: Pingfan Liu <piliu@redhat.com>
To: kexec@lists.infradead.org
Cc: horms@verge.net.au
Cc: ardb@kernel.org
Cc: jeremy.linton@arm.com
Signed-off-by: Pingfan Liu <piliu@redhat.com>
---
kexec/arch/arm64/kexec-arm64.c | 9 +++++----
kexec/arch/arm64/kexec-arm64.h | 8 ++++----
kexec/arch/arm64/kexec-elf-arm64.c | 7 +++++--
kexec/arch/arm64/kexec-image-arm64.c | 16 ++++++++++-----
kexec/arch/arm64/kexec-uImage-arm64.c | 15 ++++++++++----
kexec/arch/arm64/kexec-zImage-arm64.c | 28 +++++++++------------------
6 files changed, 45 insertions(+), 38 deletions(-)
diff --git a/kexec/arch/arm64/kexec-arm64.c b/kexec/arch/arm64/kexec-arm64.c
index ec6df4b..f391f77 100644
--- a/kexec/arch/arm64/kexec-arm64.c
+++ b/kexec/arch/arm64/kexec-arm64.c
@@ -70,11 +70,12 @@ const struct arch_map_entry arches[] = {
{ NULL, 0 },
};
+/* On arm64, probe2 is used, probe is abandoned */
struct file_type file_type[] = {
- {"vmlinux", elf_arm64_probe, elf_arm64_load, elf_arm64_usage},
- {"Image", image_arm64_probe, image_arm64_load, image_arm64_usage},
- {"uImage", uImage_arm64_probe, uImage_arm64_load, uImage_arm64_usage},
- {"zImage", zImage_arm64_probe, zImage_arm64_load, zImage_arm64_usage},
+ {"vmlinux", NULL, elf_arm64_load, elf_arm64_usage, elf_arm64_probe},
+ {"Image", NULL, image_arm64_load, image_arm64_usage, image_arm64_probe},
+ {"uImage", NULL, uImage_arm64_load, uImage_arm64_usage, uImage_arm64_probe},
+ {"zImage", NULL, zImage_arm64_load, zImage_arm64_usage, zImage_arm64_probe},
};
int file_types = sizeof(file_type) / sizeof(file_type[0]);
diff --git a/kexec/arch/arm64/kexec-arm64.h b/kexec/arch/arm64/kexec-arm64.h
index 5eb9fc0..eeb35ae 100644
--- a/kexec/arch/arm64/kexec-arm64.h
+++ b/kexec/arch/arm64/kexec-arm64.h
@@ -29,22 +29,22 @@
#define NOT_KV_ADDR (0x0)
#define NOT_PADDR (ULONGLONG_MAX)
-int elf_arm64_probe(const char *kernel_buf, off_t kernel_size);
+int elf_arm64_probe(const char *kern_fname, struct parsed_info *info);
int elf_arm64_load(int argc, char **argv, const char *kernel_buf,
off_t kernel_size, struct kexec_info *info);
void elf_arm64_usage(void);
-int image_arm64_probe(const char *kernel_buf, off_t kernel_size);
+int image_arm64_probe(const char *kern_fname, struct parsed_info *info);
int image_arm64_load(int argc, char **argv, const char *kernel_buf,
off_t kernel_size, struct kexec_info *info);
void image_arm64_usage(void);
-int uImage_arm64_probe(const char *buf, off_t len);
+int uImage_arm64_probe(const char *kern_fname, struct parsed_info *info);
int uImage_arm64_load(int argc, char **argv, const char *buf, off_t len,
struct kexec_info *info);
void uImage_arm64_usage(void);
-int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size);
+int zImage_arm64_probe(const char *kern_fname, struct parsed_info *info);
int zImage_arm64_load(int argc, char **argv, const char *kernel_buf,
off_t kernel_size, struct kexec_info *info);
void zImage_arm64_usage(void);
diff --git a/kexec/arch/arm64/kexec-elf-arm64.c b/kexec/arch/arm64/kexec-elf-arm64.c
index e14f8e9..4e8f8d9 100644
--- a/kexec/arch/arm64/kexec-elf-arm64.c
+++ b/kexec/arch/arm64/kexec-elf-arm64.c
@@ -16,12 +16,13 @@
#include "kexec-elf.h"
#include "kexec-syscall.h"
-int elf_arm64_probe(const char *kernel_buf, off_t kernel_size)
+int elf_arm64_probe(const char *kern_fname, struct parsed_info *info)
{
struct mem_ehdr ehdr;
int result;
- result = build_elf_exec_info(kernel_buf, kernel_size, &ehdr, 0);
+ info->kernel_buf = slurp_file(kern_fname, &info->kernel_size);
+ result = build_elf_exec_info(info->kernel_buf, info->kernel_size, &ehdr, 0);
if (result < 0) {
dbgprintf("%s: Not an ELF executable.\n", __func__);
@@ -34,8 +35,10 @@ int elf_arm64_probe(const char *kernel_buf, off_t kernel_size)
goto on_exit;
}
+ info->fd = open(kern_fname, O_RDONLY);
result = 0;
on_exit:
+ free(info->kernel_buf);
free_elf_info(&ehdr);
return result;
}
diff --git a/kexec/arch/arm64/kexec-image-arm64.c b/kexec/arch/arm64/kexec-image-arm64.c
index aa8f2e2..3895c1a 100644
--- a/kexec/arch/arm64/kexec-image-arm64.c
+++ b/kexec/arch/arm64/kexec-image-arm64.c
@@ -7,6 +7,7 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <stdlib.h>
#include "crashdump-arm64.h"
#include "image-header.h"
#include "kexec.h"
@@ -14,23 +15,28 @@
#include "kexec-syscall.h"
#include "arch/options.h"
-int image_arm64_probe(const char *kernel_buf, off_t kernel_size)
+int image_arm64_probe(const char *kern_fname, struct parsed_info *info)
{
const struct arm64_image_header *h;
- if (kernel_size < sizeof(struct arm64_image_header)) {
+ info->kernel_buf = slurp_file(kern_fname, &info->kernel_size);
+ if (info->kernel_size < sizeof(struct arm64_image_header)) {
dbgprintf("%s: No arm64 image header.\n", __func__);
- return -1;
+ goto err;
}
- h = (const struct arm64_image_header *)(kernel_buf);
+ h = (const struct arm64_image_header *)(info->kernel_buf);
if (!arm64_header_check_magic(h)) {
dbgprintf("%s: Bad arm64 image header.\n", __func__);
- return -1;
+ goto err;
}
+ info->fd = open(kern_fname, O_RDONLY);
return 0;
+err:
+ free(info->kernel_buf);
+ return -1;
}
int image_arm64_load(int argc, char **argv, const char *kernel_buf,
diff --git a/kexec/arch/arm64/kexec-uImage-arm64.c b/kexec/arch/arm64/kexec-uImage-arm64.c
index c466913..2bd4607 100644
--- a/kexec/arch/arm64/kexec-uImage-arm64.c
+++ b/kexec/arch/arm64/kexec-uImage-arm64.c
@@ -3,26 +3,33 @@
*/
#include <stdint.h>
#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
#include <sys/types.h>
#include <image.h>
#include <kexec-uImage.h>
#include "../../kexec.h"
#include "kexec-arm64.h"
-int uImage_arm64_probe(const char *buf, off_t len)
+int uImage_arm64_probe(const char *kern_fname, struct parsed_info *info)
{
int ret;
- ret = uImage_probe_kernel(buf, len, IH_ARCH_ARM64);
+ info->kernel_buf = slurp_file(kern_fname, &info->kernel_size);
+ ret = uImage_probe_kernel(info->kernel_buf, info->kernel_size, IH_ARCH_ARM64);
/* 0 - valid uImage.
* -1 - uImage is corrupted.
* 1 - image is not a uImage.
*/
- if (!ret)
+ if (!ret) {
+ info->fd = open(kern_fname, O_RDONLY);
return 0;
- else
+ }
+ else {
+ free(info->kernel_buf);
return -1;
+ }
}
int uImage_arm64_load(int argc, char **argv, const char *buf, off_t len,
diff --git a/kexec/arch/arm64/kexec-zImage-arm64.c b/kexec/arch/arm64/kexec-zImage-arm64.c
index 3eb1ad8..4e488a5 100644
--- a/kexec/arch/arm64/kexec-zImage-arm64.c
+++ b/kexec/arch/arm64/kexec-zImage-arm64.c
@@ -37,23 +37,15 @@
/* Returns:
* -1 : in case of error/invalid format (not a valid Image.gz format.
- * fd : File descriptor of the temp file containing the decompressed
- * Image.
*/
-int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size)
+int zImage_arm64_probe(const char *kern_fname, struct parsed_info *info)
{
int ret = -1;
int fd = 0;
- int kernel_fd = 0;
char *fname = NULL;
char *kernel_uncompressed_buf = NULL;
const struct arm64_image_header *h;
- if (!is_zlib_file(kernel_buf, &kernel_size)) {
- dbgprintf("%s: Not an zImage file (Image.gz).\n", __func__);
- return -1;
- }
-
if (!(fname = strdup(FILENAME_IMAGE))) {
dbgprintf("%s: Can't duplicate strings\n", __func__);
return -1;
@@ -68,11 +60,11 @@ int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size)
/* slurp in the input kernel */
dbgprintf("%s: ", __func__);
- kernel_uncompressed_buf = slurp_decompress_file(kernel_buf,
- &kernel_size);
+ kernel_uncompressed_buf = slurp_decompress_file(kern_fname,
+ &info->kernel_size);
/* check for correct header magic */
- if (kernel_size < sizeof(struct arm64_image_header)) {
+ if (info->kernel_size < sizeof(struct arm64_image_header)) {
dbgprintf("%s: No arm64 image header.\n", __func__);
ret = -1;
goto fail_bad_header;
@@ -87,7 +79,7 @@ int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size)
}
if (write(fd, kernel_uncompressed_buf,
- kernel_size) != kernel_size) {
+ info->kernel_size) != info->kernel_size) {
dbgprintf("%s: Can't write the uncompressed file %s\n",
__func__, fname);
ret = -1;
@@ -100,20 +92,18 @@ int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size)
* opening the file in O_RDWR and calling kexec_file_load()
* causes the kernel to return -ETXTBSY
*/
- kernel_fd = open(fname, O_RDONLY);
- if (kernel_fd == -1) {
+ info->fd = open(fname, O_RDONLY);
+ if (info->fd == -1) {
dbgprintf("%s: Failed to open file %s\n",
__func__, fname);
ret = -1;
goto fail_bad_header;
}
-
+ info->kernel_buf = kernel_uncompressed_buf;
unlink(fname);
-
- free(kernel_uncompressed_buf);
free(fname);
- return kernel_fd;
+ return 0;
fail_bad_header:
free(kernel_uncompressed_buf);
--
2.31.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCHv5 5/8] kexec: Drop condition macro for aarch64
2023-07-17 13:07 [PATCHv5 0/8] arm64: zboot support Pingfan Liu
` (3 preceding siblings ...)
2023-07-17 13:07 ` [PATCHv5 4/8] arm64: Transfer from probe() to probe2() Pingfan Liu
@ 2023-07-17 13:07 ` Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 6/8] kexec/zboot: Add arch independent zboot support Pingfan Liu
` (3 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Pingfan Liu @ 2023-07-17 13:07 UTC (permalink / raw)
To: kexec; +Cc: Pingfan Liu, horms, ardb, jeremy.linton
Since all arm64 images have transfer from the interface probe() to
probe2(), the snippet dedicated for aarch64 to call probe() can be
dropped now.
Signed-off-by: Pingfan Liu <piliu@redhat.com>
To: kexec@lists.infradead.org
Cc: horms@verge.net.au
Cc: ardb@kernel.org
Cc: jeremy.linton@arm.com
---
kexec/kexec.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 5f75179..3238c19 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -730,17 +730,7 @@ static int probe(struct file_type *ft, const char *kern_fname,
ret = initialze_probe(kern_fname, kernel_buf, kernel_size, kernel_fd);
if (ret == 0) {
-#ifdef __aarch64__
- /* handle Image.gz like cases */
- if (is_zlib_file(kern_fname, &kernel_size)) {
- if ((ret = ft->probe(kern_fname, *kernel_size)) >= 0)
- *kernel_fd = ret;
- } else {
- ret = ft->probe(*kernel_buf, *kernel_size);
- }
-#else
ret = ft->probe(*kernel_buf, *kernel_size);
-#endif
} else if (ret == 1) {
ret = ft->probe2(kern_fname, &info);
*kernel_buf = info.kernel_buf;
--
2.31.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCHv5 6/8] kexec/zboot: Add arch independent zboot support
2023-07-17 13:07 [PATCHv5 0/8] arm64: zboot support Pingfan Liu
` (4 preceding siblings ...)
2023-07-17 13:07 ` [PATCHv5 5/8] kexec: Drop condition macro for aarch64 Pingfan Liu
@ 2023-07-17 13:07 ` Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 7/8] arm64: Add ZBOOT PE containing compressed image support Pingfan Liu
` (2 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Pingfan Liu @ 2023-07-17 13:07 UTC (permalink / raw)
To: kexec; +Cc: Jeremy Linton, Pingfan Liu, horms, ardb
From: Jeremy Linton <jeremy.linton@arm.com>
The linux kernel CONFIG_ZBOOT option creates
self decompressing PE kernel images. So this means
that kexec should have a generic understanding of
the format which may be used by multiple arches.
So lets add an arch independent validation
and decompression routine.
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
[Modified by Pingfan to adapt the new probe interface]
Signed-off-by: Pingfan Liu <piliu@redhat.com>
To: kexec@lists.infradead.org
Cc: horms@verge.net.au
Cc: ardb@kernel.org
Cc: jeremy.linton@arm.com
---
include/kexec-pe-zboot.h | 15 +++++
kexec/Makefile | 1 +
kexec/kexec-pe-zboot.c | 133 +++++++++++++++++++++++++++++++++++++++
3 files changed, 149 insertions(+)
create mode 100644 include/kexec-pe-zboot.h
create mode 100644 kexec/kexec-pe-zboot.c
diff --git a/include/kexec-pe-zboot.h b/include/kexec-pe-zboot.h
new file mode 100644
index 0000000..991fb75
--- /dev/null
+++ b/include/kexec-pe-zboot.h
@@ -0,0 +1,15 @@
+#ifndef __KEXEC_PE_ZBOOT_H__
+#define __KEXEC_PE_ZBOOT_H__
+
+/* see drivers/firmware/efi/libstub/zboot-header.S */
+struct linux_pe_zboot_header {
+ uint32_t mz_magic;
+ uint32_t image_type;
+ uint32_t payload_offset;
+ uint32_t payload_size;
+ uint32_t reserved[2];
+ uint32_t compress_type;
+};
+
+int pez_prepare(const char *crude_buf, off_t buf_sz, struct parsed_info *info);
+#endif
diff --git a/kexec/Makefile b/kexec/Makefile
index 8a52e8d..11682bf 100644
--- a/kexec/Makefile
+++ b/kexec/Makefile
@@ -17,6 +17,7 @@ KEXEC_SRCS_base += kexec/kexec-elf-exec.c
KEXEC_SRCS_base += kexec/kexec-elf-core.c
KEXEC_SRCS_base += kexec/kexec-elf-rel.c
KEXEC_SRCS_base += kexec/kexec-elf-boot.c
+KEXEC_SRCS_base += kexec/kexec-pe-zboot.c
KEXEC_SRCS_base += kexec/kexec-iomem.c
KEXEC_SRCS_base += kexec/firmware_memmap.c
KEXEC_SRCS_base += kexec/crashdump.c
diff --git a/kexec/kexec-pe-zboot.c b/kexec/kexec-pe-zboot.c
new file mode 100644
index 0000000..1420eef
--- /dev/null
+++ b/kexec/kexec-pe-zboot.c
@@ -0,0 +1,133 @@
+/*
+ * Generic PE compressed Image (vmlinuz, ZBOOT) support.
+ *
+ * Several distros use 'make zinstall' with CONFIG_ZBOOT
+ * enabled to create UEFI PE images that contain
+ * a decompressor and a compressed kernel image.
+ *
+ * Currently we cannot use kexec_file_load() to load vmlinuz
+ * PE images that self decompress.
+ *
+ * To support ZBOOT, we should:
+ * a). Copy the compressed contents of vmlinuz to a temporary file.
+ * b). Decompress (gunzip-decompress) the contents inside the
+ * temporary file.
+ * c). Validate the resulting image and write it back to the
+ * temporary file.
+ * d). Pass the 'fd' of the temporary file to the kernel space.
+ *
+ * This module contains the arch independent code for the above,
+ * arch specific PE and image checks should wrap calls
+ * to functions in this module.
+ */
+
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include "kexec.h"
+#include <kexec-pe-zboot.h>
+
+#define FILENAME_IMAGE "/tmp/ImageXXXXXX"
+
+/*
+ * Returns -1 : in case of error/invalid format (not a valid PE+compressed ZBOOT format.
+ *
+ * crude_buf: the content, which is read from the kernel file without any processing
+ */
+int pez_prepare(const char *crude_buf, off_t buf_sz, struct parsed_info *info)
+{
+ int ret = -1;
+ int fd = 0;
+ char *fname = NULL;
+ char *kernel_uncompressed_buf = NULL;
+ off_t decompressed_size = 0;
+ const struct linux_pe_zboot_header *z;
+
+ z = (const struct linux_pe_zboot_header *)(crude_buf);
+
+ if (memcmp(&z->image_type, "zimg", sizeof(z->image_type))) {
+ dbgprintf("%s: PE doesn't contain a compressed kernel.\n", __func__);
+ return -1;
+ }
+
+ /*
+ * At the moment its possible to create images with more compression
+ * algorithms than are supported here, error out if we detect that.
+ */
+ if (memcmp(&z->compress_type, "gzip", 4) &&
+ memcmp(&z->compress_type, "lzma", 4)) {
+ dbgprintf("%s: kexec can only decompress gziped and lzma images.\n", __func__);
+ return -1;
+ }
+
+ if (buf_sz < z->payload_offset + z->payload_size) {
+ dbgprintf("%s: PE too small to contain complete payload.\n", __func__);
+ return -1;
+ }
+
+ if (!(fname = strdup(FILENAME_IMAGE))) {
+ dbgprintf("%s: Can't duplicate strings\n", __func__);
+ return -1;
+ }
+
+ if ((fd = mkstemp(fname)) < 0) {
+ dbgprintf("%s: Can't open file %s\n", __func__, fname);
+ ret = -1;
+ goto fail_mkstemp;
+ }
+
+ if (write(fd, &crude_buf[z->payload_offset],
+ z->payload_size) != z->payload_size) {
+ dbgprintf("%s: Can't write the compressed file %s\n",
+ __func__, fname);
+ ret = -1;
+ goto fail_write;
+ }
+
+ kernel_uncompressed_buf = slurp_decompress_file(fname,
+ &decompressed_size);
+
+ dbgprintf("%s: decompressed size %ld\n", __func__, decompressed_size);
+
+ lseek(fd, 0, SEEK_SET);
+
+ if (write(fd, kernel_uncompressed_buf,
+ decompressed_size) != decompressed_size) {
+ dbgprintf("%s: Can't write the decompressed file %s\n",
+ __func__, fname);
+ ret = -1;
+ goto fail_bad_header;
+ }
+
+ info->fd = open(fname, O_RDONLY);
+ if (info->fd == -1) {
+ dbgprintf("%s: Failed to open file %s\n",
+ __func__, fname);
+ ret = -1;
+ goto fail_bad_header;
+ }
+
+ dbgprintf("%s: ", __func__);
+
+ info->kernel_buf = kernel_uncompressed_buf;
+ info->kernel_size = decompressed_size;
+ ret = 0;
+ goto fail_write;
+
+fail_bad_header:
+ free(kernel_uncompressed_buf);
+
+fail_write:
+ if (fd >= 0)
+ close(fd);
+
+ unlink(fname);
+
+fail_mkstemp:
+ free(fname);
+
+ return ret;
+}
--
2.31.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCHv5 7/8] arm64: Add ZBOOT PE containing compressed image support
2023-07-17 13:07 [PATCHv5 0/8] arm64: zboot support Pingfan Liu
` (5 preceding siblings ...)
2023-07-17 13:07 ` [PATCHv5 6/8] kexec/zboot: Add arch independent zboot support Pingfan Liu
@ 2023-07-17 13:07 ` Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 8/8] arm64: Hook up the ZBOOT support as vmlinuz Pingfan Liu
2023-07-19 3:02 ` [PATCHv5 0/8] arm64: zboot support Dave Young
8 siblings, 0 replies; 15+ messages in thread
From: Pingfan Liu @ 2023-07-17 13:07 UTC (permalink / raw)
To: kexec; +Cc: Jeremy Linton, Pingfan Liu, horms, ardb
From: Jeremy Linton <jeremy.linton@arm.com>
The kernel EFI stub ZBOOT feature creates a PE that
contains a compressed linux kernel image. The stub
when run in a valid UEFI environment then decompresses
the resulting image and executes it.
Support these image formats with kexec as well to avoid
having to keep an alternate kernel image around.
This patch adds a the _probe() and usage() routines needed
for kexec to understand this format.
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
[Modified by Pingfan to adapt the new probe interface]
Signed-off-by: Pingfan Liu <piliu@redhat.com>
To: kexec@lists.infradead.org
Cc: horms@verge.net.au
Cc: ardb@kernel.org
Cc: jeremy.linton@arm.com
---
| 1 +
kexec/arch/arm64/kexec-vmlinuz-arm64.c | 102 +++++++++++++++++++++++++
2 files changed, 103 insertions(+)
create mode 100644 kexec/arch/arm64/kexec-vmlinuz-arm64.c
--git a/kexec/arch/arm64/image-header.h b/kexec/arch/arm64/image-header.h
index 158d411..26bb02f 100644
--- a/kexec/arch/arm64/image-header.h
+++ b/kexec/arch/arm64/image-header.h
@@ -37,6 +37,7 @@ struct arm64_image_header {
static const uint8_t arm64_image_magic[4] = {'A', 'R', 'M', 0x64U};
static const uint8_t arm64_image_pe_sig[2] = {'M', 'Z'};
+static const uint8_t arm64_pe_machtype[6] = {'P','E', 0x0, 0x0, 0x64, 0xAA};
static const uint64_t arm64_image_flag_be = (1UL << 0);
static const uint64_t arm64_image_flag_page_size = (3UL << 1);
static const uint64_t arm64_image_flag_placement = (1UL << 3);
diff --git a/kexec/arch/arm64/kexec-vmlinuz-arm64.c b/kexec/arch/arm64/kexec-vmlinuz-arm64.c
new file mode 100644
index 0000000..30e99a9
--- /dev/null
+++ b/kexec/arch/arm64/kexec-vmlinuz-arm64.c
@@ -0,0 +1,102 @@
+/*
+ * ARM64 PE compressed Image (vmlinuz, ZBOOT) support.
+ *
+ * Several distros use 'make zinstall' rule inside
+ * 'arch/arm64/boot/Makefile' to install the arm64
+ * ZBOOT compressed file inside the boot destination
+ * directory (for e.g. /boot).
+ *
+ * Currently we cannot use kexec_file_load() to load vmlinuz
+ * PE images that self decompress.
+ *
+ * To support ZBOOT, we should:
+ * a). Copy the compressed contents of vmlinuz to a temporary file.
+ * b). Decompress (gunzip-decompress) the contents inside the
+ * temporary file.
+ * c). Validate the resulting image and write it back to the
+ * temporary file.
+ * d). Pass the 'fd' of the temporary file to the kernel space.
+ *
+ * Note this, module doesn't provide a _load() function instead
+ * relying on image_arm64_load() to load the resulting decompressed
+ * image.
+ *
+ * So basically the kernel space still gets a decompressed
+ * kernel image to load via kexec-tools.
+ */
+
+#define _GNU_SOURCE
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "kexec-arm64.h"
+#include <kexec-pe-zboot.h>
+#include "arch/options.h"
+
+
+/* Returns:
+ * -1 : in case of error/invalid format (not a valid PE+compressed ZBOOT format.
+ */
+int pez_arm64_probe(const char *kern_fname, struct parsed_info *info)
+{
+ int ret = -1;
+ const struct arm64_image_header *h;
+ char *buf;
+ off_t buf_sz;
+
+ buf = slurp_file(kern_fname, &buf_sz);
+ if (!buf)
+ return -1;
+ h = (const struct arm64_image_header *)buf;
+
+ dbgprintf("%s: PROBE.\n", __func__);
+ if (buf_sz < sizeof(struct arm64_image_header)) {
+ dbgprintf("%s: Not large enough to be a PE image.\n", __func__);
+ return -1;
+ }
+ if (!arm64_header_check_pe_sig(h)) {
+ dbgprintf("%s: Not an PE image.\n", __func__);
+ return -1;
+ }
+
+ if (buf_sz < sizeof(struct arm64_image_header) + h->pe_header) {
+ dbgprintf("%s: PE image offset larger than image.\n", __func__);
+ return -1;
+ }
+
+ if (memcmp(&buf[h->pe_header],
+ arm64_pe_machtype, sizeof(arm64_pe_machtype))) {
+ dbgprintf("%s: PE header doesn't match machine type.\n", __func__);
+ return -1;
+ }
+
+ /* Output info is filled by this parser */
+ ret = pez_prepare(buf, buf_sz, info);
+
+ if (!ret) {
+ /* validate the arm64 specific header */
+ struct arm64_image_header hdr_check;
+ if (read(info->fd, &hdr_check, sizeof(hdr_check)) != sizeof(hdr_check))
+ goto bad_header;
+
+ lseek(info->fd, 0, SEEK_SET);
+
+ if (!arm64_header_check_magic(&hdr_check)) {
+ dbgprintf("%s: Bad arm64 image header.\n", __func__);
+ goto bad_header;
+ }
+ }
+
+ return ret;
+bad_header:
+ close(info->fd);
+ free(buf);
+ return -1;
+}
+
+void pez_arm64_usage(void)
+{
+ printf(
+" An ARM64 vmlinuz, PE image of a compressed, little endian.\n"
+" kernel, built with ZBOOT enabled.\n\n");
+}
--
2.31.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCHv5 8/8] arm64: Hook up the ZBOOT support as vmlinuz
2023-07-17 13:07 [PATCHv5 0/8] arm64: zboot support Pingfan Liu
` (6 preceding siblings ...)
2023-07-17 13:07 ` [PATCHv5 7/8] arm64: Add ZBOOT PE containing compressed image support Pingfan Liu
@ 2023-07-17 13:07 ` Pingfan Liu
2023-07-19 3:02 ` [PATCHv5 0/8] arm64: zboot support Dave Young
8 siblings, 0 replies; 15+ messages in thread
From: Pingfan Liu @ 2023-07-17 13:07 UTC (permalink / raw)
To: kexec; +Cc: Jeremy Linton, Pingfan Liu, horms, ardb
From: Jeremy Linton <jeremy.linton@arm.com>
Add the previously defined _probe() and _usage() routines
to the kexec file types table, and build the new module.
It should be noted that this "vmlinuz" support reuses the
"Image" support to actually load the resulting image after
it has been decompressed to a temporary file.
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Signed-off-by: Pingfan Liu <piliu@redhat.com>
To: kexec@lists.infradead.org
Cc: horms@verge.net.au
Cc: ardb@kernel.org
Cc: jeremy.linton@arm.com
---
kexec/arch/arm64/Makefile | 3 ++-
kexec/arch/arm64/kexec-arm64.c | 1 +
kexec/arch/arm64/kexec-arm64.h | 3 +++
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/kexec/arch/arm64/Makefile b/kexec/arch/arm64/Makefile
index d27c8ee..900f246 100644
--- a/kexec/arch/arm64/Makefile
+++ b/kexec/arch/arm64/Makefile
@@ -16,7 +16,8 @@ arm64_KEXEC_SRCS += \
kexec/arch/arm64/kexec-elf-arm64.c \
kexec/arch/arm64/kexec-uImage-arm64.c \
kexec/arch/arm64/kexec-image-arm64.c \
- kexec/arch/arm64/kexec-zImage-arm64.c
+ kexec/arch/arm64/kexec-zImage-arm64.c \
+ kexec/arch/arm64/kexec-vmlinuz-arm64.c
arm64_UIMAGE = kexec/kexec-uImage.c
diff --git a/kexec/arch/arm64/kexec-arm64.c b/kexec/arch/arm64/kexec-arm64.c
index f391f77..1812a88 100644
--- a/kexec/arch/arm64/kexec-arm64.c
+++ b/kexec/arch/arm64/kexec-arm64.c
@@ -76,6 +76,7 @@ struct file_type file_type[] = {
{"Image", NULL, image_arm64_load, image_arm64_usage, image_arm64_probe},
{"uImage", NULL, uImage_arm64_load, uImage_arm64_usage, uImage_arm64_probe},
{"zImage", NULL, zImage_arm64_load, zImage_arm64_usage, zImage_arm64_probe},
+ {"vmlinuz", NULL, image_arm64_load, pez_arm64_usage, pez_arm64_probe},
};
int file_types = sizeof(file_type) / sizeof(file_type[0]);
diff --git a/kexec/arch/arm64/kexec-arm64.h b/kexec/arch/arm64/kexec-arm64.h
index eeb35ae..ec8936c 100644
--- a/kexec/arch/arm64/kexec-arm64.h
+++ b/kexec/arch/arm64/kexec-arm64.h
@@ -49,6 +49,9 @@ int zImage_arm64_load(int argc, char **argv, const char *kernel_buf,
off_t kernel_size, struct kexec_info *info);
void zImage_arm64_usage(void);
+int pez_arm64_probe(const char *kern_fname, struct parsed_info *info);
+void pez_arm64_usage(void);
+
extern off_t initrd_base;
extern off_t initrd_size;
--
2.31.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCHv5 0/8] arm64: zboot support
2023-07-17 13:07 [PATCHv5 0/8] arm64: zboot support Pingfan Liu
` (7 preceding siblings ...)
2023-07-17 13:07 ` [PATCHv5 8/8] arm64: Hook up the ZBOOT support as vmlinuz Pingfan Liu
@ 2023-07-19 3:02 ` Dave Young
2023-07-20 2:04 ` Pingfan Liu
8 siblings, 1 reply; 15+ messages in thread
From: Dave Young @ 2023-07-19 3:02 UTC (permalink / raw)
To: Pingfan Liu; +Cc: kexec, horms, ardb, jeremy.linton
Hi Pingfan, Simon,
On 07/17/23 at 09:07pm, Pingfan Liu wrote:
> As more complicated capsule kernel format occurs like zboot, where the
> compressed kernel is stored as a payload. The straight forward
> decompression can not meet the demand.
>
> As the first step, on aarch64, reading in the kernel file in a probe
> method and decide how to unfold the content by the method itself.
>
> This series introduce a new image probe interface probe2(), which
> returns three factors: kernel buffer, kernel size and kernel fd through
> a struct parsed_info.
> -1. the parsed kernel_buf should be returned so that it can be used by
> the image load method later.
> -2. the final fd passed to sys_kexec_file_load, since aarch64 kernel can
> only work with Image format, the outer payload should be stripped and a
> temporary file of Image should be created.
I took a look at the Image.gz file load code, the current code can be
simplified with passing a fd directly instead of creating temp files via
memfd_create with the already decompressed kernel_buf.
The current file load is like below:
do_kexec_file_load():
1.slurp_decompress_file
2. probe
3. load
4. kexec_file_load
In step 1, the Image.gz has been decompressed to kernel_buf, so just
create a virtual memfd copy to it, then save the virtual fd for step 4
use.
Otherwise in step 2 it is some sanity checking, step 3 is setting
something else eg. initrd_fd, cmdline. With the changes below Image and
Image.gz will share same code. I think you can add the zboot
detection/checking code in the Image probe, load functions, with a new
info->kernel_fd, you can decompress the zboot kernel_buf and save to
another virtual memfd, and set to the info->kernel_fd. Then in step 4
the kexec_file_load can just use it.
The kernel_buf itself is only used for sanity checking of the formats,
kernel only needs a file fd, so I think it should be fine and easier
than the original ways.
Thoughts?
---
kexec/arch/arm64/Makefile | 3
kexec/arch/arm64/kexec-arm64.c | 1
kexec/arch/arm64/kexec-arm64.h | 6
kexec/arch/arm64/kexec-image-arm64.c | 2
kexec/arch/arm64/kexec-zImage-arm64.c | 226 ----------------------------------
kexec/kexec.c | 55 +++++---
kexec/kexec.h | 1
7 files changed, 39 insertions(+), 255 deletions(-)
Index: kexec-tools/kexec/arch/arm64/Makefile
===================================================================
--- kexec-tools.orig/kexec/arch/arm64/Makefile
+++ kexec-tools/kexec/arch/arm64/Makefile
@@ -15,8 +15,7 @@ arm64_KEXEC_SRCS += \
kexec/arch/arm64/kexec-arm64.c \
kexec/arch/arm64/kexec-elf-arm64.c \
kexec/arch/arm64/kexec-uImage-arm64.c \
- kexec/arch/arm64/kexec-image-arm64.c \
- kexec/arch/arm64/kexec-zImage-arm64.c
+ kexec/arch/arm64/kexec-image-arm64.c
arm64_UIMAGE = kexec/kexec-uImage.c
Index: kexec-tools/kexec/arch/arm64/kexec-arm64.c
===================================================================
--- kexec-tools.orig/kexec/arch/arm64/kexec-arm64.c
+++ kexec-tools/kexec/arch/arm64/kexec-arm64.c
@@ -74,7 +74,6 @@ struct file_type file_type[] = {
{"vmlinux", elf_arm64_probe, elf_arm64_load, elf_arm64_usage},
{"Image", image_arm64_probe, image_arm64_load, image_arm64_usage},
{"uImage", uImage_arm64_probe, uImage_arm64_load, uImage_arm64_usage},
- {"zImage", zImage_arm64_probe, zImage_arm64_load, zImage_arm64_usage},
};
int file_types = sizeof(file_type) / sizeof(file_type[0]);
Index: kexec-tools/kexec/arch/arm64/kexec-arm64.h
===================================================================
--- kexec-tools.orig/kexec/arch/arm64/kexec-arm64.h
+++ kexec-tools/kexec/arch/arm64/kexec-arm64.h
@@ -44,12 +44,6 @@ int uImage_arm64_load(int argc, char **a
struct kexec_info *info);
void uImage_arm64_usage(void);
-int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size);
-int zImage_arm64_load(int argc, char **argv, const char *kernel_buf,
- off_t kernel_size, struct kexec_info *info);
-void zImage_arm64_usage(void);
-
-
extern off_t initrd_base;
extern off_t initrd_size;
Index: kexec-tools/kexec/arch/arm64/kexec-image-arm64.c
===================================================================
--- kexec-tools.orig/kexec/arch/arm64/kexec-image-arm64.c
+++ kexec-tools/kexec/arch/arm64/kexec-image-arm64.c
@@ -114,6 +114,6 @@ exit:
void image_arm64_usage(void)
{
printf(
-" An ARM64 binary image, uncompressed, big or little endian.\n"
+" An ARM64 binary image, compressed or not, big or little endian.\n"
" Typically an Image file.\n\n");
}
Index: kexec-tools/kexec/arch/arm64/kexec-zImage-arm64.c
===================================================================
--- kexec-tools.orig/kexec/arch/arm64/kexec-zImage-arm64.c
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * ARM64 kexec zImage (Image.gz) support.
- *
- * Several distros use 'make zinstall' rule inside
- * 'arch/arm64/boot/Makefile' to install the arm64
- * Image.gz compressed file inside the boot destination
- * directory (for e.g. /boot).
- *
- * Currently we cannot use kexec_file_load() to load vmlinuz
- * (or Image.gz).
- *
- * To support Image.gz, we should:
- * a). Copy the contents of Image.gz to a temporary file.
- * b). Decompress (gunzip-decompress) the contents inside the
- * temporary file.
- * c). Pass the 'fd' of the temporary file to the kernel space.
- *
- * So basically the kernel space still gets a decompressed
- * kernel image to load via kexec-tools.
- */
-
-#define _GNU_SOURCE
-
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdlib.h>
-#include "crashdump-arm64.h"
-#include "image-header.h"
-#include "kexec.h"
-#include "kexec-arm64.h"
-#include "kexec-syscall.h"
-#include "kexec-zlib.h"
-#include "arch/options.h"
-
-#define FILENAME_IMAGE "/tmp/ImageXXXXXX"
-
-/* Returns:
- * -1 : in case of error/invalid format (not a valid Image.gz format.
- * fd : File descriptor of the temp file containing the decompressed
- * Image.
- */
-int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size)
-{
- int ret = -1;
- int fd = 0;
- int kernel_fd = 0;
- char *fname = NULL;
- char *kernel_uncompressed_buf = NULL;
- const struct arm64_image_header *h;
-
- if (!is_zlib_file(kernel_buf, &kernel_size)) {
- dbgprintf("%s: Not an zImage file (Image.gz).\n", __func__);
- return -1;
- }
-
- if (!(fname = strdup(FILENAME_IMAGE))) {
- dbgprintf("%s: Can't duplicate strings %s\n", __func__,
- fname);
- return -1;
- }
-
- if ((fd = mkstemp(fname)) < 0) {
- dbgprintf("%s: Can't open file %s\n", __func__,
- fname);
- ret = -1;
- goto fail_mkstemp;
- }
-
- kernel_uncompressed_buf =
- (char *) calloc(kernel_size, sizeof(off_t));
- if (!kernel_uncompressed_buf) {
- dbgprintf("%s: Can't calloc %ld bytes\n",
- __func__, kernel_size);
- ret= -ENOMEM;
- goto fail_calloc;
- }
-
- /* slurp in the input kernel */
- dbgprintf("%s: ", __func__);
- kernel_uncompressed_buf = slurp_decompress_file(kernel_buf,
- &kernel_size);
-
- /* check for correct header magic */
- if (kernel_size < sizeof(struct arm64_image_header)) {
- dbgprintf("%s: No arm64 image header.\n", __func__);
- ret = -1;
- goto fail_bad_header;
- }
-
- h = (const struct arm64_image_header *)(kernel_uncompressed_buf);
-
- if (!arm64_header_check_magic(h)) {
- dbgprintf("%s: Bad arm64 image header.\n", __func__);
- ret = -1;
- goto fail_bad_header;
- }
-
- if (write(fd, kernel_uncompressed_buf,
- kernel_size) != kernel_size) {
- dbgprintf("%s: Can't write the uncompressed file %s\n",
- __func__, fname);
- ret = -1;
- goto fail_bad_header;
- }
-
- close(fd);
-
- /* Open the tmp file again, this time in O_RDONLY mode, as
- * opening the file in O_RDWR and calling kexec_file_load()
- * causes the kernel to return -ETXTBSY
- */
- kernel_fd = open(fname, O_RDONLY);
- if (kernel_fd == -1) {
- dbgprintf("%s: Failed to open file %s\n",
- __func__, fname);
- ret = -1;
- goto fail_bad_header;
- }
-
- unlink(fname);
-
- free(kernel_uncompressed_buf);
- free(fname);
-
- return kernel_fd;
-
-fail_bad_header:
- free(kernel_uncompressed_buf);
-
-fail_calloc:
- if (fd >= 0)
- close(fd);
-
- unlink(fname);
-
-fail_mkstemp:
- free(fname);
-
- return ret;
-}
-
-int zImage_arm64_load(int argc, char **argv, const char *kernel_buf,
- off_t kernel_size, struct kexec_info *info)
-{
- const struct arm64_image_header *header;
- unsigned long kernel_segment;
- int result;
-
- if (info->file_mode) {
- if (arm64_opts.initrd) {
- info->initrd_fd = open(arm64_opts.initrd, O_RDONLY);
- if (info->initrd_fd == -1) {
- fprintf(stderr,
- "Could not open initrd file %s:%s\n",
- arm64_opts.initrd, strerror(errno));
- result = EFAILED;
- goto exit;
- }
- }
-
- if (arm64_opts.command_line) {
- info->command_line = (char *)arm64_opts.command_line;
- info->command_line_len =
- strlen(arm64_opts.command_line) + 1;
- }
-
- return 0;
- }
-
- header = (const struct arm64_image_header *)(kernel_buf);
-
- if (arm64_process_image_header(header))
- return EFAILED;
-
- kernel_segment = arm64_locate_kernel_segment(info);
-
- if (kernel_segment == ULONG_MAX) {
- dbgprintf("%s: Kernel segment is not allocated\n", __func__);
- result = EFAILED;
- goto exit;
- }
-
- dbgprintf("%s: kernel_segment: %016lx\n", __func__, kernel_segment);
- dbgprintf("%s: text_offset: %016lx\n", __func__,
- arm64_mem.text_offset);
- dbgprintf("%s: image_size: %016lx\n", __func__,
- arm64_mem.image_size);
- dbgprintf("%s: phys_offset: %016lx\n", __func__,
- arm64_mem.phys_offset);
- dbgprintf("%s: vp_offset: %016lx\n", __func__,
- arm64_mem.vp_offset);
- dbgprintf("%s: PE format: %s\n", __func__,
- (arm64_header_check_pe_sig(header) ? "yes" : "no"));
-
- /* create and initialize elf core header segment */
- if (info->kexec_flags & KEXEC_ON_CRASH) {
- result = load_crashdump_segments(info);
- if (result) {
- dbgprintf("%s: Creating eflcorehdr failed.\n",
- __func__);
- goto exit;
- }
- }
-
- /* load the kernel */
- add_segment_phys_virt(info, kernel_buf, kernel_size,
- kernel_segment + arm64_mem.text_offset,
- arm64_mem.image_size, 0);
-
- /* load additional data */
- result = arm64_load_other_segments(info, kernel_segment
- + arm64_mem.text_offset);
-
-exit:
- if (result)
- fprintf(stderr, "kexec: load failed.\n");
- return result;
-}
-
-void zImage_arm64_usage(void)
-{
- printf(
-" An ARM64 zImage, compressed, big or little endian.\n"
-" Typically an Image.gz or Image.lzma file.\n\n");
-}
Index: kexec-tools/kexec/kexec.c
===================================================================
--- kexec-tools.orig/kexec/kexec.c
+++ kexec-tools/kexec/kexec.c
@@ -638,6 +638,21 @@ char *slurp_decompress_file(const char *
return kernel_buf;
}
+int copybuf_memfd(const char *kernel_buf, size_t size)
+{
+ int fd, count;
+
+ fd = memfd_create("kernel", MFD_ALLOW_SEALING);
+ if (fd == -1)
+ return fd;
+
+ count = write(fd, kernel_buf, size);
+ if (count < 0)
+ return -1;
+
+ return fd;
+}
+
static void update_purgatory(struct kexec_info *info)
{
static const uint8_t null_buf[256];
@@ -1263,7 +1278,7 @@ static int do_kexec_file_load(int filein
unsigned long flags) {
char *kernel;
- int kernel_fd, i;
+ int kernel_fd, i, fd;
struct kexec_info info;
int ret = 0;
char *kernel_buf;
@@ -1277,6 +1292,7 @@ static int do_kexec_file_load(int filein
info.kexec_flags = flags;
info.file_mode = 1;
+ info.kernel_fd = -1;
info.initrd_fd = -1;
if (!is_kexec_file_load_implemented())
@@ -1299,22 +1315,16 @@ static int do_kexec_file_load(int filein
/* slurp in the input kernel */
kernel_buf = slurp_decompress_file(kernel, &kernel_size);
+ fd = copybuf_memfd(kernel_buf, kernel_size);
+ if (fd < 0)
+ fprintf(stderr, "Failed to copy decompressed buf\n");
+ else {
+ kernel_fd = fd;
+ }
for (i = 0; i < file_types; i++) {
-#ifdef __aarch64__
- /* handle Image.gz like cases */
- if (is_zlib_file(kernel, &kernel_size)) {
- if ((ret = file_type[i].probe(kernel, kernel_size)) >= 0) {
- kernel_fd = ret;
- break;
- }
- } else
- if (file_type[i].probe(kernel_buf, kernel_size) >= 0)
- break;
-#else
if (file_type[i].probe(kernel_buf, kernel_size) >= 0)
break;
-#endif
}
if (i == file_types) {
@@ -1324,12 +1334,19 @@ static int do_kexec_file_load(int filein
return EFAILED;
}
- ret = file_type[i].load(argc, argv, kernel_buf, kernel_size, &info);
- if (ret < 0) {
- fprintf(stderr, "Cannot load %s\n", kernel);
- close(kernel_fd);
- return ret;
- }
+ ret = file_type[i].load(argc, argv, kernel_buf, kernel_size, &info);
+ if (ret < 0) {
+ fprintf(stderr, "Cannot load %s\n", kernel);
+ close(kernel_fd);
+ return ret;
+ }
+
+ /*
+ * image type specific load functioin detect the capsule kernel type
+ * and create another fd for file load. For example the zboot kernel.
+ */
+ if (info.kernel_fd != -1)
+ kernel_fd = info.kernel_fd;
/*
* If there is no initramfs, set KEXEC_FILE_NO_INITRAMFS flag so that
Index: kexec-tools/kexec/kexec.h
===================================================================
--- kexec-tools.orig/kexec/kexec.h
+++ kexec-tools/kexec/kexec.h
@@ -164,6 +164,7 @@ struct kexec_info {
unsigned long file_mode :1;
/* Filled by kernel image processing code */
+ int kernel_fd;
int initrd_fd;
char *command_line;
int command_line_len;
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCHv5 0/8] arm64: zboot support
2023-07-19 3:02 ` [PATCHv5 0/8] arm64: zboot support Dave Young
@ 2023-07-20 2:04 ` Pingfan Liu
2023-07-20 7:29 ` Dave Young
0 siblings, 1 reply; 15+ messages in thread
From: Pingfan Liu @ 2023-07-20 2:04 UTC (permalink / raw)
To: Dave Young; +Cc: kexec, horms, ardb, jeremy.linton
Hi Dave,
Thanks for your insight. Please see the comments inline below.
On Wed, Jul 19, 2023 at 11:00 AM Dave Young <dyoung@redhat.com> wrote:
>
> Hi Pingfan, Simon,
>
> On 07/17/23 at 09:07pm, Pingfan Liu wrote:
> > As more complicated capsule kernel format occurs like zboot, where the
> > compressed kernel is stored as a payload. The straight forward
> > decompression can not meet the demand.
> >
> > As the first step, on aarch64, reading in the kernel file in a probe
> > method and decide how to unfold the content by the method itself.
> >
> > This series introduce a new image probe interface probe2(), which
> > returns three factors: kernel buffer, kernel size and kernel fd through
> > a struct parsed_info.
> > -1. the parsed kernel_buf should be returned so that it can be used by
> > the image load method later.
> > -2. the final fd passed to sys_kexec_file_load, since aarch64 kernel can
> > only work with Image format, the outer payload should be stripped and a
> > temporary file of Image should be created.
>
> I took a look at the Image.gz file load code, the current code can be
> simplified with passing a fd directly instead of creating temp files via
> memfd_create with the already decompressed kernel_buf.
>
> The current file load is like below:
>
> do_kexec_file_load():
> 1.slurp_decompress_file
> 2. probe
> 3. load
> 4. kexec_file_load
>
> In step 1, the Image.gz has been decompressed to kernel_buf, so just
> create a virtual memfd copy to it, then save the virtual fd for step 4
> use.
>
> Otherwise in step 2 it is some sanity checking, step 3 is setting
> something else eg. initrd_fd, cmdline. With the changes below Image and
> Image.gz will share same code. I think you can add the zboot
> detection/checking code in the Image probe, load functions, with a new
> info->kernel_fd, you can decompress the zboot kernel_buf and save to
> another virtual memfd, and set to the info->kernel_fd. Then in step 4
> the kexec_file_load can just use it.
>
This only results in a minor change in the interface, not like mine. I
prefer this method.
> The kernel_buf itself is only used for sanity checking of the formats,
> kernel only needs a file fd, so I think it should be fine and easier
> than the original ways.
>
Overall, this new method minimally affects the function interface, in
addition to the code simplification.
I will try to take it in the next version.
> Thoughts?
>
> ---
> kexec/arch/arm64/Makefile | 3
> kexec/arch/arm64/kexec-arm64.c | 1
> kexec/arch/arm64/kexec-arm64.h | 6
> kexec/arch/arm64/kexec-image-arm64.c | 2
> kexec/arch/arm64/kexec-zImage-arm64.c | 226 ----------------------------------
> kexec/kexec.c | 55 +++++---
> kexec/kexec.h | 1
> 7 files changed, 39 insertions(+), 255 deletions(-)
>
> Index: kexec-tools/kexec/arch/arm64/Makefile
> ===================================================================
> --- kexec-tools.orig/kexec/arch/arm64/Makefile
> +++ kexec-tools/kexec/arch/arm64/Makefile
> @@ -15,8 +15,7 @@ arm64_KEXEC_SRCS += \
> kexec/arch/arm64/kexec-arm64.c \
> kexec/arch/arm64/kexec-elf-arm64.c \
> kexec/arch/arm64/kexec-uImage-arm64.c \
> - kexec/arch/arm64/kexec-image-arm64.c \
> - kexec/arch/arm64/kexec-zImage-arm64.c
> + kexec/arch/arm64/kexec-image-arm64.c
>
> arm64_UIMAGE = kexec/kexec-uImage.c
>
> Index: kexec-tools/kexec/arch/arm64/kexec-arm64.c
> ===================================================================
> --- kexec-tools.orig/kexec/arch/arm64/kexec-arm64.c
> +++ kexec-tools/kexec/arch/arm64/kexec-arm64.c
> @@ -74,7 +74,6 @@ struct file_type file_type[] = {
> {"vmlinux", elf_arm64_probe, elf_arm64_load, elf_arm64_usage},
> {"Image", image_arm64_probe, image_arm64_load, image_arm64_usage},
> {"uImage", uImage_arm64_probe, uImage_arm64_load, uImage_arm64_usage},
> - {"zImage", zImage_arm64_probe, zImage_arm64_load, zImage_arm64_usage},
> };
>
> int file_types = sizeof(file_type) / sizeof(file_type[0]);
> Index: kexec-tools/kexec/arch/arm64/kexec-arm64.h
> ===================================================================
> --- kexec-tools.orig/kexec/arch/arm64/kexec-arm64.h
> +++ kexec-tools/kexec/arch/arm64/kexec-arm64.h
> @@ -44,12 +44,6 @@ int uImage_arm64_load(int argc, char **a
> struct kexec_info *info);
> void uImage_arm64_usage(void);
>
> -int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size);
> -int zImage_arm64_load(int argc, char **argv, const char *kernel_buf,
> - off_t kernel_size, struct kexec_info *info);
> -void zImage_arm64_usage(void);
> -
> -
> extern off_t initrd_base;
> extern off_t initrd_size;
>
> Index: kexec-tools/kexec/arch/arm64/kexec-image-arm64.c
> ===================================================================
> --- kexec-tools.orig/kexec/arch/arm64/kexec-image-arm64.c
> +++ kexec-tools/kexec/arch/arm64/kexec-image-arm64.c
> @@ -114,6 +114,6 @@ exit:
> void image_arm64_usage(void)
> {
> printf(
> -" An ARM64 binary image, uncompressed, big or little endian.\n"
> +" An ARM64 binary image, compressed or not, big or little endian.\n"
> " Typically an Image file.\n\n");
> }
> Index: kexec-tools/kexec/arch/arm64/kexec-zImage-arm64.c
> ===================================================================
> --- kexec-tools.orig/kexec/arch/arm64/kexec-zImage-arm64.c
> +++ /dev/null
> @@ -1,226 +0,0 @@
> -/*
> - * ARM64 kexec zImage (Image.gz) support.
> - *
> - * Several distros use 'make zinstall' rule inside
> - * 'arch/arm64/boot/Makefile' to install the arm64
> - * Image.gz compressed file inside the boot destination
> - * directory (for e.g. /boot).
> - *
> - * Currently we cannot use kexec_file_load() to load vmlinuz
> - * (or Image.gz).
> - *
> - * To support Image.gz, we should:
> - * a). Copy the contents of Image.gz to a temporary file.
> - * b). Decompress (gunzip-decompress) the contents inside the
> - * temporary file.
> - * c). Pass the 'fd' of the temporary file to the kernel space.
> - *
> - * So basically the kernel space still gets a decompressed
> - * kernel image to load via kexec-tools.
> - */
> -
> -#define _GNU_SOURCE
> -
> -#include <errno.h>
> -#include <fcntl.h>
> -#include <limits.h>
> -#include <stdlib.h>
> -#include "crashdump-arm64.h"
> -#include "image-header.h"
> -#include "kexec.h"
> -#include "kexec-arm64.h"
> -#include "kexec-syscall.h"
> -#include "kexec-zlib.h"
> -#include "arch/options.h"
> -
> -#define FILENAME_IMAGE "/tmp/ImageXXXXXX"
> -
> -/* Returns:
> - * -1 : in case of error/invalid format (not a valid Image.gz format.
> - * fd : File descriptor of the temp file containing the decompressed
> - * Image.
> - */
> -int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size)
> -{
> - int ret = -1;
> - int fd = 0;
> - int kernel_fd = 0;
> - char *fname = NULL;
> - char *kernel_uncompressed_buf = NULL;
> - const struct arm64_image_header *h;
> -
> - if (!is_zlib_file(kernel_buf, &kernel_size)) {
> - dbgprintf("%s: Not an zImage file (Image.gz).\n", __func__);
> - return -1;
> - }
> -
> - if (!(fname = strdup(FILENAME_IMAGE))) {
> - dbgprintf("%s: Can't duplicate strings %s\n", __func__,
> - fname);
> - return -1;
> - }
> -
> - if ((fd = mkstemp(fname)) < 0) {
> - dbgprintf("%s: Can't open file %s\n", __func__,
> - fname);
> - ret = -1;
> - goto fail_mkstemp;
> - }
> -
> - kernel_uncompressed_buf =
> - (char *) calloc(kernel_size, sizeof(off_t));
> - if (!kernel_uncompressed_buf) {
> - dbgprintf("%s: Can't calloc %ld bytes\n",
> - __func__, kernel_size);
> - ret= -ENOMEM;
> - goto fail_calloc;
> - }
> -
> - /* slurp in the input kernel */
> - dbgprintf("%s: ", __func__);
> - kernel_uncompressed_buf = slurp_decompress_file(kernel_buf,
> - &kernel_size);
> -
> - /* check for correct header magic */
> - if (kernel_size < sizeof(struct arm64_image_header)) {
> - dbgprintf("%s: No arm64 image header.\n", __func__);
> - ret = -1;
> - goto fail_bad_header;
> - }
> -
> - h = (const struct arm64_image_header *)(kernel_uncompressed_buf);
> -
> - if (!arm64_header_check_magic(h)) {
> - dbgprintf("%s: Bad arm64 image header.\n", __func__);
> - ret = -1;
> - goto fail_bad_header;
> - }
> -
> - if (write(fd, kernel_uncompressed_buf,
> - kernel_size) != kernel_size) {
> - dbgprintf("%s: Can't write the uncompressed file %s\n",
> - __func__, fname);
> - ret = -1;
> - goto fail_bad_header;
> - }
> -
> - close(fd);
> -
> - /* Open the tmp file again, this time in O_RDONLY mode, as
> - * opening the file in O_RDWR and calling kexec_file_load()
> - * causes the kernel to return -ETXTBSY
> - */
> - kernel_fd = open(fname, O_RDONLY);
> - if (kernel_fd == -1) {
> - dbgprintf("%s: Failed to open file %s\n",
> - __func__, fname);
> - ret = -1;
> - goto fail_bad_header;
> - }
> -
> - unlink(fname);
> -
> - free(kernel_uncompressed_buf);
> - free(fname);
> -
> - return kernel_fd;
> -
> -fail_bad_header:
> - free(kernel_uncompressed_buf);
> -
> -fail_calloc:
> - if (fd >= 0)
> - close(fd);
> -
> - unlink(fname);
> -
> -fail_mkstemp:
> - free(fname);
> -
> - return ret;
> -}
> -
> -int zImage_arm64_load(int argc, char **argv, const char *kernel_buf,
> - off_t kernel_size, struct kexec_info *info)
> -{
> - const struct arm64_image_header *header;
> - unsigned long kernel_segment;
> - int result;
> -
> - if (info->file_mode) {
> - if (arm64_opts.initrd) {
> - info->initrd_fd = open(arm64_opts.initrd, O_RDONLY);
> - if (info->initrd_fd == -1) {
> - fprintf(stderr,
> - "Could not open initrd file %s:%s\n",
> - arm64_opts.initrd, strerror(errno));
> - result = EFAILED;
> - goto exit;
> - }
> - }
> -
> - if (arm64_opts.command_line) {
> - info->command_line = (char *)arm64_opts.command_line;
> - info->command_line_len =
> - strlen(arm64_opts.command_line) + 1;
> - }
> -
> - return 0;
> - }
> -
> - header = (const struct arm64_image_header *)(kernel_buf);
> -
> - if (arm64_process_image_header(header))
> - return EFAILED;
> -
> - kernel_segment = arm64_locate_kernel_segment(info);
> -
> - if (kernel_segment == ULONG_MAX) {
> - dbgprintf("%s: Kernel segment is not allocated\n", __func__);
> - result = EFAILED;
> - goto exit;
> - }
> -
> - dbgprintf("%s: kernel_segment: %016lx\n", __func__, kernel_segment);
> - dbgprintf("%s: text_offset: %016lx\n", __func__,
> - arm64_mem.text_offset);
> - dbgprintf("%s: image_size: %016lx\n", __func__,
> - arm64_mem.image_size);
> - dbgprintf("%s: phys_offset: %016lx\n", __func__,
> - arm64_mem.phys_offset);
> - dbgprintf("%s: vp_offset: %016lx\n", __func__,
> - arm64_mem.vp_offset);
> - dbgprintf("%s: PE format: %s\n", __func__,
> - (arm64_header_check_pe_sig(header) ? "yes" : "no"));
> -
> - /* create and initialize elf core header segment */
> - if (info->kexec_flags & KEXEC_ON_CRASH) {
> - result = load_crashdump_segments(info);
> - if (result) {
> - dbgprintf("%s: Creating eflcorehdr failed.\n",
> - __func__);
> - goto exit;
> - }
> - }
> -
> - /* load the kernel */
> - add_segment_phys_virt(info, kernel_buf, kernel_size,
> - kernel_segment + arm64_mem.text_offset,
> - arm64_mem.image_size, 0);
> -
> - /* load additional data */
> - result = arm64_load_other_segments(info, kernel_segment
> - + arm64_mem.text_offset);
> -
> -exit:
> - if (result)
> - fprintf(stderr, "kexec: load failed.\n");
> - return result;
> -}
> -
> -void zImage_arm64_usage(void)
> -{
> - printf(
> -" An ARM64 zImage, compressed, big or little endian.\n"
> -" Typically an Image.gz or Image.lzma file.\n\n");
> -}
> Index: kexec-tools/kexec/kexec.c
> ===================================================================
> --- kexec-tools.orig/kexec/kexec.c
> +++ kexec-tools/kexec/kexec.c
> @@ -638,6 +638,21 @@ char *slurp_decompress_file(const char *
> return kernel_buf;
> }
>
> +int copybuf_memfd(const char *kernel_buf, size_t size)
> +{
> + int fd, count;
> +
> + fd = memfd_create("kernel", MFD_ALLOW_SEALING);
> + if (fd == -1)
> + return fd;
> +
> + count = write(fd, kernel_buf, size);
> + if (count < 0)
> + return -1;
> +
> + return fd;
> +}
> +
> static void update_purgatory(struct kexec_info *info)
> {
> static const uint8_t null_buf[256];
> @@ -1263,7 +1278,7 @@ static int do_kexec_file_load(int filein
> unsigned long flags) {
>
> char *kernel;
> - int kernel_fd, i;
> + int kernel_fd, i, fd;
> struct kexec_info info;
> int ret = 0;
> char *kernel_buf;
> @@ -1277,6 +1292,7 @@ static int do_kexec_file_load(int filein
> info.kexec_flags = flags;
>
> info.file_mode = 1;
> + info.kernel_fd = -1;
> info.initrd_fd = -1;
>
> if (!is_kexec_file_load_implemented())
> @@ -1299,22 +1315,16 @@ static int do_kexec_file_load(int filein
>
> /* slurp in the input kernel */
> kernel_buf = slurp_decompress_file(kernel, &kernel_size);
> + fd = copybuf_memfd(kernel_buf, kernel_size);
> + if (fd < 0)
> + fprintf(stderr, "Failed to copy decompressed buf\n");
> + else {
> + kernel_fd = fd;
> + }
>
> for (i = 0; i < file_types; i++) {
> -#ifdef __aarch64__
> - /* handle Image.gz like cases */
> - if (is_zlib_file(kernel, &kernel_size)) {
> - if ((ret = file_type[i].probe(kernel, kernel_size)) >= 0) {
Just a clarification for this:
After removing the condition macro snippet, the later patches, which
implements pez_arm64_probe() should take the original kernel image
instead of kernel file as the first parameter. It is fine.
Thanks,
Pingfan
> - kernel_fd = ret;
> - break;
> - }
> - } else
> - if (file_type[i].probe(kernel_buf, kernel_size) >= 0)
> - break;
> -#else
> if (file_type[i].probe(kernel_buf, kernel_size) >= 0)
> break;
> -#endif
> }
>
> if (i == file_types) {
> @@ -1324,12 +1334,19 @@ static int do_kexec_file_load(int filein
> return EFAILED;
> }
>
> - ret = file_type[i].load(argc, argv, kernel_buf, kernel_size, &info);
> - if (ret < 0) {
> - fprintf(stderr, "Cannot load %s\n", kernel);
> - close(kernel_fd);
> - return ret;
> - }
> + ret = file_type[i].load(argc, argv, kernel_buf, kernel_size, &info);
> + if (ret < 0) {
> + fprintf(stderr, "Cannot load %s\n", kernel);
> + close(kernel_fd);
> + return ret;
> + }
> +
> + /*
> + * image type specific load functioin detect the capsule kernel type
> + * and create another fd for file load. For example the zboot kernel.
> + */
> + if (info.kernel_fd != -1)
> + kernel_fd = info.kernel_fd;
>
> /*
> * If there is no initramfs, set KEXEC_FILE_NO_INITRAMFS flag so that
> Index: kexec-tools/kexec/kexec.h
> ===================================================================
> --- kexec-tools.orig/kexec/kexec.h
> +++ kexec-tools/kexec/kexec.h
> @@ -164,6 +164,7 @@ struct kexec_info {
> unsigned long file_mode :1;
>
> /* Filled by kernel image processing code */
> + int kernel_fd;
> int initrd_fd;
> char *command_line;
> int command_line_len;
>
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCHv5 0/8] arm64: zboot support
2023-07-20 2:04 ` Pingfan Liu
@ 2023-07-20 7:29 ` Dave Young
2023-07-20 8:59 ` Pingfan Liu
0 siblings, 1 reply; 15+ messages in thread
From: Dave Young @ 2023-07-20 7:29 UTC (permalink / raw)
To: Pingfan Liu; +Cc: kexec, horms, ardb, jeremy.linton
Hi Pingfan,
On Thu, 20 Jul 2023 at 10:05, Pingfan Liu <piliu@redhat.com> wrote:
>
> Hi Dave,
>
> Thanks for your insight. Please see the comments inline below.
>
> On Wed, Jul 19, 2023 at 11:00 AM Dave Young <dyoung@redhat.com> wrote:
> >
> > Hi Pingfan, Simon,
> >
> > On 07/17/23 at 09:07pm, Pingfan Liu wrote:
> > > As more complicated capsule kernel format occurs like zboot, where the
> > > compressed kernel is stored as a payload. The straight forward
> > > decompression can not meet the demand.
> > >
> > > As the first step, on aarch64, reading in the kernel file in a probe
> > > method and decide how to unfold the content by the method itself.
> > >
> > > This series introduce a new image probe interface probe2(), which
> > > returns three factors: kernel buffer, kernel size and kernel fd through
> > > a struct parsed_info.
> > > -1. the parsed kernel_buf should be returned so that it can be used by
> > > the image load method later.
> > > -2. the final fd passed to sys_kexec_file_load, since aarch64 kernel can
> > > only work with Image format, the outer payload should be stripped and a
> > > temporary file of Image should be created.
> >
> > I took a look at the Image.gz file load code, the current code can be
> > simplified with passing a fd directly instead of creating temp files via
> > memfd_create with the already decompressed kernel_buf.
> >
> > The current file load is like below:
> >
> > do_kexec_file_load():
> > 1.slurp_decompress_file
> > 2. probe
> > 3. load
> > 4. kexec_file_load
> >
> > In step 1, the Image.gz has been decompressed to kernel_buf, so just
> > create a virtual memfd copy to it, then save the virtual fd for step 4
> > use.
> >
> > Otherwise in step 2 it is some sanity checking, step 3 is setting
> > something else eg. initrd_fd, cmdline. With the changes below Image and
> > Image.gz will share same code. I think you can add the zboot
> > detection/checking code in the Image probe, load functions, with a new
> > info->kernel_fd, you can decompress the zboot kernel_buf and save to
> > another virtual memfd, and set to the info->kernel_fd. Then in step 4
> > the kexec_file_load can just use it.
> >
>
> This only results in a minor change in the interface, not like mine. I
> prefer this method.
>
> > The kernel_buf itself is only used for sanity checking of the formats,
> > kernel only needs a file fd, so I think it should be fine and easier
> > than the original ways.
> >
>
> Overall, this new method minimally affects the function interface, in
> addition to the code simplification.
> I will try to take it in the next version.
>
Ok, great. Btw, it would be ideal if some of the pez_prepare work can
be done early before the slurp_decompress_file in
do_kexec_file_load(), then it could be just arch independent :)
Thanks
Dave
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCHv5 0/8] arm64: zboot support
2023-07-20 7:29 ` Dave Young
@ 2023-07-20 8:59 ` Pingfan Liu
2023-07-20 10:08 ` Dave Young
0 siblings, 1 reply; 15+ messages in thread
From: Pingfan Liu @ 2023-07-20 8:59 UTC (permalink / raw)
To: Dave Young; +Cc: kexec, horms, ardb, jeremy.linton
On Thu, Jul 20, 2023 at 3:27 PM Dave Young <dyoung@redhat.com> wrote:
>
> Hi Pingfan,
>
> On Thu, 20 Jul 2023 at 10:05, Pingfan Liu <piliu@redhat.com> wrote:
> >
> > Hi Dave,
> >
> > Thanks for your insight. Please see the comments inline below.
> >
> > On Wed, Jul 19, 2023 at 11:00 AM Dave Young <dyoung@redhat.com> wrote:
> > >
> > > Hi Pingfan, Simon,
> > >
> > > On 07/17/23 at 09:07pm, Pingfan Liu wrote:
> > > > As more complicated capsule kernel format occurs like zboot, where the
> > > > compressed kernel is stored as a payload. The straight forward
> > > > decompression can not meet the demand.
> > > >
> > > > As the first step, on aarch64, reading in the kernel file in a probe
> > > > method and decide how to unfold the content by the method itself.
> > > >
> > > > This series introduce a new image probe interface probe2(), which
> > > > returns three factors: kernel buffer, kernel size and kernel fd through
> > > > a struct parsed_info.
> > > > -1. the parsed kernel_buf should be returned so that it can be used by
> > > > the image load method later.
> > > > -2. the final fd passed to sys_kexec_file_load, since aarch64 kernel can
> > > > only work with Image format, the outer payload should be stripped and a
> > > > temporary file of Image should be created.
> > >
> > > I took a look at the Image.gz file load code, the current code can be
> > > simplified with passing a fd directly instead of creating temp files via
> > > memfd_create with the already decompressed kernel_buf.
> > >
> > > The current file load is like below:
> > >
> > > do_kexec_file_load():
> > > 1.slurp_decompress_file
> > > 2. probe
> > > 3. load
> > > 4. kexec_file_load
> > >
> > > In step 1, the Image.gz has been decompressed to kernel_buf, so just
> > > create a virtual memfd copy to it, then save the virtual fd for step 4
> > > use.
> > >
> > > Otherwise in step 2 it is some sanity checking, step 3 is setting
> > > something else eg. initrd_fd, cmdline. With the changes below Image and
> > > Image.gz will share same code. I think you can add the zboot
> > > detection/checking code in the Image probe, load functions, with a new
> > > info->kernel_fd, you can decompress the zboot kernel_buf and save to
> > > another virtual memfd, and set to the info->kernel_fd. Then in step 4
> > > the kexec_file_load can just use it.
> > >
> >
> > This only results in a minor change in the interface, not like mine. I
> > prefer this method.
> >
> > > The kernel_buf itself is only used for sanity checking of the formats,
> > > kernel only needs a file fd, so I think it should be fine and easier
> > > than the original ways.
> > >
> >
> > Overall, this new method minimally affects the function interface, in
> > addition to the code simplification.
> > I will try to take it in the next version.
> >
> Ok, great. Btw, it would be ideal if some of the pez_prepare work can
> be done early before the slurp_decompress_file in
> do_kexec_file_load(), then it could be just arch independent :)
>
I assume that you suggest the following big picture:
if trying slurp_decompress_file()
else trying pez_prepare()
for (i = 0; i < file_types; i++) {
if (file_type[i].probe(kernel_buf, kernel_size) >= 0)
}
But there is some check before pez_prepare() in pez_arm64_probe(), I
am not sure whether they can be skipped or not.
BTW, I have a preview version, which takes in your patch at
https://github.com/pfliu/kexec-tools, branch: zbootV6.
Thanks,
Pingfan
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCHv5 0/8] arm64: zboot support
2023-07-20 8:59 ` Pingfan Liu
@ 2023-07-20 10:08 ` Dave Young
2023-07-20 10:08 ` Dave Young
0 siblings, 1 reply; 15+ messages in thread
From: Dave Young @ 2023-07-20 10:08 UTC (permalink / raw)
To: Pingfan Liu; +Cc: kexec, horms, ardb, jeremy.linton
On Thu, 20 Jul 2023 at 16:59, Pingfan Liu <piliu@redhat.com> wrote:
>
> On Thu, Jul 20, 2023 at 3:27 PM Dave Young <dyoung@redhat.com> wrote:
> >
> > Hi Pingfan,
> >
> > On Thu, 20 Jul 2023 at 10:05, Pingfan Liu <piliu@redhat.com> wrote:
> > >
> > > Hi Dave,
> > >
> > > Thanks for your insight. Please see the comments inline below.
> > >
> > > On Wed, Jul 19, 2023 at 11:00 AM Dave Young <dyoung@redhat.com> wrote:
> > > >
> > > > Hi Pingfan, Simon,
> > > >
> > > > On 07/17/23 at 09:07pm, Pingfan Liu wrote:
> > > > > As more complicated capsule kernel format occurs like zboot, where the
> > > > > compressed kernel is stored as a payload. The straight forward
> > > > > decompression can not meet the demand.
> > > > >
> > > > > As the first step, on aarch64, reading in the kernel file in a probe
> > > > > method and decide how to unfold the content by the method itself.
> > > > >
> > > > > This series introduce a new image probe interface probe2(), which
> > > > > returns three factors: kernel buffer, kernel size and kernel fd through
> > > > > a struct parsed_info.
> > > > > -1. the parsed kernel_buf should be returned so that it can be used by
> > > > > the image load method later.
> > > > > -2. the final fd passed to sys_kexec_file_load, since aarch64 kernel can
> > > > > only work with Image format, the outer payload should be stripped and a
> > > > > temporary file of Image should be created.
> > > >
> > > > I took a look at the Image.gz file load code, the current code can be
> > > > simplified with passing a fd directly instead of creating temp files via
> > > > memfd_create with the already decompressed kernel_buf.
> > > >
> > > > The current file load is like below:
> > > >
> > > > do_kexec_file_load():
> > > > 1.slurp_decompress_file
> > > > 2. probe
> > > > 3. load
> > > > 4. kexec_file_load
> > > >
> > > > In step 1, the Image.gz has been decompressed to kernel_buf, so just
> > > > create a virtual memfd copy to it, then save the virtual fd for step 4
> > > > use.
> > > >
> > > > Otherwise in step 2 it is some sanity checking, step 3 is setting
> > > > something else eg. initrd_fd, cmdline. With the changes below Image and
> > > > Image.gz will share same code. I think you can add the zboot
> > > > detection/checking code in the Image probe, load functions, with a new
> > > > info->kernel_fd, you can decompress the zboot kernel_buf and save to
> > > > another virtual memfd, and set to the info->kernel_fd. Then in step 4
> > > > the kexec_file_load can just use it.
> > > >
> > >
> > > This only results in a minor change in the interface, not like mine. I
> > > prefer this method.
> > >
> > > > The kernel_buf itself is only used for sanity checking of the formats,
> > > > kernel only needs a file fd, so I think it should be fine and easier
> > > > than the original ways.
> > > >
> > >
> > > Overall, this new method minimally affects the function interface, in
> > > addition to the code simplification.
> > > I will try to take it in the next version.
> > >
> > Ok, great. Btw, it would be ideal if some of the pez_prepare work can
> > be done early before the slurp_decompress_file in
> > do_kexec_file_load(), then it could be just arch independent :)
> >
>
> I assume that you suggest the following big picture:
> if trying slurp_decompress_file()
> else trying pez_prepare()
> for (i = 0; i < file_types; i++) {
> if (file_type[i].probe(kernel_buf, kernel_size) >= 0)
> }
>
> But there is some check before pez_prepare() in pez_arm64_probe(), I
> am not sure whether they can be skipped or not.
Ok, got it, if the zimage header of arm64 is arch specific , it should
still go to the arch part.
Thanks
Dave
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCHv5 0/8] arm64: zboot support
2023-07-20 10:08 ` Dave Young
@ 2023-07-20 10:08 ` Dave Young
0 siblings, 0 replies; 15+ messages in thread
From: Dave Young @ 2023-07-20 10:08 UTC (permalink / raw)
To: Pingfan Liu; +Cc: kexec, horms, ardb, jeremy.linton
On Thu, 20 Jul 2023 at 18:08, Dave Young <dyoung@redhat.com> wrote:
>
> On Thu, 20 Jul 2023 at 16:59, Pingfan Liu <piliu@redhat.com> wrote:
> >
> > On Thu, Jul 20, 2023 at 3:27 PM Dave Young <dyoung@redhat.com> wrote:
> > >
> > > Hi Pingfan,
> > >
> > > On Thu, 20 Jul 2023 at 10:05, Pingfan Liu <piliu@redhat.com> wrote:
> > > >
> > > > Hi Dave,
> > > >
> > > > Thanks for your insight. Please see the comments inline below.
> > > >
> > > > On Wed, Jul 19, 2023 at 11:00 AM Dave Young <dyoung@redhat.com> wrote:
> > > > >
> > > > > Hi Pingfan, Simon,
> > > > >
> > > > > On 07/17/23 at 09:07pm, Pingfan Liu wrote:
> > > > > > As more complicated capsule kernel format occurs like zboot, where the
> > > > > > compressed kernel is stored as a payload. The straight forward
> > > > > > decompression can not meet the demand.
> > > > > >
> > > > > > As the first step, on aarch64, reading in the kernel file in a probe
> > > > > > method and decide how to unfold the content by the method itself.
> > > > > >
> > > > > > This series introduce a new image probe interface probe2(), which
> > > > > > returns three factors: kernel buffer, kernel size and kernel fd through
> > > > > > a struct parsed_info.
> > > > > > -1. the parsed kernel_buf should be returned so that it can be used by
> > > > > > the image load method later.
> > > > > > -2. the final fd passed to sys_kexec_file_load, since aarch64 kernel can
> > > > > > only work with Image format, the outer payload should be stripped and a
> > > > > > temporary file of Image should be created.
> > > > >
> > > > > I took a look at the Image.gz file load code, the current code can be
> > > > > simplified with passing a fd directly instead of creating temp files via
> > > > > memfd_create with the already decompressed kernel_buf.
> > > > >
> > > > > The current file load is like below:
> > > > >
> > > > > do_kexec_file_load():
> > > > > 1.slurp_decompress_file
> > > > > 2. probe
> > > > > 3. load
> > > > > 4. kexec_file_load
> > > > >
> > > > > In step 1, the Image.gz has been decompressed to kernel_buf, so just
> > > > > create a virtual memfd copy to it, then save the virtual fd for step 4
> > > > > use.
> > > > >
> > > > > Otherwise in step 2 it is some sanity checking, step 3 is setting
> > > > > something else eg. initrd_fd, cmdline. With the changes below Image and
> > > > > Image.gz will share same code. I think you can add the zboot
> > > > > detection/checking code in the Image probe, load functions, with a new
> > > > > info->kernel_fd, you can decompress the zboot kernel_buf and save to
> > > > > another virtual memfd, and set to the info->kernel_fd. Then in step 4
> > > > > the kexec_file_load can just use it.
> > > > >
> > > >
> > > > This only results in a minor change in the interface, not like mine. I
> > > > prefer this method.
> > > >
> > > > > The kernel_buf itself is only used for sanity checking of the formats,
> > > > > kernel only needs a file fd, so I think it should be fine and easier
> > > > > than the original ways.
> > > > >
> > > >
> > > > Overall, this new method minimally affects the function interface, in
> > > > addition to the code simplification.
> > > > I will try to take it in the next version.
> > > >
> > > Ok, great. Btw, it would be ideal if some of the pez_prepare work can
> > > be done early before the slurp_decompress_file in
> > > do_kexec_file_load(), then it could be just arch independent :)
> > >
> >
> > I assume that you suggest the following big picture:
> > if trying slurp_decompress_file()
> > else trying pez_prepare()
> > for (i = 0; i < file_types; i++) {
> > if (file_type[i].probe(kernel_buf, kernel_size) >= 0)
> > }
> >
> > But there is some check before pez_prepare() in pez_arm64_probe(), I
> > am not sure whether they can be skipped or not.
>
> Ok, got it, if the zimage header of arm64 is arch specific , it should
s/zimage/zboot
> still go to the arch part.
>
> Thanks
> Dave
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2023-07-20 10:07 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-17 13:07 [PATCHv5 0/8] arm64: zboot support Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 1/8] arm64: Fix some issues with zImage _probe() Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 2/8] kexec: Isolate probe method Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 3/8] kexec: Introduce a new image probe method 'probe2' Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 4/8] arm64: Transfer from probe() to probe2() Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 5/8] kexec: Drop condition macro for aarch64 Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 6/8] kexec/zboot: Add arch independent zboot support Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 7/8] arm64: Add ZBOOT PE containing compressed image support Pingfan Liu
2023-07-17 13:07 ` [PATCHv5 8/8] arm64: Hook up the ZBOOT support as vmlinuz Pingfan Liu
2023-07-19 3:02 ` [PATCHv5 0/8] arm64: zboot support Dave Young
2023-07-20 2:04 ` Pingfan Liu
2023-07-20 7:29 ` Dave Young
2023-07-20 8:59 ` Pingfan Liu
2023-07-20 10:08 ` Dave Young
2023-07-20 10:08 ` Dave Young
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox