From patchwork Thu Mar 26 08:28:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 46349 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 26D5321584 for ; Thu, 26 Mar 2015 08:29:52 +0000 (UTC) Received: by labcd2 with SMTP id cd2sf3903224lab.3 for ; Thu, 26 Mar 2015 01:29:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=YEKlEk6Q9U4X14QkSumiUtMyMwiZcDgsyaPxK9L9VPw=; b=EyaXY8I3byEutPbcMZEj2S6S46wz9FxSVXl0SvvtR/t/WvMbY85DuRc55P1wRWq7te 9//zDVHhgqsB5+kG3K5ZqaxTE56Sseh5j7tVAyFF2kCxQsycjxo8Mect49uClvjbnaP4 pWURmRhegMyhNjWtMepuHWvODOuL+jkH+xr5h13FEb2JwWHLrB67OZHIf9dWc3kf1oQZ k7XqY2lX2yxe0OWw9LcuJZaAcwa28nXk7hESFz66e5fUoBy8E7oF5peccaHkK5yNvq0r vBGpKgGDBX1DjOBhIHImmu6Ns24+5VmqMTZe9qEF3sYYkj3bVy2PwwwekuJhKQVECwTN 5jOA== X-Gm-Message-State: ALoCoQnuBp618Lg/LvcvfJpsof6a8mV2XOq53PdwMtZDOBozl6vBJVIB7KVD9K7Fen2PLwbpIKj3 X-Received: by 10.152.27.134 with SMTP id t6mr3044610lag.5.1427358591104; Thu, 26 Mar 2015 01:29:51 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.178 with SMTP id p18ls174873lal.68.gmail; Thu, 26 Mar 2015 01:29:50 -0700 (PDT) X-Received: by 10.112.183.134 with SMTP id em6mr12098953lbc.52.1427358590934; Thu, 26 Mar 2015 01:29:50 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id q11si3994959lbl.110.2015.03.26.01.29.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Mar 2015 01:29:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by labe2 with SMTP id e2so39483577lab.3 for ; Thu, 26 Mar 2015 01:29:50 -0700 (PDT) X-Received: by 10.112.8.101 with SMTP id q5mr12271251lba.19.1427358590816; Thu, 26 Mar 2015 01:29:50 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.57.201 with SMTP id k9csp456483lbq; Thu, 26 Mar 2015 01:29:49 -0700 (PDT) X-Received: by 10.70.48.37 with SMTP id i5mr24443860pdn.111.1427358587302; Thu, 26 Mar 2015 01:29:47 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ss1si7296256pbc.187.2015.03.26.01.29.45; Thu, 26 Mar 2015 01:29:47 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752477AbbCZI3k (ORCPT + 27 others); Thu, 26 Mar 2015 04:29:40 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:33964 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751869AbbCZI3g (ORCPT ); Thu, 26 Mar 2015 04:29:36 -0400 Received: by pacwe9 with SMTP id we9so56369830pac.1 for ; Thu, 26 Mar 2015 01:29:35 -0700 (PDT) X-Received: by 10.66.248.40 with SMTP id yj8mr24433545pac.141.1427358575767; Thu, 26 Mar 2015 01:29:35 -0700 (PDT) Received: from localhost.localdomain (61-205-2-129m5.grp1.mineo.jp. [61.205.2.129]) by mx.google.com with ESMTPSA id sf6sm4716526pbb.82.2015.03.26.01.29.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Mar 2015 01:29:34 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, vgoyal@redhat.com, hbabus@us.ibm.com Cc: geoff@infradead.org, broonie@kernel.org, david.griego@linaro.org, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH 1/5] arm64: kdump: reserve memory for crash dump kernel Date: Thu, 26 Mar 2015 17:28:49 +0900 Message-Id: <1427358533-3754-2-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1427358533-3754-1-git-send-email-takahiro.akashi@linaro.org> References: <1427358533-3754-1-git-send-email-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: takahiro.akashi@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On system kernel, the memory region used by crash dump kernel must be specified by "crashkernel=X@Y" boot parameter. reserve_crashkernel() will allocate the region in "System RAM" and reserve it for later use. On crash dump kernel, memory region information in system kernel is described in a specific region specified by "elfcorehdr=X@Y" boot parameter. reserve_elfcorehdr() will set aside the region to avoid data destruction by the kernel. Crash dump kernel will access memory regions in system kernel via copy_oldmem_page(), which reads a page with ioremap'ing it assuming that such pages are not part of main memory of crash dump kernel. This is true under non-UEFI environment because kexec-tools modifies a device tree adding "usablemem" attributes to memory sections. Under UEFI, however, this is not true because UEFI remove memory sections in a device tree and export all the memory regions, even though they belong to system kernel. So we should add "mem=X[MG]" boot parameter to limit the meory size and avoid hitting the following assertion in ioremap(): if (WARN_ON(pfn_valid(__phys_to_pfn(phys_addr)))) return NULL; Signed-off-by: AKASHI Takahiro --- arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/crash_dump.c | 71 ++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/setup.c | 78 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 arch/arm64/kernel/crash_dump.c diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index da9a7ee..3c24d4e 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -36,6 +36,7 @@ arm64-obj-$(CONFIG_EFI) += efi.o efi-stub.o efi-entry.o arm64-obj-$(CONFIG_PCI) += pci.o arm64-obj-$(CONFIG_ARMV8_DEPRECATED) += armv8_deprecated.o arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o +arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o obj-y += $(arm64-obj-y) vdso/ obj-m += $(arm64-obj-m) diff --git a/arch/arm64/kernel/crash_dump.c b/arch/arm64/kernel/crash_dump.c new file mode 100644 index 0000000..dd31b2e --- /dev/null +++ b/arch/arm64/kernel/crash_dump.c @@ -0,0 +1,71 @@ +/* + * arch/arm64/kernel/crash_dump.c + * + * Copyright (C) 2014 Linaro Limited + * Author: AKASHI Takahiro + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include + +/** + * copy_oldmem_page() - copy one page from old kernel memory + * @pfn: page frame number to be copied + * @buf: buffer where the copied page is placed + * @csize: number of bytes to copy + * @offset: offset in bytes into the page + * @userbuf: if set, @buf is int he user address space + * + * This function copies one page from old kernel memory into buffer pointed by + * @buf. If @buf is in userspace, set @userbuf to %1. Returns number of bytes + * copied or negative error in case of failure. + */ +ssize_t copy_oldmem_page(unsigned long pfn, char *buf, + size_t csize, unsigned long offset, + int userbuf) +{ + void *vaddr; + + if (!csize) + return 0; + + vaddr = ioremap(pfn << PAGE_SHIFT, PAGE_SIZE); + if (!vaddr) + return -ENOMEM; + + if (userbuf) { + if (copy_to_user(buf, vaddr + offset, csize)) { + iounmap(vaddr); + return -EFAULT; + } + } else { + memcpy(buf, vaddr + offset, csize); + } + + iounmap(vaddr); + + return csize; +} + +/** + * elfcorehdr_read - read from ELF core header + * @buf: buffer where the data is placed + * @csize: number of bytes to read + * @ppos: address in the memory + * + * This function reads @count bytes from elf core header which exists + * on crash dump kernel's memory. + */ +ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos) +{ + memcpy(buf, phys_to_virt((phys_addr_t)*ppos), count); + return count; +} diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index e8420f6..daaed93 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -323,6 +323,69 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys) dump_stack_set_arch_desc("%s (DT)", of_flat_dt_get_machine_name()); } +#ifdef CONFIG_KEXEC +/* + * 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 a dump capture kernel when + * primary kernel is crashing. + */ +static void __init reserve_crashkernel(void) +{ + unsigned long long crash_size, crash_base; + int ret; + + /* use ULONG_MAX since we don't know system memory size here. */ + ret = parse_crashkernel(boot_command_line, ULONG_MAX, + &crash_size, &crash_base); + if (ret) + return; + + ret = memblock_reserve(crash_base, crash_size); + if (ret < 0) { + pr_warn("crashkernel reservation failed - memory is in use (0x%lx)\n", + (unsigned long)crash_base); + return; + } + + pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n", + (unsigned long)(crash_size >> 20), + (unsigned long)(crash_base >> 20)); + + crashk_res.start = crash_base; + crashk_res.end = crash_base + crash_size - 1; +} +#endif /* CONFIG_KEXEC */ + +#ifdef CONFIG_CRASH_DUMP +/* + * reserve_elfcorehdr() - reserves memory for elf core header + * + * This function reserves memory area given in "elfcorehdr=" kernel command + * line parameter. The memory reserved is used by a dump capture kernel to + * identify the memory used by primary kernel. + */ +static void __init reserve_elfcorehdr(void) +{ + int ret; + + if (!elfcorehdr_size) + return; + + ret = memblock_reserve(elfcorehdr_addr, elfcorehdr_size); + if (ret < 0) { + pr_warn("elfcorehdr reservation failed - memory is in use (0x%lx)\n", + (unsigned long)elfcorehdr_addr); + return; + } + + pr_info("Reserving %ldKB of memory at %ldMB for elfcorehdr\n", + (unsigned long)(elfcorehdr_size >> 10), + (unsigned long)(elfcorehdr_addr >> 20)); +} +#endif /* CONFIG_CRASH_DUMP */ + static void __init request_standard_resources(void) { struct memblock_region *region; @@ -378,10 +441,25 @@ void __init setup_arch(char **cmdline_p) local_async_enable(); efi_init(); + /* + * reserve_crashkernel() and reserver_elfcorehdr() must be called + * before arm64_bootmem_init() because dma_contiguous_reserve() + * may conflict with those regions. + */ +#ifdef CONFIG_KEXEC + reserve_crashkernel(); +#endif +#ifdef CONFIG_CRASH_DUMP + reserve_elfcorehdr(); +#endif arm64_memblock_init(); paging_init(); request_standard_resources(); +#ifdef CONFIG_KEXEC + /* kexec-tool will detect the region with /proc/iomem */ + insert_resource(&iomem_resource, &crashk_res); +#endif early_ioremap_reset();