All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv6 0/5] arm64: zboot support
@ 2023-07-24  2:21 Pingfan Liu
  2023-07-24  2:21 ` [PATCHv6 1/5] kexec/arm64: Simplify the code for zImage Pingfan Liu
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Pingfan Liu @ 2023-07-24  2:21 UTC (permalink / raw)
  To: kexec; +Cc: Pingfan Liu, Dave Young, 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 consists of two parts
[1/5], simplify the current aarch64 image probe
[2-5/5], return the kernel fd by the image load interface, and let the
handling of zboot image built on it. (Thanks for Dave Young, who
contributes the original idea and the code)
 
 
To ease the review, a branch is accessable at https://github.com/pfliu/kexec-tools.git
branch zbootV6
 
To: kexec@lists.infradead.org
Cc: Dave Young <dyoung@redhat.com>
Cc: horms@verge.net.au
Cc: ardb@kernel.org
Cc: jeremy.linton@arm.com
---
v5 -> v6
  introduce kexec_info.kernel_fd and return the fd through image load
interface.

Jeremy Linton (3):
  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 (2):
  kexec/arm64: Simplify the code for zImage
  kexec: Introduce a member kernel_fd in kexec_info

 include/kexec-pe-zboot.h               |  15 ++
 kexec/Makefile                         |   1 +
 kexec/arch/arm64/Makefile              |   2 +-
 kexec/arch/arm64/image-header.h        |   1 +
 kexec/arch/arm64/kexec-arm64.c         |   2 +-
 kexec/arch/arm64/kexec-arm64.h         |   8 +-
 kexec/arch/arm64/kexec-image-arm64.c   |   2 +-
 kexec/arch/arm64/kexec-vmlinuz-arm64.c | 110 ++++++++++++
 kexec/arch/arm64/kexec-zImage-arm64.c  | 226 -------------------------
 kexec/kexec-pe-zboot.c                 | 131 ++++++++++++++
 kexec/kexec.c                          |  50 ++++--
 kexec/kexec.h                          |   1 +
 12 files changed, 298 insertions(+), 251 deletions(-)
 create mode 100644 include/kexec-pe-zboot.h
 create mode 100644 kexec/arch/arm64/kexec-vmlinuz-arm64.c
 delete mode 100644 kexec/arch/arm64/kexec-zImage-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] 13+ messages in thread

* [PATCHv6 1/5] kexec/arm64: Simplify the code for zImage
  2023-07-24  2:21 [PATCHv6 0/5] arm64: zboot support Pingfan Liu
@ 2023-07-24  2:21 ` Pingfan Liu
  2023-07-24  2:21 ` [PATCHv6 2/5] kexec: Introduce a member kernel_fd in kexec_info Pingfan Liu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Pingfan Liu @ 2023-07-24  2:21 UTC (permalink / raw)
  To: kexec; +Cc: Pingfan Liu, Dave Young, horms, ardb, jeremy.linton

Inside zimage_probe(), it uncompresses the kernel and performs some
check, similar to image_probe(). Taking a close look, the uncompressing
has already executed before the image probe is called. What is missing
here is to provide a fd, pointing to an uncompressed kernel image.

This patch creates a memfd based on the result produced by
slurp_decompress_file(), and finally simplify the logical of the probe
for aarch64.

The credit goes to the Dave Young, who contributes the original code.

Signed-off-by: Pingfan Liu <piliu@redhat.com>
Co-authored-by: Dave Young <dyoung@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        |   6 -
 kexec/arch/arm64/kexec-image-arm64.c  |   2 +-
 kexec/arch/arm64/kexec-zImage-arm64.c | 226 --------------------------
 kexec/kexec.c                         |  42 +++--
 6 files changed, 26 insertions(+), 254 deletions(-)
 delete mode 100644 kexec/arch/arm64/kexec-zImage-arm64.c

diff --git a/kexec/arch/arm64/Makefile b/kexec/arch/arm64/Makefile
index d27c8ee..9d9111c 100644
--- a/kexec/arch/arm64/Makefile
+++ b/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
 
diff --git a/kexec/arch/arm64/kexec-arm64.c b/kexec/arch/arm64/kexec-arm64.c
index ec6df4b..a830ec7 100644
--- a/kexec/arch/arm64/kexec-arm64.c
+++ b/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]);
diff --git a/kexec/arch/arm64/kexec-arm64.h b/kexec/arch/arm64/kexec-arm64.h
index 5eb9fc0..d29b1b3 100644
--- a/kexec/arch/arm64/kexec-arm64.h
+++ b/kexec/arch/arm64/kexec-arm64.h
@@ -44,12 +44,6 @@ 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_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;
 
diff --git a/kexec/arch/arm64/kexec-image-arm64.c b/kexec/arch/arm64/kexec-image-arm64.c
index aa8f2e2..a196747 100644
--- a/kexec/arch/arm64/kexec-image-arm64.c
+++ b/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");
 }
diff --git a/kexec/arch/arm64/kexec-zImage-arm64.c b/kexec/arch/arm64/kexec-zImage-arm64.c
deleted file mode 100644
index 6ee82ff..0000000
--- a/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");
-}
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 36bb2ad..d132eb5 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -638,6 +638,21 @@ char *slurp_decompress_file(const char *filename, off_t *r_size)
 	return kernel_buf;
 }
 
+static 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];
@@ -1290,31 +1305,22 @@ 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,
+	/* slurp in the input kernel */
+	kernel_buf = slurp_decompress_file(kernel, &kernel_size);
+	if (!kernel_buf) {
+		fprintf(stderr, "Failed to decompress file %s:%s\n", kernel,
 				strerror(errno));
 		return EFAILED;
 	}
-
-	/* slurp in the input kernel */
-	kernel_buf = slurp_decompress_file(kernel, &kernel_size);
+	kernel_fd = copybuf_memfd(kernel_buf, kernel_size);
+	if (kernel_fd < 0) {
+		fprintf(stderr, "Failed to copy decompressed buf\n");
+		return EFAILED;
+	}
 
 	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) {
-- 
2.31.1


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

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

* [PATCHv6 2/5] kexec: Introduce a member kernel_fd in kexec_info
  2023-07-24  2:21 [PATCHv6 0/5] arm64: zboot support Pingfan Liu
  2023-07-24  2:21 ` [PATCHv6 1/5] kexec/arm64: Simplify the code for zImage Pingfan Liu
