[PATCH 5/5] xen/arm: map static memory on demand

Hari Limaye posted 5 patches 3 months ago
There is a newer version of this series
[PATCH 5/5] xen/arm: map static memory on demand
Posted by Hari Limaye 3 months ago
From: Penny Zheng <Penny.Zheng@arm.com>

In the function `init_staticmem_pages` we need to have mapped static
memory banks for initialization. Unlike on an MMU system, we cannot map
the entire RAM on an MPU system as we have a limited number of MPU
memory regions. To solve this, transiently map the static memory banks
for initialization.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Signed-off-by: Wei Chen <wei.chen@arm.com>
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Signed-off-by: Hari Limaye <hari.limaye@arm.com>
---
 xen/arch/arm/include/asm/mmu/mm.h |  3 +++
 xen/arch/arm/include/asm/mpu/mm.h |  4 ++++
 xen/arch/arm/mpu/setup.c          | 11 +++++++++++
 xen/include/xen/static-memory.h   |  8 ++++++++
 4 files changed, 26 insertions(+)

diff --git a/xen/arch/arm/include/asm/mmu/mm.h b/xen/arch/arm/include/asm/mmu/mm.h
index 7f4d59137d..645a0ea3cb 100644
--- a/xen/arch/arm/include/asm/mmu/mm.h
+++ b/xen/arch/arm/include/asm/mmu/mm.h
@@ -110,6 +110,9 @@ void dump_pt_walk(paddr_t ttbr, paddr_t addr,
 extern void switch_ttbr(uint64_t ttbr);
 extern void relocate_and_switch_ttbr(uint64_t ttbr);
 
+static inline void map_staticmem_pages_to_xen(paddr_t start, paddr_t end) {}
+static inline void unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end) {}
+
 #endif /* __ARM_MMU_MM_H__ */
 
 /*
diff --git a/xen/arch/arm/include/asm/mpu/mm.h b/xen/arch/arm/include/asm/mpu/mm.h
index 177550f5bd..118034bbdc 100644
--- a/xen/arch/arm/include/asm/mpu/mm.h
+++ b/xen/arch/arm/include/asm/mpu/mm.h
@@ -128,6 +128,10 @@ void *map_mm_range(paddr_t start, paddr_t end, unsigned int flags);
  */
 void unmap_mm_range(paddr_t start);
 
+/* {un}map_staticmem_pages_to_xen used while initializing static memory banks */
+void map_staticmem_pages_to_xen(paddr_t start, paddr_t end);
+void unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end);
+
 /*
  * Checks whether a given memory range is present in the provided table of
  * MPU protection regions.
diff --git a/xen/arch/arm/mpu/setup.c b/xen/arch/arm/mpu/setup.c
index 163573b932..dbc3107333 100644
--- a/xen/arch/arm/mpu/setup.c
+++ b/xen/arch/arm/mpu/setup.c
@@ -83,6 +83,17 @@ void * __init early_fdt_map(paddr_t fdt_paddr)
     return fdt_virt;
 }
 
+void __init map_staticmem_pages_to_xen(paddr_t start, paddr_t end)
+{
+    if ( !map_mm_range(start, end, PAGE_HYPERVISOR) )
+        panic("Unable to map staticmem pages to Xen!");
+}
+
+void __init unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end)
+{
+    unmap_mm_range(start);
+}
+
 /*
  * copy_from_paddr - copy data from a physical address
  * @dst: destination virtual address
diff --git a/xen/include/xen/static-memory.h b/xen/include/xen/static-memory.h
index e445aa8057..d99abac113 100644
--- a/xen/include/xen/static-memory.h
+++ b/xen/include/xen/static-memory.h
@@ -18,7 +18,15 @@ static inline void init_staticmem_bank(const struct membank *bank)
     if ( mfn_x(bank_end) <= mfn_x(bank_start) )
         return;
 
+    /* Map temporarily before initialization */
+    map_staticmem_pages_to_xen(mfn_to_maddr(bank_start),
+                               mfn_to_maddr(bank_end));
+
     unprepare_staticmem_pages(mfn_to_page(bank_start), bank_pages, false);
