Skip to content

Commit bf8be1c

Browse files
jiribohacakpm00
authored andcommitted
x86: implement crashkernel cma reservation
Implement the crashkernel CMA reservation for x86: - enable parsing of the cma suffix by parse_crashkernel() - reserve memory with reserve_crashkernel_cma() - add the CMA-reserved ranges to the e820 map for the crash kernel - exclude the CMA-reserved ranges from vmcore Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Jiri Bohac <[email protected]> Cc: Baoquan He <[email protected]> Cc: Dave Young <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Donald Dutile <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Philipp Rudo <[email protected]> Cc: Pingfan Liu <[email protected]> Cc: Tao Liu <[email protected]> Cc: Vivek Goyal <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent e1280f3 commit bf8be1c

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

arch/x86/kernel/crash.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ static struct crash_mem *fill_up_crash_elf_data(void)
163163
return NULL;
164164

165165
/*
166-
* Exclusion of crash region and/or crashk_low_res may cause
167-
* another range split. So add extra two slots here.
166+
* Exclusion of crash region, crashk_low_res and/or crashk_cma_ranges
167+
* may cause range splits. So add extra slots here.
168168
*/
169-
nr_ranges += 2;
169+
nr_ranges += 2 + crashk_cma_cnt;
170170
cmem = vzalloc(struct_size(cmem, ranges, nr_ranges));
171171
if (!cmem)
172172
return NULL;
@@ -184,6 +184,7 @@ static struct crash_mem *fill_up_crash_elf_data(void)
184184
static int elf_header_exclude_ranges(struct crash_mem *cmem)
185185
{
186186
int ret = 0;
187+
int i;
187188

188189
/* Exclude the low 1M because it is always reserved */
189190
ret = crash_exclude_mem_range(cmem, 0, SZ_1M - 1);
@@ -198,8 +199,17 @@ static int elf_header_exclude_ranges(struct crash_mem *cmem)
198199
if (crashk_low_res.end)
199200
ret = crash_exclude_mem_range(cmem, crashk_low_res.start,
200201
crashk_low_res.end);
202+
if (ret)
203+
return ret;
201204

202-
return ret;
205+
for (i = 0; i < crashk_cma_cnt; ++i) {
206+
ret = crash_exclude_mem_range(cmem, crashk_cma_ranges[i].start,
207+
crashk_cma_ranges[i].end);
208+
if (ret)
209+
return ret;
210+
}
211+
212+
return 0;
203213
}
204214

205215
static int prepare_elf64_ram_headers_callback(struct resource *res, void *arg)
@@ -374,6 +384,14 @@ int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)
374384
add_e820_entry(params, &ei);
375385
}
376386

387+
for (i = 0; i < crashk_cma_cnt; ++i) {
388+
ei.addr = crashk_cma_ranges[i].start;
389+
ei.size = crashk_cma_ranges[i].end -
390+
crashk_cma_ranges[i].start + 1;
391+
ei.type = E820_TYPE_RAM;
392+
add_e820_entry(params, &ei);
393+
}
394+
377395
out:
378396
vfree(cmem);
379397
return ret;

arch/x86/kernel/setup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ static void __init memblock_x86_reserve_range_setup_data(void)
599599

600600
static void __init arch_reserve_crashkernel(void)
601601
{
602-
unsigned long long crash_base, crash_size, low_size = 0;
602+
unsigned long long crash_base, crash_size, low_size = 0, cma_size = 0;
603603
bool high = false;
604604
int ret;
605605

@@ -608,7 +608,7 @@ static void __init arch_reserve_crashkernel(void)
608608

609609
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
610610
&crash_size, &crash_base,
611-
&low_size, NULL, &high);
611+
&low_size, &cma_size, &high);
612612
if (ret)
613613
return;
614614

@@ -618,6 +618,7 @@ static void __init arch_reserve_crashkernel(void)
618618
}
619619

620620
reserve_crashkernel_generic(crash_size, crash_base, low_size, high);
621+
reserve_crashkernel_cma(cma_size);
621622
}
622623

623624
static struct resource standard_io_resources[] = {

0 commit comments

Comments
 (0)