@ 2023-07-24  2:21 ` Pingfan Liu
  2023-07-24  2:21 ` [PATCHv6 3/5] kexec/zboot: Add arch independent zboot support Pingfan Liu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Pingfan Liu @ 2023-07-24  2:21 UTC (permalink / raw)
  To: kexec; +Cc: Pingfan Liu, Dave Young, horms, ardb, jeremy.linton

Utilize the image load interface to export the kernel fd, which points
to the uncompressed kernel and will be passed to kexec_file_load.

The credit goes to the Dave Young, who contributes the original code.

Signed-off-by: Pingfan Liu <piliu@redhat.com>
Co-authored-by: Dave Young <dyoung@redhat.com>
To: kexec@lists.infradead.org
Cc: horms@verge.net.au
Cc: ardb@kernel.org
Cc: jeremy.linton@arm.com
---
 kexec/kexec.c | 8 ++++++++
 kexec/kexec.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/kexec/kexec.c b/kexec/kexec.c
index d132eb5..c3b182e 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -1292,6 +1292,7 @@ static int do_kexec_file_load(int fileind, int argc, char **argv,
 	info.kexec_flags = flags;
 
 	info.file_mode = 1;
+	info.kernel_fd = -1;
 	info.initrd_fd = -1;
 
 	if (!is_kexec_file_load_implemented())
@@ -1337,6 +1338,13 @@ static int do_kexec_file_load(int fileind, int argc, char **argv,
 		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
 	 * kernel does not return error with negative initrd_fd.
diff --git a/kexec/kexec.h b/kexec/kexec.h
index 0d820ad..ed3b499 100644
--- a/kexec/kexec.h
+++ b/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;
-- 
2.31.1


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

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

* [PATCHv6 3/5] kexec/zboot: Add arch independent zboot support
  2023-07-24  2:21 [PATCHv6 0/5] arm64: zboot support Pingfan Liu
  2023-07-24  2:21 ` [PATCHv6 1/5] kexec/arm64: Simplify the code for zImage Pingfan Liu
  2023-07-24  2:21 ` [PATCHv6 2/5] kexec: Introduce a member kernel_fd in kexec_info Pingfan Liu
@ 2023-07-24  2:21 ` Pingfan Liu
  2023-08-01  7:00   ` Simon Horman
  2023-07-24  2:21 ` [PATCHv6 4/5] arm64: Add ZBOOT PE containing compressed image support Pingfan Liu
  2023-07-24  2:21 ` [PATCHv6 5/5] arm64: Hook up the ZBOOT support as vmlinuz Pingfan Liu
  4 siblings, 1 reply; 13+ messages in thread
From: Pingfan Liu @ 2023-07-24  2:21 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 export kernel fd]
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   | 131 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 147 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..c588ca2
--- /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, int *kernel_fd);
+#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..2f2e052
--- /dev/null
+++ b/kexec/kexec-pe-zboot.c
@@ -0,0 +1,131 @@
+/*
+ * 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, int *kernel_fd)
+{
+	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;
+	}
+
+	*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;
+	}
+
+	dbgprintf("%s: done\n", __func__);
+
+	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] 13+ messages in thread

* [PATCHv6 4/5] arm64: Add ZBOOT PE containing compressed image support
  2023-07-24  2:21 [PATCHv6 0/5] arm64: zboot support Pingfan Liu
                   ` (2 preceding siblings ...)
  2023-07-24  2:21 ` [PATCHv6 3/5] kexec/zboot: Add arch independent zboot support Pingfan Liu
@ 2023-07-24  2:21 ` Pingfan Liu
  2023-07-24  2:21 ` [PATCHv6 5/5] arm64: Hook up the ZBOOT support as vmlinuz Pingfan Liu
  4 siblings, 0 replies; 13+ messages in thread
From: Pingfan Liu @ 2023-07-24  2:21 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(), _load() and usage() routines needed for
kexec to understand this format.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
[Modified by Pingfan to export kernel fd with load method]
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/image-header.h        |   1 +
 kexec/arch/arm64/kexec-vmlinuz-arm64.c | 110 +++++++++++++++++++++++++
 2 files changed, 111 insertions(+)
 create mode 100644 kexec/arch/arm64/kexec-vmlinuz-arm64.c

diff --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..c0ee47c
--- /dev/null
+++ b/kexec/arch/arm64/kexec-vmlinuz-arm64.c
@@ -0,0 +1,110 @@
+/*
+ * 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"
+
+static int kernel_fd = -1;
+
+/* Returns:
+ * -1 : in case of error/invalid format (not a valid PE+compressed ZBOOT format.
+ */
+int pez_arm64_probe(const char *kernel_buf, off_t kernel_size)
+{
+	int ret = -1;
+	const struct arm64_image_header *h;
+	char *buf;
+	off_t buf_sz;
+
+	buf = (char *)kernel_buf;
+	buf_sz = kernel_size;
+	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;
+	}
+
+	ret = pez_prepare(buf, buf_sz, &kernel_fd);
+
+	if (!ret) {
+	    /* validate the arm64 specific header */
+	    struct arm64_image_header hdr_check;
+	    if (read(kernel_fd, &hdr_check, sizeof(hdr_check)) != sizeof(hdr_check))
+		goto bad_header;
+
+	    lseek(kernel_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(kernel_fd);
+	free(buf);
+	return -1;
+}
+
+int pez_arm64_load(int argc, char **argv, const char *buf, off_t len,
+			struct kexec_info *info)
+{
+	info->kernel_fd = kernel_fd;
+	return image_arm64_load(argc, argv, buf, len, info);
+}
+
+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] 13+ messages in thread

