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 \(Arm\)" 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: