Re: [PATCH v3 3/4] arm64: kdump: support more than one crash kernel regions

From: Mike Rapoport
Date: Wed Apr 10 2019 - 09:09:34 EST


Hi,

On Tue, Apr 09, 2019 at 06:28:18PM +0800, Chen Zhou wrote:
> After commit (arm64: kdump: support reserving crashkernel above 4G),
> there may be two crash kernel regions, one is below 4G, the other is
> above 4G.
>
> Crash dump kernel reads more than one crash kernel regions via a dtb
> property under node /chosen,
> linux,usable-memory-range = <BASE1 SIZE1 [BASE2 SIZE2]>
>
> Signed-off-by: Chen Zhou <chenzhou10@xxxxxxxxxx>
> ---
> arch/arm64/mm/init.c | 66 ++++++++++++++++++++++++++++++++++++++++--------
> include/linux/memblock.h | 6 +++++
> mm/memblock.c | 7 ++---
> 3 files changed, 66 insertions(+), 13 deletions(-)
>
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 3bebddf..0f18665 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -65,6 +65,11 @@ phys_addr_t arm64_dma_phys_limit __ro_after_init;
>
> #ifdef CONFIG_KEXEC_CORE
>
> +/* at most two crash kernel regions, low_region and high_region */
> +#define CRASH_MAX_USABLE_RANGES 2
> +#define LOW_REGION_IDX 0
> +#define HIGH_REGION_IDX 1
> +
> /*
> * reserve_crashkernel() - reserves memory for crash kernel
> *
> @@ -297,8 +302,8 @@ static int __init early_init_dt_scan_usablemem(unsigned long node,
> const char *uname, int depth, void *data)
> {
> struct memblock_region *usablemem = data;
> - const __be32 *reg;
> - int len;
> + const __be32 *reg, *endp;
> + int len, nr = 0;
>
> if (depth != 1 || strcmp(uname, "chosen") != 0)
> return 0;
> @@ -307,22 +312,63 @@ static int __init early_init_dt_scan_usablemem(unsigned long node,
> if (!reg || (len < (dt_root_addr_cells + dt_root_size_cells)))
> return 1;
>
> - usablemem->base = dt_mem_next_cell(dt_root_addr_cells, &reg);
> - usablemem->size = dt_mem_next_cell(dt_root_size_cells, &reg);
> + endp = reg + (len / sizeof(__be32));
> + while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
> + usablemem[nr].base = dt_mem_next_cell(dt_root_addr_cells, &reg);
> + usablemem[nr].size = dt_mem_next_cell(dt_root_size_cells, &reg);
> +
> + if (++nr >= CRASH_MAX_USABLE_RANGES)
> + break;
> + }
>
> return 1;
> }
>
> static void __init fdt_enforce_memory_region(void)
> {
> - struct memblock_region reg = {
> - .size = 0,
> - };
> + int i, cnt = 0;
> + struct memblock_region regs[CRASH_MAX_USABLE_RANGES];

I only now noticed that fdt_enforce_memory_region() uses memblock_region to
pass the ranges around. If we'd switch to memblock_type instead, the
implementation of memblock_cap_memory_ranges() would be really
straightforward. Can you check if the below patch works for you?