diff mbox series

[05/11] xen/arm: Introduce helper for static memory pages

Message ID 20240312130331.78418-6-luca.fancellu@arm.com (mailing list archive)
State Superseded
Headers show
Series Static shared memory followup v2 - pt1 | expand

Commit Message

Luca Fancellu March 12, 2024, 1:03 p.m. UTC
Introduce a new helper function in the static-memory module
that can be called to manage static memory banks, this is
done to reuse the code when other modules would like to
manage static memory banks that are not part of the
reserved_mem structure.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
---
 xen/arch/arm/include/asm/static-memory.h | 12 ++++++++++++
 xen/arch/arm/static-memory.c             | 12 +-----------
 2 files changed, 13 insertions(+), 11 deletions(-)

Comments

Michal Orzel March 20, 2024, 10:41 a.m. UTC | #1
Hi Luca,

On 12/03/2024 14:03, Luca Fancellu wrote:
> 
> 
> Introduce a new helper function in the static-memory module
> that can be called to manage static memory banks, this is
> done to reuse the code when other modules would like to
> manage static memory banks that are not part of the
> reserved_mem structure.
The placement of this patch in a series is a bit strange given no use of init_staticmem_bank()
in the subsequent patch. I would move it right before patch #8.

Also, you could mention that this is because the information about shared memory regions
will no longer be stored in reserved_mem.

> 
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
> ---
>  xen/arch/arm/include/asm/static-memory.h | 12 ++++++++++++
>  xen/arch/arm/static-memory.c             | 12 +-----------
>  2 files changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/xen/arch/arm/include/asm/static-memory.h b/xen/arch/arm/include/asm/static-memory.h
> index 3e3efd70c38d..665d4df50eda 100644
> --- a/xen/arch/arm/include/asm/static-memory.h
> +++ b/xen/arch/arm/include/asm/static-memory.h
> @@ -7,6 +7,18 @@
> 
>  #ifdef CONFIG_STATIC_MEMORY
> 
> +static inline void init_staticmem_bank(const struct membank *bank)
> +{
> +    mfn_t bank_start = _mfn(PFN_UP(bank->start));
The header should be self-contained so you should add <xen/pfn.h> that is not included in asm/kernel.h path.

Other than that:
Reviewed-by: Michal Orzel <michal.orzel@amd.com>

~Michal
diff mbox series

Patch

diff --git a/xen/arch/arm/include/asm/static-memory.h b/xen/arch/arm/include/asm/static-memory.h
index 3e3efd70c38d..665d4df50eda 100644
--- a/xen/arch/arm/include/asm/static-memory.h
+++ b/xen/arch/arm/include/asm/static-memory.h
@@ -7,6 +7,18 @@ 
 
 #ifdef CONFIG_STATIC_MEMORY
 
+static inline void init_staticmem_bank(const struct membank *bank)
+{
+    mfn_t bank_start = _mfn(PFN_UP(bank->start));
+    unsigned long bank_pages = PFN_DOWN(bank->size);
+    mfn_t bank_end = mfn_add(bank_start, bank_pages);
+
+    if ( mfn_x(bank_end) <= mfn_x(bank_start) )
+        return;
+
+    unprepare_staticmem_pages(mfn_to_page(bank_start), bank_pages, false);
+}
+
 void allocate_static_memory(struct domain *d, struct kernel_info *kinfo,
                             const struct dt_device_node *node);
 void assign_static_memory_11(struct domain *d, struct kernel_info *kinfo,
diff --git a/xen/arch/arm/static-memory.c b/xen/arch/arm/static-memory.c
index 34bd12696a53..d4585c5a0633 100644
--- a/xen/arch/arm/static-memory.c
+++ b/xen/arch/arm/static-memory.c
@@ -265,17 +265,7 @@  void __init init_staticmem_pages(void)
     for ( bank = 0 ; bank < reserved_mem->nr_banks; bank++ )
     {
         if ( reserved_mem->bank[bank].type == MEMBANK_STATIC_DOMAIN )
-        {
-            mfn_t bank_start = _mfn(PFN_UP(reserved_mem->bank[bank].start));
-            unsigned long bank_pages = PFN_DOWN(reserved_mem->bank[bank].size);
-            mfn_t bank_end = mfn_add(bank_start, bank_pages);
-
-            if ( mfn_x(bank_end) <= mfn_x(bank_start) )
-                return;
-
-            unprepare_staticmem_pages(mfn_to_page(bank_start),
-                                      bank_pages, false);
-        }
+            init_staticmem_bank(&reserved_mem->bank[bank]);
     }
 }