All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] arm64: support --mem-min and --mem-max parameters
@ 2016-08-29  8:28 AKASHI Takahiro
  2016-08-29  8:28 ` [PATCH 1/2] fixup! arm64: Add arm64 kexec support AKASHI Takahiro
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: AKASHI Takahiro @ 2016-08-29  8:28 UTC (permalink / raw)
  To: horms, geoff; +Cc: AKASHI Takahiro, kexec

Geoff's current patches of kexec support for arm64 [1] ignores command
line paramters, --mem-min and --mem-max and always load the kernel at
the address above "TEXT_OFFSET" bytes in the first memory regions.

My patches add the support of both parameters and, moreover, make
the differences between elf_arm64_load() and image_arm64_load() quite
small for better understandings.

Please think about merging my fixup patches.
	-> Geoff

[1] http://lists.infradead.org/pipermail/kexec/2016-August/016942.html

AKASHI Takahiro (2):
  fixup! arm64: Add arm64 kexec support
  fixup! arm64: Add support for binary image files

 kexec/arch/arm64/kexec-arm64.c       | 22 ++++++++--
 kexec/arch/arm64/kexec-arm64.h       |  1 +
 kexec/arch/arm64/kexec-elf-arm64.c   | 79 ++++++++++++++++++++----------------
 kexec/arch/arm64/kexec-image-arm64.c | 29 ++++++++++---
 4 files changed, 88 insertions(+), 43 deletions(-)

-- 
2.9.0


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

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

* [PATCH 1/2] fixup! arm64: Add arm64 kexec support
  2016-08-29  8:28 [PATCH 0/2] arm64: support --mem-min and --mem-max parameters AKASHI Takahiro
@ 2016-08-29  8:28 ` AKASHI Takahiro
  2016-08-29  8:28 ` [PATCH 2/2] fixup! arm64: Add support for binary image files AKASHI Takahiro
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: AKASHI Takahiro @ 2016-08-29  8:28 UTC (permalink / raw)
  To: horms, geoff; +Cc: AKASHI Takahiro, kexec

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 kexec/arch/arm64/kexec-arm64.c     | 22 +++++++++--
 kexec/arch/arm64/kexec-arm64.h     |  1 +
 kexec/arch/arm64/kexec-elf-arm64.c | 79 ++++++++++++++++++++++----------------
 3 files changed, 64 insertions(+), 38 deletions(-)

diff --git a/kexec/arch/arm64/kexec-arm64.c b/kexec/arch/arm64/kexec-arm64.c
index be3f964..253affa 100644
--- a/kexec/arch/arm64/kexec-arm64.c
+++ b/kexec/arch/arm64/kexec-arm64.c
@@ -300,16 +300,30 @@ static int setup_2nd_dtb(struct dtb *dtb, char *command_line)
 	return result;
 }
 
+unsigned long arm64_locate_kernel_segment(struct kexec_info *info)
+{
+	unsigned long image_base;
+
+	image_base = locate_hole(info,
+		arm64_mem.text_offset + arm64_mem.image_size,
+		MiB(2), 0, ULONG_MAX, 1);
+	if (image_base == ULONG_MAX) {
+		dbgprintf("%s: locate_hole failed\n", __func__);
+	}
+
+	return image_base;
+}
+
 /**
  * arm64_load_other_segments - Prepare the dtb, initrd and purgatory segments.
  */
 
 int arm64_load_other_segments(struct kexec_info *info,
-	uint64_t kernel_entry)
+	unsigned long kernel_entry)
 {
 	int result;
-	uint64_t dtb_base;
-	uint64_t image_base;
+	unsigned long dtb_base;
+	unsigned long image_base;
 	unsigned long hole_min;
 	unsigned long hole_max;
 	char *initrd_buf = NULL;
@@ -343,7 +357,7 @@ int arm64_load_other_segments(struct kexec_info *info,
 
 	/* Put the other segments after the image. */
 
-	image_base = arm64_mem.phys_offset + arm64_mem.text_offset;
+	image_base = kernel_entry;
 	hole_min = image_base + arm64_mem.image_size;
 	hole_max = ULONG_MAX;
 
diff --git a/kexec/arch/arm64/kexec-arm64.h b/kexec/arch/arm64/kexec-arm64.h
index c40e383..e4bc6d0 100644
--- a/kexec/arch/arm64/kexec-arm64.h
+++ b/kexec/arch/arm64/kexec-arm64.h
@@ -64,6 +64,7 @@ static inline void set_phys_offset(uint64_t v)
 }
 
 int arm64_process_image_header(const struct arm64_image_header *h);
+unsigned long arm64_locate_kernel_segment(struct kexec_info *info);
 int arm64_load_other_segments(struct kexec_info *info,
 	uint64_t kernel_entry);
 
diff --git a/kexec/arch/arm64/kexec-elf-arm64.c b/kexec/arch/arm64/kexec-elf-arm64.c
index 2635d29..18aca3c 100644
--- a/kexec/arch/arm64/kexec-elf-arm64.c
+++ b/kexec/arch/arm64/kexec-elf-arm64.c
@@ -5,6 +5,7 @@
 #define _GNU_SOURCE
 
 #include <errno.h>
+#include <limits.h>
 #include <stdlib.h>
 #include <linux/elf.h>
 
@@ -42,6 +43,8 @@ int elf_arm64_load(int argc, char **argv, const char *kernel_buf,
 	struct mem_ehdr ehdr;
 	int result;
 	int i;
+	const struct arm64_image_header *h = NULL;
+	unsigned long image_base;
 
 	if (info->kexec_flags & KEXEC_ON_CRASH) {
 		fprintf(stderr, "kexec: kdump not yet supported on arm64\n");
@@ -59,7 +62,6 @@ int elf_arm64_load(int argc, char **argv, const char *kernel_buf,
 
 	for (i = 0; i < ehdr.e_phnum; i++) {
 		struct mem_phdr *phdr = &ehdr.e_phdr[i];
-		const struct arm64_image_header *h;
 		unsigned long header_offset;
 
 		if (phdr->p_type != PT_LOAD)
@@ -76,45 +78,54 @@ int elf_arm64_load(int argc, char **argv, const char *kernel_buf,
 		h = (const struct arm64_image_header *)(
 			kernel_buf + phdr->p_offset + header_offset);
 
-		if (arm64_process_image_header(h))
-			continue;
+		if (!arm64_process_image_header(h)) {
+			dbgprintf("%s: e_entry:       %016llx\n", __func__,
+				ehdr.e_entry);
+			dbgprintf("%s: p_vaddr:       %016llx\n", __func__,
+				phdr->p_vaddr);
+			dbgprintf("%s: header_offset: %016lx\n", __func__,
+				header_offset);
 
-		arm64_mem.vp_offset = ehdr.e_entry - arm64_mem.text_offset;
-
-		dbgprintf("%s: e_entry:       %016llx -> %016lx\n", __func__,
-			ehdr.e_entry,
-			virt_to_phys(ehdr.e_entry));
-		dbgprintf("%s: p_vaddr:       %016llx -> %016lx\n", __func__,
-			phdr->p_vaddr,
-			virt_to_phys(phdr->p_vaddr));
-		dbgprintf("%s: header_offset: %016lx\n", __func__,
-			header_offset);
-		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(h) ? "yes" : "no"));
-
-		result = elf_exec_load(&ehdr, info);
-
-		if (result) {
-			dbgprintf("%s: elf_exec_load failed\n", __func__);
-			goto exit;
+			break;
 		}
+	}
+	if (i == ehdr.e_phnum) {
+		dbgprintf("%s: Valid arm64 header not found\n", __func__);
+		result = -EFAILED;
+		goto exit;
+	}
+
+	image_base = arm64_locate_kernel_segment(info);
+	if (image_base == ULONG_MAX) {
+		dbgprintf("%s: Kernel segment is not allocated\n", __func__);
+		result = -EFAILED;
+		goto exit;
+	}
 
-		result = arm64_load_other_segments(info,
-			virt_to_phys(ehdr.e_entry));
+	arm64_mem.vp_offset = _ALIGN_DOWN(ehdr.e_entry, MiB(2));
+	arm64_mem.vp_offset -= image_base - get_phys_offset();
+
+	dbgprintf("%s: image_base:    %016lx\n", __func__, image_base);
+	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(h) ? "yes" : "no"));
+
+	/* load the kernel */
+	result = elf_exec_load(&ehdr, info);
+	if (result) {
+		dbgprintf("%s: elf_exec_load failed\n", __func__);
 		goto exit;
 	}
 
-	dbgprintf("%s: Bad arm64 image header\n", __func__);
-	result = -EFAILED;
-	goto exit;
+	result = arm64_load_other_segments(info,
+			image_base + arm64_mem.text_offset);
 
 exit:
 	reset_vp_offset();
-- 
2.9.0


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

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

* [PATCH 2/2] fixup! arm64: Add support for binary image files
  2016-08-29  8:28 [PATCH 0/2] arm64: support --mem-min and --mem-max parameters AKASHI Takahiro
  2016-08-29  8:28 ` [PATCH 1/2] fixup! arm64: Add arm64 kexec support AKASHI Takahiro
