From patchwork Wed Jul 11 07:41:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10519089 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 286526032A for ; Wed, 11 Jul 2018 07:58:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19550289FB for ; Wed, 11 Jul 2018 07:58:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CFF628A0C; Wed, 11 Jul 2018 07:58:59 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 82D11289FB for ; Wed, 11 Jul 2018 07:58:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=+aU+Faqvcw4GT9jOxpy0R+lLX5hilBkIlX1LfrftWRw=; b=G8KnXcC/0GS2SEVuqPLMxX5MHC gCq+ESldNhzgdq1lIcsv7VDeBZtBwO4AnnMqQ4SBBboVAlw6bc6NTSzTb6BqKddGS70ju58xdJdGl 5laf1XZbOiCL/mvyV+77+3QNVQjKVOKBmM1ctgerbiDL3rTBMjXxN/cf09iXd3NEw4CmiDHBsUgEs BqMrHOZMngE4c/VzQ8jggKmM3OGNkTUNJmDUIvRV+uwLhboyNXTRx+V8HxjNoAyQKVcg/2ZJeqboj dCLTIfUW7lsI1stTHVNe/J1uo+rVJfV6WyAQ/knWJJ9cfU/u2JJRNFjur3JLiq+rAHavDX1pJtp89 hu1q8FIg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fdA1V-0007LW-Vi; Wed, 11 Jul 2018 07:58:54 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fdA1B-0006ne-4L for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Jul 2018 07:58:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=RcxmasK1UQ66nFR2YeB7D8hx/WTFRWwRJKg54HGY9qY=; b=DUIc/SDwyGTAlIYFspx+64z7S BnP6ggwGtcktgX8cKy+iaodyz5XZqW0hh7fu1jjk9N3gbhO6aGcBeSq31B7brbNooyb9A2L+u8s/s iCN3h84cLXuofWUserdMVUOQJeHFkxCzozdrVA9ris3ah2DRrOPSd8MHdLkBlLO0sWlxh6Dj91lfb iHGUkOx29NR11PdZbE7SItySCV0cRC3fiiaSymh9WEhoHUyEcOsy49vFnM2lA++h3nyhSt76wOZq4 T/aG6kGPXwI3a8BLN2ey1Vh/ma52AXmJCUNjU11bjm9t6PPSwb6gA4sslcTlz7M/mEjXefjNbPzsZ SjR1VoCDQ==; Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fd9mJ-0005EQ-Mh for linux-arm-kernel@lists.infradead.org; Wed, 11 Jul 2018 07:43:13 +0000 Received: by mail-pl0-x243.google.com with SMTP id c41-v6so8806585plj.10 for ; Wed, 11 Jul 2018 00:43:01 -0700 (PDT) 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=RcxmasK1UQ66nFR2YeB7D8hx/WTFRWwRJKg54HGY9qY=; b=h/yQmTYX0hKuqb7yAMhcjmC685olIDo+jYSGu2Rta0sGpycgxWKC4dlu1vczw+OQQL DxYLu12M2sYvV9rzraX3JfSk23wG3jNrkiZni4Jean93pJtuJMu0l+nAOOaaGTpC7/Kc 2Wfj5uCYAr6nONpAveqBMlDdHgrjNOMkHiBSA= 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=RcxmasK1UQ66nFR2YeB7D8hx/WTFRWwRJKg54HGY9qY=; b=haA8OdiRjttWAeedji7YDnEUbFz+5lBVlmUHgX1GUmLnl/ULt2brxIrjGKztzZrbZi R7RBvBmGheoIHlo2NUptTfal3CgmH/IC2bvUxjk8EMvC/ydUiWXzkElCRI47fgI6nAtJ E/Ef0KgWBHOb5UI6S8nmABHCj1ADjgHnO6+x72fw/0A1sClfyj2JH1JPaHK5vMhNSHEc 9bTtf8K/mryKe/0wN/+Kq+b2slF/syhRpUjrw2LXUcY+77FObdE3BeFzsT1AzA91D/E8 0tb12GxMfl66r0lM9f2qdhfb3+NXXNi3e9vEQw+dM2bnvnb3oSfFiRKn1+bWs5rO/MVT alIw== X-Gm-Message-State: APt69E1ZEXUX80H70AfCyH+3abty5fJON0JOBnFImaMGytOOl9Yg0usX f+Vi3faEBytXUVQhJQoT1lRu3Q== X-Google-Smtp-Source: AAOMgpf/baB6M8L/bvz+1hXtCdGmwyA2CsdPBMSJ4fVYGwqHLxTW7AvM/8zEkcwNOp910W7wosU6TA== X-Received: by 2002:a17:902:5381:: with SMTP id c1-v6mr27418061pli.137.1531294980239; Wed, 11 Jul 2018 00:43:00 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v66-v6sm35520715pfb.84.2018.07.11.00.42.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:42:59 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Subject: [PATCH v11 11/15] arm64: kexec_file: add crash dump support Date: Wed, 11 Jul 2018 16:41:59 +0900 Message-Id: <20180711074203.3019-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180711_084311_763390_B683FA28 X-CRM114-Status: GOOD ( 23.25 ) 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: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , james.morse@arm.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 Enabling crash dump (kdump) includes * prepare contents of ELF header of a core dump file, /proc/vmcore, using crash_prepare_elf64_headers(), and * add two device tree properties, "linux,usable-memory-range" and "linux,elfcorehdr", which represent respectively a memory range to be used by crash dump kernel and the header's location Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/kexec.h | 4 + arch/arm64/kernel/kexec_image.c | 9 +- arch/arm64/kernel/machine_kexec_file.c | 114 ++++++++++++++++++++++++- 3 files changed, 124 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 69333694e3e2..eeb5766928b0 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -99,6 +99,10 @@ static inline void crash_post_resume(void) {} struct kimage_arch { phys_addr_t dtb_mem; void *dtb_buf; + /* Core ELF header buffer */ + void *elf_headers; + unsigned long elf_headers_sz; + unsigned long elf_load_addr; }; /** diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index a47cf9bc699e..df1e341d3a28 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -67,8 +67,13 @@ static void *image_load(struct kimage *image, /* Load the kernel */ kbuf.image = image; - kbuf.buf_min = 0; - kbuf.buf_max = ULONG_MAX; + if (image->type == KEXEC_TYPE_CRASH) { + kbuf.buf_min = crashk_res.start; + kbuf.buf_max = crashk_res.end + 1; + } else { + kbuf.buf_min = 0; + kbuf.buf_max = ULONG_MAX; + } kbuf.top_down = false; kbuf.buffer = kernel; diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index a0b44fe18b95..261564df7210 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,7 +16,9 @@ #include #include #include +#include #include +#include #include const struct kexec_file_ops * const kexec_file_loaders[] = { @@ -29,6 +31,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) vfree(image->arch.dtb_buf); image->arch.dtb_buf = NULL; + vfree(image->arch.elf_headers); + image->arch.elf_headers = NULL; + image->arch.elf_headers_sz = 0; + return kexec_image_post_load_cleanup_default(image); } @@ -38,13 +44,31 @@ static int setup_dtb(struct kimage *image, char **dtb_buf, size_t *dtb_buf_len) { char *buf = NULL; - size_t buf_size; + size_t buf_size, range_size; int nodeoffset; u64 value; int ret; + /* check ranges against root's #address-cells and #size-cells */ + if (image->type == KEXEC_TYPE_CRASH && + (!of_fdt_cells_size_fitted(image->arch.elf_load_addr, + image->arch.elf_headers_sz) || + !of_fdt_cells_size_fitted(crashk_res.start, + crashk_res.end - crashk_res.start + 1))) { + pr_err("Crash memory region doesn't fit into DT's root cell sizes.\n"); + ret = -EINVAL; + goto out_err; + } + /* duplicate dt blob */ buf_size = fdt_totalsize(initial_boot_params); + range_size = of_fdt_reg_cells_size(); + + if (image->type == KEXEC_TYPE_CRASH) { + buf_size += fdt_prop_len("linux,elfcorehdr", range_size); + buf_size += fdt_prop_len("linux,usable-memory-range", + range_size); + } if (initrd_load_addr) { /* can be redundant, but trimmed at the end */ @@ -74,6 +98,23 @@ static int setup_dtb(struct kimage *image, goto out_err; } + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_setprop_reg(buf, nodeoffset, "linux,elfcorehdr", + image->arch.elf_load_addr, + image->arch.elf_headers_sz); + if (ret) + goto out_err; + + /* add linux,usable-memory-range */ + ret = fdt_setprop_reg(buf, nodeoffset, + "linux,usable-memory-range", + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + goto out_err; + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop_string(buf, nodeoffset, "bootargs", cmdline); @@ -132,6 +173,45 @@ static int setup_dtb(struct kimage *image, return ret; } +static int prepare_elf_headers(void **addr, unsigned long *sz) +{ + struct crash_mem *cmem; + unsigned int nr_ranges; + int ret; + u64 i; + phys_addr_t start, end; + + nr_ranges = 1; /* for exclusion of crashkernel region */ + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, 0, + &start, &end, NULL) + nr_ranges++; + + cmem = kmalloc(sizeof(struct crash_mem) + + sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL); + if (!cmem) + return -ENOMEM; + + cmem->max_nr_ranges = nr_ranges; + cmem->nr_ranges = 0; + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, 0, + &start, &end, NULL) { + cmem->ranges[cmem->nr_ranges].start = start; + cmem->ranges[cmem->nr_ranges].end = end - 1; + cmem->nr_ranges++; + } + + /* Exclude crashkernel region */ + ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + if (ret) + goto out; + + ret = crash_prepare_elf64_headers(cmem, true, addr, sz); + +out: + kfree(cmem); + return ret; +} + int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, unsigned long kernel_size, @@ -139,11 +219,43 @@ int load_other_segments(struct kimage *image, char *cmdline, unsigned long cmdline_len) { struct kexec_buf kbuf; + void *hdrs_addr; + unsigned long hdrs_sz; unsigned long initrd_load_addr = 0; char *dtb = NULL; unsigned long dtb_len = 0; int ret = 0; + /* load elf core header */ + if (image->type == KEXEC_TYPE_CRASH) { + ret = prepare_elf_headers(&hdrs_addr, &hdrs_sz); + if (ret) { + pr_err("Preparing elf core header failed\n"); + goto out_err; + } + + kbuf.image = image; + kbuf.buffer = hdrs_addr; + kbuf.bufsz = hdrs_sz; + kbuf.memsz = hdrs_sz; + kbuf.buf_align = PAGE_SIZE; + kbuf.buf_min = crashk_res.start; + kbuf.buf_max = crashk_res.end + 1; + kbuf.top_down = true; + + ret = kexec_add_buffer(&kbuf); + if (ret) { + vfree(hdrs_addr); + goto out_err; + } + image->arch.elf_headers = hdrs_addr; + image->arch.elf_headers_sz = hdrs_sz; + image->arch.elf_load_addr = kbuf.mem; + + pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + image->arch.elf_load_addr, hdrs_sz, hdrs_sz); + } + kbuf.image = image; /* not allocate anything below the kernel */ kbuf.buf_min = kernel_load_addr + kernel_size;