Commit 6120cdc0 authored by Mike Rapoport's avatar Mike Rapoport Committed by Linus Torvalds

x86/setup: simplify reserve_crashkernel()

* Replace magic numbers with defines
* Replace memblock_find_in_range() + memblock_reserve() with
  memblock_phys_alloc_range()
* Stop checking for low memory size in reserve_crashkernel_low(). The
  allocation from limited range will anyway fail if there is no enough
  memory, so there is no need for extra traversal of memblock.memory
Signed-off-by: default avatarMike Rapoport <rppt@linux.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarBaoquan He <bhe@redhat.com>
Acked-by: default avatarIngo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Daniel Axtens <dja@axtens.net>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Emil Renner Berthing <kernel@esmil.dk>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Stafford Horne <shorne@gmail.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Link: https://lkml.kernel.org/r/20200818151634.14343-15-rppt@kernel.orgSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 3c45ee6d
...@@ -421,13 +421,13 @@ static int __init reserve_crashkernel_low(void) ...@@ -421,13 +421,13 @@ static int __init reserve_crashkernel_low(void)
{ {
#ifdef CONFIG_X86_64 #ifdef CONFIG_X86_64
unsigned long long base, low_base = 0, low_size = 0; unsigned long long base, low_base = 0, low_size = 0;
unsigned long total_low_mem; unsigned long low_mem_limit;
int ret; int ret;
total_low_mem = memblock_mem_size(1UL << (32 - PAGE_SHIFT)); low_mem_limit = min(memblock_phys_mem_size(), CRASH_ADDR_LOW_MAX);
/* crashkernel=Y,low */ /* crashkernel=Y,low */
ret = parse_crashkernel_low(boot_command_line, total_low_mem, &low_size, &base); ret = parse_crashkernel_low(boot_command_line, low_mem_limit, &low_size, &base);
if (ret) { if (ret) {
/* /*
* two parts from kernel/dma/swiotlb.c: * two parts from kernel/dma/swiotlb.c:
...@@ -445,23 +445,17 @@ static int __init reserve_crashkernel_low(void) ...@@ -445,23 +445,17 @@ static int __init reserve_crashkernel_low(void)
return 0; return 0;
} }
low_base = memblock_find_in_range(0, 1ULL << 32, low_size, CRASH_ALIGN); low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX);
if (!low_base) { if (!low_base) {
pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n",
(unsigned long)(low_size >> 20)); (unsigned long)(low_size >> 20));
return -ENOMEM; return -ENOMEM;
} }
ret = memblock_reserve(low_base, low_size); pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (low RAM limit: %ldMB)\n",
if (ret) {
pr_err("%s: Error reserving crashkernel low memblock.\n", __func__);
return ret;
}
pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (System low RAM: %ldMB)\n",
(unsigned long)(low_size >> 20), (unsigned long)(low_size >> 20),
(unsigned long)(low_base >> 20), (unsigned long)(low_base >> 20),
(unsigned long)(total_low_mem >> 20)); (unsigned long)(low_mem_limit >> 20));
crashk_low_res.start = low_base; crashk_low_res.start = low_base;
crashk_low_res.end = low_base + low_size - 1; crashk_low_res.end = low_base + low_size - 1;
...@@ -505,13 +499,13 @@ static void __init reserve_crashkernel(void) ...@@ -505,13 +499,13 @@ static void __init reserve_crashkernel(void)
* unless "crashkernel=size[KMG],high" is specified. * unless "crashkernel=size[KMG],high" is specified.
*/ */
if (!high) if (!high)
crash_base = memblock_find_in_range(CRASH_ALIGN, crash_base = memblock_phys_alloc_range(crash_size,
CRASH_ADDR_LOW_MAX, CRASH_ALIGN, CRASH_ALIGN,
crash_size, CRASH_ALIGN); CRASH_ADDR_LOW_MAX);
if (!crash_base) if (!crash_base)
crash_base = memblock_find_in_range(CRASH_ALIGN, crash_base = memblock_phys_alloc_range(crash_size,
CRASH_ADDR_HIGH_MAX, CRASH_ALIGN, CRASH_ALIGN,
crash_size, CRASH_ALIGN); CRASH_ADDR_HIGH_MAX);
if (!crash_base) { if (!crash_base) {
pr_info("crashkernel reservation failed - No suitable area found.\n"); pr_info("crashkernel reservation failed - No suitable area found.\n");
return; return;
...@@ -519,19 +513,13 @@ static void __init reserve_crashkernel(void) ...@@ -519,19 +513,13 @@ static void __init reserve_crashkernel(void)
} else { } else {
unsigned long long start; unsigned long long start;
start = memblock_find_in_range(crash_base, start = memblock_phys_alloc_range(crash_size, SZ_1M, crash_base,
crash_base + crash_size, crash_base + crash_size);
crash_size, 1 << 20);
if (start != crash_base) { if (start != crash_base) {
pr_info("crashkernel reservation failed - memory is in use.\n"); pr_info("crashkernel reservation failed - memory is in use.\n");
return; return;
} }
} }
ret = memblock_reserve(crash_base, crash_size);
if (ret) {
pr_err("%s: Error reserving crashkernel memblock.\n", __func__);
return;
}
if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) {
memblock_free(crash_base, crash_size); memblock_free(crash_base, crash_size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment