linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH 1/2] ARM: kexec: scan for dtb magic in segments
@ 2012-09-20 16:03 Will Deacon
  2012-09-20 16:03 ` [RESEND PATCH 2/2] ARM: kexec: Check segment memory addresses Will Deacon
  0 siblings, 1 reply; 6+ messages in thread
From: Will Deacon @ 2012-09-20 16:03 UTC (permalink / raw)
  To: linux-arm-kernel

From: Matthew Leach <matthew.leach@arm.com>

This patch allows a dtb to be passed to a new kernel using the kexec
mechinism.

When loading segments from userspace, scan each segment's first four
bytes for the dtb magic. If this is found set the kexec_boot_atags
parameter to the relocate_kernel code to the phyical address of this
segment.

Reviewed-by: Simon Horman <horms@verge.net.au>
Reviewed-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Matthew Leach <matthew.leach@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 arch/arm/kernel/machine_kexec.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/arch/arm/kernel/machine_kexec.c b/arch/arm/kernel/machine_kexec.c
index dfcdb9f..dee34ef 100644
--- a/arch/arm/kernel/machine_kexec.c
+++ b/arch/arm/kernel/machine_kexec.c
@@ -9,6 +9,7 @@
 #include <linux/io.h>
 #include <linux/irq.h>
 #include <asm/pgtable.h>
+#include <linux/of_fdt.h>
 #include <asm/pgalloc.h>
 #include <asm/mmu_context.h>
 #include <asm/cacheflush.h>
@@ -32,6 +33,24 @@ static atomic_t waiting_for_crash_ipi;
 
 int machine_kexec_prepare(struct kimage *image)
 {
+	struct kexec_segment *current_segment;
+	__be32 header;
+	int i, err;
+
+	/*
+	 * No segment at default ATAGs address. try to locate
+	 * a dtb using magic.
+	 */
+	for (i = 0; i < image->nr_segments; i++) {
+		current_segment = &image->segment[i];
+
+		err = get_user(header, (__be32*)current_segment->buf);
+		if (err)
+			return err;
+
+		if (be32_to_cpu(header) == OF_DT_HEADER)
+			kexec_boot_atags = current_segment->mem;
+	}
 	return 0;
 }
 
@@ -122,7 +141,9 @@ void machine_kexec(struct kimage *image)
 	kexec_start_address = image->start;
 	kexec_indirection_page = page_list;
 	kexec_mach_type = machine_arch_type;
-	kexec_boot_atags = image->start - KEXEC_ARM_ZIMAGE_OFFSET + KEXEC_ARM_ATAGS_OFFSET;
+	if (!kexec_boot_atags)
+		kexec_boot_atags = image->start - KEXEC_ARM_ZIMAGE_OFFSET + KEXEC_ARM_ATAGS_OFFSET;
+
 
 	/* copy our kernel relocation code to the control code page */
 	memcpy(reboot_code_buffer,
-- 
1.7.4.1

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

* [RESEND PATCH 2/2] ARM: kexec: Check segment memory addresses
  2012-09-20 16:03 [RESEND PATCH 1/2] ARM: kexec: scan for dtb magic in segments Will Deacon
@ 2012-09-20 16:03 ` Will Deacon
  2012-10-16 16:10   ` Aaro Koskinen
  0 siblings, 1 reply; 6+ messages in thread
From: Will Deacon @ 2012-09-20 16:03 UTC (permalink / raw)
  To: linux-arm-kernel

From: Matthew Leach <matthew.leach@arm.com>

Ensure that the memory regions that are set within the segments
correspond to physical contiguous memory regions.

Reviewed-by: Simon Horman <horms@verge.net.au>
Reviewed-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Matthew Leach <matthew.leach@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 arch/arm/kernel/machine_kexec.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/arm/kernel/machine_kexec.c b/arch/arm/kernel/machine_kexec.c
index dee34ef..e29c333 100644
--- a/arch/arm/kernel/machine_kexec.c
+++ b/arch/arm/kernel/machine_kexec.c
@@ -8,6 +8,7 @@
 #include <linux/reboot.h>
 #include <linux/io.h>
 #include <linux/irq.h>
+#include <linux/memblock.h>
 #include <asm/pgtable.h>
 #include <linux/of_fdt.h>
 #include <asm/pgalloc.h>
@@ -44,6 +45,11 @@ int machine_kexec_prepare(struct kimage *image)
 	for (i = 0; i < image->nr_segments; i++) {
 		current_segment = &image->segment[i];
 
+		err = memblock_is_region_memory(current_segment->mem,
+						current_segment->memsz);
+		if (err)
+			return - EINVAL;
+
 		err = get_user(header, (__be32*)current_segment->buf);
 		if (err)
 			return err;
-- 
1.7.4.1

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

* [RESEND PATCH 2/2] ARM: kexec: Check segment memory addresses
  2012-09-20 16:03 ` [RESEND PATCH 2/2] ARM: kexec: Check segment memory addresses Will Deacon