* [PATCHv6 5/5] arm64: Hook up the ZBOOT support as vmlinuz
  2023-07-24  2:21 [PATCHv6 0/5] arm64: zboot support Pingfan Liu
                   ` (3 preceding siblings ...)
  2023-07-24  2:21 ` [PATCHv6 4/5] arm64: Add ZBOOT PE containing compressed image support Pingfan Liu
@ 2023-07-24  2:21 ` Pingfan Liu
  4 siblings, 0 replies; 13+ messages in thread
From: Pingfan Liu @ 2023-07-24  2:21 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 | 6 ++++++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/kexec/arch/arm64/Makefile b/kexec/arch/arm64/Makefile
index 9d9111c..59212f1 100644
--- a/kexec/arch/arm64/Makefile
+++ b/kexec/arch/arm64/Makefile
@@ -15,7 +15,8 @@ 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-image-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 a830ec7..4a67b0d 100644
--- a/kexec/arch/arm64/kexec-arm64.c
+++ b/kexec/arch/arm64/kexec-arm64.c
@@ -74,6 +74,7 @@ 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},
+	{"vmlinuz", pez_arm64_probe, pez_arm64_load, pez_arm64_usage},
 };
 
 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 d29b1b3..95fb5c2 100644
--- a/kexec/arch/arm64/kexec-arm64.h
+++ b/kexec/arch/arm64/kexec-arm64.h
@@ -44,6 +44,12 @@ int uImage_arm64_load(int argc, char **argv, const char *buf, off_t len,
 		      struct kexec_info *info);
 void uImage_arm64_usage(void);
 
+int pez_arm64_probe(const char *kernel_buf, off_t kernel_size);
+int pez_arm64_load(int argc, char **argv, const char *buf, off_t len,
+			struct kexec_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] 13+ messages in thread

* Re: [PATCHv6 3/5] kexec/zboot: Add arch independent zboot support
  2023-07-24  2:21 ` [PATCHv6 3/5] kexec/zboot: Add arch independent zboot support Pingfan Liu
@ 2023-08-01  7:00   ` Simon Horman
  2023-08-02  9:53     ` Pingfan Liu
  0 siblings, 1 reply; 13+ messages in thread
From: Simon Horman @ 2023-08-01  7:00 UTC (permalink / raw)
  To: Pingfan Liu; +Cc: kexec, Jeremy Linton, horms, ardb

On Mon, Jul 24, 2023 at 10:21:40AM +0800, Pingfan Liu wrote:
> 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 export kernel fd]
> Signed-off-by: Pingfan Liu <piliu@redhat.com>

Hi Pingfan,

unfortunately this causes a build failure on hppa.

