From nobody Thu Oct 30 23:31:25 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 1753865173532841.5714522442477; Wed, 30 Jul 2025 01:46:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1063531.1429243 (Exim 4.92) (envelope-from ) id 1uh2Rg-0007So-5p; Wed, 30 Jul 2025 08:45:56 +0000 Received: by outflank-mailman (output) from mailman id 1063531.1429243; Wed, 30 Jul 2025 08:45:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uh2Rg-0007Sf-2Z; Wed, 30 Jul 2025 08:45:56 +0000 Received: by outflank-mailman (input) for mailman id 1063531; Wed, 30 Jul 2025 08:45:55 +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 1uh2Rf-0006zM-7H for xen-devel@lists.xenproject.org; Wed, 30 Jul 2025 08:45:55 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 9a72fa0e-6d21-11f0-a320-13f23c93f187; Wed, 30 Jul 2025 10:45:54 +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 A2C8A1515; Wed, 30 Jul 2025 01:45:45 -0700 (PDT) Received: from PWQ0QT7DJ1.arm.com (unknown [10.57.73.135]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 439EB3F66E; Wed, 30 Jul 2025 01:45:52 -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: 9a72fa0e-6d21-11f0-a320-13f23c93f187 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 2/5] arm/mpu: Implement setup_mm for MPU systems Date: Wed, 30 Jul 2025 09:45:31 +0100 Message-ID: X-Mailer: git-send-email 2.42.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1753865175224116600 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: Ayan Kumarb Halder Tested-by: Ayan Kumarb Halder --- xen/arch/arm/mpu/mm.c | 64 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c index 6a16fa348d..0b05103180 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; @@ -364,9 +367,68 @@ 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(); + + total_pages =3D 0; + 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; + max_page =3D PFN_DOWN(ram_end); + + 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