Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2517686pxj; Mon, 10 May 2021 05:03:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqNQ5W3ar6Y42Qhc8xdbxDmZAT0sM4WrdNYGkm+0EgkgzmZL8ichE8LD55Jq7uuZhlNoH1 X-Received: by 2002:a17:906:538a:: with SMTP id g10mr484545ejo.243.1620648185988; Mon, 10 May 2021 05:03:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620648185; cv=none; d=google.com; s=arc-20160816; b=nPjtEma7LvLZExRFVF0F8AXvhQUmv8m9z2Rt/HSp26JPTNbL+bOqW013sA+dlU/UJy Q+l2E/3I2UVPeQQWrTavUYAdJW7PLcVyc3RnVy0qnSonEp69aHyPk3LI4mn6qplBKD83 q4Vdkzf2QnhUAsTXdGcmlyJ7QQhaYRd1LAt9oO0dzEQ6UhaB407CaRN/UXEnprrhC4qG Cyab+hChSm+ajJzmQUwHf1IWVaiaDNXPXnGUaCwbjBnM6ZpwOm8nfLhD4qTRifU4rNXw +Ogp96EeDe0Vr0wEF6T7DgyAgWdhzCM7BZ4/L79JGfDKvIpdGyFFPw+7Je1gcBWyCaDe 49GQ== 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=NFn6l2q5l6DXjJtbtD/imau7KCDd578mBxrFw6guArHZXkZ+tDCIsvPSKr/BzAWro9 fqFAdnigAivlnaOxic9gRw6xYLhFN1WG8DdGQhJbNhmrvZJfKFUwEBRDciNCoqPuFuui QmmxYITGqHizEEw96IMSUDhU/5P+ak9qD2KrKIuGNRqSOjZGhdHZIa2wKcNC/gz6to4K ckNuInxXAQZ4Dw3mtCwQ0bI7jedQ/KFKy2bvqUZSsJjauGIgl/mMeguUH3rCdoR92VVz ahDDijBDV/Y2lk4ODwGva2YDI6XmesF/nRlcLGIuJVe+LCIeyIiPE2+DfV7Uex5rseDb b54Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KvQi3UFC; 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 bx14si14269801edb.119.2021.05.10.05.02.40; Mon, 10 May 2021 05:03:05 -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=KvQi3UFC; 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 S237737AbhEJLyL (ORCPT + 99 others); Mon, 10 May 2021 07:54:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:36544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231480AbhEJLDs (ORCPT ); Mon, 10 May 2021 07:03:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0EE206101E; Mon, 10 May 2021 10:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620644070; bh=acsZ0fQWrgwm+atbVh3Rw83PjOyKrKmsInSFMqaBH00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KvQi3UFCTJ35NS5CCz5ZLTYLlQnMI8XZhHduFt6x7BwLOsLdK7SuOAmoGmMUqcDDd j1QLc8VtOev27MNCE9Mub8OWw+hL+CazQRm7qxQbcQfZaj/WqimV5KvwG55OTU2xWm kBujm+KeBugEOGxdmSj6ZzM5N2AJqGMTDIYCtqI8= 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.11 275/342] powerpc/kexec_file: Use current CPU info while setting up FDT Date: Mon, 10 May 2021 12:21:05 +0200 Message-Id: <20210510102019.190623492@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102010.096403571@linuxfoundation.org> References: <20210510102010.096403571@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)