../../kexec/kexec-pe-zboot.c:31:10: fatal error: kexec-pe-zboot.h: No such file or directory
   31 | #include <kexec-pe-zboot.h>
      |          ^~~~~~~~~~~~~~~~~~

Link: https://github.com/horms/kexec-tools/actions/runs/5723580523/job/15508425790

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

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

* Re: [PATCHv6 3/5] kexec/zboot: Add arch independent zboot support
  2023-08-01  7:00   ` Simon Horman
@ 2023-08-02  9:53     ` Pingfan Liu
  2023-08-02 12:16       ` Simon Horman
  0 siblings, 1 reply; 13+ messages in thread
From: Pingfan Liu @ 2023-08-02  9:53 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec, Jeremy Linton, horms, ardb

Hi Simon,

Thanks for the try. Please see the comment below.

On Tue, Aug 1, 2023 at 3:00 PM Simon Horman <horms@kernel.org> wrote:
>
> On Mon, Jul 24, 2023 at 10:21:40AM +0800, Pingfan Liu wrote:
> > 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 export kernel fd]
> > Signed-off-by: Pingfan Liu <piliu@redhat.com>
>
> Hi Pingfan,
>
> unfortunately this causes a build failure on hppa.
>
> ../../kexec/kexec-pe-zboot.c:31:10: fatal error: kexec-pe-zboot.h: No such file or directory
>    31 | #include <kexec-pe-zboot.h>
>       |          ^~~~~~~~~~~~~~~~~~
>
> Link: https://github.com/horms/kexec-tools/actions/runs/5723580523/job/15508425790
>

It is not related to cross-compiling. Actually, I have tried to
simplify the test matrix, which limits the compilation only on x86_64.
And I got the similar error [1]

The workflow control file is [2], which clips out all arches except
x86_64.  But I can successfully build it on the Fedora system with the
following bash script, which is based on the github's build log.  So
maybe it is a bug with the compiling tools?

kexec_tools_dir="./"

mkdir $kexec_tools_dir/_build \
         $kexec_tools_dir/_build/sub \
         $kexec_tools_dir/_inst \
         $kexec_tools_dir/_dest
chmod a-w $kexec_tools_dir
test -d $kexec_tools_dir/_build
INSTALL_BASE=$(cd $kexec_tools_dir/_inst && pwd | sed -e
's,^[^:\\/]:[\\/],/,') &&\
        DESTDIR="$kexec_tools_dir/_dest" && \
        cd $kexec_tools_dir/_build/sub && \
                ../../configure \
                 \
                --srcdir=../.. --prefix="$INSTALL_BASE" && \
        make  -j8


[1]: https://github.com/pfliu/kexec-tools/actions/runs/5737254109/job/15548520863
[2]: https://github.com/pfliu/kexec-tools/blob/zbootV6/.github/workflows/main.yml


Thanks,

Pingfan


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

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

* Re: [PATCHv6 3/5] kexec/zboot: Add arch independent zboot support
  2023-08-02  9:53     ` Pingfan Liu
@ 2023-08-02 12:16       ` Simon Horman
  2023-08-02 12:17         ` Simon Horman
  0 siblings, 1 reply; 13+ messages in thread
From: Simon Horman @ 2023-08-02 12:16 UTC (permalink / raw)
  To: Pingfan Liu; +Cc: kexec, Jeremy Linton, horms, ardb

On Wed, Aug 02, 2023 at 05:53:59PM +0800, Pingfan Liu wrote:
> Hi Simon,
> 
> Thanks for the try. Please see the comment below.
> 
> On Tue, Aug 1, 2023 at 3:00 PM Simon Horman <horms@kernel.org> wrote:
> >
> > On Mon, Jul 24, 2023 at 10:21:40AM +0800, Pingfan Liu wrote:
> > > 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 export kernel fd]
> > > Signed-off-by: Pingfan Liu <piliu@redhat.com>
> >
> > Hi Pingfan,
> >
> > unfortunately this causes a build failure on hppa.
> >
> > ../../kexec/kexec-pe-zboot.c:31:10: fatal error: kexec-pe-zboot.h: No such file or directory
> >    31 | #include <kexec-pe-zboot.h>
> >       |          ^~~~~~~~~~~~~~~~~~
> >
> > Link: https://github.com/horms/kexec-tools/actions/runs/5723580523/job/15508425790
> >
> 
> It is not related to cross-compiling. Actually, I have tried to
> simplify the test matrix, which limits the compilation only on x86_64.
> And I got the similar error [1]
> 
> The workflow control file is [2], which clips out all arches except
> x86_64.  But I can successfully build it on the Fedora system with the
> following bash script, which is based on the github's build log.  So
> maybe it is a bug with the compiling tools?
> 
> kexec_tools_dir="./"
> 
> mkdir $kexec_tools_dir/_build \
>          $kexec_tools_dir/_build/sub \
>          $kexec_tools_dir/_inst \
>          $kexec_tools_dir/_dest
> chmod a-w $kexec_tools_dir
> test -d $kexec_tools_dir/_build
> INSTALL_BASE=$(cd $kexec_tools_dir/_inst && pwd | sed -e
> 's,^[^:\\/]:[\\/],/,') &&\
>         DESTDIR="$kexec_tools_dir/_dest" && \
>         cd $kexec_tools_dir/_build/sub && \
>                 ../../configure \
>                  \
>                 --srcdir=../.. --prefix="$INSTALL_BASE" && \
>         make  -j8
> 
> 
> [1]: https://github.com/pfliu/kexec-tools/actions/runs/5737254109/job/15548520863
> [2]: https://github.com/pfliu/kexec-tools/blob/zbootV6/.github/workflows/main.yml

