]> xenbits.xensource.com Git - people/andrewcoop/xen.git/commitdiff
xen/arm: Check for Static Heap feature when freeing resources
authorPenny Zheng <Penny.Zheng@arm.com>
Fri, 13 Dec 2024 10:50:47 +0000 (10:50 +0000)
committerMichal Orzel <michal.orzel@amd.com>
Tue, 17 Dec 2024 08:58:47 +0000 (09:58 +0100)
If the Xen heap is statically configured in Device Tree, its size is
definite, so only the defined memory shall be given to the boot
allocator. Have a check where init_domheap_pages() is called
which takes into account if static heap feature is used.

Extract static_heap flag from init data bootinfo, as it will be needed
after destroying the init data section, rename it to using_static_heap
and use it to tell whether the Xen static heap feature is enabled.

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>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
xen/arch/arm/arm32/mmu/mm.c
xen/arch/arm/kernel.c
xen/arch/arm/mmu/setup.c
xen/arch/arm/setup.c
xen/common/device-tree/bootfdt.c
xen/common/device-tree/bootinfo.c
xen/common/page_alloc.c
xen/include/xen/bootfdt.h
xen/include/xen/mm.h

index 063611412be00eacfcdc37cfd32f933eb68440d6..0824d61323b5c9aea723c0259abc8673683fb19f 100644 (file)
@@ -199,7 +199,7 @@ void __init setup_mm(void)
 
     total_pages = ram_size >> PAGE_SHIFT;
 
-    if ( bootinfo.static_heap )
+    if ( using_static_heap )
     {
         const struct membanks *reserved_mem = bootinfo_get_reserved_mem();
 
@@ -246,7 +246,7 @@ void __init setup_mm(void)
 
     do
     {
-        e = bootinfo.static_heap ?
+        e = using_static_heap ?
             fit_xenheap_in_static_heap(pfn_to_paddr(xenheap_pages), MB(32)) :
             consider_modules(ram_start, ram_end,
                              pfn_to_paddr(xenheap_pages),
index 293d7efaed9c6ea8ca39644c909fb436e6bebbae..80fad8b3362cb53546d5be76edda4ee5fdfe9d41 100644 (file)
@@ -235,6 +235,13 @@ static __init int kernel_decompress(struct bootmodule *mod, uint32_t offset)
     for ( ; i < (1 << kernel_order_out); i++ )
         free_domheap_page(pages + i);
 
+    /*
+     * When using static heap feature, don't give bootmodules memory back to
+     * the heap allocator
+     */
+    if ( using_static_heap )
+        return 0;
+
     /*
      * When freeing the kernel, we need to pass the module start address and
      * size as they were before taking an offset to gzip header into account,
index 9664e85ee6c0f05848dc00bee92e046c065cfc3a..8c87649bc88e9cc7ff7938df8d2900679014c610 100644 (file)
@@ -341,8 +341,12 @@ void free_init_memory(void)
     if ( rc )
         panic("Unable to remove the init section (rc = %d)\n", rc);
 
-    init_domheap_pages(pa, pa + len);
-    printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>10);
+    if ( !using_static_heap )
+    {
+        init_domheap_pages(pa, pa + len);
+        printk("Freed %ldkB init memory.\n",
+               (long)(__init_end-__init_begin) >> 10);
+    }
 }
 
 /**
index 2e27af4560a504bf57daef572d4a768bd886145b..545702d8a32dadcd11d7340972e41ecf81afb2f4 100644 (file)
@@ -206,6 +206,13 @@ void __init discard_initial_modules(void)
     struct bootmodules *mi = &bootinfo.modules;
     int i;
 
+    /*
+     * When using static heap feature, don't give bootmodules memory back to
+     * the heap allocator
+     */
+    if ( using_static_heap )
+        goto out;
+
     for ( i = 0; i < mi->nr_mods; i++ )
     {
         paddr_t s = mi->module[i].start;
@@ -223,6 +230,7 @@ void __init discard_initial_modules(void)
 
     mi->nr_mods = 0;
 
+ out:
     remove_early_mappings();
 }
 
index fc93d86e82325324e2fb887aa570bb2352952247..47386d4fffeab60143a2fe580582168c382702c6 100644 (file)
@@ -410,7 +410,7 @@ static int __init process_chosen_node(const void *fdt, int node,
         if ( rc )
             return rc;
 
-        bootinfo.static_heap = true;
+        using_static_heap = true;
     }
 
     printk("Checking for initrd in /chosen\n");
index 0daf5e941a51c73dd0a63dc687ffe5e706da23d3..76d652c0de0b29d18fc3531f85b7daf36319b51d 100644 (file)
@@ -407,7 +407,7 @@ void __init populate_boot_allocator(void)
     const struct membanks *reserved_mem = bootinfo_get_reserved_mem();
     paddr_t s, e;
 
-    if ( bootinfo.static_heap )
+    if ( using_static_heap )
     {
         for ( i = 0 ; i < reserved_mem->nr_banks; i++ )
         {
index 92abed6514b468acda3ae5af482bf5b32f915c40..1f424333db27d752097531e841a46e16a5562d1a 100644 (file)
 #define PGT_TYPE_INFO_INITIALIZER 0
 #endif
 
+/* Flag saved when Xen is using the static heap feature */
+bool __ro_after_init using_static_heap;
+
 unsigned long __read_mostly max_page;
 unsigned long __read_mostly total_pages;
 paddr_t __ro_after_init mem_hotplug;
index 343c48b73d2cb46ed278ee6d6a5d2774de79e6b5..c8bbfd8979b24d250af821b368fcea282175d2d4 100644 (file)
@@ -139,7 +139,6 @@ struct bootinfo {
 #ifdef CONFIG_STATIC_SHM
     struct shared_meminfo shmem;
 #endif
-    bool static_heap;
 };
 
 #ifdef CONFIG_ACPI
index d7dcf0f06330096e85f3de744f222187694fde1c..16f733281af31dd4f811859c472c3ed47e01a095 100644 (file)
@@ -72,6 +72,8 @@
 
 struct page_info;
 
+extern bool using_static_heap;
+
 void put_page(struct page_info *page);
 bool __must_check get_page(struct page_info *page,
                            const struct domain *domain);