From patchwork Tue Jul 24 06:57:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541359 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE874184F for ; Tue, 24 Jul 2018 06:59:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB25A2873D for ; Tue, 24 Jul 2018 06:59:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E8DA28740; Tue, 24 Jul 2018 06:59:50 +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=ham 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 17EFC2873D for ; Tue, 24 Jul 2018 06:59:50 +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=n4Xs3Nh5FgUeucwOaJPq9nTXn5DPt7v9vAHqpOgapfw=; b=Jync8mWllk6GqWqlQwvR8gK2OU YrTm+hs+WmWKIk7QpWpnGSJgjmiQr5xPd2Ur9rEruP9dRXcDlnY3PV2s50LjOHTIxisTDHS/V6p9i qpmQQ8m/5fe/oywGbkupD6IUjDAhIj82sHWpBdXofMVsZBAyVwruNzaD1M73PbbZeZoj83fyiFO87 XAdpHkYmdjGExhEa2SZtmGuQMeEn2ISmwvuiGaK5PFQdiwTMPtJT3J+kfvgdAhF4Zq8O979ah3g4V CulIi3Pkup+Qhg95BpetXXYMnec2qhWT119PANad14GXugZqX/k5uwIuql+c8UKUouGS4kcrwVDH1 X6Aj/jdw==; 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 1fhrIQ-0003Ob-3V; Tue, 24 Jul 2018 06:59:46 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrHf-0002V2-J4 for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:59:11 +0000 Received: by mail-pf1-x443.google.com with SMTP id a26-v6so624206pfo.4 for ; Mon, 23 Jul 2018 23:58:49 -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=NrZw1260Snx5buwrLrr5fcvVbV6cTmqraLcLZQTZkLs=; b=Y+n40Cn0PUxEfrHIT/fGbjCmcUHa0Xn47ymffC+V87QKT+cNafSRa5tfjMDNQ2XTmU gA/8rCZYwmQc5ZETtw1o6TE3N59f1pjEOgIPXXNAN0FE3ykbdYs/aEOUcV8sYm1lLANC ATiFdhuXXARVZGjQwDm63+lpg0G1s6N5FFYks= 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=NrZw1260Snx5buwrLrr5fcvVbV6cTmqraLcLZQTZkLs=; b=QoTLE7UxjpfrlxWyaQr9INqxgzBi2+YJ97VzMQjVsMBIiScQnoY8b5G6iCExLP385q jd/Hv3hdQ/4bwfWOb1P7XaetrLR/oCOxhhLfbnbvrF1TsgjWlGyW8JfZEyXeHZlfwS9M 7/+gTOe2mpywAVcxvW5KySpOynQcx+/keAIRdx1QIVaZYdjG+8OhknEWeAu/BZ5x4Gwq K9XLOPtl1guhGpQ5/9ZS6rVnOOux+32O6daOIiJ6l3f96zKTicvgx68b8+I0NSazaE43 FLKI79+o8rQ4vJNFC++CqRx37YqU9MYyVhNvmmi9MA+urYtjN79k63Sg95IFE2nMSrmX aNDw== X-Gm-Message-State: AOUpUlGFraSP8mKqAi3lU54fUls2/QRRmJh0KgrdjUpAIxSh4XS+soj6 Hu9mUBYllD4VCporMcMry/S6fA== X-Google-Smtp-Source: AAOMgpe2E+msjm/gLvLjKZTckbG8bUtjug8td3OJN5Ihk/T1HjIzOuhOvGIdcXO/RXtSkHaic/LZxA== X-Received: by 2002:a62:6746:: with SMTP id b67-v6mr16504274pfc.243.1532415529050; Mon, 23 Jul 2018 23:58:49 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 87-v6sm22962394pfn.103.2018.07.23.23.58.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58:48 -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, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v12 12/16] arm64: kexec_file: add crash dump support Date: Tue, 24 Jul 2018 15:57:55 +0900 Message-Id: <20180724065759.19186-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180723_235900_087357_E22333E3 X-CRM114-Status: GOOD ( 21.06 ) 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 Reviewed-by: James Morse --- arch/arm64/include/asm/kexec.h | 6 +- arch/arm64/kernel/machine_kexec_file.c | 113 ++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 5d102a1054b3..1b2c27026ae0 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -97,8 +97,12 @@ static inline void crash_post_resume(void) {} #define ARCH_HAS_KIMAGE_ARCH struct kimage_arch { - void *dtb_buf; + void *dtb; unsigned long dtb_mem; + /* Core ELF header buffer */ + void *elf_headers; + unsigned long elf_headers_mem; + unsigned long elf_headers_sz; }; /** diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index b8297f10e2ef..7356da5a53d5 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); image->arch.dtb = 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,12 +44,30 @@ static int setup_dtb(struct kimage *image, void **dtb_buf, unsigned long *dtb_buf_len) { void *buf = NULL; - size_t buf_size; + size_t buf_size, range_size; int nodeoffset; 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_headers_mem, + 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 */ @@ -73,6 +97,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_headers_mem, + 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); @@ -129,6 +170,43 @@ 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, + MEMBLOCK_NONE, &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) + ret = crash_prepare_elf64_headers(cmem, true, addr, sz); + + kfree(cmem); + return ret; +} + int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, unsigned long kernel_size, @@ -136,14 +214,43 @@ int load_other_segments(struct kimage *image, char *cmdline, unsigned long cmdline_len) { struct kexec_buf kbuf; - void *dtb = NULL; - unsigned long initrd_load_addr = 0, dtb_len; + void *headers, *dtb = NULL; + unsigned long headers_sz, initrd_load_addr = 0, dtb_len; int ret = 0; kbuf.image = image; /* not allocate anything below the kernel */ kbuf.buf_min = kernel_load_addr + kernel_size; + /* load elf core header */ + if (image->type == KEXEC_TYPE_CRASH) { + ret = prepare_elf_headers(&headers, &headers_sz); + if (ret) { + pr_err("Preparing elf core header failed\n"); + goto out_err; + } + + kbuf.buffer = headers; + kbuf.bufsz = headers_sz; + kbuf.mem = 0; + kbuf.memsz = headers_sz; + kbuf.buf_align = SZ_64K; /* largest supported page size */ + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = true; + + ret = kexec_add_buffer(&kbuf); + if (ret) { + vfree(headers); + goto out_err; + } + image->arch.elf_headers = headers; + image->arch.elf_headers_mem = kbuf.mem; + image->arch.elf_headers_sz = headers_sz; + + pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + image->arch.elf_headers_mem, headers_sz, headers_sz); + } + /* load initrd */ if (initrd) { kbuf.buffer = initrd;