Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2490281pxj; Mon, 10 May 2021 04:21:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0uTctMYjdPlZ6dW2aVWyZd6t60BAAMwYqRO7CIam1TGRnFloTNSTbxiR1THMLfj94RyMS X-Received: by 2002:aa7:d6c6:: with SMTP id x6mr28325475edr.193.1620645707248; Mon, 10 May 2021 04:21:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645707; cv=none; d=google.com; s=arc-20160816; b=Q2xn+J+rNYLeBsbOAOg+Q+5Z5pIhvtmt3oVBR0oYmNEDmXlgiOvJ0EYv7lpN2uQIN7 UNSVJlQ02/3SiYFf6G9vboLmLQe+WupdS+R6ybKyr84M24jNsuRkTdfrjyWzayyxTjZm MsOH82cUtmOkdwlm8mNwCgsOzvVWp0Ya301+FQc2ggreCRoliihOea+vB6OjBZ5gFoBA gZ1RiGLD8XC9GKjW247Rlj7VwuKceptUTik46Lu1ndSJMv808PPy3o6+AFc9CTq0bd+y WwQGkF27HZcrHqRmzFAY1BCeE1GA52/bDqw13oUmUf37UZbt6GL28gMat8trhERxoRmC CIEg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AA+2tkE5mJhXqC6Rm4081gs8Wwx1OduDU8y8KiI69VY=; b=i/6s7VmyH0cTIetDDNtd065Da2F8iv0fdxL0AE3fwOuwELQSyt0UKCYIr+kk000uKV 2yDV5S0FHcJx6WSTR6XHEvbN5ggY2Qv+40slOMKVuPretkRv/NifZmYBFZtVjeS4W3FO 9RQWZqTVXjaXqlZJeRSRaER0ST269F6Ki28HzIaoX7GrSAVt08EdJaaa0+GXhF5O6osH FzVudyBnEA8ELG/1hWk0nJ1ZI6pa7VwwGf1CtxlaeJYAtSH4TvRe84tcaFZ0F1e6DjAp k46KwNWMniRl/+M7TSMwly3DkAvVpw2aYm12RvwqjGDs31cXmdSQrYDlD0IVeaXCmqLG kJ7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="p8x/jvho"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k19si12535165edx.68.2021.05.10.04.21.24; Mon, 10 May 2021 04:21:47 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b="p8x/jvho"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238669AbhEJLS0 (ORCPT + 99 others); Mon, 10 May 2021 07:18:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:52158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233773AbhEJKzK (ORCPT ); Mon, 10 May 2021 06:55:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3686361C1D; Mon, 10 May 2021 10:42:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643342; bh=acsZ0fQWrgwm+atbVh3Rw83PjOyKrKmsInSFMqaBH00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p8x/jvhoZaecjInMxBfusEqq+dmNYrK1L2XPkHneTN8usht6UmIxX/q7g4ejBI+Gu qMoLcO0SYZZ3JAbQKPw8BDlQB+HFlBW/IggS6uB3Am3B8n0F7Tnh1ACVS/w4IgVBpu 5PFHEa4DSy5yWhGVocEjQbYnpiDdw2ppXiL7UNOE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sourabh Jain , Hari Bathini , Michael Ellerman Subject: [PATCH 5.10 241/299] powerpc/kexec_file: Use current CPU info while setting up FDT Date: Mon, 10 May 2021 12:20:38 +0200 Message-Id: <20210510102012.922942800@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sourabh Jain commit 40c753993e3aad51a12c21233486e2037417a4d6 upstream. kexec_file_load() uses initial_boot_params in setting up the device tree for the kernel to be loaded. Though initial_boot_params holds info about CPUs at the time of boot, it doesn't account for hot added CPUs. So, kexec'ing with kexec_file_load() syscall leaves the kexec'ed kernel with inaccurate CPU info. If kdump kernel is loaded with kexec_file_load() syscall and the system crashes on a hot added CPU, the capture kernel hangs failing to identify the boot CPU, with no output. To avoid this from happening, extract current CPU info from of_root device node and use it for setting up the fdt in kexec_file_load case. Fixes: 6ecd0163d360 ("powerpc/kexec_file: Add appropriate regions for memory reserve map") Cc: stable@vger.kernel.org # v5.9+ Signed-off-by: Sourabh Jain Reviewed-by: Hari Bathini Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210429060256.199714-1-sourabhjain@linux.ibm.com Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kexec/file_load_64.c | 92 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) --- a/arch/powerpc/kexec/file_load_64.c +++ b/arch/powerpc/kexec/file_load_64.c @@ -961,6 +961,93 @@ unsigned int kexec_fdt_totalsize_ppc64(s } /** + * add_node_props - Reads node properties from device node structure and add + * them to fdt. + * @fdt: Flattened device tree of the kernel + * @node_offset: offset of the node to add a property at + * @dn: device node pointer + * + * Returns 0 on success, negative errno on error. + */ +static int add_node_props(void *fdt, int node_offset, const struct device_node *dn) +{ + int ret = 0; + struct property *pp; + + if (!dn) + return -EINVAL; + + for_each_property_of_node(dn, pp) { + ret = fdt_setprop(fdt, node_offset, pp->name, pp->value, pp->length); + if (ret < 0) { + pr_err("Unable to add %s property: %s\n", pp->name, fdt_strerror(ret)); + return ret; + } + } + return ret; +} + +/** + * update_cpus_node - Update cpus node of flattened device tree using of_root + * device node. + * @fdt: Flattened device tree of the kernel. + * + * Returns 0 on success, negative errno on error. + */ +static int update_cpus_node(void *fdt) +{ + struct device_node *cpus_node, *dn; + int cpus_offset, cpus_subnode_offset, ret = 0; + + cpus_offset = fdt_path_offset(fdt, "/cpus"); + if (cpus_offset < 0 && cpus_offset != -FDT_ERR_NOTFOUND) { + pr_err("Malformed device tree: error reading /cpus node: %s\n", + fdt_strerror(cpus_offset)); + return cpus_offset; + } + + if (cpus_offset > 0) { + ret = fdt_del_node(fdt, cpus_offset); + if (ret < 0) { + pr_err("Error deleting /cpus node: %s\n", fdt_strerror(ret)); + return -EINVAL; + } + } + + /* Add cpus node to fdt */ + cpus_offset = fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "cpus"); + if (cpus_offset < 0) { + pr_err("Error creating /cpus node: %s\n", fdt_strerror(cpus_offset)); + return -EINVAL; + } + + /* Add cpus node properties */ + cpus_node = of_find_node_by_path("/cpus"); + ret = add_node_props(fdt, cpus_offset, cpus_node); + of_node_put(cpus_node); + if (ret < 0) + return ret; + + /* Loop through all subnodes of cpus and add them to fdt */ + for_each_node_by_type(dn, "cpu") { + cpus_subnode_offset = fdt_add_subnode(fdt, cpus_offset, dn->full_name); + if (cpus_subnode_offset < 0) { + pr_err("Unable to add %s subnode: %s\n", dn->full_name, + fdt_strerror(cpus_subnode_offset)); + ret = cpus_subnode_offset; + goto out; + } + + ret = add_node_props(fdt, cpus_subnode_offset, dn); + if (ret < 0) + goto out; + } +out: + of_node_put(dn); + return ret; +} + +/** * setup_new_fdt_ppc64 - Update the flattend device-tree of the kernel * being loaded. * @image: kexec image being loaded. @@ -1020,6 +1107,11 @@ int setup_new_fdt_ppc64(const struct kim } } + /* Update cpus nodes information to account hotplug CPUs. */ + ret = update_cpus_node(fdt); + if (ret < 0) + goto out; + /* Update memory reserve map */ ret = get_reserved_memory_ranges(&rmem); if (ret)