From nobody Sat Nov 23 04:16:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=raptorengineering.com ARC-Seal: i=1; a=rsa-sha256; t=1727389526; cv=none; d=zohomail.com; s=zohoarc; b=KGo7F4KEuWjJYUg2PQa7pb47B+l0xz30QWEek0/H/KHKxda4RdJvyUh+yFDvO2cNBmvwdBlUM2dxSajjYLKtZMt6NiRO3GyrMyT7sDd22cwAcmuOoJPUnoxLSvuRzAD+r4UFjJHNDpTupu9DyCjKQXb1rCGqDFN4m314igI7Emc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727389526; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=THnizrM8WgaLaQIQIbJlVxO/Ss/IgUEmhuA4iY9zqi8=; b=N/MjAHPhUdajpjby40SmP+8dJQWSnduAGyZT42WH6766z5uoScDl/Im/ulXikfx3VgAC5WTwpjtYcGes6wepjCB0LgetQldNchhhTAq5sVroGMgOJiXPXZFHI4JMibdi8IET+XOTuJfGRyxXvYezNziPEMFagpyBwaIdlMOPk64= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727389526690422.18978213743037; Thu, 26 Sep 2024 15:25:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.805919.1217180 (Exim 4.92) (envelope-from ) id 1stwv4-0002gd-Cg; Thu, 26 Sep 2024 22:25:06 +0000 Received: by outflank-mailman (output) from mailman id 805919.1217180; Thu, 26 Sep 2024 22:25:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stwv4-0002fC-7V; Thu, 26 Sep 2024 22:25:06 +0000 Received: by outflank-mailman (input) for mailman id 805919; Thu, 26 Sep 2024 22:25:05 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1stwv3-0002UO-GH for xen-devel@lists.xenproject.org; Thu, 26 Sep 2024 22:25:05 +0000 Received: from raptorengineering.com (mail.raptorengineering.com [23.155.224.40]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2b7f996d-7c56-11ef-a0ba-8be0dac302b0; Fri, 27 Sep 2024 00:25:02 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id C1729828533D; Thu, 26 Sep 2024 17:25:00 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id znw22mSfNoGb; Thu, 26 Sep 2024 17:25:00 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id E85528287AD2; Thu, 26 Sep 2024 17:24:59 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id wgumsF1QtB_l; Thu, 26 Sep 2024 17:24:59 -0500 (CDT) Received: from raptor-ewks-026.rptsys.com (5.edge.rptsys.com [23.155.224.38]) by mail.rptsys.com (Postfix) with ESMTPSA id 6AF3E82875D8; Thu, 26 Sep 2024 17:24:59 -0500 (CDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2b7f996d-7c56-11ef-a0ba-8be0dac302b0 DKIM-Filter: OpenDKIM Filter v2.10.3 mail.rptsys.com E85528287AD2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raptorengineering.com; s=B8E824E6-0BE2-11E6-931D-288C65937AAD; t=1727389499; bh=THnizrM8WgaLaQIQIbJlVxO/Ss/IgUEmhuA4iY9zqi8=; h=From:To:Date:Message-Id:MIME-Version; b=qyjb8lNeEJVOA7DrNWsd4JqmTjBTN+OojreSI5ZnhchAAwBcOnu4rG2ZMZCMQ5Uuu T4Zm7L2FnbipcTa4r01dynbuDKDPti3SZWM1x+t16JO36656wD46guRGg0D3adf13z qbJ1LQdBjYZzNnfDKhDKPT4sS3QRiQpeOtd8o2GM= X-Virus-Scanned: amavisd-new at rptsys.com From: Shawn Anastasio To: xen-devel@lists.xenproject.org Cc: tpearson@raptorengineering.com, Jan Beulich , Shawn Anastasio , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel Subject: [PATCH v5 1/3] xen/device-tree: Let DT reserve map entries overlap reserved-memory Date: Thu, 26 Sep 2024 17:24:42 -0500 Message-Id: <302647e409d91ea7ed39e568dadeedc572976c3b.1727388925.git.sanastasio@raptorengineering.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @raptorengineering.com) X-ZM-MESSAGEID: 1727389528112116601 Content-Type: text/plain; charset="utf-8" Commit 53dc37829c31 ("xen/arm: Add DT reserve map regions to bootinfo.reserved_mem") changes the way reserve map regions are tracked, and as a result broke bootfdt's ability to handle device trees in which the reserve map and the `reserved-memory` node contain the same entries as each other, as is the case on PPC when booted by skiboot. Fix this behavior by moving the reserve map check to after the DT has been parsed and by explicitly allowing overlap with entries created by `reserved-memory` nodes. Fixes: 53dc37829c31 ("xen/arm: Add DT reserve map regions to bootinfo.reser= ved_mem") Signed-off-by: Shawn Anastasio --- xen/common/device-tree/bootfdt.c | 28 +++++++++++++++++++++++----- xen/common/device-tree/bootinfo.c | 11 +++++++++-- xen/include/xen/bootfdt.h | 3 ++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/xen/common/device-tree/bootfdt.c b/xen/common/device-tree/boot= fdt.c index 911a630e7d..2a51ee44a3 100644 --- a/xen/common/device-tree/bootfdt.c +++ b/xen/common/device-tree/bootfdt.c @@ -177,7 +177,7 @@ static int __init device_tree_get_meminfo(const void *f= dt, int node, { device_tree_get_reg(&cell, address_cells, size_cells, &start, &siz= e); if ( mem =3D=3D bootinfo_get_reserved_mem() && - check_reserved_regions_overlap(start, size) ) + check_reserved_regions_overlap(start, size, NULL) ) return -EINVAL; /* Some DT may describe empty bank, ignore them */ if ( !size ) @@ -590,14 +590,36 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t = paddr) if ( nr_rsvd < 0 ) panic("Parsing FDT memory reserve map failed (%d)\n", nr_rsvd); =20 + ret =3D device_tree_for_each_node(fdt, 0, early_scan_node, NULL); + if ( ret ) + panic("Early FDT parsing failed (%d)\n", ret); + for ( i =3D 0; i < nr_rsvd; i++ ) { + const struct membanks *overlap =3D NULL; struct membank *bank; paddr_t s, sz; =20 if ( fdt_get_mem_rsv_paddr(device_tree_flattened, i, &s, &sz) < 0 ) continue; =20 + if ( check_reserved_regions_overlap(s, sz, &overlap) ) + { + if ( overlap =3D=3D bootinfo_get_reserved_mem() ) + { + /* + * Some valid device trees, such as those generated by Ope= nPOWER + * skiboot firmware, expose all reserved memory regions in= the + * FDT memory reservation block (here) AND in the + * reserved-memory node which has already been parsed. Thu= s, any + * overlaps in the mem_reserved banks should be ignored. + */ + continue; + } + else + panic("FDT reserve map overlapped with membanks/modules\n"= ); + } + if ( reserved_mem->nr_banks < reserved_mem->max_banks ) { bank =3D &reserved_mem->bank[reserved_mem->nr_banks]; @@ -610,10 +632,6 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t p= addr) panic("Cannot allocate reserved memory bank\n"); } =20 - ret =3D device_tree_for_each_node(fdt, 0, early_scan_node, NULL); - if ( ret ) - panic("Early FDT parsing failed (%d)\n", ret); - /* * On Arm64 setup_directmap_mappings() expects to be called with the l= owest * bank in memory first. There is no requirement that the DT will prov= ide diff --git a/xen/common/device-tree/bootinfo.c b/xen/common/device-tree/boo= tinfo.c index f2e6a1145b..c1752bfdc8 100644 --- a/xen/common/device-tree/bootinfo.c +++ b/xen/common/device-tree/bootinfo.c @@ -171,7 +171,8 @@ void __init fw_unreserved_regions(paddr_t s, paddr_t e, * existing reserved memory regions, otherwise false. */ bool __init check_reserved_regions_overlap(paddr_t region_start, - paddr_t region_size) + paddr_t region_size, + const struct membanks **out_ove= rlapping_membanks) { const struct membanks *mem_banks[] =3D { bootinfo_get_reserved_mem(), @@ -190,8 +191,14 @@ bool __init check_reserved_regions_overlap(paddr_t reg= ion_start, * shared memory banks (when static shared memory feature is enabled) */ for ( i =3D 0; i < ARRAY_SIZE(mem_banks); i++ ) + { if ( meminfo_overlap_check(mem_banks[i], region_start, region_size= ) ) + { + if ( out_overlapping_membanks ) + *out_overlapping_membanks =3D mem_banks[i]; return true; + } + } =20 /* Check if input region is overlapping with bootmodules */ if ( bootmodules_overlap_check(&bootinfo.modules, @@ -216,7 +223,7 @@ struct bootmodule __init *add_boot_module(bootmodule_ki= nd kind, return NULL; } =20 - if ( check_reserved_regions_overlap(start, size) ) + if ( check_reserved_regions_overlap(start, size, NULL) ) return NULL; =20 for ( i =3D 0 ; i < mods->nr_mods ; i++ ) diff --git a/xen/include/xen/bootfdt.h b/xen/include/xen/bootfdt.h index 16fa05f38f..03e1d5fde8 100644 --- a/xen/include/xen/bootfdt.h +++ b/xen/include/xen/bootfdt.h @@ -158,7 +158,8 @@ struct bootinfo { extern struct bootinfo bootinfo; =20 bool check_reserved_regions_overlap(paddr_t region_start, - paddr_t region_size); + paddr_t region_size, + const struct membanks **out_overlappin= g_membanks); =20 struct bootmodule *add_boot_module(bootmodule_kind kind, paddr_t start, paddr_t size, bool domU); --=20 2.30.2