Skip to content

Commit fdc2682

Browse files
Baoquan Heakpm00
authored andcommitted
arm64: kdump: use generic interface to simplify crashkernel reservation
With the help of newly changed function parse_crashkernel() and generic reserve_crashkernel_generic(), crashkernel reservation can be simplified by steps: 1) Add a new header file <asm/crash_core.h>, and define CRASH_ALIGN, CRASH_ADDR_LOW_MAX, CRASH_ADDR_HIGH_MAX and DEFAULT_CRASH_KERNEL_LOW_SIZE in <asm/crash_core.h>; 2) Add arch_reserve_crashkernel() to call parse_crashkernel() and reserve_crashkernel_generic(); 3) Add ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION Kconfig in arch/arm64/Kconfig. The old reserve_crashkernel_low() and reserve_crashkernel() can be removed. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Baoquan He <[email protected]> Reviewed-by: Zhen Lei <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Chen Jiahao <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 9c08a2a commit fdc2682

File tree

3 files changed

+21
-132
lines changed

3 files changed

+21
-132
lines changed

arch/arm64/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,9 @@ config ARCH_DEFAULT_KEXEC_IMAGE_VERIFY_SIG
14831483
config ARCH_SUPPORTS_CRASH_DUMP
14841484
def_bool y
14851485

1486+
config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION
1487+
def_bool CRASH_CORE
1488+
14861489
config TRANS_TABLE
14871490
def_bool y
14881491
depends on HIBERNATION || KEXEC_CORE

arch/arm64/include/asm/crash_core.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
#ifndef _ARM64_CRASH_CORE_H
3+
#define _ARM64_CRASH_CORE_H
4+
5+
/* Current arm64 boot protocol requires 2MB alignment */
6+
#define CRASH_ALIGN SZ_2M
7+
8+
#define CRASH_ADDR_LOW_MAX arm64_dma_phys_limit
9+
#define CRASH_ADDR_HIGH_MAX (PHYS_MASK + 1)
10+
#endif

arch/arm64/mm/init.c

Lines changed: 8 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,6 @@ EXPORT_SYMBOL(memstart_addr);
6464
*/
6565
phys_addr_t __ro_after_init arm64_dma_phys_limit;
6666