@ 2016-08-29  8:28 ` AKASHI Takahiro
  2016-09-01 21:43 ` [PATCH 0/2] arm64: support --mem-min and --mem-max parameters Geoff Levand
  2016-09-01 21:44 ` Geoff Levand
  3 siblings, 0 replies; 5+ messages in thread
From: AKASHI Takahiro @ 2016-08-29  8:28 UTC (permalink / raw)
  To: horms, geoff; +Cc: AKASHI Takahiro, kexec

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 kexec/arch/arm64/kexec-image-arm64.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/kexec/arch/arm64/kexec-image-arm64.c b/kexec/arch/arm64/kexec-image-arm64.c
index b77b63e..77cff59 100644
--- a/kexec/arch/arm64/kexec-image-arm64.c
+++ b/kexec/arch/arm64/kexec-image-arm64.c
@@ -3,7 +3,9 @@
  */
 
 #define _GNU_SOURCE
+
 #include "kexec-arm64.h"
+#include <limits.h>
 
 int image_arm64_probe(const char *kernel_buf, off_t kernel_size)
 {
@@ -29,27 +31,44 @@ int image_arm64_load(int argc, char **argv, const char *kernel_buf,
 {
 	const struct arm64_image_header *h;
 	unsigned long image_base;
+	int result;
 
 	h = (const struct arm64_image_header *)(kernel_buf);
 
 	if (arm64_process_image_header(h))
 		return -1;
 
+        image_base = arm64_locate_kernel_segment(info);
+        if (image_base == ULONG_MAX) {
+                dbgprintf("%s: Kernel segment is not allocated\n", __func__);
+                result = -EFAILED;
+                goto exit;
+        }
+
+	dbgprintf("%s: image_base:    %016lx\n", __func__, image_base);
 	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(h) ? "yes" : "no"));
 
-	image_base = get_phys_offset() + arm64_mem.text_offset;
-	
-	add_segment_phys_virt(info, kernel_buf, kernel_size, image_base,
-		arm64_mem.image_size, 0);
+	/* load the kernel */
+	add_segment_phys_virt(info, kernel_buf, kernel_size,
+			image_base + arm64_mem.text_offset,
+			arm64_mem.image_size, 0);
+
+	result = arm64_load_other_segments(info,
+			image_base + arm64_mem.text_offset);
 
-	return arm64_load_other_segments(info, image_base);
+exit:
+        if (result)
+                fprintf(stderr, "kexec: load failed.\n");
+        return result;
 }
 
 void image_arm64_usage(void)
-- 
2.9.0


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

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

* Re: [PATCH 0/2] arm64: support --mem-min and --mem-max parameters
  2016-08-29  8:28 [PATCH 0/2] arm64: support --mem-min and --mem-max parameters AKASHI Takahiro
  2016-08-29  8:28 ` [PATCH 1/2] fixup! arm64: Add arm64 kexec support AKASHI Takahiro
  2016-08-29  8:28 ` [PATCH 2/2] fixup! arm64: Add support for binary image files AKASHI Takahiro
@ 2016-09-01 21:43 ` Geoff Levand
  2016-09-01 21:44 ` Geoff Levand
  3 siblings, 0 replies; 5+ messages in thread
From: Geoff Levand @ 2016-09-01 21:43 UTC (permalink / raw)
  To: AKASHI Takahiro, horms; +Cc: kexec

Hi Takahiro,

On Mon, 2016-08-29 at 17:28 +0900, AKASHI Takahiro wrote:
> Geoff's current patches of kexec support for arm64 [1] ignores
> command
> line paramters, --mem-min and --mem-max and always load the kernel at
> the address above "TEXT_OFFSET" bytes in the first memory regions.
> 
> My patches add the support of both parameters and, moreover, make
> the differences between elf_arm64_load() and image_arm64_load() quite
> small for better understandings.

These look OK.  I renamed some of the symbols to make things clearer.

-Geoff


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

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

* Re: [PATCH 0/2] arm64: support --mem-min and --mem-max parameters
  2016-08-29  8:28 [PATCH 0/2] arm64: support --mem-min and --mem-max parameters AKASHI Takahiro
                   ` (2 preceding siblings ...)
  2016-09-01 21:43 ` [PATCH 0/2] arm64: support --mem-min and --mem-max parameters Geoff Levand
@ 2016-09-01 21:44 ` Geoff Levand
  3 siblings, 0 replies; 5+ messages in thread