Thanks,

I guess that kexec-pe-zboot.h is missing in the build environment for the
GitHub actions, but present in your Fedora environment.

Could you take a look and see where your copy of kexec-pe-zboot.h
came from?

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

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

* Re: [PATCHv6 3/5] kexec/zboot: Add arch independent zboot support
  2023-08-02 12:16       ` Simon Horman
@ 2023-08-02 12:17         ` Simon Horman
  2023-08-02 12:33           ` Simon Horman
  0 siblings, 1 reply; 13+ messages in thread
From: Simon Horman @ 2023-08-02 12:17 UTC (permalink / raw)
  To: Pingfan Liu; +Cc: kexec, Jeremy Linton, horms, ardb

On Wed, Aug 02, 2023 at 02:16:33PM +0200, Simon Horman wrote:
> On Wed, Aug 02, 2023 at 05:53:59PM +0800, Pingfan Liu wrote:
> > Hi Simon,
> > 
> > Thanks for the try. Please see the comment below.
> > 
> > On Tue, Aug 1, 2023 at 3:00 PM Simon Horman <horms@kernel.org> wrote:
> > >
> > > On Mon, Jul 24, 2023 at 10:21:40AM +0800, Pingfan Liu wrote:
> > > > 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 export kernel fd]
> > > > Signed-off-by: Pingfan Liu <piliu@redhat.com>
> > >
> > > Hi Pingfan,
> > >
> > > unfortunately this causes a build failure on hppa.
> > >
> > > ../../kexec/kexec-pe-zboot.c:31:10: fatal error: kexec-pe-zboot.h: No such file or directory
> > >    31 | #include <kexec-pe-zboot.h>
> > >       |          ^~~~~~~~~~~~~~~~~~
> > >
> > > Link: https://github.com/horms/kexec-tools/actions/runs/5723580523/job/15508425790
> > >
> > 
> > It is not related to cross-compiling. Actually, I have tried to
> > simplify the test matrix, which limits the compilation only on x86_64.
> > And I got the similar error [1]
> > 
> > The workflow control file is [2], which clips out all arches except
> > x86_64.  But I can successfully build it on the Fedora system with the
> > following bash script, which is based on the github's build log.  So
> > maybe it is a bug with the compiling tools?
> > 
> > kexec_tools_dir="./"
> > 
> > mkdir $kexec_tools_dir/_build \
> >          $kexec_tools_dir/_build/sub \
> >          $kexec_tools_dir/_inst \
> >          $kexec_tools_dir/_dest
> > chmod a-w $kexec_tools_dir
> > test -d $kexec_tools_dir/_build
> > INSTALL_BASE=$(cd $kexec_tools_dir/_inst && pwd | sed -e
> > 's,^[^:\\/]:[\\/],/,') &&\
> >         DESTDIR="$kexec_tools_dir/_dest" && \
> >         cd $kexec_tools_dir/_build/sub && \
> >                 ../../configure \
> >                  \
> >                 --srcdir=../.. --prefix="$INSTALL_BASE" && \
> >         make  -j8
> > 
> > 
> > [1]: https://github.com/pfliu/kexec-tools/actions/runs/5737254109/job/15548520863
> > [2]: https://github.com/pfliu/kexec-tools/blob/zbootV6/.github/workflows/main.yml
> 
> Thanks,
> 
> I guess that kexec-pe-zboot.h is missing in the build environment for the
> GitHub actions, but present in your Fedora environment.
> 
> Could you take a look and see where your copy of kexec-pe-zboot.h
> came from?

Actually it seems to be added by this patch (sorry for not noticing)!
So I guess it is an include path problem.

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

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

* Re: [PATCHv6 3/5] kexec/zboot: Add arch independent zboot support
  2023-08-02 12:17         ` Simon Horman
@ 2023-08-02 12:33           ` Simon Horman
  2023-08-03  2:37             ` Pingfan Liu
  0 siblings, 1 reply; 13+ messages in thread
From: Simon Horman @ 2023-08-02 12:33 UTC (permalink / raw)
  To: Pingfan Liu; +Cc: kexec, Jeremy Linton, horms, ardb

