Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2402239pxb; Sat, 30 Jan 2021 01:15:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJybV7PlDxnghimJos929WYzbsdJc63B5/CuFxgtUC3vffdhrno/lA0nyGS1bi14AOUUniT6 X-Received: by 2002:a17:906:4893:: with SMTP id v19mr8228016ejq.454.1611998115404; Sat, 30 Jan 2021 01:15:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611998115; cv=none; d=google.com; s=arc-20160816; b=OBsM2Tr4ctTXPlD6dhq/U2aiAdidYdNnfuCAQL+8Z8KvnmhYIMo1WzFbeu9YnaEgZq nyMpza3R0HYmsA1MOzw4vVpGU47Jqdu4FzdtDSrq2I62tHkTktmGxa/Uo8FR1e2bgvSK e+EqzzjHM2fbSWGnjUQvx5bx6TXIAMqkrYbA7smNoVDeWyMjvP+HrcTl7TZFVw6mGjyF epglwvQTaWyLpqBDl93hcuMjJ/YWzCgNk5GKBsqHkNaoub7Jrob1brLPb9aCMLxdf8mo HR7+XasE/D9lJw2DOoVD7c4ZUVl+K3V3p6Dr0mDLByKa0CYi8nm01f1pawSkm6wsf7UM b59w== 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=N2jIAjS+J/xiuUC7ftWU6FUrPzyvIFUrLAfd1jpCJJc=; b=m+g3pAj5k7rLvFr/RMdka1m4mjW7X3gEHR1VvVmcTt4lOG8DL5/9Y4/GDQOlVPqjLw xwF79kDlqzs++vYBevWyuT2FhF5S0MLoP/JyJXpqFKblIL7IBOc+FTz2VjkxW7rA17Xp wsU799/OPyTkVY5Uynd3xmDfl2SBCTjMHeouKvJ7bb5AqaWMefQpQks4T/CF8LO5RMzY FeouZhnc6bEbRXUK82patDe15KlF5HVij3sWF8Y/gpsUuYKRsBxVnox27nu4oS9CCO9S IkNETN9gJfqt946BmviaFbLNUG3Ht2QRIb+xlbLiA1ey1d7633pekC677yTSqaLvuidh kWQg== 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 i7si6874353edg.300.2021.01.30.01.14.35; Sat, 30 Jan 2021 01:15:15 -0800 (PST) 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 S232625AbhA3JNv (ORCPT + 99 others); Sat, 30 Jan 2021 04:13:51 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:11989 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231912AbhA3JND (ORCPT ); Sat, 30 Jan 2021 04:13:03 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DSQFX3nx7zjGPw; Sat, 30 Jan 2021 15:05:04 +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.498.0; Sat, 30 Jan 2021 15:06:11 +0800 From: Chen Zhou To: , , , , , , , , , , , CC: , , , , , , , , , , , , , John Donnelly Subject: [PATCH v14 10/11] arm64: kdump: add memory for devices by DT property linux,usable-memory-range Date: Sat, 30 Jan 2021 15:10:24 +0800 Message-ID: <20210130071025.65258-11-chenzhou10@huawei.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210130071025.65258-1-chenzhou10@huawei.com> References: <20210130071025.65258-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 d20f5c444ebf..180a25b67f55 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -68,6 +68,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) @@ -201,9 +210,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; @@ -212,22 +221,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