@ 2012-10-16 16:10   ` Aaro Koskinen
  2012-10-16 16:32     ` Will Deacon
  0 siblings, 1 reply; 6+ messages in thread
From: Aaro Koskinen @ 2012-10-16 16:10 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Thu, Sep 20, 2012 at 05:03:38PM +0100, Will Deacon wrote:
> From: Matthew Leach <matthew.leach@arm.com>
> 
> Ensure that the memory regions that are set within the segments
> correspond to physical contiguous memory regions.

This patch seems to break kexec for me in 3.7-rc1 (commit
c564df4db85aac8d1d65a56176a0a25f46138064, bisected).

kexec -l fails with the following output:

kexec_load failed: Invalid argument
entry       = 0x80008000 flags = 280000
nr_segments = 2
segment[0].buf   = 0xc48008
segment[0].bufsz = 230
segment[0].mem   = 0x80001000
segment[0].memsz = 1000
segment[1].buf   = 0xb6a9b008
segment[1].bufsz = 3a4668
segment[1].mem   = 0x80008000
segment[1].memsz = 3a5000
Could not load the kexec kernel: n800-zImage

The board is OMAP2420 / Nokia N800.

A.

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

* [RESEND PATCH 2/2] ARM: kexec: Check segment memory addresses
  2012-10-16 16:10   ` Aaro Koskinen
@ 2012-10-16 16:32     ` Will Deacon
  2012-10-16 17:09       ` Aaro Koskinen
  0 siblings, 1 reply; 6+ messages in thread
From: Will Deacon @ 2012-10-16 16:32 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Oct 16, 2012 at 05:10:21PM +0100, Aaro Koskinen wrote:
> Hi,

Hi Aaro,

> On Thu, Sep 20, 2012 at 05:03:38PM +0100, Will Deacon wrote:
> > From: Matthew Leach <matthew.leach@arm.com>
> > 
> > Ensure that the memory regions that are set within the segments
> > correspond to physical contiguous memory regions.
> 
> This patch seems to break kexec for me in 3.7-rc1 (commit
> c564df4db85aac8d1d65a56176a0a25f46138064, bisected).
> 
> kexec -l fails with the following output:
> 
> kexec_load failed: Invalid argument
> entry       = 0x80008000 flags = 280000
> nr_segments = 2
> segment[0].buf   = 0xc48008
> segment[0].bufsz = 230
> segment[0].mem   = 0x80001000
> segment[0].memsz = 1000
> segment[1].buf   = 0xb6a9b008
> segment[1].bufsz = 3a4668
> segment[1].mem   = 0x80008000
> segment[1].memsz = 3a5000
> Could not load the kexec kernel: n800-zImage
> 
> The board is OMAP2420 / Nokia N800.

Interesting, it sounds like kexec thinks that you don't have contiguous
memory from 0x80008000 to 0x803ad000. Can you provide some more information
about your physical memory map please?

Cheers,

Will

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

* [RESEND PATCH 2/2] ARM: kexec: Check segment memory addresses
  2012-10-16 16:32     ` Will Deacon
@ 2012-10-16 17:09       ` Aaro Koskinen
  2012-10-16 17:16         ` Will Deacon
  0 siblings, 1 reply; 6+ messages in thread
