Skip to content

Commit 0d70262

Browse files
author
Russell King
committed
ARM: kexec: fix failure to boot crash kernel
When kexec was converted to DTB, the dtb address was passed between machine_kexec_prepare() and machine_kexec() using a static variable. This is bad news if you load a crash kernel followed by a normal kernel or vice versa - the last loaded kernel overwrites the dtb address. This can result in kexec failures, as (eg) we try to boot the crash kernel with the last loaded dtb. For example, with: the crash kernel fails to find the dtb. Avoid this by defining a kimage architecture structure, and store the address to be passed in r2 there, which will either be the ATAGs or the dtb blob. Fixes: 4cabd1d ("ARM: 7539/1: kexec: scan for dtb magic in segments") Fixes: 42d720d ("ARM: kexec: Make .text R/W in machine_kexec") Reported-by: Keerthy <j-keerthy@ti.com> Tested-by: Keerthy <j-keerthy@ti.com> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
1 parent 67556d7 commit 0d70262

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎arch/arm/include/asm/kexec.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919

2020
#ifndef __ASSEMBLY__
2121

22+
#define ARCH_HAS_KIMAGE_ARCH
23+
struct kimage_arch {
24+
u32 kernel_r2;
25+
};
26+
2227
/**
2328
* crash_setup_regs() - save registers for the panic kernel
2429
* @newregs: registers are saved here

‎arch/arm/kernel/machine_kexec.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ extern unsigned long kexec_boot_atags;
3030

3131
static atomic_t waiting_for_crash_ipi;
3232

33-
static unsigned long dt_mem;
3433
/*
3534
* Provide a dummy crash_notes definition while crash dump arrives to arm.
3635
* This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
@@ -42,6 +41,9 @@ int machine_kexec_prepare(struct kimage *image)
4241
__be32 header;
4342
int i, err;
4443

44+
image->arch.kernel_r2 = image->start - KEXEC_ARM_ZIMAGE_OFFSET
45+
+ KEXEC_ARM_ATAGS_OFFSET;
46+
4547
/*
4648
* Validate that if the current HW supports SMP, then the SW supports
4749
* and implements CPU hotplug for the current HW. If not, we won't be
@@ -66,8 +68,8 @@ int machine_kexec_prepare(struct kimage *image)
6668
if (err)
6769
return err;
6870

69-
if (be32_to_cpu(header) == OF_DT_HEADER)
70-
dt_mem = current_segment->mem;
71+
if (header == cpu_to_be32(OF_DT_HEADER))
72+
image->arch.kernel_r2 = current_segment->mem;
7173
}
7274
return 0;
7375
}
@@ -165,8 +167,7 @@ void machine_kexec(struct kimage *image)
165167
kexec_start_address = image->start;
166168
kexec_indirection_page = page_list;
167169
kexec_mach_type = machine_arch_type;
168-
kexec_boot_atags = dt_mem ?: image->start - KEXEC_ARM_ZIMAGE_OFFSET
169-
+ KEXEC_ARM_ATAGS_OFFSET;
170+
kexec_boot_atags = image->arch.kernel_r2;
170171

171172
/* copy our kernel relocation code to the control code page */
172173
reboot_entry = fncpy(reboot_code_buffer,

0 commit comments

Comments
 (0)