Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2592294pxb; Thu, 11 Feb 2021 17:13:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJyEHcdImMOPhpZmCwPeFt5VVmuZSFp2oFh9lQtEcVzmQpgbGeJgMywDnxrOnIOnMb+GTTi+ X-Received: by 2002:a50:bb47:: with SMTP id y65mr898663ede.33.1613092402795; Thu, 11 Feb 2021 17:13:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613092402; cv=none; d=google.com; s=arc-20160816; b=juDYsQk0gnNti/SMfJ+wNC/wdFjNI7er/ai7KdXEJcdSBcurotr95pyLqoZWB0GmAB jJZpb+ik7Zr3lL9C0V2YAmUsDZApOYR3CesbaP3vhmCfxJoXu7aVdF+W2Xl/sUeWJeIv IZcwWyncag6epAsaxrrBI/63iEmzZ2gk43Ny10QCruPZbQaVeLbRCshETAO5jPpILWod 23z4cwTLpiw0mlWlrcMd9Ft8O6H2M7aOggtptYEnTNhkLAZJMdWPqHwyy+fYF1mj/YqE j7uKioax2DMK1yqKO0ooqJ6vYq8BQhwl8RhPkcnLp/p++wu4IWfEa4IMvBs7G6hJr4Yv MdLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:in-reply-to:subject :cc:to:from:user-agent:references:dkim-signature; bh=nmTDub/Ux2hr+XxZPtDhKJc7n/Ne0M1pVdt80JFvfdQ=; b=ILH+H1bs3V1ZAiWeTz2jNBhhb7ANKQ/hMZLnlFfRj9Jy55g2+vA0zrWEdx/4Li2Mb9 YVvEDg/xYcoUrw8/nIeeAL9jJHpZVdUu7AOjw5H8LPor7X98lAcMoVBZy5ZGim+LkFqR 4Vsyd1GELz4AQCph+7l8WKHH4q0uAYekvOH4os8Tf/vVASGB46NIremCVpqGp+0cVkSN 859rUfZ0I7YWzGweczaLWYlCbaqdWHmjkaFbuB9VY8TPNFlTNxEJheQXzt2piovy/Pm9 AyvYvgYJAwkjgzAdP6IpM2PKhIKb4L7C+j68oVbb4CwVx363Hj9Z0jWQgfRQpuA9QmP4 qddA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=XbDVdfjo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v10si5063167ejg.86.2021.02.11.17.12.59; Thu, 11 Feb 2021 17:13:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=XbDVdfjo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229952AbhBLBM2 (ORCPT + 99 others); Thu, 11 Feb 2021 20:12:28 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:64608 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230352AbhBLBLD (ORCPT ); Thu, 11 Feb 2021 20:11:03 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 11C12oKE194214; Thu, 11 Feb 2021 20:09:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=references : from : to : cc : subject : in-reply-to : date : message-id : mime-version : content-type; s=pp1; bh=nmTDub/Ux2hr+XxZPtDhKJc7n/Ne0M1pVdt80JFvfdQ=; b=XbDVdfjo/SU5a0O3VlsI2elV+tb+sDBEh2f+oVr/sVjssPcdCs2ry1DJt9NhPOACCzwG wujbHQX1O9pL9zUeolxtp7Msg2zhC9l3pjUiFL7uRhlLDE9VrXL5Y3NWCB/+VeKPQjWg lw2aZGOIAcK0JSi2m7Jd7j0mmmx8XFAS9wrxd3F/GgvGpH9ecX86udfT5zq6vknNQe54 vMDTUlUb1ViVpKDBlO1rWmxT49z6oPddljPHS2qt72RI1WIS0jYVq18P7tw6EoM5qfM0 y08ByxfxuQsqYUFeV4j9yqNmBNM9JaW0dO+jQwoqmwqwYd5Bv8LnOjC30/j3QhdTFeSs YQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 36nfcpgvw7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Feb 2021 20:09:30 -0500 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 11C13XG3003550; Thu, 11 Feb 2021 20:09:29 -0500 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com with ESMTP id 36nfcpgvvg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Feb 2021 20:09:29 -0500 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 11C17WSq008415; Fri, 12 Feb 2021 01:09:28 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma04dal.us.ibm.com with ESMTP id 36hjra451h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 12 Feb 2021 01:09:28 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 11C19RC912845554 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Feb 2021 01:09:27 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 668D5AE062; Fri, 12 Feb 2021 01:09:27 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 44AA1AE05C; Fri, 12 Feb 2021 01:09:20 +0000 (GMT) Received: from manicouagan.localdomain (unknown [9.85.204.73]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTPS; Fri, 12 Feb 2021 01:09:20 +0000 (GMT) References: <20210209182200.30606-1-nramas@linux.microsoft.com> <20210209182200.30606-3-nramas@linux.microsoft.com> User-agent: mu4e 1.4.10; emacs 27.1 From: Thiago Jung Bauermann To: Lakshmi Ramasubramanian Cc: zohar@linux.ibm.com, robh@kernel.org, takahiro.akashi@linaro.org, gregkh@linuxfoundation.org, will@kernel.org, joe@perches.com, catalin.marinas@arm.com, mpe@ellerman.id.au, 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, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr, prsriva@linux.microsoft.com, balajib@linux.microsoft.com, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function In-reply-to: <20210209182200.30606-3-nramas@linux.microsoft.com> Date: Thu, 11 Feb 2021 22:09:18 -0300 Message-ID: <87k0reozwh.fsf@manicouagan.localdomain> MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.737 definitions=2021-02-11_07:2021-02-11,2021-02-11 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 priorityscore=1501 malwarescore=0 spamscore=0 adultscore=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 phishscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102120002 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There's actually a complication that I just noticed and needs to be addressed. More below. Lakshmi Ramasubramanian writes: > From: Rob Herring > > Both arm64 and powerpc do essentially the same FDT /chosen setup for > kexec. The differences are either omissions that arm64 should have > or additional properties that will be ignored. The setup code can be > combined and shared by both powerpc and arm64. > > 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. > > Combine the code for setting up the /chosen node in the FDT and updating > the memory reservation for kexec, for powerpc and arm64, in > of_kexec_alloc_and_setup_fdt() and move it to "drivers/of/kexec.c". > > Signed-off-by: Rob Herring > Signed-off-by: Lakshmi Ramasubramanian > --- > drivers/of/Makefile | 6 ++ > drivers/of/kexec.c | 258 ++++++++++++++++++++++++++++++++++++++++++++ > include/linux/of.h | 13 +++ > 3 files changed, 277 insertions(+) > create mode 100644 drivers/of/kexec.c > > diff --git a/drivers/of/Makefile b/drivers/of/Makefile > index 6e1e5212f058..c13b982084a3 100644 > --- a/drivers/of/Makefile > +++ b/drivers/of/Makefile > @@ -14,4 +14,10 @@ obj-$(CONFIG_OF_RESOLVE) += resolver.o > obj-$(CONFIG_OF_OVERLAY) += overlay.o > obj-$(CONFIG_OF_NUMA) += of_numa.o > > +ifdef CONFIG_KEXEC_FILE > +ifdef CONFIG_OF_FLATTREE > +obj-y += kexec.o > +endif > +endif > + > obj-$(CONFIG_OF_UNITTEST) += unittest-data/ > diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c > new file mode 100644 > index 000000000000..469e09613cdd > --- /dev/null > +++ b/drivers/of/kexec.c > @@ -0,0 +1,258 @@ > +// 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 > + * > + * @fdt: Flattened device tree for the current kernel. > + * @start: Starting address of the reserved memory. > + * @size: Size of the reserved memory. > + * > + * 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_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree > + * > + * @image: kexec image being loaded. > + * @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: fdt on success, or NULL errno on error. > + */ > +void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, > + unsigned long initrd_load_addr, > + unsigned long initrd_len, > + const char *cmdline) > +{ > + void *fdt; > + int ret, chosen_node; > + const void *prop; > + unsigned long fdt_size; > + > + fdt_size = fdt_totalsize(initial_boot_params) + > + (cmdline ? strlen(cmdline) : 0) + > + FDT_EXTRA_SPACE; Just adding 4 KB to initial_boot_params won't be enough for crash kernels on ppc64. The current powerpc code doubles the size of initial_boot_params (which is normally larger than 4 KB) and even that isn't enough. A patch was added to powerpc/next today which uses a more precise (but arch-specific) formula: https://lore.kernel.org/linuxppc-dev/161243826811.119001.14083048209224609814.stgit@hbathini/ So I believe we need a hook here where architectures can provide their own specific calculation for the size of the fdt. Perhaps a weakly defined function providing a default implementation which an arch-specific file can override (a la arch_kexec_kernel_image_load())? Then the powerpc specific hook would be the kexec_fdt_totalsize_ppc64() function from the patch I linked above. -- Thiago Jung Bauermann IBM Linux Technology Center