Skip to content

Commit 0d3db54

Browse files
author
AKASHI Takahiro
committed
arm64: kdump: reserve memory for crash dump kernel
"crashkernel=" kernel parameter specifies the size (and optionally the start address) of the system ram to be used by crash dump kernel. reserve_crashkernel() will allocate and reserve that memory at boot time of primary kernel. The memory range will be exposed to userspace as a resource named "Crash kernel" in /proc/iomem. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Mark Salter <msalter@redhat.com> Signed-off-by: Pratyush Anand <panand@redhat.com> Reviewed-by: James Morse <james.morse@arm.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Conflicts: arch/arm64/mm/init.c due to some included headers which are not to be here.
1 parent a6a7862 commit 0d3db54

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

arch/arm64/kernel/setup.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <linux/screen_info.h>
3232
#include <linux/init.h>
3333
#include <linux/kexec.h>
34-
#include <linux/crash_dump.h>
3534
#include <linux/root_dev.h>
3635
#include <linux/cpu.h>
3736
#include <linux/interrupt.h>
@@ -220,6 +219,12 @@ static void __init request_standard_resources(void)
220219
if (kernel_data.start >= res->start &&
221220
kernel_data.end <= res->end)
222221
request_resource(res, &kernel_data);
222+
#ifdef CONFIG_KEXEC_CORE
223+
/* Userspace will find "Crash kernel" region in /proc/iomem. */
224+
if (crashk_res.end && crashk_res.start >= res->start &&
225+
crashk_res.end <= res->end)
226+
request_resource(res, &crashk_res);
227+
#endif
223228
}
224229
}
225230

arch/arm64/mm/init.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
#include <linux/gfp.h>
3030
#include <linux/memblock.h>
3131
#include <linux/sort.h>
32+
#include <linux/of.h>
3233
#include <linux/of_fdt.h>
3334
#include <linux/dma-mapping.h>
3435
#include <linux/dma-contiguous.h>
3536
#include <linux/efi.h>
3637
#include <linux/swiotlb.h>
38+
#include <linux/kexec.h>
3739

3840
#include <asm/boot.h>
3941
#include <asm/fixmap.h>
@@ -75,6 +77,67 @@ static int __init early_initrd(char *p)
7577
early_param("initrd", early_initrd);
7678
#endif
7779

80+
#ifdef CONFIG_KEXEC_CORE
81+
/*
82+
* reserve_crashkernel() - reserves memory for crash kernel
83+
*
84+
* This function reserves memory area given in "crashkernel=" kernel command
85+
* line parameter. The memory reserved is used by dump capture kernel when
86+
* primary kernel is crashing.
87+
*/
88+
static void __init reserve_crashkernel(void)
89+
{
90+
unsigned long long crash_base, crash_size;
91+
int ret;
92+
93+
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
94+
&crash_size, &crash_base);
95+
/* no crashkernel= or invalid value specified */
96+
if (ret || !crash_size)
97+
return;
98+
99+
crash_size = PAGE_ALIGN(crash_size);
100+
101+
if (crash_base == 0) {
102+
/* Current arm64 boot protocol requires 2MB alignment */
103+
crash_base = memblock_find_in_range(0, ARCH_LOW_ADDRESS_LIMIT,
104+
crash_size, SZ_2M);
105+
if (crash_base == 0) {
106+
pr_warn("cannot allocate crashkernel (size:0x%llx)\n",
107+
crash_size);
108+
return;
109+
}
110+
} else {
111+
/* User specifies base address explicitly. */
112+
if (!memblock_is_region_memory(crash_base, crash_size)) {
113+
pr_warn("cannot reserve crashkernel: region is not memory\n");
114+
return;
115+
}
116+
117+
if (memblock_is_region_reserved(crash_base, crash_size)) {
118+
pr_warn("cannot reserve crashkernel: region overlaps reserved memory\n");
119+
return;
120+
}
121+
122+
if (!IS_ALIGNED(crash_base, SZ_2M)) {
123+
pr_warn("cannot reserve crashkernel: base address is not 2MB aligned\n");
124+
return;
125+
}
126+
}
127+
memblock_reserve(crash_base, crash_size);
128+
129+
pr_info("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n",
130+
crash_base, crash_base + crash_size, crash_size >> 20);
131+
132+
crashk_res.start = crash_base;
133+
crashk_res.end = crash_base + crash_size - 1;
134+
}
135+
#else
136+
static void __init reserve_crashkernel(void)
137+
{
138+
}
139+
#endif /* CONFIG_KEXEC_CORE */
140+
78141
/*
79142
* Return the maximum physical address for ZONE_DMA (DMA_BIT_MASK(32)). It
80143
* currently assumes that for memory starting above 4G, 32-bit devices will
@@ -277,6 +340,9 @@ void __init arm64_memblock_init(void)
277340
arm64_dma_phys_limit = max_zone_dma_phys();
278341
else
279342
arm64_dma_phys_limit = PHYS_MASK + 1;
343+
344+
reserve_crashkernel();
345+
280346
dma_contiguous_reserve(arm64_dma_phys_limit);
281347

282348
memblock_allow_resize();

0 commit comments

Comments
 (0)