Introduce reserved heap
v2 cover Introduce reserved heap
The reserved heap, or statically configured heap, refers to parts of RAM reserved in the beginning for heap. Like the static memory allocation, such reserved heap regions are reserved by configuration in the device tree using physical address ranges.
This feature is useful to run Xen on Arm MPU systems, where only a finite number of memory protection regions are available. The limited number of protection regions places requirement on planning the use of MPU protection regions and one or more MPU protection regions needs to be reserved only for heap.
The first patch introduces the reserved heap and the device tree parsing code. The second patch enhances the error handling in processing the dts chosen node. The third patch adds the implementation of the reserved heap pages handling in boot and heap allocator for Arm. The fourth patch renames xenheap_* to directmap_* for better readablity.
Changes from v1 to v2:
- Rename the device tree property to xen,static-heap to avoid confusion.
- Change of commit msg and doc wording, correct typo in commit msg.
- Add an empty line in make_memory_node() memory type check to improve readability.
- Use enum membank_type to make the memory type cleaner.
- New commits for make process_chosen_node() return int and rename xenheap_* to directmap_*.
- Move the global bool reserved_heap to bootinfo.
- Replace the open open-coding address ~0 by INVALID_PADDR.
- Do not use reverted logic in heap_pages calculation.
- Remove unused Arm32 reserved_heap_start variable.
- Decouple the arm32 reserved heap too small size check with region end check.
- Reuse the arm32 original xenheap finding logic with the new helper to make sure xenheap on arm32 is contiguous.
Henry Wang (4):
docs, xen/arm: Introduce reserved heap memory xen/arm: bootfdt: Make process_chosen_node() return int xen/arm: Handle reserved heap pages in boot and heap allocator xen/arm: mm: Rename xenheap_* variable to directmap_*
docs/misc/arm/device-tree/booting.txt | 45 ++++++++ xen/arch/arm/bootfdt.c | 54 +++++++--- xen/arch/arm/domain_build.c | 8 +- xen/arch/arm/include/asm/config.h | 2 +- xen/arch/arm/include/asm/mm.h | 22 ++-- xen/arch/arm/include/asm/setup.h | 8 +- xen/arch/arm/mm.c | 24 ++--- xen/arch/arm/setup.c | 145 ++++++++++++++++++++------ 8 files changed, 238 insertions(+), 70 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/4 docs, xen/arm: Introduce reserved heap memory
This commit introduces the reserved heap memory, which is parts of RAM reserved in the beginning of the boot time for heap.
Firstly, since a new type of memory bank is needed for marking the memory bank solely as the heap, this commit defines enum membank_type and use this enum in function device_tree_get_meminfo(). Changes of code are done accordingly following the introduction of this enum.
Also, this commit introduces the logic to parse the reserved heap configuration in device tree by reusing the device tree entry definition of the static memory allocation feature. If the memory bank is reserved as heap through xen,static-heap property in device tree chosen node, the memory will be marked as heap type.
A documentation section is added, describing the definition of reserved heap memory and the method of enabling the reserved heap memory through device tree at boot time.
---
Changes from v1 to v2:
- Rename the device tree property to xen,static-heap to avoid confusion.
- Change of commit msg and doc wording, correct typo in commit msg.
- Do not change the process_chosen_node() return type.
- Add an empty line in make_memory_node() memory type check to improve readability.
- Use enum membank_type to make the memory type cleaner. Changes from RFC to v1:
- Rename the terminology to reserved heap.
--- docs/misc/arm/device-tree/booting.txt | 45 +++++++++++++++++++++++++++ xen/arch/arm/bootfdt.c | 31 +++++++++++++++--- xen/arch/arm/domain_build.c | 8 +++-- xen/arch/arm/include/asm/setup.h | 7 ++++- xen/arch/arm/setup.c | 2 +- 5 files changed, 84 insertions(+), 9 deletions(-)
docs/misc/arm/device-tree/booting.txt +45 -0
@@ -378,3 +378,48 @@ device-tree: This will reserve a 512MB region starting at the host physical address 0x30000000 to be exclusively used by DomU1. + + +Reserved Heap Memory +==================== + +The reserved heap memory (also known as the statically-configured heap) refers +to parts of RAM reserved in the beginning of boot time for heap. The memory is +reserved by configuration in the device tree using physical address ranges. + +The reserved heap memory declared in the device tree defines the memory areas +that will be reserved to be used exclusively as heap. + +- For Arm32, since there are seperated heaps, the reserved heap will be used +for both domheap and xenheap. +- For Arm64, since there is a single heap, the defined reserved heap areas +shall always go to the heap allocator. + +The reserved heap memory is an optional feature and can be enabled by adding +below device tree properties in the `chosen` node. + +The dtb should have the following properties: + +- xen,static-heap + + Property under the top-level "chosen" node. It specifies the address + and size of Xen reserved heap memory. + +- #xen,static-heap-address-cells and #xen,static-heap-size-cells + + Specify the number of cells used for the address and size of the + "xen,static-heap" property under "chosen". + +Below is an example on how to specify the reserved heap in device tree: + + / { + chosen { + #xen,static-heap-address-cells = <0x2>; + #xen,static-heap-size-cells = <0x2>; + xen,static-heap = <0x0 0x30000000 0x0 0x40000000>; + ... + }; + }; + +RAM starting from the host physical address 0x30000000 of 1GB size will +be reserved as heap.
xen/arch/arm/bootfdt.c +27 -4
@@ -64,7 +64,7 @@ void __init device_tree_get_reg(const __be32 **cell, u32 address_cells,static int __init device_tree_get_meminfo (const void *fdt,int node,const char *prop_name,u32 address_cells,u32 size_cells, -void *data,bool xen_domain) +void *data,membank_type type) {const struct fdt_property *prop;unsigned int i, banks;
@@ -95,7 +95,7 @@ static int __init device_tree_get_meminfo(const void *fdt, int node,continue ; mem->bank[mem->nr_banks].start = start; mem->bank[mem->nr_banks].size = size; - mem->bank[mem->nr_banks].xen_domain = xen_domain; + mem->bank[mem->nr_banks].type = type; mem->nr_banks++; }
@@ -185,7 +185,7 @@ static int __init process_memory_node(const void *fdt, int node, void *data) {return device_tree_get_meminfo (fdt, node,"reg" , address_cells, size_cells, - data, false); + data,MEMBANK_MEMORY ); } static int __init process_reserved_memory_node(const void *fdt, int node,
@@ -301,6 +301,28 @@ static void __init process_chosen_node(const void *fdt, int node,paddr_t start, end;int len; +if (fdt_get_property (fdt, node,"xen,static-heap" ,NULL ) ) + { +u32 address_cells =device_tree_get_u32 (fdt, node, +"#xen,static-heap-address-cells" ,0 ); +u32 size_cells =device_tree_get_u32 (fdt, node, +"#xen,static-heap-size-cells" ,0 ); + +printk ("Checking for reserved heap in /chosen\n" ); +if ( address_cells <1 || size_cells <1 ) + { +printk ("fdt: node `%s': invalid #xen,static-heap-address-cells or #xen,static-heap-size-cells\n" , + name); +return ; + } + +if (device_tree_get_meminfo (fdt, node,"xen,static-heap" , + address_cells, size_cells, + &bootinfo.reserved_mem, +MEMBANK_RSVD_HEAP ) ) +return ; + } +printk ("Checking for initrd in /chosen\n" ); prop =fdt_get_property (fdt, node,"linux,initrd-start" , &len);
@@ -358,7 +380,8 @@ static int __init process_domain_node(const void *fdt, int node, "#xen,static-mem-size-cells", 0);return device_tree_get_meminfo (fdt, node,"xen,static-mem" , address_cells, - size_cells, &bootinfo.reserved_mem, true); + size_cells, &bootinfo.reserved_mem, +MEMBANK_XEN_DOMAIN ); } static int __init early_scan_node(const void *fdt,
xen/arch/arm/domain_build.c +5 -3
@@ -1038,9 +1038,11 @@ static int __init make_memory_node(const struct domain *d,if ( mem->nr_banks ==0 )return -ENOENT ; -/* find first memory range not bound to a Xen domain */ -for ( i =0 ; i < mem->nr_banks && mem->bank[i].xen_domain; i++ ) +/* find first memory range not bound to a Xen domain nor heap */ +for ( i =0 ; i < mem->nr_banks && + (mem->bank[i].type !=MEMBANK_MEMORY ); i++ ) ; +if ( i == mem->nr_banks )return 0 ;
@@ -1062,7 +1064,7 @@ static int __init make_memory_node(const struct domain *d,u64 start = mem->bank[i].start;u64 size = mem->bank[i].size; -if ( mem->bank[i].xen_domain ) +if ( mem->bank[i].type ==MEMBANK_XEN_DOMAIN )continue ; dt_dprintk(" Bank %d: %#"PRIx64"->%#"PRIx64"\n",
xen/arch/arm/include/asm/setup.h +6 -1
@@ -22,11 +22,16 @@ typedef enum {BOOTMOD_UNKNOWN } bootmodule_kind; +typedef enum { +MEMBANK_MEMORY , +MEMBANK_XEN_DOMAIN ,/* whether the memory bank is bound to a Xen domain. */ +MEMBANK_RSVD_HEAP ,/* whether the memory bank is reserved as heap. */ +}membank_type ;struct membank {paddr_t start;paddr_t size; -bool xen_domain;/* whether the memory bank is bound to a Xen domain. */ +membank_type type; };struct meminfo {
xen/arch/arm/setup.c +1 -1
@@ -644,7 +644,7 @@ static void __init init_staticmem_pages(void)for ( bank =0 ; bank < bootinfo.reserved_mem.nr_banks; bank++ ) { -if ( bootinfo.reserved_mem.bank[bank].xen_domain ) +if ( bootinfo.reserved_mem.bank[bank].type ==MEMBANK_XEN_DOMAIN ) {mfn_t bank_start =_mfn (PFN_UP (bootinfo.reserved_mem.bank[bank].start));unsigned long bank_pages =PFN_DOWN (bootinfo.reserved_mem.bank[bank].size);
Signature · 1 line
2.17.1
Re: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memory
Hi Henry,
Quoted 6 lines · Henry Wang
xen/arch/arm/include/asm/setup.h +0
-0
xen/arch/arm/include/asm/setup.h typedef enum { · line 29
Quoted 8 lines
xen/arch/arm/include/asm/setup.h +5
-0@@ -22,11 +22,16 @@ typedef enum { BOOTMOD_UNKNOWN } bootmodule_kind; +typedef enum { +MEMBANK_MEMORY , +MEMBANK_XEN_DOMAIN ,/* whether the memory bank is bound to a Xen domain. */ +MEMBANK_RSVD_HEAP ,/* whether the memory bank is reserved as heap. */ +}membank_type ;
Whereas the patch itself looks ok (it must be modified anyway given the comments for patch #2), MEMBANK_XEN_DOMAIN name is quite ambiguous to me, now when it is part of membank_type enum. Something like MEMBANK_STATIC or MEMBANK_STATICMEM would be much cleaner in my opinion as it would directly indicate what type of memory we are talking about.
~Michal
RE: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memory
Hi Michal,
Quoted 8 lines
-----Original Message-----
From: Michal Orzel <[email protected]>xen/arch/arm/include/asm/setup.h typedef enum {
Quoted 3 lines
xen/arch/arm/include/asm/setup.h +3
-0+typedef enum { + MEMBANK_MEMORY, + MEMBANK_XEN_DOMAIN, /* whether the memory bank is bound to aXen domain. */
Quoted 1 line
+
MEMBANK_RSVD_HEAP, /* whether the memory bank is reserved asheap. */
Quoted 8 lines
Quoted 1 line
+}
membank_type;Whereas the patch itself looks ok (it must be modified anyway given the comments for patch #2),
MEMBANK_XEN_DOMAINname is quite ambiguous to me, now when it is part ofmembank_typeenum.
Something likeMEMBANK_STATICorMEMBANK_STATICMEMwould be much cleaner in my opinion
as it would directly indicate what type of memory we are talking about.
Thanks for the suggestion. I am pretty bad in naming things so in this patch I simply reused the original name for static memory banks.
I prefer MEMBANK_STATICMEM and will change in v3. I will check the 80 char limit in current code, if STATICMEM does not fit, I will go STATIC.
Kind regards,
Henry
Quoted 2 lines
~Michal
Re: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memory
In reply to Michal OrzelHi Michal,
Quoted 10 lines · Michal Orzel
Quoted 9 lines · Henry Wang
xen/arch/arm/include/asm/setup.h +0
-0@@ -22,11 +22,16 @@ typedef enum { BOOTMOD_UNKNOWN } bootmodule_kind;
Quoted 9 lines
xen/arch/arm/include/asm/setup.h typedef enum { · line 29
Quoted 5 lines
xen/arch/arm/include/asm/setup.h +5
-0+typedef enum { +MEMBANK_MEMORY , +MEMBANK_XEN_DOMAIN ,/* whether the memory bank is bound to a Xen domain. */ +MEMBANK_RSVD_HEAP ,/* whether the memory bank is reserved as heap. */ +}membank_type ;Whereas the patch itself looks ok (it must be modified anyway given the comments for patch #2),
MEMBANK_XEN_DOMAINname is quite ambiguous to me, now when it is part ofmembank_typeenum. Something likeMEMBANK_STATICorMEMBANK_STATICMEMwould be much cleaner in my opinion as it would directly indicate what type of memory we are talking about.
I am not sure. Technically the reserved heap is static memory that has been allocated for the heap. In fact, I think thn name "staticmem" is now becoming quite confusing because we are referring to a very specific use case (i.e. memory that has been reserved for domain use).
So I would prefer if we keep "domain" in the name. Maybe MEMBANK_STATIC_DOMAIN or MEMBANK_RESERVED_DOMAIN.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memory
Hi Julien,
Quoted 24 lines · Julien Grall
Hi Michal,
Quoted 10 lines · Michal Orzel
Quoted 9 lines · Henry Wang
xen/arch/arm/include/asm/setup.h +0
-0@@ -22,11 +22,16 @@ typedef enum { BOOTMOD_UNKNOWN } bootmodule_kind;Quoted 9 lines
xen/arch/arm/include/asm/setup.h typedef enum { · line 29
Quoted 5 lines
xen/arch/arm/include/asm/setup.h +5
-0+typedef enum { +MEMBANK_MEMORY , +MEMBANK_XEN_DOMAIN ,/* whether the memory bank is bound to a Xen domain. */ +MEMBANK_RSVD_HEAP ,/* whether the memory bank is reserved as heap. */ +}membank_type ;Whereas the patch itself looks ok (it must be modified anyway given the comments for patch #2),
MEMBANK_XEN_DOMAINname is quite ambiguous to me, now when it is part ofmembank_typeenum. Something likeMEMBANK_STATICorMEMBANK_STATICMEMwould be much cleaner in my opinion as it would directly indicate what type of memory we are talking about.
Quoted 8 lines
I am not sure. Technically the reserved heap is static memory that has been allocated for the heap. In fact, I think thn name "staticmem" is now becoming quite confusing because we are referring to a very specific use case (i.e. memory that has been reserved for domain use).
So I would prefer if we keep "domain" in the name. Maybe
MEMBANK_STATIC_DOMAINorMEMBANK_RESERVED_DOMAIN.
Personally I would drop completely using the "reserved heap" naming in favor
of "static heap" because "staticmem" is also something we reserve at boot time for a domain use. This would also directly correlate to the device tree property "static-heap" and "static-mem". Then such enum would be created as follows and for me this is the cleanest solution:MEMBANK_DEFAULTMEMBANK_STATIC_DOMAINMEMBANK_STATIC_HEAP
But I think we are already too late in this series to request such changes, so with the current naming we can go for:MEMBANK_DEFAULTMEMBANK_RSVD_DOMAIN /* memory reserved for a domain use */MEMBANK_RSVD_HEAP /* memory reserved for a heap use */
Quoted 4 lines
Cheers,
--
Julien Grall
~Michal
RE: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memory
Hi Michal,
Quoted 57 lines
-----Original Message-----
From: Michal Orzel <[email protected]>
Subject: Re: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memoryHi Julien,
Quoted 7 lines · Julien Grall
Hi Michal,
Quoted 3 lines · Michal Orzel
Review
Quoted 2 lines · Henry Wang
(quoted diff) +0
-0
b/xen/arch/arm/include/asm/setup.hQuoted 10 lines
Quoted 10 lines
xen/arch/arm/include/asm/setup.h typedef enum { · line 27
Quoted 10 lines
index
5815ccf8c5..d0cc556833100644xen/arch/arm/include/asm/setup.h +3
-0@@ -22,11 +22,16 @@ typedef enum {BOOTMOD_UNKNOWN } bootmodule_kind; +typedef enum { + MEMBANK_MEMORY, + MEMBANK_XEN_DOMAIN, /* whether the memory bank is bound toa Xen domain. */
Quoted 1 line
Quoted 1 line
xen/arch/arm/include/asm/setup.h typedef enum { · line 28
Quoted 1 line
xen/arch/arm/include/asm/setup.h +1
-0+ MEMBANK_RSVD_HEAP, /* whether the memory bank is reserved asheap. */
Quoted 2 lines
Quoted 2 lines
xen/arch/arm/include/asm/setup.h typedef enum { · line 29
Quoted 1 line
xen/arch/arm/include/asm/setup.h +1
-0+} membank_type;Whereas the patch itself looks ok (it must be modified anyway given the
comments for patch #2),
Quoted 1 line
Quoted 1 line
MEMBANK_XEN_DOMAINname is quite ambiguous to me, now when it ispart of
membank_typeenum.Quoted 1 line
Quoted 1 line
Something like
MEMBANK_STATICorMEMBANK_STATICMEMwould bemuch cleaner in my opinion
Quoted 10 lines
Quoted 1 line
as it would directly indicate what type of memory we are talking about.
I am not sure. Technically the reserved heap is static memory that has been allocated for the heap. In fact, I think thn name "staticmem" is now becoming quite confusing because we are referring to a very specific use case (i.e. memory that has been reserved for domain use).
So I would prefer if we keep "domain" in the name. Maybe
MEMBANK_STATIC_DOMAINorMEMBANK_RESERVED_DOMAIN.Personally I would drop completely using the "reserved heap" naming in favor
of "static heap" because "staticmem" is also something we reserve at boot time for a domain use.
This would also directly correlate to the device tree property "static-heap" and "static-mem".
Then such enum would be created as follows and for me this is the cleanest solution:MEMBANK_DEFAULTMEMBANK_STATIC_DOMAINMEMBANK_STATIC_HEAP
Quoted 1 line
But I think we are already too late in this series to request such changes,
I am ok with a pure renaming to static heap if Julien is ok with that. I think Julien has done most of the code review and we still have 2~3 days for it.
Kind regards,
Henry
Quoted 11 lines
So with the current naming we can go for:
MEMBANK_DEFAULTMEMBANK_RSVD_DOMAIN/* memory reserved for a domain use */MEMBANK_RSVD_HEAP/* memory reserved for a heap use */Quoted 4 lines
Cheers,
--
Julien Grall~Michal
Re: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memory
Hi Henry and Michal,
Quoted 57 lines · Henry Wang
Quoted 57 lines
-----Original Message-----
From: Michal Orzel <[email protected]>
Subject: Re: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memoryHi Julien,
Quoted 7 lines · Julien Grall
Hi Michal,
Quoted 3 lines · Michal Orzel
Review
Quoted 2 lines · Henry Wang
(quoted diff) +0
-0
b/xen/arch/arm/include/asm/setup.hQuoted 10 lines
Quoted 10 lines
xen/arch/arm/include/asm/setup.h typedef enum { · line 27
Quoted 10 lines
index
5815ccf8c5..d0cc556833100644xen/arch/arm/include/asm/setup.h +3
-0@@ -22,11 +22,16 @@ typedef enum {BOOTMOD_UNKNOWN } bootmodule_kind; +typedef enum { + MEMBANK_MEMORY, + MEMBANK_XEN_DOMAIN, /* whether the memory bank is bound toa Xen domain. */
Quoted 1 line
Quoted 1 line
xen/arch/arm/include/asm/setup.h typedef enum { · line 28
Quoted 1 line
xen/arch/arm/include/asm/setup.h +1
-0+ MEMBANK_RSVD_HEAP, /* whether the memory bank is reserved asheap. */
Quoted 2 lines
Quoted 2 lines
xen/arch/arm/include/asm/setup.h typedef enum { · line 29
Quoted 1 line
xen/arch/arm/include/asm/setup.h +1
-0+} membank_type;Whereas the patch itself looks ok (it must be modified anyway given the
comments for patch #2),
Quoted 1 line
Quoted 1 line
MEMBANK_XEN_DOMAINname is quite ambiguous to me, now when it ispart of
membank_typeenum.Quoted 1 line
Quoted 1 line
Something like
MEMBANK_STATICorMEMBANK_STATICMEMwould bemuch cleaner in my opinion
Quoted 10 lines
Quoted 1 line
as it would directly indicate what type of memory we are talking about.
I am not sure. Technically the reserved heap is static memory that has been allocated for the heap. In fact, I think thn name "staticmem" is now becoming quite confusing because we are referring to a very specific use case (i.e. memory that has been reserved for domain use).
So I would prefer if we keep "domain" in the name. Maybe
MEMBANK_STATIC_DOMAINorMEMBANK_RESERVED_DOMAIN.Personally I would drop completely using the "reserved heap" naming in favor
of "static heap" because "staticmem" is also something we reserve at boot time for a domain use.
This would also directly correlate to the device tree property "static-heap" and "static-mem".
Then such enum would be created as follows and for me this is the cleanest solution:MEMBANK_DEFAULTMEMBANK_STATIC_DOMAINMEMBANK_STATIC_HEAP
Quoted 1 line
Quoted 1 line
But I think we are already too late in this series to request such changes,
The naming was introduced in this version. So I would not view this as a late request.
Quoted 3 lines
I am ok with a pure renaming to static heap if Julien is ok with that. I think Julien has done most of the code review and we still have 2~3 days for it.
I am fine with the version proposed by Michal. I.e.:
MEMBANK_DEFAULTMEMBANK_STATIC_DOMAINMEMBANK_STATIC_HEAP
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memory
In reply to Henry WangHi Henry,
Quoted 5 lines · Henry Wang
This commit introduces the reserved heap memory, which is parts of RAM reserved in the beginning of the boot time for heap.
Firstly, since a new type of memory bank is needed for marking the memory bank solely as the heap, this commit defines
enum membank_type
The wording is a bit confusing. I read this as the code will use "enum membank_type" but this is not possible as your enum is anonymous.
My suggestion would be to avoid creating a typedef (see below).
Quoted 44 lines
and use this enum in function
device_tree_get_meminfo(). Changes of code are done accordingly following the introduction of this enum.Also, this commit introduces the logic to parse the reserved heap configuration in device tree by reusing the device tree entry definition of the static memory allocation feature. If the memory bank is reserved as heap through
xen,static-heapproperty in device treechosennode, the memory will be marked as heap type.A documentation section is added, describing the definition of reserved heap memory and the method of enabling the reserved heap memory through device tree at boot time.
Signed-off-by Henry Wang <[email protected]>Signed-off-by Penny Zheng <[email protected]>---
Changes from v1 to v2:
- Rename the device tree property to xen,static-heap to avoid confusion.
- Change of commit msg and doc wording, correct typo in commit msg.
- Do not change theprocess_chosen_node()return type.
- Add an empty line inmake_memory_node()memory type check to improve readability.
- Use enummembank_typeto make the memory type cleaner. Changes from RFC to v1:
- Rename the terminology to reserved heap.--- docs/misc/arm/device-tree/booting.txt | 45 +++++++++++++++++++++++++++ xen/arch/arm/bootfdt.c | 31 +++++++++++++++--- xen/arch/arm/domain_build.c | 8 +++-- xen/arch/arm/include/asm/setup.h | 7 ++++- xen/arch/arm/setup.c | 2 +- 5 files changed, 84 insertions(+), 9 deletions(-)docs/misc/arm/device-tree/booting.txt +3
-0@@ -378,3 +378,48 @@ device-tree: This will reserve a 512MB region starting at the host physical address 0x30000000 to be exclusively used by DomU1. + + +Reserved Heap Memory
docs/misc/arm/device-tree/booting.txt device-tree: · line 393
Quoted 10 lines
docs/misc/arm/device-tree/booting.txt +10
-0+==================== + +The reserved heap memory (also known as the statically-configured heap) refers +to parts of RAM reserved in the beginning of boot time for heap. The memory is +reserved by configuration in the device tree using physical address ranges. + +The reserved heap memory declared in the device tree defines the memory areas +that will be reserved to be used exclusively as heap. + +- For Arm32, since there are seperated heaps, the reserved heap will be used
type: s/seperated/separated/
Quoted 134 lines
docs/misc/arm/device-tree/booting.txt +32
-0+for both domheap and xenheap. +- For Arm64, since there is a single heap, the defined reserved heap areas +shall always go to the heap allocator. + +The reserved heap memory is an optional feature and can be enabled by adding +below device tree properties in the `chosen` node. + +The dtb should have the following properties: + +- xen,static-heap + + Property under the top-level "chosen" node. It specifies the address + and size of Xen reserved heap memory. + +- #xen,static-heap-address-cells and #xen,static-heap-size-cells + + Specify the number of cells used for the address and size of the + "xen,static-heap" property under "chosen". + +Below is an example on how to specify the reserved heap in device tree: + + / { + chosen { + #xen,static-heap-address-cells = <0x2>; + #xen,static-heap-size-cells = <0x2>; + xen,static-heap = <0x0 0x30000000 0x0 0x40000000>; + ... + }; + }; + +RAM starting from the host physical address 0x30000000 of 1GB size will +be reserved as heap.xen/arch/arm/bootfdt.c +27
-4@@ -64,7 +64,7 @@ void __init device_tree_get_reg(const __be32 **cell, u32 address_cells,static int __init device_tree_get_meminfo (const void *fdt,int node,const char *prop_name,u32 address_cells,u32 size_cells, -void *data,bool xen_domain) +void *data,membank_type type) {const struct fdt_property *prop;unsigned int i, banks;@@ -95,7 +95,7 @@ static int __init device_tree_get_meminfo(const void *fdt, int node,continue ; mem->bank[mem->nr_banks].start = start; mem->bank[mem->nr_banks].size = size; - mem->bank[mem->nr_banks].xen_domain = xen_domain; + mem->bank[mem->nr_banks].type = type; mem->nr_banks++; }@@ -185,7 +185,7 @@ static int __init process_memory_node(const void *fdt, int node, void *data) {return device_tree_get_meminfo (fdt, node,"reg" , address_cells, size_cells, - data, false); + data,MEMBANK_MEMORY ); } static int __init process_reserved_memory_node(const void *fdt, int node,@@ -301,6 +301,28 @@ static void __init process_chosen_node(const void *fdt, int node,paddr_t start, end;int len; +if (fdt_get_property (fdt, node,"xen,static-heap" ,NULL ) ) + { +u32 address_cells =device_tree_get_u32 (fdt, node, +"#xen,static-heap-address-cells" ,0 ); +u32 size_cells =device_tree_get_u32 (fdt, node, +"#xen,static-heap-size-cells" ,0 ); + +printk ("Checking for reserved heap in /chosen\n" ); +if ( address_cells <1 || size_cells <1 ) + { +printk ("fdt: node `%s': invalid #xen,static-heap-address-cells or #xen,static-heap-size-cells\n" , + name); +return ; + } + +if (device_tree_get_meminfo (fdt, node,"xen,static-heap" , + address_cells, size_cells, + &bootinfo.reserved_mem, +MEMBANK_RSVD_HEAP ) ) +return ; + } +printk ("Checking for initrd in /chosen\n" ); prop =fdt_get_property (fdt, node,"linux,initrd-start" , &len);@@ -358,7 +380,8 @@ static int __init process_domain_node(const void *fdt, int node, "#xen,static-mem-size-cells", 0);return device_tree_get_meminfo (fdt, node,"xen,static-mem" , address_cells, - size_cells, &bootinfo.reserved_mem, true); + size_cells, &bootinfo.reserved_mem, +MEMBANK_XEN_DOMAIN ); } static int __init early_scan_node(const void *fdt,xen/arch/arm/domain_build.c +5
-3@@ -1038,9 +1038,11 @@ static int __init make_memory_node(const struct domain *d,if ( mem->nr_banks ==0 )return -ENOENT ; -/* find first memory range not bound to a Xen domain */ -for ( i =0 ; i < mem->nr_banks && mem->bank[i].xen_domain; i++ ) +/* find first memory range not bound to a Xen domain nor heap */ +for ( i =0 ; i < mem->nr_banks && + (mem->bank[i].type !=MEMBANK_MEMORY ); i++ ) ; +if ( i == mem->nr_banks )return 0 ;@@ -1062,7 +1064,7 @@ static int __init make_memory_node(const struct domain *d,u64 start = mem->bank[i].start;u64 size = mem->bank[i].size; -if ( mem->bank[i].xen_domain ) +if ( mem->bank[i].type ==MEMBANK_XEN_DOMAIN )continue ; dt_dprintk(" Bank %d: %#"PRIx64"->%#"PRIx64"\n",xen/arch/arm/include/asm/setup.h +0
-0
xen/arch/arm/include/asm/setup.h typedef enum { · line 26
Quoted 5 lines
xen/arch/arm/include/asm/setup.h +2
-0@@ -22,11 +22,16 @@ typedef enum {BOOTMOD_UNKNOWN } bootmodule_kind; +typedef enum { + MEMBANK_MEMORY,
Technically everything is memory :). I think here you are referring to either:
- Reserved memory for the device (or firmware)
- Any memory that will be used by the allocator.
I would consider to name the field MEMBANK_UNKNOWN or MEMBANK_DEFAULT with a comment explaining the meaning depends where it used (we have several arrays using struct membank).
xen/arch/arm/include/asm/setup.h typedef enum { · line 28
Quoted 2 lines
xen/arch/arm/include/asm/setup.h +2
-0+MEMBANK_XEN_DOMAIN ,/* whether the memory bank is bound to a Xen domain. */ + MEMBANK_RSVD_HEAP, /* whether the memory bank is reserved as heap. */
I would clarify the two values are only valid when the bank in in reserved_mem.
xen/arch/arm/include/asm/setup.h typedef enum { · line 29
Quoted 1 line
xen/arch/arm/include/asm/setup.h +1
-0+} membank_type;
I would prefer if if we don't define any typedef for this enum. But if you want to keep it, then please suffix with _t.
Quoted 14 lines
xen/arch/arm/include/asm/setup.h +1
-1struct membank {paddr_t start;paddr_t size; -bool xen_domain;/* whether the memory bank is bound to a Xen domain. */ +membank_type type; };struct meminfo {xen/arch/arm/setup.c +0
-0
xen/arch/arm/setup.c static void __init init_staticmem_pages(void) · line 650
Quoted 8 lines
xen/arch/arm/setup.c +1
-1@@ -644,7 +644,7 @@ static void __init init_staticmem_pages(void)for ( bank =0 ; bank < bootinfo.reserved_mem.nr_banks; bank++ ) { -if ( bootinfo.reserved_mem.bank[bank].xen_domain ) +if ( bootinfo.reserved_mem.bank[bank].type ==MEMBANK_XEN_DOMAIN ) {mfn_t bank_start =_mfn (PFN_UP (bootinfo.reserved_mem.bank[bank].start));unsigned long bank_pages =PFN_DOWN (bootinfo.reserved_mem.bank[bank].size);
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memory
Hi Julien,
Quoted 10 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Subject: Re: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memoryHi Henry,
Quoted 3 lines · Henry Wang
This commit introduces the reserved heap memory, which is parts of RAM reserved in the beginning of the boot time for heap.
Quoted 8 lines
Quoted 2 lines
Firstly, since a new type of memory bank is needed for marking the memory bank solely as the heap, this commit defines `enum
membank_type`
The wording is a bit confusing. I read this as the code will use "enum
membank_type" but this is not possible as your enum is anonymous.My suggestion would be to avoid creating a typedef (see below).
Yeah I think you are correct. The typedef is not really necessary.
Quoted 5 lines
Quoted 2 lines
+- For Arm32, since there are seperated heaps, the reserved heap will be
used
type: s/seperated/separated/
Oops, sorry again..
Quoted 9 lines
xen/arch/arm/include/asm/setup.h typedef enum { · line 26
Quoted 3 lines
xen/arch/arm/include/asm/setup.h +2
-0+typedef enum { + MEMBANK_MEMORY,Technically everything is memory :). I think here you are referring to either:
- Reserved memory for the device (or firmware)
- Any memory that will be used by the allocator.
Quoted 4 lines
I would consider to name the field
MEMBANK_UNKNOWNorMEMBANK_DEFAULT
with a comment explaining the meaning depends where it used (we have several arrays using struct membank).
MEMBANK_DEFAULT sounds good, and I will add the comment.
Quoted 7 lines
Quoted 2 lines
+
MEMBANK_XEN_DOMAIN, /* whether the memory bank is bound to aXen domain. */
Quoted 1 line
+
MEMBANK_RSVD_HEAP, /* whether the memory bank is reserved asheap. */
I would clarify the two values are only valid when the bank in inreserved_mem.
Good point, will do.
Quoted 5 lines
Quoted 2 lines
+}
membank_type;I would prefer if if we don't define any typedef for this enum. But if you want to keep it, then please suffix with _t.
No I think you are correct, a enum membank_type instead of a typedef would be enough here.
Kind regards,
Henry
Quoted 32 lines
Quoted 6 lines
struct membank { paddr_t start; paddr_t size;- bool
xen_domain; /* whether the memory bank is bound to a Xendomain. */
Quoted 9 lines
xen/arch/arm/include/asm/setup.h +1
-0+membank_type type; };struct meminfo {xen/arch/arm/setup.c +0
-0xen/arch/arm/setup.c static void __init init_staticmem_pages(void) · line 647
Quoted 5 lines
xen/arch/arm/setup.c +1
-1@@ -644,7 +644,7 @@ static void __init init_staticmem_pages(void)for ( bank =0 ; bank < bootinfo.reserved_mem.nr_banks; bank++ ) { -if ( bootinfo.reserved_mem.bank[bank].xen_domain ) + if ( bootinfo.reserved_mem.bank[bank].type ==
MEMBANK_XEN_DOMAIN)xen/arch/arm/setup.c static void __init init_staticmem_pages(void) · line 649
Quoted 2 lines
xen/arch/arm/setup.c +0
-0{ mfn_t bank_start =_mfn(PFN_UP(bootinfo.reserved_mem.bank[bank].start));
xen/arch/arm/setup.c static void __init init_staticmem_pages(void) · line 650
Quoted 1 line
xen/arch/arm/setup.c +0
-0unsigned long bank_pages =
PFN_DOWN(bootinfo.reserved_mem.bank[bank].size);Cheers,
--
Julien Grall
Re: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memory
In reply to Henry WangQuoted 14 lines · Henry Wang
This commit introduces the reserved heap memory, which is parts of RAM reserved in the beginning of the boot time for heap.
Firstly, since a new type of memory bank is needed for marking the memory bank solely as the heap, this commit defines
enum membank_typeand use this enum in functiondevice_tree_get_meminfo(). Changes of code are done accordingly following the introduction of this enum.Also, this commit introduces the logic to parse the reserved heap configuration in device tree by reusing the device tree entry definition of the static memory allocation feature. If the memory bank is reserved as heap through
xen,static-heapproperty in device treechosennode, the memory will be marked as heap type.
Quoted 6 lines
A documentation section is added, describing the definition of reserved heap memory and the method of enabling the reserved heap memory through device tree at boot time.
Signed-off-by Henry Wang <[email protected]>Signed-off-by Penny Zheng <[email protected]>
I think the device tree interface is good and you can consider it acked by me. I'll let you follow up on the other comments by others on the code changes.
Quoted 206 lines
---
Changes from v1 to v2:
- Rename the device tree property to xen,static-heap to avoid confusion.
- Change of commit msg and doc wording, correct typo in commit msg.
- Do not change theprocess_chosen_node()return type.
- Add an empty line inmake_memory_node()memory type check to improve readability.
- Use enummembank_typeto make the memory type cleaner. Changes from RFC to v1:
- Rename the terminology to reserved heap.--- docs/misc/arm/device-tree/booting.txt | 45 +++++++++++++++++++++++++++ xen/arch/arm/bootfdt.c | 31 +++++++++++++++--- xen/arch/arm/domain_build.c | 8 +++-- xen/arch/arm/include/asm/setup.h | 7 ++++- xen/arch/arm/setup.c | 2 +- 5 files changed, 84 insertions(+), 9 deletions(-)docs/misc/arm/device-tree/booting.txt +45
-0@@ -378,3 +378,48 @@ device-tree: This will reserve a 512MB region starting at the host physical address 0x30000000 to be exclusively used by DomU1. + + +Reserved Heap Memory +==================== + +The reserved heap memory (also known as the statically-configured heap) refers +to parts of RAM reserved in the beginning of boot time for heap. The memory is +reserved by configuration in the device tree using physical address ranges. + +The reserved heap memory declared in the device tree defines the memory areas +that will be reserved to be used exclusively as heap. + +- For Arm32, since there are seperated heaps, the reserved heap will be used +for both domheap and xenheap. +- For Arm64, since there is a single heap, the defined reserved heap areas +shall always go to the heap allocator. + +The reserved heap memory is an optional feature and can be enabled by adding +below device tree properties in the `chosen` node. + +The dtb should have the following properties: + +- xen,static-heap + + Property under the top-level "chosen" node. It specifies the address + and size of Xen reserved heap memory. + +- #xen,static-heap-address-cells and #xen,static-heap-size-cells + + Specify the number of cells used for the address and size of the + "xen,static-heap" property under "chosen". + +Below is an example on how to specify the reserved heap in device tree: + + / { + chosen { + #xen,static-heap-address-cells = <0x2>; + #xen,static-heap-size-cells = <0x2>; + xen,static-heap = <0x0 0x30000000 0x0 0x40000000>; + ... + }; + }; + +RAM starting from the host physical address 0x30000000 of 1GB size will +be reserved as heap.xen/arch/arm/bootfdt.c +27
-4@@ -64,7 +64,7 @@ void __init device_tree_get_reg(const __be32 **cell, u32 address_cells,static int __init device_tree_get_meminfo (const void *fdt,int node,const char *prop_name,u32 address_cells,u32 size_cells, -void *data,bool xen_domain) +void *data,membank_type type) {const struct fdt_property *prop;unsigned int i, banks;@@ -95,7 +95,7 @@ static int __init device_tree_get_meminfo(const void *fdt, int node,continue ; mem->bank[mem->nr_banks].start = start; mem->bank[mem->nr_banks].size = size; - mem->bank[mem->nr_banks].xen_domain = xen_domain; + mem->bank[mem->nr_banks].type = type; mem->nr_banks++; }@@ -185,7 +185,7 @@ static int __init process_memory_node(const void *fdt, int node, void *data) {return device_tree_get_meminfo (fdt, node,"reg" , address_cells, size_cells, - data, false); + data,MEMBANK_MEMORY ); } static int __init process_reserved_memory_node(const void *fdt, int node,@@ -301,6 +301,28 @@ static void __init process_chosen_node(const void *fdt, int node,paddr_t start, end;int len; +if (fdt_get_property (fdt, node,"xen,static-heap" ,NULL ) ) + { +u32 address_cells =device_tree_get_u32 (fdt, node, +"#xen,static-heap-address-cells" ,0 ); +u32 size_cells =device_tree_get_u32 (fdt, node, +"#xen,static-heap-size-cells" ,0 ); + +printk ("Checking for reserved heap in /chosen\n" ); +if ( address_cells <1 || size_cells <1 ) + { +printk ("fdt: node `%s': invalid #xen,static-heap-address-cells or #xen,static-heap-size-cells\n" , + name); +return ; + } + +if (device_tree_get_meminfo (fdt, node,"xen,static-heap" , + address_cells, size_cells, + &bootinfo.reserved_mem, +MEMBANK_RSVD_HEAP ) ) +return ; + } +printk ("Checking for initrd in /chosen\n" ); prop =fdt_get_property (fdt, node,"linux,initrd-start" , &len);@@ -358,7 +380,8 @@ static int __init process_domain_node(const void *fdt, int node, "#xen,static-mem-size-cells", 0);return device_tree_get_meminfo (fdt, node,"xen,static-mem" , address_cells, - size_cells, &bootinfo.reserved_mem, true); + size_cells, &bootinfo.reserved_mem, +MEMBANK_XEN_DOMAIN ); } static int __init early_scan_node(const void *fdt,xen/arch/arm/domain_build.c +5
-3@@ -1038,9 +1038,11 @@ static int __init make_memory_node(const struct domain *d,if ( mem->nr_banks ==0 )return -ENOENT ; -/* find first memory range not bound to a Xen domain */ -for ( i =0 ; i < mem->nr_banks && mem->bank[i].xen_domain; i++ ) +/* find first memory range not bound to a Xen domain nor heap */ +for ( i =0 ; i < mem->nr_banks && + (mem->bank[i].type !=MEMBANK_MEMORY ); i++ ) ; +if ( i == mem->nr_banks )return 0 ;@@ -1062,7 +1064,7 @@ static int __init make_memory_node(const struct domain *d,u64 start = mem->bank[i].start;u64 size = mem->bank[i].size; -if ( mem->bank[i].xen_domain ) +if ( mem->bank[i].type ==MEMBANK_XEN_DOMAIN )continue ; dt_dprintk(" Bank %d: %#"PRIx64"->%#"PRIx64"\n",xen/arch/arm/include/asm/setup.h +6
-1@@ -22,11 +22,16 @@ typedef enum {BOOTMOD_UNKNOWN } bootmodule_kind; +typedef enum { +MEMBANK_MEMORY , +MEMBANK_XEN_DOMAIN ,/* whether the memory bank is bound to a Xen domain. */ +MEMBANK_RSVD_HEAP ,/* whether the memory bank is reserved as heap. */ +}membank_type ;struct membank {paddr_t start;paddr_t size; -bool xen_domain;/* whether the memory bank is bound to a Xen domain. */ +membank_type type; };struct meminfo {xen/arch/arm/setup.c +1
-1@@ -644,7 +644,7 @@ static void __init init_staticmem_pages(void)for ( bank =0 ; bank < bootinfo.reserved_mem.nr_banks; bank++ ) { -if ( bootinfo.reserved_mem.bank[bank].xen_domain ) +if ( bootinfo.reserved_mem.bank[bank].type ==MEMBANK_XEN_DOMAIN ) {mfn_t bank_start =_mfn (PFN_UP (bootinfo.reserved_mem.bank[bank].start));unsigned long bank_pages =PFN_DOWN (bootinfo.reserved_mem.bank[bank].size);Signature · 1 line
2.17.1
RE: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memory
Hi Stefano,
Quoted 23 lines
-----Original Message-----
From: Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v2 1/4] docs, xen/arm: Introduce reserved heap memoryQuoted 5 lines · Henry Wang
This commit introduces the reserved heap memory, which is parts of RAM reserved in the beginning of the boot time for heap.
Firstly, since a new type of memory bank is needed for marking the memory bank solely as the heap, this commit defines `enum
membank_type`
Quoted 11 lines
and use this enum in function
device_tree_get_meminfo(). Changes of code are done accordingly following the introduction of this enum.Also, this commit introduces the logic to parse the reserved heap configuration in device tree by reusing the device tree entry definition of the static memory allocation feature. If the memory bank is reserved as heap through
xen,static-heapproperty in device treechosennode, the memory will be marked as heap type.A documentation section is added, describing the definition of reserved heap memory and the method of enabling the reserved heap memory
through
Quoted 8 lines
Quoted 4 lines
device tree at boot time.
Signed-off-by Henry Wang <[email protected]>Signed-off-by Penny Zheng <[email protected]>I think the device tree interface is good and you can consider it acked by me. I'll let you follow up on the other comments by others on the code changes.
Thanks, I will fix the comments from Michal and Julien.
Kind regards,
Henry
PATCH v2 2/4 xen/arm: bootfdt: Make process_chosen_node() return int
In reply to Henry WangAt the boot time, it is saner to stop booting early if an error occurs when parsing the device tree chosen node, rather than seeing random behavior afterwards. Therefore, this commit changes the return type of the process_chosen_node() from void to int, and return correct errno based on the error type.
---
Changes from v1 to v2:
- New commit.
--- xen/arch/arm/bootfdt.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-)
xen/arch/arm/bootfdt.c +17 -14
@@ -293,9 +293,9 @@ static void __init process_multiboot_node(const void *fdt, int node, kind, start, domU); } -static void __init process_chosen_node (const void *fdt,int node, -const char *name, -u32 address_cells,u32 size_cells) +static int __init process_chosen_node (const void *fdt,int node, +const char *name, +u32 address_cells,u32 size_cells) {const struct fdt_property *prop;paddr_t start, end;
@@ -303,6 +303,7 @@ static void __init process_chosen_node(const void *fdt, int node,if (fdt_get_property (fdt, node,"xen,static-heap" ,NULL ) ) { +int rc;u32 address_cells =device_tree_get_u32 (fdt, node,"#xen,static-heap-address-cells" ,0 ); u32 size_cells = device_tree_get_u32(fdt, node,
@@ -313,14 +314,14 @@ static void __init process_chosen_node(const void *fdt, int node, {printk ("fdt: node `%s': invalid #xen,static-heap-address-cells or #xen,static-heap-size-cells\n" , name); -return ; +return -EINVAL ; } -if (device_tree_get_meminfo (fdt, node,"xen,static-heap" , + rc =device_tree_get_meminfo (fdt, node,"xen,static-heap" , address_cells, size_cells, - &bootinfo.reserved_mem, -MEMBANK_RSVD_HEAP ) ) -return ; + &bootinfo.reserved_mem,MEMBANK_RSVD_HEAP ); +if ( rc ) +return rc; }printk ("Checking for initrd in /chosen\n" );
@@ -328,11 +329,11 @@ static void __init process_chosen_node(const void *fdt, int node, prop =fdt_get_property (fdt, node,"linux,initrd-start" , &len);if ( !prop )/* No initrd present. */ -return ; +return 0 ;if ( len !=sizeof (u32) && len !=sizeof (u64) ) {printk ("linux,initrd-start property has invalid length %d\n" , len); -return ; +return -EINVAL ; } start =dt_read_number ((void *)&prop->data,dt_size_to_cells (len));
@@ -340,12 +341,12 @@ static void __init process_chosen_node(const void *fdt, int node,if ( !prop ) {printk ("linux,initrd-end not present but -start was\n" ); -return ; +return -EINVAL ; }if ( len !=sizeof (u32) && len !=sizeof (u64) ) {printk ("linux,initrd-end property has invalid length %d\n" , len); -return ; +return -EINVAL ; } end =dt_read_number ((void *)&prop->data,dt_size_to_cells (len));
@@ -353,12 +354,14 @@ static void __init process_chosen_node(const void *fdt, int node, {printk ("linux,initrd limits invalid: %" PRIpaddr" >= %" PRIpaddr"\n" , start, end); -return ; +return -EINVAL ; }printk ("Initrd %" PRIpaddr"-%" PRIpaddr"\n" , start, end);add_boot_module (BOOTMOD_RAMDISK , start, end-start, false); + +return 0 ; } static int __init process_domain_node(const void *fdt, int node,
@@ -406,7 +409,7 @@ static int __init early_scan_node(const void *fdt, device_tree_node_compatible(fdt, node, "multiboot,module" )))process_multiboot_node (fdt, node, name, address_cells, size_cells); else if ( depth == 1 && device_tree_node_matches(fdt, node, "chosen") ) - process_chosen_node(fdt, node, name, address_cells, size_cells); + rc =process_chosen_node (fdt, node, name, address_cells, size_cells); else if ( depth == 2 && device_tree_node_compatible(fdt, node, "xen,domain") ) rc =process_domain_node (fdt, node, name, address_cells, size_cells);
Signature · 1 line
2.17.1
Re: [PATCH v2 2/4] xen/arm: bootfdt: Make process_chosen_node() return int
Hi Henry,
Quoted 7 lines · Henry Wang
At the boot time, it is saner to stop booting early if an error occurs when parsing the device tree chosen node, rather than seeing random behavior afterwards. Therefore, this commit changes the return type of the
process_chosen_node()from void to int, and return correct errno based on the error type.
Quoted 5 lines
Signed-off-by Henry Wang <[email protected]>---
Changes from v1 to v2:
- New commit.
---
The patch looks good but I think it should be put as the first one in the series as this is a natural prerequisite for the introduction of the reserved heap. This will also help not to modify the same reserved heap code you introduced in the first patch.
~Michal
Re: [PATCH v2 2/4] xen/arm: bootfdt: Make process_chosen_node() return int
Quoted 16 lines · Michal Orzel
Hi Henry,
Quoted 7 lines · Henry Wang
At the boot time, it is saner to stop booting early if an error occurs when parsing the device tree chosen node, rather than seeing random behavior afterwards. Therefore, this commit changes the return type of the
process_chosen_node()from void to int, and return correct errno based on the error type.Quoted 5 lines
Signed-off-by Henry Wang <[email protected]>---
Changes from v1 to v2:
- New commit.
---
Quoted 3 lines
The patch looks good but I think it should be put as the first one in the series as this is a natural prerequisite for the introduction of the reserved heap. This will also help not to modify the same reserved heap code you introduced in the first patch.
+1. The same could be said with patch #4. The renaming should be before patch #3.
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH v2 2/4] xen/arm: bootfdt: Make process_chosen_node() return int
Hi Julien and Michal,
Quoted 7 lines
-----Original Message-----
From: Julien Grall <[email protected]>Quoted 5 lines
Quoted 3 lines
Changes from v1 to v2:
- New commit.
---The patch looks good but I think it should be put as the first one in the
Quoted 8 lines
series
Quoted 1 line
as this is a natural prerequisite for the introduction of the reserved heap.
This
Quoted 1 line
will also help not to modify the same reserved heap code you introduced in
the first patch.
+1. The same could be said with patch #4. The renaming should be before patch #3.
Cool, I will send a v3 with these adjusted. Will send after fixing more possible comments for v2.
Kind regards,
Henry
Quoted 5 lines
Cheers,
--
Julien Grall
PATCH v2 3/4 xen/arm: Handle reserved heap pages in boot and heap allocator
In reply to Henry WangThis commit firstly adds a bool field reserved_heap to bootinfo. This newly introduced field is set at the device tree parsing time if the reserved heap ranges are defined in the device tree chosen node.
For Arm32, In setup_mm, if the reserved heap is enabled, we use the reserved heap region for both domheap and xenheap allocation. Note that the xenheap on Arm32 should be always contiguous, so also add a helper fit_xenheap_in_reserved_heap() for Arm32 to find the required xenheap in the reserved heap regions.
For Arm64, In setup_mm, if the reserved heap is enabled and used, we make sure that only these reserved heap pages are added to the boot allocator. These reserved heap pages in the boot allocator are added to the heap allocator at end_boot_allocator().
If the reserved heap is disabled, we stick to current page allocation strategy at boot time.
Also, take the chance to correct a "double not" print in Arm32 setup_mm() and replace the open-coding address ~0 by INVALID_PADDR.
---
Changes from v1 to v2:
- Move the global bool reserved_heap to bootinfo.
- Replace the open open-coding address ~0 by INVALID_PADDR.
- Do not use reverted logic in heap_pages calculation.
- Remove unused Arm32 reserved_heap_start variable.
- Decouple the arm32 reserved heap too small size check with region end check.
- Reuse the arm32 original xenheap finding logic with the new helper to make sure xenheap on arm32 is contiguous.
Changes from RFC to v1:
- Rebase on top of latest setup_mm() changes.
- Added Arm32 logic in setup_mm().
--- xen/arch/arm/bootfdt.c | 2 + xen/arch/arm/include/asm/setup.h | 1 + xen/arch/arm/setup.c | 116 +++++++++++++++++++++++++++---- 3 files changed, 104 insertions(+), 15 deletions(-)
xen/arch/arm/bootfdt.c +2 -0
@@ -322,6 +322,8 @@ static int __init process_chosen_node(const void *fdt, int node, &bootinfo.reserved_mem, MEMBANK_RSVD_HEAP);if ( rc )return rc; + + bootinfo.reserved_heap = true; }printk ("Checking for initrd in /chosen\n" );
xen/arch/arm/include/asm/setup.h +1 -0
@@ -82,6 +82,7 @@ struct bootinfo {#ifdef CONFIG_ACPI struct meminfo acpi;#endif +bool reserved_heap; };struct map_range_data
xen/arch/arm/setup.c +101 -15
185 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v2 3/4] xen/arm: Handle reserved heap pages in boot and heap allocator
Hi Henry,
Quoted 72 lines · Henry Wang
This commit firstly adds a bool field
reserved_heapto bootinfo. This newly introduced field is set at the device tree parsing time if the reserved heap ranges are defined in the device tree chosen node.For Arm32, In
setup_mm, if the reserved heap is enabled, we use the reserved heap region for both domheap and xenheap allocation. Note that the xenheap on Arm32 should be always contiguous, so also add a helperfit_xenheap_in_reserved_heap()for Arm32 to find the required xenheap in the reserved heap regions.For Arm64, In
setup_mm, if the reserved heap is enabled and used, we make sure that only these reserved heap pages are added to the boot allocator. These reserved heap pages in the boot allocator are added to the heap allocator atend_boot_allocator().If the reserved heap is disabled, we stick to current page allocation strategy at boot time.
Also, take the chance to correct a "double not" print in Arm32
setup_mm()and replace the open-coding address ~0 byINVALID_PADDR.Signed-off-by Henry Wang <[email protected]>---
Changes from v1 to v2:
- Move the global boolreserved_heapto bootinfo.
- Replace the open open-coding address ~0 byINVALID_PADDR.
- Do not use reverted logic inheap_pagescalculation.
- Remove unused Arm32reserved_heap_startvariable.
- Decouple the arm32 reserved heap too small size check with region end check.
- Reuse the arm32 original xenheap finding logic with the new helper to make sure xenheap on arm32 is contiguous.
Changes from RFC to v1:
- Rebase on top of latestsetup_mm()changes.
- Added Arm32 logic insetup_mm().--- xen/arch/arm/bootfdt.c | 2 + xen/arch/arm/include/asm/setup.h | 1 + xen/arch/arm/setup.c | 116 +++++++++++++++++++++++++++---- 3 files changed, 104 insertions(+), 15 deletions(-)xen/arch/arm/bootfdt.c +2
-0@@ -322,6 +322,8 @@ static int __init process_chosen_node(const void *fdt, int node, &bootinfo.reserved_mem, MEMBANK_RSVD_HEAP);if ( rc )return rc; + + bootinfo.reserved_heap = true; }printk ("Checking for initrd in /chosen\n" );xen/arch/arm/include/asm/setup.h +1
-0@@ -82,6 +82,7 @@ struct bootinfo {#ifdef CONFIG_ACPI struct meminfo acpi;#endif +bool reserved_heap; };struct map_range_data xen/arch/arm/setup.c +0
-0
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 561
Quoted 6 lines
xen/arch/arm/setup.c +3
-0@@ -556,6 +556,43 @@ static paddr_t __init consider_modules(paddr_t s, paddr_t e, }return e; } + +/* +* Find the contiguous xenheap region that fits in the reserved heap region with
There might be multiple. So "Find a contiguous...". I would also drop "xenheap".
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 562
Quoted 1 line
xen/arch/arm/setup.c +1
-0+* required size and alignment, and return the end address of xenheap.
I would write "and return the end address of the region if found otherwise 0".
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 566
Quoted 4 lines
xen/arch/arm/setup.c +4
-0+*/ +static paddr_t __init fit_xenheap_in_reserved_heap (uint32_t size,paddr_t align) +{ +int i;
Please use unsigned int.
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 572
Quoted 6 lines
xen/arch/arm/setup.c +6
-0+paddr_t end =0 , aligned_start, aligned_end; +paddr_t bank_start, bank_size, bank_end; + +for ( i =0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + { +if ( bootinfo.reserved_mem.bank[i].type ==MEMBANK_RSVD_HEAP )
NIT: You could avoid the extra indentation by reverting the condition.
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 582
Quoted 10 lines
xen/arch/arm/setup.c +10
-0+ { + bank_start = bootinfo.reserved_mem.bank[i].start; + bank_size = bootinfo.reserved_mem.bank[i].size; + bank_end = bank_start + bank_size; + +if ( bank_size < size ) +continue ; + + aligned_end = bank_end & ~(align -1 ); + aligned_start = (aligned_end - size) & ~(align -1 );
I find the logic a bit confusing. AFAIU, aligned_start could be below the start of the RAM which is not what I would usually expect.
The code works. So no change requested.
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 586
Quoted 4 lines
xen/arch/arm/setup.c +4
-0+ +if ( aligned_start > bank_start ) +/* +* Arm32 allocates xenheap from higher address to lower, so if
This code is also called on arm32. So what are you referring to? Is it consider_modules()?
Quoted 49 lines
xen/arch/arm/setup.c +23
-5+* there are multiple memory banks that satisfy the requirement, +* use the highest bank. +*/ + end = max(end, aligned_end); + } + } + +return end; +}#endif /* @@ -713,8 +750,9 @@ static void __init populate_boot_allocator(void)#ifdef CONFIG_ARM_32 static void __init setup_mm (void ) { -paddr_t ram_start, ram_end, ram_size, e; -unsigned long ram_pages; +paddr_t ram_start, ram_end, ram_size, e, bank_start, bank_end, bank_size; +paddr_t reserved_heap_end =0 , reserved_heap_size =0 ; +unsigned long ram_pages, reserved_heap_pages =0 ;unsigned long heap_pages, xenheap_pages, domheap_pages;unsigned int i;const uint32_t ctr =READ_CP32 (CTR );@@ -734,9 +772,9 @@ static void __init setup_mm(void)for ( i =1 ; i < bootinfo.mem.nr_banks; i++ ) { -paddr_t bank_start = bootinfo.mem.bank[i].start; -paddr_t bank_size = bootinfo.mem.bank[i].size; -paddr_t bank_end = bank_start + bank_size; + bank_start = bootinfo.mem.bank[i].start; + bank_size = bootinfo.mem.bank[i].size; + bank_end = bank_start + bank_size; ram_size = ram_size + bank_size; ram_start =min (ram_start,bank_start);@@ -745,19 +783,42 @@ static void __init setup_mm(void) total_pages = ram_pages = ram_size >>PAGE_SHIFT ; +if ( bootinfo.reserved_heap ) + { +for ( i =0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + { +if ( bootinfo.reserved_mem.bank[i].type ==MEMBANK_RSVD_HEAP ) + { + bank_start = bootinfo.reserved_mem.bank[i].start; + bank_size = bootinfo.reserved_mem.bank[i].size;
xen/arch/arm/setup.c static void __init setup_mm(void) · line 803
Quoted 10 lines
xen/arch/arm/setup.c +10
-0+ bank_end = bank_start + bank_size; + + reserved_heap_size += bank_size; + reserved_heap_end =max (reserved_heap_end, bank_end); + } + } + + reserved_heap_pages = reserved_heap_size >>PAGE_SHIFT ; +if ( reserved_heap_pages <32 <<(20 -PAGE_SHIFT ) ) +panic ("Too small reserved heap region, should be at least 32M\n" );
This is a bit misleading. 32MB is not sufficient, it also has to be contiguous. So I would drop this panic() completely.
xen/arch/arm/setup.c static void __init setup_mm(void) · line 813
Quoted 11 lines
xen/arch/arm/setup.c +4
-1+ } +/* * If the user has not requested otherwise via the command line * then locate the xenheap using these constraints: * * - must be 32 MiB aligned * - must not include Xen itself or the boot modules -* - must be at most 1GB or 1/32 the total RAM in the system if less +* - must be at most 1GB or 1/32 the total RAM in the system +* (there is no reserved heap) or 1/32 the total reserved
Did you forgot to add "if" before "there"?
xen/arch/arm/setup.c static void __init setup_mm(void) · line 814
Quoted 1 line
xen/arch/arm/setup.c +1
-0+* heap region (there is reserved heap) if less
The new wording suggests that the 1GB limit only applies when the admin doesn't specify the reserved heap. However, we don't support larger heap than 1GB. So the limit should also apply for the reserved heap. So how about:
- must be at most 1GB or 1/32 the total RAM in the system (or reserved heap if enabled)
xen/arch/arm/setup.c static void __init setup_mm(void) · line 820
Quoted 7 lines
xen/arch/arm/setup.c +1
-1* - must be at least 32M * * We try to allocate the largest xenheap possible within these * constraints. */ - heap_pages = ram_pages; + heap_pages = bootinfo.reserved_heap ? reserved_heap_pages : ram_pages;
You can avoid the ternary operation here by setting heap_pages in the 'if' above and add a else for the 'ram_pages' part.
In fact, 'ram_pages' could be completely dropped in favor of 'total_pages'.
xen/arch/arm/setup.c static void __init setup_mm(void) · line 834
Quoted 12 lines
xen/arch/arm/setup.c +5
-0+if ( opt_xenheap_megabytes ) xenheap_pages = opt_xenheap_megabytes << (20 -PAGE_SHIFT );else @@ -767,9 +828,15 @@ static void __init setup_mm(void) xenheap_pages =min (xenheap_pages,1UL <<(30 -PAGE_SHIFT )); } +/* +* On Arm32, xenheap must be contiguous, look for one of the region +* that matches the above-mentioned xenheap constraints. +*/
IMHO this is already implied by the large comment above. But if you want to be more obvious, then I think this should belong to the comment above.
xen/arch/arm/setup.c static void __init setup_mm(void) · line 838
Quoted 5 lines
xen/arch/arm/setup.c +2
-1do { - e = consider_modules(ram_start, ram_end, + e = bootinfo.reserved_heap ? + fit_xenheap_in_reserved_heap(pfn_to_paddr(xenheap_pages), 32<<20) :
Please use MB(32) in new code.
Quoted 27 lines
xen/arch/arm/setup.c +5
-4+consider_modules (ram_start, ram_end,pfn_to_paddr (xenheap_pages),32 <<20 ,0 );if ( e )@@ -779,7 +846,7 @@ static void __init setup_mm(void) }while ( !opt_xenheap_megabytes && xenheap_pages >32 <<(20 -PAGE_SHIFT ) );if ( ! e ) -panic ("Not not enough space for xenheap\n" ); +panic ("Not enough space for xenheap\n" ); domheap_pages = heap_pages - xenheap_pages;@@ -824,9 +891,9 @@ static void __init setup_mm(void)static void __init setup_mm (void ) {const struct meminfo *banks = &bootinfo.mem; -paddr_t ram_start = ~0 ; -paddr_t ram_end =0 ; -paddr_t ram_size =0 ; +paddr_t ram_start =INVALID_PADDR , bank_start =INVALID_PADDR ; +paddr_t ram_end =0 , bank_end =0 ; +paddr_t ram_size =0 , bank_size =0 ;unsigned int i;init_pdx ();
xen/arch/arm/setup.c static void __init setup_mm(void) · line 905
Quoted 5 lines
xen/arch/arm/setup.c +1
-1@@ -835,17 +902,36 @@ static void __init setup_mm(void)* We need some memory to allocate the page-tables used for the xenheap * mappings. But some regions may contain memory already allocated * for other uses (e.g. modules, reserved-memory...). -* +* If there are non-empty reserved heap regions, (only) add these regions
I am not sure what you mean by "non-empty" here. How about something like:
"If a reserved heap was provided by the admin, populate the boot allocator with the corresponding regions only".
Quoted 13 lines
xen/arch/arm/setup.c +13
-0+* in the boot allocator. +*/ +if ( bootinfo.reserved_heap ) + { +for ( i =0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + { +if ( bootinfo.reserved_mem.bank[i].type ==MEMBANK_RSVD_HEAP ) + { + bank_start = bootinfo.reserved_mem.bank[i].start; + bank_size = bootinfo.reserved_mem.bank[i].size; + bank_end = bank_start + bank_size; + +init_boot_pages (bank_start, bank_end);
xen/arch/arm/setup.c static void __init setup_mm(void) · line 927
Quoted 10 lines
xen/arch/arm/setup.c +7
-1+ } + } + } +/* +* No reserved heap regions: * For simplicity, add all the free regions in the boot allocator. */ -populate_boot_allocator (); +else +populate_boot_allocator ();
For arm32, shouldn't we also only add the reserved heap (minus the xenheap) to the boot allocator? At which point, I would move the change in populate_boot_allocator().
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH v2 3/4] xen/arm: Handle reserved heap pages in boot and heap allocator
Hi Julien,
Thanks for your comments, I added my reply and some of the questions that I am not 100% sure inline below.
Quoted 10 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Hi Henry,xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e,
Quoted 3 lines
xen/arch/arm/setup.c +3
-0+ +/* +* Find the contiguous xenheap region that fits in the reserved heap region with
There might be multiple. So "Find a contiguous...". I would also drop "xenheap".
I will follow the wording that you suggested here and ...
Quoted 5 lines
Quoted 2 lines
+ * required size and alignment, and return the end address of xenheap.
I would write "and return the end address of the region if found otherwise 0".
...here.
Quoted 8 lines
Quoted 3 lines
+ */
+staticpaddr_t__initfit_xenheap_in_reserved_heap(uint32_t size,paddr_talign)
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 566
Quoted 2 lines
xen/arch/arm/setup.c +2
-0+{ +int i;Please use unsigned int.
Ah sure.
Quoted 8 lines
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 572
Quoted 7 lines
xen/arch/arm/setup.c +6
-0+paddr_t end =0 , aligned_start, aligned_end; +paddr_t bank_start, bank_size, bank_end; + +for ( i =0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + { +if ( bootinfo.reserved_mem.bank[i].type ==MEMBANK_RSVD_HEAP )NIT: You could avoid the extra indentation by reverting the condition.
Sorry I am not 100% sure the extra indentation you were referring to. Are you suggesting that we need to do a
```
if ( bootinfo.reserved_mem.bank[i].type != MEMBANK_RSVD_HEAP )
continue;
bank_start = bootinfo.reserved_mem.bank[i].start;
...
```?
If so I will change in v3.
Quoted 14 lines
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 582
Quoted 11 lines
xen/arch/arm/setup.c +10
-0+ { + bank_start = bootinfo.reserved_mem.bank[i].start; + bank_size = bootinfo.reserved_mem.bank[i].size; + bank_end = bank_start + bank_size; + +if ( bank_size < size ) +continue ; + + aligned_end = bank_end & ~(align -1 ); + aligned_start = (aligned_end - size) & ~(align -1 );I find the logic a bit confusing. AFAIU,
aligned_startcould be below the start of the RAM which is not what I would usually expect.
Yeah I understand your concern. Here I want to make sure even if the given size is not aligned (although less likely happen in real life given the size calculation logic in setup_mm) the code still work. So the aligned_start = (aligned_end - size) & ~(align - 1) and below if (aligned_start > bank_start) check.
Quoted 2 lines
The code works. So no change requested.
Thanks!
Quoted 9 lines
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 586
Quoted 6 lines
xen/arch/arm/setup.c +4
-0+ +if ( aligned_start > bank_start ) +/* +* Arm32 allocates xenheap from higher address to lower, so if This code is also called on arm32. So what are you referring to? Is it
consider_modules()?
Yes, I think the current arm32 behavior in consider_modules() is what I am referring to. In fact, I just want to add some comments that explain why we need the end = max(end, aligned_end) since technically if there are multiple reserved heap banks and all of them can fit the xenheap region, we can use either of them. But following the current behavior we can only use the highest bank to keep the consistency.
Quoted 49 lines
Quoted 14 lines
xen/arch/arm/setup.c +9
-0+* there are multiple memory banks that satisfy the requirement, +* use the highest bank. +*/ + end = max(end, aligned_end); + } + } + +return end; +}#endif /* xen/arch/arm/setup.c static void __init populate_boot_allocator(void) · line 753
Quoted 6 lines
xen/arch/arm/setup.c +1
-2@@ -713,8 +750,9 @@ static void __init populate_boot_allocator(void)#ifdef CONFIG_ARM_32 static void __init setup_mm (void ) { -paddr_t ram_start, ram_end, ram_size, e; -unsigned long ram_pages; + paddr_t ram_start, ram_end, ram_size, e, bank_start, bank_end,
bank_size;Quoted 19 lines
xen/arch/arm/setup.c +5
-3+paddr_t reserved_heap_end =0 , reserved_heap_size =0 ; +unsigned long ram_pages, reserved_heap_pages =0 ;unsigned long heap_pages, xenheap_pages, domheap_pages;unsigned int i;const uint32_t ctr =READ_CP32 (CTR );@@ -734,9 +772,9 @@ static void __init setup_mm(void)for ( i =1 ; i < bootinfo.mem.nr_banks; i++ ) { -paddr_t bank_start = bootinfo.mem.bank[i].start; -paddr_t bank_size = bootinfo.mem.bank[i].size; -paddr_t bank_end = bank_start + bank_size; + bank_start = bootinfo.mem.bank[i].start; + bank_size = bootinfo.mem.bank[i].size; + bank_end = bank_start + bank_size; ram_size = ram_size + bank_size; ram_start =min (ram_start,bank_start);xen/arch/arm/setup.c static void __init setup_mm(void) · line 790
Quoted 8 lines
xen/arch/arm/setup.c +5
-0@@ -745,19 +783,42 @@ static void __init setup_mm(void) total_pages = ram_pages = ram_size >>PAGE_SHIFT ; +if ( bootinfo.reserved_heap ) + { +for ( i =0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + { + if ( bootinfo.reserved_mem.bank[i].type ==
MEMBANK_RSVD_HEAP)
Quoted 16 lines
xen/arch/arm/setup.c static void __init setup_mm(void) · line 803
Quoted 13 lines
xen/arch/arm/setup.c +13
-0+ { + bank_start = bootinfo.reserved_mem.bank[i].start; + bank_size = bootinfo.reserved_mem.bank[i].size; + bank_end = bank_start + bank_size; + + reserved_heap_size += bank_size; + reserved_heap_end =max (reserved_heap_end, bank_end); + } + } + + reserved_heap_pages = reserved_heap_size >>PAGE_SHIFT ; +if ( reserved_heap_pages <32 <<(20 -PAGE_SHIFT ) ) +panic ("Too small reserved heap region, should be at least 32M\n" );This is a bit misleading. 32MB is not sufficient, it also has to be contiguous. So I would drop this
panic()completely.
Sure.
Quoted 13 lines
xen/arch/arm/setup.c static void __init setup_mm(void) · line 813
Quoted 12 lines
xen/arch/arm/setup.c +4
-1+ } +/* * If the user has not requested otherwise via the command line * then locate the xenheap using these constraints: * * - must be 32 MiB aligned * - must not include Xen itself or the boot modules -* - must be at most 1GB or 1/32 the total RAM in the system if less +* - must be at most 1GB or 1/32 the total RAM in the system +* (there is no reserved heap) or 1/32 the total reserved
Quoted 1 line
Did you forgot to add "if" before "there"?
I will use the wording that you suggested in ...
Quoted 10 lines
xen/arch/arm/setup.c static void __init setup_mm(void) · line 814
Quoted 2 lines
xen/arch/arm/setup.c +1
-0+* heap region (there is reserved heap) if less The new wording suggests that the 1GB limit only applies when the admin doesn't specify the reserved heap. However, we don't support larger heap than 1GB. So the limit should also apply for the reserved heap. So how about:
- must be at most 1GB or 1/32 the total RAM in the system (or reserved heap if enabled)
...here.
Quoted 8 lines
xen/arch/arm/setup.c static void __init setup_mm(void)
Quoted 8 lines
xen/arch/arm/setup.c +1
-1* - must be at least 32M * * We try to allocate the largest xenheap possible within these * constraints. */ - heap_pages = ram_pages; + heap_pages = bootinfo.reserved_heap ? reserved_heap_pages :
Quoted 4 lines
ram_pages;You can avoid the ternary operation here by setting
heap_pagesin the 'if' above and add a else for the 'ram_pages' part.
Sorry I might understand your comment in the wrong way, but do you suggest we need to:
```
if ( bootinfo.reserved_heap )
{
...
heap_pages = reserved_heap_pages;
}
else
heap_pages = total_pages;
```?
If so I will do that in v3.
Quoted 2 lines
In fact, '
ram_pages' could be completely dropped in favor of 'total_pages'.
Good point, I will do that in v3.
Quoted 9 lines
Quoted 9 lines
xen/arch/arm/setup.c +1
-0+if ( opt_xenheap_megabytes ) xenheap_pages = opt_xenheap_megabytes << (20 -PAGE_SHIFT );else @@ -767,9 +828,15 @@ static void __init setup_mm(void) xenheap_pages =min (xenheap_pages,1UL <<(30 -PAGE_SHIFT )); }
Quoted 7 lines
xen/arch/arm/setup.c static void __init setup_mm(void) · line 834
Quoted 4 lines
xen/arch/arm/setup.c +4
-0+/* +* On Arm32, xenheap must be contiguous, look for one of the region +* that matches the above-mentioned xenheap constraints. +*/ IMHO this is already implied by the large comment above. But if you want to be more obvious, then I think this should belong to the comment above.
I think I will add "the xenheap should be contiguous" as I missed this one Before you mentioned this in the code review. I think adding this will avoid people who change this part in the future making mistakes like I did :))
Quoted 9 lines
xen/arch/arm/setup.c static void __init setup_mm(void)
Quoted 6 lines
xen/arch/arm/setup.c +2
-1do { - e = consider_modules(ram_start, ram_end, + e = bootinfo.reserved_heap ? + fit_xenheap_in_reserved_heap(pfn_to_paddr(xenheap_pages),32<<20) :
Please use MB(32) in new code.
Oh sure. Thanks for pointing this out.
Quoted 35 lines
xen/arch/arm/setup.c static void __init setup_mm(void) · line 846
Quoted 7 lines
xen/arch/arm/setup.c +1
-0+consider_modules (ram_start, ram_end,pfn_to_paddr (xenheap_pages),32 <<20 ,0 );if ( e )@@ -779,7 +846,7 @@ static void __init setup_mm(void) } while ( !opt_xenheap_megabytes && xenheap_pages > 32<<(20-
PAGE_SHIFT) );Quoted 21 lines
xen/arch/arm/setup.c +4
-4if ( ! e ) -panic ("Not not enough space for xenheap\n" ); +panic ("Not enough space for xenheap\n" ); domheap_pages = heap_pages - xenheap_pages;@@ -824,9 +891,9 @@ static void __init setup_mm(void)static void __init setup_mm (void ) {const struct meminfo *banks = &bootinfo.mem; -paddr_t ram_start = ~0 ; -paddr_t ram_end =0 ; -paddr_t ram_size =0 ; +paddr_t ram_start =INVALID_PADDR , bank_start =INVALID_PADDR ; +paddr_t ram_end =0 , bank_end =0 ; +paddr_t ram_size =0 , bank_size =0 ;unsigned int i;init_pdx ();xen/arch/arm/setup.c static void __init setup_mm(void) · line 902
Quoted 1 line
xen/arch/arm/setup.c +0
-0@@ -835,17 +902,36 @@ static void __init setup_mm(void)* We need some memory to allocate the page-tables used for the xenheap
xen/arch/arm/setup.c static void __init setup_mm(void)
Quoted 4 lines
xen/arch/arm/setup.c +1
-1* mappings. But some regions may contain memory already allocated * for other uses (e.g. modules, reserved-memory...). -* +* If there are non-empty reserved heap regions, (only) add these
Quoted 7 lines
regions
I am not sure what you mean by "non-empty" here. How about something like:
"If a reserved heap was provided by the admin, populate the boot allocator with the corresponding regions only".
Sure.
Quoted 26 lines
xen/arch/arm/setup.c static void __init setup_mm(void)
Quoted 8 lines
xen/arch/arm/setup.c +7
-0+* in the boot allocator. +*/ +if ( bootinfo.reserved_heap ) + { +for ( i =0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + { + if ( bootinfo.reserved_mem.bank[i].type ==
MEMBANK_RSVD_HEAP)Quoted 6 lines
xen/arch/arm/setup.c +6
-0+ { + bank_start = bootinfo.reserved_mem.bank[i].start; + bank_size = bootinfo.reserved_mem.bank[i].size; + bank_end = bank_start + bank_size; + +init_boot_pages (bank_start, bank_end);xen/arch/arm/setup.c static void __init setup_mm(void) · line 927
Quoted 10 lines
xen/arch/arm/setup.c +7
-1+ } + } + } +/* +* No reserved heap regions: * For simplicity, add all the free regions in the boot allocator. */ -populate_boot_allocator (); +else +populate_boot_allocator ();
Quoted 3 lines
For arm32, shouldn't we also only add the reserved heap (minus the xenheap) to the boot allocator? At which point, I would move the change in
populate_boot_allocator().
Sorry I am not sure what this comment about...as here the code is for arm64. For the question, yes.
For the latter one, do you request some changes? If so, could you please kindly elaborate a little bit more? Thanks.
Kind regards,
Henry
Quoted 5 lines
Cheers,
--
Julien Grall
Re: [PATCH v2 3/4] xen/arm: Handle reserved heap pages in boot and heap allocator
Hi Henry
Quoted 54 lines · Henry Wang
Thanks for your comments, I added my reply and some of the questions that I am not 100% sure inline below.
Quoted 10 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Hi Henry,xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e,
Quoted 3 lines
xen/arch/arm/setup.c +3
-0+ +/* +* Find the contiguous xenheap region that fits in the reserved heap region with
There might be multiple. So "Find a contiguous...". I would also drop "xenheap".
I will follow the wording that you suggested here and ...
Quoted 5 lines
Quoted 2 lines
+ * required size and alignment, and return the end address of xenheap.
I would write "and return the end address of the region if found otherwise 0".
...here.
Quoted 8 lines
Quoted 3 lines
+ */
+staticpaddr_t__initfit_xenheap_in_reserved_heap(uint32_t size,paddr_talign)
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 566
Quoted 2 lines
xen/arch/arm/setup.c +2
-0+{ +int i;Please use unsigned int.
Ah sure.
Quoted 8 lines
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 572
Quoted 7 lines
xen/arch/arm/setup.c +6
-0+paddr_t end =0 , aligned_start, aligned_end; +paddr_t bank_start, bank_size, bank_end; + +for ( i =0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + { +if ( bootinfo.reserved_mem.bank[i].type ==MEMBANK_RSVD_HEAP )NIT: You could avoid the extra indentation by reverting the condition.
Sorry I am not 100% sure the extra indentation you were referring to. Are you suggesting that we need to do a
``` if ( bootinfo.reserved_mem.bank[i].type != MEMBANK_RSVD_HEAP ) continue; bank_start = bootinfo.reserved_mem.bank[i].start; ... ```
Quoted 1 line
?
Yes.
Quoted 18 lines
If so I will change in v3.
Quoted 14 lines
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 582
Quoted 11 lines
xen/arch/arm/setup.c +10
-0+ { + bank_start = bootinfo.reserved_mem.bank[i].start; + bank_size = bootinfo.reserved_mem.bank[i].size; + bank_end = bank_start + bank_size; + +if ( bank_size < size ) +continue ; + + aligned_end = bank_end & ~(align -1 ); + aligned_start = (aligned_end - size) & ~(align -1 );I find the logic a bit confusing. AFAIU,
aligned_startcould be below the start of the RAM which is not what I would usually expect.
Quoted 3 lines
Yeah I understand your concern. Here I want to make sure even if the given size is not aligned (although less likely happen in real life given the size calculation logic in
setup_mm) the code still work.
I don't think I agree on the less likely here. The regions are provided by in the Device-Tree. And there are more chance they are incorrect because the value will be specific to a software/device stack.
Related to this discussion, I can't find any alignment requirement in the device-tree binding. I think we at least want to require 64KB aligned (so the same Device-Tree works if we were going to support 64KB page granularity).
Quoted 9 lines
Quoted 8 lines
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 586
Quoted 5 lines
xen/arch/arm/setup.c +4
-0+ +if ( aligned_start > bank_start ) +/* +* Arm32 allocates xenheap from higher address to lower, so if This code is also called on arm32. So what are you referring to? Is it
consider_modules()?
Quoted 6 lines
Yes, I think the current arm32 behavior in
consider_modules()is what I am referring to. In fact, I just want to add some comments that explain why we need the end =max(end, aligned_end)since technically if there are multiple reserved heap banks and all of them can fit the xenheap region, we can use either of them. But following the current behavior we can only use the highest bank to keep the consistency.
Xenheap is currently allocated the highest possible so there is enough low memory available for domain memory. This is in order to allow 32-bit DMA device to function.
I am less certain this makes sense when the heap is reserved. Because an admin could decide to define the heap solely above/below 4GB.
That said, nothing in the document suggests that domain memory would not be allocated from the reserved heap. So I would suggest to write the following comment:
"Allocate the xenheap as high as possible to keep low-memory available (assuming the admin supplied region below 4GB) for other use (e.g. domain memory allocation)."
Also, I think the documentation wants to be updated to clarify whether the reserved heap could be used to allocate domain. If it could, then I think we need to explain that the region should contain enough memory below some 4GB to cater 32-bit DMA.
Quoted 34 lines
Quoted 7 lines
The new wording suggests that the 1GB limit only applies when the admin doesn't specify the reserved heap. However, we don't support larger heap than 1GB. So the limit should also apply for the reserved heap. So how about:
- must be at most 1GB or 1/32 the total RAM in the system (or reserved heap if enabled)
...here.
Quoted 8 lines
Review
Quoted 8 lines
* - must be at least 32M
*
* We try to allocate the largest xenheap possible within these
* constraints.
*/(quoted diff) +1
-1- heap_pages = ram_pages; + heap_pages = bootinfo.reserved_heap ? reserved_heap_pages :Quoted 4 lines
ram_pages;You can avoid the ternary operation here by setting
heap_pagesin the 'if' above and add a else for the 'ram_pages' part.Sorry I might understand your comment in the wrong way, but do you suggest we need to:
``` if ( bootinfo.reserved_heap ) { ... heap_pages = reserved_heap_pages; } else heap_pages = total_pages; ```
Quoted 1 line
?
Yes.
Quoted 1 line
If so I will do that in v3.
Thanks.
Quoted 25 lines
Quoted 25 lines
xen/arch/arm/setup.c static void __init setup_mm(void)
Quoted 7 lines
xen/arch/arm/setup.c +7
-0+* in the boot allocator. +*/ +if ( bootinfo.reserved_heap ) + { +for ( i =0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + { + if ( bootinfo.reserved_mem.bank[i].type ==
MEMBANK_RSVD_HEAP)Quoted 16 lines
xen/arch/arm/setup.c +13
-1+ { + bank_start = bootinfo.reserved_mem.bank[i].start; + bank_size = bootinfo.reserved_mem.bank[i].size; + bank_end = bank_start + bank_size; + +init_boot_pages (bank_start, bank_end); + } + } + } +/* +* No reserved heap regions: * For simplicity, add all the free regions in the boot allocator. */ -populate_boot_allocator (); +else +populate_boot_allocator ();
Quoted 5 lines
Quoted 3 lines
For arm32, shouldn't we also only add the reserved heap (minus the xenheap) to the boot allocator? At which point, I would move the change in
populate_boot_allocator().Sorry I am not sure what this comment about...as here the code is for arm64.
Right, I wasn't sure where to comment because you don't touch the call to populate_boot_allocator().
Quoted 3 lines
For the question, yes.
For the latter one, do you request some changes? If so, could you please kindly elaborate a little bit more? Thanks.
Yes I am requesting some change because I think the code on arm32 is incorrect (the boot allocator will not be populated with the reserved heap).
I think the code should be moved in populate_boot_allocator():
if ( bootinfo.reserved_heap )
{
for ( ...; i < bootinfo.reserved_mem.nr_banks; i++ )
[....]
init_boot_pages_pages()
}Note that to handle arm32, you will also need to exclude the xenheap area.
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH v2 3/4] xen/arm: Handle reserved heap pages in boot and heap allocator
Hi Julien,
Thanks for the clarification and your patience. For the populate_boot_allocator() change, I attached my change in the end, and personally I would like to hear your opinion before sending v3 since we now have limited time.
Quoted 20 lines
-----Original Message-----
From: Julien Grall <[email protected]>Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/arm/setup.c +5
-0+ { + bank_start = bootinfo.reserved_mem.bank[i].start; + bank_size = bootinfo.reserved_mem.bank[i].size; + bank_end = bank_start + bank_size; +Quoted 8 lines
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 582
Quoted 5 lines
xen/arch/arm/setup.c +5
-0+if ( bank_size < size ) +continue ; + + aligned_end = bank_end & ~(align -1 ); + aligned_start = (aligned_end - size) & ~(align -1 );I find the logic a bit confusing. AFAIU,
aligned_startcould be below the start of the RAM which is not what I would usually expect.Yeah I understand your concern. Here I want to make sure even if the given size is not aligned (although less likely happen in real life given the size calculation logic in
setup_mm) the code still work.
Sorry I probably explained in the wrong way in previous mail, but since no change requested here this is purely for discussion. In the code we are sure aligned_end calculation will make sure the end address will satisfy the alignment requirement within the range to a aligned (lower) address. The aligned_start = (aligned_end - size) & ~(align - 1) will make sure the start address is following the same alignment requirement, but the only issue would be in this case the start address will below the region start, hence the if ( aligned_start > bank_start ) check.
Quoted 8 lines
I don't think I agree on the less likely here. The regions are provided by in the Device-Tree. And there are more chance they are incorrect because the value will be specific to a software/device stack.
Related to this discussion, I can't find any alignment requirement in the device-tree binding. I think we at least want to require 64KB aligned (so the same Device-Tree works if we were going to support 64KB page granularity).
I agree we need to require 64KB alignment, and currently we are following this because we are doing 32MB alignment. I will add a comment in the function comment to mention we at least want a 64KB alignment so that future callers will not make mistakes.
Quoted 26 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
xen/arch/arm/setup.c +4
-0+ +if ( aligned_start > bank_start ) +/* +* Arm32 allocates xenheap from higher address to lower, so if Quoted 5 lines
Quoted 2 lines
This code is also called on arm32. So what are you referring to? Is it
consider_modules()?Yes, I think the current arm32 behavior in
consider_modules()is what I am referring to. In fact, I just want to add some comments that explainwhy
Quoted 3 lines
we need the end =
max(end, aligned_end)since technically if there are multiple reserved heap banks and all of them can fit the xenheap region, we can use either of them. But following the current behavior we can onlyuse
Quoted 1 line
the highest bank to keep the consistency.
Xenheap is currently allocated the highest possible so there is enough low memory available for domain memory. This is in order to allow 32-bit DMA device to function.
I am less certain this makes sense when the heap is reserved. Because an admin could decide to define the heap solely above/below 4GB.
Quoted 7 lines
That said, nothing in the document suggests that domain memory would not be allocated from the reserved heap. So I would suggest to write the following comment:
"Allocate the xenheap as high as possible to keep low-memory available (assuming the admin supplied region below 4GB) for other use (e.g. domain memory allocation)."
Sure.
Quoted 5 lines
Also, I think the documentation wants to be updated to clarify whether the reserved heap could be used to allocate domain. If it could, then I think we need to explain that the region should contain enough memory below some 4GB to cater 32-bit DMA.
Ok I will add in v3.
Quoted 29 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
xen/arch/arm/setup.c +4
-1+/* +* No reserved heap regions: * For simplicity, add all the free regions in the boot allocator. */ -populate_boot_allocator (); + else +populate_boot_allocator ();Quoted 5 lines
Quoted 3 lines
For arm32, shouldn't we also only add the reserved heap (minus the xenheap) to the boot allocator? At which point, I would move the change in
populate_boot_allocator().Sorry I am not sure what this comment about...as here the code is for
arm64.
Right, I wasn't sure where to comment because you don't touch the call to
populate_boot_allocator().Quoted 2 lines
For the question, yes.
For the latter one, do you request some changes? If so, could you pleasekindly
Quoted 1 line
elaborate a little bit more? Thanks.
Yes I am requesting some change because I think the code on arm32 is incorrect (the boot allocator will not be populated with the reserved heap).
I think the code should be moved in
populate_boot_allocator():
Quoted 8 lines
if ( bootinfo.reserved_heap )
{ for ( ...; i < bootinfo.reserved_mem.nr_banks; i++ ) [....] init_boot_pages_pages() }Note that to handle arm32, you will also need to exclude the xenheap area.
When I implement the code, I found that the arm32 Xenheap excluding logic somehow can be reused.
So I think I tried to reuse as much as current code. Would below populate_boot_allocator() seem ok to you?
static void __init populate_boot_allocator(void)
{
unsigned int i;
const struct meminfo *banks = bootinfo.static_heap ?
&bootinfo.reserved_mem : &bootinfo.mem;
for ( i = 0; i < banks->nr_banks; i++ )
{
const struct membank *bank = &banks->bank[i];
paddr_t bank_end = bank->start + bank->size;
paddr_t s, e;
if ( bootinfo.static_heap && bank->type != MEMBANK_STATIC_HEAP )
continue;
s = bank->start;
while ( s < bank_end )
{
paddr_t n = bank_end;
if ( bootinfo.static_heap )
e = bank_end;
else
{
e = next_module(s, &n);
if ( e == ~(paddr_t)0 )
e = n = bank_end;
/*
* Module in a RAM bank other than the one which we are
* not dealing with here.
*/
if ( e > bank_end )
e = bank_end;
}#ifdef CONFIG_ARM_32
/* Avoid the xenheap */
if ( s < mfn_to_maddr(directmap_mfn_end) &&
mfn_to_maddr(directmap_mfn_start) < e )
{
e = mfn_to_maddr(directmap_mfn_start);
n = mfn_to_maddr(directmap_mfn_end);
}#endif
if ( bootinfo.static_heap )
init_boot_pages(s, e);
else
fw_unreserved_regions(s, e, init_boot_pages, 0);
s = n;
}
}
}Kind regards,
Henry
Quoted 5 lines
Cheers,
--
Julien Grall
Re: [PATCH v2 3/4] xen/arm: Handle reserved heap pages in boot and heap allocator
Hi Henry,
Quoted 34 lines · Henry Wang
Quoted 20 lines
-----Original Message-----
From: Julien Grall <[email protected]>Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/arm/setup.c +5
-0+ { + bank_start = bootinfo.reserved_mem.bank[i].start; + bank_size = bootinfo.reserved_mem.bank[i].size; + bank_end = bank_start + bank_size; +Quoted 8 lines
xen/arch/arm/setup.c static paddr_t __init consider_modules(paddr_t s, paddr_t e, · line 582
Quoted 5 lines
xen/arch/arm/setup.c +5
-0+if ( bank_size < size ) +continue ; + + aligned_end = bank_end & ~(align -1 ); + aligned_start = (aligned_end - size) & ~(align -1 );I find the logic a bit confusing. AFAIU,
aligned_startcould be below the start of the RAM which is not what I would usually expect.Yeah I understand your concern. Here I want to make sure even if the given size is not aligned (although less likely happen in real life given the size calculation logic in
setup_mm) the code still work.Sorry I probably explained in the wrong way in previous mail, but since no change requested here this is purely for discussion. In the code we are sure
aligned_endcalculation will make sure the end address will satisfy the alignment requirement within the range to a aligned (lower) address. Thealigned_start= (aligned_end- size) & ~(align - 1) will make sure the start address is following the same alignment requirement, but the only issue would be in this case the start address will below the region start, hence the if (aligned_start>bank_start) check.Quoted 4 lines
I don't think I agree on the less likely here. The regions are provided by in the Device-Tree. And there are more chance they are incorrect because the value will be specific to a software/device stack.
Quoted 7 lines
Quoted 4 lines
Related to this discussion, I can't find any alignment requirement in the device-tree binding. I think we at least want to require 64KB aligned (so the same Device-Tree works if we were going to support 64KB page granularity).
I agree we need to require 64KB alignment, and currently we are following this because we are doing 32MB alignment.
Hmmm... I think we are talking about two different things here. What I am referring to is the alignment of the start/end of the region provided by the admin.
[...]
Quoted 9 lines
Quoted 9 lines
I think the code should be moved in
populate_boot_allocator():if ( bootinfo.reserved_heap )
{ for ( ...; i < bootinfo.reserved_mem.nr_banks; i++ ) [....] init_boot_pages_pages() }
Quoted 7 lines
Quoted 1 line
Note that to handle arm32, you will also need to exclude the xenheap area.
When I implement the code, I found that the arm32 Xenheap excluding logic somehow can be reused.
So I think I tried to reuse as much as current code. Would below
populate_boot_allocator()seem ok to you?
I would prefer if they are separate because the logic can be simplified when using the static heap (the xenheap cannot across a region).
Something like:
for ( i = 0; i < banks->nr_banks; i++ )
{
#ifdef CONFIG_ARM_32
if ( (bank_start >= mfn_to_maddr(direct_mfn_start) &&
bank_end < mfn_to_maddr(direct_mfn_start) )
{
/* Add the memory *before* and *after* the region */
}
else
#endif
init_boot_pages(s, e);
}Quoted 66 lines
static void
__initpopulate_boot_allocator(void){ unsigned int i; const struct meminfo *banks = bootinfo.static_heap ? &bootinfo.reserved_mem : &bootinfo.mem; for ( i = 0; i < banks->nr_banks; i++ ) { const struct membank *bank = &banks->bank[i]; paddr_t bank_end = bank->start + bank->size; paddr_t s, e; if ( bootinfo.static_heap && bank->type != MEMBANK_STATIC_HEAP ) continue; s = bank->start; while ( s < bank_end ) { paddr_t n = bank_end; if ( bootinfo.static_heap ) e = bank_end; else { e = next_module(s, &n); if ( e == ~(paddr_t)0 ) e = n = bank_end; /* * Module in a RAM bank other than the one which we are * not dealing with here. */ if ( e > bank_end ) e = bank_end; }#ifdef CONFIG_ARM_32 /* Avoid the xenheap */ if ( s < mfn_to_maddr(directmap_mfn_end) && mfn_to_maddr(directmap_mfn_start) < e ) { e = mfn_to_maddr(directmap_mfn_start); n = mfn_to_maddr(directmap_mfn_end); }#endif
if ( bootinfo.static_heap ) init_boot_pages(s, e); else fw_unreserved_regions(s, e, init_boot_pages, 0); s = n; } } }Kind regards,
HenryQuoted 5 lines
Cheers,
--
Julien Grall
Signature · 1 line
Julien Grall
RE: [PATCH v2 3/4] xen/arm: Handle reserved heap pages in boot and heap allocator
Hi Julien,
Quoted 7 lines
-----Original Message-----
From: Julien Grall <[email protected]>Quoted 2 lines
I agree we need to require 64KB alignment, and currently we are following this because we are doing 32MB alignment.
Hmmm... I think we are talking about two different things here. What I am referring to is the alignment of the start/end of the region provided by the admin.
Ahh sorry my bad, yeah I should add the alignment requirement in dt-binding. Will do that in v3.
Quoted 7 lines
[...]
Quoted 1 line
Quoted 1 line
Note that to handle arm32, you will also need to exclude the xenheap
area.
Quoted 2 lines
When I implement the code, I found that the arm32 Xenheap excluding
Quoted 8 lines
logic
Quoted 4 lines
somehow can be reused.
So I think I tried to reuse as much as current code. Would below
populate_boot_allocator()seem ok to you?I would prefer if they are separate because the logic can be simplified when using the static heap (the xenheap cannot across a region).
I think whether separate this logic or not is personal taste, I did miss the "xenheap cannot across the bank" part so I agree your suggestion is better, but I think...
Quoted 9 lines
Something like:
for ( i = 0; i <
banks->nr_banks; i++ )
{#ifdef
CONFIG_ARM_32
if ( (bank_start>=mfn_to_maddr(direct_mfn_start)&&
bank_end<mfn_to_maddr(direct_mfn_start))
... this is probably wrong or I misunderstood? IMHO the xenheap is always smaller (or equal) than the bank, based on the logic that finding a contiguous xenheap in a bank.
So the code I propose would be:
```
@@ -712,12 +712,37 @@ static void __init populate_boot_allocator(void)
{
unsigned int i;
const struct meminfo *banks = &bootinfo.mem;
+ paddr_t s, e;
+
+ if ( bootinfo.static_heap )
+ {
+ for ( i = 0 ; i < bootinfo.reserved_mem.nr_banks; i++ )
+ {
+ if ( bootinfo.reserved_mem.bank[i].type != MEMBANK_STATIC_HEAP )
+ continue;
+
+ s = bootinfo.reserved_mem.bank[i].start;
+ e = s + bootinfo.reserved_mem.bank[i].size;
+#ifdef CONFIG_ARM_32
+ /* Avoid the xenheap, note that the xenheap cannot across a bank */
+ if ( s <= mfn_to_maddr(directmap_mfn_start) &&
+ e >= mfn_to_maddr(directmap_mfn_end) )
+ {
+ init_boot_pages(s, mfn_to_maddr(directmap_mfn_start));
+ init_boot_pages(mfn_to_maddr(directmap_mfn_end), e);
+ }
+ else
+#endif
+ init_boot_pages(s, e);
+ }
+
+ return;
+ }
for ( i = 0; i < banks->nr_banks; i++ )
/* The original logic in populate_boot_allocator()*/
```Kind regards,
Henry
PATCH v2 4/4 xen/arm: mm: Rename xenheap_* variable to directmap_*
In reply to Henry WangWith the reserved heap setup, keep using xenheap_* in the function setup_xenheap_mappings() will make the code confusing to read, because we always need to map the full RAM on Arm64. Therefore, renaming all "xenheap_*" variables to "directmap_*" to make clear the area is used to access the RAM easily.
On Arm32, only the xenheap is direct mapped today. So the renaming to "directmap_*" would be still valid for Arm32.
No functional change is intended.
---
Changes from v1 to v2:
- New commit.
--- xen/arch/arm/include/asm/config.h | 2 +- xen/arch/arm/include/asm/mm.h | 22 +++++++++++----------- xen/arch/arm/mm.c | 24 ++++++++++++------------ xen/arch/arm/setup.c | 27 ++++++++++++++------------- 4 files changed, 38 insertions(+), 37 deletions(-)
xen/arch/arm/include/asm/config.h +1 -1
@@ -160,7 +160,7 @@#define DIRECTMAP_SIZE (SLOT0_ENTRY_SIZE * (265-256))#define DIRECTMAP_VIRT_END (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE - 1) -#define XENHEAP_VIRT_START xenheap_virt_start +#define XENHEAP_VIRT_START directmap_virt_start#define HYPERVISOR_VIRT_END DIRECTMAP_VIRT_END
xen/arch/arm/include/asm/mm.h +11 -11
@@ -150,19 +150,19 @@ struct page_info#define _PGC_need_scrub _PGC_allocated#define PGC_need_scrub PGC_allocated -extern mfn_t xenheap_mfn_start, xenheap_mfn_end; -extern vaddr_t xenheap_virt_end; +extern mfn_t directmap_mfn_start, directmap_mfn_end; +extern vaddr_t directmap_virt_end;#ifdef CONFIG_ARM_64 -extern vaddr_t xenheap_virt_start; -extern unsigned long xenheap_base_pdx; +extern vaddr_t directmap_virt_start; +extern unsigned long directmap_base_pdx;#endif #ifdef CONFIG_ARM_32 #define is_xen_heap_page (page) is_xen_heap_mfn(page_to_mfn(page))#define is_xen_heap_mfn (mfn) ({ \ unsigned long mfn_ = mfn_x(mfn); \ - (mfn_ >= mfn_x(xenheap_mfn_start) && \ - mfn_ < mfn_x(xenheap_mfn_end)); \ + (mfn_ >= mfn_x(directmap_mfn_start) && \ + mfn_ < mfn_x(directmap_mfn_end)); \ })#else #define is_xen_heap_page (page) ((page)->count_info & PGC_xen_heap)
@@ -263,16 +263,16 @@ static inline paddr_t __virt_to_maddr(vaddr_t va)static inline void *maddr_to_virt (paddr_t ma) {ASSERT (is_xen_heap_mfn (maddr_to_mfn (ma))); - ma -=mfn_to_maddr (xenheap_mfn_start); + ma -=mfn_to_maddr (directmap_mfn_start);return (void *)(unsigned long ) ma +XENHEAP_VIRT_START ; }#else static inline void *maddr_to_virt (paddr_t ma) { -ASSERT ((mfn_to_pdx (maddr_to_mfn (ma)) - xenheap_base_pdx) < +ASSERT ((mfn_to_pdx (maddr_to_mfn (ma)) - directmap_base_pdx) < (DIRECTMAP_SIZE >>PAGE_SHIFT ));return (void *)(XENHEAP_VIRT_START - - (xenheap_base_pdx <<PAGE_SHIFT ) + + (directmap_base_pdx <<PAGE_SHIFT ) + ((ma & ma_va_bottom_mask) | ((ma & ma_top_mask) >> pfn_pdx_hole_shift))); }
@@ -315,10 +315,10 @@ static inline struct page_info *virt_to_page(const void *v)unsigned long pdx;ASSERT (va >=XENHEAP_VIRT_START ); -ASSERT (va < xenheap_virt_end); +ASSERT (va < directmap_virt_end); pdx = (va -XENHEAP_VIRT_START ) >>PAGE_SHIFT ; - pdx +=mfn_to_pdx (xenheap_mfn_start); + pdx +=mfn_to_pdx (directmap_mfn_start);return frame_table + pdx - frametable_base_pdx; }
xen/arch/arm/mm.c +12 -12
@@ -132,12 +132,12 @@ uint64_t init_ttbr;static paddr_t phys_offset;/* Limits of the Xen heap */ -mfn_t xenheap_mfn_start__read_mostly =INVALID_MFN_INITIALIZER ; -mfn_t xenheap_mfn_end__read_mostly ; -vaddr_t xenheap_virt_end__read_mostly ; +mfn_t directmap_mfn_start__read_mostly =INVALID_MFN_INITIALIZER ; +mfn_t directmap_mfn_end__read_mostly ; +vaddr_t directmap_virt_end__read_mostly ;#ifdef CONFIG_ARM_64 -vaddr_t xenheap_virt_start__read_mostly ; -unsigned long xenheap_base_pdx__read_mostly ; +vaddr_t directmap_virt_start__read_mostly ; +unsigned long directmap_base_pdx__read_mostly ;#endif unsigned long frametable_base_pdx__read_mostly ;
@@ -609,7 +609,7 @@ void __init setup_xenheap_mappings(unsigned long base_mfn,panic ("Unable to setup the xenheap mappings.\n" );/* Record where the xenheap is, for translation routines. */ - xenheap_virt_end =XENHEAP_VIRT_START + nr_mfns *PAGE_SIZE ; + directmap_virt_end =XENHEAP_VIRT_START + nr_mfns *PAGE_SIZE ; }#else /* CONFIG_ARM_64 */ void __init setup_xenheap_mappings(unsigned long base_mfn,
@@ -618,12 +618,12 @@ void __init setup_xenheap_mappings(unsigned long base_mfn,int rc;/* First call sets the xenheap physical and virtual offset. */ -if (mfn_eq (xenheap_mfn_start,INVALID_MFN ) ) +if (mfn_eq (directmap_mfn_start,INVALID_MFN ) ) {unsigned long mfn_gb = base_mfn & ~((FIRST_SIZE >>PAGE_SHIFT ) -1 ); - xenheap_mfn_start =_mfn (base_mfn); - xenheap_base_pdx =mfn_to_pdx (_mfn (base_mfn)); + directmap_mfn_start =_mfn (base_mfn); + directmap_base_pdx =mfn_to_pdx (_mfn (base_mfn));/* * The base address may not be aligned to the first level * size (e.g. 1GB when using 4KB pages). This would prevent
@@ -633,13 +633,13 @@ void __init setup_xenheap_mappings(unsigned long base_mfn,* Prevent that by offsetting the start of the xenheap virtual * address. */ - xenheap_virt_start =DIRECTMAP_VIRT_START + + directmap_virt_start =DIRECTMAP_VIRT_START + (base_mfn - mfn_gb) *PAGE_SIZE ; } -if ( base_mfn <mfn_x (xenheap_mfn_start) ) +if ( base_mfn <mfn_x (directmap_mfn_start) )panic ("cannot add xenheap mapping at %lx below heap start %lx\n" , - base_mfn,mfn_x (xenheap_mfn_start)); + base_mfn,mfn_x (directmap_mfn_start)); rc = map_pages_to_xen((vaddr_t)__mfn_to_virt(base_mfn), _mfn(base_mfn), nr_mfns,
xen/arch/arm/setup.c +14 -13
@@ -733,11 +733,11 @@ static void __init populate_boot_allocator(void)#ifdef CONFIG_ARM_32 /* Avoid the xenheap */ -if ( s <mfn_to_maddr (xenheap_mfn_end) && -mfn_to_maddr (xenheap_mfn_start) < e ) +if ( s <mfn_to_maddr (directmap_mfn_end) && +mfn_to_maddr (directmap_mfn_start) < e ) { - e =mfn_to_maddr (xenheap_mfn_start); - n =mfn_to_maddr (xenheap_mfn_end); + e =mfn_to_maddr (directmap_mfn_start); + n =mfn_to_maddr (directmap_mfn_end); }#endif
@@ -859,15 +859,16 @@ static void __init setup_mm(void)* We need some memory to allocate the page-tables used for the * xenheap mappings. So populate the boot allocator first. * -* This requires us to set xenheap_mfn_{start, end} first so the Xenheap +* Note that currently xenheap is direct mapped on Arm32. +* This requires us to set directmap_mfn_{start, end} first so the Xenheap * region can be avoided. */ - xenheap_mfn_start =_mfn ((e >>PAGE_SHIFT ) - xenheap_pages); - xenheap_mfn_end =mfn_add (xenheap_mfn_start, xenheap_pages); + directmap_mfn_start =_mfn ((e >>PAGE_SHIFT ) - xenheap_pages); + directmap_mfn_end =mfn_add (directmap_mfn_start, xenheap_pages);populate_boot_allocator (); -setup_xenheap_mappings (mfn_x (xenheap_mfn_start), xenheap_pages); +setup_xenheap_mappings (mfn_x (directmap_mfn_start), xenheap_pages);/* Frame table covers all of RAM region, including holes */ setup_frametable_mappings (ram_start, ram_end);
@@ -882,8 +883,8 @@ static void __init setup_mm(void) smp_processor_id());/* Add xenheap memory that was not already added to the boot allocator. */ -init_xenheap_pages (mfn_to_maddr (xenheap_mfn_start), -mfn_to_maddr (xenheap_mfn_end)); +init_xenheap_pages (mfn_to_maddr (directmap_mfn_start), +mfn_to_maddr (directmap_mfn_end));init_staticmem_pages (); }
@@ -943,9 +944,9 @@ static void __init setup_mm(void) total_pages += ram_size >>PAGE_SHIFT ; - xenheap_virt_end =XENHEAP_VIRT_START + ram_end - ram_start; - xenheap_mfn_start =maddr_to_mfn (ram_start); - xenheap_mfn_end =maddr_to_mfn (ram_end); + directmap_virt_end =XENHEAP_VIRT_START + ram_end - ram_start; + directmap_mfn_start =maddr_to_mfn (ram_start); + directmap_mfn_end =maddr_to_mfn (ram_end);setup_frametable_mappings (ram_start, ram_end); max_page =PFN_DOWN (ram_end);
Signature · 1 line
2.17.1