From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCD99C433B4 for ; Mon, 19 Apr 2021 05:56:00 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1E9B261057 for ; Mon, 19 Apr 2021 05:56:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E9B261057 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FNwzL2g2gz3c1h for ; Mon, 19 Apr 2021 15:55:58 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=d5lX5mW7; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2401:3900:2:1::2; helo=ozlabs.org; envelope-from=srs0=oagm=jq=linux.ibm.com=hbathini@ozlabs.org; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=d5lX5mW7; dkim-atps=neutral Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4FNwyq5wMZz2ysv for ; Mon, 19 Apr 2021 15:55:31 +1000 (AEST) Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) by ozlabs.org (Postfix) with ESMTP id 4FNwyq49f3z9vFg for ; Mon, 19 Apr 2021 15:55:31 +1000 (AEST) Received: by ozlabs.org (Postfix) id 4FNwyq3mkYz9vFb; Mon, 19 Apr 2021 15:55:31 +1000 (AEST) Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=hbathini@linux.ibm.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=d5lX5mW7; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FNwyq05Rnz9vFR; Mon, 19 Apr 2021 15:55:30 +1000 (AEST) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13J5YKC6157375; Mon, 19 Apr 2021 01:55:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : to : cc : references : from : message-id : date : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pp1; bh=juRWTAe37MqEmqMeXTX2/f4zDfT5Y3rJM+GGdIj/p4g=; b=d5lX5mW7XqEgUk9sKC06Nzwrv1sE6hND4az3k49UHq6AZDqayD0sH9/fzG5glNIy+UIe 9X4dnC5w/ERxMd17Ge2/NQPTCCrUMmANYOZjw2CxOIo3mC6tXV8m9Ry8oCVw+Go0PIK/ hGFg+pLGUvQPqRKKLrOvyJM5K0MMcYQCtYNg0fR6BjzGvlcnrvlCldhSktpcW/ZK+oi/ eRCG8TEKpxfsDo36ggvvwJSBqdhJeEhenWJlvnTWX7VvSksbE6lWI23R9fTZf5EbSotP 3kN0xXrVU/vsvBhSMcEjZQGYTbdyMO/klJQW1IxHlKUFq+elEPBRNKAbes1OIr37NH6o XQ== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 380d0amx5s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Apr 2021 01:55:28 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13J5tDZg032016; Mon, 19 Apr 2021 05:55:26 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06ams.nl.ibm.com with ESMTP id 37yt2rrsjk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Apr 2021 05:55:26 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13J5tNtg34472318 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Apr 2021 05:55:23 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A99C6AE04D; Mon, 19 Apr 2021 05:55:23 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D07D0AE045; Mon, 19 Apr 2021 05:55:20 +0000 (GMT) Received: from [9.211.74.96] (unknown [9.211.74.96]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 19 Apr 2021 05:55:20 +0000 (GMT) Subject: Re: [PATCH v3] powerpc/kexec_file: use current CPU info while setting up FDT To: Sourabh Jain , mpe@ellerman.id.au References: <20210417053805.800907-1-sourabhjain@linux.ibm.com> From: Hari Bathini Message-ID: <50f1259c-c9b3-1255-8b40-f151f1a60ebf@linux.ibm.com> Date: Mon, 19 Apr 2021 11:25:18 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 In-Reply-To: <20210417053805.800907-1-sourabhjain@linux.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-GUID: DYQXp8hq9Ul7qVvpRy6HeEu5XjLV9Gjh X-Proofpoint-ORIG-GUID: DYQXp8hq9Ul7qVvpRy6HeEu5XjLV9Gjh Content-Transfer-Encoding: 7bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-19_02:2021-04-16, 2021-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 priorityscore=1501 clxscore=1011 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104190037 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mahesh@linux.vnet.ibm.com, bauerman@linux.ibm.com, stable@vger.kernel.org, linuxppc-dev@ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Hi Sourabh, Thanks for fixing this. Generating an FDT based on of_root (the latest unflattened device-tree) should be ideal as something similar to what is done for /cpus here applies to /memory@* & /ibm,dynamic-reconfiguration-memory nodes too (probably also applies to other nodes like pci@* ?). But IIUC, there is no API in the kernel currently that converts an unflattened device-tree (struct device_node *of_root) to FDT and having one might have it's own challenges. Should pursue fixing /memory@* and other nodes for kexec as follow-up to this patch either with the unflattened DT to FDT approach or otherwise... On 17/04/21 11:08 am, Sourabh Jain wrote: > 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 would leave the kexec'ed > kernel with inaccurate CPU info. Also, if kdump kernel is loaded with > kexec_file_load syscall and the system crashes on a hot added CPU, > capture kernel hangs failing to identify the boot CPU. > > Kernel panic - not syncing: sysrq triggered crash > CPU: 24 PID: 6065 Comm: echo Kdump: loaded Not tainted 5.12.0-rc5upstream #54 > Call Trace: > [c0000000e590fac0] [c0000000007b2400] dump_stack+0xc4/0x114 (unreliable) > [c0000000e590fb00] [c000000000145290] panic+0x16c/0x41c > [c0000000e590fba0] [c0000000008892e0] sysrq_handle_crash+0x30/0x40 > [c0000000e590fc00] [c000000000889cdc] __handle_sysrq+0xcc/0x1f0 > [c0000000e590fca0] [c00000000088a538] write_sysrq_trigger+0xd8/0x178 > [c0000000e590fce0] [c0000000005e9b7c] proc_reg_write+0x10c/0x1b0 > [c0000000e590fd10] [c0000000004f26d0] vfs_write+0xf0/0x330 > [c0000000e590fd60] [c0000000004f2aec] ksys_write+0x7c/0x140 > [c0000000e590fdb0] [c000000000031ee0] system_call_exception+0x150/0x290 > [c0000000e590fe10] [c00000000000ca5c] system_call_common+0xec/0x278 > --- interrupt: c00 at 0x7fff905b9664 > NIP: 00007fff905b9664 LR: 00007fff905320c4 CTR: 0000000000000000 > REGS: c0000000e590fe80 TRAP: 0c00 Not tainted (5.12.0-rc5upstream) > MSR: 800000000280f033 CR: 28000242 > XER: 00000000 > IRQMASK: 0 > GPR00: 0000000000000004 00007ffff5fedf30 00007fff906a7300 0000000000000001 > GPR04: 000001002a7355b0 0000000000000002 0000000000000001 00007ffff5fef616 > GPR08: 0000000000000001 0000000000000000 0000000000000000 0000000000000000 > GPR12: 0000000000000000 00007fff9073a160 0000000000000000 0000000000000000 > GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 > GPR20: 0000000000000000 00007fff906a4ee0 0000000000000002 0000000000000001 > GPR24: 00007fff906a0898 0000000000000000 0000000000000002 000001002a7355b0 > GPR28: 0000000000000002 00007fff906a1790 000001002a7355b0 0000000000000002 > NIP [00007fff905b9664] 0x7fff905b9664 > LR [00007fff905320c4] 0x7fff905320c4 > --- interrupt: c00 > > 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") > > Signed-off-by: Sourabh Jain > Cc: Fow now, this should be a good stop-gap fix for /cpus node case. Reviewed-by: Hari Bathini > --- > arch/powerpc/kexec/file_load_64.c | 98 +++++++++++++++++++++++++++++++ > 1 file changed, 98 insertions(+) > > --- > Changelog: > > v1 -> v2 > - fdt should be updated regardless of kexec type > - updated commit message and title > > v2 -> v3 > - Fixed warnings reported by patchwork > (https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20210416124658.718860-1-sourabhjain@linux.ibm.com/) > - argument aligned to open parenthesis > - declared add_node_prop and update_cpus_node function static > --- > > diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c > index 02b9e4d0dc40..878f8297fbed 100644 > --- a/arch/powerpc/kexec/file_load_64.c > +++ b/arch/powerpc/kexec/file_load_64.c > @@ -960,6 +960,99 @@ unsigned int kexec_fdt_totalsize_ppc64(struct kimage *image) > return fdt_size; > } > > +/** > + * add_node_prop - Read property 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 > + * np: device node pointer > + * > + * Returns 0 on success, negative errno on error. > + */ > +static int add_node_prop(void *fdt, int node_offset, const struct device_node *np) > +{ > + int ret = 0; > + struct property *pp; > + unsigned long flags; > + > + if (!np) > + return -EINVAL; > + > + raw_spin_lock_irqsave(&devtree_lock, flags); > + for (pp = np->properties; pp; pp = pp->next) { > + 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)); > + goto out; > + } > + } > +out: > + raw_spin_unlock_irqrestore(&devtree_lock, flags); > + 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_off, ret = 0; > + > + cpus_offset = fdt_path_offset(fdt, "/cpus"); > + if (cpus_offset == -FDT_ERR_NOTFOUND || cpus_offset > 0) { > + 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_prop(fdt, cpus_offset, 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_off = fdt_add_subnode(fdt, > + cpus_offset, > + dn->full_name); > + if (cpus_subnode_off < 0) { > + pr_err("Unable to add %s subnode: %s\n", > + dn->full_name, fdt_strerror(cpus_subnode_off)); > + return cpus_subnode_off; > + } > + ret = add_node_prop(fdt, cpus_subnode_off, dn); > + if (ret < 0) > + return ret; > + } > + } else if (cpus_offset < 0) { > + pr_err("Malformed device tree: error reading /cpus node: %s\n", > + fdt_strerror(cpus_offset)); > + } > + > + return ret; > +} > + > /** > * setup_new_fdt_ppc64 - Update the flattend device-tree of the kernel > * being loaded. > @@ -1020,6 +1113,11 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt, > } > } > > + /* Update cpus nodes information to account hotplug CPUs. */ > + ret = update_cpus_node(fdt); > + if (ret < 0) > + return ret; > + > /* Update memory reserve map */ > ret = get_reserved_memory_ranges(&rmem); > if (ret) >