Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1923503yba; Tue, 2 Apr 2019 19:55:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxmlIQ0RKYzRZ0er/ZZ4PO69Y4aH2YpSvFSgfIx+kzYkX2WJ+1sm67qDw+AG5SSVLsARXsF X-Received: by 2002:aa7:80c8:: with SMTP id a8mr73588843pfn.193.1554260152834; Tue, 02 Apr 2019 19:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554260152; cv=none; d=google.com; s=arc-20160816; b=ovcHjjaZDOSkmFrSk6GpDyDrpRsh/nfQF/5NYju1j/iqBgQuuN9nMtykwAXeLaHpuR oDtlCXSfa9c2nts/svRpriCk+9aSCgqorgOHPt2bvMA2Q/L5Q+NYdNQca2s+M6Q/UBA2 Se5NfwpXRVOEFVX481scv0oe/BiMyP4zginU9pqfE4d8Bmc7bo0I/CM+uBtU03xU0/Fj fSgqDoBxC+hSm7KRbicFkcRA+DWIpTWAEFGek5avMK0nD63TuyU0c9+O1kou4Nrn6ufn 3pGUrsD3Ph0KdXB+cw+bJdg+GfF/wZR6xaedpVFUGIJxiyiNP6aFatX8IkN+gbh08W2I 8Xbg== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9vsSbmVCazVXk2p16cdSj8FEZujNbQEaLSgHoumtHQQ=; b=bXDMh65HvnbBuCC/10O15CnpyC3zWcxekAbiS9RyyScFTvQ9572g3dy6wiZ1Rwt67c Lr2KGfijXIzUu6v3akSp7SYytklt186bt3ygIS3+J4nw6CtGGcFVbZpg0X+73CXF85Du 6isE083THY/NhmstjVQt3vWBlfVaqhKm/JYsmnrBcdfHaop6gDjhgDm4SIQNGprt6UOl 7QjiojhpAifiF8NqDWMGN699F95v8tr6qNrSA+oeW8mPrEoofjvejzOPv+fMcI/fBNiy u7g8UwpHNuout4eo9RJL9ayiYnm0EzXtoMyZtDU2HWTZMGemBxFNM1KA6iCRAf1fijgs zG8Q== 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 q9si11766289pll.41.2019.04.02.19.55.37; Tue, 02 Apr 2019 19:55:52 -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 S1726920AbfDCCyo (ORCPT + 99 others); Tue, 2 Apr 2019 22:54:44 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5654 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726425AbfDCCyo (ORCPT ); Tue, 2 Apr 2019 22:54:44 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [10.3.19.208]) by Forcepoint Email with ESMTP id 0B3E5907F4EA0FB37403; Wed, 3 Apr 2019 10:54:42 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.408.0; Wed, 3 Apr 2019 10:54:32 +0800 From: Chen Zhou To: , , , , , CC: , , , , , Chen Zhou Subject: [PATCH 1/3] arm64: kdump: support reserving crashkernel above 4G Date: Wed, 3 Apr 2019 11:05:44 +0800 Message-ID: <20190403030546.23718-2-chenzhou10@huawei.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403030546.23718-1-chenzhou10@huawei.com> References: <20190403030546.23718-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] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When crashkernel is reserved above 4G in memory, kernel should reserve some amount of low memory for swiotlb and some DMA buffers. Kernel would try to allocate at least 256M below 4G automatically as x86_64 if crashkernel is above 4G. Meanwhile, support crashkernel=X,[high,low] in arm64. Signed-off-by: Chen Zhou --- arch/arm64/kernel/setup.c | 3 ++ arch/arm64/mm/init.c | 71 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 413d566..82cd9a0 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -243,6 +243,9 @@ static void __init request_standard_resources(void) request_resource(res, &kernel_data); #ifdef CONFIG_KEXEC_CORE /* Userspace will find "Crash kernel" region in /proc/iomem. */ + if (crashk_low_res.end && crashk_low_res.start >= res->start && + crashk_low_res.end <= res->end) + request_resource(res, &crashk_low_res); if (crashk_res.end && crashk_res.start >= res->start && crashk_res.end <= res->end) request_resource(res, &crashk_res); diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 6bc1350..ceb2a25 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -64,6 +64,57 @@ EXPORT_SYMBOL(memstart_addr); phys_addr_t arm64_dma_phys_limit __ro_after_init; #ifdef CONFIG_KEXEC_CORE +static int __init reserve_crashkernel_low(void) +{ + unsigned long long base, low_base = 0, low_size = 0; + unsigned long total_low_mem; + int ret; + + total_low_mem = memblock_mem_size(1UL << (32 - PAGE_SHIFT)); + + /* crashkernel=Y,low */ + ret = parse_crashkernel_low(boot_command_line, total_low_mem, &low_size, &base); + if (ret) { + /* + * two parts from lib/swiotlb.c: + * -swiotlb size: user-specified with swiotlb= or default. + * + * -swiotlb overflow buffer: now hardcoded to 32k. We round it + * to 8M for other buffers that may need to stay low too. Also + * make sure we allocate enough extra low memory so that we + * don't run out of DMA buffers for 32-bit devices. + */ + low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); + } else { + /* passed with crashkernel=0,low ? */ + if (!low_size) + return 0; + } + + low_base = memblock_find_in_range(0, 1ULL << 32, low_size, SZ_2M); + if (!low_base) { + pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", + (unsigned long)(low_size >> 20)); + return -ENOMEM; + } + + ret = memblock_reserve(low_base, low_size); + if (ret) { + pr_err("%s: Error reserving crashkernel low memblock.\n", __func__); + return ret; + } + + pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (System RAM: %ldMB)\n", + (unsigned long)(low_size >> 20), + (unsigned long)(low_base >> 20), + (unsigned long)(total_low_mem >> 20)); + + crashk_low_res.start = low_base; + crashk_low_res.end = low_base + low_size - 1; + + return 0; +} + /* * reserve_crashkernel() - reserves memory for crash kernel * @@ -74,19 +125,28 @@ phys_addr_t arm64_dma_phys_limit __ro_after_init; static void __init reserve_crashkernel(void) { unsigned long long crash_base, crash_size; + bool high = false; int ret; ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), &crash_size, &crash_base); /* no crashkernel= or invalid value specified */ - if (ret || !crash_size) - return; + if (ret || !crash_size) { + /* crashkernel=X,high */ + ret = parse_crashkernel_high(boot_command_line, memblock_phys_mem_size(), + &crash_size, &crash_base); + if (ret || !crash_size) + return; + high = true; + } crash_size = PAGE_ALIGN(crash_size); if (crash_base == 0) { /* Current arm64 boot protocol requires 2MB alignment */ - crash_base = memblock_find_in_range(0, ARCH_LOW_ADDRESS_LIMIT, + crash_base = memblock_find_in_range(0, + high ? memblock_end_of_DRAM() + : ARCH_LOW_ADDRESS_LIMIT, crash_size, SZ_2M); if (crash_base == 0) { pr_warn("cannot allocate crashkernel (size:0x%llx)\n", @@ -112,6 +172,11 @@ static void __init reserve_crashkernel(void) } memblock_reserve(crash_base, crash_size); + if (crash_base >= SZ_4G && reserve_crashkernel_low()) { + memblock_free(crash_base, crash_size); + return; + } + pr_info("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n", crash_base, crash_base + crash_size, crash_size >> 20); -- 2.7.4