Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp181636yba; Wed, 3 Apr 2019 06:53:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEN00b1kaiLO+aHXQZUuqsyzeGQL30YktDsRMS25nuRk6F/7lqWrFM7YdLPYZffNerM+oD X-Received: by 2002:a17:902:8345:: with SMTP id z5mr23721868pln.197.1554299593671; Wed, 03 Apr 2019 06:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554299593; cv=none; d=google.com; s=arc-20160816; b=D+xpyw4MhVY7p9UpbbCY2OnSg4a9HJBrj0i+qMA9TYXyix/TaIGqR0EqNmdRoVWZB3 /yG8I6+ZgmYVgaajdO8YalV0U/Wfpc0ttYrz0NKnXYRWkHizoGXnYgFURF9RYDPyQBEz Mx0V5NE7c1K6ioLq2++sDy5OOaJ9m6muN28VXhCGaNts2kCJva98vpJJwRW8Odx4z+YK iLn5QmY76WmumMAkdhGu7mLhSVpuYqG1bkePs03IV9tEb4nHpCCanF7aXrXCbMa28jiN EpWVMj1p9tptnRil4xEijqchyW+HnSg7a1oClewDp/E+6c+wO+uWZEo4Wq4QVqPKY+He 4MKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=hMqWuI/9b+ZRX77roP5GfpQ2LoTiBddiSi6eq65PLE8=; b=hdCtcnfj40mUE2uQ2ddkiPfDWvvG5S3AMPqCbJBc2Oet7LXC9T7tasdpeIHkC0lAc1 A+crq3ERTodgEPp7uN+UHUITYo6lT+SaHN/mgKHpsU4MPyO0Mg4NPobdDnUDignFCWQj IEka0kVDw5JhdCrMod5jKGibR4xQy3b0hCIdopTHjpBmsMlY29Cny6/27Jrg66EvaiVW JpUVuRgVH05Y4hPpD3N1Z+8VOVJ8NQdD+8PnySM9lOgCF90a+yGWC9WkZ0zOu200mdKz ry46uY+2aw+HtC47SlqeRPk2NGW8LLwQh4Bxl+8fgT4ZrwhSuokH3AuYbYI2CK9Rt5xM JydQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n7si13743105pff.190.2019.04.03.06.52.58; Wed, 03 Apr 2019 06:53:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726545AbfDCNvw (ORCPT + 99 others); Wed, 3 Apr 2019 09:51:52 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:6227 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725959AbfDCNvw (ORCPT ); Wed, 3 Apr 2019 09:51:52 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [10.3.19.207]) by Forcepoint Email with ESMTP id 7F3A75F44857EBFD6F91; Wed, 3 Apr 2019 21:51:38 +0800 (CST) Received: from [127.0.0.1] (10.177.131.64) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.408.0; Wed, 3 Apr 2019 21:51:29 +0800 Subject: Re: [PATCH 2/3] arm64: kdump: support more than one crash kernel regions To: Mike Rapoport References: <20190403030546.23718-1-chenzhou10@huawei.com> <20190403030546.23718-3-chenzhou10@huawei.com> <20190403112929.GA7715@rapoport-lnx> CC: , , , , , , , , , From: Chen Zhou Message-ID: Date: Wed, 3 Apr 2019 21:51:27 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20190403112929.GA7715@rapoport-lnx> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.131.64] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mike, On 2019/4/3 19:29, Mike Rapoport wrote: > On Wed, Apr 03, 2019 at 11:05:45AM +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 = >> >> Signed-off-by: Chen Zhou >> --- >> arch/arm64/mm/init.c | 37 +++++++++++++++++++++++++------------ >> include/linux/memblock.h | 1 + >> mm/memblock.c | 40 ++++++++++++++++++++++++++++++++++++++++ >> 3 files changed, 66 insertions(+), 12 deletions(-) >> >> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c >> index ceb2a25..769c77a 100644 >> --- a/arch/arm64/mm/init.c >> +++ b/arch/arm64/mm/init.c >> @@ -64,6 +64,8 @@ EXPORT_SYMBOL(memstart_addr); >> phys_addr_t arm64_dma_phys_limit __ro_after_init; >> >> #ifdef CONFIG_KEXEC_CORE >> +# define CRASH_MAX_USABLE_RANGES 2 >> + >> static int __init reserve_crashkernel_low(void) >> { >> unsigned long long base, low_base = 0, low_size = 0; >> @@ -346,8 +348,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; >> @@ -356,22 +358,33 @@ 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, ®); >> - usablemem->size = dt_mem_next_cell(dt_root_size_cells, ®); >> + 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, ®); >> + usablemem[nr].size = dt_mem_next_cell(dt_root_size_cells, ®); >> + >> + if (++nr >= CRASH_MAX_USABLE_RANGES) >> + break; >> + } >> >> return 1; >> } >> >> static void __init fdt_enforce_memory_region(void) >> { >> - struct memblock_region reg = { >> - .size = 0, >> - }; >> - >> - of_scan_flat_dt(early_init_dt_scan_usablemem, ®); >> - >> - if (reg.size) >> - memblock_cap_memory_range(reg.base, reg.size); >> + int i, cnt = 0; >> + struct memblock_region regs[CRASH_MAX_USABLE_RANGES]; >> + >> + memset(regs, 0, sizeof(regs)); >> + of_scan_flat_dt(early_init_dt_scan_usablemem, regs); >> + >> + for (i = 0; i < CRASH_MAX_USABLE_RANGES; i++) >> + if (regs[i].size) >> + cnt++; >> + else >> + break; >> + if (cnt) >> + memblock_cap_memory_ranges(regs, cnt); > > Why not simply call memblock_cap_memory_range() for each region? Function memblock_cap_memory_range() removes all memory type ranges except specified range. So if we call memblock_cap_memory_range() for each region simply, there will be no usable-memory on kdump capture kernel. Thanks, Chen Zhou > >> } >> >> void __init arm64_memblock_init(void) >> diff --git a/include/linux/memblock.h b/include/linux/memblock.h >> index 47e3c06..aeade34 100644 >> --- a/include/linux/memblock.h >> +++ b/include/linux/memblock.h >> @@ -446,6 +446,7 @@ phys_addr_t memblock_start_of_DRAM(void); >> phys_addr_t memblock_end_of_DRAM(void); >> void memblock_enforce_memory_limit(phys_addr_t memory_limit); >> void memblock_cap_memory_range(phys_addr_t base, phys_addr_t size); >> +void memblock_cap_memory_ranges(struct memblock_region *regs, int cnt); >> void memblock_mem_limit_remove_map(phys_addr_t limit); >> bool memblock_is_memory(phys_addr_t addr); >> bool memblock_is_map_memory(phys_addr_t addr); >> diff --git a/mm/memblock.c b/mm/memblock.c >> index 28fa8926..1a7f4ee7c 100644 >> --- a/mm/memblock.c >> +++ b/mm/memblock.c >> @@ -1697,6 +1697,46 @@ void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size) >> base + size, PHYS_ADDR_MAX); >> } >> >> +void __init memblock_cap_memory_ranges(struct memblock_region *regs, int cnt) >> +{ >> + int start_rgn[INIT_MEMBLOCK_REGIONS], end_rgn[INIT_MEMBLOCK_REGIONS]; >> + int i, j, ret, nr = 0; >> + >> + for (i = 0; i < cnt; i++) { >> + ret = memblock_isolate_range(&memblock.memory, regs[i].base, >> + regs[i].size, &start_rgn[i], &end_rgn[i]); >> + if (ret) >> + break; >> + nr++; >> + } >> + if (!nr) >> + return; >> + >> + /* remove all the MAP regions */ >> + for (i = memblock.memory.cnt - 1; i >= end_rgn[nr - 1]; i--) >> + if (!memblock_is_nomap(&memblock.memory.regions[i])) >> + memblock_remove_region(&memblock.memory, i); >> + >> + for (i = nr - 1; i > 0; i--) >> + for (j = start_rgn[i] - 1; j >= end_rgn[i - 1]; j--) >> + if (!memblock_is_nomap(&memblock.memory.regions[j])) >> + memblock_remove_region(&memblock.memory, j); >> + >> + for (i = start_rgn[0] - 1; i >= 0; i--) >> + if (!memblock_is_nomap(&memblock.memory.regions[i])) >> + memblock_remove_region(&memblock.memory, i); >> + >> + /* truncate the reserved regions */ >> + memblock_remove_range(&memblock.reserved, 0, regs[0].base); >> + >> + for (i = nr - 1; i > 0; i--) >> + memblock_remove_range(&memblock.reserved, >> + regs[i].base, regs[i - 1].base + regs[i - 1].size); >> + >> + memblock_remove_range(&memblock.reserved, >> + regs[nr - 1].base + regs[nr - 1].size, PHYS_ADDR_MAX); >> +} >> + >> void __init memblock_mem_limit_remove_map(phys_addr_t limit) >> { >> phys_addr_t max_addr; >> -- >> 2.7.4 >> >