xen/arm: Check for Static Heap feature when freeing resources
PATCH v6 1/1 xen/arm: Check for Static Heap feature when freeing resources
From: Penny Zheng <[email protected]>
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.
---
Changes from v5:
- Drop Jan R-by due to the code changes
- Static heap is not dependent on static memory, so delete #ifdefs for CONFIG_STATIC_MEMORY
Changes from v4:
- Add R-by Jan
- Changed code to reduce nesting in discard_initial_modules (Julien)
Changes from v3:
- Removed helper using_static_heap(), renamed static_heap variable to using_static_heap and simplified #ifdef-ary (Jan suggestion)
Changes from v2:
- Change xen_is_using_staticheap() to using_static_heap()
- Move declaration of static_heap to xen/mm.h and import that in bootfdt.h
- Reprased first part of the commit message
Changes from v1:
- moved static_heap to common/page_alloc.c
- protect static_heap access with CONFIG_STATIC_MEMORY
- update comment in arm/kernel.c kernel_decompress()
---
--- xen/arch/arm/arm32/mmu/mm.c | 4 ++-- xen/arch/arm/kernel.c | 7 ++++--- xen/arch/arm/mmu/setup.c | 8 ++++++-- xen/arch/arm/setup.c | 3 +++ xen/common/device-tree/bootfdt.c | 2 +- xen/common/device-tree/bootinfo.c | 2 +- xen/common/page_alloc.c | 3 +++ xen/include/xen/bootfdt.h | 1 - xen/include/xen/mm.h | 2 ++ 9 files changed, 22 insertions(+), 10 deletions(-)
xen/arch/arm/arm32/mmu/mm.c +2 -2
@@ -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),
xen/arch/arm/kernel.c +4 -3
@@ -244,10 +244,11 @@ static __init int kernel_decompress(struct bootmodule *mod, uint32_t offset) size += offset;/* -* Free the original kernel, update the pointers to the -* decompressed kernel +* In case Xen is not using the static heap feature, free the original +* kernel, update the pointers to the decompressed kernel */ -fw_unreserved_regions (addr, addr + size, init_domheap_pages,0 ); +if ( !using_static_heap ) +fw_unreserved_regions (addr, addr + size, init_domheap_pages,0 );return 0 ; }
xen/arch/arm/mmu/setup.c +6 -2
@@ -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 ); + } }/**
xen/arch/arm/setup.c +3 -0
@@ -206,6 +206,9 @@ void __init discard_initial_modules(void)struct bootmodules *mi = &bootinfo.modules;int i; +if ( using_static_heap ) +return ; +for ( i =0 ; i < mi->nr_mods; i++ ) {paddr_t s = mi->module[i].start;
xen/common/device-tree/bootfdt.c +1 -1
@@ -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" );
xen/common/device-tree/bootinfo.c +1 -1
@@ -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++ ) {
xen/common/page_alloc.c +3 -0
@@ -165,6 +165,9 @@#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;
xen/include/xen/bootfdt.h +0 -1
@@ -139,7 +139,6 @@ struct bootinfo {#ifdef CONFIG_STATIC_SHM struct shared_meminfo shmem;#endif -bool static_heap; };#ifdef CONFIG_ACPI
xen/include/xen/mm.h +2 -0
@@ -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);
Signature · 1 line
2.34.1
Quoted 76 lines · Luca Fancellu
From: Penny Zheng <[email protected]>
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_heapflag from init data bootinfo, as it will be needed after destroying the init data section, rename it tousing_static_heapand use it to tell whether the Xen static heap feature is enabled.Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>Signed-off-by Luca Fancellu <[email protected]>---
Changes from v5:
- Drop Jan R-by due to the code changes
- Static heap is not dependent on static memory, so delete #ifdefs forCONFIG_STATIC_MEMORY
Changes from v4:
- Add R-by Jan
- Changed code to reduce nesting indiscard_initial_modules(Julien)
Changes from v3:
- Removed helperusing_static_heap(), renamedstatic_heapvariable tousing_static_heapand simplified #ifdef-ary (Jan suggestion)
Changes from v2:
- Changexen_is_using_staticheap()tousing_static_heap()
- Move declaration ofstatic_heaptoxen/mm.hand import that inbootfdt.h
- Reprased first part of the commit message
Changes from v1:
- movedstatic_heaptocommon/page_alloc.c
- protectstatic_heapaccess withCONFIG_STATIC_MEMORY
- update comment inarm/kernel.ckernel_decompress()
------ xen/arch/arm/arm32/mmu/mm.c | 4 ++-- xen/arch/arm/kernel.c | 7 ++++--- xen/arch/arm/mmu/setup.c | 8 ++++++-- xen/arch/arm/setup.c | 3 +++ xen/common/device-tree/bootfdt.c | 2 +- xen/common/device-tree/bootinfo.c | 2 +- xen/common/page_alloc.c | 3 +++ xen/include/xen/bootfdt.h | 1 - xen/include/xen/mm.h | 2 ++ 9 files changed, 22 insertions(+), 10 deletions(-)xen/arch/arm/arm32/mmu/mm.c +2
-2@@ -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),xen/arch/arm/kernel.c +0
-0
xen/arch/arm/kernel.c static __init int kernel_decompress(struct bootmodule *mod, uint32_t offset) · line 250
Quoted 10 lines
xen/arch/arm/kernel.c +3
-3@@ -244,10 +244,11 @@ static __init int kernel_decompress(struct bootmodule *mod, uint32_t offset) size += offset;/* -* Free the original kernel, update the pointers to the -* decompressed kernel +* In case Xen is not using the static heap feature, free the original +* kernel, update the pointers to the decompressed kernel */ -fw_unreserved_regions (addr, addr + size, init_domheap_pages,0 ); +if ( !using_static_heap )
You should get out of this function even earlier, before calculating addr and size that are only used in fw_unreserved_regions.
Quoted 9 lines
xen/arch/arm/kernel.c +1
-0+fw_unreserved_regions (addr, addr + size, init_domheap_pages,0 );return 0 ; }xen/arch/arm/mmu/setup.c +0
-0
xen/arch/arm/mmu/setup.c void free_init_memory(void) · line 344
Quoted 6 lines
xen/arch/arm/mmu/setup.c +1
-2@@ -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 )
So here, you allow the init region mappings to be destroyed (above), yet ...
Quoted 13 lines
xen/arch/arm/mmu/setup.c +5
-0+ { +init_domheap_pages (pa, pa + len); +printk ("Freed %ldkB init memory.\n" , + (long )(__init_end-__init_begin) >>10 ); + } }/** xen/arch/arm/setup.c +0
-0
xen/arch/arm/setup.c void __init discard_initial_modules(void) · line 210
Quoted 5 lines
xen/arch/arm/setup.c +2
-0@@ -206,6 +206,9 @@ void __init discard_initial_modules(void)struct bootmodules *mi = &bootinfo.modules;int i; +if ( using_static_heap ) +return ;
... here you would get out without calling remove_early_mappings() that today destroys early FDT mappings. IMO you should allow to call remove_early_mappings().
With the remarks addressed:
~Michal