Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1871945pxx; Sat, 31 Oct 2020 00:41:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYTEz9wrrPjm2ICD3uYZi2ixj1DDWpieYT+IQuROX/RpBzX4HMcSfbyTQB98ecerBkVgvx X-Received: by 2002:a50:d88c:: with SMTP id p12mr6200224edj.352.1604130071367; Sat, 31 Oct 2020 00:41:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604130071; cv=none; d=google.com; s=arc-20160816; b=lKll8D/DtGVqb/4h8pSj7bXb8jxSt37Ek2JWjiZJh/yUSiA4hptkXECX01vv/er9Tf IZCo/pKoVgS06GY9Zje3dDKdCq5KK7W7a9a1Gfra7KBIgFtAsxHV2ZOtCMjxf7GT08bz FtopDt3bJB2niieVFieb13k1nLClp3pPq8Sx0A7yydiIDkEBldCdzS2XydiIMMvlmZ8T 2mTrWxxjeof+RpBqL9sE2Rmp6uYel5xrHzlnu0w7iO4z+pkZvsN15VHqumTgJ2ubQRoR KaYJYWkYj7RrKxmB0PxxRRYL68q821CVSTpXVaPWFd3j/rmv3/T2bOjZ+nlCY9jHl2dF HFAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Ja9TJWWCnId6rKxIZ0Dja/dMDgAVzcQZqD6uX8khMH8=; b=dBygaKiFsTiyyv44T+NMKLpTZwOFFQn2jRApp12cAT+RimKhaMgzJg4ZD3aW5tPujF qE5enFNIp+If0X3FEFpEeW8A0Lfm262Q+yeOvZHFCDdeG+jOG+M/IBbwbxPUWRB80HwN am1WJcWua8k+ilOJZGh66vA7/3gHfqCCrbPZ87SIm8jsRCIZB1Tn22WGRZwV0MwUOpYt 02hleAFt/5W/nnUfazZBYsdKpOtzfd0A51S9Cg3XxUCx/TggUlyC8IRltQiKtZhPiaEY UZxy5CKnBTHvIsUEFNZAqeXDm+krVQ+8arB4AAO/3/4F1y64Kw3LpNWI8EOhEW/44hM2 vJ/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i25si6406681edr.515.2020.10.31.00.40.49; Sat, 31 Oct 2020 00:41:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726436AbgJaHjT (ORCPT + 99 others); Sat, 31 Oct 2020 03:39:19 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6683 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726420AbgJaHjR (ORCPT ); Sat, 31 Oct 2020 03:39:17 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CNWJz45YZz15PLx; Sat, 31 Oct 2020 15:39:15 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Sat, 31 Oct 2020 15:39:06 +0800 From: Chen Zhou To: , , , , , , , , , CC: , , , , , , , , , , , , , , John Donnelly Subject: [PATCH v13 7/8] arm64: kdump: add memory for devices by DT property linux,usable-memory-range Date: Sat, 31 Oct 2020 15:44:36 +0800 Message-ID: <20201031074437.168008-8-chenzhou10@huawei.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201031074437.168008-1-chenzhou10@huawei.com> References: <20201031074437.168008-1-chenzhou10@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When reserving crashkernel in high memory, some low memory is reserved for crash dump kernel devices and never mapped by the first kernel. This memory range is advertised to crash dump kernel via DT property under /chosen, linux,usable-memory-range = We reused the DT property linux,usable-memory-range and made the low memory region as the second range "BASE2 SIZE2", which keeps compatibility with existing user-space and older kdump kernels. Crash dump kernel reads this property at boot time and call memblock_add() to add the low memory region after memblock_cap_memory_range() has been called. Signed-off-by: Chen Zhou Tested-by: John Donnelly --- arch/arm64/mm/init.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 888c4f7eadc3..794f992cb200 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -69,6 +69,15 @@ static void __init reserve_crashkernel(void) } #endif +/* + * The main usage of linux,usable-memory-range is for crash dump kernel. + * Originally, the number of usable-memory regions is one. Now there may + * be two regions, low region and high region. + * To make compatibility with existing user-space and older kdump, the low + * region is always the last range of linux,usable-memory-range if exist. + */ +#define MAX_USABLE_RANGES 2 + #ifdef CONFIG_CRASH_DUMP static int __init early_init_dt_scan_elfcorehdr(unsigned long node, const char *uname, int depth, void *data) @@ -184,9 +193,9 @@ early_param("mem", early_mem); 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; + struct memblock_region *usable_rgns = data; + const __be32 *reg, *endp; + int len, nr = 0; if (depth != 1 || strcmp(uname, "chosen") != 0) return 0; @@ -195,22 +204,36 @@ 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)) { + usable_rgns[nr].base = dt_mem_next_cell(dt_root_addr_cells, ®); + usable_rgns[nr].size = dt_mem_next_cell(dt_root_size_cells, ®); + + if (++nr >= MAX_USABLE_RANGES) + break; + } return 1; } static void __init fdt_enforce_memory_region(void) { - struct memblock_region reg = { - .size = 0, + struct memblock_region usable_rgns[MAX_USABLE_RANGES] = { + { .size = 0 }, + { .size = 0 } }; - of_scan_flat_dt(early_init_dt_scan_usablemem, ®); + of_scan_flat_dt(early_init_dt_scan_usablemem, &usable_rgns); - if (reg.size) - memblock_cap_memory_range(reg.base, reg.size); + /* + * The first range of usable-memory regions is for crash dump + * kernel with only one region or for high region with two regions, + * the second range is dedicated for low region if exist. + */ + if (usable_rgns[0].size) + memblock_cap_memory_range(usable_rgns[0].base, usable_rgns[0].size); + if (usable_rgns[1].size) + memblock_add(usable_rgns[1].base, usable_rgns[1].size); } void __init arm64_memblock_init(void) -- 2.20.1