Skip to content

Commit ab47551

Browse files
jiribohacakpm00
authored andcommitted
kdump: implement reserve_crashkernel_cma
reserve_crashkernel_cma() reserves CMA ranges for the crash kernel. If allocating the requested size fails, try to reserve in smaller blocks. Store the reserved ranges in the crashk_cma_ranges array and the number of ranges in crashk_cma_cnt. 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 35c18f2 commit ab47551

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

include/linux/crash_reserve.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,24 @@
1313
*/
1414
extern struct resource crashk_res;
1515
extern struct resource crashk_low_res;
16+
extern struct range crashk_cma_ranges[];
17+
#if defined(CONFIG_CMA) && defined(CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION)
18+
#define CRASHKERNEL_CMA
19+
#define CRASHKERNEL_CMA_RANGES_MAX 4
20+
extern int crashk_cma_cnt;
21+
#else
22+
#define crashk_cma_cnt 0
23+
#define CRASHKERNEL_CMA_RANGES_MAX 0
24+
#endif
25+
1626

1727
int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
1828
unsigned long long *crash_size, unsigned long long *crash_base,
1929
unsigned long long *low_size, unsigned long long *cma_size,
2030
bool *high);
2131

32+
void __init reserve_crashkernel_cma(unsigned long long cma_size);
33+
2234
#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION
2335
#ifndef DEFAULT_CRASH_KERNEL_LOW_SIZE
2436
#define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20)

kernel/crash_reserve.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <linux/cpuhotplug.h>
1515
#include <linux/memblock.h>
1616
#include <linux/kmemleak.h>
17+
#include <linux/cma.h>
18+
#include <linux/crash_reserve.h>
1719

1820
#include <asm/page.h>
1921
#include <asm/sections.h>
@@ -469,6 +471,56 @@ void __init reserve_crashkernel_generic(unsigned long long crash_size,
469471
#endif
470472
}
471473

474+
struct range crashk_cma_ranges[CRASHKERNEL_CMA_RANGES_MAX];
475+
#ifdef CRASHKERNEL_CMA
476+
int crashk_cma_cnt;
477+
void __init reserve_crashkernel_cma(unsigned long long cma_size)
478+
{
479+
unsigned long long request_size = roundup(cma_size, PAGE_SIZE);
480+
unsigned long long reserved_size = 0;
481+
482+
if (!cma_size)
483+
return;
484+
485+
while (cma_size > reserved_size &&
486+
crashk_cma_cnt < CRASHKERNEL_CMA_RANGES_MAX) {
487+
488+
struct cma *res;
489+
490+
if (cma_declare_contiguous(0, request_size, 0, 0, 0, false,
491+
"crashkernel", &res)) {
492+
/* reservation failed, try half-sized blocks */
493+
if (request_size <= PAGE_SIZE)
494+
break;
495+
496+
request_size = roundup(request_size / 2, PAGE_SIZE);
497+
continue;
498+
}
499+
500+
crashk_cma_ranges[crashk_cma_cnt].start = cma_get_base(res);
501+
crashk_cma_ranges[crashk_cma_cnt].end =
502+
crashk_cma_ranges[crashk_cma_cnt].start +
503+
cma_get_size(res) - 1;
504+
++crashk_cma_cnt;
505+
reserved_size += request_size;
506+
}
507+
508+
if (cma_size > reserved_size)
509+
pr_warn("crashkernel CMA reservation failed: %lld MB requested, %lld MB reserved in %d ranges\n",
510+
cma_size >> 20, reserved_size >> 20, crashk_cma_cnt);
511+
else
512+
pr_info("crashkernel CMA reserved: %lld MB in %d ranges\n",
513+
reserved_size >> 20, crashk_cma_cnt);
514+
}
515+
516+
#else /* CRASHKERNEL_CMA */
517+
void __init reserve_crashkernel_cma(unsigned long long cma_size)
518+
{
519+
if (cma_size)
520+
pr_warn("crashkernel CMA reservation not supported\n");
521+
}
522+
#endif
523+
472524
#ifndef HAVE_ARCH_ADD_CRASH_RES_TO_IOMEM_EARLY
473525
static __init int insert_crashkernel_resources(void)
474526
{

0 commit comments

Comments
 (0)