On Wed, Aug 02, 2023 at 02:17:57PM +0200, Simon Horman wrote:
> On Wed, Aug 02, 2023 at 02:16:33PM +0200, Simon Horman wrote:
> > On Wed, Aug 02, 2023 at 05:53:59PM +0800, Pingfan Liu wrote:
> > > Hi Simon,
> > > 
> > > Thanks for the try. Please see the comment below.
> > > 
> > > On Tue, Aug 1, 2023 at 3:00 PM Simon Horman <horms@kernel.org> wrote:
> > > >
> > > > On Mon, Jul 24, 2023 at 10:21:40AM +0800, Pingfan Liu wrote:
> > > > > 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 export kernel fd]
> > > > > Signed-off-by: Pingfan Liu <piliu@redhat.com>
> > > >
> > > > Hi Pingfan,
> > > >
> > > > unfortunately this causes a build failure on hppa.
> > > >
> > > > ../../kexec/kexec-pe-zboot.c:31:10: fatal error: kexec-pe-zboot.h: No such file or directory
> > > >    31 | #include <kexec-pe-zboot.h>
> > > >       |          ^~~~~~~~~~~~~~~~~~
> > > >
> > > > Link: https://github.com/horms/kexec-tools/actions/runs/5723580523/job/15508425790
> > > >
> > > 
> > > It is not related to cross-compiling. Actually, I have tried to
> > > simplify the test matrix, which limits the compilation only on x86_64.
> > > And I got the similar error [1]
> > > 
> > > The workflow control file is [2], which clips out all arches except
> > > x86_64.  But I can successfully build it on the Fedora system with the
> > > following bash script, which is based on the github's build log.  So
> > > maybe it is a bug with the compiling tools?
> > > 
> > > kexec_tools_dir="./"
> > > 
> > > mkdir $kexec_tools_dir/_build \
> > >          $kexec_tools_dir/_build/sub \
> > >          $kexec_tools_dir/_inst \
> > >          $kexec_tools_dir/_dest
> > > chmod a-w $kexec_tools_dir
> > > test -d $kexec_tools_dir/_build
> > > INSTALL_BASE=$(cd $kexec_tools_dir/_inst && pwd | sed -e
> > > 's,^[^:\\/]:[\\/],/,') &&\
> > >         DESTDIR="$kexec_tools_dir/_dest" && \
> > >         cd $kexec_tools_dir/_build/sub && \
> > >                 ../../configure \
> > >                  \
> > >                 --srcdir=../.. --prefix="$INSTALL_BASE" && \
> > >         make  -j8
> > > 
> > > 
> > > [1]: https://github.com/pfliu/kexec-tools/actions/runs/5737254109/job/15548520863
> > > [2]: https://github.com/pfliu/kexec-tools/blob/zbootV6/.github/workflows/main.yml
> > 
> > Thanks,
> > 
> > I guess that kexec-pe-zboot.h is missing in the build environment for the
> > GitHub actions, but present in your Fedora environment.
> > 
> > Could you take a look and see where your copy of kexec-pe-zboot.h
> > came from?
> 
> Actually it seems to be added by this patch (sorry for not noticing)!
> So I guess it is an include path problem.

I think I have found the problem.
The kexec-tools build system is a bit unusual,
and the new file, kexec-pe-zboot.h, was not included in distribution
tarballs. Thus the build failures.

I think you can resolve that by squashing the following into this patch.

diff --git a/include/Makefile b/include/Makefile
--- a/include/Makefile
+++ b/include/Makefile
@@ -1,6 +1,7 @@
 dist += include/Makefile		\
 	include/config.h		\
 	include/config.h.in		\
+	include/kexec-pe-zboot.h	\
 	include/kexec-uImage.h		\
 	include/x86/x86-linux.h		\
 	include/x86/mb_info.h		\

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

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