+
+    /* Unmap immediately after initialization */
+    unmap_staticmem_pages_to_xen(mfn_to_maddr(bank_start),
+                                 mfn_to_maddr(bank_end));
 }
 
 void allocate_static_memory(struct domain *d, struct kernel_info *kinfo,
-- 
2.34.1
Re: [PATCH 5/5] xen/arm: map static memory on demand
Posted by Orzel, Michal 2 months, 1 week ago

On 30/07/2025 10:45, Hari Limaye wrote:
> From: Penny Zheng <Penny.Zheng@arm.com>
> 
> In the function `init_staticmem_pages` we need to have mapped static
> memory banks for initialization. Unlike on an MMU system, we cannot map
> the entire RAM on an MPU system as we have a limited number of MPU
> memory regions. To solve this, transiently map the static memory banks
> for initialization.
How does this correspond to Arm32 MPU (R52), where all of the RAM will be
covered? I don't think 'transient' mappings will be needed there but all of your
work targets common (i.e. not only Arm64) MPU code.

~Michal
Re: [PATCH 5/5] xen/arm: map static memory on demand
Posted by Hari Limaye 2 months ago
Hi Michal,

> On 22 Aug 2025, at 08:50, Orzel, Michal <michal.orzel@amd.com> wrote:
> 
> 
> 
> On 30/07/2025 10:45, Hari Limaye wrote:
>> From: Penny Zheng <Penny.Zheng@arm.com>
>> 
>> In the function `init_staticmem_pages` we need to have mapped static
>> memory banks for initialization. Unlike on an MMU system, we cannot map
>> the entire RAM on an MPU system as we have a limited number of MPU
>> memory regions. To solve this, transiently map the static memory banks
>> for initialization.
> How does this correspond to Arm32 MPU (R52), where all of the RAM will be
> covered? I don't think 'transient' mappings will be needed there but all of your
> work targets common (i.e. not only Arm64) MPU code.
> 
> ~Michal
> 

Hm fair point - when this series was submitted to the ML, I had no knowledge of the intention for all of the RAM to be mapped on Arm32 MPU systems and imagined that things would be more aligned here. 

Are happy for this to remain common for now? Or would you prefer it to be split off?

Many thanks,
Hari
Re: [PATCH 5/5] xen/arm: map static memory on demand
Posted by Orzel, Michal 2 months ago

On 27/08/2025 14:31, Hari Limaye wrote:
> Hi Michal,
> 
>> On 22 Aug 2025, at 08:50, Orzel, Michal <michal.orzel@amd.com> wrote:
>>
>>
>>
>> On 30/07/2025 10:45, Hari Limaye wrote:
>>> From: Penny Zheng <Penny.Zheng@arm.com>
>>>
>>> In the function `init_staticmem_pages` we need to have mapped static
>>> memory banks for initialization. Unlike on an MMU system, we cannot map
>>> the entire RAM on an MPU system as we have a limited number of MPU
>>> memory regions. To solve this, transiently map the static memory banks
>>> for initialization.
>> How does this correspond to Arm32 MPU (R52), where all of the RAM will be
>> covered? I don't think 'transient' mappings will be needed there but all of your
>> work targets common (i.e. not only Arm64) MPU code.
>>
>> ~Michal
>>
> 
> Hm fair point - when this series was submitted to the ML, I had no knowledge of the intention for all of the RAM to be mapped on Arm32 MPU systems and imagined that things would be more aligned here. 
> 
> Are happy for this to remain common for now? Or would you prefer it to be split off?
Let it be common for now. We can revisit it after the release to align on the
final approach.

~Michal
Re: [PATCH 5/5] xen/arm: map static memory on demand
Posted by Ayan Kumar Halder 2 months ago
On 27/08/2025 13:31, Hari Limaye wrote:
> CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
>
>
> Hi Michal,
Hi Hari, Michal,
>
>> On 22 Aug 2025, at 08:50, Orzel, Michal <michal.orzel@amd.com> wrote:
>>
>>
>>
>> On 30/07/2025 10:45, Hari Limaye wrote:
>>> From: Penny Zheng <Penny.Zheng@arm.com>
>>>
>>> In the function `init_staticmem_pages` we need to have mapped static
>>> memory banks for initialization. Unlike on an MMU system, we cannot map
>>> the entire RAM on an MPU system as we have a limited number of MPU
>>> memory regions. To solve this, transiently map the static memory banks
>>> for initialization.
>> How does this correspond to Arm32 MPU (R52), where all of the RAM will be
>> covered? I don't think 'transient' mappings will be needed there but all of your
>> work targets common (i.e. not only Arm64) MPU code.
>>
>> ~Michal
>>
> Hm fair point - when this series was submitted to the ML, I had no knowledge of the intention for all of the RAM to be mapped on Arm32 MPU systems and imagined that things would be more aligned here.
>
> Are happy for this to remain common for now? Or would you prefer it to be split off?

Let's split here between Arm_32 and Arm_64.

As discussed on Matrix, for Arm_32 we are mapping the entire static 
memory as a permanent MPU region. In light of Julien's comments and 
Alejandro's patch, I will revisit the approach in some time.
However, I don't want to create a dependency for this series.

We can realign later if needed. :)

- Ayan

>
> Many thanks,
> Hari
Re: [PATCH 5/5] xen/arm: map static memory on demand
Posted by Ayan Kumar Halder 2 months, 3 weeks ago
Hi Hari,

On 30/07/2025 09:45, Hari Limaye wrote:
> CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
>
>
> From: Penny Zheng <Penny.Zheng@arm.com>
>
> In the function `init_staticmem_pages` we need to have mapped static
> memory banks for initialization. Unlike on an MMU system, we cannot map
> the entire RAM on an MPU system as we have a limited number of MPU
> memory regions. To solve this, transiently map the static memory banks
> for initialization.
>
> Signed-off-by: Penny Zheng <penny.zheng@arm.com>
> Signed-off-by: Wei Chen <wei.chen@arm.com>
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
> Signed-off-by: Hari Limaye <hari.limaye@arm.com>
Reviewed-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Tested-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
(On R82 and R52 with some additional patches)