67-
/* Current arm64 boot protocol requires 2MB alignment */
68-
#define CRASH_ALIGN SZ_2M
69-
70-
#define CRASH_ADDR_LOW_MAX arm64_dma_phys_limit
71-
#define CRASH_ADDR_HIGH_MAX (PHYS_MASK + 1)
72-
#define CRASH_HIGH_SEARCH_BASE SZ_4G
73-
74-
#define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20)
75-
7667
/*
7768
* To make optimal use of block mappings when laying out the linear
7869
* mapping, round down the base of physical memory to a size that can
@@ -100,140 +91,25 @@ phys_addr_t __ro_after_init arm64_dma_phys_limit;
10091
#define ARM64_MEMSTART_ALIGN (1UL << ARM64_MEMSTART_SHIFT)
10192
#endif
10293

103-
static int __init reserve_crashkernel_low(unsigned long long low_size)
104-
{
105-
unsigned long long low_base;
106-
107-
low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX);
108-
if (!low_base) {
109-
pr_err("cannot allocate crashkernel low memory (size:0x%llx).\n", low_size);
110-
return -ENOMEM;
111-
}
112-
113-
pr_info("crashkernel low memory reserved: 0x%08llx - 0x%08llx (%lld MB)\n",
114-
low_base, low_base + low_size, low_size >> 20);
115-
116-
crashk_low_res.start = low_base;
117-
crashk_low_res.end = low_base + low_size - 1;
118-
insert_resource(&iomem_resource, &crashk_low_res);
119-
120-
return 0;
121-
}
122-
123-
/*
124-
* reserve_crashkernel() - reserves memory for crash kernel
125-
*
126-
* This function reserves memory area given in "crashkernel=" kernel command
127-
* line parameter. The memory reserved is used by dump capture kernel when
128-
* primary kernel is crashing.
129-
*/
130-
static void __init reserve_crashkernel(void)
94+
static void __init arch_reserve_crashkernel(void)
13195
{
132-
unsigned long long crash_low_size = 0, search_base = 0;
133-
unsigned long long crash_max = CRASH_ADDR_LOW_MAX;
96+
unsigned long long low_size = 0;
13497
unsigned long long crash_base, crash_size;
13598
char *cmdline = boot_command_line;
136-
bool fixed_base = false;
13799
bool high = false;
138100
int ret;
139101

140102
if (!IS_ENABLED(CONFIG_KEXEC_CORE))
141103
return;
142104

143-
/* crashkernel=X[@offset] */
144105
ret = parse_crashkernel(cmdline, memblock_phys_mem_size(),
145-
&crash_size, &crash_base, NULL, NULL);
146-
if (ret == -ENOENT) {
147-
ret = parse_crashkernel_high(cmdline, 0, &crash_size, &crash_base);
148-
if (ret || !crash_size)
149-
return;
150-
151-
/*
152-
* crashkernel=Y,low can be specified or not, but invalid value
153-
* is not allowed.
154-
*/
155-
ret = parse_crashkernel_low(cmdline, 0, &crash_low_size, &crash_base);
156-
if (ret == -ENOENT)
157-
crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
158-
else if (ret)
159-
return;
160-
161-
search_base = CRASH_HIGH_SEARCH_BASE;
162-
crash_max = CRASH_ADDR_HIGH_MAX;
163-
high = true;
164-
} else if (ret || !crash_size) {
165-
/* The specified value is invalid */
106+
&crash_size, &crash_base,
107+
&low_size, &high);
108+
if (ret)
166109
return;
167-
}
168-
169-
crash_size = PAGE_ALIGN(crash_size);
170-
171-
/* User specifies base address explicitly. */
172-
if (crash_base) {
173-
fixed_base = true;
174-
search_base = crash_base;
175-
crash_max = crash_base + crash_size;
176-
}
177-
178-
retry:
179-
crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN,
180-
search_base, crash_max);
181-
if (!crash_base) {
182-
/*
183-
* For crashkernel=size[KMG]@offset[KMG], print out failure
184-
* message if can't reserve the specified region.
185-
*/
186-
if (fixed_base) {
187-
pr_warn("crashkernel reservation failed - memory is in use.\n");
188-
return;
189-
}
190-
191-
/*
192-
* For crashkernel=size[KMG], if the first attempt was for
193-
* low memory, fall back to high memory, the minimum required
194-
* low memory will be reserved later.
195-
*/
196-
if (!high && crash_max == CRASH_ADDR_LOW_MAX) {
197-
crash_max = CRASH_ADDR_HIGH_MAX;
198-
search_base = CRASH_ADDR_LOW_MAX;
199-
crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
200-
goto retry;
201-
}
202-
203-
/*
204-
* For crashkernel=size[KMG],high, if the first attempt was
205-
* for high memory, fall back to low memory.
206-
*/
207-
if (high && crash_max == CRASH_ADDR_HIGH_MAX) {
208-
crash_max = CRASH_ADDR_LOW_MAX;
209-
search_base = 0;
210-
goto retry;
211-
}
212-
pr_warn("cannot allocate crashkernel (size:0x%llx)\n",
213-
crash_size);
214-
return;
215-
}
216-
217-
if ((crash_base >= CRASH_ADDR_LOW_MAX) && crash_low_size &&
218-
reserve_crashkernel_low(crash_low_size)) {
219-
memblock_phys_free(crash_base, crash_size);
220-
return;
221-
}
222-
223-
pr_info("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n",
224-
crash_base, crash_base + crash_size, crash_size >> 20);
225-
226-
/*
227-
* The crashkernel memory will be removed from the kernel linear
228-
* map. Inform kmemleak so that it won't try to access it.
229-
*/
230-
kmemleak_ignore_phys(crash_base);
231-
if (crashk_low_res.end)
232-
kmemleak_ignore_phys(crashk_low_res.start);
233110

234-
crashk_res.start = crash_base;
235-
crashk_res.end = crash_base + crash_size - 1;
236-
insert_resource(&iomem_resource, &crashk_res);
111+
reserve_crashkernel_generic(cmdline, crash_size, crash_base,
112+
low_size, high);
237113
}
238114

239115
/*
@@ -479,7 +355,7 @@ void __init bootmem_init(void)
479355
* request_standard_resources() depends on crashkernel's memory being
480356
* reserved, so do it here.
481357
*/
482-
reserve_crashkernel();
358+
arch_reserve_crashkernel();
483359

484360
memblock_dump_all();
485361
}

0 commit comments

Comments
 (0)