* Re: [PATCHv6 3/5] kexec/zboot: Add arch independent zboot support
  2023-08-02 12:33           ` Simon Horman
@ 2023-08-03  2:37             ` Pingfan Liu
  2023-08-03  8:04               ` Simon Horman
  0 siblings, 1 reply; 13+ messages in thread
From: Pingfan Liu @ 2023-08-03  2:37 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec, Jeremy Linton, horms, ardb

On Wed, Aug 2, 2023 at 8:33 PM Simon Horman <horms@kernel.org> wrote:
>
> On Wed, Aug 02, 2023 at 02:17:57PM +0200, Simon Horman wrote:
> > On Wed, Aug 02, 2023 at 02:16:33PM +0200, Simon Horman wrote:
> > > On Wed, Aug 02, 2023 at 05:53:59PM +0800, Pingfan Liu wrote:
> > > > Hi Simon,
> > > >
> > > > Thanks for the try. Please see the comment below.
> > > >
> > > > On Tue, Aug 1, 2023 at 3:00 PM Simon Horman <horms@kernel.org> wrote:
> > > > >
> > > > > On Mon, Jul 24, 2023 at 10:21:40AM +0800, Pingfan Liu wrote:
> > > > > > 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 export kernel fd]
> > > > > > Signed-off-by: Pingfan Liu <piliu@redhat.com>
> > > > >
> > > > > Hi Pingfan,
> > > > >
> > > > > unfortunately this causes a build failure on hppa.
> > > > >
> > > > > ../../kexec/kexec-pe-zboot.c:31:10: fatal error: kexec-pe-zboot.h: No such file or directory
> > > > >    31 | #include <kexec-pe-zboot.h>
> > > > >       |          ^~~~~~~~~~~~~~~~~~
> > > > >
> > > > > Link: https://github.com/horms/kexec-tools/actions/runs/5723580523/job/15508425790
> > > > >
> > > >
> > > > It is not related to cross-compiling. Actually, I have tried to
> > > > simplify the test matrix, which limits the compilation only on x86_64.
> > > > And I got the similar error [1]
> > > >
> > > > The workflow control file is [2], which clips out all arches except
> > > > x86_64.  But I can successfully build it on the Fedora system with the
> > > > following bash script, which is based on the github's build log.  So
> > > > maybe it is a bug with the compiling tools?
> > > >
> > > > kexec_tools_dir="./"
> > > >
> > > > mkdir $kexec_tools_dir/_build \
> > > >          $kexec_tools_dir/_build/sub \
> > > >          $kexec_tools_dir/_inst \
> > > >          $kexec_tools_dir/_dest
> > > > chmod a-w $kexec_tools_dir
> > > > test -d $kexec_tools_dir/_build
> > > > INSTALL_BASE=$(cd $kexec_tools_dir/_inst && pwd | sed -e
> > > > 's,^[^:\\/]:[\\/],/,') &&\
> > > >         DESTDIR="$kexec_tools_dir/_dest" && \
> > > >         cd $kexec_tools_dir/_build/sub && \
> > > >                 ../../configure \
> > > >                  \
> > > >                 --srcdir=../.. --prefix="$INSTALL_BASE" && \
> > > >         make  -j8
> > > >
> > > >
> > > > [1]: https://github.com/pfliu/kexec-tools/actions/runs/5737254109/job/15548520863
> > > > [2]: https://github.com/pfliu/kexec-tools/blob/zbootV6/.github/workflows/main.yml
> > >
> > > Thanks,
> > >
> > > I guess that kexec-pe-zboot.h is missing in the build environment for the
> > > GitHub actions, but present in your Fedora environment.
> > >
> > > Could you take a look and see where your copy of kexec-pe-zboot.h
> > > came from?
> >
> > Actually it seems to be added by this patch (sorry for not noticing)!
> > So I guess it is an include path problem.
>
> I think I have found the problem.
> The kexec-tools build system is a bit unusual,
> and the new file, kexec-pe-zboot.h, was not included in distribution
> tarballs. Thus the build failures.
>

Unexpectedly, and thank for your insight.

> I think you can resolve that by squashing the following into this patch.
>
> diff --git a/include/Makefile b/include/Makefile
> --- a/include/Makefile
> +++ b/include/Makefile
> @@ -1,6 +1,7 @@
>  dist += include/Makefile               \
>         include/config.h                \
>         include/config.h.in             \
> +       include/kexec-pe-zboot.h        \
>         include/kexec-uImage.h          \
>         include/x86/x86-linux.h         \
>         include/x86/mb_info.h           \
>

After applying this patch, the github workflow successfully finished.
I will send out V7 immediately.

Appreciate for your kind help again.

Thanks,

Pingfan


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

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

* Re: [PATCHv6 3/5] kexec/zboot: Add arch independent zboot support
  2023-08-03  2:37             ` Pingfan Liu
