[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/5] arm/mpu: Implement setup_mm for MPU systems


  • To: Hari Limaye <hari.limaye@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Thu, 21 Aug 2025 12:54:57 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=arm.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NQ1bLXXhExpFxPT5ePWApPcDNlZrRuF/q+j1MbvLydY=; b=d5DhQiDyx9A3dybjM08xVNFS/XUF7cdU5rlx0WFQTPOJpZOwciOg5DFVdUyF2O8oMjmnhja+tAzJfZkYdQbvoxZCJtMjrr9zd8jtRj/cJARfFuoBjQeVo/NyTJz5FFElLPvkA13z8bTMG0c9R8+uW23zA0CNZ1wJx5cKebURmAu7KLger47Y9MaDNIpIrsuYeeDcJ7e1kDo19fVBjGhU4Ak6Ld/w+JWgr537qbP69sKqxP1IOQGpKq2GSz7DbxJt68J/w/rzh1VzjA5FP1etvjCP4GVuGLr2AQLjYt+9YaYKu1fM+h8AS93aS+aj1lyp/9NosMO5kFuCT1VIL2rnxg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qEsreqZGpMNG2sOd7OaID3wLCIGMbfQiOiGylJZf+bw2P2RyH10wejfpnvmSuiWCkNpJ6t6mbEMn5103U/K+w9RKNTXI1EsmTW6FTlpL+7mhwWOPYATRq8Y1XRm88TFfkIdNmmIRtwhAYGbS2Tf1ZNGDcWdCXRJL9LI/BAssmYUf3M2KFKObLCB4PcjzaPJVN0O2AUcClUuhL4mOkA97HQIzLftzBWdbuP5ppaH+1i9g/HsV8RT7daXTjfQ4iTCWXox3NKXn/JRI8UfZuuQT58UXGBAxCOYBbG3E16Jr1icy2KnO4Div+gfyTzAPmAZPUwoQCZPKodVO4KtoXK5VsQ==
  • Cc: <luca.fancellu@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 21 Aug 2025 10:55:09 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 30/07/2025 10:45, Hari Limaye wrote:
> From: Luca Fancellu <luca.fancellu@xxxxxxx>
> 
> Implement `setup_mm` for MPU systems. This variant doesn't need to set
> up the direct map.
> 
> Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>
> Signed-off-by: Hari Limaye <hari.limaye@xxxxxxx>
> ---
>  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 <xen/sizes.h>
>  #include <xen/spinlock.h>
>  #include <xen/types.h>
> +#include <xen/static-memory.h>
> +#include <xen/static-shmem.h>
>  #include <asm/mpu.h>
>  #include <asm/mpu/mm.h>
>  #include <asm/page.h>
> +#include <asm/setup.h>
>  #include <asm/sysregs.h>
>  
>  struct page_info *frame_table;
> @@ -364,9 +367,68 @@ int map_pages_to_xen(unsigned long virt, mfn_t mfn, 
> unsigned long nr_mfns,
>      return xen_mpumap_update(virt, mfn_to_maddr(mfn_add(mfn, nr_mfns)), 
> flags);
>  }
>  
> +/*
> + * Heap must be statically configured in Device Tree through 
> "xen,static-heap"
> + * on MPU systems.
> + */
> +static void __init setup_staticheap_mappings(void)
> +{
> +    const struct membanks *reserved_mem = bootinfo_get_reserved_mem();
> +    unsigned int bank = 0;
> +
> +    for ( ; bank < reserved_mem->nr_banks; bank++ )
> +    {
> +        if ( reserved_mem->bank[bank].type == MEMBANK_STATIC_HEAP )
> +        {
> +            paddr_t bank_start = round_pgup(reserved_mem->bank[bank].start);
> +            paddr_t bank_size = round_pgdown(reserved_mem->bank[bank].size);
> +            paddr_t bank_end = 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 == reserved_mem->nr_banks )
> +        panic("No static heap memory bank found\n");
> +}
> +
>  void __init setup_mm(void)
>  {
> -    BUG_ON("unimplemented");
> +    const struct membanks *mem = bootinfo_get_mem();
> +    paddr_t ram_start = INVALID_PADDR, ram_end = 0, ram_size = 0;
> +
> +    if ( !mem->nr_banks )
> +        panic("No memory bank\n");
> +
> +    init_pdx();
> +
> +    populate_boot_allocator();
> +
> +    total_pages = 0;
There's no other place setting up total_pages between this and += ram_size
so I consider it not needed assignment. And actually, this could be calculated
in init_pdx() next to max_page to avoid requiring each arch (arm32, arm64, mpu)
to set it exactly the same.

> +    for ( unsigned int bank = 0 ; bank < mem->nr_banks; bank++ )
; should be added right after a field, so bank = 0; > +    {
> +        paddr_t bank_start = round_pgup(mem->bank[bank].start);
> +        paddr_t bank_size = round_pgdown(mem->bank[bank].size);
> +        paddr_t bank_end = bank_start + bank_size;
> +
> +        ram_size = ram_size + bank_size;
> +        ram_start = min(ram_start, bank_start);
> +        ram_end = max(ram_end, bank_end);
> +    }
> +
> +    setup_staticheap_mappings();
> +
> +    total_pages += ram_size >> PAGE_SHIFT;
> +    max_page = PFN_DOWN(ram_end);
This is already calculated in init_pdx() after my recent changes

> +
> +    setup_frametable_mappings(ram_start, ram_end);
> +
> +    init_staticmem_pages();
> +    init_sharedmem_pages();
>  }
>  
>  int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)

~Michal




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.