Joel Stanley | 2d7d343 | 2019-10-09 16:55:26 +1030 | [diff] [blame] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | From: Hari Bathini <hbathini@linux.ibm.com> |
| 3 | Date: Wed, 9 Oct 2019 10:45:26 +0530 |
Joel Stanley | d7fd58d | 2019-10-23 12:30:37 +1100 | [diff] [blame] | 4 | Subject: [PATCH 3/8] powerpc/fadump: improve how crashed kernel's memory is |
Joel Stanley | 2d7d343 | 2019-10-09 16:55:26 +1030 | [diff] [blame] | 5 | reserved |
| 6 | |
| 7 | The size parameter to fadump_reserve_crash_area() function is not needed |
| 8 | as all the memory above boot memory size must be preserved anyway. Update |
| 9 | the function by dropping this redundant parameter. |
| 10 | |
| 11 | This is the backport of upstream commit b2a815a554a3 ("powerpc/fadump: |
| 12 | improve how crashed kernel's memory is reserved"). |
| 13 | |
| 14 | Signed-off-by: Hari Bathini <hbathini@linux.ibm.com> |
| 15 | Signed-off-by: Joel Stanley <joel@jms.id.au> |
| 16 | --- |
| 17 | arch/powerpc/kernel/fadump.c | 53 ++++++++++++++++++++---------------- |
| 18 | 1 file changed, 30 insertions(+), 23 deletions(-) |
| 19 | |
| 20 | diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c |
| 21 | index 4eab97292cc2..4dacce3fac72 100644 |
| 22 | --- a/arch/powerpc/kernel/fadump.c |
| 23 | +++ b/arch/powerpc/kernel/fadump.c |
| 24 | @@ -33,6 +33,9 @@ |
| 25 | #include <asm/setup.h> |
| 26 | |
| 27 | static struct fw_dump fw_dump; |
| 28 | + |
| 29 | +static void __init fadump_reserve_crash_area(u64 base); |
| 30 | + |
| 31 | static struct fadump_mem_struct fdm; |
| 32 | static const struct fadump_mem_struct *fdm_active; |
| 33 | #ifdef CONFIG_CMA |
| 34 | @@ -426,26 +429,6 @@ static unsigned long get_fadump_area_size(void) |
| 35 | return size; |
| 36 | } |
| 37 | |
| 38 | -static void __init fadump_reserve_crash_area(unsigned long base, |
| 39 | - unsigned long size) |
| 40 | -{ |
| 41 | - struct memblock_region *reg; |
| 42 | - unsigned long mstart, mend, msize; |
| 43 | - |
| 44 | - for_each_memblock(memory, reg) { |
| 45 | - mstart = max_t(unsigned long, base, reg->base); |
| 46 | - mend = reg->base + reg->size; |
| 47 | - mend = min(base + size, mend); |
| 48 | - |
| 49 | - if (mstart < mend) { |
| 50 | - msize = mend - mstart; |
| 51 | - memblock_reserve(mstart, msize); |
| 52 | - pr_info("Reserved %ldMB of memory at %#016lx for saving crash dump\n", |
| 53 | - (msize >> 20), mstart); |
| 54 | - } |
| 55 | - } |
| 56 | -} |
| 57 | - |
| 58 | int __init fadump_reserve_mem(void) |
| 59 | { |
| 60 | unsigned long base, size, memory_boundary; |
| 61 | @@ -510,13 +493,13 @@ int __init fadump_reserve_mem(void) |
| 62 | #endif |
| 63 | /* |
| 64 | * If last boot has crashed then reserve all the memory |
| 65 | - * above boot_memory_size so that we don't touch it until |
| 66 | + * above boot memory size so that we don't touch it until |
| 67 | * dump is written to disk by userspace tool. This memory |
| 68 | - * will be released for general use once the dump is saved. |
| 69 | + * can be released for general use by invalidating fadump. |
| 70 | */ |
| 71 | base = fw_dump.boot_memory_size; |
| 72 | size = memory_boundary - base; |
| 73 | - fadump_reserve_crash_area(base, size); |
| 74 | + fadump_reserve_crash_area(base); |
| 75 | |
| 76 | fw_dump.fadumphdr_addr = |
| 77 | be64_to_cpu(fdm_active->rmr_region.destination_address) + |
| 78 | @@ -1701,3 +1684,27 @@ int __init setup_fadump(void) |
| 79 | return 1; |
| 80 | } |
| 81 | subsys_initcall(setup_fadump); |
| 82 | + |
| 83 | +/* Preserve everything above the base address */ |
| 84 | +static void __init fadump_reserve_crash_area(u64 base) |
| 85 | +{ |
| 86 | + struct memblock_region *reg; |
| 87 | + u64 mstart, msize; |
| 88 | + |
| 89 | + for_each_memblock(memory, reg) { |
| 90 | + mstart = reg->base; |
| 91 | + msize = reg->size; |
| 92 | + |
| 93 | + if ((mstart + msize) < base) |
| 94 | + continue; |
| 95 | + |
| 96 | + if (mstart < base) { |
| 97 | + msize -= (base - mstart); |
| 98 | + mstart = base; |
| 99 | + } |
| 100 | + |
| 101 | + pr_info("Reserving %lluMB of memory at %#016llx for preserving crash data", |
| 102 | + (msize >> 20), mstart); |
| 103 | + memblock_reserve(mstart, msize); |
| 104 | + } |
| 105 | +} |