@ 2023-08-03  8:04               ` Simon Horman
  0 siblings, 0 replies; 13+ messages in thread
From: Simon Horman @ 2023-08-03  8:04 UTC (permalink / raw)
  To: Pingfan Liu; +Cc: kexec, Jeremy Linton, horms, ardb

On Thu, Aug 03, 2023 at 10:37:10AM +0800, Pingfan Liu wrote:
> On Wed, Aug 2, 2023 at 8:33 PM Simon Horman <horms@kernel.org> wrote:
> >
> > On Wed, Aug 02, 2023 at 02:17:57PM +0200, Simon Horman wrote:
> > > On Wed, Aug 02, 2023 at 02:16:33PM +0200, Simon Horman wrote:
> > > > On Wed, Aug 02, 2023 at 05:53:59PM +0800, Pingfan Liu wrote:
> > > > > Hi Simon,
> > > > >
> > > > > Thanks for the try. Please see the comment below.
> > > > >
> > > > > On Tue, Aug 1, 2023 at 3:00 PM Simon Horman <horms@kernel.org> wrote:
> > > > > >
> > > > > > On Mon, Jul 24, 2023 at 10:21:40AM +0800, Pingfan Liu wrote:
> > > > > > > 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 export kernel fd]
> > > > > > > Signed-off-by: Pingfan Liu <piliu@redhat.com>
> > > > > >
> > > > > > Hi Pingfan,
> > > > > >
> > > > > > unfortunately this causes a build failure on hppa.
> > > > > >
> > > > > > ../../kexec/kexec-pe-zboot.c:31:10: fatal error: kexec-pe-zboot.h: No such file or directory
> > > > > >    31 | #include <kexec-pe-zboot.h>
> > > > > >       |          ^~~~~~~~~~~~~~~~~~
> > > > > >
> > > > > > Link: https://github.com/horms/kexec-tools/actions/runs/5723580523/job/15508425790
> > > > > >
> > > > >
> > > > > It is not related to cross-compiling. Actually, I have tried to
> > > > > simplify the test matrix, which limits the compilation only on x86_64.
> > > > > And I got the similar error [1]
> > > > >
> > > > > The workflow control file is [2], which clips out all arches except
> > > > > x86_64.  But I can successfully build it on the Fedora system with the
> > > > > following bash script, which is based on the github's build log.  So
> > > > > maybe it is a bug with the compiling tools?
> > > > >
> > > > > kexec_tools_dir="./"
> > > > >
> > > > > mkdir $kexec_tools_dir/_build \
> > > > >          $kexec_tools_dir/_build/sub \
> > > > >          $kexec_tools_dir/_inst \
> > > > >          $kexec_tools_dir/_dest
> > > > > chmod a-w $kexec_tools_dir
> > > > > test -d $kexec_tools_dir/_build
> > > > > INSTALL_BASE=$(cd $kexec_tools_dir/_inst && pwd | sed -e
> > > > > 's,^[^:\\/]:[\\/],/,') &&\
> > > > >         DESTDIR="$kexec_tools_dir/_dest" && \
> > > > >         cd $kexec_tools_dir/_build/sub && \
> > > > >                 ../../configure \
> > > > >                  \
> > > > >                 --srcdir=../.. --prefix="$INSTALL_BASE" && \
> > > > >         make  -j8
> > > > >
> > > > >
> > > > > [1]: https://github.com/pfliu/kexec-tools/actions/runs/5737254109/job/15548520863
> > > > > [2]: https://github.com/pfliu/kexec-tools/blob/zbootV6/.github/workflows/main.yml
> > > >
> > > > Thanks,
> > > >
> > > > I guess that kexec-pe-zboot.h is missing in the build environment for the
> > > > GitHub actions, but present in your Fedora environment.
> > > >
> > > > Could you take a look and see where your copy of kexec-pe-zboot.h
> > > > came from?
> > >
> > > Actually it seems to be added by this patch (sorry for not noticing)!
> > > So I guess it is an include path problem.
> >
> > I think I have found the problem.
> > The kexec-tools build system is a bit unusual,
> > and the new file, kexec-pe-zboot.h, was not included in distribution
> > tarballs. Thus the build failures.
> >
> 
> Unexpectedly, and thank for your insight.
> 
> > I think you can resolve that by squashing the following into this patch.
> >
> > diff --git a/include/Makefile b/include/Makefile
> > --- a/include/Makefile
> > +++ b/include/Makefile
> > @@ -1,6 +1,7 @@
> >  dist += include/Makefile               \
> >         include/config.h                \
> >         include/config.h.in             \
> > +       include/kexec-pe-zboot.h        \
> >         include/kexec-uImage.h          \
> >         include/x86/x86-linux.h         \
> >         include/x86/mb_info.h           \
> >
> 
> After applying this patch, the github workflow successfully finished.
> I will send out V7 immediately.
> 
> Appreciate for your kind help again.

Thanks, I see v7 now.

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

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

end of thread, other threads:[~2023-08-03  8:05 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-24  2:21 [PATCHv6 0/5] arm64: zboot support Pingfan Liu
2023-07-24  2:21 ` [PATCHv6 1/5] kexec/arm64: Simplify the code for zImage Pingfan Liu
2023-07-24  2:21 ` [PATCHv6 2/5] kexec: Introduce a member kernel_fd in kexec_info Pingfan Liu
2023-07-24  2:21 ` [PATCHv6 3/5] kexec/zboot: Add arch independent zboot support Pingfan Liu
2023-08-01  7:00   ` Simon Horman
2023-08-02  9:53     ` Pingfan Liu
2023-08-02 12:16       ` Simon Horman
2023-08-02 12:17         ` Simon Horman
2023-08-02 12:33           ` Simon Horman
2023-08-03  2:37             ` Pingfan Liu
2023-08-03  8:04               ` Simon Horman
2023-07-24  2:21 ` [PATCHv6 4/5] arm64: Add ZBOOT PE containing compressed image support Pingfan Liu
2023-07-24  2:21 ` [PATCHv6 5/5] arm64: Hook up the ZBOOT support as vmlinuz Pingfan Liu

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.