From: Geoff Levand @ 2016-09-01 21:44 UTC (permalink / raw)
  To: AKASHI Takahiro, horms; +Cc: kexec

Hi Takahiro,

On Mon, 2016-08-29 at 17:28 +0900, AKASHI Takahiro wrote:
> Geoff's current patches of kexec support for arm64 [1] ignores
> command
> line paramters, --mem-min and --mem-max and always load the kernel at
> the address above "TEXT_OFFSET" bytes in the first memory regions.
> 
> My patches add the support of both parameters and, moreover, make
> the differences between elf_arm64_load() and image_arm64_load() quite
> small for better understandings.

These look OK.  I renamed some of the symbols to make things clearer.

-Geoff


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

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

end of thread, other threads:[~2016-09-01 21:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-29  8:28 [PATCH 0/2] arm64: support --mem-min and --mem-max parameters AKASHI Takahiro
2016-08-29  8:28 ` [PATCH 1/2] fixup! arm64: Add arm64 kexec support AKASHI Takahiro
2016-08-29  8:28 ` [PATCH 2/2] fixup! arm64: Add support for binary image files AKASHI Takahiro
2016-09-01 21:43 ` [PATCH 0/2] arm64: support --mem-min and --mem-max parameters Geoff Levand
2016-09-01 21:44 ` Geoff Levand

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.