From patchwork Fri Dec 11 22:10:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 341988 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp899804ejs; Fri, 11 Dec 2020 14:13:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJweIdBRcsF8Y1iusZx+W48I2TK3A8FF16zmN2ufTfzCiqHCZs4huxj/GfbIicPVdeimjUpU X-Received: by 2002:aa7:c698:: with SMTP id n24mr13865983edq.277.1607724818876; Fri, 11 Dec 2020 14:13:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607724818; cv=none; d=google.com; s=arc-20160816; b=cMkJnCp46V9NoQWlHhpOkrYz9E5tVtX4y27YvQxK7mBuaeWCdz8PJ0nHvvLV8y6l1F jZ7em/rJPSp569mUBYVMUgN8UUHQRs1xxShhHIWGqg8nekHPmy6OhYKi33JLQ8Lfh6HQ Zmlv0S7pn89Vj1XOHUPMQdjax+pnraMc4t4o5HgW5eGH+wcJwwr0O7oDEAjJMR2ijS94 y7IFP9oqwbrmOOQvfuWLWVD/Jmo4jRuo4D6xnWDKFXD2CxuOWKAYDfzp2BcSGS4cgL5t /bN8u4f5a5jm56jKd8FaZIYTQ62josl7FgyLLgy3NRYxCnPRduGDxpeXDxDvaKcNSnjS eWew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5DOUAwNBZTpsAGtj8/sa2DV++d3Am3UoJ46lgHI5NXw=; b=DcsL2SQvGtrYzLYKCrTOy/lmuy2w9r32s01JxP06pzBSDxV52l7Jcb9PysaMr5lqnw 67Pw+Wl1lZu+2UpcpWr0zJuwRUvbGW8SSwDS8pGr/R+HuMCytf1ccL/oHehtci18daoz Eb7XKTFFkV7Iu2cb2LnipOHGBzAU0hxSv4Cl1GG8+m2lJubBU+wZuXGwsilZtgNQwfLI sbK7H0Ur3DMHKM+Pa6YgyEDDhc3o/AiuLlH0rB/LJeKXIHj2GTI/B4AbU1AW7FAB8IcR KBynxWA1r/YvPSsVAPV0W9ZnaLxNNj1jReBvaRWp874VSBbKuC01m59Iton6stzCiR4I CaBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si5673539edq.317.2020.12.11.14.13.38; Fri, 11 Dec 2020 14:13:38 -0800 (PST) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406580AbgLKWLa (ORCPT + 7 others); Fri, 11 Dec 2020 17:11:30 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:40487 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394262AbgLKWKz (ORCPT ); Fri, 11 Dec 2020 17:10:55 -0500 Received: by mail-ot1-f65.google.com with SMTP id j12so9665184ota.7; Fri, 11 Dec 2020 14:10:39 -0800 (PST) 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=5DOUAwNBZTpsAGtj8/sa2DV++d3Am3UoJ46lgHI5NXw=; b=QoWSMnbppJSUUFb2H8QEY3uQskYL6C1V4t+yuxVo0PwvPZzl+WXljFchfg4U2l1bb1 QkZtqQnZxLWfrMGQP2mG6lvX/N32VNTzZMkx02Nwy3/yekUJN79e112wxf3+kCh8GXsC LWcZiGbeSvFYWeBrFa2WzzYpt/nJhZoRbD7auscNtM++BelSvjfrbLHKwEpDPD4KeWd+ RLz+yl6IpBam5aAsnQVh3zkyWT7l4yEaT0aCqsARcxfU0RYn+lYUAuGGe8ZFR8DYdy5M SScUsKBdY3TeHz4zHNYkErINx9KWQ3aJ9luNo4tcUI7WYKmSjfT4p9TPXDBqELs9Qq5a 9p8Q== X-Gm-Message-State: AOAM533MDVCvk6Z2gafqAviN/IhmzebBdYMMQGB6MsiAJ/Tg1oC722g7 3BrN3ksj4lHnDBG7gtFflQ== X-Received: by 2002:a9d:37c4:: with SMTP id x62mr10493712otb.87.1607724614033; Fri, 11 Dec 2020 14:10:14 -0800 (PST) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id p3sm2137383otf.3.2020.12.11.14.10.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 14:10:11 -0800 (PST) From: Rob Herring To: Lakshmi Ramasubramanian , takahiro.akashi@linaro.org, will@kernel.org, catalin.marinas@arm.com, mpe@ellerman.id.au Cc: Thiago Jung Bauermann , zohar@linux.ibm.com, james.morse@arm.com, sashal@kernel.org, benh@kernel.crashing.org, paulus@samba.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, prsriva@linux.microsoft.com, balajib@linux.microsoft.com Subject: [RFC PATCH 1/4] powerpc: Rename kexec elfcorehdr_addr to elf_headers_mem Date: Fri, 11 Dec 2020 16:10:03 -0600 Message-Id: <20201211221006.1052453-2-robh@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201211221006.1052453-1-robh@kernel.org> References: <20201211221006.1052453-1-robh@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Align with arm64 name so common code can use it. Signed-off-by: Rob Herring --- arch/powerpc/include/asm/kexec.h | 2 +- arch/powerpc/kexec/file_load.c | 4 ++-- arch/powerpc/kexec/file_load_64.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) -- 2.25.1 Reviewed-by: Lakshmi Ramasubramanian Reviewed-by: Thiago Jung Bauermann diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/kexec.h index 55d6ede30c19..dbf09d2f36d0 100644 --- a/arch/powerpc/include/asm/kexec.h +++ b/arch/powerpc/include/asm/kexec.h @@ -108,7 +108,7 @@ struct kimage_arch { unsigned long backup_start; void *backup_buf; - unsigned long elfcorehdr_addr; + unsigned long elf_headers_mem; unsigned long elf_headers_sz; void *elf_headers; diff --git a/arch/powerpc/kexec/file_load.c b/arch/powerpc/kexec/file_load.c index 9a232bc36c8f..e452b11df631 100644 --- a/arch/powerpc/kexec/file_load.c +++ b/arch/powerpc/kexec/file_load.c @@ -45,7 +45,7 @@ char *setup_kdump_cmdline(struct kimage *image, char *cmdline, return NULL; elfcorehdr_strlen = sprintf(cmdline_ptr, "elfcorehdr=0x%lx ", - image->arch.elfcorehdr_addr); + image->arch.elf_headers_mem); if (elfcorehdr_strlen + cmdline_len > COMMAND_LINE_SIZE) { pr_err("Appending elfcorehdr= exceeds cmdline size\n"); @@ -263,7 +263,7 @@ int setup_new_fdt(const struct kimage *image, void *fdt, * Avoid elfcorehdr from being stomped on in kdump kernel by * setting up memory reserve map. */ - ret = fdt_add_mem_rsv(fdt, image->arch.elfcorehdr_addr, + ret = fdt_add_mem_rsv(fdt, image->arch.elf_headers_mem, image->arch.elf_headers_sz); if (ret) { pr_err("Error reserving elfcorehdr memory: %s\n", diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c index c69bcf9b547a..a05c19b3cc60 100644 --- a/arch/powerpc/kexec/file_load_64.c +++ b/arch/powerpc/kexec/file_load_64.c @@ -815,7 +815,7 @@ static int load_elfcorehdr_segment(struct kimage *image, struct kexec_buf *kbuf) goto out; } - image->arch.elfcorehdr_addr = kbuf->mem; + image->arch.elf_headers_mem = kbuf->mem; image->arch.elf_headers_sz = headers_sz; image->arch.elf_headers = headers; out: @@ -851,7 +851,7 @@ int load_crashdump_segments_ppc64(struct kimage *image, return ret; } pr_debug("Loaded elf core header at 0x%lx, bufsz=0x%lx memsz=0x%lx\n", - image->arch.elfcorehdr_addr, kbuf->bufsz, kbuf->memsz); + image->arch.elf_headers_mem, kbuf->bufsz, kbuf->memsz); return 0; } From patchwork Fri Dec 11 22:10:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 341986 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp899541ejs; Fri, 11 Dec 2020 14:13:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYm/FFGV+3t46R39d+VdHVz5TB1052SNrcNGrUGlY2UDp4ncXlFSHUqroC/4QAs2o2PrGm X-Received: by 2002:a05:6402:c1c:: with SMTP id co28mr14059429edb.287.1607724798178; Fri, 11 Dec 2020 14:13:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607724798; cv=none; d=google.com; s=arc-20160816; b=UMPVwMzKCLh+ZdaLyVFJU0rUVMARl6FZe/ETCW7DBeNWmtWvcR7hDf1VeK2bYCB7mU eBQ46pMSzdJywTl2yrYGFKr1eq8S3ZaKqGwhic/IrmY/ZZ1BClHi7pALnLIx7gXUR4IW 2UnlZPbnR6wJtyIKYARWtzXXHbXcyr7SwYylzMqNpXYNCI6U6TsJl+aO38HCNGqj1f+y 3TuyPSGLqBCqs/kFQxbThq/pK5DKo8H2Sgi8etYb0rZZbnU1c++82ssbX7FshU6zn4WM xLcvi8aZKRbMIXx6pQ9frR752Th8NUm5BlKAnfJsr9pfFbzCHA2SdjuJH1DHas6xxZft r5Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hZ8Ccd5snkOKXftEHLmAvtNpaBoEgIct3KMYISqIfxE=; b=nmFPV/w/VoP2nm7ST/eSh4x2lVHsMUtsrRDn9eSp8fM5YWJ4hOOhtFBo/oDbgtGMKM 8Sn4xB7ktDheiUSgaMwQYk3ENExgjz5sBsTX2l8+yyNW1mM8JQ90KMXpnlQPUU4Qi3mX 25N2Qs/3Rvrh7NQcnlwPvAgpNjQ0QtO5o5GCVpJ7NOtELpG/YaXvfKl0jfahCLEVxFlK yyACxn51ZkNjpkV+Zs8Q3hFWHcvOaaJK9SmCx3VmE8ytcc4BhGAuJqZlIyZUdkCJxvWZ Wx9NJvyYj5GSSkKWCy6163elkafmYBIUpIew+qRIi4HkGSrSDqNiSlJxF3Z2uUENWg4I Uj+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si5673539edq.317.2020.12.11.14.13.17; Fri, 11 Dec 2020 14:13:18 -0800 (PST) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406578AbgLKWLa (ORCPT + 7 others); Fri, 11 Dec 2020 17:11:30 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:42050 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406469AbgLKWK7 (ORCPT ); Fri, 11 Dec 2020 17:10:59 -0500 Received: by mail-ot1-f65.google.com with SMTP id 11so9663606oty.9; Fri, 11 Dec 2020 14:10:43 -0800 (PST) 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=hZ8Ccd5snkOKXftEHLmAvtNpaBoEgIct3KMYISqIfxE=; b=PqTgSimioWrReDOfzuNXnhtVOASK03wW2o0A5vKzmTownoTRK4ng2Shkd6IlFmujOM W6X3mGZRKhf/v058WxoWj6DqQ+/F18WcGZwsHlUrhLfT0ot7soLqtAxpyeXq6mQ3pgUr FrYmd5Pp4+7bbJ8jYpx9bD14Hi179fNP30Izyb8UMsNybJ1BZbCL7GycnMrGW4Eyd6fI KFkws1UhmBGy7xXL7hXNfOc9T/fsKjVsPqGfU7VArv44Vt6ESuykysL3uzpnDVy159Dc ACTWfMOzE4Iy61R/jTOvV/E8Px/6U+8gTgVUI/yjKwAeDtyiI2U4ucvZFgKZt2k/CN5l u9lw== X-Gm-Message-State: AOAM531XOfoAMczQqpZpl407+aINiwpZcAZh6PwXKlciFg4+sObNW6Cm VqjXuxGCAPTjhwqZDi1Jdw== X-Received: by 2002:a9d:4c8d:: with SMTP id m13mr9281644otf.229.1607724617904; Fri, 11 Dec 2020 14:10:17 -0800 (PST) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id p3sm2137383otf.3.2020.12.11.14.10.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 14:10:16 -0800 (PST) From: Rob Herring To: Lakshmi Ramasubramanian , takahiro.akashi@linaro.org, will@kernel.org, catalin.marinas@arm.com, mpe@ellerman.id.au Cc: Thiago Jung Bauermann , zohar@linux.ibm.com, james.morse@arm.com, sashal@kernel.org, benh@kernel.crashing.org, paulus@samba.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, prsriva@linux.microsoft.com, balajib@linux.microsoft.com Subject: [RFC PATCH 2/4] of: Add a common kexec FDT setup function Date: Fri, 11 Dec 2020 16:10:04 -0600 Message-Id: <20201211221006.1052453-3-robh@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201211221006.1052453-1-robh@kernel.org> References: <20201211221006.1052453-1-robh@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Both arm64 and powerpc do essentially the same FDT /chosen setup for kexec. We can simply combine everything each arch does. The differences are either omissions that arm64 should have or additional properties that will be ignored. The differences relative to the arm64 version: - If /chosen doesn't exist, it will be created (should never happen). - Any old dtb and initrd reserved memory will be released. - The new initrd and elfcorehdr are marked reserved. - "linux,booted-from-kexec" is set. The differences relative to the powerpc version: - "kaslr-seed" and "rng-seed" may be set. - "linux,elfcorehdr" is set. - Any existing "linux,usable-memory-range" is removed. Signed-off-by: Rob Herring --- This could be taken a step further and do the allocation of the new FDT. The difference is arm64 uses vmalloc and powerpc uses kmalloc. The arm64 version also retries with a bigger allocation. That seems unnecessary. --- drivers/of/Makefile | 1 + drivers/of/kexec.c | 228 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 5 + 3 files changed, 234 insertions(+) create mode 100644 drivers/of/kexec.c -- 2.25.1 Reviewed-by: Thiago Jung Bauermann diff --git a/drivers/of/Makefile b/drivers/of/Makefile index 6e1e5212f058..8ce11955afde 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -13,5 +13,6 @@ obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o obj-$(CONFIG_OF_NUMA) += of_numa.o +obj-$(CONFIG_KEXEC_FILE) += kexec.o obj-$(CONFIG_OF_UNITTEST) += unittest-data/ diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c new file mode 100644 index 000000000000..66787be081fe --- /dev/null +++ b/drivers/of/kexec.c @@ -0,0 +1,228 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2020 Arm Limited + * + * Based on arch/arm64/kernel/machine_kexec_file.c: + * Copyright (C) 2018 Linaro Limited + * + * And arch/powerpc/kexec/file_load.c: + * Copyright (C) 2016 IBM Corporation + */ + +#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" +#define FDT_PROP_KASLR_SEED "kaslr-seed" +#define FDT_PROP_RNG_SEED "rng-seed" +#define RNG_SEED_SIZE 128 + +/** + * fdt_find_and_del_mem_rsv - delete memory reservation with given address and size + * + * Return: 0 on success, or negative errno on error. + */ +static int fdt_find_and_del_mem_rsv(void *fdt, unsigned long start, unsigned long size) +{ + int i, ret, num_rsvs = fdt_num_mem_rsv(fdt); + + for (i = 0; i < num_rsvs; i++) { + u64 rsv_start, rsv_size; + + ret = fdt_get_mem_rsv(fdt, i, &rsv_start, &rsv_size); + if (ret) { + pr_err("Malformed device tree.\n"); + return -EINVAL; + } + + if (rsv_start == start && rsv_size == size) { + ret = fdt_del_mem_rsv(fdt, i); + if (ret) { + pr_err("Error deleting device tree reservation.\n"); + return -EINVAL; + } + + return 0; + } + } + + return -ENOENT; +} + +/* + * of_kexec_setup_new_fdt - modify /chosen and memory reservation for the next kernel + * + * @image: kexec image being loaded. + * @fdt: Flattened device tree for the next kernel. + * @initrd_load_addr: Address where the next initrd will be loaded. + * @initrd_len: Size of the next initrd, or 0 if there will be none. + * @cmdline: Command line for the next kernel, or NULL if there will + * be none. + * + * Return: 0 on success, or negative errno on error. + */ +int of_kexec_setup_new_fdt(const struct kimage *image, void *fdt, + unsigned long initrd_load_addr, unsigned long initrd_len, + const char *cmdline) +{ + int ret, chosen_node; + const void *prop; + + /* Remove memory reservation for the current device tree. */ + ret = fdt_find_and_del_mem_rsv(fdt, __pa(initial_boot_params), + fdt_totalsize(initial_boot_params)); + if (ret == -EINVAL) + return ret; + + chosen_node = fdt_path_offset(fdt, "/chosen"); + if (chosen_node == -FDT_ERR_NOTFOUND) + chosen_node = fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), + "chosen"); + if (chosen_node < 0) { + ret = chosen_node; + goto out; + } + + ret = fdt_delprop(fdt, chosen_node, FDT_PROP_KEXEC_ELFHDR); + if (ret && ret != -FDT_ERR_NOTFOUND) + goto out; + ret = fdt_delprop(fdt, chosen_node, FDT_PROP_MEM_RANGE); + if (ret && ret != -FDT_ERR_NOTFOUND) + goto out; + + /* Did we boot using an initrd? */ + prop = fdt_getprop(fdt, chosen_node, "linux,initrd-start", NULL); + if (prop) { + u64 tmp_start, tmp_end, tmp_size; + + tmp_start = fdt64_to_cpu(*((const fdt64_t *) prop)); + + prop = fdt_getprop(fdt, chosen_node, "linux,initrd-end", NULL); + if (!prop) + return -EINVAL; + + tmp_end = fdt64_to_cpu(*((const fdt64_t *) prop)); + + /* + * kexec reserves exact initrd size, while firmware may + * reserve a multiple of PAGE_SIZE, so check for both. + */ + tmp_size = tmp_end - tmp_start; + ret = fdt_find_and_del_mem_rsv(fdt, tmp_start, tmp_size); + if (ret == -ENOENT) + ret = fdt_find_and_del_mem_rsv(fdt, tmp_start, + round_up(tmp_size, PAGE_SIZE)); + if (ret == -EINVAL) + return ret; + } + + /* add initrd-* */ + if (initrd_load_addr) { + ret = fdt_setprop_u64(fdt, chosen_node, FDT_PROP_INITRD_START, + initrd_load_addr); + if (ret) + goto out; + + ret = fdt_setprop_u64(fdt, chosen_node, FDT_PROP_INITRD_END, + initrd_load_addr + initrd_len); + if (ret) + goto out; + + ret = fdt_add_mem_rsv(fdt, initrd_load_addr, initrd_len); + if (ret) + goto out; + + } else { + ret = fdt_delprop(fdt, chosen_node, FDT_PROP_INITRD_START); + if (ret && (ret != -FDT_ERR_NOTFOUND)) + goto out; + + ret = fdt_delprop(fdt, chosen_node, FDT_PROP_INITRD_END); + if (ret && (ret != -FDT_ERR_NOTFOUND)) + goto out; + } + + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_appendprop_addrrange(fdt, 0, chosen_node, + FDT_PROP_KEXEC_ELFHDR, + image->arch.elf_headers_mem, + image->arch.elf_headers_sz); + if (ret) + goto out; + + /* + * Avoid elfcorehdr from being stomped on in kdump kernel by + * setting up memory reserve map. + */ + ret = fdt_add_mem_rsv(fdt, image->arch.elf_headers_mem, + image->arch.elf_headers_sz); + + /* add linux,usable-memory-range */ + ret = fdt_appendprop_addrrange(fdt, 0, chosen_node, + FDT_PROP_MEM_RANGE, + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + goto out; + } + + /* add bootargs */ + if (cmdline) { + ret = fdt_setprop_string(fdt, chosen_node, FDT_PROP_BOOTARGS, cmdline); + if (ret) + goto out; + } else { + ret = fdt_delprop(fdt, chosen_node, FDT_PROP_BOOTARGS); + if (ret && (ret != -FDT_ERR_NOTFOUND)) + goto out; + } + + /* add kaslr-seed */ + ret = fdt_delprop(fdt, chosen_node, FDT_PROP_KASLR_SEED); + if (ret == -FDT_ERR_NOTFOUND) + ret = 0; + else if (ret) + goto out; + + if (rng_is_initialized()) { + u64 seed = get_random_u64(); + ret = fdt_setprop_u64(fdt, chosen_node, FDT_PROP_KASLR_SEED, seed); + if (ret) + goto out; + } else { + pr_notice("RNG is not initialised: omitting \"%s\" property\n", + FDT_PROP_KASLR_SEED); + } + + /* add rng-seed */ + if (rng_is_initialized()) { + void *rng_seed; + ret = fdt_setprop_placeholder(fdt, chosen_node, FDT_PROP_RNG_SEED, + RNG_SEED_SIZE, &rng_seed); + if (ret) + goto out; + get_random_bytes(rng_seed, RNG_SEED_SIZE); + } else { + pr_notice("RNG is not initialised: omitting \"%s\" property\n", + FDT_PROP_RNG_SEED); + } + + ret = fdt_setprop(fdt, chosen_node, "linux,booted-from-kexec", NULL, 0); + +out: + if (ret) + return (ret == -FDT_ERR_NOSPACE) ? -ENOMEM : -EINVAL; + + return 0; +} diff --git a/include/linux/of.h b/include/linux/of.h index 5d51891cbf1a..3375f5295875 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -558,6 +558,11 @@ int of_map_id(struct device_node *np, u32 id, const char *map_name, const char *map_mask_name, struct device_node **target, u32 *id_out); +struct kimage; +int of_kexec_setup_new_fdt(const struct kimage *image, void *fdt, + unsigned long initrd_load_addr, unsigned long initrd_len, + const char *cmdline); + #else /* CONFIG_OF */ static inline void of_core_init(void) From patchwork Fri Dec 11 22:10:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 341989 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp899812ejs; Fri, 11 Dec 2020 14:13:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJwe65jQi78r9VSWai4GLhH4a5oyZ1k28bn41wYjyQyoXtgOKGp5TIwP6HSAP7OuMh2HP/Sj X-Received: by 2002:a17:906:3ec8:: with SMTP id d8mr12840649ejj.32.1607724819238; Fri, 11 Dec 2020 14:13:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607724819; cv=none; d=google.com; s=arc-20160816; b=0xdbFxE7MXF3TkiODdd4/obpBnmKFJifGN5RRQzluSCubFcYDWRzL/2N1Zra3Ah9pJ 9OU0rawK20aJF6w4Cvv2q9knoXZ/cyqoWa6N8BeGzx4H4vGyTd213kGXN6ICEJ6vl6qG t1R0YAYbSf9QUNonnKwpwgHgYTuNVWa7rqXDXdPtDA8mK8Ng6VA+CTgXftacpA2MmLSL W7Xaa/nVZ97PH1kdg3lF0DdmSmsj0aKc1iblqqKRH1N5gNzxaQZ/OLyIg/x5rtycXryG j5CLLhzFC9GlTGXCqxgihdguKM1hfkWVT71ygezu5ahgaiFYN1rEJFTIGmRy5av2GMPM 0/8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=atZrSis+DH0JxvPZXBDGMdQeM648/lZjeny5zjHLlh4=; b=be66oJ/epnrFOY5Rlp7ylSBT2tJZBwbQiVMhNIg9jkGJugHiW3TAJF4UlqlhHq0elu DR7GDO+KTCLJoyrKIzwQTXQyrzsYIVEAppgkSRWoijDsyGjMliFI11uL6Asb3K+yb0fZ uyoXL7kc0LQly3iH17zM2lNeC3wZBqjKelFlfOLAPNFzLjqaF6CnVi6pUq5N0wse8eH+ H3yyM9niejBf8475chomPMK1xpiabskJ2vj1pBnpnLB9WvKsiYvD9r2HqKIhWPIzNr4l K4iAagm08RCAPM7RQnOdh81VprEkeF0AuSqvydunjZ1cw6wfwEfNtaQtHXyhc5upU9SH MvTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si5673539edq.317.2020.12.11.14.13.39; Fri, 11 Dec 2020 14:13:39 -0800 (PST) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406598AbgLKWLg (ORCPT + 7 others); Fri, 11 Dec 2020 17:11:36 -0500 Received: from mail-oi1-f196.google.com ([209.85.167.196]:35010 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406569AbgLKWLD (ORCPT ); Fri, 11 Dec 2020 17:11:03 -0500 Received: by mail-oi1-f196.google.com with SMTP id s2so11597683oij.2; Fri, 11 Dec 2020 14:10:46 -0800 (PST) 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=atZrSis+DH0JxvPZXBDGMdQeM648/lZjeny5zjHLlh4=; b=NGYQ/rhwBf/ymts2BLTPGYpJmEUXcK2JFuKiwKl9scD818rgs4kUR8cdhWFqWHrdjP 4Tby73wMac5GSsfa1ccx28S+GXYVwVPnxb6H0YBeeMeYjeD9Pt1SrU+ahOfvlIil/yEv H5X7m7BteQhCX/s2O8v8UzOY7nICEP2ybxSRvjpysptUjVxor/GsYSAkR8boUlCuG7wY BwzlVgilFmCFA4GNdPiCbhyLYbZp+VpzkNPJrx2Bh32nfzxjsanpRtxG1l2cB6YuBDKI 6pA/A+g92rX2ett03JUri1+IIxIBDoe7EyOjBpEptFSj4lLzfZcEkcKchlDS54KVQd2L FAWQ== X-Gm-Message-State: AOAM531Sp17tELHgsJ7KQhIKeE5jAzu9I2porOsnp5K2HAQJClrkNu+D CzyXdqOtjbJDcfkMaEYD/w== X-Received: by 2002:aca:58d7:: with SMTP id m206mr11170021oib.0.1607724621528; Fri, 11 Dec 2020 14:10:21 -0800 (PST) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id p3sm2137383otf.3.2020.12.11.14.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 14:10:20 -0800 (PST) From: Rob Herring To: Lakshmi Ramasubramanian , takahiro.akashi@linaro.org, will@kernel.org, catalin.marinas@arm.com, mpe@ellerman.id.au Cc: Thiago Jung Bauermann , zohar@linux.ibm.com, james.morse@arm.com, sashal@kernel.org, benh@kernel.crashing.org, paulus@samba.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, prsriva@linux.microsoft.com, balajib@linux.microsoft.com Subject: [RFC PATCH 3/4] arm64: Use common of_kexec_setup_new_fdt() Date: Fri, 11 Dec 2020 16:10:05 -0600 Message-Id: <20201211221006.1052453-4-robh@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201211221006.1052453-1-robh@kernel.org> References: <20201211221006.1052453-1-robh@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Signed-off-by: Rob Herring --- arch/arm64/kernel/machine_kexec_file.c | 123 +------------------------ 1 file changed, 3 insertions(+), 120 deletions(-) -- 2.25.1 Reviewed-by: Lakshmi Ramasubramanian Reviewed-by: Thiago Jung Bauermann Acked-by: Will Deacon diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 5b0e67b93cdc..7de9c47dee7c 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -15,23 +15,12 @@ #include #include #include +#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" -#define FDT_PROP_KASLR_SEED "kaslr-seed" -#define FDT_PROP_RNG_SEED "rng-seed" -#define RNG_SEED_SIZE 128 const struct kexec_file_ops * const kexec_file_loaders[] = { &kexec_image_ops, @@ -50,112 +39,6 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) return kexec_image_post_load_cleanup_default(image); } -static int setup_dtb(struct kimage *image, - unsigned long initrd_load_addr, unsigned long initrd_len, - char *cmdline, void *dtb) -{ - int off, ret; - - ret = fdt_path_offset(dtb, "/chosen"); - if (ret < 0) - goto out; - - 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); - if (ret) - goto out; - } else { - ret = fdt_delprop(dtb, off, FDT_PROP_BOOTARGS); - if (ret && (ret != -FDT_ERR_NOTFOUND)) - goto out; - } - - /* add initrd-* */ - if (initrd_load_addr) { - ret = fdt_setprop_u64(dtb, off, FDT_PROP_INITRD_START, - initrd_load_addr); - if (ret) - goto out; - - ret = fdt_setprop_u64(dtb, off, FDT_PROP_INITRD_END, - initrd_load_addr + initrd_len); - if (ret) - goto out; - } else { - ret = fdt_delprop(dtb, off, FDT_PROP_INITRD_START); - if (ret && (ret != -FDT_ERR_NOTFOUND)) - goto out; - - ret = fdt_delprop(dtb, off, FDT_PROP_INITRD_END); - if (ret && (ret != -FDT_ERR_NOTFOUND)) - goto out; - } - - /* add kaslr-seed */ - ret = fdt_delprop(dtb, off, FDT_PROP_KASLR_SEED); - if (ret == -FDT_ERR_NOTFOUND) - ret = 0; - else if (ret) - goto out; - - if (rng_is_initialized()) { - u64 seed = get_random_u64(); - ret = fdt_setprop_u64(dtb, off, FDT_PROP_KASLR_SEED, seed); - if (ret) - goto out; - } else { - pr_notice("RNG is not initialised: omitting \"%s\" property\n", - FDT_PROP_KASLR_SEED); - } - - /* add rng-seed */ - if (rng_is_initialized()) { - void *rng_seed; - ret = fdt_setprop_placeholder(dtb, off, FDT_PROP_RNG_SEED, - RNG_SEED_SIZE, &rng_seed); - if (ret) - goto out; - get_random_bytes(rng_seed, RNG_SEED_SIZE); - } else { - pr_notice("RNG is not initialised: omitting \"%s\" property\n", - FDT_PROP_RNG_SEED); - } - -out: - if (ret) - return (ret == -FDT_ERR_NOSPACE) ? -ENOMEM : -EINVAL; - - return 0; -} - /* * More space needed so that we can add initrd, bootargs, kaslr-seed, * rng-seed, userable-memory-range and elfcorehdr. @@ -185,8 +68,8 @@ static int create_dtb(struct kimage *image, if (ret) return -EINVAL; - ret = setup_dtb(image, initrd_load_addr, initrd_len, - cmdline, buf); + ret = of_kexec_setup_new_fdt(image, buf, initrd_load_addr, + initrd_len, cmdline); if (ret) { vfree(buf); if (ret == -ENOMEM) { From patchwork Fri Dec 11 22:10:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 341987 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp899561ejs; Fri, 11 Dec 2020 14:13:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZuxNnkflvgq/fYnT2upEl4GB3qbpFGToe7ivZroMTBnA1S3xOICiygSpGmdS3GGuTUY89 X-Received: by 2002:a50:9310:: with SMTP id m16mr14118980eda.94.1607724799444; Fri, 11 Dec 2020 14:13:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607724799; cv=none; d=google.com; s=arc-20160816; b=avw8XXsYWpO+qNjsBefPOyeFkddcHbPwBdXfn5C+BxEjAdqtjgmFLoio/2bvilovjr 6G4hM30/96FkGhqApZyEZyN51qTPZyRsvOz+2f39ZQjknBIyiMrFiDq6VlRCw0MNkl3V f0p8NKUWfkUBdFrqWlOYD6hRx+VMjPpqRcLKSjf99nyeUpS/S9zf2fBw91ZRJCeD/D03 m3jy7lfeEGs36fSZ7YN2KC08j4gzt03+Xg3XreDt0ErZvxbKADlsjey8cGrjkky86VOf f36nKX38oyiXaeo3GLcDh5Y80280sr6+mvs9/XZ813KU6rH6w6S3Gxg98hyMlw1n6adu HCYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=sZsbBtl86KBSh7SposuR5mWR/E5ADZV446RLtS+YWPM=; b=bqm6q6QuQAf8zOT5AdWAtBAZMSSIZRLwE7qr4a8P87gFhfqxrMY9tdbN9WwtjgbZdg ObHQFTUDS+dBb9eaJyMXUJQDbSsyZzNxgxiDKZ9u3givzKBkWUMF03r9fG86T52wAGDy pKRMV8v8qalB0i0sZMVrKUzogEyT2lvcQd/Y8l+3vkjsAqvK6VpM7T9snTyZD3/F578p 1RP9VfxSv4SOkYBePwQMTwt1FCBY2i7mCLo8Rx3suxs3EqG+wyPOqJTzkxBcGaN3dzKV TuemNkOW8bjojgQzH1ebWZNo7QoxFUEgShlmpZYx0G2FrBncW7LVRyge0kFwC4k0N0q4 QFpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si5673539edq.317.2020.12.11.14.13.19; Fri, 11 Dec 2020 14:13:19 -0800 (PST) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406606AbgLKWLh (ORCPT + 7 others); Fri, 11 Dec 2020 17:11:37 -0500 Received: from mail-oi1-f196.google.com ([209.85.167.196]:41179 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406573AbgLKWLF (ORCPT ); Fri, 11 Dec 2020 17:11:05 -0500 Received: by mail-oi1-f196.google.com with SMTP id 15so11583703oix.8; Fri, 11 Dec 2020 14:10:49 -0800 (PST) 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=sZsbBtl86KBSh7SposuR5mWR/E5ADZV446RLtS+YWPM=; b=OGM6hCQT981eG6OOxJtcP0JGTGo+C1TyXNg7sL55GdS639UStuZbZ8kccriDvvI7Q4 XNOmXlopGXTZpJbMCkkysJvPUIhgGS0ClUBtKTXSb/RdVMox6eI61wpM6WM80SWqmW3p V1UGQU5IUlMc4HMwwC+T1wJIfNv5mw29JawBZb2FkEzS5FrK4dEFU62nxCq1A7DxP+3Q +FvHcwEvJWKGWzYqFAeNKs+QjA1v2oYngiIRqQeyyIh2boUJTJEhA22V56OydcbF3dzH NDBzcGHufQI5xZyYJvBSjNNuVUml2s9hUjZ8a4miakTEd2cB02c4WkuQ4kh13vEcI/Wi tC+w== X-Gm-Message-State: AOAM531R4xfQnnkfi8neprU3IblLR6JK4JUIOXgLOtC0pIQMsE1pY0ZO +U6rWFVaKR+yLTNCMveZuQ== X-Received: by 2002:aca:ba42:: with SMTP id k63mr10639446oif.111.1607724624431; Fri, 11 Dec 2020 14:10:24 -0800 (PST) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id p3sm2137383otf.3.2020.12.11.14.10.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 14:10:23 -0800 (PST) From: Rob Herring To: Lakshmi Ramasubramanian , takahiro.akashi@linaro.org, will@kernel.org, catalin.marinas@arm.com, mpe@ellerman.id.au Cc: Thiago Jung Bauermann , zohar@linux.ibm.com, james.morse@arm.com, sashal@kernel.org, benh@kernel.crashing.org, paulus@samba.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, prsriva@linux.microsoft.com, balajib@linux.microsoft.com Subject: [RFC PATCH 4/4] powerpc: Use common of_kexec_setup_new_fdt() Date: Fri, 11 Dec 2020 16:10:06 -0600 Message-Id: <20201211221006.1052453-5-robh@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201211221006.1052453-1-robh@kernel.org> References: <20201211221006.1052453-1-robh@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Signed-off-by: Rob Herring --- After the IMA changes, delete_fdt_mem_rsv() can also be removed. arch/powerpc/kexec/file_load.c | 125 ++------------------------------- 1 file changed, 6 insertions(+), 119 deletions(-) -- 2.25.1 Reviewed-by: Lakshmi Ramasubramanian Reviewed-by: Thiago Jung Bauermann diff --git a/arch/powerpc/kexec/file_load.c b/arch/powerpc/kexec/file_load.c index e452b11df631..956bcb2d1ec2 100644 --- a/arch/powerpc/kexec/file_load.c +++ b/arch/powerpc/kexec/file_load.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -156,132 +157,18 @@ int setup_new_fdt(const struct kimage *image, void *fdt, unsigned long initrd_load_addr, unsigned long initrd_len, const char *cmdline) { - int ret, chosen_node; - const void *prop; - - /* Remove memory reservation for the current device tree. */ - ret = delete_fdt_mem_rsv(fdt, __pa(initial_boot_params), - fdt_totalsize(initial_boot_params)); - if (ret == 0) - pr_debug("Removed old device tree reservation.\n"); - else if (ret != -ENOENT) - return ret; - - chosen_node = fdt_path_offset(fdt, "/chosen"); - if (chosen_node == -FDT_ERR_NOTFOUND) { - chosen_node = fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), - "chosen"); - if (chosen_node < 0) { - pr_err("Error creating /chosen.\n"); - return -EINVAL; - } - } else if (chosen_node < 0) { - pr_err("Malformed device tree: error reading /chosen.\n"); - return -EINVAL; - } - - /* Did we boot using an initrd? */ - prop = fdt_getprop(fdt, chosen_node, "linux,initrd-start", NULL); - if (prop) { - uint64_t tmp_start, tmp_end, tmp_size; - - tmp_start = fdt64_to_cpu(*((const fdt64_t *) prop)); - - prop = fdt_getprop(fdt, chosen_node, "linux,initrd-end", NULL); - if (!prop) { - pr_err("Malformed device tree.\n"); - return -EINVAL; - } - tmp_end = fdt64_to_cpu(*((const fdt64_t *) prop)); - - /* - * kexec reserves exact initrd size, while firmware may - * reserve a multiple of PAGE_SIZE, so check for both. - */ - tmp_size = tmp_end - tmp_start; - ret = delete_fdt_mem_rsv(fdt, tmp_start, tmp_size); - if (ret == -ENOENT) - ret = delete_fdt_mem_rsv(fdt, tmp_start, - round_up(tmp_size, PAGE_SIZE)); - if (ret == 0) - pr_debug("Removed old initrd reservation.\n"); - else if (ret != -ENOENT) - return ret; - - /* If there's no new initrd, delete the old initrd's info. */ - if (initrd_len == 0) { - ret = fdt_delprop(fdt, chosen_node, - "linux,initrd-start"); - if (ret) { - pr_err("Error deleting linux,initrd-start.\n"); - return -EINVAL; - } - - ret = fdt_delprop(fdt, chosen_node, "linux,initrd-end"); - if (ret) { - pr_err("Error deleting linux,initrd-end.\n"); - return -EINVAL; - } - } - } - - if (initrd_len) { - ret = fdt_setprop_u64(fdt, chosen_node, - "linux,initrd-start", - initrd_load_addr); - if (ret < 0) - goto err; - - /* initrd-end is the first address after the initrd image. */ - ret = fdt_setprop_u64(fdt, chosen_node, "linux,initrd-end", - initrd_load_addr + initrd_len); - if (ret < 0) - goto err; - - ret = fdt_add_mem_rsv(fdt, initrd_load_addr, initrd_len); - if (ret) { - pr_err("Error reserving initrd memory: %s\n", - fdt_strerror(ret)); - return -EINVAL; - } - } - - if (cmdline != NULL) { - ret = fdt_setprop_string(fdt, chosen_node, "bootargs", cmdline); - if (ret < 0) - goto err; - } else { - ret = fdt_delprop(fdt, chosen_node, "bootargs"); - if (ret && ret != -FDT_ERR_NOTFOUND) { - pr_err("Error deleting bootargs.\n"); - return -EINVAL; - } - } + int ret; - if (image->type == KEXEC_TYPE_CRASH) { - /* - * Avoid elfcorehdr from being stomped on in kdump kernel by - * setting up memory reserve map. - */ - ret = fdt_add_mem_rsv(fdt, image->arch.elf_headers_mem, - image->arch.elf_headers_sz); - if (ret) { - pr_err("Error reserving elfcorehdr memory: %s\n", - fdt_strerror(ret)); - goto err; - } - } + ret = of_kexec_setup_new_fdt(image, fdt, initrd_load_addr, initrd_len, cmdline); + if (ret) + goto err; - ret = setup_ima_buffer(image, fdt, chosen_node); + ret = setup_ima_buffer(image, fdt, fdt_path_offset(fdt, "/chosen")); if (ret) { pr_err("Error setting up the new device tree.\n"); return ret; } - ret = fdt_setprop(fdt, chosen_node, "linux,booted-from-kexec", NULL, 0); - if (ret) - goto err; - return 0; err: