| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| From: Hari Bathini <hbathini@linux.ibm.com> |
| Date: Wed, 9 Oct 2019 10:45:26 +0530 |
| Subject: [PATCH 3/8] powerpc/fadump: improve how crashed kernel's memory is |
| reserved |
| |
| The size parameter to fadump_reserve_crash_area() function is not needed |
| as all the memory above boot memory size must be preserved anyway. Update |
| the function by dropping this redundant parameter. |
| |
| This is the backport of upstream commit b2a815a554a3 ("powerpc/fadump: |
| improve how crashed kernel's memory is reserved"). |
| |
| Signed-off-by: Hari Bathini <hbathini@linux.ibm.com> |
| Signed-off-by: Joel Stanley <joel@jms.id.au> |
| --- |
| arch/powerpc/kernel/fadump.c | 53 ++++++++++++++++++++---------------- |
| 1 file changed, 30 insertions(+), 23 deletions(-) |
| |
| diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c |
| index 4eab97292cc2..4dacce3fac72 100644 |
| --- a/arch/powerpc/kernel/fadump.c |
| +++ b/arch/powerpc/kernel/fadump.c |
| @@ -33,6 +33,9 @@ |
| #include <asm/setup.h> |
| |
| static struct fw_dump fw_dump; |
| + |
| +static void __init fadump_reserve_crash_area(u64 base); |
| + |
| static struct fadump_mem_struct fdm; |
| static const struct fadump_mem_struct *fdm_active; |
| #ifdef CONFIG_CMA |
| @@ -426,26 +429,6 @@ static unsigned long get_fadump_area_size(void) |
| return size; |
| } |
| |
| -static void __init fadump_reserve_crash_area(unsigned long base, |
| - unsigned long size) |
| -{ |
| - struct memblock_region *reg; |
| - unsigned long mstart, mend, msize; |
| - |
| - for_each_memblock(memory, reg) { |
| - mstart = max_t(unsigned long, base, reg->base); |
| - mend = reg->base + reg->size; |
| - mend = min(base + size, mend); |
| - |
| - if (mstart < mend) { |
| - msize = mend - mstart; |
| - memblock_reserve(mstart, msize); |
| - pr_info("Reserved %ldMB of memory at %#016lx for saving crash dump\n", |
| - (msize >> 20), mstart); |
| - } |
| - } |
| -} |
| - |
| int __init fadump_reserve_mem(void) |
| { |
| unsigned long base, size, memory_boundary; |
| @@ -510,13 +493,13 @@ int __init fadump_reserve_mem(void) |
| #endif |
| /* |
| * If last boot has crashed then reserve all the memory |
| - * above boot_memory_size so that we don't touch it until |
| + * above boot memory size so that we don't touch it until |
| * dump is written to disk by userspace tool. This memory |
| - * will be released for general use once the dump is saved. |
| + * can be released for general use by invalidating fadump. |
| */ |
| base = fw_dump.boot_memory_size; |
| size = memory_boundary - base; |
| - fadump_reserve_crash_area(base, size); |
| + fadump_reserve_crash_area(base); |
| |
| fw_dump.fadumphdr_addr = |
| be64_to_cpu(fdm_active->rmr_region.destination_address) + |
| @@ -1701,3 +1684,27 @@ int __init setup_fadump(void) |
| return 1; |
| } |
| subsys_initcall(setup_fadump); |
| + |
| +/* Preserve everything above the base address */ |
| +static void __init fadump_reserve_crash_area(u64 base) |
| +{ |
| + struct memblock_region *reg; |
| + u64 mstart, msize; |
| + |
| + for_each_memblock(memory, reg) { |
| + mstart = reg->base; |
| + msize = reg->size; |
| + |
| + if ((mstart + msize) < base) |
| + continue; |
| + |
| + if (mstart < base) { |
| + msize -= (base - mstart); |
| + mstart = base; |
| + } |
| + |
| + pr_info("Reserving %lluMB of memory at %#016llx for preserving crash data", |
| + (msize >> 20), mstart); |
| + memblock_reserve(mstart, msize); |
| + } |
| +} |