From patchwork Mon Dec 9 03:03:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 11278373 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 82BCE6C1 for ; Mon, 9 Dec 2019 03:02:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 607F420663 for ; Mon, 9 Dec 2019 03:02:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TxlJvLHk"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="mhExn69W" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 607F420663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=uEdOOvQfIOWj5F2kukueKPvpRmhYRPMiuD0IJwzLRf8=; b=TxlJvLHkN6dBy2 ETE8TyaRFhjbXiNXmW2PNct9L2ibxACtB3vDBd0URa9bLqVHqZFqRJtEmh3uwBMNihfvquaix3fhi KQMMCIUxD+u3CRC3Epf4Ts+eTm+8HZ1o+F6ndweqLDYFh2/OJHGvdKQ95f3RiCAKT2mJFMjkhu173 UhZPyICYxqHZhqgr4iVyTwRfH9NmiV4naktMJMfLzfHH1iYyhoHlX7l/MZBEB3y07u/8PwzArAHAh EIPP3fTbka+tCM8GQk4hvgHAgzAdgiRprp0k3F8/9Sy8WJ1pVHvc3DQQ+qqWad6Z2SODQbfcy7EiD l3KG8MiHuRHZfHoMIssQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ie9Jh-0006LB-04; Mon, 09 Dec 2019 03:02:33 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ie9JY-00069K-Bp for linux-arm-kernel@lists.infradead.org; Mon, 09 Dec 2019 03:02:25 +0000 Received: by mail-pg1-x541.google.com with SMTP id l24so6364299pgk.2 for ; Sun, 08 Dec 2019 19:02:20 -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 :mime-version:content-transfer-encoding; bh=3FqOO3wE0tn2QZf6UyRIRojyX4xpI+NMDGsdK9w/Ap4=; b=mhExn69WBmHBESFt1kIaGlKEdtVe/i5Vgkp7eu8YMclVAMDegJkLMfclMCIgtyazfI b6bESJ1o1e6qyzDAXET8Nn9VmdMgWHdUzAhh6nUcy+zOUzMfvA6EErA24TTqdUxwGgVL ONw9363URg5l+xWM8acqZx8CyPwgxgwTA+wS252KtfXfoDyHZxb/KJk4T18mOkPNWlZA XjryhXj+d6UMVWcf1c4vWY4qxD/qSdC13hqxRQ4j0xdJtOvrMiBvQy0kiwOVMxNCEZ7+ 41KAvVcarkRe9lB14/lFzwhV73IBZAcR1OMqcmqm3mud/RyBsmEM92xv9xQmR1eMkLJa OcxQ== 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:mime-version:content-transfer-encoding; bh=3FqOO3wE0tn2QZf6UyRIRojyX4xpI+NMDGsdK9w/Ap4=; b=Az4FdeQ3hyDp4xxa0iAXDL863eMMKOYwmiRQZgkbSxBrMEZDzn4vb0Lcl2Ul2JCCIC oNHKqyiHNEjJF1vcXqbQNWDrWhCfE1qn4yOcdRlSHfl0dFi0ARdBvPmwMcEX/SOm9DAI xmhyUiKxTrxrJfBPxXLKu6/1NVr9fn5cAxKK0J1epgEoPPsJCvCh9vlaCcN1/lu0ScOq Vqt8MrRcZyEsfC4Gbn1I6nknOmej01SnbSuKxIO7p2Lq+dMJjn3Luk6BraHrvHbZhcO3 bnufiRrwjkpLFZbJk3gXtuMoyrlmoJYBtivCyn4H07S52TvoBNXOFnUoi+WsPIISIw13 tFjQ== X-Gm-Message-State: APjAAAUsJHlHBuVxqMbD1yhLOoQo4EbWgJjm4ITdaYlIf2Usbk4PXGV9 JPM8xasndhcxwHNVcNCkoc+OYA== X-Google-Smtp-Source: APXvYqxZsY4uqLOpisCtOZNKEdJ3FgiBq1GlA/9MSZaWOtU0pz8n9rOYtSAydnEby2zUtslCi8FiRA== X-Received: by 2002:a63:dc41:: with SMTP id f1mr16838812pgj.119.1575860539860; Sun, 08 Dec 2019 19:02:19 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y76sm15454209pfc.87.2019.12.08.19.02.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Dec 2019 19:02:19 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, robh+dt@kernel.org, frowand.list@gmail.com Subject: [PATCH v3 1/2] libfdt: include fdt_addresses.c Date: Mon, 9 Dec 2019 12:03:44 +0900 Message-Id: <20191209030345.5735-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191209030345.5735-1-takahiro.akashi@linaro.org> References: <20191209030345.5735-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191208_190224_423624_FAF419E8 X-CRM114-Status: GOOD ( 11.77 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:541 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kexec@lists.infradead.org, james.morse@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, AKASHI Takahiro Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org In the implementation of kexec_file_loaded-based kdump for arm64, fdt_appendprop_addrrange() will be needed. So include fdt_addresses.c in making libfdt. Signed-off-by: AKASHI Takahiro Cc: Rob Herring Cc: Frank Rowand --- lib/Makefile | 2 +- lib/fdt_addresses.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 lib/fdt_addresses.c diff --git a/lib/Makefile b/lib/Makefile index 93217d44237f..c20b1debe9b4 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -223,7 +223,7 @@ KASAN_SANITIZE_stackdepot.o := n KCOV_INSTRUMENT_stackdepot.o := n libfdt_files = fdt.o fdt_ro.o fdt_wip.o fdt_rw.o fdt_sw.o fdt_strerror.o \ - fdt_empty_tree.o + fdt_empty_tree.o fdt_addresses.o $(foreach file, $(libfdt_files), \ $(eval CFLAGS_$(file) = -I $(srctree)/scripts/dtc/libfdt)) lib-$(CONFIG_LIBFDT) += $(libfdt_files) diff --git a/lib/fdt_addresses.c b/lib/fdt_addresses.c new file mode 100644 index 000000000000..23610bcf390b --- /dev/null +++ b/lib/fdt_addresses.c @@ -0,0 +1,2 @@ +#include +#include "../scripts/dtc/libfdt/fdt_addresses.c" From patchwork Mon Dec 9 03:03:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 11278375 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E88816C1 for ; Mon, 9 Dec 2019 03:02:56 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C60F220663 for ; Mon, 9 Dec 2019 03:02:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JOs0Z1vR"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="O7dFI6rD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C60F220663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=JxB/h8S6EJXi7jhq9yF8szLRzgHI8gEy+K42ge0ha1s=; b=JOs0Z1vRNqQ2+T P7K3apZS77yrxJnlEwpeg9luZ3iWUvswZA/8Xj0RJwV7/pbpI6f0p/WP6ugyF5QC7ggd3vzIuWmx0 UVTIQ4kco/hWG4pMi0EJYGKMMrkL4Zq4VEakUQEXyLfsmV0N62GezI4v3+m05noqQdpo8DO/oQ4Bm yKcur4YErRawlU2pG6QBlbwLuJsX50pd26EaADNOKSZNY4idkSonQllcW2yMI6MqgwS3ZIRGb+fTO n46sqxvPO7zRjdA6JiTLb/Qz4SvUcEIfn4+9xqON+BNDUR8RSCGKX0Ql59q9sCELPU6LB5je6ez5S sGc8yhaDSN6+moVpohGw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ie9K1-0006le-Cl; Mon, 09 Dec 2019 03:02:53 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ie9JZ-0006A9-2z for linux-arm-kernel@lists.infradead.org; Mon, 09 Dec 2019 03:02:28 +0000 Received: by mail-pl1-x644.google.com with SMTP id w7so5156698plz.12 for ; Sun, 08 Dec 2019 19:02:23 -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 :mime-version:content-transfer-encoding; bh=K1LLOVeJtONoqpWzLiZzppWNSNBZ0v/NxRhgPKC4b2k=; b=O7dFI6rD2zZnI2kre5EzJMO+Bw36s1NGTVWnohQAwFMBsg/xt8z9WShTKOKuP4qDJ9 F0kZkuBVevWNnPNkQXqblak50hDfM/Crlj2vR6U/6aNTwc5FTvde+cCcdeSc2mfEtKt+ 8PIWMj0rPUhWUPX2YgMecsL05uwxCVpP0XUO/9B4dmesxsn4eVeKp0dBdGn6A2PE/4Yq /bAxZQL43RAUrYfrSozwIyyxIz/A59jgQkqOFJnyoIOwxwoYmbTasHpUb2WW75PyGH5o VG2f4CBmngK6zm0RIhDF4sCr8wJNMGeBQBBfSW0f6hlcmf+LNVE+X6UZqM581U1V7Nv3 TjTA== 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:mime-version:content-transfer-encoding; bh=K1LLOVeJtONoqpWzLiZzppWNSNBZ0v/NxRhgPKC4b2k=; b=s/S5Q7TtcGMjPLgPGAP0dQcsp726YQgRim1u8X18xMuMZK1RrftTyyF3e4JPXi5ax5 r8dqLwV15tRjAz0lBBeFSCUpw3MRhHB1g7HEPev7N5dT5fQ0pjwgPPoZhLP30ipTaBIA 1AyfQWJcX6MkvwzT31NIDwtdK3rC4hz65pTkdNw26LM2plsC4zKkYISWMUxTlHyaQ6tj flZIFrUEgMss9EcoTvmxqkr2gqnC8kCGX12Jxuxd2VXsZo2QSDDecvNxT1n2YfQ1WdRh sPMQbYWc/ViEjg6jJqkmCh8tgfHFvsOy9k2bQHYshUUGxE+SxEZulyGStJ6kR0rU0DR9 XnTQ== X-Gm-Message-State: APjAAAVG2uChA6t3ctb6jFeH+Bqg8RFh9XgysCg+8L+19dZrJRpOl2rx M3l4lfv374Tpp3XHx4D/WT4XNg== X-Google-Smtp-Source: APXvYqyJvjBg3ma14h+/TdMJZyPnWqz4Ej8Vw8Ndc1+bfZTO7tFYRTO9/cJ9oOgd3i4IMecEW9nX1A== X-Received: by 2002:a17:902:ab86:: with SMTP id f6mr24215136plr.78.1575860543219; Sun, 08 Dec 2019 19:02:23 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b2sm7497299pjq.3.2019.12.08.19.02.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Dec 2019 19:02:22 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, robh+dt@kernel.org, frowand.list@gmail.com Subject: [PATCH v3 2/2] arm64: kexec_file: add crash dump support Date: Mon, 9 Dec 2019 12:03:45 +0900 Message-Id: <20191209030345.5735-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191209030345.5735-1-takahiro.akashi@linaro.org> References: <20191209030345.5735-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191208_190225_143878_47D82793 X-CRM114-Status: GOOD ( 19.87 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:644 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kexec@lists.infradead.org, james.morse@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, AKASHI Takahiro Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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 | 4 + arch/arm64/kernel/kexec_image.c | 4 - arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++- 3 files changed, 106 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 12a561a54128..d24b527e8c00 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -96,6 +96,10 @@ static inline void crash_post_resume(void) {} struct kimage_arch { void *dtb; unsigned long dtb_mem; + /* Core ELF header buffer */ + void *elf_headers; + unsigned long elf_headers_mem; + unsigned long elf_headers_sz; }; extern const struct kexec_file_ops kexec_image_ops; diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index 29a9428486a5..af9987c154ca 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -47,10 +47,6 @@ static void *image_load(struct kimage *image, struct kexec_segment *kernel_segment; int ret; - /* We don't support crash kernels yet. */ - if (image->type == KEXEC_TYPE_CRASH) - return ERR_PTR(-EOPNOTSUPP); - /* * We require a kernel with an unambiguous Image header. Per * Documentation/arm64/booting.rst, this is the case when image_size diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 7b08bf9499b6..f1d1bb895fd2 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -17,12 +17,15 @@ #include #include #include +#include #include #include #include #include /* relevant device tree properties */ +#define FDT_PROP_KEXEC_ELFHDR "linux,elfcorehdr" +#define FDT_PROP_MEM_RANGE "linux,usable-memory-range" #define FDT_PROP_INITRD_START "linux,initrd-start" #define FDT_PROP_INITRD_END "linux,initrd-end" #define FDT_PROP_BOOTARGS "bootargs" @@ -40,6 +43,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); } @@ -55,6 +62,31 @@ static int setup_dtb(struct kimage *image, off = ret; + ret = fdt_delprop(dtb, off, FDT_PROP_KEXEC_ELFHDR); + if (ret && ret != -FDT_ERR_NOTFOUND) + goto out; + ret = fdt_delprop(dtb, off, FDT_PROP_MEM_RANGE); + if (ret && ret != -FDT_ERR_NOTFOUND) + goto out; + + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_appendprop_addrrange(dtb, 0, off, + FDT_PROP_KEXEC_ELFHDR, + image->arch.elf_headers_mem, + image->arch.elf_headers_sz); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + + /* add linux,usable-memory-range */ + ret = fdt_appendprop_addrrange(dtb, 0, off, + FDT_PROP_MEM_RANGE, + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop_string(dtb, off, FDT_PROP_BOOTARGS, cmdline); @@ -125,8 +157,8 @@ static int setup_dtb(struct kimage *image, } /* - * More space needed so that we can add initrd, bootargs, kaslr-seed, and - * rng-seed. + * More space needed so that we can add initrd, bootargs, kaslr-seed, + * rng-seed, userable-memory-range and elfcorehdr. */ #define DTB_EXTRA_SPACE 0x1000 @@ -174,6 +206,43 @@ static int create_dtb(struct kimage *image, } } +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, + MEMBLOCK_NONE, &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, @@ -181,14 +250,43 @@ int load_other_segments(struct kimage *image, char *cmdline) { 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;