From patchwork Tue Feb 7 08:08:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 9559429 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DC91E60547 for ; Tue, 7 Feb 2017 08:29:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF38E20246 for ; Tue, 7 Feb 2017 08:29:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C343126E1A; Tue, 7 Feb 2017 08:29:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 72C9E20246 for ; Tue, 7 Feb 2017 08:29:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cb19t-0001XZ-W5; Tue, 07 Feb 2017 08:29:54 +0000 Received: from merlin.infradead.org ([205.233.59.134]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cb174-0007nK-20 for linux-arm-kernel@bombadil.infradead.org; Tue, 07 Feb 2017 08:26:58 +0000 Received: from mail-pg0-x22b.google.com ([2607:f8b0:400e:c05::22b]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cb0ra-0000Fm-CS for linux-arm-kernel@lists.infradead.org; Tue, 07 Feb 2017 08:10:59 +0000 Received: by mail-pg0-x22b.google.com with SMTP id 194so36721859pgd.2 for ; Tue, 07 Feb 2017 00:10:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=coBPH4xyZlkxg/fx2CGEktyfv6DyMPUv59+I3aK1fZE=; b=XLTloI6CeujGfkR1fOY5BG1j4OdP5NYIZe3v90otB6E/9IdSlADZUxe/nXzlY9xxTS mO/WCxmTbL8Z12qa78Xp00REN1TlK0kdBV+M8IpkA4D25u0KB40ESQ+jzReGx7a36NnS 0N7h41fNzPr9CpAEmvuLcTzDsxbeQ2QgRO80Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=coBPH4xyZlkxg/fx2CGEktyfv6DyMPUv59+I3aK1fZE=; b=GSYu96xa17niNV8hNpDguW+mzJjsOBSxxU36ANKv/iv6VvluJ+LNEqZi/hfusw6CLP EOgjTGDgkMfuxx9Z1q5tmOmkKMd8ehiM8yNphhSLjcxabEStZOcxvvXUTjCaeWOYP8G2 BYmB9RZst3gkDpXGb2g2JQIZ+8lnjogtVDNypgAu1I7LV+8fWPh4oOukqIwyYgS49T8h bYMZ4AFQbjI6v5YNxLl5lt219LXr6bj/ghUVyZ9j2x3SnuFGqGq65y3BhP7a9dQiVGqj UbikHqdlGvL0R4HOP/tpIgMbtGrweV6n72GgkbLrrHVjnl/xg772xxW/nEQ4xdgp0AV9 z/iA== X-Gm-Message-State: AIkVDXKBXT7BGpSqAgmN4x5HfuY2hn1FKycWwBJhIUrXokBydn5MIUh3PxOuIZ62YtYZ/q/1 X-Received: by 10.84.217.202 with SMTP id d10mr23987570plj.53.1486454857273; Tue, 07 Feb 2017 00:07:37 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x81sm8491520pff.69.2017.02.07.00.07.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Feb 2017 00:07:36 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com Subject: [PATCH v32 04/13] arm64: kdump: reserve memory for crash dump kernel Date: Tue, 7 Feb 2017 17:08:56 +0900 Message-Id: <20170207080904.5974-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170207080601.5816-1-takahiro.akashi@linaro.org> References: <20170207080601.5816-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170207_031058_544262_ADFD6258 X-CRM114-Status: GOOD ( 18.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, Pratyush Anand , geoff@infradead.org, kexec@lists.infradead.org, AKASHI Takahiro , james.morse@arm.com, Mark Salter , bauerman@linux.vnet.ibm.com, dyoung@redhat.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP "crashkernel=" kernel parameter specifies the size (and optionally the start address) of the system ram to be used by crash dump kernel. reserve_crashkernel() will allocate and reserve that memory at boot time of primary kernel. The memory range will be exposed to userspace as a resource named "Crash kernel" in /proc/iomem. Signed-off-by: AKASHI Takahiro Signed-off-by: Mark Salter Signed-off-by: Pratyush Anand Reviewed-by: James Morse Acked-by: Catalin Marinas --- arch/arm64/kernel/setup.c | 7 ++++- arch/arm64/mm/init.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index b051367e2149..515e9c6696df 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -224,6 +223,12 @@ static void __init request_standard_resources(void) if (kernel_data.start >= res->start && kernel_data.end <= res->end) request_resource(res, &kernel_data); +#ifdef CONFIG_KEXEC_CORE + /* Userspace will find "Crash kernel" region in /proc/iomem. */ + if (crashk_res.end && crashk_res.start >= res->start && + crashk_res.end <= res->end) + request_resource(res, &crashk_res); +#endif } } diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 3c41fd0bbce6..083e8fc9b771 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -30,12 +30,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include @@ -76,6 +78,67 @@ static int __init early_initrd(char *p) early_param("initrd", early_initrd); #endif +#ifdef CONFIG_KEXEC_CORE +/* + * reserve_crashkernel() - reserves memory for crash kernel + * + * This function reserves memory area given in "crashkernel=" kernel command + * line parameter. The memory reserved is used by dump capture kernel when + * primary kernel is crashing. + */ +static void __init reserve_crashkernel(void) +{ + unsigned long long crash_base, crash_size; + 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; + + 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_size, SZ_2M); + if (crash_base == 0) { + pr_warn("cannot allocate crashkernel (size:0x%llx)\n", + crash_size); + return; + } + } else { + /* User specifies base address explicitly. */ + if (!memblock_is_region_memory(crash_base, crash_size)) { + pr_warn("cannot reserve crashkernel: region is not memory\n"); + return; + } + + if (memblock_is_region_reserved(crash_base, crash_size)) { + pr_warn("cannot reserve crashkernel: region overlaps reserved memory\n"); + return; + } + + if (!IS_ALIGNED(crash_base, SZ_2M)) { + pr_warn("cannot reserve crashkernel: base address is not 2MB aligned\n"); + return; + } + } + memblock_reserve(crash_base, crash_size); + + pr_info("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n", + crash_base, crash_base + crash_size, crash_size >> 20); + + crashk_res.start = crash_base; + crashk_res.end = crash_base + crash_size - 1; +} +#else +static void __init reserve_crashkernel(void) +{ +} +#endif /* CONFIG_KEXEC_CORE */ + /* * Return the maximum physical address for ZONE_DMA (DMA_BIT_MASK(32)). It * currently assumes that for memory starting above 4G, 32-bit devices will @@ -331,6 +394,9 @@ void __init arm64_memblock_init(void) arm64_dma_phys_limit = max_zone_dma_phys(); else arm64_dma_phys_limit = PHYS_MASK + 1; + + reserve_crashkernel(); + dma_contiguous_reserve(arm64_dma_phys_limit); memblock_allow_resize();