From nobody Thu Oct 30 23:21:33 2025 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; 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=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1756379638676993.2563437104353; Thu, 28 Aug 2025 04:13:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1098393.1452472 (Exim 4.92) (envelope-from ) id 1uraZb-00024f-KF; Thu, 28 Aug 2025 11:13:43 +0000 Received: by outflank-mailman (output) from mailman id 1098393.1452472; Thu, 28 Aug 2025 11:13:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uraZb-00024Y-HF; Thu, 28 Aug 2025 11:13:43 +0000 Received: by outflank-mailman (input) for mailman id 1098393; Thu, 28 Aug 2025 11:13:42 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uraZa-00023f-SW for xen-devel@lists.xenproject.org; Thu, 28 Aug 2025 11:13:42 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 0d2e73b9-8400-11f0-ae26-e363de0e7a9e; Thu, 28 Aug 2025 13:13:40 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A72952944; Thu, 28 Aug 2025 04:13:31 -0700 (PDT) Received: from PWQ0QT7DJ1.emea.arm.com (PWQ0QT7DJ1.cambridge.arm.com [10.1.33.71]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7D8053F694; Thu, 28 Aug 2025 04:13:38 -0700 (PDT) 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: 0d2e73b9-8400-11f0-ae26-e363de0e7a9e From: Hari Limaye To: xen-devel@lists.xenproject.org Cc: luca.fancellu@arm.com, Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 2/5] arm/mpu: Implement setup_mm for MPU systems Date: Thu, 28 Aug 2025 12:12:04 +0100 Message-ID: <2d41ab5c2bd45f788e96a93659595d66c258c8df.1756379422.git.hari.limaye@arm.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1756379640659116601 Content-Type: text/plain; charset="utf-8" From: Luca Fancellu Implement `setup_mm` for MPU systems. This variant doesn't need to set up the direct map. Signed-off-by: Luca Fancellu Signed-off-by: Hari Limaye Reviewed-by: Michal Orzel --- Changes from v2: - Add Michal's R-b Changes from v1: - Fix total_pages dead assignment - Remove extraneous space - Remove redundant max_page assignment --- xen/arch/arm/mpu/mm.c | 62 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c index 3f155b7db2..4c517d6e43 100644 --- a/xen/arch/arm/mpu/mm.c +++ b/xen/arch/arm/mpu/mm.c @@ -8,9 +8,12 @@ #include #include #include +#include +#include #include #include #include +#include #include =20 struct page_info *frame_table; @@ -378,9 +381,66 @@ int map_pages_to_xen(unsigned long virt, mfn_t mfn, un= signed long nr_mfns, return xen_mpumap_update(virt, mfn_to_maddr(mfn_add(mfn, nr_mfns)), fl= ags); } =20 +/* + * Heap must be statically configured in Device Tree through "xen,static-h= eap" + * on MPU systems. + */ +static void __init setup_staticheap_mappings(void) +{ + const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); + unsigned int bank =3D 0; + + for ( ; bank < reserved_mem->nr_banks; bank++ ) + { + if ( reserved_mem->bank[bank].type =3D=3D MEMBANK_STATIC_HEAP ) + { + paddr_t bank_start =3D round_pgup(reserved_mem->bank[bank].sta= rt); + paddr_t bank_size =3D round_pgdown(reserved_mem->bank[bank].si= ze); + paddr_t bank_end =3D bank_start + bank_size; + + /* Map static heap with one MPU protection region */ + if ( xen_mpumap_update(bank_start, bank_end, PAGE_HYPERVISOR) ) + panic("Failed to map static heap\n"); + + break; + } + } + + if ( bank =3D=3D reserved_mem->nr_banks ) + panic("No static heap memory bank found\n"); +} + void __init setup_mm(void) { - BUG_ON("unimplemented"); + const struct membanks *mem =3D bootinfo_get_mem(); + paddr_t ram_start =3D INVALID_PADDR, ram_end =3D 0, ram_size =3D 0; + + if ( !mem->nr_banks ) + panic("No memory bank\n"); + + init_pdx(); + + populate_boot_allocator(); + + for ( unsigned int bank =3D 0; bank < mem->nr_banks; bank++ ) + { + paddr_t bank_start =3D round_pgup(mem->bank[bank].start); + paddr_t bank_size =3D round_pgdown(mem->bank[bank].size); + paddr_t bank_end =3D bank_start + bank_size; + + ram_size =3D ram_size + bank_size; + ram_start =3D min(ram_start, bank_start); + ram_end =3D max(ram_end, bank_end); + } + + setup_staticheap_mappings(); + + total_pages =3D ram_size >> PAGE_SHIFT; + + setup_frametable_mappings(ram_start, ram_end); + + init_staticmem_pages(); + init_sharedmem_pages(); } =20 int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) --=20 2.34.1