[PATCH -v2] x86, memblock: Fix crashkernel allocation Cai Qian found crashkernel is broken with x86 memblock changes 1. crashkernel=128M@32M always reported that range is used, even first kernel is small no one use that range 2. always get following report when using "kexec -p" Could not find a free area of memory of a000 bytes... locate_hole failed The root cause is that generic memblock_find_in_range() will try to get range from top_down. But crashkernel do need from low and specified range. Let's limit the target range with rash_base + crash_size to make sure that We get range from bottom. -v2: don't limit it with 0xffffffff, in case kexec will use bzImage 64bit entry or vmlinux, and try to allocate huge area for crashkernel. Reported-and-Bisected-by: CAI Qian Signed-off-by: Yinghai Lu --- arch/x86/kernel/setup.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) Index: linux-2.6/arch/x86/kernel/setup.c =================================================================== --- linux-2.6.orig/arch/x86/kernel/setup.c +++ linux-2.6/arch/x86/kernel/setup.c @@ -516,19 +516,28 @@ static void __init reserve_crashkernel(v /* 0 means: find the address automatically */ if (crash_base <= 0) { + unsigned long long start = 0; const unsigned long long alignment = 16<<20; /* 16M */ - crash_base = memblock_find_in_range(alignment, ULONG_MAX, crash_size, - alignment); - if (crash_base == MEMBLOCK_ERROR) { + crash_base = alignment; + while ((crash_base + crash_size) <= total_mem) { + start = memblock_find_in_range(crash_base, + crash_base + crash_size, crash_size, alignment); + + if (start == crash_base) + break; + + crash_base += alignment; + } + if (start != crash_base) { pr_info("crashkernel reservation failed - No suitable area found.\n"); return; } } else { unsigned long long start; - start = memblock_find_in_range(crash_base, ULONG_MAX, crash_size, - 1<<20); + start = memblock_find_in_range(crash_base, + crash_base + crash_size, crash_size, 1<<20); if (start != crash_base) { pr_info("crashkernel reservation failed - memory is in use.\n"); return;