From: Aaro Koskinen @ 2012-10-16 17:09 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Oct 16, 2012 at 05:32:26PM +0100, Will Deacon wrote:
> On Tue, Oct 16, 2012 at 05:10:21PM +0100, Aaro Koskinen wrote:
> > On Thu, Sep 20, 2012 at 05:03:38PM +0100, Will Deacon wrote:
> > > From: Matthew Leach <matthew.leach@arm.com>
> > > 
> > > Ensure that the memory regions that are set within the segments
> > > correspond to physical contiguous memory regions.
> > 
> > This patch seems to break kexec for me in 3.7-rc1 (commit
> > c564df4db85aac8d1d65a56176a0a25f46138064, bisected).
> > 
> > kexec -l fails with the following output:
> > 
> > kexec_load failed: Invalid argument
> > entry       = 0x80008000 flags = 280000
> > nr_segments = 2
> > segment[0].buf   = 0xc48008
> > segment[0].bufsz = 230
> > segment[0].mem   = 0x80001000
> > segment[0].memsz = 1000
> > segment[1].buf   = 0xb6a9b008
> > segment[1].bufsz = 3a4668
> > segment[1].mem   = 0x80008000
> > segment[1].memsz = 3a5000
> > Could not load the kexec kernel: n800-zImage
> > 
> > The board is OMAP2420 / Nokia N800.
> 
> Interesting, it sounds like kexec thinks that you don't have contiguous
> memory from 0x80008000 to 0x803ad000. Can you provide some more information
> about your physical memory map please?

Well, I think it's because the patch is wrong. Shouldn't it be:

diff --git a/arch/arm/kernel/machine_kexec.c b/arch/arm/kernel/machine_kexec.c
index e29c333..a80192e 100644
--- a/arch/arm/kernel/machine_kexec.c
+++ b/arch/arm/kernel/machine_kexec.c
@@ -47,7 +47,7 @@ int machine_kexec_prepare(struct kimage *image)
 
 		err = memblock_is_region_memory(current_segment->mem,
 						current_segment->memsz);
-		if (err)
+		if (!err)
 			return - EINVAL;
 
 		err = get_user(header, (__be32*)current_segment->buf);

A.

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

* [RESEND PATCH 2/2] ARM: kexec: Check segment memory addresses
  2012-10-16 17:09       ` Aaro Koskinen
@ 2012-10-16 17:16         ` Will Deacon
  0 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2012-10-16 17:16 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Oct 16, 2012 at 06:09:00PM +0100, Aaro Koskinen wrote:
> On Tue, Oct 16, 2012 at 05:32:26PM +0100, Will Deacon wrote:
> > Interesting, it sounds like kexec thinks that you don't have contiguous
> > memory from 0x80008000 to 0x803ad000. Can you provide some more information
> > about your physical memory map please?
> 
> Well, I think it's because the patch is wrong. Shouldn't it be:
> 
> diff --git a/arch/arm/kernel/machine_kexec.c b/arch/arm/kernel/machine_kexec.c
> index e29c333..a80192e 100644
> --- a/arch/arm/kernel/machine_kexec.c
> +++ b/arch/arm/kernel/machine_kexec.c
> @@ -47,7 +47,7 @@ int machine_kexec_prepare(struct kimage *image)
>  
>  		err = memblock_is_region_memory(current_segment->mem,
>  						current_segment->memsz);
> -		if (err)
> +		if (!err)
>  			return - EINVAL;
>  
>  		err = get_user(header, (__be32*)current_segment->buf);

Oops, that's a howler! Thanks for spotting it. We should probably reflow the
code a bit because !err sounds like everything should be ok.

Fancy reworking the patch or do you want me to take care of this?

Cheers,

Will

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

end of thread, other threads:[~2012-10-16 17:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-20 16:03 [RESEND PATCH 1/2] ARM: kexec: scan for dtb magic in segments Will Deacon
2012-09-20 16:03 ` [RESEND PATCH 2/2] ARM: kexec: Check segment memory addresses Will Deacon
2012-10-16 16:10   ` Aaro Koskinen
2012-10-16 16:32     ` Will Deacon
2012-10-16 17:09       ` Aaro Koskinen
2012-10-16 17:16         ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).