Domain on Static Allocation
cover Domain on Static Allocation
Static allocation refers to system or sub-system(domains) for which memory areas are pre-defined by configuration using physical address ranges. Those pre-defined memory, -- Static Momery, as parts of RAM reserved in the beginning, shall never go to heap allocator or boot allocator for any use.
This Patch Serie only talks about Domain on Static Allocation.
Domain on Static Allocation is supported through device tree property xen,static-mem specifying reserved RAM banks as this domain's guest RAM. By default, they shall be mapped to the fixed guest RAM address GUEST_RAM0_BASE, GUEST_RAM1_BASE.
Looking into related [design link](
https://lists.xenproject.org/archives/html/xen-devel/2021-05/msg00882.html)
for more details.
The whole design is about Static Allocation and 1:1 direct-map, and this Patch Serie only covers parts of it, which are Domain on Static Allocation. Other features will be delievered through different patch series.
Penny Zheng (10):
xen/arm: introduce domain on Static Allocation xen/arm: handle static memory in dt_unreserved_regions xen/arm: introduce PGC_reserved
xen/arm: static memory initialization
xen/arm: introduce alloc_staticmem_pages
xen: replace order with nr_pfns in assign_pages for better
compatibility
xen/arm: intruduce alloc_domstatic_pages
xen/arm: introduce reserved_page_list
xen/arm: parse xen,static-mem info during domain construction xen/arm: introduce allocate_static_memory
docs/misc/arm/device-tree/booting.txt | 33 ++++ xen/arch/arm/bootfdt.c | 52 +++++++ xen/arch/arm/domain_build.c | 211 +++++++++++++++++++++++++- xen/arch/arm/setup.c | 41 ++++- xen/arch/x86/pv/dom0_build.c | 2 +- xen/common/domain.c | 1 + xen/common/grant_table.c | 2 +- xen/common/memory.c | 4 +- xen/common/page_alloc.c | 210 +++++++++++++++++++++++-- xen/include/asm-arm/domain.h | 3 + xen/include/asm-arm/mm.h | 16 +- xen/include/asm-arm/setup.h | 2 + xen/include/xen/mm.h | 9 +- xen/include/xen/sched.h | 5 + 14 files changed, 564 insertions(+), 27 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/10 xen/arm: introduce domain on Static Allocation
Static Allocation refers to system or sub-system(domains) for which memory areas are pre-defined by configuration using physical address ranges. Those pre-defined memory, -- Static Momery, as parts of RAM reserved in the beginning, shall never go to heap allocator or boot allocator for any use.
Domains on Static Allocation is supported through device tree property xen,static-mem specifying reserved RAM banks as this domain's guest RAM. By default, they shall be mapped to the fixed guest RAM address GUEST_RAM0_BASE, GUEST_RAM1_BASE.
This patch introduces this new xen,static-mem property to define static memory nodes in device tree file.
This patch also documents and parses this new attribute at boot time and stores related info in static_mem for later initialization.
--- docs/misc/arm/device-tree/booting.txt | 33 +++++++++++++++++ xen/arch/arm/bootfdt.c | 52 +++++++++++++++++++++++++++ xen/include/asm-arm/setup.h | 2 ++ 3 files changed, 87 insertions(+)
docs/misc/arm/device-tree/booting.txt +33 -0
@@ -268,3 +268,36 @@ The DTB fragment is loaded at 0xc000000 in the example above. It should follow the convention explained in docs/misc/arm/passthrough.txt. The DTB fragment will be added to the guest device tree, so that the guest kernel will be able to discover the device. + + +Static Allocation +============= + +Static Allocation refers to system or sub-system(domains) for which memory +areas are pre-defined by configuration using physical address ranges. +Those pre-defined memory, -- Static Momery, as parts of RAM reserved in the +beginning, shall never go to heap allocator or boot allocator for any use. + +Domains on Static Allocation is supported through device tree property +`xen,static-mem` specifying reserved RAM banks as this domain's guest RAM. +By default, they shall be mapped to the fixed guest RAM address +`GUEST_RAM0_BASE`, `GUEST_RAM1_BASE`. + +Static Allocation is only supported on AArch64 for now. + +The dtb property should look like as follows: + + chosen { + domU1 { + compatible = "xen,domain"; + #address-cells = <0x2>; + #size-cells = <0x2>; + cpus = <2>; + xen,static-mem = <0x0 0x30000000 0x0 0x20000000>; + + ... + }; + }; + +DOMU1 on Static Allocation has reserved RAM bank at 0x30000000 of 512MB size +as guest RAM.
xen/arch/arm/bootfdt.c +52 -0
64 lines not on this page · raw message
xen/include/asm-arm/setup.h +2 -0
@@ -74,6 +74,8 @@ struct bootinfo {#ifdef CONFIG_ACPI struct meminfo acpi;#endif +/* Static Memory */ +struct meminfo static_mem; };extern struct bootinfo bootinfo;
Signature · 1 line
2.25.1
Re: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Hi Penny,
Quoted 3 lines · Penny Zheng
Static Allocation refers to system or sub-system(domains) for which memory areas are pre-defined by configuration using physical address ranges. Those pre-defined memory, -- Static Momery, as parts of RAM reserved in the
s/Momery/Memory/
Quoted 25 lines
beginning, shall never go to heap allocator or boot allocator for any use.
Domains on Static Allocation is supported through device tree property
xen,static-memspecifying reserved RAM banks as this domain's guest RAM. By default, they shall be mapped to the fixed guest RAM addressGUEST_RAM0_BASE,GUEST_RAM1_BASE.This patch introduces this new
xen,static-memproperty to define static memory nodes in device tree file.
This patch also documents and parses this new attribute at boot time and stores related info instatic_memfor later initialization.Signed-off-by Penny Zheng <[email protected]>--- docs/misc/arm/device-tree/booting.txt | 33 +++++++++++++++++ xen/arch/arm/bootfdt.c | 52 +++++++++++++++++++++++++++ xen/include/asm-arm/setup.h | 2 ++ 3 files changed, 87 insertions(+)docs/misc/arm/device-tree/booting.txt +0
-0@@ -268,3 +268,36 @@ The DTB fragment is loaded at 0xc000000 in the example above. It should follow the convention explained in docs/misc/arm/passthrough.txt. The
docs/misc/arm/device-tree/booting.txt The DTB fragment is loaded at 0xc000000 in the example above. It should · line 278
Quoted 10 lines
docs/misc/arm/device-tree/booting.txt +8
-0DTB fragment will be added to the guest device tree, so that the guest kernel will be able to discover the device. + + +Static Allocation +============= + +Static Allocation refers to system or sub-system(domains) for which memory +areas are pre-defined by configuration using physical address ranges. +Those pre-defined memory, -- Static Momery, as parts of RAM reserved in the
s/Momery/Memory/
docs/misc/arm/device-tree/booting.txt The DTB fragment is loaded at 0xc000000 in the example above. It should · line 282
Quoted 4 lines
docs/misc/arm/device-tree/booting.txt +4
-0+beginning, shall never go to heap allocator or boot allocator for any use. + +Domains on Static Allocation is supported through device tree property +`xen,static-mem` specifying reserved RAM banks as this domain's guest RAM.
I would suggest to use "physical RAM" when you refer to the host memory.
docs/misc/arm/device-tree/booting.txt The DTB fragment is loaded at 0xc000000 in the example above. It should · line 284
Quoted 2 lines
docs/misc/arm/device-tree/booting.txt +2
-0+By default, they shall be mapped to the fixed guest RAM address +`GUEST_RAM0_BASE`, `GUEST_RAM1_BASE`.
There are a few bits that needs to clarified or part of the description:
1) "By default" suggests there is an alternative possibility.
However, I don't see any.
2) Will the first region of xen,static-mem be mapped toGUEST_RAM0_BASE and the second to GUEST_RAM1_BASE? What if a third region is specificed?
3) We don't guarantee the base address and the size of the banks.
Wouldn't it be better to let the admin select the region he/she wants?
4) How do you determine the number of cells for the address and the size?
docs/misc/arm/device-tree/booting.txt The DTB fragment is loaded at 0xc000000 in the example above. It should · line 286
Quoted 1 line
docs/misc/arm/device-tree/booting.txt +1
-0+Static Allocation is only supported on AArch64 for now.
The code doesn't seem to be AArch64 specific. So why can't this be used for 32-bit Arm?
Quoted 6 lines
docs/misc/arm/device-tree/booting.txt +6
-0+ +The dtb property should look like as follows: + + chosen { + domU1 { + compatible = "xen,domain";
docs/misc/arm/device-tree/booting.txt The DTB fragment is loaded at 0xc000000 in the example above. It should · line 302
Quoted 10 lines
docs/misc/arm/device-tree/booting.txt +10
-0+ #address-cells = <0x2>; + #size-cells = <0x2>; + cpus = <2>; + xen,static-mem = <0x0 0x30000000 0x0 0x20000000>; + + ... + }; + }; + +DOMU1 on Static Allocation has reserved RAM bank at 0x30000000 of 512MB size
Do you mean "DomU1 will have a static memory of 512MB reserved from the physical address..."?
Quoted 62 lines
docs/misc/arm/device-tree/booting.txt +1
-0+as guest RAM.xen/arch/arm/bootfdt.c +49
-0@@ -327,6 +327,55 @@ static void __init process_chosen_node(const void *fdt, int node,add_boot_module (BOOTMOD_RAMDISK , start, end-start, false); } +static int __init process_static_memory (const void *fdt,int node, +const char *name, +u32 address_cells,u32 size_cells, +void *data) +{ +int i; +int banks; +const __be32 *cell; +paddr_t start, size; +u32 reg_cells = address_cells + size_cells; +struct meminfo *mem = data; +const struct fdt_property *prop; + +if ( address_cells <1 || size_cells <1 ) + { +printk ("fdt: invalid #address-cells or #size-cells for static memory" ); +return -EINVAL ; + } + +/* +* Check if static memory property belongs to a specific domain, that is, +* its node `domUx` has compatible string "xen,domain". +*/ +if (fdt_node_check_compatible (fdt, node,"xen,domain" ) !=0 ) +printk ("xen,static-mem property can only locate under /domUx node.\n" ); + + prop =fdt_get_property (fdt, node, name,NULL ); +if ( !prop ) +return -ENOENT ; + + cell = (const __be32 *)prop->data; + banks =fdt32_to_cpu (prop->len) / (reg_cells *sizeof (u32)); + +for ( i =0 ; i < banks && mem->nr_banks <NR_MEM_BANKS ; i++ ) + { +device_tree_get_reg (&cell, address_cells, size_cells, &start, &size); +/* Some DT may describe empty bank, ignore them */ +if ( !size ) +continue ; + mem->bank[mem->nr_banks].start = start; + mem->bank[mem->nr_banks].size = size; + mem->nr_banks++; + } + +if ( i < banks ) +return -ENOSPC ; +return 0 ; +} + static int __init early_scan_node(const void *fdt, int node, const char *name, int depth, u32 address_cells, u32 size_cells,
xen/arch/arm/bootfdt.c static int __init early_scan_node(const void *fdt, · line 399
Quoted 6 lines
xen/arch/arm/bootfdt.c +3
-0@@ -345,6 +394,9 @@ static int __init early_scan_node(const void *fdt,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); + else if ( depth == 2 && fdt_get_property(fdt, node, "xen,static-mem", NULL) ) + process_static_memory(fdt, node, "xen,static-mem", address_cells, + size_cells, &bootinfo.static_mem);
I am a bit concerned to add yet another method to parse the DT and all the extra code it will add like in patch #2.
From the host PoV, they are memory reserved for a specific purpose. Would it be possible to consider the reserve-memory binding for that purpose? This will happen outside of chosen, but we could use a phandle to refer the region.
Quoted 9 lines
xen/arch/arm/bootfdt.c +0
-0if ( rc <0 )printk ("fdt: node `%s': parsing failed\n" , name);xen/include/asm-arm/setup.h +0
-0
xen/include/asm-arm/setup.h struct bootinfo { · line 81
Quoted 8 lines
xen/include/asm-arm/setup.h +2
-0@@ -74,6 +74,8 @@ struct bootinfo {#ifdef CONFIG_ACPI struct meminfo acpi;#endif +/* Static Memory */ +struct meminfo static_mem; };extern struct bootinfo bootinfo;
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Hi Julien
Quoted 11 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 4:58 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 01/10] xen/arm: introduce domain on Static AllocationHi Penny,
Quoted 8 lines
Quoted 2 lines · Penny Zheng
Static Allocation refers to system or sub-system(domains) for which memory areas are pre-defined by configuration using physical address
ranges.
Quoted 2 lines
Those pre-defined memory, -- Static Momery, as parts of RAM reserved in the
s/Momery/Memory/
Oh, thx!
Quoted 39 lines
Quoted 5 lines
beginning, shall never go to heap allocator or boot allocator for any use.
Domains on Static Allocation is supported through device tree property
xen,static-memspecifying reserved RAM banks as this domain's guestRAM.
docs/misc/arm/device-tree/booting.txt The DTB fragment is loaded at 0xc000000 in the
Quoted 21 lines
By default, they shall be mapped to the fixed guest RAM address
GUEST_RAM0_BASE,GUEST_RAM1_BASE.This patch introduces this new
xen,static-memproperty to define static memory nodes in device tree file.
This patch also documents and parses this new attribute at boot time and stores related info instatic_memfor later initialization.Signed-off-by Penny Zheng <[email protected]>--- docs/misc/arm/device-tree/booting.txt | 33 +++++++++++++++++ xen/arch/arm/bootfdt.c | 52 +++++++++++++++++++++++++++ xen/include/asm-arm/setup.h | 2 ++ 3 files changed, 87 insertions(+)docs/misc/arm/device-tree/booting.txt +0
-0@@ -268,3 +268,36 @@ The DTB fragment is loaded at 0xc000000 in theexample above. It should
docs/misc/arm/device-tree/booting.txt The DTB fragment is loaded at 0xc000000 in the example above. It should
Quoted 10 lines
docs/misc/arm/device-tree/booting.txt +7
-0follow the convention explained in docs/misc/arm/passthrough.txt. The DTB fragment will be added to the guest device tree, so that the guest kernel will be able to discover the device. + + +Static Allocation +============= + +Static Allocation refers to system or sub-system(domains) for which +memory areas are pre-defined by configuration using physical addressranges.
Quoted 5 lines
docs/misc/arm/device-tree/booting.txt The DTB fragment is loaded at 0xc000000 in the · line 279
Quoted 2 lines
docs/misc/arm/device-tree/booting.txt +2
-0+Those pre-defined memory, -- Static Momery, as parts of RAM reserved +in thes/Momery/Memory/
Oh, thx
Quoted 11 lines
docs/misc/arm/device-tree/booting.txt The DTB fragment is loaded at 0xc000000 in the example above. It should
Quoted 4 lines
docs/misc/arm/device-tree/booting.txt +4
-0+beginning, shall never go to heap allocator or boot allocator for any use. + +Domains on Static Allocation is supported through device tree +property `xen,static-mem` specifying reserved RAM banks as this domain'sguest RAM.
I would suggest to use "physical RAM" when you refer to the host memory.
docs/misc/arm/device-tree/booting.txt The DTB fragment is loaded at 0xc000000 in the example above. It should · line 284
Quoted 2 lines
docs/misc/arm/device-tree/booting.txt +2
-0+By default, they shall be mapped to the fixed guest RAM address +`GUEST_RAM0_BASE`, `GUEST_RAM1_BASE`.
Quoted 9 lines
There are a few bits that needs to clarified or part of the description:
1) "By default" suggests there is an alternative possibility.
However, I don't see any.
2) Will the first region of xen,static-mem be mapped toGUEST_RAM0_BASE
and the second toGUEST_RAM1_BASE? What if a third region is specificed?
3) We don't guarantee the base address and the size of the banks.
Wouldn't it be better to let the admin select the region he/she wants?
4) How do you determine the number of cells for the address and the size?
The specific implementation on this part could be traced to the last commit
https://patchew.org/Xen/[email protected]/[email protected]/
It will exhaust the GUEST_RAM0_SIZE, then seek to the GUEST_RAM1_BASE. GUEST_RAM0 may take up several regions.
Yes, I may add the 1:1 direct-map scenario here to explain the alternative possibility
For the third point, are you suggesting that we could provide an option that let user also define guest memory base address/size?
I'm confused on the fourth point, you mean the address cell and size cell for xen,static-mem = <...>? It will be consistent with the ones defined in the parent node, domUx.
Quoted 5 lines
docs/misc/arm/device-tree/booting.txt The DTB fragment is loaded at 0xc000000 in the example above. It should · line 286
Quoted 1 line
docs/misc/arm/device-tree/booting.txt +1
-0+Static Allocation is only supported on AArch64 for now.The code doesn't seem to be AArch64 specific. So why can't this be used for 32-bit Arm?
True, we have plans to make it also workable in AArch32 in the future. Because we considered XEN on cortex-R52.
Quoted 12 lines
Quoted 12 lines
docs/misc/arm/device-tree/booting.txt +12
-0+ +The dtb property should look like as follows: + + chosen { + domU1 { + compatible = "xen,domain"; + #address-cells = <0x2>; + #size-cells = <0x2>; + cpus = <2>; + xen,static-mem = <0x0 0x30000000 0x0 0x20000000>; + + ...
Quoted 9 lines
docs/misc/arm/device-tree/booting.txt The DTB fragment is loaded at 0xc000000 in the example above. It should
Quoted 5 lines
docs/misc/arm/device-tree/booting.txt +5
-0+ }; + }; + +DOMU1 on Static Allocation has reserved RAM bank at 0x30000000 of +512MB sizeDo you mean "DomU1 will have a static memory of 512MB reserved from the physical address..."?
Yes, yes. You phrase it more clearly, thx
Quoted 72 lines
xen/arch/arm/bootfdt.c static void __init process_chosen_node(const void
Quoted 6 lines
docs/misc/arm/device-tree/booting.txt +1
-0+as guest RAM.xen/arch/arm/bootfdt.c index renamed from xen/arch/arm/bootfdt.c +0
-0
dcff512648..e9f14e6a44100644xen/arch/arm/bootfdt.c +0
-0@@ -327,6 +327,55 @@ static void __init process_chosen_node(const void*fdt, int node,
Quoted 56 lines
xen/arch/arm/bootfdt.c +49
-0add_boot_module (BOOTMOD_RAMDISK , start, end-start, false); } +static int __init process_static_memory (const void *fdt,int node, +const char *name, +u32 address_cells,u32 size_cells, +void *data) { +int i; +int banks; +const __be32 *cell; +paddr_t start, size; +u32 reg_cells = address_cells + size_cells; +struct meminfo *mem = data; +const struct fdt_property *prop; + +if ( address_cells <1 || size_cells <1 ) + { +printk ("fdt: invalid #address-cells or #size-cells for static memory" ); +return -EINVAL ; + } + +/* +* Check if static memory property belongs to a specific domain, that is, +* its node `domUx` has compatible string "xen,domain". +*/ +if (fdt_node_check_compatible (fdt, node,"xen,domain" ) !=0 ) + printk("xen,static-mem property can only locate under /domUx + node.\n"); + + prop =fdt_get_property (fdt, node, name,NULL ); +if ( !prop ) +return -ENOENT ; + + cell = (const __be32 *)prop->data; + banks =fdt32_to_cpu (prop->len) / (reg_cells *sizeof (u32)); + +for ( i =0 ; i < banks && mem->nr_banks <NR_MEM_BANKS ; i++ ) + { +device_tree_get_reg (&cell, address_cells, size_cells, &start, &size); +/* Some DT may describe empty bank, ignore them */ +if ( !size ) +continue ; + mem->bank[mem->nr_banks].start = start; + mem->bank[mem->nr_banks].size = size; + mem->nr_banks++; + } + +if ( i < banks ) +return -ENOSPC ; +return 0 ; +} + static int __init early_scan_node(const void *fdt, int node, const char *name, int depth, u32 address_cells, u32 size_cells,xen/arch/arm/bootfdt.c static int __init early_scan_node(const void *fdt, · line 398
Quoted 5 lines
xen/arch/arm/bootfdt.c +1
-0@@ -345,6 +394,9 @@ static int __init early_scan_node(const void *fdt,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); + else if ( depth == 2 && fdt_get_property(fdt, node, "xen,static-mem",NULL) )
xen/arch/arm/bootfdt.c static int __init early_scan_node(const void *fdt, · line 399
Quoted 2 lines
xen/arch/arm/bootfdt.c +2
-0+process_static_memory (fdt, node,"xen,static-mem" , address_cells, + size_cells, &bootinfo.static_mem);
Quoted 8 lines
I am a bit concerned to add yet another method to parse the DT and all the extra code it will add like in patch #2.
From the host PoV, they are memory reserved for a specific purpose.
Would it be possible to consider the reserve-memory binding for that purpose? This will happen outside of chosen, but we could use a phandle to refer the region.
Correct me if I understand wrongly, do you mean what this device tree snippet looks like:
reserved-memory {
#address-cells = <2>;
#size-cells = <2>;
ranges;
static-mem-domU1: static-mem@0x30000000{
reg = <0x0 0x30000000 0x0 0x20000000>; };
};
Chosen {
...
domU1 {
xen,static-mem = <&static-mem-domU1>;
};
...
};
Quoted 22 lines
Quoted 9 lines
xen/arch/arm/bootfdt.c +0
-0if ( rc <0 ) printk("fdt: node `%s': parsing failed\n", name); diff --git
a/xen/include/asm-arm/setup.hb/xen/include/asm-arm/setup.hindex 5283244015..5e9f296760 100644xen/include/asm-arm/setup.h struct bootinfo { · line 81
Quoted 8 lines
xen/include/asm-arm/setup.h +2
-0@@ -74,6 +74,8 @@ struct bootinfo {#ifdef CONFIG_ACPI struct meminfo acpi;#endif +/* Static Memory */ +struct meminfo static_mem; };extern struct bootinfo bootinfo;Cheers,
--
Julien Grall
Re: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Quoted 1 line · Penny Zheng
Hi Julien
Hi Penny,
Quoted 29 lines
Quoted 19 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 4:58 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 01/10] xen/arm: introduce domain on Static Allocationdocs/misc/arm/device-tree/booting.txt The DTB fragment is loaded at 0xc000000 in the example above. It should
Quoted 4 lines
docs/misc/arm/device-tree/booting.txt +4
-0+beginning, shall never go to heap allocator or boot allocator for any use. + +Domains on Static Allocation is supported through device tree +property `xen,static-mem` specifying reserved RAM banks as this domain'sguest RAM.
I would suggest to use "physical RAM" when you refer to the host memory.
Quoted 2 lines
+By default, they shall be mapped to the fixed guest RAM address +
GUEST_RAM0_BASE,GUEST_RAM1_BASE.Quoted 9 lines
There are a few bits that needs to clarified or part of the description:
1) "By default" suggests there is an alternative possibility.
However, I don't see any.
2) Will the first region of xen,static-mem be mapped toGUEST_RAM0_BASE
and the second toGUEST_RAM1_BASE? What if a third region is specificed?
3) We don't guarantee the base address and the size of the banks.
Wouldn't it be better to let the admin select the region he/she wants?
4) How do you determine the number of cells for the address and the size?
Quoted 2 lines
The specific implementation on this part could be traced to the last commit
https://patchew.org/Xen/[email protected]/[email protected]/
Right. My point is an admin should not have to read the code in order to figure out how the allocation works.
Quoted 3 lines
It will exhaust the
GUEST_RAM0_SIZE, then seek to theGUEST_RAM1_BASE.GUEST_RAM0may take up several regions.
Can this be clarified in the commit message.
Quoted 1 line
Yes, I may add the 1:1 direct-map scenario here to explain the alternative possibility
Ok. So I would suggest to remove "by default" until the implementation for direct-map is added.
Quoted 2 lines
For the third point, are you suggesting that we could provide an option that let user also define guest memory base address/size?
When reading the document, I originally thought that the first region would be mapped to bank1, and then the second region mapped to bank2...
But from your reply, this is not the expected behavior. Therefore, please ignore my suggestion here.
Quoted 1 line
I'm confused on the fourth point, you mean the address cell and size cell for xen,static-mem = <...>?
Yes. This should be clarified in the document. See more below why?
Quoted 1 line
It will be consistent with the ones defined in the parent node, domUx.
Hmmm... To take the example you provided, the parent would be chosen. However, from the example, I would expect the property #{address, size}-cells in domU1 to be used. What did I miss?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
+Static Allocation is only supported on AArch64 for now.
The code doesn't seem to be AArch64 specific. So why can't this be used for 32-bit Arm?
True, we have plans to make it also workable in AArch32 in the future. Because we considered XEN on cortex-R52.
All the code seems to be implemented in arm generic code. So isn't it already working?
Quoted 16 lines
Quoted 16 lines
Review static int __init early_scan_node(const void *fdt, · line 398
Quoted 9 lines
static int
__initearly_scan_node(const void *fdt,
int node, const char *name, int depth, u32address_cells, u32size_cells,(quoted diff) +1
-0@@ -345,6 +394,9 @@ static int __init early_scan_node(const void *fdt, 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); + else if ( depth == 2 && fdt_get_property(fdt, node, "xen,static-mem",NULL) )
xen/arch/arm/bootfdt.c static int __init early_scan_node(const void *fdt, · line 399
Quoted 2 lines
xen/arch/arm/bootfdt.c +2
-0+process_static_memory (fdt, node,"xen,static-mem" , address_cells, + size_cells, &bootinfo.static_mem);I am a bit concerned to add yet another method to parse the DT and all the extra code it will add like in patch #2.
Quoted 7 lines
Quoted 5 lines
From the host PoV, they are memory reserved for a specific purpose.
Would it be possible to consider the reserve-memory binding for that purpose? This will happen outside of chosen, but we could use a phandle to refer the region.Correct me if I understand wrongly, do you mean what this device tree snippet looks like:
Yes, this is what I had in mind. Although I have one small remark below.
Quoted 6 lines
reserved-memory {
#address-cells = <2>;
#size-cells = <2>;
ranges;
static-mem-domU1: static-mem@0x30000000{I think the node would need to contain a compatible (name to be defined).
Quoted 4 lines
reg = <0x0 0x30000000 0x0 0x20000000>;
};
};Quoted 30 lines
Chosen {
...domU1 { xen,static-mem = <&static-mem-domU1>; };...
};Quoted 22 lines
Quoted 9 lines
(quoted diff) +0
-0if ( rc < 0 ) printk("fdt: node `%s': parsing failed\n", name); diff --git
a/xen/include/asm-arm/setup.hb/xen/include/asm-arm/setup.hindex 5283244015..5e9f296760 100644xen/include/asm-arm/setup.h struct bootinfo { · line 81
Quoted 8 lines
xen/include/asm-arm/setup.h +2
-0@@ -74,6 +74,8 @@ struct bootinfo {#ifdef CONFIG_ACPI struct meminfo acpi;#endif +/* Static Memory */ +struct meminfo static_mem; };extern struct bootinfo bootinfo;Cheers,
--
Julien Grall
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Hi Julien
Quoted 52 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Thursday, May 20, 2021 2:27 AM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 01/10] xen/arm: introduce domain on Static AllocationQuoted 1 line · Penny Zheng
Hi Julien
Hi Penny,
Quoted 18 lines
Quoted 18 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 4:58 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 01/10] xen/arm: introduce domain on Static AllocationReview
Quoted 5 lines
(quoted diff) +5
-0+beginning, shall never go to heap allocator or boot allocator for any use. + +Domains on Static Allocation is supported through device tree +property `xen,static-mem` specifying reserved RAM banks as this +domain'sguest RAM.
I would suggest to use "physical RAM" when you refer to the host memory.
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
+By default, they shall be mapped to the fixed guest RAM address +
GUEST_RAM0_BASE,GUEST_RAM1_BASE.There are a few bits that needs to clarified or part of the description:
1) "By default" suggests there is an alternative possibility.
However, I don't see any.
2) Will the first region of xen,static-mem be mapped toGUEST_RAM0_BASEand the second toGUEST_RAM1_BASE? What if a thirdregion is specificed?
Quoted 8 lines
Quoted 4 lines
3) We don't guarantee the base address and the size of the banks.
Wouldn't it be better to let the admin select the region he/she wants?
4) How do you determine the number of cells for the address and the size?The specific implementation on this part could be traced to the last commit
https://patchew.org/Xen/20210518052113.725808-1-Quoted 1 line
Quoted 9 lines
Right. My point is an admin should not have to read the code in order to figure out how the allocation works.
Quoted 3 lines
It will exhaust the
GUEST_RAM0_SIZE, then seek to theGUEST_RAM1_BASE.GUEST_RAM0may take up several regions.Can this be clarified in the commit message.
Ok, I will expand commit to let it be clarified more clearly.
Quoted 6 lines
Quoted 2 lines
Yes, I may add the 1:1 direct-map scenario here to explain the alternative possibility
Ok. So I would suggest to remove "by default" until the implementation for direct-map is added.
Ok, will do. Thx.
Quoted 10 lines
Quoted 2 lines
For the third point, are you suggesting that we could provide an option that let user also define guest memory base address/size?
When reading the document, I originally thought that the first region would be mapped to bank1, and then the second region mapped to bank2...
But from your reply, this is not the expected behavior. Therefore, please ignore my suggestion here.
Quoted 1 line
I'm confused on the fourth point, you mean the address cell and size cell for
Quoted 9 lines
xen,static-mem = <...>?
Yes. This should be clarified in the document. See more below why?
Quoted 1 line
It will be consistent with the ones defined in the parent node, domUx.
Hmmm... To take the example you provided, the parent would be chosen. However, from the example, I would expect the property #{address, size}-cells in domU1 to be used. What did I miss?
Yeah, the property #{address, size}-cells in domU1 will be used. And the parent node will be domU1.
The dtb property should look like as follows:
chosen {
domU1 {
compatible = "xen,domain";
#address-cells = <0x2>;
#size-cells = <0x2>;
cpus = <2>;
xen,static-mem = <0x0 0x30000000 0x0 0x20000000>;
...
};
};Quoted 45 lines
Quoted 10 lines
+DOMU1 on Static Allocation has reserved RAM bank at
0x30000000of 512MB sizeQuoted 5 lines
Quoted 1 line
+Static Allocation is only supported on AArch64 for now.
The code doesn't seem to be AArch64 specific. So why can't this be used for 32-bit Arm?
True, we have plans to make it also workable in AArch32 in the future. Because we considered XEN on cortex-R52.
All the code seems to be implemented in arm generic code. So isn't it already working?
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
static int
__initearly_scan_node(const void *fdt,
int node, const char *name, int depth, u32address_cells, u32size_cells, @@ -345,6 +394,9 @@ static int__initearly_scan_node(constvoid *fdt,
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
process_multiboot_node(fdt, node, name, address_cells, size_cells); else if ( depth == 1 && device_tree_node_matches(fdt, node,"chosen") )
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
process_chosen_node(fdt, node, name,
address_cells,size_cells);
+ else if ( depth == 2 && fdt_get_property(fdt, node,
+ "xen,static-mem",NULL) )
xen/arch/arm/bootfdt.c static int __init early_scan_node(const void *fdt, · line 399
Quoted 2 lines
xen/arch/arm/bootfdt.c +2
-0+process_static_memory (fdt, node,"xen,static-mem" , address_cells, + size_cells, &bootinfo.static_mem);I am a bit concerned to add yet another method to parse the DT and all the extra code it will add like in patch #2.
Quoted 7 lines
Quoted 5 lines
From the host PoV, they are memory reserved for a specific purpose.
Would it be possible to consider the reserve-memory binding for that purpose? This will happen outside of chosen, but we could use a phandle to refer the region.Correct me if I understand wrongly, do you mean what this device tree
snippet looks like:
Yes, this is what I had in mind. Although I have one small remark below.
Quoted 9 lines
Quoted 6 lines
reserved-memory { #address-cells = <2>; #size-cells = <2>; ranges; static-mem-domU1: static-mem@0x30000000{I think the node would need to contain a compatible (name to be defined).
Ok, maybe, hmmm, how about "xen,static-memory"?
Quoted 30 lines
Quoted 30 lines
reg = <0x0 0x30000000 0x0 0x20000000>; }; };Chosen {
...domU1 { xen,static-mem = <&static-mem-domU1>; }; ... };Quoted 20 lines
Quoted 9 lines
if ( rc < 0 ) printk("fdt: node `%s': parsing failed\n", name); diff --git
a/xen/include/asm-arm/setup.hb/xen/include/asm-arm/setup.hindex 5283244015..5e9f296760 100644xen/include/asm-arm/setup.h struct bootinfo { · line 81
Quoted 8 lines
xen/include/asm-arm/setup.h +2
-0@@ -74,6 +74,8 @@ struct bootinfo {#ifdef CONFIG_ACPI struct meminfo acpi;#endif +/* Static Memory */ +struct meminfo static_mem; };extern struct bootinfo bootinfo;Cheers,
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
--
Julien GrallCheers,
--
Julien Grall
Cheers
Penny Zheng
Re: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Hi,
Quoted 8 lines · Penny Zheng
Quoted 5 lines
Quoted 1 line
It will be consistent with the ones defined in the parent node, domUx.
Hmmm... To take the example you provided, the parent would be chosen. However, from the example, I would expect the property #{address, size}-cells in domU1 to be used. What did I miss?
Yeah, the property #{address, size}-cells in domU1 will be used. And the parent node will be domU1.
You may have misunderstood what I meant. "domU1" is the node that contains the property "xen,static-mem". The parent node would be the one above (in our case "chosen").
Quoted 65 lines
The dtb property should look like as follows:
chosen { domU1 { compatible = "xen,domain"; #address-cells = <0x2>; #size-cells = <0x2>; cpus = <2>; xen,static-mem = <0x0 0x30000000 0x0 0x20000000>; ... }; };Quoted 50 lines
Quoted 10 lines
+DOMU1 on Static Allocation has reserved RAM bank at
0x30000000of 512MB sizeQuoted 5 lines
Quoted 1 line
+Static Allocation is only supported on AArch64 for now.
The code doesn't seem to be AArch64 specific. So why can't this be used for 32-bit Arm?
True, we have plans to make it also workable in AArch32 in the future. Because we considered XEN on cortex-R52.
All the code seems to be implemented in arm generic code. So isn't it already working?
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
static int
__initearly_scan_node(const void *fdt,
int node, const char *name, int depth, u32address_cells, u32size_cells, @@ -345,6 +394,9 @@ static int__initearly_scan_node(constvoid *fdt,
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
process_multiboot_node(fdt, node, name, address_cells, size_cells); else if ( depth == 1 && device_tree_node_matches(fdt, node,"chosen") )
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
process_chosen_node(fdt, node, name,
address_cells,size_cells);
+ else if ( depth == 2 && fdt_get_property(fdt, node,
+ "xen,static-mem",NULL) )
xen/arch/arm/bootfdt.c static int __init early_scan_node(const void *fdt, · line 399
Quoted 2 lines
xen/arch/arm/bootfdt.c +2
-0+process_static_memory (fdt, node,"xen,static-mem" , address_cells, + size_cells, &bootinfo.static_mem);I am a bit concerned to add yet another method to parse the DT and all the extra code it will add like in patch #2.
Quoted 7 lines
Quoted 5 lines
From the host PoV, they are memory reserved for a specific purpose.
Would it be possible to consider the reserve-memory binding for that purpose? This will happen outside of chosen, but we could use a phandle to refer the region.Correct me if I understand wrongly, do you mean what this device tree
snippet looks like:
Yes, this is what I had in mind. Although I have one small remark below.
Quoted 5 lines
reserved-memory { #address-cells = <2>; #size-cells = <2>; ranges;
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
static-mem-domU1: static-mem@0x30000000{I think the node would need to contain a compatible (name to be defined).
Ok, maybe, hmmm, how about "xen,static-memory"?
I would possibly add "domain" in the name to make clear this is domain memory. Stefano, what do you think?
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Hi Julien
Quoted 18 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Thursday, May 20, 2021 4:51 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 01/10] xen/arm: introduce domain on Static AllocationHi,
Quoted 6 lines · Penny Zheng
Quoted 5 lines
Quoted 1 line
It will be consistent with the ones defined in the parent node, domUx.
Hmmm... To take the example you provided, the parent would be chosen. However, from the example, I would expect the property #{address, size}-cells in domU1 to be used. What did I miss?
Quoted 7 lines
Quoted 2 lines
Yeah, the property #{address, size}-cells in domU1 will be used. And the parent node will be domU1.
You may have misunderstood what I meant. "domU1" is the node that contains the property "xen,static-mem". The parent node would be the one above (in our case "chosen").
I re-re-reconsider what you meant here, hope this time I get what you mean, correct me if I'm wrong, List an example here:
/ {
reserved-memory {
#address-cells = <2>;
#size-cells = <2>;
staticmemdomU1: static-memory@0x30000000 {
compatible = "xen,static-memory-domain";
reg = <0x0 0x30000000 0x0 0x20000000>;
};
};
chosen {
domU1 {
compatible = "xen,domain";
#address-cells = <0x1>;
#size-cells = <0x1>;
cpus = <2>;
xen,static-mem = <&staticmemdomU1>;
...
};
};
};If user gives two different #address-cells and #size-cells in reserved-memory and domU1, Then when parsing it through xen,static-mem, it may have unexpected answers.
I could not think a way to fix it properly in codes, do you have any suggestion? Or we just put a warning in doc/commits.
Quoted 77 lines
Quoted 37 lines
The dtb property should look like as follows:
chosen { domU1 { compatible = "xen,domain"; #address-cells = <0x2>; #size-cells = <0x2>; cpus = <2>; xen,static-mem = <0x0 0x30000000 0x0 0x20000000>; ... }; };Quoted 22 lines
Quoted 11 lines
+DOMU1 on Static Allocation has reserved RAM bank at
0x30000000of +512MB sizeQuoted 5 lines
Quoted 1 line
+Static Allocation is only supported on AArch64 for now.
The code doesn't seem to be AArch64 specific. So why can't this be used for 32-bit Arm?
True, we have plans to make it also workable in AArch32 in the future. Because we considered XEN on cortex-R52.
All the code seems to be implemented in arm generic code. So isn't it already working?
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
static int
__initearly_scan_node(const void *fdt,
int node, const char *name, int depth, u32address_cells, u32size_cells, @@ -345,6 +394,9 @@ static int__initearly_scan_node(constvoid *fdt,
Quoted 1 line
Quoted 1 line
Quoted 1 line
process_multiboot_node(fdt, node, name,
address_cells,
size_cells);Quoted 32 lines
Quoted 32 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
else if ( depth == 1 && device_tree_node_matches(fdt,node,
"chosen") )
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
process_chosen_node(fdt, node, name,
address_cells,size_cells);
+ else if ( depth == 2 && fdt_get_property(fdt, node,
+ "xen,static-mem",NULL) )
xen/arch/arm/bootfdt.c static int __init early_scan_node(const void *fdt, · line 399
Quoted 2 lines
xen/arch/arm/bootfdt.c +2
-0+process_static_memory (fdt, node,"xen,static-mem" , address_cells, + size_cells, &bootinfo.static_mem);I am a bit concerned to add yet another method to parse the DT and all the extra code it will add like in patch #2.
Quoted 8 lines
Quoted 5 lines
From the host PoV, they are memory reserved for a specific purpose.
Would it be possible to consider the reserve-memory binding for that purpose? This will happen outside of chosen, but we could use a phandle to refer the region.Correct me if I understand wrongly, do you mean what this device tree
snippet looks like:
Yes, this is what I had in mind. Although I have one small remark below.
Quoted 5 lines
reserved-memory { #address-cells = <2>; #size-cells = <2>; ranges;Quoted 6 lines
Quoted 4 lines
Quoted 1 line
static-mem-domU1: static-mem@0x30000000{I think the node would need to contain a compatible (name to be defined).
Ok, maybe, hmmm, how about "xen,static-memory"?
Quoted 7 lines
I would possibly add "domain" in the name to make clear this is domain memory. Stefano, what do you think?
Cheers,
Julien Grall
Cheers,
Penny Zheng
Re: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Hi,
Quoted 55 lines · Penny Zheng
Hi Julien
Quoted 18 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Thursday, May 20, 2021 4:51 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 01/10] xen/arm: introduce domain on Static AllocationHi,
Quoted 6 lines · Penny Zheng
Quoted 5 lines
Quoted 1 line
It will be consistent with the ones defined in the parent node, domUx.
Hmmm... To take the example you provided, the parent would be chosen. However, from the example, I would expect the property #{address, size}-cells in domU1 to be used. What did I miss?
Quoted 7 lines
Quoted 2 lines
Yeah, the property #{address, size}-cells in domU1 will be used. And the parent node will be domU1.
You may have misunderstood what I meant. "domU1" is the node that contains the property "xen,static-mem". The parent node would be the one above (in our case "chosen").
I re-re-reconsider what you meant here, hope this time I get what you mean, correct me if I'm wrong, List an example here:
/ { reserved-memory { #address-cells = <2>; #size-cells = <2>; staticmemdomU1: static-memory@0x30000000 { compatible = "xen,static-memory-domain"; reg = <0x0 0x30000000 0x0 0x20000000>; }; }; chosen { domU1 { compatible = "xen,domain"; #address-cells = <0x1>; #size-cells = <0x1>; cpus = <2>; xen,static-mem = <&staticmemdomU1>; ... }; }; };
Quoted 2 lines
If user gives two different #address-cells and #size-cells in reserved-memory and domU1, Then when parsing it through
xen,static-mem, it may have unexpected answers.
Why are you using the #address-cells and #size-cells from the node domU1 to parse staticmemdomU1?
Quoted 1 line
I could not think a way to fix it properly in codes, do you have any suggestion? Or we just put a warning in doc/commits.
The correct approach is to find the parent of staticmemdomU1 (i.e. reserved-memory) and use the #address-cells and #size-cells from there.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
I have not read most emails in this thread (sorry!) but I spotted this discussion about device tree and I would like to reply to that as we have discussed something very similar in the context of system device tree.
Quoted 62 lines · Julien Grall
Quoted 57 lines · Penny Zheng
Hi Julien
Quoted 19 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Thursday, May 20, 2021 4:51 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 01/10] xen/arm: introduce domain on Static AllocationHi,
Quoted 7 lines · Penny Zheng
Quoted 6 lines
Quoted 2 lines
It will be consistent with the ones defined in the parent node, domUx.
Hmmm... To take the example you provided, the parent would be chosen. However, from the example, I would expect the property #{address, size}-cells in domU1 to be used. What did I miss?
Quoted 7 lines
Quoted 2 lines
Yeah, the property #{address, size}-cells in domU1 will be used. And the parent node will be domU1.
You may have misunderstood what I meant. "domU1" is the node that contains the property "xen,static-mem". The parent node would be the one above (in our case "chosen").
I re-re-reconsider what you meant here, hope this time I get what you mean, correct me if I'm wrong,
List an example here:/ { reserved-memory { #address-cells = <2>; #size-cells = <2>; staticmemdomU1: static-memory@0x30000000 { compatible = "xen,static-memory-domain"; reg = <0x0 0x30000000 0x0 0x20000000>; }; }; chosen { domU1 { compatible = "xen,domain"; #address-cells = <0x1>; #size-cells = <0x1>; cpus = <2>; xen,static-mem = <&staticmemdomU1>; ... }; }; };Quoted 3 lines
If user gives two different #address-cells and #size-cells in reserved-memory and domU1, Then when parsing it through
xen,static-mem, it may have unexpected answers.
Quoted 8 lines
Why are you using the #address-cells and #size-cells from the node domU1 to parse staticmemdomU1?
Quoted 2 lines
I could not think a way to fix it properly in codes, do you have any suggestion? Or we just put a warning in doc/commits.
The correct approach is to find the parent of staticmemdomU1 (i.e. reserved-memory) and use the #address-cells and #size-cells from there.
Julien is right about how to parse the static-memory.
But I have a suggestion on the new binding. The /reserved-memory node is a weird node: it is one of the very few node (the only node aside from /chosen) which is about software configurations rather than hardware description.
For this reason, in a device tree with multiple domains /reserved-memory doesn't make a lot of sense: for which domain is the memory reserved?
This was one of the first points raised by Rob Herring in reviewing system device tree.
So the solution we went for is the following: if there is a default domain /reserved-memory applies to the default domain. Otherwise, each domain is going to have its own reserved-memory. Example:
domU1 {
compatible = "xen,domain";
#address-cells = <0x1>;
#size-cells = <0x1>;
cpus = <2>;
reserved-memory {
#address-cells = <2>;
#size-cells = <2>;
static-memory@0x30000000 {
compatible = "xen,static-memory-domain";
reg = <0x0 0x30000000 0x0 0x20000000>;
};
};
};So I don't think we want to use reserved-memory for this, either /reserved-memory or /chosen/domU1/reserved-memory. Instead it would be good to align it with system device tree and define it as a new property under domU1.
In system device tree we would use a property called "memory" to specify one or more ranges, e.g.:
domU1 {
memory = <0x0 0x500000 0x0 0x7fb00000>;Unfortunately for xen,domains we have already defined "memory" to specify an amount, rather than a range. That's too bad because the most natural way to do this would be:
domU1 {
size = <amount>;
memory = <ranges>;When we'll introduce native system device tree support in Xen we'll be able to do that. For now, we need to come up with a different property. For instance: "static-memory" (other names are welcome if you have a better suggestion).
We use a new property called "static-memory" together with #static-memory-address-cells and #static-memory-size-cells to define how many cells to use for address and size.
Example:
domU1 {
#static-memory-address-cells = <2>;
#static-memory-size-cells = <2>;
static-memory = <0x0 0x500000 0x0 0x7fb00000>;Another alternative would be to extend the definition of the existing "memory" property to potentially handle not just sizes but also address and size pairs. There are a couple of ways to do that, including using #memory-address-cells = <0>; to specify when memory only has a size, or changing compatible string to "xen,domain-v2". But actually I would avoid it. I would keep it simple and just introduce a new property like "static-memory" (we can come up with a better name).
Re: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Hi,
Quoted 10 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall
Quoted 2 lines · Penny Zheng
I could not think a way to fix it properly in codes, do you have any suggestion? Or we just put a warning in doc/commits.
The correct approach is to find the parent of staticmemdomU1 (i.e. reserved-memory) and use the #address-cells and #size-cells from there.
Julien is right about how to parse the static-memory.
Quoted 7 lines
But I have a suggestion on the new binding. The /reserved-memory node is a weird node: it is one of the very few node (the only node aside from /chosen) which is about software configurations rather than hardware description.
For this reason, in a device tree with multiple domains /reserved-memory doesn't make a lot of sense: for which domain is the memory reserved?
IHMO, /reserved-memory refers to the memory that the hypervisor should not touch. It is just a coincidence that most of the domains are then passed through to dom0.
This also matches the fact that the GIC, /memory is consumed by the hypervisor directly and not the domain..
Quoted 8 lines
This was one of the first points raised by Rob Herring in reviewing system device tree.
So the solution we went for is the following: if there is a default domain /reserved-memory applies to the default domain. Otherwise, each domain is going to have its own reserved-memory. Example:
Quoted 16 lines
domU1 {
compatible = "xen,domain";
#address-cells = <0x1>;
#size-cells = <0x1>;
cpus = <2>;
reserved-memory {
#address-cells = <2>;
#size-cells = <2>;
static-memory@0x30000000 {
compatible = "xen,static-memory-domain";
reg = <0x0 0x30000000 0x0 0x20000000>;
};
};
};This sounds wrong to me because the memory is reserved from the hypervisor PoV not from the domain. IOW, when I read this, I think the memory will be reserved in the domain.
Quoted 5 lines
So I don't think we want to use reserved-memory for this, either /reserved-memory or /chosen/domU1/reserved-memory. Instead it would be good to align it with system device tree and define it as a new property under domU1.
Do you have any formal documentation of the system device-tree?
Quoted 24 lines
In system device tree we would use a property called "memory" to specify one or more ranges, e.g.:
domU1 { memory = <0x0 0x500000 0x0 0x7fb00000>;Unfortunately for xen,domains we have already defined "memory" to specify an amount, rather than a range. That's too bad because the most natural way to do this would be:
domU1 { size = <amount>; memory = <ranges>;When we'll introduce native system device tree support in Xen we'll be able to do that. For now, we need to come up with a different property. For instance: "static-memory" (other names are welcome if you have a better suggestion).
We use a new property called "static-memory" together with #static-memory-address-cells and #static-memory-size-cells to define how many cells to use for address and size.
Quoted 6 lines
Example:
domU1 { #static-memory-address-cells = <2>; #static-memory-size-cells = <2>; static-memory = <0x0 0x500000 0x0 0x7fb00000>;
This is pretty similar to what Penny suggested. But I dislike it because of the amount of code that needs to be duplicated with the reserved memory.
Cheers,
Re: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Quoted 19 lines · Julien Grall
Quoted 10 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall
Quoted 2 lines · Penny Zheng
I could not think a way to fix it properly in codes, do you have any suggestion? Or we just put a warning in doc/commits.
The correct approach is to find the parent of staticmemdomU1 (i.e. reserved-memory) and use the #address-cells and #size-cells from there.
Julien is right about how to parse the static-memory.
Quoted 7 lines
But I have a suggestion on the new binding. The /reserved-memory node is a weird node: it is one of the very few node (the only node aside from /chosen) which is about software configurations rather than hardware description.
For this reason, in a device tree with multiple domains /reserved-memory doesn't make a lot of sense: for which domain is the memory reserved?
Quoted 6 lines
IHMO, /reserved-memory refers to the memory that the hypervisor should not touch. It is just a coincidence that most of the domains are then passed through to dom0.
This also matches the fact that the GIC, /memory is consumed by the hypervisor directly and not the domain..
In system device tree one of the key principles is to distinguish between hardware description and domains configuration. The domains configuration is under /domains (originally it was under /chosen then the DT maintainers requested to move it to its own top-level node), while everything else is for hardware description.
/chosen and /reserved-memory are exceptions. They are top-level nodes but they are for software configurations. In system device tree configurations go under the domain node. This makes sense: Xen, dom0 and domU can all have different reserved-memory and chosen configurations.
/domains/domU1/reserved-memory gives us a clear way to express reserved-memory configurations for domU1.
Which leaves us with /reserved-memory. Who is that for? It is for the default domain.
The default domain is the one receiving all devices by default. In a Xen setting, it is probably Dom0. In this case, we don't want to add reserved-memory regions for DomUs to Dom0's list. Dom0's reserved-memory list is for its own drivers. We could also make an argument that the default domain is Xen itself. From a spec perspective, that would be fine too. In this case, /reserved-memory is a list of memory regions reserved for Xen drivers. Either way, I don't think is a great fit for domains memory allocations.
Quoted 24 lines
Quoted 7 lines
This was one of the first points raised by Rob Herring in reviewing system device tree.
So the solution we went for is the following: if there is a default domain /reserved-memory applies to the default domain. Otherwise, each domain is going to have its own reserved-memory. Example:
Quoted 16 lines
domU1 { compatible = "xen,domain"; #address-cells = <0x1>; #size-cells = <0x1>; cpus = <2>; reserved-memory { #address-cells = <2>; #size-cells = <2>; static-memory@0x30000000 { compatible = "xen,static-memory-domain"; reg = <0x0 0x30000000 0x0 0x20000000>; }; }; };
Quoted 3 lines
This sounds wrong to me because the memory is reserved from the hypervisor PoV not from the domain. IOW, when I read this, I think the memory will be reserved in the domain.
It is definitely very wrong to place the static-memory allocation under /chosen/domU1/reserved-memory. Sorry if I caused confusion. I only meant it as an example of how reserved-memory (actual reserved-memory list driver-specific memory ranges) is used.
Quoted 7 lines
Quoted 5 lines
So I don't think we want to use reserved-memory for this, either /reserved-memory or /chosen/domU1/reserved-memory. Instead it would be good to align it with system device tree and define it as a new property under domU1.
Do you have any formal documentation of the system device-tree?
It lives here:
https://github.com/devicetree-org/lopper/tree/master/specification
Start from specification.md. It is the oldest part of the spec, so it is not yet written with a formal specification language.
FYI there are a number of things in-flight in regards to domains that we discussed in the last call but they are not yet settled, thus, they are not yet committed (access flags definitions and hierarchical domains). However, they don't affect domains memory allocations so from that perspective nothing has changed.
Quoted 25 lines
Quoted 25 lines
In system device tree we would use a property called "memory" to specify one or more ranges, e.g.:
domU1 { memory = <0x0 0x500000 0x0 0x7fb00000>;Unfortunately for xen,domains we have already defined "memory" to specify an amount, rather than a range. That's too bad because the most natural way to do this would be:
domU1 { size = <amount>; memory = <ranges>;When we'll introduce native system device tree support in Xen we'll be able to do that. For now, we need to come up with a different property. For instance: "static-memory" (other names are welcome if you have a better suggestion).
We use a new property called "static-memory" together with #static-memory-address-cells and #static-memory-size-cells to define how many cells to use for address and size.
Example:
Quoted 8 lines
Quoted 4 lines
domU1 { #static-memory-address-cells = <2>; #static-memory-size-cells = <2>; static-memory = <0x0 0x500000 0x0 0x7fb00000>;This is pretty similar to what Penny suggested. But I dislike it because of the amount of code that needs to be duplicated with the reserved memory.
Where is the code duplication? In the parsing itself?
If there is code duplication, can we find a way to share some of the code to avoid the duplication?
RE: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Hi stefano and julien
Quoted 151 lines
-----Original Message-----
From: Stefano Stabellini <[email protected]>
Sent: Friday, June 4, 2021 7:56 AM
To: Julien Grall <[email protected]>
Cc: Stefano Stabellini <[email protected]>; Penny Zheng <[email protected]>; [email protected]; Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 01/10] xen/arm: introduce domain on Static AllocationQuoted 1 line · Julien Grall
On Thu, 3 Jun 2021 at 22:33, Stefano Stabellini <[email protected]>
Quoted 10 lines · wrote:
Quoted 10 lines · Julien Grall
Quoted 6 lines · Penny Zheng
Quoted 2 lines
I could not think a way to fix it properly in codes, do you have any suggestion? Or we just put a warning in doc/commits.
The correct approach is to find the parent of staticmemdomU1 (i.e. reserved-memory) and use the #address-cells and #size-cells from there.
Julien is right about how to parse the static-memory.
Quoted 8 lines
Quoted 8 lines
But I have a suggestion on the new binding. The /reserved-memory node is a weird node: it is one of the very few node (the only node aside from
/chosen) which is about software configurations rather than hardware description.For this reason, in a device tree with multiple domains /reserved-memory doesn't make a lot of sense: for which domain is the
memory reserved?
Quoted 7 lines
IHMO, /reserved-memory refers to the memory that the hypervisor should not touch. It is just a coincidence that most of the domains are then passed through to dom0.
This also matches the fact that the GIC, /memory is consumed by the hypervisor directly and not the domain..
In system device tree one of the key principles is to distinguish between hardware description and domains configuration. The domains configuration is under /domains (originally it was under /chosen then the DT maintainers requested to move it to its own top-level node), while everything else is for hardware description.
/chosen and /reserved-memory are exceptions. They are top-level nodes but they are for software configurations. In system device tree configurations go under the domain node. This makes sense: Xen, dom0 and domU can all have different reserved-memory and chosen configurations.
/domains/domU1/reserved-memory gives us a clear way to express reserved- memory configurations for domU1.
Which leaves us with /reserved-memory. Who is that for? It is for the default domain.
The default domain is the one receiving all devices by default. In a Xen setting, it is probably Dom0. In this case, we don't want to add reserved-memory regions for DomUs to Dom0's list. Dom0's reserved-memory list is for its own drivers. We could also make an argument that the default domain is Xen itself. From a spec perspective, that would be fine too. In this case, /reserved- memory is a list of memory regions reserved for Xen drivers. Either way, I don't think is a great fit for domains memory allocations.
Quoted 24 lines
Quoted 7 lines
This was one of the first points raised by Rob Herring in reviewing system device tree.
So the solution we went for is the following: if there is a default domain /reserved-memory applies to the default domain. Otherwise, each domain is going to have its own reserved-memory. Example:
Quoted 16 lines
domU1 { compatible = "xen,domain"; #address-cells = <0x1>; #size-cells = <0x1>; cpus = <2>; reserved-memory { #address-cells = <2>; #size-cells = <2>; static-memory@0x30000000 { compatible = "xen,static-memory-domain"; reg = <0x0 0x30000000 0x0 0x20000000>; }; }; };Quoted 3 lines
This sounds wrong to me because the memory is reserved from the hypervisor PoV not from the domain. IOW, when I read this, I think the memory will be reserved in the domain.
It is definitely very wrong to place the static-memory allocation under /chosen/domU1/reserved-memory. Sorry if I caused confusion. I only meant it as an example of how reserved-memory (actual reserved-memory list driver- specific memory ranges) is used.
Quoted 7 lines
Quoted 5 lines
So I don't think we want to use reserved-memory for this, either /reserved-memory or /chosen/domU1/reserved-memory. Instead it would be good to align it with system device tree and define it as a new property under domU1.
Do you have any formal documentation of the system device-tree?
It lives here:
https://github.com/devicetree-org/lopper/tree/master/specificationStart from specification.md. It is the oldest part of the spec, so it is not yet written with a formal specification language.
FYI there are a number of things in-flight in regards to domains that we discussed in the last call but they are not yet settled, thus, they are not yet committed (access flags definitions and hierarchical domains). However, they don't affect domains memory allocations so from that perspective nothing has changed.
Quoted 30 lines
Quoted 29 lines
In system device tree we would use a property called "memory" to specify one or more ranges, e.g.:
domU1 { memory = <0x0 0x500000 0x0 0x7fb00000>;Unfortunately for xen,domains we have already defined "memory" to specify an amount, rather than a range. That's too bad because the most natural way to do this would be:
domU1 { size = <amount>; memory = <ranges>;When we'll introduce native system device tree support in Xen we'll be able to do that. For now, we need to come up with a different property. For instance: "static-memory" (other names are welcome if you have a better suggestion).
We use a new property called "static-memory" together with #static-memory-address-cells and #static-memory-size-cells to define how many cells to use for address and size.
Example:
domU1 { #static-memory-address-cells = <2>; #static-memory-size-cells = <2>; static-memory = <0x0 0x500000 0x0 0x7fb00000>;
Quoted 8 lines
Quoted 3 lines
This is pretty similar to what Penny suggested. But I dislike it because of the amount of code that needs to be duplicated with the reserved memory.
Where is the code duplication? In the parsing itself?
If there is code duplication, can we find a way to share some of the code to avoid the duplication?
Both your opinions are so convincing... :/
Correct me if I am wrong:
I think the duplication which Julien means are here, See commit
https://patchew.org/Xen/[email protected]/[email protected]/
I added a another similar loop in dt_unreserved_regions to unreserve static memory. For this part, I could try to extract common codes.
But another part I think is just this commit, where I added another check for static memory in early_scan_node:
+ else if ( depth == 2 && fdt_get_property(fdt, node, "xen,static-mem", NULL) )
+ process_static_memory(fdt, node, "xen,static-mem", address_cells,
+ size_cells, &bootinfo.static_mem);
TBH, I don't know how to fix here....
I've already finished Patch v2, we could continue discussing on how to define it in Device tree here, and it will be included in Patch v3~~~ 😉
Cheers
Penny Zheng
RE: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Quoted 54 lines · Penny Zheng
Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
In system device tree we would use a property called "memory" to specify one or more ranges, e.g.:
domU1 { memory = <0x0 0x500000 0x0 0x7fb00000>;Unfortunately for xen,domains we have already defined "memory" to specify an amount, rather than a range. That's too bad because the most natural way to do this would be:
domU1 { size = <amount>; memory = <ranges>;When we'll introduce native system device tree support in Xen we'll be able to do that. For now, we need to come up with a different property. For instance: "static-memory" (other names are welcome if you have a better suggestion).
We use a new property called "static-memory" together with #static-memory-address-cells and #static-memory-size-cells to define how many cells to use for address and size.
Example:
domU1 { #static-memory-address-cells = <2>; #static-memory-size-cells = <2>; static-memory = <0x0 0x500000 0x0 0x7fb00000>;Quoted 8 lines
Quoted 3 lines
This is pretty similar to what Penny suggested. But I dislike it because of the amount of code that needs to be duplicated with the reserved memory.
Where is the code duplication? In the parsing itself?
If there is code duplication, can we find a way to share some of the code to avoid the duplication?
Both your opinions are so convincing... :/
Correct me if I am wrong:
I think the duplication which Julien means are here, See commit
https://patchew.org/Xen/[email protected]/[email protected]/
I added a another similar loop indt_unreserved_regionsto unreserve static memory. For this part, I could try to extract common codes.But another part I think is just this commit, where I added another check for static memory in
early_scan_node:(quoted diff) +3
-0+ else if ( depth == 2 && fdt_get_property(fdt, node, "xen,static-mem", NULL) ) + process_static_memory(fdt, node, "xen,static-mem", address_cells, + size_cells, &bootinfo.static_mem);
Quoted 1 line
TBH, I don't know how to fix here....
Is it only one loop in dt_unreserved_regions and another call to process_static_memory? If you can make the code common in dt_unreserved_regions there wouldn't be much duplication left.
To explain my point of view a bit better, I think we have a lot more freedom in the Xen implementation compared to the device tree specification. For the sake of an example, let's say that we wanted Xen to reuse bootinfo.reserved_mem for both reserved-memory and static-memory. I don't know if it is even a good idea (I haven't looked into it, it is just an example) but I think it would be OK, we could decide to do that.
We have less room for flexibility in the device tree specification. /reserved-memory is for special configurations of 1 domain only. I don't think we could add domain static memory allocations to it.
Re: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
In reply to Stefano StabelliniHi Stefano,
Quoted 38 lines · Stefano Stabellini
Quoted 19 lines · Julien Grall
Quoted 10 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall
Quoted 2 lines · Penny Zheng
I could not think a way to fix it properly in codes, do you have any suggestion? Or we just put a warning in doc/commits.
The correct approach is to find the parent of staticmemdomU1 (i.e. reserved-memory) and use the #address-cells and #size-cells from there.
Julien is right about how to parse the static-memory.
Quoted 7 lines
But I have a suggestion on the new binding. The /reserved-memory node is a weird node: it is one of the very few node (the only node aside from /chosen) which is about software configurations rather than hardware description.
For this reason, in a device tree with multiple domains /reserved-memory doesn't make a lot of sense: for which domain is the memory reserved?
Quoted 6 lines
IHMO, /reserved-memory refers to the memory that the hypervisor should not touch. It is just a coincidence that most of the domains are then passed through to dom0.
This also matches the fact that the GIC, /memory is consumed by the hypervisor directly and not the domain..
In system device tree one of the key principles is to distinguish between hardware description and domains configuration. The domains configuration is under /domains (originally it was under /chosen then the DT maintainers requested to move it to its own top-level node), while everything else is for hardware description.
/chosen and /reserved-memory are exceptions. They are top-level nodes but they are for software configurations. In system device tree configurations go under the domain node. This makes sense: Xen, dom0 and domU can all have different reserved-memory and chosen configurations.
Quoted 8 lines
/domains/domU1/reserved-memory gives us a clear way to express reserved-memory configurations for domU1.
Which leaves us with /reserved-memory. Who is that for? It is for the default domain.
The default domain is the one receiving all devices by default. In a Xen setting, it is probably Dom0.
Let's take an example, let say in the future someone wants to allocate a specific region for the memory used by the GICv3 ITS.
From what you said above, /reserved-memory would be used by dom0. So how would you be able to tell the hypervisor that the region is reserved for itself?
Quoted 6 lines
In this case, we don't want to add
reserved-memory regions for DomUs to Dom0's list. Dom0's reserved-memory list is for its own drivers. We could also make an argument that the default domain is Xen itself. From a spec perspective, that would be fine too. In this case, /reserved-memory is a list of memory regions reserved for Xen drivers.
We seem to have a different way to read the binding description in [1]. For convenience, I will copy it here:
"Reserved memory is specified as a node under the /reserved-memory node. The operating system shall exclude reserved memory from normal usage one can create child nodes describing particular reserved (excluded from normal use) memory regions. Such memory regions are usually designed for the special usage by various device drivers.
"
I read it as this can be used to exclude any memory from the allocator for a specific purpose. They give the example of device drivers, but they don't exclude other purpose. So...
Quoted 2 lines
Either way, I don't think is a great fit for
domains memory allocations.
... I don't really understand why this is not a great fit. The regions have been *reserved* for a purpose.
Quoted 11 lines
Quoted 7 lines
Quoted 5 lines
So I don't think we want to use reserved-memory for this, either /reserved-memory or /chosen/domU1/reserved-memory. Instead it would be good to align it with system device tree and define it as a new property under domU1.
Do you have any formal documentation of the system device-tree?
It lives here:
https://github.com/devicetree-org/lopper/tree/master/specification
Quoted 8 lines
Start from specification.md. It is the oldest part of the spec, so it is not yet written with a formal specification language.
FYI there are a number of things in-flight in regards to domains that we discussed in the last call but they are not yet settled, thus, they are not yet committed (access flags definitions and hierarchical domains). However, they don't affect domains memory allocations so from that perspective nothing has changed.
Thanks!
Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
In system device tree we would use a property called "memory" to specify one or more ranges, e.g.:
domU1 { memory = <0x0 0x500000 0x0 0x7fb00000>;Unfortunately for xen,domains we have already defined "memory" to specify an amount, rather than a range. That's too bad because the most natural way to do this would be:
domU1 { size = <amount>; memory = <ranges>;When we'll introduce native system device tree support in Xen we'll be able to do that. For now, we need to come up with a different property. For instance: "static-memory" (other names are welcome if you have a better suggestion).
We use a new property called "static-memory" together with #static-memory-address-cells and #static-memory-size-cells to define how many cells to use for address and size.
Example:
domU1 { #static-memory-address-cells = <2>; #static-memory-size-cells = <2>; static-memory = <0x0 0x500000 0x0 0x7fb00000>;
Quoted 5 lines
Quoted 3 lines
This is pretty similar to what Penny suggested. But I dislike it because of the amount of code that needs to be duplicated with the reserved memory.
Where is the code duplication? In the parsing itself?
So the problem is we need an entire new way to parse and walk yet another binding that will describe memory excluded from normal allocator hypervisor.
The code is pretty much the same as parsing /reserved-memory except it will be on a different address cells, size cells, property.
Quoted 3 lines
If there is code duplication, can we find a way to share some of the code to avoid the duplication?
Feel free to propose one. I suggested to use /reserved-memory because this is the approach that makes the most sense to me (see my reply above).
TBH, even after your explanation, I am still a bit puzzled into why /reserved-memory cannot be leveraged to exclude domain region from the hypervisor allocator.
Cheers,
[1] https://www.kernel.org/doc/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt
Signature · 1 line
Julien Grall
Re: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Hi All,
On 7 Jun 2021, at 19:09, Julien Grall <[email protected]<mailto:[email protected]>> wrote:
Hi Stefano,
On 04/06/2021 00:55, Stefano Stabellini wrote:
On Thu, 3 Jun 2021, Julien Grall wrote:
On Thu, 3 Jun 2021 at 22:33, Stefano Stabellini <[email protected]<mailto:[email protected]>> wrote:
On Thu, 3 Jun 2021, Julien Grall wrote:
On 02/06/2021 11:09, Penny Zheng wrote:
I could not think a way to fix it properly in codes, do you have any
suggestion? Or we just put a warning in doc/commits.
The correct approach is to find the parent of staticmemdomU1 (i.e. reserved-memory) and use the #address-cells and #size-cells from there.
Julien is right about how to parse the static-memory.
But I have a suggestion on the new binding. The /reserved-memory node is a weird node: it is one of the very few node (the only node aside from /chosen) which is about software configurations rather than hardware description.
For this reason, in a device tree with multiple domains /reserved-memory doesn't make a lot of sense: for which domain is the memory reserved?
IHMO, /reserved-memory refers to the memory that the hypervisor should not touch. It is just a coincidence that most of the domains are then passed through to dom0.
This also matches the fact that the GIC, /memory is consumed by the hypervisor directly and not the domain..
In system device tree one of the key principles is to distinguish between hardware description and domains configuration. The domains configuration is under /domains (originally it was under /chosen then the DT maintainers requested to move it to its own top-level node), while everything else is for hardware description.
/chosen and /reserved-memory are exceptions. They are top-level nodes but they are for software configurations. In system device tree configurations go under the domain node. This makes sense: Xen, dom0 and domU can all have different reserved-memory and chosen configurations. /domains/domU1/reserved-memory gives us a clear way to express reserved-memory configurations for domU1.
Which leaves us with /reserved-memory. Who is that for? It is for the default domain.
The default domain is the one receiving all devices by default. In a Xen setting, it is probably Dom0.
Let's take an example, let say in the future someone wants to allocate a specific region for the memory used by the GICv3 ITS.
From what you said above, /reserved-memory would be used by dom0. So how would you be able to tell the hypervisor that the region is reserved for itself?
In this case, we don't want to add
reserved-memory regions for DomUs to Dom0's list. Dom0's reserved-memory list is for its own drivers. We could also make an argument that the default domain is Xen itself. From a spec perspective, that would be fine too. In this case, /reserved-memory is a list of memory regions reserved for Xen drivers.
We seem to have a different way to read the binding description in [1]. For convenience, I will copy it here:
"Reserved memory is specified as a node under the /reserved-memory node. The operating system shall exclude reserved memory from normal usage one can create child nodes describing particular reserved (excluded from normal use) memory regions. Such memory regions are usually designed for the special usage by various device drivers.
"
I read it as this can be used to exclude any memory from the allocator for a specific purpose. They give the example of device drivers, but they don't exclude other purpose. So...
Either way, I don't think is a great fit for
domains memory allocations.
... I don't really understand why this is not a great fit. The regions have been *reserved* for a purpose.
So I don't think we want to use reserved-memory for this, either /reserved-memory or /chosen/domU1/reserved-memory. Instead it would be good to align it with system device tree and define it as a new property under domU1.
Do you have any formal documentation of the system device-tree? It lives here:
https://github.com/devicetree-org/lopper/tree/master/specification
Start from specification.md. It is the oldest part of the spec, so it is not yet written with a formal specification language.
FYI there are a number of things in-flight in regards to domains that we discussed in the last call but they are not yet settled, thus, they are not yet committed (access flags definitions and hierarchical domains). However, they don't affect domains memory allocations so from that perspective nothing has changed.
Thanks!
In system device tree we would use a property called "memory" to specify one or more ranges, e.g.:
domU1 {
memory = <0x0 0x500000 0x0 0x7fb00000>;Unfortunately for xen,domains we have already defined "memory" to specify an amount, rather than a range. That's too bad because the most natural way to do this would be:
domU1 {
size = <amount>;
memory = <ranges>;When we'll introduce native system device tree support in Xen we'll be able to do that. For now, we need to come up with a different property. For instance: "static-memory" (other names are welcome if you have a better suggestion).
We use a new property called "static-memory" together with #static-memory-address-cells and #static-memory-size-cells to define how many cells to use for address and size.
Example:
domU1 {
#static-memory-address-cells = <2>;
#static-memory-size-cells = <2>;
static-memory = <0x0 0x500000 0x0 0x7fb00000>;This is pretty similar to what Penny suggested. But I dislike it because of the amount of code that needs to be duplicated with the reserved memory.
Where is the code duplication? In the parsing itself?
So the problem is we need an entire new way to parse and walk yet another binding that will describe memory excluded from normal allocator hypervisor.
The code is pretty much the same as parsing /reserved-memory except it will be on a different address cells, size cells, property.
If there is code duplication, can we find a way to share some of the code to avoid the duplication?
Feel free to propose one. I suggested to use /reserved-memory because this is the approach that makes the most sense to me (see my reply above).
TBH, even after your explanation, I am still a bit puzzled into why /reserved-memory cannot be leveraged to exclude domain region from the hypervisor allocator.
I really tend to think that the original solution from Penny is for now the easiest and simplest to document.
In the long term, using directly memory and giving in it the address range directly is the most natural solution but that would clash with the current usage for it.
I would like to suggest the following approach:
- keep original solution from Penny
- start to discuss a domain v2 so that we could solve current issues we have including the passthrough devices which are not really easy to define. As a user I would just expect to put a device tree or links in a domain definition to define its characteristic and devices and using the standard names (memory for example). Also I must admit I need to read more the system device tree spec to check if we could just use it directly (and be compliant to a standard).
Would that approach be acceptable ?
I am more then happy to drive a working group on rethinking the device tree together with Penny.
Cheers
Bertrand
Cheers,
[1] https://www.kernel.org/doc/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt
--
Julien Grall
Re: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Quoted 1 line · Bertrand Marquis
Hi All,
Hi,
Quoted 6 lines
Quoted 4 lines · On 7 Jun 2021, at 19:09, Julien Grall <[email protected] <mailto:[email protected]>>…
Feel free to propose one. I suggested to use /reserved-memory because this is the approach that makes the most sense to me (see my reply above).
TBH, even after your explanation, I am still a bit puzzled into why /reserved-memory cannot be leveraged to exclude domain region from the hypervisor allocator.
I really tend to think that the original solution from Penny is for now the easiest and simplest to document.
I can live with Penny's solution so long we don't duplicate the parsing and we don't create new datastructure in Xen for the new type of reserved memory. However...
Quoted 2 lines
In the long term, using directly memory and giving in it the address range directly is the most natural solution but that would clash with the current usage for it.
... we are already going to have quite some churn to support the system device-tree. So I don't want yet another binding to be invented in a few months time.
IOW, the new binding should be a long term solution rather than a temporary one to fill the gap until we agree on what you call "domain v2".
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Hi julien
Quoted 26 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Wednesday, June 9, 2021 6:47 PM
To: Bertrand Marquis <[email protected]>
Cc: Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Penny Zheng <[email protected]>; xen- [email protected]; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 01/10] xen/arm: introduce domain on Static AllocationQuoted 1 line · Bertrand Marquis
Hi All,
Hi,
Quoted 9 lines
Quoted 8 lines
On 7 Jun 2021, at 19:09, Julien Grall <[email protected] <mailto:[email protected]>> wrote:
Feel free to propose one. I suggested to use /reserved-memory because this is the approach that makes the most sense to me (see my reply above).TBH, even after your explanation, I am still a bit puzzled into why /reserved-memory cannot be leveraged to exclude domain region from the hypervisor allocator.
Quoted 7 lines
Quoted 2 lines
I really tend to think that the original solution from Penny is for now the easiest and simplest to document.
I can live with Penny's solution so long we don't duplicate the parsing and we don't create new datastructure in Xen for the new type of reserved memory. However...
Just to confirm what I understand here, you are not only worrying about the duplication code imported in dt_unreserved_regions, but also must introducing another path in func early_scan_node to parse my first implementation "xen,static-mem = <...>", right?
On duplication code part, I could think of a way to extract common codes to fix, but for introducing another new path to parse, FWIT, it is inevitable if not re-using reserved-memory. ;/
Quoted 8 lines
Quoted 3 lines
In the long term, using directly memory and giving in it the address range directly is the most natural solution but that would clash with the current usage for it.
... we are already going to have quite some churn to support the system device-tree. So I don't want yet another binding to be invented in a few months time.
Quoted 6 lines
IOW, the new binding should be a long term solution rather than a temporary one to fill the gap until we agree on what you call "domain v2".
Cheers,
--
Cheers
Penny
Quoted 1 line
Julien Grall
Re: [PATCH 01/10] xen/arm: introduce domain on Static Allocation
Quoted 1 line · Penny Zheng
Hi julien
Hi Penny,
Quoted 29 lines
Quoted 29 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Wednesday, June 9, 2021 6:47 PM
To: Bertrand Marquis <[email protected]>
Cc: Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Penny Zheng <[email protected]>; xen- [email protected]; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 01/10] xen/arm: introduce domain on Static AllocationQuoted 1 line · Bertrand Marquis
Hi All,
Hi,
Quoted 11 lines
Quoted 8 lines
On 7 Jun 2021, at 19:09, Julien Grall <[email protected] <mailto:[email protected]>> wrote:
Feel free to propose one. I suggested to use /reserved-memory because this is the approach that makes the most sense to me (see my reply above).TBH, even after your explanation, I am still a bit puzzled into why /reserved-memory cannot be leveraged to exclude domain region from the hypervisor allocator.
I really tend to think that the original solution from Penny is for now the easiest and simplest to document.
Quoted 8 lines
Quoted 4 lines
I can live with Penny's solution so long we don't duplicate the parsing and we don't create new datastructure in Xen for the new type of reserved memory. However...
Just to confirm what I understand here, you are not only worrying about the duplication code imported in
dt_unreserved_regions, but also must introducing another path in funcearly_scan_nodeto parse my first implementation "xen,static-mem = <...>", right?
That's correct.
Quoted 3 lines
On duplication code part, I could think of a way to extract common codes to fix, but for introducing another new path to parse, FWIT, it is inevitable if not re-using reserved-memory. ;/
I don't think this is inevitable. If you look at the code, we already share the parsing between reserved-memory and memory.
AFAICT, the main difference now is the property to parse. Other than that, the content is exactly the same. So we could pass the name of the property to parse.
Cheers,
Signature · 1 line
Julien Grall
PATCH 2/10 xen/arm: handle static memory in dt_unreserved_regions
In reply to Penny Zhengstatic memory regions overlap with memory nodes. The overlapping memory is reserved-memory and should be handled accordingly:dt_unreserved_regions should skip these regions the same way they are already skipping mem-reserved regions.
--- xen/arch/arm/setup.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-)
xen/arch/arm/setup.c +33 -6
@@ -201,7 +201,7 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e,void (*cb)(paddr_t ,paddr_t ), int first) { - int i, nr = fdt_num_mem_rsv(device_tree_flattened); + int i, nr_reserved, nr_static, nr = fdt_num_mem_rsv(device_tree_flattened);for ( i = first; i < nr ; i++ ) {
@@ -222,18 +222,45 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e, }/* -* i is the current bootmodule we are evaluating across all possible -* kinds. +* i is the current reserved RAM banks we are evaluating across all +* possible kinds. * * When retrieving the corresponding reserved-memory addresses * below, we need to index the bootinfo.reserved_mem bank starting * from 0, and only counting the reserved-memory modules. Hence, * we need to use i - nr. */ -for ( ; i - nr < bootinfo.reserved_mem.nr_banks; i++ ) + i = i - nr; + nr_reserved = bootinfo.reserved_mem.nr_banks; +for ( ; i < nr_reserved; i++ ) { -paddr_t r_s = bootinfo.reserved_mem.bank[i - nr].start; -paddr_t r_e = r_s + bootinfo.reserved_mem.bank[i - nr].size; +paddr_t r_s = bootinfo.reserved_mem.bank[i].start; +paddr_t r_e = r_s + bootinfo.reserved_mem.bank[i].size; + +if ( s < r_e && r_s < e ) + { +dt_unreserved_regions (r_e, e, cb, i +1 ); +dt_unreserved_regions (s, r_s, cb, i +1 ); +return ; + } + } + +/* +* i is the current reserved RAM banks we are evaluating across all +* possible kinds. +* +* When retrieving the corresponding static-memory bank address +* below, we need to index the bootinfo.static_mem starting +* from 0, and only counting the static-memory bank. Hence, +* we need to use i - nr_reserved. +*/ + + i = i - nr_reserved; + nr_static = bootinfo.static_mem.nr_banks; +for ( ; i < nr_static; i++ ) + { +paddr_t r_s = bootinfo.static_mem.bank[i].start; +paddr_t r_e = r_s + bootinfo.static_mem.bank[i].size;if ( s < r_e && r_s < e ) {
Signature · 1 line
2.25.1
Re: [PATCH 02/10] xen/arm: handle static memory in dt_unreserved_regions
Hi Penny,
Quoted 61 lines · Penny Zheng
static memory regions overlap with memory nodes. The overlapping memory is reserved-memory and should be handled accordingly:
dt_unreserved_regionsshould skip these regions the same way they are already skipping mem-reserved regions.Signed-off-by Penny Zheng <[email protected]>--- xen/arch/arm/setup.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-)xen/arch/arm/setup.c +22
-6@@ -201,7 +201,7 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e,void (*cb)(paddr_t ,paddr_t ), int first) { - int i, nr = fdt_num_mem_rsv(device_tree_flattened); + int i, nr_reserved, nr_static, nr = fdt_num_mem_rsv(device_tree_flattened);for ( i = first; i < nr ; i++ ) {@@ -222,18 +222,45 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e, }/* -* i is the current bootmodule we are evaluating across all possible -* kinds. +* i is the current reserved RAM banks we are evaluating across all +* possible kinds. * * When retrieving the corresponding reserved-memory addresses * below, we need to index the bootinfo.reserved_mem bank starting * from 0, and only counting the reserved-memory modules. Hence, * we need to use i - nr. */ -for ( ; i - nr < bootinfo.reserved_mem.nr_banks; i++ ) + i = i - nr; + nr_reserved = bootinfo.reserved_mem.nr_banks; +for ( ; i < nr_reserved; i++ ) { -paddr_t r_s = bootinfo.reserved_mem.bank[i - nr].start; -paddr_t r_e = r_s + bootinfo.reserved_mem.bank[i - nr].size; +paddr_t r_s = bootinfo.reserved_mem.bank[i].start; +paddr_t r_e = r_s + bootinfo.reserved_mem.bank[i].size; + +if ( s < r_e && r_s < e ) + { +dt_unreserved_regions (r_e, e, cb, i +1 ); +dt_unreserved_regions (s, r_s, cb, i +1 ); +return ; + } + } + +/* +* i is the current reserved RAM banks we are evaluating across all +* possible kinds. +* +* When retrieving the corresponding static-memory bank address
xen/arch/arm/setup.c static void __init dt_unreserved_regions(paddr_t s, paddr_t e, · line 262
Quoted 10 lines
xen/arch/arm/setup.c +10
-0+* below, we need to index the bootinfo.static_mem starting +* from 0, and only counting the static-memory bank. Hence, +* we need to use i - nr_reserved. +*/ + + i = i - nr_reserved; + nr_static = bootinfo.static_mem.nr_banks; +for ( ; i < nr_static; i++ ) + { + paddr_t r_s = bootinfo.static_mem.bank[i].start; > + paddr_t r_e = r_s + bootinfo.static_mem.bank[i].size;
This is the 3rd loop we are adding in dt_unreserved_regions(). Each loop are doing pretty much the same thing except with a different array. I'd like to avoid the new loop if possible.
As mentionned in patch#1, the static memory is another kind of reserved memory. So could we describe the static memory using the reserved-memory?
xen/arch/arm/setup.c static void __init dt_unreserved_regions(paddr_t s, paddr_t e,
Quoted 4 lines
xen/arch/arm/setup.c +0
-0if ( s < r_e && r_s < e ) {
Cheers,
Signature · 1 line
Julien Grall
PATCH 3/10 xen/arm: introduce PGC_reserved
In reply to Penny ZhengIn order to differentiate pages of static memory, from those allocated from heap, this patch introduces a new page flag PGC_reserved to tell.
New struct reserved in struct page_info is to describe reserved page info, that is, which specific domain this page is reserved to.
Helper page_get_reserved_owner and page_set_reserved_owner are designated to get/set reserved page's owner.
Struct domain is enlarged to more than PAGE_SIZE, due to newly-imported struct reserved in struct page_info.
--- xen/include/asm-arm/mm.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
xen/include/asm-arm/mm.h +15 -1
@@ -88,7 +88,15 @@ struct page_info*/ u32 tlbflush_timestamp; }; -u64 pad; + +/* Page is reserved. */ +struct { +/* +* Reserved Owner of this page, +* if this page is reserved to a specific domain. +*/ +struct domain *domain; + } reserved; };#define PG_shift (idx) (BITS_PER_LONG - (idx))
@@ -108,6 +116,9 @@ struct page_info/* Page is Xen heap? */ #define _PGC_xen_heap PG_shift(2)#define PGC_xen_heap PG_mask(1, 2) +/* Page is reserved, referring static memory */ +#define _PGC_reserved PG_shift(3) +#define PGC_reserved PG_mask(1, 3)/* ... */ /* Page is broken? */ #define _PGC_broken PG_shift(7)
@@ -161,6 +172,9 @@ extern unsigned long xenheap_base_pdx;#define page_get_owner (_p) (_p)->v.inuse.domain#define page_set_owner (_p,_d) ((_p)->v.inuse.domain = (_d)) +#define page_get_reserved_owner (_p) (_p)->reserved.domain +#define page_set_reserved_owner (_p,_d) ((_p)->reserved.domain = (_d)) +#define maddr_get_owner (ma) (page_get_owner(maddr_to_page((ma))))#define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)
Signature · 1 line
2.25.1
Re: [PATCH 03/10] xen/arm: introduce PGC_reserved
Quoted 10 lines · Penny Zheng
In order to differentiate pages of static memory, from those allocated from heap, this patch introduces a new page flag
PGC_reservedto tell.New struct reserved in struct
page_infois to describe reserved page info, that is, which specific domain this page is reserved to. > Helperpage_get_reserved_ownerandpage_set_reserved_ownerare designated to get/set reserved page's owner.Struct domain is enlarged to more than
PAGE_SIZE, due to newly-imported struct reserved in structpage_info.
struct domain may embed a pointer to a struct page_info but never directly embed the structure. So can you clarify what you mean?
Quoted 14 lines
Signed-off-by Penny Zheng <[email protected]>--- xen/include/asm-arm/mm.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)xen/include/asm-arm/mm.h +0
-0@@ -88,7 +88,15 @@ struct page_info*/ u32 tlbflush_timestamp; };
xen/include/asm-arm/mm.h struct page_info · line 99
Quoted 10 lines
xen/include/asm-arm/mm.h +9
-1-u64 pad; + +/* Page is reserved. */ +struct { +/* +* Reserved Owner of this page, +* if this page is reserved to a specific domain. +*/ +struct domain *domain; + } reserved;
The space in page_info is quite tight, so I would like to avoid introducing new fields unless we can't get away from it.
In this case, it is not clear why we need to differentiate the "Owner" vs the "Reserved Owner". It might be clearer if this change is folded in the first user of the field.
As an aside, for 32-bit Arm, you need to add a 4-byte padding.
xen/include/asm-arm/mm.h struct page_info · line 119
Quoted 8 lines
xen/include/asm-arm/mm.h +1
-0};#define PG_shift (idx) (BITS_PER_LONG - (idx))@@ -108,6 +116,9 @@ struct page_info/* Page is Xen heap? */ #define _PGC_xen_heap PG_shift(2)#define PGC_xen_heap PG_mask(1, 2) +/* Page is reserved, referring static memory */
I would drop the second part of the sentence because the flag could be used for other purpose. One example is reserved memory when Live Updating.
Quoted 7 lines
xen/include/asm-arm/mm.h +2
-0+#define _PGC_reserved PG_shift(3) +#define PGC_reserved PG_mask(1, 3)/* ... */ /* Page is broken? */ #define _PGC_broken PG_shift(7)
xen/include/asm-arm/mm.h extern unsigned long xenheap_base_pdx; · line 180
Quoted 9 lines
xen/include/asm-arm/mm.h +3
-0@@ -161,6 +172,9 @@ extern unsigned long xenheap_base_pdx;#define page_get_owner (_p) (_p)->v.inuse.domain#define page_set_owner (_p,_d) ((_p)->v.inuse.domain = (_d)) +#define page_get_reserved_owner (_p) (_p)->reserved.domain +#define page_set_reserved_owner (_p,_d) ((_p)->reserved.domain = (_d)) +#define maddr_get_owner (ma) (page_get_owner(maddr_to_page((ma))))#define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 03/10] xen/arm: introduce PGC_reserved
Hi Julien
Quoted 55 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 5:46 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 03/10] xen/arm: introducePGC_reservedQuoted 10 lines · Penny Zheng
In order to differentiate pages of static memory, from those allocated from heap, this patch introduces a new page flag
PGC_reservedto tell.New struct reserved in struct
page_infois to describe reserved page info, that is, which specific domain this page is reserved to. > Helperpage_get_reserved_ownerandpage_set_reserved_ownerare designated to get/set reserved page's owner.Struct domain is enlarged to more than
PAGE_SIZE, due to newly-imported struct reserved in structpage_info.struct domain may embed a pointer to a struct
page_infobut never directly embed the structure. So can you clarify what you mean?xen/include/asm-arm/mm.h
Quoted 7 lines
Signed-off-by Penny Zheng <[email protected]>--- xen/include/asm-arm/mm.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)xen/include/asm-arm/mm.h +0
-0index
Quoted 7 lines
0b7de3102e..d8922fd5db100644xen/include/asm-arm/mm.h +0
-0@@ -88,7 +88,15 @@ struct page_info*/ u32 tlbflush_timestamp; };xen/include/asm-arm/mm.h struct page_info · line 99
Quoted 10 lines
xen/include/asm-arm/mm.h +9
-1-u64 pad; + +/* Page is reserved. */ +struct { +/* +* Reserved Owner of this page, +* if this page is reserved to a specific domain. +*/ +struct domain *domain; + } reserved;The space in
page_infois quite tight, so I would like to avoid introducing new fields unless we can't get away from it.
Quoted 6 lines
In this case, it is not clear why we need to differentiate the "Owner" vs the "Reserved Owner". It might be clearer if this change is folded in the first user of the field.
As an aside, for 32-bit Arm, you need to add a 4-byte padding.
Yeah, I may delete this change. I imported this change as considering the functionality of rebooting domain on static allocation.
A little more discussion on rebooting domain on static allocation. Considering the major user cases for domain on static allocation
are system has a total pre-defined, static behavior all the time. No domain allocation on runtime, while there still exists domain rebooting.
And when rebooting domain on static allocation, all these reserved pages could not go back to heap when freeing them. So I am considering to use one global struct page_info*[DOMID] value to store.
As Jan suggested, when domain get rebooted, struct domain will not exist anymore. But I think DOMID info could last.
Quoted 12 lines
xen/include/asm-arm/mm.h struct page_info · line 119
Quoted 8 lines
xen/include/asm-arm/mm.h +1
-0};#define PG_shift (idx) (BITS_PER_LONG - (idx))@@ -108,6 +116,9 @@ struct page_info/* Page is Xen heap? */ #define _PGC_xen_heap PG_shift(2)#define PGC_xen_heap PG_mask(1, 2) +/* Page is reserved, referring static memory */ I would drop the second part of the sentence because the flag could be used for other purpose. One example is reserved memory when Live Updating.
Sure, I will drop it.
Quoted 14 lines
Quoted 14 lines
xen/include/asm-arm/mm.h +5
-0+#define _PGC_reserved PG_shift(3) +#define PGC_reserved PG_mask(1, 3)/* ... */ /* Page is broken? */ #define _PGC_broken PG_shift(7)@@ -161,6 +172,9 @@ extern unsigned long xenheap_base_pdx;#define page_get_owner (_p) (_p)->v.inuse.domain#define page_set_owner (_p,_d) ((_p)->v.inuse.domain = (_d)) +#define page_get_reserved_owner (_p) (_p)->reserved.domain +#define page_set_reserved_owner (_p,_d) ((_p)->reserved.domain = (_d)) +#define maddr_get_owner (ma) (page_get_owner(maddr_to_page((ma))))
Quoted 7 lines
xen/include/asm-arm/mm.h extern unsigned long xenheap_base_pdx; · line 180
Quoted 2 lines
xen/include/asm-arm/mm.h +0
-0#define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)Cheers,
--
Julien Grall
Cheers,
Penny Zheng
Re: [PATCH 03/10] xen/arm: introduce PGC_reserved
Quoted 34 lines · Penny Zheng
Quoted 24 lines
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 5:46 PMQuoted 6 lines · Penny Zheng
xen/include/asm-arm/mm.h +0
-0@@ -88,7 +88,15 @@ struct page_info*/ u32 tlbflush_timestamp; };xen/include/asm-arm/mm.h struct page_info · line 99
Quoted 10 lines
xen/include/asm-arm/mm.h +9
-1-u64 pad; + +/* Page is reserved. */ +struct { +/* +* Reserved Owner of this page, +* if this page is reserved to a specific domain. +*/ +struct domain *domain; + } reserved;The space in
page_infois quite tight, so I would like to avoid introducing new fields unless we can't get away from it.Quoted 6 lines
In this case, it is not clear why we need to differentiate the "Owner" vs the "Reserved Owner". It might be clearer if this change is folded in the first user of the field.
As an aside, for 32-bit Arm, you need to add a 4-byte padding.
Yeah, I may delete this change. I imported this change as considering the functionality of rebooting domain on static allocation.
Quoted 8 lines
A little more discussion on rebooting domain on static allocation. Considering the major user cases for domain on static allocation
are system has a total pre-defined, static behavior all the time. No domain allocation on runtime, while there still exists domain rebooting.And when rebooting domain on static allocation, all these reserved pages could not go back to heap when freeing them. So I am considering to use one global
struct page_info*[DOMID]value to store.
Except such a separate array will consume quite a bit of space for no real gain: v.free has 32 bits of padding space right now on Arm64, so there's room for a domid_t there already. Even on Arm32 this could be arranged for, as I doubt "order" needs to be 32 bits wide.
Jan
Re: [PATCH 03/10] xen/arm: introduce PGC_reserved
Hi Jan,
Quoted 44 lines · Jan Beulich
Quoted 34 lines · Penny Zheng
Quoted 24 lines
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 5:46 PMQuoted 6 lines · Penny Zheng
xen/include/asm-arm/mm.h +0
-0@@ -88,7 +88,15 @@ struct page_info*/ u32 tlbflush_timestamp; };xen/include/asm-arm/mm.h struct page_info · line 99
Quoted 10 lines
xen/include/asm-arm/mm.h +9
-1-u64 pad; + +/* Page is reserved. */ +struct { +/* +* Reserved Owner of this page, +* if this page is reserved to a specific domain. +*/ +struct domain *domain; + } reserved;The space in
page_infois quite tight, so I would like to avoid introducing new fields unless we can't get away from it.Quoted 6 lines
In this case, it is not clear why we need to differentiate the "Owner" vs the "Reserved Owner". It might be clearer if this change is folded in the first user of the field.
As an aside, for 32-bit Arm, you need to add a 4-byte padding.
Yeah, I may delete this change. I imported this change as considering the functionality of rebooting domain on static allocation.
Quoted 8 lines
A little more discussion on rebooting domain on static allocation. Considering the major user cases for domain on static allocation
are system has a total pre-defined, static behavior all the time. No domain allocation on runtime, while there still exists domain rebooting.And when rebooting domain on static allocation, all these reserved pages could not go back to heap when freeing them. So I am considering to use one global
struct page_info*[DOMID]value to store.
Quoted 5 lines
Except such a separate array will consume quite a bit of space for no real gain: v.free has 32 bits of padding space right now on Arm64, so there's room for a
domid_tthere already. Even on Arm32 this could be arranged for, as I doubt "order" needs to be 32 bits wide.
I agree we shouldn't need 32-bit to cover the "order". Although, I would like to see any user reading the field before introducing it.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 03/10] xen/arm: introduce PGC_reserved
Quoted 45 lines · Julien Grall
Quoted 44 lines · Jan Beulich
Quoted 42 lines · Penny Zheng
Quoted 24 lines
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 5:46 PMQuoted 6 lines · Penny Zheng
xen/include/asm-arm/mm.h +0
-0@@ -88,7 +88,15 @@ struct page_info*/ u32 tlbflush_timestamp; };xen/include/asm-arm/mm.h struct page_info · line 99
Quoted 10 lines
xen/include/asm-arm/mm.h +9
-1-u64 pad; + +/* Page is reserved. */ +struct { +/* +* Reserved Owner of this page, +* if this page is reserved to a specific domain. +*/ +struct domain *domain; + } reserved;The space in
page_infois quite tight, so I would like to avoid introducing new fields unless we can't get away from it.Quoted 6 lines
In this case, it is not clear why we need to differentiate the "Owner" vs the "Reserved Owner". It might be clearer if this change is folded in the first user of the field.
As an aside, for 32-bit Arm, you need to add a 4-byte padding.
Yeah, I may delete this change. I imported this change as considering the functionality of rebooting domain on static allocation.
A little more discussion on rebooting domain on static allocation. Considering the major user cases for domain on static allocation
are system has a total pre-defined, static behavior all the time. No domain allocation on runtime, while there still exists domain rebooting.And when rebooting domain on static allocation, all these reserved pages could not go back to heap when freeing them. So I am considering to use one global
struct page_info*[DOMID]value to store.
Quoted 8 lines
Quoted 5 lines
Except such a separate array will consume quite a bit of space for no real gain: v.free has 32 bits of padding space right now on Arm64, so there's room for a
domid_tthere already. Even on Arm32 this could be arranged for, as I doubt "order" needs to be 32 bits wide.I agree we shouldn't need 32-bit to cover the "order". Although, I would like to see any user reading the field before introducing it.
Of course, but I thought the plan was to mark static pages with their designated domid, which would happen prior to domain creation. The reader of the field would then naturally appear during domain creation.
Jan
Re: [PATCH 03/10] xen/arm: introduce PGC_reserved
In reply to Penny ZhengQuoted 1 line · Penny Zheng
Hi Julien
Hi Penny,
Quoted 63 lines
Quoted 56 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 5:46 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 03/10] xen/arm: introducePGC_reservedQuoted 10 lines · Penny Zheng
In order to differentiate pages of static memory, from those allocated from heap, this patch introduces a new page flag
PGC_reservedto tell.New struct reserved in struct
page_infois to describe reserved page info, that is, which specific domain this page is reserved to. > Helperpage_get_reserved_ownerandpage_set_reserved_ownerare designated to get/set reserved page's owner.Struct domain is enlarged to more than
PAGE_SIZE, due to newly-imported struct reserved in structpage_info.struct domain may embed a pointer to a struct
page_infobut never directly embed the structure. So can you clarify what you mean?xen/include/asm-arm/mm.h
Quoted 7 lines
Signed-off-by Penny Zheng <[email protected]>--- xen/include/asm-arm/mm.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)xen/include/asm-arm/mm.h +0
-0index
Quoted 7 lines
0b7de3102e..d8922fd5db100644xen/include/asm-arm/mm.h +0
-0@@ -88,7 +88,15 @@ struct page_info*/ u32 tlbflush_timestamp; };xen/include/asm-arm/mm.h struct page_info · line 99
Quoted 10 lines
xen/include/asm-arm/mm.h +9
-1-u64 pad; + +/* Page is reserved. */ +struct { +/* +* Reserved Owner of this page, +* if this page is reserved to a specific domain. +*/ +struct domain *domain; + } reserved;The space in
page_infois quite tight, so I would like to avoid introducing new fields unless we can't get away from it.Quoted 6 lines
In this case, it is not clear why we need to differentiate the "Owner" vs the "Reserved Owner". It might be clearer if this change is folded in the first user of the field.
As an aside, for 32-bit Arm, you need to add a 4-byte padding.
Quoted 7 lines
Yeah, I may delete this change. I imported this change as considering the functionality of rebooting domain on static allocation.
A little more discussion on rebooting domain on static allocation. Considering the major user cases for domain on static allocation
are system has a total pre-defined, static behavior all the time. No domain allocation on runtime, while there still exists domain rebooting.
Hmmm... With this series it is still possible to allocate memory at runtime outside of the static allocation (see my comment on the design document [1]). So is it meant to be complete?
Quoted 7 lines
And when rebooting domain on static allocation, all these reserved pages could not go back to heap when freeing them. So I am considering to use one global
struct page_info*[DOMID]value to store.As Jan suggested, when domain get rebooted, struct domain will not exist anymore. But I think DOMID info could last.
You would need to make sure the domid to be reserved. But I am not entirely convinced this is necessary here.
When recreating the domain, you need a way to know its configuration. Mostly likely this will come from the Device-Tree. At which point, you can also find the static region from there.
Cheers,
[1] <[email protected]>
Signature · 1 line
Julien Grall
RE: [PATCH 03/10] xen/arm: introduce PGC_reserved
Hi Julien
Quoted 83 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Thursday, May 20, 2021 3:46 AM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 03/10] xen/arm: introducePGC_reservedQuoted 1 line · Penny Zheng
Hi Julien
Hi Penny,
Quoted 12 lines
Quoted 12 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 5:46 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 03/10] xen/arm: introducePGC_reservedQuoted 3 lines
Quoted 3 lines · Penny Zheng
Quoted 2 lines
In order to differentiate pages of static memory, from those allocated from heap, this patch introduces a new page flag
PGC_reservedto tell.
Quoted 51 lines
Quoted 41 lines
Quoted 8 lines
New struct reserved in struct
page_infois to describe reserved page info, that is, which specific domain this page is reserved to. > Helperpage_get_reserved_ownerandpage_set_reserved_ownerare designated to get/set reserved page's owner.Struct domain is enlarged to more than
PAGE_SIZE, due to newly-imported struct reserved in structpage_info.struct domain may embed a pointer to a struct
page_infobut never directly embed the structure. So can you clarify what you mean?xen/include/asm-arm/mm.h
Quoted 7 lines
Signed-off-by Penny Zheng <[email protected]>--- xen/include/asm-arm/mm.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)xen/include/asm-arm/mm.h +0
-0index
Quoted 7 lines
0b7de3102e..d8922fd5db100644xen/include/asm-arm/mm.h +0
-0@@ -88,7 +88,15 @@ struct page_info*/ u32 tlbflush_timestamp; };xen/include/asm-arm/mm.h struct page_info · line 99
Quoted 10 lines
xen/include/asm-arm/mm.h +9
-1-u64 pad; + +/* Page is reserved. */ +struct { +/* +* Reserved Owner of this page, +* if this page is reserved to a specific domain. +*/ +struct domain *domain; + } reserved;The space in
page_infois quite tight, so I would like to avoid introducing new fields unless we can't get away from it.Quoted 6 lines
In this case, it is not clear why we need to differentiate the "Owner" vs the "Reserved Owner". It might be clearer if this change is folded in the first user of the field.
As an aside, for 32-bit Arm, you need to add a 4-byte padding.
Yeah, I may delete this change. I imported this change as considering the functionality of rebooting domain on static allocation.
Quoted 9 lines
Quoted 4 lines
A little more discussion on rebooting domain on static allocation. Considering the major user cases for domain on static allocation are system has a total pre-defined, static behavior all the time. No domain allocation on runtime, while there still exists domain rebooting.
Hmmm... With this series it is still possible to allocate memory at runtime outside of the static allocation (see my comment on the design document [1]). So is it meant to be complete?
I'm guessing that the "allocate memory at runtime outside of the static allocation" is referring to XEN heap on static allocation, that is, users pre-defining heap in device tree configuration to let the whole system more static and predictable.
And I've replied you in the design there, sorry for the late reply. Save your time, and I’ll paste here:
"Right now, on AArch64, all RAM, except reserved memory, will be finally given to buddy allocator as heap, like you said, guest RAM for normal domain will be allocated from there, xmalloc eventually is get memory from there, etc. So we want to refine the heap here, not iterating through bootinfo.mem to set up XEN heap, but like iterating bootinfo. reserved_heap to set up XEN heap.
On ARM32, xen heap and domain heap are separately mapped, which is more complicated here. That's why I only talking about implementing these features on AArch64 as first step."
Above implementation will be delivered through another patch Serie. This patch Serie
Is only focusing on Domain on Static Allocation.
Quoted 6 lines
Quoted 6 lines
And when rebooting domain on static allocation, all these reserved pages could not go back to heap when freeing them. So I am considering to use one global
struct page_info*[DOMID]value to store.As Jan suggested, when domain get rebooted, struct domain will not exist
Quoted 9 lines
anymore.
Quoted 1 line
But I think DOMID info could last.
You would need to make sure the domid to be reserved. But I am not entirely convinced this is necessary here.
When recreating the domain, you need a way to know its configuration. Mostly likely this will come from the Device-Tree. At which point, you can also find the static region from there.
True, true. I'll dig more in your suggestion, thx. 😉
Quoted 6 lines
Cheers,
[1] <[email protected]>
--
Julien Grall
Cheers
Penny
RE: [PATCH 03/10] xen/arm: introduce PGC_reserved
Hi julien
Quoted 121 lines
-----Original Message-----
From: Penny Zheng
Sent: Thursday, May 20, 2021 2:20 PM
To: Julien Grall <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH 03/10] xen/arm: introducePGC_reservedHi Julien
Quoted 84 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Thursday, May 20, 2021 3:46 AM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 03/10] xen/arm: introducePGC_reservedQuoted 1 line · Penny Zheng
Hi Julien
Hi Penny,
Quoted 12 lines
Quoted 12 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 5:46 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 03/10] xen/arm: introducePGC_reservedQuoted 4 lines
Quoted 4 lines · Penny Zheng
Quoted 3 lines
In order to differentiate pages of static memory, from those allocated from heap, this patch introduces a new page flag
PGC_reservedto tell.
Quoted 51 lines
Quoted 41 lines
Quoted 8 lines
New struct reserved in struct
page_infois to describe reserved page info, that is, which specific domain this page is reserved to. > Helperpage_get_reserved_ownerandpage_set_reserved_ownerare designated to get/set reserved page's owner.Struct domain is enlarged to more than
PAGE_SIZE, due to newly-imported struct reserved in structpage_info.struct domain may embed a pointer to a struct
page_infobut never directly embed the structure. So can you clarify what you mean?xen/include/asm-arm/mm.h
Quoted 7 lines
Signed-off-by Penny Zheng <[email protected]>--- xen/include/asm-arm/mm.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)xen/include/asm-arm/mm.h +0
-0index
Quoted 7 lines
0b7de3102e..d8922fd5db100644xen/include/asm-arm/mm.h +0
-0@@ -88,7 +88,15 @@ struct page_info*/ u32 tlbflush_timestamp; };xen/include/asm-arm/mm.h struct page_info · line 99
Quoted 10 lines
xen/include/asm-arm/mm.h +9
-1-u64 pad; + +/* Page is reserved. */ +struct { +/* +* Reserved Owner of this page, +* if this page is reserved to a specific domain. +*/ +struct domain *domain; + } reserved;The space in
page_infois quite tight, so I would like to avoid introducing new fields unless we can't get away from it.Quoted 6 lines
In this case, it is not clear why we need to differentiate the "Owner" vs the "Reserved Owner". It might be clearer if this change is folded in the first user of the field.
As an aside, for 32-bit Arm, you need to add a 4-byte padding.
Yeah, I may delete this change. I imported this change as considering the functionality of rebooting domain on static allocation.
Quoted 7 lines
Quoted 4 lines
A little more discussion on rebooting domain on static allocation. Considering the major user cases for domain on static allocation are system has a total pre-defined, static behavior all the time. No domain allocation on runtime, while there still exists domain rebooting.
Hmmm... With this series it is still possible to allocate memory at runtime outside of the static allocation (see my comment on the design
document [1]).
Quoted 2 lines
So is it meant to be complete?
I'm guessing that the "allocate memory at runtime outside of the static allocation" is referring to XEN heap on static allocation, that is, users pre- defining heap in device tree configuration to let the whole system more static and predictable.
And I've replied you in the design there, sorry for the late reply. Save your time, and I’ll paste here:
"Right now, on AArch64, all RAM, except reserved memory, will be finally given to buddy allocator as heap, like you said, guest RAM for normal domain will be allocated from there, xmalloc eventually is get memory from there, etc. So we want to refine the heap here, not iterating through
bootinfo.memto set up XEN heap, but like iteratingbootinfo. reserved_heapto set up XEN heap.
Quoted 7 lines
On ARM32, xen heap and domain heap are separately mapped, which is more complicated here. That's why I only talking about implementing these features on AArch64 as first step."
Above implementation will be delivered through another patch Serie. This
patch Serie Is only focusing on Domain on Static Allocation.
Oh, Second thought on this.
And I think you are referring to balloon in/out here, hmm, also, like I replied there:
"For issues on ballooning out or in, it is not supported here. Domain on Static Allocation and 1:1 direct-map are all based on dom0-less right now, so no PV, grant table, event channel, etc, considered.
Right now, it only supports device got passthrough into the guest."
Quoted 21 lines
Quoted 7 lines
Quoted 7 lines
And when rebooting domain on static allocation, all these reserved pages could not go back to heap when freeing them. So I am considering to use one global
struct page_info*[DOMID]value to store.As Jan suggested, when domain get rebooted, struct domain will not exist
Quoted 9 lines
anymore.
Quoted 1 line
But I think DOMID info could last.
You would need to make sure the domid to be reserved. But I am not entirely convinced this is necessary here.
When recreating the domain, you need a way to know its configuration. Mostly likely this will come from the Device-Tree. At which point, you can also find the static region from there.
True, true. I'll dig more in your suggestion, thx. 😉
Quoted 2 lines
Cheers,
Quoted 8 lines
Quoted 4 lines
[1] <[email protected]>
--
Julien GrallCheers
Penny
Cheers
Penny
Re: [PATCH 03/10] xen/arm: introduce PGC_reserved
Quoted 1 line · Penny Zheng
Hi julien
Hi Penny,
Quoted 126 lines
Quoted 126 lines
-----Original Message-----
From: Penny Zheng
Sent: Thursday, May 20, 2021 2:20 PM
To: Julien Grall <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH 03/10] xen/arm: introducePGC_reservedHi Julien
Quoted 84 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Thursday, May 20, 2021 3:46 AM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 03/10] xen/arm: introducePGC_reservedQuoted 1 line · Penny Zheng
Hi Julien
Hi Penny,
Quoted 12 lines
Quoted 12 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 5:46 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 03/10] xen/arm: introducePGC_reservedQuoted 4 lines
Quoted 4 lines · Penny Zheng
Quoted 3 lines
In order to differentiate pages of static memory, from those allocated from heap, this patch introduces a new page flag
PGC_reservedto tell.
Quoted 51 lines
Quoted 41 lines
Quoted 8 lines
New struct reserved in struct
page_infois to describe reserved page info, that is, which specific domain this page is reserved to. > Helperpage_get_reserved_ownerandpage_set_reserved_ownerare designated to get/set reserved page's owner.Struct domain is enlarged to more than
PAGE_SIZE, due to newly-imported struct reserved in structpage_info.struct domain may embed a pointer to a struct
page_infobut never directly embed the structure. So can you clarify what you mean?xen/include/asm-arm/mm.h
Quoted 7 lines
Signed-off-by Penny Zheng <[email protected]>--- xen/include/asm-arm/mm.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)xen/include/asm-arm/mm.h +0
-0index
Quoted 7 lines
0b7de3102e..d8922fd5db100644xen/include/asm-arm/mm.h +0
-0@@ -88,7 +88,15 @@ struct page_info*/ u32 tlbflush_timestamp; };xen/include/asm-arm/mm.h struct page_info · line 99
Quoted 10 lines
xen/include/asm-arm/mm.h +9
-1-u64 pad; + +/* Page is reserved. */ +struct { +/* +* Reserved Owner of this page, +* if this page is reserved to a specific domain. +*/ +struct domain *domain; + } reserved;The space in
page_infois quite tight, so I would like to avoid introducing new fields unless we can't get away from it.Quoted 6 lines
In this case, it is not clear why we need to differentiate the "Owner" vs the "Reserved Owner". It might be clearer if this change is folded in the first user of the field.
As an aside, for 32-bit Arm, you need to add a 4-byte padding.
Yeah, I may delete this change. I imported this change as considering the functionality of rebooting domain on static allocation.
Quoted 7 lines
Quoted 4 lines
A little more discussion on rebooting domain on static allocation. Considering the major user cases for domain on static allocation are system has a total pre-defined, static behavior all the time. No domain allocation on runtime, while there still exists domain rebooting.
Hmmm... With this series it is still possible to allocate memory at runtime outside of the static allocation (see my comment on the design
document [1]).
Quoted 2 lines
So is it meant to be complete?
I'm guessing that the "allocate memory at runtime outside of the static allocation" is referring to XEN heap on static allocation, that is, users pre- defining heap in device tree configuration to let the whole system more static and predictable.
And I've replied you in the design there, sorry for the late reply. Save your time, and I’ll paste here:
"Right now, on AArch64, all RAM, except reserved memory, will be finally given to buddy allocator as heap, like you said, guest RAM for normal domain will be allocated from there, xmalloc eventually is get memory from there, etc. So we want to refine the heap here, not iterating through
bootinfo.memto set up XEN heap, but like iteratingbootinfo. reserved_heapto set up XEN heap.On ARM32, xen heap and domain heap are separately mapped, which is more complicated here. That's why I only talking about implementing these features on AArch64 as first step."
Quoted 6 lines
Quoted 3 lines
Above implementation will be delivered through another patch Serie. This
patch Serie Is only focusing on Domain on Static Allocation.Oh, Second thought on this.
And I think you are referring to balloon in/out here, hmm, also, like
Yes I am referring to balloon in/out.
Quoted 2 lines
I replied there:
"For issues on ballooning out or in, it is not supported here.
So long you are not using the solution in prod then you are fine (see below)... But then we should make clear this feature is a tech preview.
Quoted 4 lines
Domain on Static Allocation and 1:1 direct-map are all based on dom0-less right now, so no PV, grant table, event channel, etc, considered.
Right now, it only supports device got passthrough into the guest."
So we are not creating the hypervisor node in the DT for dom0less domU. However, the hypercalls are still accessible by a domU if it really wants to use them.
Therefore, a guest can easily mess up with your static configuration and predictability.
IMHO, this is a must to solve before "static memory" can be used in production.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 03/10] xen/arm: introduce PGC_reserved
Quoted 21 lines · Julien Grall
Quoted 2 lines · Penny Zheng
Oh, Second thought on this.
And I think you are referring to balloon in/out here, hmm, also, likeYes I am referring to balloon in/out.
Quoted 2 lines
I replied there:
"For issues on ballooning out or in, it is not supported here.So long you are not using the solution in prod then you are fine (see below)... But then we should make clear this feature is a tech preview.
Quoted 4 lines
Domain on Static Allocation and 1:1 direct-map are all based on dom0-less right now, so no PV, grant table, event channel, etc, considered.
Right now, it only supports device got passthrough into the guest."
So we are not creating the hypervisor node in the DT for dom0less domU. However, the hypercalls are still accessible by a domU if it really wants to use them.
Quoted 5 lines
Therefore, a guest can easily mess up with your static configuration and predictability.
IMHO, this is a must to solve before "static memory" can be used in production.
I'm having trouble seeing why it can't be addressed right away: Such guests can balloon in only after they've ballooned out some pages, and such balloon-in requests would be satisfied from the same static memory that is associated by the guest anyway.
Jan
Re: [PATCH 03/10] xen/arm: introduce PGC_reserved
Hi Jan,
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Julien Grall
Quoted 2 lines · Penny Zheng
Oh, Second thought on this.
And I think you are referring to balloon in/out here, hmm, also, likeYes I am referring to balloon in/out.
Quoted 2 lines
I replied there:
"For issues on ballooning out or in, it is not supported here.So long you are not using the solution in prod then you are fine (see below)... But then we should make clear this feature is a tech preview.
Quoted 4 lines
Domain on Static Allocation and 1:1 direct-map are all based on dom0-less right now, so no PV, grant table, event channel, etc, considered.
Right now, it only supports device got passthrough into the guest."
So we are not creating the hypervisor node in the DT for dom0less domU. However, the hypercalls are still accessible by a domU if it really wants to use them.
Quoted 7 lines
Quoted 5 lines
Therefore, a guest can easily mess up with your static configuration and predictability.
IMHO, this is a must to solve before "static memory" can be used in production.
I'm having trouble seeing why it can't be addressed right away:
It can be solved right away. Dom0less domUs don't officially know they are running on Xen (they could bruteforce it though), so I think it would be fine to merge without it for a tech preview.
Quoted 4 lines
Such
guests can balloon in only after they've ballooned out some pages, and such balloon-in requests would be satisfied from the same static memory that is associated by the guest anyway.
This would require some bookeeping to know the page was used previously. But nothing very challenging though.
Cheers,
Signature · 1 line
Julien Grall
PATCH 4/10 xen/arm: static memory initialization
In reply to Penny ZhengThis patch introduces static memory initialization, during system RAM boot up.
New func init_staticmem_pages is the equivalent of init_heap_pages, responsible for static memory initialization.
Helper func free_staticmem_pages is the equivalent of free_heap_pages, to free nr_pfns pages of static memory.
For each page, it includes the following steps:
1. change page state from in-use(also initialization state) to free state and grant PGC_reserved.
2. set its owner NULL and make sure this page is not a guest frame any more
3. follow the same cache coherency policy in free_heap_pages
4. scrub the page in need
--- xen/arch/arm/setup.c | 2 ++ xen/common/page_alloc.c | 70 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/mm.h | 3 ++ 3 files changed, 75 insertions(+)
xen/arch/arm/setup.c +2 -0
@@ -818,6 +818,8 @@ static void __init setup_mm(void)setup_frametable_mappings (ram_start, ram_end); max_page =PFN_DOWN (ram_end); + + init_staticmem_pages(); }#endif
xen/common/page_alloc.c +70 -0
88 lines not on this page · raw message
xen/include/xen/mm.h +3 -0
@@ -85,6 +85,9 @@ bool scrub_free_pages(void); } while ( false )#define FREE_XENHEAP_PAGE (p) FREE_XENHEAP_PAGES(p, 0) +/* Static Memory */ +void init_staticmem_pages (void ); +/* Map machine page range in Xen virtual address space. */ int map_pages_to_xen( unsigned long virt,
Signature · 1 line
2.25.1
Re: [PATCH 04/10] xen/arm: static memory initialization
Quoted 11 lines · Penny Zheng
This patch introduces static memory initialization, during system RAM boot up.
New func
init_staticmem_pagesis the equivalent ofinit_heap_pages, responsible for static memory initialization.Helper func
free_staticmem_pagesis the equivalent offree_heap_pages, to freenr_pfnspages of static memory.
For each page, it includes the following steps:
1. change page state from in-use(also initialization state) to free state and grantPGC_reserved.
2. set its owner NULL and make sure this page is not a guest frame any more
But isn't the goal (as per the previous patch) to associate such pages with a _specific_ domain?
xen/common/page_alloc.c line 155
Quoted 9 lines
xen/common/page_alloc.c +3
-0@@ -150,6 +150,9 @@#define p2m_pod_offline_or_broken_hit (pg) 0#define p2m_pod_offline_or_broken_replace (pg) BUG_ON(pg != NULL)#endif +#ifdef CONFIG_ARM_64 +#include <asm/setup.h> +#endif
Whatever it is that's needed from this header suggests the code won't build for other architectures. I think init_staticmem_pages() in its current shape shouldn't live in this (common) file.
xen/common/page_alloc.c static void free_heap_pages( · line 1520
Quoted 7 lines
xen/common/page_alloc.c +3
-0@@ -1512,6 +1515,49 @@ static void free_heap_pages(spin_unlock (&heap_lock); } +/* Equivalent of free_heap_pages to free nr_pfns pages of static memory. */ +static void free_staticmem_pages (struct page_info *pg,unsigned long nr_pfns, +bool need_scrub)
Right now this function gets called only from an __init one. Unless it is intended to gain further callers, it should be marked __init itself then. Otherwise it should be made sure that other architectures don't include this (dead there) code.
xen/common/page_alloc.c static void free_heap_pages( · line 1523
Quoted 3 lines
xen/common/page_alloc.c +3
-0+{ +mfn_t mfn =page_to_mfn (pg); +int i;
This type doesn't fit nr_pfns'es.
Jan
RE: [PATCH 04/10] xen/arm: static memory initialization
Hi Jan
Quoted 24 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:16 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 04/10] xen/arm: static memory initializationQuoted 1 line · Penny Zheng
This patch introduces static memory initialization, during system RAM boot
up.
Quoted 11 lines
New func
init_staticmem_pagesis the equivalent ofinit_heap_pages, responsible for static memory initialization.Helper func
free_staticmem_pagesis the equivalent offree_heap_pages, to freenr_pfnspages of static memory.
For each page, it includes the following steps:
1. change page state from in-use(also initialization state) to free state and grantPGC_reserved.
2. set its owner NULL and make sure this page is not a guest frame any more
Quoted 3 lines
But isn't the goal (as per the previous patch) to associate such pages with a _specific_ domain?
Free_staticmem_pages are alike free_heap_pages, are not used only for initialization. Freeing used pages to unused are also included.
Here, setting its owner NULL is to set owner in used field NULL.
Still, I need to add more explanation here.
Quoted 4 lines
Quoted 4 lines
xen/common/page_alloc.c +0
-0@@ -150,6 +150,9 @@#define p2m_pod_offline_or_broken_hit (pg) 0 #define
Quoted 9 lines
xen/common/page_alloc.c line 155
Quoted 4 lines
p2m_pod_offline_or_broken_replace(pg)BUG_ON(pg != NULL)#endifxen/common/page_alloc.c +3
-0+#ifdef CONFIG_ARM_64 +#include <asm/setup.h> +#endif Whatever it is that's needed from this header suggests the code won't build for other architectures. I think
init_staticmem_pages()in its current shape shouldn't live in this (common) file.
Yes, I should include them all both under one specific config, maybe like CONFIG_STATIC_MEM, and this config is arm-specific.
Quoted 7 lines
xen/common/page_alloc.c static void free_heap_pages( · line 1519
Quoted 6 lines
xen/common/page_alloc.c +2
-0@@ -1512,6 +1515,49 @@ static void free_heap_pages(spin_unlock (&heap_lock); } +/* Equivalent of free_heap_pages to free nr_pfns pages of static +memory. */ static void free_staticmem_pages(struct page_info *pg,unsigned long
nr_pfns,
Quoted 7 lines
xen/common/page_alloc.c static void free_heap_pages( · line 1520
Quoted 1 line
xen/common/page_alloc.c +1
-0+ bool need_scrub)Right now this function gets called only from an
__initone. Unless it is intended to gain further callers, it should be marked__inititself then. Otherwise it should be made sure that other architectures don't include this (dead there) code.
Sure, I'll add __init. Thx.
Quoted 6 lines
xen/common/page_alloc.c static void free_heap_pages( · line 1523
Quoted 3 lines
xen/common/page_alloc.c +3
-0+{ +mfn_t mfn =page_to_mfn (pg); +int i;This type doesn't fit nr_pfns'es.
Sure, nr_mfns is better in also many other places.
Quoted 1 line
Jan
Re: [PATCH 04/10] xen/arm: static memory initialization
Quoted 18 lines · Penny Zheng
Quoted 18 lines
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:16 PMQuoted 1 line · Penny Zheng
This patch introduces static memory initialization, during system RAM boot
up.
Quoted 11 lines
New func
init_staticmem_pagesis the equivalent ofinit_heap_pages, responsible for static memory initialization.Helper func
free_staticmem_pagesis the equivalent offree_heap_pages, to freenr_pfnspages of static memory.
For each page, it includes the following steps:
1. change page state from in-use(also initialization state) to free state and grantPGC_reserved.
2. set its owner NULL and make sure this page is not a guest frame any more
Quoted 7 lines
Quoted 3 lines
But isn't the goal (as per the previous patch) to associate such pages with a _specific_ domain?
Free_staticmem_pagesare alikefree_heap_pages, are not used only for initialization. Freeing used pages to unused are also included.
Here, setting its owner NULL is to set owner in used field NULL.
I'm afraid I still don't understand.
Quoted 1 line
Still, I need to add more explanation here.
Yes please.
Quoted 9 lines
Quoted 9 lines
xen/common/page_alloc.c static void free_heap_pages( · line 1519
Quoted 6 lines
xen/common/page_alloc.c +2
-0@@ -1512,6 +1515,49 @@ static void free_heap_pages(spin_unlock (&heap_lock); } +/* Equivalent of free_heap_pages to free nr_pfns pages of static +memory. */ static void free_staticmem_pages(struct page_info *pg,unsigned long
nr_pfns,Quoted 1 line
xen/common/page_alloc.c +1
-0+ bool need_scrub)
Quoted 7 lines
Quoted 5 lines
Right now this function gets called only from an
__initone. Unless it is intended to gain further callers, it should be marked__inititself then. Otherwise it should be made sure that other architectures don't include this (dead there) code.Sure, I'll add
__init. Thx.
Didn't I see a 2nd call to the function later in the series? That one doesn't permit the function to be __init, iirc.
Jan
RE: [PATCH 04/10] xen/arm: static memory initialization
Hi Jan
Quoted 33 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 6:43 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 04/10] xen/arm: static memory initializationQuoted 23 lines · Penny Zheng
Quoted 22 lines
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:16 PMQuoted 2 lines · Penny Zheng
This patch introduces static memory initialization, during system RAM boot
up.
Quoted 11 lines
New func
init_staticmem_pagesis the equivalent ofinit_heap_pages, responsible for static memory initialization.Helper func
free_staticmem_pagesis the equivalent offree_heap_pages, to freenr_pfnspages of static memory. For each page, it includes the following steps:
1. change page state from in-use(also initialization state) to free state and grantPGC_reserved.
2. set its owner NULL and make sure this page is not a guest frame any moreBut isn't the goal (as per the previous patch) to associate such pages with a _specific_ domain?
Quoted 7 lines
Quoted 1 line
Free_staticmem_pagesare alikefree_heap_pages, are not used only forinitialization.
Quoted 2 lines
Freeing used pages to unused are also included.
Here, setting its owner NULL is to set owner in used field NULL.I'm afraid I still don't understand.
When initializing heap, xen is using free_heap_pages to do the initialization. And also when normal domain get destroyed/rebooted, xen is using free_domheap_pages, which calls free_heap_pages to free the pages.
So here, since free_staticmem_pages is the equivalent of the free_heap_pages for static memory, I'm also considering both two scenarios here. And if it is domain get destroyed/rebooted, Page state is in inuse state(PGC_inuse), and the page_info.v.inuse.domain is holding the domain owner.
When freeing then, we need to switch the page state to free state(PGC_free) and set its inuse owner to NULL.
I'll clarify it more clearly in commit message.
Quoted 19 lines
Quoted 1 line
Still, I need to add more explanation here.
Yes please.
Quoted 15 lines
Quoted 14 lines
xen/common/page_alloc.c static void free_heap_pages( · line 1519
Quoted 6 lines
xen/common/page_alloc.c +2
-0@@ -1512,6 +1515,49 @@ static void free_heap_pages(spin_unlock (&heap_lock); } +/* Equivalent of free_heap_pages to free nr_pfns pages of static +memory. */ static void free_staticmem_pages(struct page_info *pg,unsigned long
nr_pfns,xen/common/page_alloc.c static void free_heap_pages( · line 1520
Quoted 1 line
xen/common/page_alloc.c +1
-0+ bool need_scrub)Right now this function gets called only from an
__initone. Unless it is intended to gain further callers, it should be marked__inititself then. Otherwise it should be made sure that other architectures don't include this (dead there) code.
Quoted 6 lines
Quoted 1 line
Sure, I'll add
__init. Thx.Didn't I see a 2nd call to the function later in the series? That one doesn't permit the function to be
__init, iirc.Jan
Cheers
Penny
Re: [PATCH 04/10] xen/arm: static memory initialization
Quoted 47 lines · Penny Zheng
Hi Jan
Quoted 33 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 6:43 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 04/10] xen/arm: static memory initializationQuoted 23 lines · Penny Zheng
Quoted 22 lines
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:16 PMQuoted 2 lines · Penny Zheng
This patch introduces static memory initialization, during system RAM boot
up.
Quoted 11 lines
New func
init_staticmem_pagesis the equivalent ofinit_heap_pages, responsible for static memory initialization.Helper func
free_staticmem_pagesis the equivalent offree_heap_pages, to freenr_pfnspages of static memory. For each page, it includes the following steps:
1. change page state from in-use(also initialization state) to free state and grantPGC_reserved.
2. set its owner NULL and make sure this page is not a guest frame any moreBut isn't the goal (as per the previous patch) to associate such pages with a _specific_ domain?
Quoted 7 lines
Quoted 1 line
Free_staticmem_pagesare alikefree_heap_pages, are not used only forinitialization.
Quoted 2 lines
Freeing used pages to unused are also included.
Here, setting its owner NULL is to set owner in used field NULL.I'm afraid I still don't understand.
When initializing heap, xen is using
free_heap_pagesto do the initialization. And also when normal domain get destroyed/rebooted, xen is usingfree_domheap_pages, which callsfree_heap_pagesto free the pages.
Quoted 5 lines
So here, since
free_staticmem_pagesis the equivalent of thefree_heap_pagesfor static memory, I'm also considering both two scenarios here. And if it is domain get destroyed/rebooted, Page state is in inusestate(PGC_inuse), and the page_info.v.inuse.domain is holding the domain owner.
When freeing then, we need to switch the page state to freestate(PGC_free)and set its inuse owner to NULL.
Perhaps my confusion comes from your earlier outline missing
3. re-associate the page with the domain (as represented in free pages)
The property of "designated for Dom<N>" should never go away, if I understand the overall proposal correctly.
Jan
Re: [PATCH 04/10] xen/arm: static memory initialization
In reply to Penny ZhengHi Penny,
Quoted 49 lines · Penny Zheng
This patch introduces static memory initialization, during system RAM boot up.
New func
init_staticmem_pagesis the equivalent ofinit_heap_pages, responsible for static memory initialization.Helper func
free_staticmem_pagesis the equivalent offree_heap_pages, to freenr_pfnspages of static memory.
For each page, it includes the following steps:
1. change page state from in-use(also initialization state) to free state and grantPGC_reserved.
2. set its owner NULL and make sure this page is not a guest frame any more
3. follow the same cache coherency policy infree_heap_pages
4. scrub the page in needSigned-off-by Penny Zheng <[email protected]>--- xen/arch/arm/setup.c | 2 ++ xen/common/page_alloc.c | 70 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/mm.h | 3 ++ 3 files changed, 75 insertions(+)xen/arch/arm/setup.c +2
-0@@ -818,6 +818,8 @@ static void __init setup_mm(void)setup_frametable_mappings (ram_start, ram_end); max_page =PFN_DOWN (ram_end); + + init_staticmem_pages(); }#endif xen/common/page_alloc.c +3
-0@@ -150,6 +150,9 @@#define p2m_pod_offline_or_broken_hit (pg) 0#define p2m_pod_offline_or_broken_replace (pg) BUG_ON(pg != NULL)#endif +#ifdef CONFIG_ARM_64 +#include <asm/setup.h> +#endif /* * Comma-separated list of hexadecimal page numbers containing bad bytes.
xen/common/page_alloc.c static void free_heap_pages( · line 1519
Quoted 5 lines
xen/common/page_alloc.c +2
-0@@ -1512,6 +1515,49 @@ static void free_heap_pages(spin_unlock (&heap_lock); } +/* Equivalent of free_heap_pages to free nr_pfns pages of static memory. */ +static void free_staticmem_pages(struct page_info *pg, unsigned long nr_pfns,
This function is dealing with MFNs, so the second parameter should be called nr_mfns.
Quoted 26 lines
xen/common/page_alloc.c +26
-0+ bool need_scrub) +{ +mfn_t mfn =page_to_mfn (pg); +int i; + +for ( i =0 ; i < nr_pfns; i++ ) + { +switch ( pg[i].count_info & PGC_state ) + { +case PGC_state_inuse: +BUG_ON (pg[i].count_info & PGC_broken); +/* Make it free and reserved. */ + pg[i].count_info = PGC_state_free | PGC_reserved; +break ; + +default : +printk (XENLOG_ERR +"Page state shall be only in PGC_state_inuse. " +"pg[%u] MFN %" PRI_mfn" count_info=%#lx tlbflush_timestamp=%#x.\n" , + i,mfn_x (mfn) + i, + pg[i].count_info, + pg[i].tlbflush_timestamp); +BUG (); + } + +/*
xen/common/page_alloc.c static void free_heap_pages( · line 1555
Quoted 10 lines
xen/common/page_alloc.c +10
-0+* Follow the same cache coherence scheme in free_heap_pages. +* If a page has no owner it will need no safety TLB flush. +*/ + pg[i].u.free.need_tlbflush = (page_get_owner (&pg[i]) !=NULL ); +if ( pg[i].u.free.need_tlbflush ) +page_set_tlbflush_timestamp (&pg[i]); + +/* This page is not a guest frame any more. */ +page_set_owner (&pg[i],NULL ); +set_gpfn_from_mfn (mfn_x (mfn) + i,INVALID_M2P_ENTRY );
The code looks quite similar to free_heap_pages(). Could we possibly create an helper which can be called from both?
xen/common/page_alloc.c static void free_heap_pages( · line 1558
Quoted 3 lines
xen/common/page_alloc.c +3
-0+ +if ( need_scrub ) +scrub_one_page (&pg[i]);
So the scrubbing will be synchronous. Is it what we want?
You also seem to miss the flush the call to flush_page_to_ram().
Quoted 8 lines
xen/common/page_alloc.c +2
-0+ } +}/* * Following rules applied for page offline: @@ -1828,6 +1874,30 @@ static void init_heap_pages( } }
xen/common/page_alloc.c static void init_heap_pages( · line 1885
Quoted 10 lines
xen/common/page_alloc.c +9
-0+/* Equivalent of init_heap_pages to do static memory initialization */ +void __init init_staticmem_pages (void ) +{ +int bank; + +/* +* TODO: Considering NUMA-support scenario. +*/ +for ( bank =0 ; bank < bootinfo.static_mem.nr_banks; bank++ )
bootinfo is arm specific, so this code should live in arch/arm rather than common/.
Quoted 24 lines
xen/common/page_alloc.c +15
-0+ { +paddr_t bank_start = bootinfo.static_mem.bank[bank].start; +paddr_t bank_size = bootinfo.static_mem.bank[bank].size; +paddr_t bank_end = bank_start + bank_size; + + bank_start =round_pgup (bank_start); + bank_end =round_pgdown (bank_end); +if ( bank_end <= bank_start ) +return ; + +free_staticmem_pages (maddr_to_page (bank_start), + (bank_end - bank_start) >>PAGE_SHIFT , false); + } +} +static unsigned long avail_heap_pages (unsigned int zone_lo,unsigned int zone_hi,unsigned int node) {xen/include/xen/mm.h +0
-0
xen/include/xen/mm.h bool scrub_free_pages(void); · line 93
Quoted 9 lines
xen/include/xen/mm.h +3
-0@@ -85,6 +85,9 @@ bool scrub_free_pages(void); } while ( false )#define FREE_XENHEAP_PAGE (p) FREE_XENHEAP_PAGES(p, 0) +/* Static Memory */ +void init_staticmem_pages (void ); +/* Map machine page range in Xen virtual address space. */ int map_pages_to_xen( unsigned long virt,
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 04/10] xen/arm: static memory initialization
Quoted 98 lines · Julien Grall
Hi Penny,
Quoted 49 lines · Penny Zheng
This patch introduces static memory initialization, during system RAM boot up.
New func
init_staticmem_pagesis the equivalent ofinit_heap_pages, responsible for static memory initialization.Helper func
free_staticmem_pagesis the equivalent offree_heap_pages, to freenr_pfnspages of static memory.
For each page, it includes the following steps:
1. change page state from in-use(also initialization state) to free state and grantPGC_reserved.
2. set its owner NULL and make sure this page is not a guest frame any more
3. follow the same cache coherency policy infree_heap_pages
4. scrub the page in needSigned-off-by Penny Zheng <[email protected]>---
xen/arch/arm/setup.c | 2 ++
xen/common/page_alloc.c| 70 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/mm.h | 3 ++3 files changed, 75 insertions(+)xen/arch/arm/setup.c +2
-0@@ -818,6 +818,8 @@ static void __init setup_mm(void) setup_frametable_mappings(ram_start, ram_end); max_page = PFN_DOWN(ram_end); + + init_staticmem_pages(); } #endifxen/common/page_alloc.c +4
-0@@ -150,6 +150,9 @@ #define p2m_pod_offline_or_broken_hit(pg) 0 #define p2m_pod_offline_or_broken_replace(pg) BUG_ON(pg != NULL) #endif +#ifdef CONFIG_ARM_64 +#include <asm/setup.h> +#endif /** Comma-separated list of hexadecimal page numbers containing bad bytes. @@ -1512,6 +1515,49 @@ static void free_heap_pages( spin_unlock(&heap_lock); } +/* Equivalent of free_heap_pages to free nr_pfns pages of static Quoted 3 lines
memory. */
+static void free_staticmem_pages(structpage_info*pg, unsigned longnr_pfns,This function is dealing with MFNs, so the second parameter should be called
nr_mfns.Quoted 27 lines
+ bool
need_scrub)xen/common/page_alloc.c +18
-0+{ + mfn_t mfn = page_to_mfn(pg); + int i; + + for ( i = 0; i < nr_pfns; i++ ) + { + switch ( pg[i].count_info & PGC_state ) + { + case PGC_state_inuse: + BUG_ON(pg[i].count_info & PGC_broken); + /* Make it free and reserved. */ + pg[i].count_info = PGC_state_free | PGC_reserved; + break; + + default: + printk(XENLOG_ERR + "Page state shall be only in PGC_state_inuse. " + "pg[%u] MFN %"PRI_mfn" count_info=%#lxtlbflush_timestamp=%#x.\n",
+ i,mfn_x(mfn)+ i,
+ pg[i].count_info,
+ pg[i].tlbflush_timestamp);
+BUG();
+ }xen/common/page_alloc.c +2
-0+ + /*xen/common/page_alloc.c static void free_heap_pages( · line 1555
Quoted 10 lines
xen/common/page_alloc.c +10
-0+* Follow the same cache coherence scheme in free_heap_pages. +* If a page has no owner it will need no safety TLB flush. +*/ + pg[i].u.free.need_tlbflush = (page_get_owner(&pg[i]) != NULL); + if ( pg[i].u.free.need_tlbflush ) + page_set_tlbflush_timestamp(&pg[i]); + + /* This page is not a guest frame any more. */ + page_set_owner(&pg[i], NULL); + set_gpfn_from_mfn(mfn_x(mfn) + i, INVALID_M2P_ENTRY);The code looks quite similar to
free_heap_pages(). Could we possibly create an helper which can be called from both?
Quoted 7 lines
Quoted 3 lines
+
+ if (need_scrub)
+scrub_one_page(&pg[i]);So the scrubbing will be synchronous. Is it what we want?
You also seem to miss the flush the call to
flush_page_to_ram().
Hmmmm... Sorry I looked at the wrong function. This is not necessary for the free part.
Quoted 56 lines
Quoted 7 lines
+ }
+}
/*
* Following rules applied for page offline:xen/common/page_alloc.c +0
-0@@ -1828,6 +1874,30 @@ static void init_heap_pages( }xen/common/page_alloc.c static void init_heap_pages( · line 1884
Quoted 10 lines
xen/common/page_alloc.c +9
-0} +/* Equivalent of init_heap_pages to do static memory initialization */ +void __init init_staticmem_pages (void ) +{ + int bank; + + /* + * TODO: Considering NUMA-support scenario. + */ + for ( bank = 0 ; bank < bootinfo.static_mem.nr_banks; bank++ )bootinfo is arm specific, so this code should live in
arch/armrather than common/.Quoted 30 lines
xen/common/page_alloc.c +15
-0+ { + paddr_t bank_start = bootinfo.static_mem.bank[bank].start; + paddr_t bank_size = bootinfo.static_mem.bank[bank].size; + paddr_t bank_end = bank_start + bank_size; + + bank_start = round_pgup(bank_start); + bank_end = round_pgdown(bank_end); + if ( bank_end <= bank_start ) + return; + + free_staticmem_pages(maddr_to_page(bank_start), + (bank_end - bank_start) >> PAGE_SHIFT, false); + } +} +static unsigned long avail_heap_pages(
unsigned intzone_lo, unsigned intzone_hi, unsigned int node) {xen/include/xen/mm.h +3
-0@@ -85,6 +85,9 @@ bool scrub_free_pages(void); } while ( false ) #define FREE_XENHEAP_PAGE(p) FREE_XENHEAP_PAGES(p, 0) +/* Static Memory */ +void init_staticmem_pages (void ); + /* Map machine page range in Xen virtual address space. */Quoted 3 lines
int map_pages_to_xen(
unsigned long virt,Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 04/10] xen/arm: static memory initialization
In reply to Julien GrallHi Julien
Quoted 67 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 6:01 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 04/10] xen/arm: static memory initializationHi Penny,
Quoted 1 line · Penny Zheng
This patch introduces static memory initialization, during system RAM boot
up.
Quoted 13 lines
New func
init_staticmem_pagesis the equivalent ofinit_heap_pages, responsible for static memory initialization.Helper func
free_staticmem_pagesis the equivalent offree_heap_pages, to freenr_pfnspages of static memory.
For each page, it includes the following steps:
1. change page state from in-use(also initialization state) to free state and grantPGC_reserved.
2. set its owner NULL and make sure this page is not a guest frame any more 3. follow the same cache coherency policy infree_heap_pages4. scrub the page in needQuoted 4 lines
Signed-off-by Penny Zheng <[email protected]>--- xen/arch/arm/setup.c | 2 ++ xen/common/page_alloc.c | 70+++++++++++++++++++++++++++++++++++++++++
Quoted 21 lines
xen/include/xen/mm.h | 3 ++ 3 files changed, 75 insertions(+)xen/arch/arm/setup.c index renamed from xen/arch/arm/setup.c +0
-0
444dbbd676..f80162c478100644xen/arch/arm/setup.c +2
-0@@ -818,6 +818,8 @@ static void __init setup_mm(void)setup_frametable_mappings (ram_start, ram_end); max_page =PFN_DOWN (ram_end); + + init_staticmem_pages(); }#endif xen/common/page_alloc.c index renamed from xen/common/page_alloc.c +0
-0
ace6333c18..58b53c6ac2100644xen/common/page_alloc.c line 158
Quoted 9 lines
xen/common/page_alloc.c +3
-0@@ -150,6 +150,9 @@#define p2m_pod_offline_or_broken_hit (pg) 0#define p2m_pod_offline_or_broken_replace (pg) BUG_ON(pg != NULL)#endif +#ifdef CONFIG_ARM_64 +#include <asm/setup.h> +#endif /* * Comma-separated list of hexadecimal page numbers containing bad bytes.
Quoted 4 lines
xen/common/page_alloc.c +0
-0@@ -1512,6 +1515,49 @@ static void free_heap_pages(spin_unlock (&heap_lock); }
Quoted 7 lines
xen/common/page_alloc.c static void free_heap_pages( · line 1520
Quoted 3 lines
xen/common/page_alloc.c +3
-0+/* Equivalent of free_heap_pages to free nr_pfns pages of static +memory. */ static void free_staticmem_pages(struct page_info *pg, +unsigned long nr_pfns,This function is dealing with MFNs, so the second parameter should be called
nr_mfns.
Agreed, thx.
Quoted 31 lines
Quoted 8 lines
xen/common/page_alloc.c +8
-0+ bool need_scrub) { +mfn_t mfn =page_to_mfn (pg); +int i; + +for ( i =0 ; i < nr_pfns; i++ ) + { +switch ( pg[i].count_info & PGC_state ) + {xen/common/page_alloc.c static void free_heap_pages(
Quoted 10 lines
xen/common/page_alloc.c +10
-0+case PGC_state_inuse: +BUG_ON (pg[i].count_info & PGC_broken); +/* Make it free and reserved. */ + pg[i].count_info = PGC_state_free | PGC_reserved; +break ; + +default : +printk (XENLOG_ERR +"Page state shall be only in PGC_state_inuse. " + "pg[%u] MFN %"PRI_mfn" count_info=%#lxtlbflush_timestamp=%#x.\n",
Quoted 12 lines
xen/common/page_alloc.c +12
-0+ i,mfn_x (mfn) + i, + pg[i].count_info, + pg[i].tlbflush_timestamp); +BUG (); + } + +/* +* Follow the same cache coherence scheme in free_heap_pages. +* If a page has no owner it will need no safety TLB flush. +*/ + pg[i].u.free.need_tlbflush = (page_get_owner (&pg[i]) !=NULL ); +if ( pg[i].u.free.need_tlbflush )
Quoted 9 lines
xen/common/page_alloc.c static void free_heap_pages( · line 1555
Quoted 5 lines
xen/common/page_alloc.c +5
-0+page_set_tlbflush_timestamp (&pg[i]); + +/* This page is not a guest frame any more. */ +page_set_owner (&pg[i],NULL ); +set_gpfn_from_mfn (mfn_x (mfn) + i,INVALID_M2P_ENTRY );The code looks quite similar to
free_heap_pages(). Could we possibly create an helper which can be called from both?
Ok, I will extract the common code here and there.
Quoted 8 lines
xen/common/page_alloc.c static void free_heap_pages( · line 1558
Quoted 3 lines
xen/common/page_alloc.c +3
-0+ +if ( need_scrub ) +scrub_one_page (&pg[i]);So the scrubbing will be synchronous. Is it what we want?
You also seem to miss the flush the call to
flush_page_to_ram().
Yeah, right now, it is synchronous.
I guess that it is not an optimal choice, only a workable one right now. I'm trying to borrow some asynchronous scrubbing ideas from heap in the future.
Yes! If we are doing synchronous scrubbing, we need to flush_page_to_ram(). Thx.
Quoted 9 lines
Quoted 9 lines
xen/common/page_alloc.c +2
-0+ } +}/* * Following rules applied for page offline: @@ -1828,6 +1874,30 @@ static void init_heap_pages( } }
Quoted 12 lines
xen/common/page_alloc.c static void init_heap_pages( · line 1885
Quoted 8 lines
xen/common/page_alloc.c +8
-0+/* Equivalent of init_heap_pages to do static memory initialization +*/ void __init init_staticmem_pages (void ) { +int bank; + +/* +* TODO: Considering NUMA-support scenario. +*/ +for ( bank =0 ; bank < bootinfo.static_mem.nr_banks; bank++ )bootinfo is arm specific, so this code should live in
arch/armrather than common/.
Yes, I'm considering to create a new CONFIG_STATIC_MEM to include all static-memory-related functions.
Quoted 36 lines
Quoted 24 lines
xen/common/page_alloc.c +15
-0+ { +paddr_t bank_start = bootinfo.static_mem.bank[bank].start; +paddr_t bank_size = bootinfo.static_mem.bank[bank].size; +paddr_t bank_end = bank_start + bank_size; + + bank_start =round_pgup (bank_start); + bank_end =round_pgdown (bank_end); +if ( bank_end <= bank_start ) +return ; + +free_staticmem_pages (maddr_to_page (bank_start), + (bank_end - bank_start) >>PAGE_SHIFT , false); + } +} +static unsigned long avail_heap_pages (unsigned int zone_lo,unsigned int zone_hi,unsigned int node) {xen/include/xen/mm.h index renamed from xen/include/xen/mm.h +0
-0
667f9dac83..8b1a2207b2100644xen/include/xen/mm.h bool scrub_free_pages(void); · line 93
Quoted 9 lines
xen/include/xen/mm.h +3
-0@@ -85,6 +85,9 @@ bool scrub_free_pages(void); } while ( false )#define FREE_XENHEAP_PAGE (p) FREE_XENHEAP_PAGES(p, 0) +/* Static Memory */ +void init_staticmem_pages (void ); +/* Map machine page range in Xen virtual address space. */ int map_pages_to_xen( unsigned long virt,Cheers,
Quoted 2 lines
--
Julien Grall
Cheers
Penny
PATCH 5/10 xen/arm: introduce alloc_staticmem_pages
In reply to Penny Zhengalloc_staticmem_pages is designated to allocate nr_pfns contiguous pages of static memory. And it is the equivalent of alloc_heap_pages for static memory.
This commit only covers allocating at specified starting address.
For each page, it shall check if the page is reserved (PGC_reserved) and free. It shall also do a set of necessary initialization, which are mostly the same ones in alloc_heap_pages, like, following the same cache-coherency policy and turning page status into PGC_state_used, etc.
--- xen/common/page_alloc.c | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
xen/common/page_alloc.c +64 -0
@@ -1068,6 +1068,70 @@ static struct page_info *alloc_heap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of static memory. +* It is the equivalent of alloc_heap_pages for static memory +*/ +static struct page_info *alloc_staticmem_pages (unsigned long nr_pfns, +paddr_t start, +unsigned int memflags) +{ +bool need_tlbflush = false; +uint32_t tlbflush_timestamp =0 ; +unsigned int i; +struct page_info *pg; +mfn_t s_mfn; + +/* For now, it only supports allocating at specified address. */ + s_mfn =maddr_to_mfn (start); + pg =mfn_to_page (s_mfn); +if ( !pg ) +return NULL ; + +for ( i =0 ; i < nr_pfns; i++) + { +/* +* Reference count must continuously be zero for free pages +* of static memory(PGC_reserved). +*/ +ASSERT (pg[i].count_info & PGC_reserved); +if ( (pg[i].count_info & ~PGC_reserved) != PGC_state_free ) + { +printk (XENLOG_ERR +"Reference count must continuously be zero for free pages" +"pg[%u] MFN %" PRI_mfn" c=%#lx t=%#x\n" , + i,mfn_x (page_to_mfn (pg + i)), + pg[i].count_info, pg[i].tlbflush_timestamp); +BUG (); + } + +if ( !(memflags & MEMF_no_tlbflush) ) +accumulate_tlbflush (&need_tlbflush, &pg[i], + &tlbflush_timestamp); + +/* +* Reserve flag PGC_reserved and change page state +* to PGC_state_inuse. +*/ + pg[i].count_info = (pg[i].count_info & PGC_reserved) | PGC_state_inuse; +/* Initialise fields which have other uses for free pages. */ + pg[i].u.inuse.type_info =0 ; +page_set_owner (&pg[i],NULL ); + +/* +* Ensure cache and RAM are consistent for platforms where the +* guest can control its own visibility of/through the cache. +*/ +flush_page_to_ram (mfn_x (page_to_mfn (&pg[i])), + !(memflags & MEMF_no_icache_flush)); + } + +if ( need_tlbflush ) +filtered_flush_tlb_mask (tlbflush_timestamp); + +return pg; +} +/* Remove any offlined page in the buddy pointed to by head. */ static int reserve_offlined_page (struct page_info *head) {
Signature · 1 line
2.25.1
Re: [PATCH 05/10] xen/arm: introduce alloc_staticmem_pages
Quoted 21 lines · Penny Zheng
alloc_staticmem_pagesis designated to allocatenr_pfnscontiguous pages of static memory. And it is the equivalent ofalloc_heap_pagesfor static memory.
This commit only covers allocating at specified starting address.For each page, it shall check if the page is reserved (
PGC_reserved) and free. It shall also do a set of necessary initialization, which are mostly the same ones inalloc_heap_pages, like, following the same cache-coherency policy and turning page status intoPGC_state_used, etc.Signed-off-by Penny Zheng <[email protected]>--- xen/common/page_alloc.c | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)xen/common/page_alloc.c +0
-0
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1077
Quoted 10 lines
xen/common/page_alloc.c +7
-0@@ -1068,6 +1068,70 @@ static struct page_info *alloc_heap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of static memory. +* It is the equivalent of alloc_heap_pages for static memory +*/ +static struct page_info *alloc_staticmem_pages (unsigned long nr_pfns, +paddr_t start, +unsigned int memflags)
This is surely breaking the build (at this point in the series - recall that a series should build fine at every patch boundary), for introducing an unused static function, which most compilers will warn about.
Also again - please avoid introducing code that's always dead for certain architectures. Quite likely you want a Kconfig option to put a suitable #ifdef around such functions.
And a nit: Please correct the apparently off-by-one indentation.
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1081
Quoted 4 lines
xen/common/page_alloc.c +4
-0+{ +bool need_tlbflush = false; +uint32_t tlbflush_timestamp =0 ; +unsigned int i;
This variable's type should (again) match nr_pfns'es (albeit I think that parameter really wants to be nr_mfns).
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1089
Quoted 8 lines
xen/common/page_alloc.c +8
-0+struct page_info *pg; +mfn_t s_mfn; + +/* For now, it only supports allocating at specified address. */ + s_mfn =maddr_to_mfn (start); + pg =mfn_to_page (s_mfn); +if ( !pg ) +return NULL ;
Under what conditions would mfn_to_page() return NULL?
Quoted 4 lines
xen/common/page_alloc.c +4
-0+for ( i =0 ; i < nr_pfns; i++) + { +/* +* Reference count must continuously be zero for free pages
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1104
Quoted 10 lines
xen/common/page_alloc.c +10
-0+* of static memory(PGC_reserved). +*/ +ASSERT (pg[i].count_info & PGC_reserved); +if ( (pg[i].count_info & ~PGC_reserved) != PGC_state_free ) + { +printk (XENLOG_ERR +"Reference count must continuously be zero for free pages" +"pg[%u] MFN %" PRI_mfn" c=%#lx t=%#x\n" , + i,mfn_x (page_to_mfn (pg + i)), + pg[i].count_info, pg[i].tlbflush_timestamp);
Nit: Indentation again.
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1113
Quoted 9 lines
xen/common/page_alloc.c +9
-0+BUG (); + } + +if ( !(memflags & MEMF_no_tlbflush) ) +accumulate_tlbflush (&need_tlbflush, &pg[i], + &tlbflush_timestamp); + +/* +* Reserve flag PGC_reserved and change page state
DYM "Preserve ..."?
Quoted 7 lines
xen/common/page_alloc.c +7
-0+* to PGC_state_inuse. +*/ + pg[i].count_info = (pg[i].count_info & PGC_reserved) | PGC_state_inuse; +/* Initialise fields which have other uses for free pages. */ + pg[i].u.inuse.type_info =0 ; +page_set_owner (&pg[i],NULL ); +
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1130
Quoted 10 lines
xen/common/page_alloc.c +10
-0+/* +* Ensure cache and RAM are consistent for platforms where the +* guest can control its own visibility of/through the cache. +*/ +flush_page_to_ram (mfn_x (page_to_mfn (&pg[i])), + !(memflags & MEMF_no_icache_flush)); + } + +if ( need_tlbflush ) +filtered_flush_tlb_mask (tlbflush_timestamp);
With reserved pages dedicated to a specific domain, in how far is it possible that stale mappings from a prior use can still be around, making such TLB flushing necessary?
Jan
RE: [PATCH 05/10] xen/arm: introduce alloc_staticmem_pages
Hi Jan
Quoted 35 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:24 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 05/10] xen/arm: introducealloc_staticmem_pagesQuoted 25 lines · Penny Zheng
alloc_staticmem_pagesis designated to allocatenr_pfnscontiguous pages of static memory. And it is the equivalent ofalloc_heap_pagesfor static memory.
This commit only covers allocating at specified starting address.For each page, it shall check if the page is reserved (
PGC_reserved) and free. It shall also do a set of necessary initialization, which are mostly the same ones inalloc_heap_pages, like, following the same cache-coherency policy and turning page status intoPGC_state_used, etc.Signed-off-by Penny Zheng <[email protected]>--- xen/common/page_alloc.c | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)xen/common/page_alloc.c index renamed from xen/common/page_alloc.c +0
-0
58b53c6ac2..adf2889e76100644xen/common/page_alloc.c +0
-0@@ -1068,6 +1068,70 @@ static struct page_info *alloc_heap_pages(return pg; }
Quoted 12 lines
xen/common/page_alloc.c static struct page_info *alloc_heap_pages(
Quoted 7 lines
xen/common/page_alloc.c +7
-0+/* +* Allocate nr_pfns contiguous pages, starting at #start, of static memory. +* It is the equivalent of alloc_heap_pages for static memory */ +static struct page_info *alloc_staticmem_pages (unsigned long nr_pfns, +paddr_t start, +unsigned int +memflags)This is surely breaking the build (at this point in the series - recall that a series should build fine at every patch boundary), for introducing an unused static function, which most compilers will warn about.
Sure, I'll combine it with other commits
Quoted 4 lines
Also again - please avoid introducing code that's always dead for certain architectures. Quite likely you want a
Kconfigoption to put a suitable #ifdef around such functions.
Sure, sorry for all the missing #ifdefs.
Quoted 2 lines
And a nit: Please correct the apparently off-by-one indentation.
Sure, I'll check through the code more carefully.
Quoted 8 lines
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1081
Quoted 4 lines
xen/common/page_alloc.c +4
-0+{ +bool need_tlbflush = false; +uint32_t tlbflush_timestamp =0 ; +unsigned int i;This variable's type should (again) match nr_pfns'es (albeit I think that parameter really wants to be
nr_mfns).
Correct if I understand you wrongly, you mean that parameters in alloc_staticmem_pages are better be named after unsigned long nr_mfns, right?
Quoted 10 lines
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1089
Quoted 8 lines
xen/common/page_alloc.c +8
-0+struct page_info *pg; +mfn_t s_mfn; + +/* For now, it only supports allocating at specified address. */ + s_mfn =maddr_to_mfn (start); + pg =mfn_to_page (s_mfn); +if ( !pg ) +return NULL ;Under what conditions would
mfn_to_page()return NULL?
Right, my mistake.
Quoted 16 lines
Quoted 5 lines
xen/common/page_alloc.c +4
-0+for ( i =0 ; i < nr_pfns; i++) + { +/* +* Reference count must continuously be zero for free pages xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1104
Quoted 10 lines
xen/common/page_alloc.c +10
-0+* of static memory(PGC_reserved). +*/ +ASSERT (pg[i].count_info & PGC_reserved); +if ( (pg[i].count_info & ~PGC_reserved) != PGC_state_free ) + { +printk (XENLOG_ERR +"Reference count must continuously be zero for free pages" +"pg[%u] MFN %" PRI_mfn" c=%#lx t=%#x\n" , + i,mfn_x (page_to_mfn (pg + i)), + pg[i].count_info, pg[i].tlbflush_timestamp);
Quoted 2 lines
Nit: Indentation again.
Thx
Quoted 12 lines
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1113
Quoted 9 lines
xen/common/page_alloc.c +9
-0+BUG (); + } + +if ( !(memflags & MEMF_no_tlbflush) ) +accumulate_tlbflush (&need_tlbflush, &pg[i], + &tlbflush_timestamp); + +/* +* Reserve flag PGC_reserved and change page state DYM "Preserve ..."?
Sure, thx
Quoted 14 lines
xen/common/page_alloc.c static struct page_info *alloc_heap_pages(
Quoted 3 lines
xen/common/page_alloc.c +3
-0+* to PGC_state_inuse. +*/ + pg[i].count_info = (pg[i].count_info & PGC_reserved) |
PGC_state_inuse;Quoted 10 lines
xen/common/page_alloc.c +10
-0+/* Initialise fields which have other uses for free pages. */ + pg[i].u.inuse.type_info =0 ; +page_set_owner (&pg[i],NULL ); + +/* +* Ensure cache and RAM are consistent for platforms where the +* guest can control its own visibility of/through the cache. +*/ +flush_page_to_ram (mfn_x (page_to_mfn (&pg[i])), + !(memflags & MEMF_no_icache_flush));
Quoted 9 lines
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1130
Quoted 4 lines
xen/common/page_alloc.c +4
-0+ } + +if ( need_tlbflush ) +filtered_flush_tlb_mask (tlbflush_timestamp);With reserved pages dedicated to a specific domain, in how far is it possible that stale mappings from a prior use can still be around, making such TLB flushing necessary?
Yes, you're right.
Quoted 1 line
Jan
Re: [PATCH 05/10] xen/arm: introduce alloc_staticmem_pages
In reply to Jan BeulichHi Jan,
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Penny Zheng
xen/common/page_alloc.c +13
-0+* to PGC_state_inuse. +*/ + pg[i].count_info = (pg[i].count_info & PGC_reserved) | PGC_state_inuse; +/* Initialise fields which have other uses for free pages. */ + pg[i].u.inuse.type_info =0 ; +page_set_owner (&pg[i],NULL ); + +/* +* Ensure cache and RAM are consistent for platforms where the +* guest can control its own visibility of/through the cache. +*/ +flush_page_to_ram (mfn_x (page_to_mfn (&pg[i])), + !(memflags & MEMF_no_icache_flush));
Quoted 8 lines
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1130
Quoted 4 lines
xen/common/page_alloc.c +4
-0+ } + +if ( need_tlbflush ) +filtered_flush_tlb_mask (tlbflush_timestamp);With reserved pages dedicated to a specific domain, in how far is it possible that stale mappings from a prior use can still be around, making such TLB flushing necessary?
I would rather not make the assumption. I can see future where we just want to allocate memory from a static pool that may be shared with multiple domains.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 05/10] xen/arm: introduce alloc_staticmem_pages
In reply to Penny ZhengHi Penny,
Quoted 21 lines · Penny Zheng
alloc_staticmem_pagesis designated to allocatenr_pfnscontiguous pages of static memory. And it is the equivalent ofalloc_heap_pagesfor static memory.
This commit only covers allocating at specified starting address.For each page, it shall check if the page is reserved (
PGC_reserved) and free. It shall also do a set of necessary initialization, which are mostly the same ones inalloc_heap_pages, like, following the same cache-coherency policy and turning page status intoPGC_state_used, etc.Signed-off-by Penny Zheng <[email protected]>--- xen/common/page_alloc.c | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)xen/common/page_alloc.c +0
-0
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1075
Quoted 8 lines
xen/common/page_alloc.c +5
-0@@ -1068,6 +1068,70 @@ static struct page_info *alloc_heap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of static memory. +* It is the equivalent of alloc_heap_pages for static memory +*/ +static struct page_info *alloc_staticmem_pages(unsigned long nr_pfns,
This wants to be nr_mfns.
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1076
Quoted 1 line
xen/common/page_alloc.c +1
-0+ paddr_t start,
I would prefer if this helper takes an mfn_t in parameter.
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1087
Quoted 11 lines
xen/common/page_alloc.c +11
-0+ unsigned int memflags) +{ +bool need_tlbflush = false; +uint32_t tlbflush_timestamp =0 ; +unsigned int i; +struct page_info *pg; +mfn_t s_mfn; + +/* For now, it only supports allocating at specified address. */ + s_mfn =maddr_to_mfn (start); + pg =mfn_to_page (s_mfn);
We should avoid to make the assumption the start address will be valid. So you want to call mfn_valid() first.
At the same time, there is no guarantee that if the first page is valid, then the next nr_pfns will be. So the check should be performed for all of them.
Quoted 8 lines
xen/common/page_alloc.c +8
-0+if ( !pg ) +return NULL ; + +for ( i =0 ; i < nr_pfns; i++) + { +/* +* Reference count must continuously be zero for free pages +* of static memory(PGC_reserved).
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1105
Quoted 10 lines
xen/common/page_alloc.c +10
-0+*/ +ASSERT (pg[i].count_info & PGC_reserved); +if ( (pg[i].count_info & ~PGC_reserved) != PGC_state_free ) + { +printk (XENLOG_ERR +"Reference count must continuously be zero for free pages" +"pg[%u] MFN %" PRI_mfn" c=%#lx t=%#x\n" , + i,mfn_x (page_to_mfn (pg + i)), + pg[i].count_info, pg[i].tlbflush_timestamp); +BUG ();
So we would crash Xen if the caller pass a wrong range. Is it what we want?
Also, who is going to prevent concurrent access?
Quoted 23 lines
xen/common/page_alloc.c +22
-0+ } + +if ( !(memflags & MEMF_no_tlbflush) ) +accumulate_tlbflush (&need_tlbflush, &pg[i], + &tlbflush_timestamp); + +/* +* Reserve flag PGC_reserved and change page state +* to PGC_state_inuse. +*/ + pg[i].count_info = (pg[i].count_info & PGC_reserved) | PGC_state_inuse; +/* Initialise fields which have other uses for free pages. */ + pg[i].u.inuse.type_info =0 ; +page_set_owner (&pg[i],NULL ); + +/* +* Ensure cache and RAM are consistent for platforms where the +* guest can control its own visibility of/through the cache. +*/ +flush_page_to_ram (mfn_x (page_to_mfn (&pg[i])), + !(memflags & MEMF_no_icache_flush)); + }
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1137
Quoted 10 lines
xen/common/page_alloc.c +7
-0+ +if ( need_tlbflush ) +filtered_flush_tlb_mask (tlbflush_timestamp); + +return pg; +} +/* Remove any offlined page in the buddy pointed to by head. */ static int reserve_offlined_page (struct page_info *head) {
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 05/10] xen/arm: introduce alloc_staticmem_pages
Hi Julien
Quoted 44 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 6:15 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 05/10] xen/arm: introducealloc_staticmem_pagesHi Penny,
Quoted 11 lines · Penny Zheng
alloc_staticmem_pagesis designated to allocatenr_pfnscontiguous pages of static memory. And it is the equivalent ofalloc_heap_pagesfor static memory.
This commit only covers allocating at specified starting address.For each page, it shall check if the page is reserved (
PGC_reserved) and free. It shall also do a set of necessary initialization, which are mostly the same ones inalloc_heap_pages, like, following the same cache-coherency policy and turning page status intoPGC_state_used, etc.Quoted 3 lines
Signed-off-by Penny Zheng <[email protected]>--- xen/common/page_alloc.c | 64+++++++++++++++++++++++++++++++++++++++++
Quoted 7 lines
1 file changed, 64 insertions(+)xen/common/page_alloc.c index renamed from xen/common/page_alloc.c +0
-0
58b53c6ac2..adf2889e76100644xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1074
Quoted 7 lines
xen/common/page_alloc.c +4
-0@@ -1068,6 +1068,70 @@ static struct page_info *alloc_heap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of static memory. +* It is the equivalent of alloc_heap_pages for static memory */ +static struct page_info *alloc_staticmem_pages(unsigned long nr_pfns,This wants to be
nr_mfns.
Quoted 4 lines
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1076
Quoted 1 line
xen/common/page_alloc.c +1
-0+ paddr_t start,I would prefer if this helper takes an
mfn_tin parameter.
Sure, I will change both.
Quoted 15 lines
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1087
Quoted 11 lines
xen/common/page_alloc.c +11
-0+unsigned int +memflags) { +bool need_tlbflush = false; +uint32_t tlbflush_timestamp =0 ; +unsigned int i; +struct page_info *pg; +mfn_t s_mfn; + +/* For now, it only supports allocating at specified address. */ + s_mfn =maddr_to_mfn (start); + pg =mfn_to_page (s_mfn);We should avoid to make the assumption the start address will be valid. So you want to call
mfn_valid()first.
Quoted 3 lines
At the same time, there is no guarantee that if the first page is valid, then the next
nr_pfnswill be. So the check should be performed for all of them.
Ok. I'll do validation check on both of them.
Quoted 19 lines
Quoted 8 lines
xen/common/page_alloc.c +8
-0+if ( !pg ) +return NULL ; + +for ( i =0 ; i < nr_pfns; i++) + { +/* +* Reference count must continuously be zero for free pages +* of static memory(PGC_reserved). xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1105
Quoted 10 lines
xen/common/page_alloc.c +10
-0+*/ +ASSERT (pg[i].count_info & PGC_reserved); +if ( (pg[i].count_info & ~PGC_reserved) != PGC_state_free ) + { +printk (XENLOG_ERR +"Reference count must continuously be zero for free pages" +"pg[%u] MFN %" PRI_mfn" c=%#lx t=%#x\n" , + i,mfn_x (page_to_mfn (pg + i)), + pg[i].count_info, pg[i].tlbflush_timestamp); +BUG ();
Quoted 4 lines
So we would crash Xen if the caller pass a wrong range. Is it what we want?
Also, who is going to prevent concurrent access?
Sure, to fix concurrency issue, I may need to add one spinlock like static DEFINE_SPINLOCK(staticmem_lock);
In current alloc_heap_pages, it will do similar check, that pages in free state MUST have zero reference count. I guess, if condition not met, there is no need to proceed.
Quoted 37 lines
xen/common/page_alloc.c static struct page_info *alloc_heap_pages(
Quoted 11 lines
xen/common/page_alloc.c +11
-0+ } + +if ( !(memflags & MEMF_no_tlbflush) ) +accumulate_tlbflush (&need_tlbflush, &pg[i], + &tlbflush_timestamp); + +/* +* Reserve flag PGC_reserved and change page state +* to PGC_state_inuse. +*/ + pg[i].count_info = (pg[i].count_info & PGC_reserved) |
PGC_state_inuse;Quoted 12 lines
xen/common/page_alloc.c +11
-0+/* Initialise fields which have other uses for free pages. */ + pg[i].u.inuse.type_info =0 ; +page_set_owner (&pg[i],NULL ); + +/* +* Ensure cache and RAM are consistent for platforms where the +* guest can control its own visibility of/through the cache. +*/ +flush_page_to_ram (mfn_x (page_to_mfn (&pg[i])), + !(memflags & MEMF_no_icache_flush)); + }xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1137
Quoted 10 lines
xen/common/page_alloc.c +7
-0+ +if ( need_tlbflush ) +filtered_flush_tlb_mask (tlbflush_timestamp); + +return pg; +} +/* Remove any offlined page in the buddy pointed to by head. */ static int reserve_offlined_page (struct page_info *head) {Cheers,
Quoted 2 lines
--
Julien Grall
Cheers,
Penny Zheng
RE: [PATCH 05/10] xen/arm: introduce alloc_staticmem_pages
Hi Julien
Quoted 109 lines
-----Original Message-----
From: Penny Zheng
Sent: Wednesday, May 19, 2021 1:24 PM
To: Julien Grall <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: RE: [PATCH 05/10] xen/arm: introducealloc_staticmem_pagesHi Julien
Quoted 45 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 6:15 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 05/10] xen/arm: introducealloc_staticmem_pagesHi Penny,
Quoted 11 lines · Penny Zheng
alloc_staticmem_pagesis designated to allocatenr_pfnscontiguous pages of static memory. And it is the equivalent ofalloc_heap_pagesfor static memory.
This commit only covers allocating at specified starting address.For each page, it shall check if the page is reserved (
PGC_reserved) and free. It shall also do a set of necessary initialization, which are mostly the same ones inalloc_heap_pages, like, following the same cache-coherency policy and turning page status intoPGC_state_used, etc.Quoted 3 lines
Signed-off-by Penny Zheng <[email protected]>--- xen/common/page_alloc.c | 64+++++++++++++++++++++++++++++++++++++++++
Quoted 7 lines
1 file changed, 64 insertions(+)xen/common/page_alloc.c index renamed from xen/common/page_alloc.c +0
-0
58b53c6ac2..adf2889e76100644xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1075
Quoted 8 lines
xen/common/page_alloc.c +5
-0@@ -1068,6 +1068,70 @@ static struct page_info *alloc_heap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of static memory. +* It is the equivalent of alloc_heap_pages for static memory */ +static struct page_info *alloc_staticmem_pages(unsigned long +nr_pfns,This wants to be
nr_mfns.Quoted 4 lines
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1076
Quoted 1 line
xen/common/page_alloc.c +1
-0+ paddr_t start,I would prefer if this helper takes an
mfn_tin parameter.Sure, I will change both.
Quoted 15 lines
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1087
Quoted 11 lines
xen/common/page_alloc.c +11
-0+unsigned int +memflags) { +bool need_tlbflush = false; +uint32_t tlbflush_timestamp =0 ; +unsigned int i; +struct page_info *pg; +mfn_t s_mfn; + +/* For now, it only supports allocating at specified address. */ + s_mfn =maddr_to_mfn (start); + pg =mfn_to_page (s_mfn);We should avoid to make the assumption the start address will be valid. So you want to call
mfn_valid()first.Quoted 2 lines
At the same time, there is no guarantee that if the first page is valid, then the next
nr_pfnswill be. So the check should be performed for allof them.
Quoted 1 line
Ok. I'll do validation check on both of them.
Quoted 19 lines
Quoted 8 lines
xen/common/page_alloc.c +8
-0+if ( !pg ) +return NULL ; + +for ( i =0 ; i < nr_pfns; i++) + { +/* +* Reference count must continuously be zero for free pages +* of static memory(PGC_reserved). xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1105
Quoted 10 lines
xen/common/page_alloc.c +10
-0+*/ +ASSERT (pg[i].count_info & PGC_reserved); +if ( (pg[i].count_info & ~PGC_reserved) != PGC_state_free ) + { +printk (XENLOG_ERR +"Reference count must continuously be zero for free pages" +"pg[%u] MFN %" PRI_mfn" c=%#lx t=%#x\n" , + i,mfn_x (page_to_mfn (pg + i)), + pg[i].count_info, pg[i].tlbflush_timestamp); +BUG ();Quoted 4 lines
So we would crash Xen if the caller pass a wrong range. Is it what we want?
Also, who is going to prevent concurrent access?
Quoted 7 lines
Sure, to fix concurrency issue, I may need to add one spinlock like
static DEFINE_SPINLOCK(staticmem_lock);In current
alloc_heap_pages, it will do similar check, that pages in free state MUST have zero reference count. I guess, if condition not met, there is no need to proceed.
Another thought on concurrency problem, when constructing patch v2, do we need to consider concurrency here?heap_lock is to take care concurrent allocation on the one heap, but static memory is always reserved for only one specific domain.
Quoted 37 lines
Quoted 37 lines
xen/common/page_alloc.c static struct page_info *alloc_heap_pages(
Quoted 11 lines
xen/common/page_alloc.c +11
-0+ } + +if ( !(memflags & MEMF_no_tlbflush) ) +accumulate_tlbflush (&need_tlbflush, &pg[i], + &tlbflush_timestamp); + +/* +* Reserve flag PGC_reserved and change page state +* to PGC_state_inuse. +*/ + pg[i].count_info = (pg[i].count_info & PGC_reserved) |
PGC_state_inuse;Quoted 12 lines
xen/common/page_alloc.c +11
-0+/* Initialise fields which have other uses for free pages. */ + pg[i].u.inuse.type_info =0 ; +page_set_owner (&pg[i],NULL ); + +/* +* Ensure cache and RAM are consistent for platforms where the +* guest can control its own visibility of/through the cache. +*/ +flush_page_to_ram (mfn_x (page_to_mfn (&pg[i])), + !(memflags & MEMF_no_icache_flush)); + }xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1137
Quoted 10 lines
xen/common/page_alloc.c +7
-0+ +if ( need_tlbflush ) +filtered_flush_tlb_mask (tlbflush_timestamp); + +return pg; +} +/* Remove any offlined page in the buddy pointed to by head. */ static int reserve_offlined_page (struct page_info *head) {Cheers,
Quoted 6 lines
Quoted 2 lines
--
Julien GrallCheers,
Penny Zheng
Cheers
Penny
Re: [PATCH 05/10] xen/arm: introduce alloc_staticmem_pages
Quoted 1 line · Penny Zheng
Hi Julien
Hi Penny,
Quoted 32 lines
Quoted 24 lines
Quoted 19 lines
Quoted 8 lines
xen/common/page_alloc.c +8
-0+if ( !pg ) +return NULL ; + +for ( i =0 ; i < nr_pfns; i++) + { +/* +* Reference count must continuously be zero for free pages +* of static memory(PGC_reserved). xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1105
Quoted 10 lines
xen/common/page_alloc.c +10
-0+*/ +ASSERT (pg[i].count_info & PGC_reserved); +if ( (pg[i].count_info & ~PGC_reserved) != PGC_state_free ) + { +printk (XENLOG_ERR +"Reference count must continuously be zero for free pages" +"pg[%u] MFN %" PRI_mfn" c=%#lx t=%#x\n" , + i,mfn_x (page_to_mfn (pg + i)), + pg[i].count_info, pg[i].tlbflush_timestamp); +BUG ();Quoted 4 lines
So we would crash Xen if the caller pass a wrong range. Is it what we want?
Also, who is going to prevent concurrent access?
Quoted 7 lines
Sure, to fix concurrency issue, I may need to add one spinlock like
static DEFINE_SPINLOCK(staticmem_lock);In current
alloc_heap_pages, it will do similar check, that pages in free state MUST have zero reference count. I guess, if condition not met, there is no need to proceed.
Quoted 4 lines
Another thought on concurrency problem, when constructing patch v2, do we need to consider concurrency here?
heap_lockis to take care concurrent allocation on the one heap, but static memory is always reserved for only one specific domain.
In theory yes, but you are relying on the admin to correctly write the device-tree nodes.
You are probably not going to hit the problem today because the domains are created one by one. But, as you may want to allocate memory at runtime, this is quite important to get the code protected from concurrent access.
Here, you will likely want to use the heaplock rather than a new lock. So you are also protect against concurrent access to count_info from other part of Xen.
Cheers,
Signature · 1 line
Julien Grall
PATCH 6/10 xen: replace order with nr_pfns in assign_pages for better compatibility
In reply to Penny ZhengFunction parameter order in assign_pages is always used as 1ul << order, referring to 2@order pages.
Now, for better compatibility with new static memory, order shall be replaced with nr_pfns pointing to page count with no constraint, like 250MB.
--- xen/arch/x86/pv/dom0_build.c | 2 +- xen/common/grant_table.c | 2 +- xen/common/memory.c | 4 ++-- xen/common/page_alloc.c | 16 ++++++++-------- xen/include/xen/mm.h | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-)
xen/arch/x86/pv/dom0_build.c +1 -1
@@ -556,7 +556,7 @@ int __init dom0_construct_pv(struct domain *d,else {while ( count-- ) -if (assign_pages (d,mfn_to_page (_mfn (mfn++)),0 ,0 ) ) +if (assign_pages (d,mfn_to_page (_mfn (mfn++)),1 ,0 ) )BUG (); } initrd->mod_end =0 ;
xen/common/grant_table.c +1 -1
@@ -2354,7 +2354,7 @@ gnttab_transfer(* is respected and speculative execution is blocked accordingly */ if (unlikely (!evaluate_nospec (okay)) || -unlikely (assign_pages (e, page,0 , MEMF_no_refcount)) ) +unlikely (assign_pages (e, page,1 , MEMF_no_refcount)) ) {bool drop_dom_ref;
xen/common/memory.c +2 -2
@@ -722,7 +722,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)/* Assign each output page to the domain. */ for ( j =0 ; (page =page_list_remove_head (&out_chunk_list)); ++j ) { -if (assign_pages (d, page, exch.out.extent_order, +if (assign_pages (d, page,1UL << exch.out.extent_order, MEMF_no_refcount) ) {unsigned long dec_count;
@@ -791,7 +791,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)* cleared PGC_allocated. */ while ( (page =page_list_remove_head (&in_chunk_list)) ) -if (assign_pages (d, page,0 , MEMF_no_refcount) ) +if (assign_pages (d, page,1 , MEMF_no_refcount) ) {BUG_ON (!d->is_dying);free_domheap_page (page);
xen/common/page_alloc.c +8 -8
@@ -2388,7 +2388,7 @@ void init_domheap_pages(paddr_t ps, paddr_t pe)int assign_pages (struct domain *d,struct page_info *pg, -unsigned int order, +unsigned long nr_pfns,unsigned int memflags) {int rc =0 ;
@@ -2408,7 +2408,7 @@ int assign_pages( {unsigned int extra_pages =0 ; -for ( i =0 ; i < (1ul << order); i++ ) +for ( i =0 ; i < nr_pfns; i++ ) {ASSERT (!(pg[i].count_info & ~PGC_extra));if ( pg[i].count_info & PGC_extra )
@@ -2417,18 +2417,18 @@ int assign_pages(ASSERT (!extra_pages || ((memflags & MEMF_no_refcount) && - extra_pages == 1u << order)); + extra_pages == nr_pfns)); }#endif if ( pg[0 ].count_info & PGC_extra ) { - d->extra_pages +=1u << order; + d->extra_pages += nr_pfns; memflags &= ~MEMF_no_refcount; }else if ( !(memflags & MEMF_no_refcount) ) { -unsigned int tot_pages =domain_tot_pages (d) + (1 << order); +unsigned int tot_pages =domain_tot_pages (d) + nr_pfns;if (unlikely (tot_pages > d->max_pages) ) {
@@ -2440,10 +2440,10 @@ int assign_pages( }if ( !(memflags & MEMF_no_refcount) && -unlikely (domain_adjust_tot_pages (d,1 << order) == (1 << order)) ) +unlikely (domain_adjust_tot_pages (d, nr_pfns) == nr_pfns) )get_knownalive_domain (d); -for ( i =0 ; i < (1 << order); i++ ) +for ( i =0 ; i < nr_pfns; i++ ) {ASSERT (page_get_owner (&pg[i]) ==NULL );page_set_owner (&pg[i], d);
@@ -2499,7 +2499,7 @@ struct page_info *alloc_domheap_pages( pg[i].count_info = PGC_extra; } } -if (assign_pages (d, pg, order, memflags) ) +if (assign_pages (d, pg,1ul << order, memflags) ) {free_heap_pages (pg, order, memflags & MEMF_no_scrub);return NULL ;
xen/include/xen/mm.h +1 -1
@@ -131,7 +131,7 @@ void heap_init_late(void);int assign_pages (struct domain *d,struct page_info *pg, -unsigned int order, +unsigned long nr_pfns,unsigned int memflags);/* Dump info to serial console */
Signature · 1 line
2.25.1
Re: [PATCH 06/10] xen: replace order with nr_pfns in assign_pages for better compatibility
Quoted 6 lines · Penny Zheng
Function parameter order in
assign_pagesis always used as 1ul << order, referring to 2@order pages.Now, for better compatibility with new static memory, order shall be replaced with
nr_pfnspointing to page count with no constraint, like 250MB.
While I'm not entirely opposed, I'm also not convinced. The new user could as well break up the range into suitable power-of-2 chunks. In no case do I view the wording "compatibility" here as appropriate. There's no incompatibility at present.
Jan
RE: [PATCH 06/10] xen: replace order with nr_pfns in assign_pages for better compatibility
Hi Jan
Quoted 14 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:28 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 06/10] xen: replace order withnr_pfnsinassign_pagesfor better compatibilityQuoted 3 lines · Penny Zheng
Function parameter order in
assign_pagesis always used as 1ul << order, referring to 2@order pages.
Quoted 9 lines
Quoted 3 lines
Now, for better compatibility with new static memory, order shall be replaced with
nr_pfnspointing to page count with no constraint, like 250MB.While I'm not entirely opposed, I'm also not convinced. The new user could as well break up the range into suitable power-of-2 chunks. In no case do I view the wording "compatibility" here as appropriate. There's no incompatibility at present.
Yes, maybe the incompatibility is not the good choice here.
Sure, the new user definitely could choose the workaround to break up the range, while it may cost extra time.
And while considering MPU system, memory range size is often not in the power-of-2.
Quoted 1 line
Jan
Thanks
Penny
Re: [PATCH 06/10] xen: replace order with nr_pfns in assign_pages for better compatibility
In reply to Penny ZhengHi Penny,
Quoted 6 lines · Penny Zheng
Function parameter order in
assign_pagesis always used as 1ul << order, referring to 2@order pages.Now, for better compatibility with new static memory, order shall be replaced with
nr_pfnspointing to page count with no constraint, like 250MB.
We have similar requirements for LiveUpdate because are preserving the memory with a number of pages (rather than a power-of-two). With the current interface would be need to split the range in a power of 2 which is a bit of pain.
However, I think I would prefer if we introduce a new interface (maybe assign_pages_nr()) rather than change the meaning of the field. This is for two reasons:
1) We limit the risk to make mistake when backporting a patch touchassign_pages().
2) Adding (1UL << order) for pretty much all the caller is not nice.
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 06/10] xen: replace order with nr_pfns in assign_pages for better compatibility
Hi Julien
Quoted 25 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 6:21 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 06/10] xen: replace order withnr_pfnsinassign_pagesfor better compatibilityHi Penny,
Quoted 6 lines · Penny Zheng
Function parameter order in
assign_pagesis always used as 1ul << order, referring to 2@order pages.Now, for better compatibility with new static memory, order shall be replaced with
nr_pfnspointing to page count with no constraint, like 250MB.We have similar requirements for LiveUpdate because are preserving the memory with a number of pages (rather than a power-of-two). With the current interface would be need to split the range in a power of 2 which is a bit of pain.
Quoted 7 lines
However, I think I would prefer if we introduce a new interface (maybe
assign_pages_nr()) rather than change the meaning of the field. This is for two reasons:
1) We limit the risk to make mistake when backporting a patch touchassign_pages().
2) Adding (1UL << order) for pretty much all the caller is not nice.
Ok. I will create a new interface assign_pages_nr(), and let assign_pages to call it with 2@order.
Quoted 4 lines
Cheers,
--
Julien Grall
Cheers
Penny Zheng
PATCH 7/10 xen/arm: intruduce alloc_domstatic_pages
In reply to Penny Zhengalloc_domstatic_pages is the equivalent of alloc_domheap_pages for static mmeory, and it is to allocate nr_pfns pages of static memory and assign them to one specific domain.
It uses alloc_staticmen_pages to get nr_pages pages of static memory, then on success, it will use assign_pages to assign those pages to one specific domain, including using page_set_reserved_owner to set its reserved domain owner.
--- xen/common/page_alloc.c | 53 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/mm.h | 4 ++++ 2 files changed, 57 insertions(+)
xen/common/page_alloc.c +53 -0
@@ -2447,6 +2447,9 @@ int assign_pages( {ASSERT (page_get_owner (&pg[i]) ==NULL );page_set_owner (&pg[i], d); +/* use page_set_reserved_owner to set its reserved domain owner. */ +if ( (pg[i].count_info & PGC_reserved) ) +page_set_reserved_owner (&pg[i], d);smp_wmb ();/* Domain pointer must be visible before updating refcnt. */ pg[i].count_info = (pg[i].count_info & PGC_extra) | PGC_allocated |1 ;
@@ -2509,6 +2512,56 @@ struct page_info *alloc_domheap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of static memory, +* then assign them to one specific domain #d. +* It is the equivalent of alloc_domheap_pages for static memory. +*/ +struct page_info *alloc_domstatic_pages ( +struct domain *d,unsigned long nr_pfns,paddr_t start, +unsigned int memflags) +{ +struct page_info *pg =NULL ; +unsigned long dma_size; + +ASSERT (!in_irq ()); + +if ( memflags & MEMF_no_owner ) + memflags |= MEMF_no_refcount; + +if ( !dma_bitsize ) + memflags &= ~MEMF_no_dma; +else + { + dma_size =1ul <<bits_to_zone (dma_bitsize); +/* Starting address shall meet the DMA limitation. */ +if ( dma_size && start < dma_size ) +return NULL ; + } + + pg =alloc_staticmem_pages (nr_pfns, start, memflags); +if ( !pg ) +return NULL ; + +if ( d && !(memflags & MEMF_no_owner) ) + { +if ( memflags & MEMF_no_refcount ) + { +unsigned long i; + +for ( i =0 ; i < nr_pfns; i++ ) + pg[i].count_info = PGC_extra; + } +if (assign_pages (d, pg, nr_pfns, memflags) ) + { +free_staticmem_pages (pg, nr_pfns, memflags & MEMF_no_scrub); +return NULL ; + } + } + +return pg; +} +void free_domheap_pages (struct page_info *pg,unsigned int order) {struct domain *d =page_get_owner (pg);
xen/include/xen/mm.h +4 -0
@@ -111,6 +111,10 @@ unsigned long __must_check domain_adjust_tot_pages(struct domain *d,int domain_set_outstanding_pages (struct domain *d,unsigned long pages);void get_outstanding_claims (uint64_t *free_pages,uint64_t *outstanding_pages); +/* Static Memory */ +struct page_info *alloc_domstatic_pages (struct domain *d, +unsigned long nr_pfns,paddr_t start,unsigned int memflags); +/* Domain suballocator. These functions are *not* interrupt-safe.*/ void init_domheap_pages (paddr_t ps,paddr_t pe); struct page_info *alloc_domheap_pages(
Signature · 1 line
2.25.1
Re: [PATCH 07/10] xen/arm: intruduce alloc_domstatic_pages
xen/common/page_alloc.c int assign_pages( · line 2452
Quoted 9 lines · Penny Zheng
xen/common/page_alloc.c +3
-0@@ -2447,6 +2447,9 @@ int assign_pages( {ASSERT (page_get_owner (&pg[i]) ==NULL );page_set_owner (&pg[i], d); +/* use page_set_reserved_owner to set its reserved domain owner. */ +if ( (pg[i].count_info & PGC_reserved) ) +page_set_reserved_owner (&pg[i], d);
Now this is puzzling: What's the point of setting two owner fields to the same value? I also don't recall you having introduced page_set_reserved_owner() for x86, so how is this going to build there?
Quoted 19 lines
xen/common/page_alloc.c +15
-0@@ -2509,6 +2512,56 @@ struct page_info *alloc_domheap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of static memory, +* then assign them to one specific domain #d. +* It is the equivalent of alloc_domheap_pages for static memory. +*/ +struct page_info *alloc_domstatic_pages ( +struct domain *d,unsigned long nr_pfns,paddr_t start, +unsigned int memflags) +{ +struct page_info *pg =NULL ; +unsigned long dma_size; + +ASSERT (!in_irq ()); + +if ( memflags & MEMF_no_owner )
xen/common/page_alloc.c struct page_info *alloc_domheap_pages( · line 2539
Quoted 10 lines
xen/common/page_alloc.c +10
-0+ memflags |= MEMF_no_refcount; + +if ( !dma_bitsize ) + memflags &= ~MEMF_no_dma; +else + { + dma_size =1ul <<bits_to_zone (dma_bitsize); +/* Starting address shall meet the DMA limitation. */ +if ( dma_size && start < dma_size ) +return NULL ;
It is the entire range (i.e. in particular the last byte) which needs to meet such a restriction. I'm not convinced though that DMA width restrictions and static allocation are sensible to coexist.
Quoted 5 lines
xen/common/page_alloc.c +5
-0+ } + + pg =alloc_staticmem_pages (nr_pfns, start, memflags); +if ( !pg ) +return NULL ;
xen/common/page_alloc.c struct page_info *alloc_domheap_pages( · line 2554
Quoted 10 lines
xen/common/page_alloc.c +10
-0+ +if ( d && !(memflags & MEMF_no_owner) ) + { +if ( memflags & MEMF_no_refcount ) + { +unsigned long i; + +for ( i =0 ; i < nr_pfns; i++ ) + pg[i].count_info = PGC_extra; + }
Is this as well as the MEMF_no_owner case actually meaningful for statically allocated pages?
Jan
RE: [PATCH 07/10] xen/arm: intruduce alloc_domstatic_pages
Hi Jan
Quoted 18 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:35 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 07/10] xen/arm: intruducealloc_domstatic_pagesxen/common/page_alloc.c int assign_pages( · line 2450
Quoted 7 lines · Penny Zheng
xen/common/page_alloc.c +1
-0@@ -2447,6 +2447,9 @@ int assign_pages( {ASSERT (page_get_owner (&pg[i]) ==NULL );page_set_owner (&pg[i], d); +/* use page_set_reserved_owner to set its reserved domain owner. */
Quoted 7 lines
xen/common/page_alloc.c int assign_pages( · line 2452
Quoted 2 lines
xen/common/page_alloc.c +2
-0+if ( (pg[i].count_info & PGC_reserved) ) +page_set_reserved_owner (&pg[i], d);Now this is puzzling: What's the point of setting two owner fields to the same value? I also don't recall you having introduced
page_set_reserved_owner()for x86, so how is this going to build there?
Thanks for pointing out that it will fail on x86.
As for the same value, sure, I shall change it to domid_t domid to record its reserved owner. Only domid is enough for differentiate.
And even when domain get rebooted, struct domain may be destroyed, but domid will stays The same.
Major user cases for domain on static allocation are referring to the whole system are static, No runtime creation.
Quoted 26 lines
Quoted 26 lines
xen/common/page_alloc.c +22
-0@@ -2509,6 +2512,56 @@ struct page_info *alloc_domheap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of static +memory, +* then assign them to one specific domain #d. +* It is the equivalent of alloc_domheap_pages for static memory. +*/ +struct page_info *alloc_domstatic_pages ( +struct domain *d,unsigned long nr_pfns,paddr_t start, +unsigned int memflags) +{ +struct page_info *pg =NULL ; +unsigned long dma_size; + +ASSERT (!in_irq ()); + +if ( memflags & MEMF_no_owner ) + memflags |= MEMF_no_refcount; + +if ( !dma_bitsize ) + memflags &= ~MEMF_no_dma; +else + {
Quoted 9 lines
xen/common/page_alloc.c struct page_info *alloc_domheap_pages( · line 2539
Quoted 4 lines
xen/common/page_alloc.c +4
-0+ dma_size =1ul <<bits_to_zone (dma_bitsize); +/* Starting address shall meet the DMA limitation. */ +if ( dma_size && start < dma_size ) +return NULL ;It is the entire range (i.e. in particular the last byte) which needs to meet such a restriction. I'm not convinced though that DMA width restrictions and static allocation are sensible to coexist.
FWIT, if starting address meets the limitation, the last byte, greater than starting address shall meet it too.
Quoted 10 lines
Quoted 10 lines
xen/common/page_alloc.c +10
-0+ } + + pg =alloc_staticmem_pages (nr_pfns, start, memflags); +if ( !pg ) +return NULL ; + +if ( d && !(memflags & MEMF_no_owner) ) + { +if ( memflags & MEMF_no_refcount ) + {
Quoted 9 lines
xen/common/page_alloc.c struct page_info *alloc_domheap_pages( · line 2554
Quoted 5 lines
xen/common/page_alloc.c +5
-0+unsigned long i; + +for ( i =0 ; i < nr_pfns; i++ ) + pg[i].count_info = PGC_extra; + }Is this as well as the
MEMF_no_ownercase actually meaningful for statically allocated pages?
Thanks for pointing out. Truly, we do not need to take it considered.
Quoted 1 line
Jan
Re: [PATCH 07/10] xen/arm: intruduce alloc_domstatic_pages
Quoted 20 lines · Penny Zheng
Quoted 12 lines
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:35 PMxen/common/page_alloc.c int assign_pages( · line 2450
Quoted 7 lines · Penny Zheng
xen/common/page_alloc.c +1
-0@@ -2447,6 +2447,9 @@ int assign_pages( {ASSERT (page_get_owner (&pg[i]) ==NULL );page_set_owner (&pg[i], d); +/* use page_set_reserved_owner to set its reserved domain owner. */
Quoted 7 lines
xen/common/page_alloc.c int assign_pages( · line 2452
Quoted 2 lines
xen/common/page_alloc.c +2
-0+if ( (pg[i].count_info & PGC_reserved) ) +page_set_reserved_owner (&pg[i], d);Now this is puzzling: What's the point of setting two owner fields to the same value? I also don't recall you having introduced
page_set_reserved_owner()for x86, so how is this going to build there?
Quoted 5 lines
Thanks for pointing out that it will fail on x86.
As for the same value, sure, I shall change it todomid_tdomid to record its reserved owner. Only domid is enough for differentiate.
And even when domain get rebooted, struct domain may be destroyed, but domid will stays The same.
Will it? Are you intending to put in place restrictions that make it impossible for the ID to get re-used by another domain?
Quoted 2 lines
Major user cases for domain on static allocation are referring to the whole system are static, No runtime creation.
Right, but that's not currently enforced afaics. If you would enforce it, it may simplify a number of things.
Quoted 36 lines
Quoted 26 lines
Quoted 26 lines
xen/common/page_alloc.c +22
-0@@ -2509,6 +2512,56 @@ struct page_info *alloc_domheap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of static +memory, +* then assign them to one specific domain #d. +* It is the equivalent of alloc_domheap_pages for static memory. +*/ +struct page_info *alloc_domstatic_pages ( +struct domain *d,unsigned long nr_pfns,paddr_t start, +unsigned int memflags) +{ +struct page_info *pg =NULL ; +unsigned long dma_size; + +ASSERT (!in_irq ()); + +if ( memflags & MEMF_no_owner ) + memflags |= MEMF_no_refcount; + +if ( !dma_bitsize ) + memflags &= ~MEMF_no_dma; +else + {Quoted 9 lines
xen/common/page_alloc.c struct page_info *alloc_domheap_pages( · line 2539
Quoted 4 lines
xen/common/page_alloc.c +4
-0+ dma_size =1ul <<bits_to_zone (dma_bitsize); +/* Starting address shall meet the DMA limitation. */ +if ( dma_size && start < dma_size ) +return NULL ;It is the entire range (i.e. in particular the last byte) which needs to meet such a restriction. I'm not convinced though that DMA width restrictions and static allocation are sensible to coexist.
Quoted 2 lines
FWIT, if starting address meets the limitation, the last byte, greater than starting address shall meet it too.
I'm afraid I don't know what you're meaning to tell me here.
Jan
RE: [PATCH 07/10] xen/arm: intruduce alloc_domstatic_pages
Hi Jan
Quoted 82 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 7:23 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 07/10] xen/arm: intruducealloc_domstatic_pagesQuoted 15 lines · Penny Zheng
Quoted 15 lines
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:35 PMxen/common/page_alloc.c int assign_pages( · line 2450
Quoted 7 lines · Penny Zheng
xen/common/page_alloc.c +1
-0@@ -2447,6 +2447,9 @@ int assign_pages( {ASSERT (page_get_owner (&pg[i]) ==NULL );page_set_owner (&pg[i], d); +/* use page_set_reserved_owner to set its reserved domain owner. */
Quoted 2 lines
xen/common/page_alloc.c +2
-0+if ( (pg[i].count_info & PGC_reserved) ) +page_set_reserved_owner (&pg[i], d);Quoted 7 lines
Quoted 4 lines
Now this is puzzling: What's the point of setting two owner fields to the same value? I also don't recall you having introduced
page_set_reserved_owner()for x86, so how is this going to build there?Thanks for pointing out that it will fail on x86.
As for the same value, sure, I shall change it todomid_tdomid to record itsreserved owner.
Quoted 3 lines
Only domid is enough for differentiate.
And even when domain get rebooted, struct domain may be destroyed, but domid will stays The same.Will it? Are you intending to put in place restrictions that make it impossible for the ID to get re-used by another domain?
Quoted 2 lines
Major user cases for domain on static allocation are referring to the whole system are static, No runtime creation.
Right, but that's not currently enforced afaics. If you would enforce it, it may simplify a number of things.
Quoted 36 lines
Quoted 35 lines
Quoted 20 lines
xen/common/page_alloc.c +16
-0@@ -2509,6 +2512,56 @@ struct page_info *alloc_domheap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of static +memory, +* then assign them to one specific domain #d. +* It is the equivalent of alloc_domheap_pages for static memory. +*/ +struct page_info *alloc_domstatic_pages ( +struct domain *d,unsigned long nr_pfns,paddr_t start, +unsigned int memflags) +{ +struct page_info *pg =NULL ; +unsigned long dma_size; + +ASSERT (!in_irq ()); + +if ( memflags & MEMF_no_owner )xen/common/page_alloc.c struct page_info *alloc_domheap_pages( · line 2540
Quoted 10 lines
xen/common/page_alloc.c +10
-0+ memflags |= MEMF_no_refcount; + +if ( !dma_bitsize ) + memflags &= ~MEMF_no_dma; +else + { + dma_size =1ul <<bits_to_zone (dma_bitsize); +/* Starting address shall meet the DMA limitation. */ +if ( dma_size && start < dma_size ) +return NULL ;It is the entire range (i.e. in particular the last byte) which needs to meet such a restriction. I'm not convinced though that DMA width restrictions and static allocation are sensible to coexist.
Quoted 5 lines
Quoted 2 lines
FWIT, if starting address meets the limitation, the last byte, greater than starting address shall meet it too.
I'm afraid I don't know what you're meaning to tell me here.
Referring to alloc_domheap_pages, if dma_bitsize is none-zero value, it will use alloc_heap_pages to allocate pages from [dma_zone + 1, zone_hi], dma_zone + 1 pointing to address larger than 2^(dma_zone + 1). So I was setting address limitation for the starting address.
Quoted 1 line
Jan
Cheers
Penny
Re: [PATCH 07/10] xen/arm: intruduce alloc_domstatic_pages
Quoted 87 lines · Penny Zheng
Hi Jan
Quoted 85 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 7:23 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 07/10] xen/arm: intruducealloc_domstatic_pagesQuoted 15 lines · Penny Zheng
Quoted 15 lines
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:35 PMxen/common/page_alloc.c int assign_pages( · line 2450
Quoted 7 lines · Penny Zheng
xen/common/page_alloc.c +1
-0@@ -2447,6 +2447,9 @@ int assign_pages( {ASSERT (page_get_owner (&pg[i]) ==NULL );page_set_owner (&pg[i], d); +/* use page_set_reserved_owner to set its reserved domain owner. */
Quoted 2 lines
xen/common/page_alloc.c +2
-0+if ( (pg[i].count_info & PGC_reserved) ) +page_set_reserved_owner (&pg[i], d);Quoted 7 lines
Quoted 4 lines
Now this is puzzling: What's the point of setting two owner fields to the same value? I also don't recall you having introduced
page_set_reserved_owner()for x86, so how is this going to build there?Thanks for pointing out that it will fail on x86.
As for the same value, sure, I shall change it todomid_tdomid to record itsreserved owner.
Quoted 3 lines
Only domid is enough for differentiate.
And even when domain get rebooted, struct domain may be destroyed, but domid will stays The same.Will it? Are you intending to put in place restrictions that make it impossible for the ID to get re-used by another domain?
Quoted 2 lines
Major user cases for domain on static allocation are referring to the whole system are static, No runtime creation.
Right, but that's not currently enforced afaics. If you would enforce it, it may simplify a number of things.
Quoted 38 lines
Quoted 26 lines
Quoted 26 lines
xen/common/page_alloc.c +22
-0@@ -2509,6 +2512,56 @@ struct page_info *alloc_domheap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of static +memory, +* then assign them to one specific domain #d. +* It is the equivalent of alloc_domheap_pages for static memory. +*/ +struct page_info *alloc_domstatic_pages ( +struct domain *d,unsigned long nr_pfns,paddr_t start, +unsigned int memflags) +{ +struct page_info *pg =NULL ; +unsigned long dma_size; + +ASSERT (!in_irq ()); + +if ( memflags & MEMF_no_owner ) + memflags |= MEMF_no_refcount; + +if ( !dma_bitsize ) + memflags &= ~MEMF_no_dma; +else + {Quoted 9 lines
xen/common/page_alloc.c struct page_info *alloc_domheap_pages( · line 2539
Quoted 4 lines
xen/common/page_alloc.c +4
-0+ dma_size =1ul <<bits_to_zone (dma_bitsize); +/* Starting address shall meet the DMA limitation. */ +if ( dma_size && start < dma_size ) +return NULL ;It is the entire range (i.e. in particular the last byte) which needs to meet such a restriction. I'm not convinced though that DMA width restrictions and static allocation are sensible to coexist.
FWIT, if starting address meets the limitation, the last byte, greater than starting address shall meet it too.
Quoted 7 lines
Quoted 2 lines
I'm afraid I don't know what you're meaning to tell me here.
Referring to
alloc_domheap_pages, ifdma_bitsizeis none-zero value, it will usealloc_heap_pagesto allocate pages from [dma_zone+ 1,zone_hi],dma_zone + 1pointing to address larger than 2^(dma_zone + 1). So I was setting address limitation for the starting address.
But does this zone concept apply to static pages at all?
Jan
RE: [PATCH 07/10] xen/arm: intruduce alloc_domstatic_pages
Hi Jan
Quoted 101 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Friday, May 21, 2021 3:09 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 07/10] xen/arm: intruducealloc_domstatic_pagesQuoted 91 lines · Penny Zheng
Hi Jan
Quoted 88 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 7:23 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 07/10] xen/arm: intruducealloc_domstatic_pagesQuoted 15 lines · Penny Zheng
Quoted 15 lines
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:35 PMxen/common/page_alloc.c int assign_pages( · line 2450
Quoted 7 lines · Penny Zheng
xen/common/page_alloc.c +1
-0@@ -2447,6 +2447,9 @@ int assign_pages( {ASSERT (page_get_owner (&pg[i]) ==NULL );page_set_owner (&pg[i], d); +/* use page_set_reserved_owner to set its reserved domain owner. */
Quoted 2 lines
xen/common/page_alloc.c +2
-0+if ( (pg[i].count_info & PGC_reserved) ) +page_set_reserved_owner (&pg[i], d);Quoted 8 lines
Quoted 4 lines
Now this is puzzling: What's the point of setting two owner fields to the same value? I also don't recall you having introduced
page_set_reserved_owner()for x86, so how is this going to build there?Thanks for pointing out that it will fail on x86.
As for the same value, sure, I shall change it todomid_tdomid to record itsreserved owner.
Quoted 3 lines
Only domid is enough for differentiate.
And even when domain get rebooted, struct domain may be destroyed, but domid will stays The same.Will it? Are you intending to put in place restrictions that make it impossible for the ID to get re-used by another domain?
Quoted 2 lines
Major user cases for domain on static allocation are referring to the whole system are static, No runtime creation.
Right, but that's not currently enforced afaics. If you would enforce it, it may simplify a number of things.
Quoted 36 lines
Quoted 26 lines
Quoted 26 lines
xen/common/page_alloc.c +22
-0@@ -2509,6 +2512,56 @@ struct page_info *alloc_domheap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of +static memory, +* then assign them to one specific domain #d. +* It is the equivalent of alloc_domheap_pages for static memory. +*/ +struct page_info *alloc_domstatic_pages ( +struct domain *d,unsigned long nr_pfns,paddr_t start, +unsigned int memflags) +{ +struct page_info *pg =NULL ; +unsigned long dma_size; + +ASSERT (!in_irq ()); + +if ( memflags & MEMF_no_owner ) + memflags |= MEMF_no_refcount; + +if ( !dma_bitsize ) + memflags &= ~MEMF_no_dma; +else + {Quoted 9 lines
xen/common/page_alloc.c struct page_info *alloc_domheap_pages( · line 2539
Quoted 4 lines
xen/common/page_alloc.c +4
-0+ dma_size =1ul <<bits_to_zone (dma_bitsize); +/* Starting address shall meet the DMA limitation. */ +if ( dma_size && start < dma_size ) +return NULL ;It is the entire range (i.e. in particular the last byte) which needs to meet such a restriction. I'm not convinced though that DMA width restrictions and static allocation are sensible to coexist.
Quoted 2 lines
FWIT, if starting address meets the limitation, the last byte, greater than starting address shall meet it too.
I'm afraid I don't know what you're meaning to tell me here.
Quoted 7 lines
Quoted 4 lines
Referring to
alloc_domheap_pages, ifdma_bitsizeis none-zero value, it will usealloc_heap_pagesto allocate pages from [dma_zone+ 1,zone_hi],dma_zone + 1pointing to address larger than 2^(dma_zone + 1). So I was setting address limitation for the starting address.But does this zone concept apply to static pages at all?
Oh, so sorry. I finally got what you were asking here. Hmm, I was using the logic in bits_to_zone to do the address bits translation. But I got, it will bring confusion. I'll fix it. Thx.
Quoted 1 line
Jan
Re: [PATCH 07/10] xen/arm: intruduce alloc_domstatic_pages
In reply to Penny ZhengHi Penny,
Quoted 26 lines · Penny Zheng
Quoted 18 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:35 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 07/10] xen/arm: intruducealloc_domstatic_pagesxen/common/page_alloc.c int assign_pages( · line 2450
Quoted 7 lines · Penny Zheng
xen/common/page_alloc.c +1
-0@@ -2447,6 +2447,9 @@ int assign_pages( {ASSERT (page_get_owner (&pg[i]) ==NULL );page_set_owner (&pg[i], d); +/* use page_set_reserved_owner to set its reserved domain owner. */
Quoted 7 lines
xen/common/page_alloc.c int assign_pages( · line 2452
Quoted 2 lines
xen/common/page_alloc.c +2
-0+if ( (pg[i].count_info & PGC_reserved) ) +page_set_reserved_owner (&pg[i], d);Now this is puzzling: What's the point of setting two owner fields to the same value? I also don't recall you having introduced
page_set_reserved_owner()for x86, so how is this going to build there?
Quoted 7 lines
Thanks for pointing out that it will fail on x86.
As for the same value, sure, I shall change it todomid_tdomid to record its reserved owner. Only domid is enough for differentiate.
And even when domain get rebooted, struct domain may be destroyed, but domid will stays The same.
Major user cases for domain on static allocation are referring to the whole system are static, No runtime creation.
One may want to have static memory yet doesn't care about the domid. So I am not in favor to restrict about the domid unless there is no other way.
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 07/10] xen/arm: intruduce alloc_domstatic_pages
Hi Julien
Quoted 42 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 8:13 PM
To: Penny Zheng <[email protected]>; Jan Beulich <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH 07/10] xen/arm: intruducealloc_domstatic_pagesHi Penny,
Quoted 6 lines · Penny Zheng
Quoted 6 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:35 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; xen-Quoted 15 lines
Quoted 15 lines
[email protected]; [email protected]
Subject: Re: [PATCH 07/10] xen/arm: intruducealloc_domstatic_pagesxen/common/page_alloc.c int assign_pages( · line 2450
Quoted 7 lines · Penny Zheng
xen/common/page_alloc.c +1
-0@@ -2447,6 +2447,9 @@ int assign_pages( {ASSERT (page_get_owner (&pg[i]) ==NULL );page_set_owner (&pg[i], d); +/* use page_set_reserved_owner to set its reserved domain owner. */
Quoted 2 lines
xen/common/page_alloc.c +2
-0+if ( (pg[i].count_info & PGC_reserved) ) +page_set_reserved_owner (&pg[i], d);Quoted 7 lines
Quoted 4 lines
Now this is puzzling: What's the point of setting two owner fields to the same value? I also don't recall you having introduced
page_set_reserved_owner()for x86, so how is this going to build there?Thanks for pointing out that it will fail on x86.
As for the same value, sure, I shall change it todomid_tdomid to record itsreserved owner.
Quoted 9 lines
Quoted 5 lines
Only domid is enough for differentiate.
And even when domain get rebooted, struct domain may be destroyed, but domid will stays The same.
Major user cases for domain on static allocation are referring to the whole system are static, No runtime creation.One may want to have static memory yet doesn't care about the domid. So I am not in favor to restrict about the domid unless there is no other way.
The user case you bring up here is that static memory pool?
Right now, the user cases are mostly restricted to static system. If we bring runtime allocation, xl here, it will add a lot more complexity. But if the system has static behavior, the domid is also static.
On rebooting domain from static memory pool, it brings up more discussion, like do we intend to give the memory back to static memory pool when rebooting, if so, ram could be allocated from different place compared with the previous one. And it kinds destroys system static behavior.
or not giving back, just store it in global variable struct page_info *[DOMID] like the others.
Quoted 4 lines
Cheers,
--
Julien Grall
Cheers
Penny Zheng
Re: [PATCH 07/10] xen/arm: intruduce alloc_domstatic_pages
Quoted 1 line · Penny Zheng
Hi Julien
Hi Penny,
Quoted 49 lines
Quoted 49 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 8:13 PM
To: Penny Zheng <[email protected]>; Jan Beulich <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH 07/10] xen/arm: intruducealloc_domstatic_pagesHi Penny,
Quoted 6 lines · Penny Zheng
Quoted 6 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:35 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; xen-Quoted 15 lines
Quoted 15 lines
[email protected]; [email protected]
Subject: Re: [PATCH 07/10] xen/arm: intruducealloc_domstatic_pagesxen/common/page_alloc.c int assign_pages( · line 2450
Quoted 7 lines · Penny Zheng
xen/common/page_alloc.c +1
-0@@ -2447,6 +2447,9 @@ int assign_pages( {ASSERT (page_get_owner (&pg[i]) ==NULL );page_set_owner (&pg[i], d); +/* use page_set_reserved_owner to set its reserved domain owner. */
Quoted 2 lines
xen/common/page_alloc.c +2
-0+if ( (pg[i].count_info & PGC_reserved) ) +page_set_reserved_owner (&pg[i], d);Quoted 7 lines
Quoted 4 lines
Now this is puzzling: What's the point of setting two owner fields to the same value? I also don't recall you having introduced
page_set_reserved_owner()for x86, so how is this going to build there?Thanks for pointing out that it will fail on x86.
As for the same value, sure, I shall change it todomid_tdomid to record itsreserved owner.
Quoted 5 lines
Only domid is enough for differentiate.
And even when domain get rebooted, struct domain may be destroyed, but domid will stays The same.
Major user cases for domain on static allocation are referring to the whole system are static, No runtime creation.
Quoted 5 lines
Quoted 3 lines
One may want to have static memory yet doesn't care about the domid. So I am not in favor to restrict about the domid unless there is no other way.
The user case you bring up here is that static memory pool?
No. The use case I am talking about is an user who wants to give a specific memory region to the guest but doesn't care about which domid was allocated to the guest.
Quoted 4 lines
Right now, the user cases are mostly restricted to static system. If we bring runtime allocation,
xlhere, it will add a lot more complexity. But if the system has static behavior, the domid is also static.
I read this as the admin would have to specify the domain ID in the Device-Tree. Is that what you meant?
If so, then I don't see why we should mandate that. I would mind less if by static you mean the domid will be allocated by Xen and then not changed accross reboot.
Quoted 4 lines
On rebooting domain from static memory pool, it brings up more discussion, like do we intend to give the memory back to static memory pool when rebooting, if so, ram could be allocated from different place compared with the previous one.
You should have all the information in the Device-Tree to re-assign the correct regions. So why would it be allocated from a different place?
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 07/10] xen/arm: intruduce alloc_domstatic_pages
In reply to Penny ZhengHi Penny,
Title: s/intruduce/introduce/
Quoted 20 lines · Penny Zheng
alloc_domstatic_pagesis the equivalent ofalloc_domheap_pagesfor static mmeory, and it is to allocatenr_pfnspages of static memory and assign them to one specific domain.It uses
alloc_staticmen_pagesto getnr_pagespages of static memory, then on success, it will useassign_pagesto assign those pages to one specific domain, including usingpage_set_reserved_ownerto set its reserved domain owner.Signed-off-by Penny Zheng <[email protected]>--- xen/common/page_alloc.c | 53 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/mm.h | 4 ++++ 2 files changed, 57 insertions(+)xen/common/page_alloc.c +0
-0
xen/common/page_alloc.c int assign_pages( · line 2452
Quoted 6 lines
xen/common/page_alloc.c +3
-0@@ -2447,6 +2447,9 @@ int assign_pages( {ASSERT (page_get_owner (&pg[i]) ==NULL );page_set_owner (&pg[i], d); +/* use page_set_reserved_owner to set its reserved domain owner. */ +if ( (pg[i].count_info & PGC_reserved) ) +page_set_reserved_owner (&pg[i], d);
I have skimmed through the rest of the series and couldn't find anyone calling page_get_reserved_owner(). The value is also going to be the exact same as page_set_owner().
So why do we need it?
xen/common/page_alloc.c int assign_pages( · line 2455
Quoted 3 lines
xen/common/page_alloc.c +0
-0smp_wmb ();/* Domain pointer must be visible before updating refcnt. */ pg[i].count_info = (pg[i].count_info & PGC_extra) | PGC_allocated |1 ;
This will clobber PGC_reserved.
xen/common/page_alloc.c struct page_info *alloc_domheap_pages( · line 2516
Quoted 6 lines
xen/common/page_alloc.c +2
-0@@ -2509,6 +2512,56 @@ struct page_info *alloc_domheap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of static memory,
s/nr_pfns/nr_mfns/
xen/common/page_alloc.c struct page_info *alloc_domheap_pages( · line 2521
Quoted 5 lines
xen/common/page_alloc.c +5
-0+* then assign them to one specific domain #d. +* It is the equivalent of alloc_domheap_pages for static memory. +*/ +struct page_info *alloc_domstatic_pages( + struct domain *d, unsigned long nr_pfns, paddr_t start,
s/nr_pfns/nf_mfns/. Also, I would the third parameter to be an mfn_t.
Quoted 52 lines
xen/common/page_alloc.c +43
-0+ unsigned int memflags) +{ +struct page_info *pg =NULL ; +unsigned long dma_size; + +ASSERT (!in_irq ()); + +if ( memflags & MEMF_no_owner ) + memflags |= MEMF_no_refcount; + +if ( !dma_bitsize ) + memflags &= ~MEMF_no_dma; +else + { + dma_size =1ul <<bits_to_zone (dma_bitsize); +/* Starting address shall meet the DMA limitation. */ +if ( dma_size && start < dma_size ) +return NULL ; + } + + pg =alloc_staticmem_pages (nr_pfns, start, memflags); +if ( !pg ) +return NULL ; + +if ( d && !(memflags & MEMF_no_owner) ) + { +if ( memflags & MEMF_no_refcount ) + { +unsigned long i; + +for ( i =0 ; i < nr_pfns; i++ ) + pg[i].count_info = PGC_extra; + } +if (assign_pages (d, pg, nr_pfns, memflags) ) + { +free_staticmem_pages (pg, nr_pfns, memflags & MEMF_no_scrub); +return NULL ; + } + } + +return pg; +} +void free_domheap_pages (struct page_info *pg,unsigned int order) {struct domain *d =page_get_owner (pg);xen/include/xen/mm.h +0
-0
xen/include/xen/mm.h unsigned long __must_check domain_adjust_tot_pages(struct domain *d, · line 120
Quoted 10 lines
xen/include/xen/mm.h +4
-0@@ -111,6 +111,10 @@ unsigned long __must_check domain_adjust_tot_pages(struct domain *d,int domain_set_outstanding_pages (struct domain *d,unsigned long pages);void get_outstanding_claims (uint64_t *free_pages,uint64_t *outstanding_pages); +/* Static Memory */ +struct page_info *alloc_domstatic_pages (struct domain *d, +unsigned long nr_pfns,paddr_t start,unsigned int memflags); +/* Domain suballocator. These functions are *not* interrupt-safe.*/ void init_domheap_pages (paddr_t ps,paddr_t pe); struct page_info *alloc_domheap_pages(
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 07/10] xen/arm: intruduce alloc_domstatic_pages
Hi Julien
Quoted 9 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 6:30 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 07/10] xen/arm: intruducealloc_domstatic_pages
Quoted 4 lines
Hi Penny,
Title: s/intruduce/introduce/
Thx~
Quoted 27 lines · Penny Zheng
Quoted 4 lines
alloc_domstatic_pagesis the equivalent ofalloc_domheap_pagesfor static mmeory, and it is to allocatenr_pfnspages of static memory and assign them to one specific domain.Quoted 8 lines
It uses
alloc_staticmen_pagesto getnr_pagespages of static memory, then on success, it will useassign_pagesto assign those pages to one specific domain, including usingpage_set_reserved_ownerto set its reserved domain owner.Signed-off-by Penny Zheng <[email protected]>--- xen/common/page_alloc.c | 53+++++++++++++++++++++++++++++++++++++++++
xen/common/page_alloc.c int assign_pages( · line 2450
Quoted 12 lines
xen/include/xen/mm.h | 4 ++++ 2 files changed, 57 insertions(+)xen/common/page_alloc.c index renamed from xen/common/page_alloc.c +0
-0
0eb9f22a00..f1f1296a61100644xen/common/page_alloc.c +1
-0@@ -2447,6 +2447,9 @@ int assign_pages( {ASSERT (page_get_owner (&pg[i]) ==NULL );page_set_owner (&pg[i], d); +/* use page_set_reserved_owner to set its reserved domain owner. */
Quoted 9 lines
xen/common/page_alloc.c int assign_pages( · line 2452
Quoted 2 lines
xen/common/page_alloc.c +2
-0+if ( (pg[i].count_info & PGC_reserved) ) +page_set_reserved_owner (&pg[i], d);I have skimmed through the rest of the series and couldn't find anyone calling
page_get_reserved_owner(). The value is also going to be the exact same aspage_set_owner().So why do we need it?
In my first intent, This two helper page_get_reserved_owner/ page_set_reserved_owner and the new field reserved in page_info are all for rebooting domain on static allocation.
I was considering that, when implementing rebooting domain on static allocation, memory will be relinquished and right now, all freed back to heap, which is not suitable for static memory here. relinquish_memory(d, &d->page_list) --> put_page --> free_domheap_page
For pages in PGC_reserved, now, I am considering that, other than giving it back to heap, maybe creating a new global struct page_info*[DOMID] value to hold.
So it is better to have a new field in struct page_info, as follows, to hold such info.
/* Page is reserved. */
struct {
/*
* Reserved Owner of this page,
* if this page is reserved to a specific domain.
*/
domid_t reserved_owner;
} reserved;But this patch Serie is not going to include this feature, and I will delete related helpers and values.
Quoted 7 lines
xen/common/page_alloc.c int assign_pages( · line 2453
Quoted 1 line
xen/common/page_alloc.c +0
-0smp_wmb ();/* Domain pointer must be visible before updating refcnt. */
xen/common/page_alloc.c int assign_pages( · line 2455
Quoted 2 lines
xen/common/page_alloc.c +0
-0pg[i].count_info = (pg[i].count_info & PGC_extra) | PGC_allocated |1 ;This will clobber
PGC_reserved.
related changes have been included into the commit of "0008-xen-arm-introduce-reserved_page_list.patch".
Quoted 10 lines
xen/common/page_alloc.c struct page_info *alloc_domheap_pages( · line 2517
Quoted 7 lines
xen/common/page_alloc.c +3
-0@@ -2509,6 +2512,56 @@ struct page_info *alloc_domheap_pages(return pg; } +/* +* Allocate nr_pfns contiguous pages, starting at #start, of static +memory, s/nr_pfns/nr_mfns/
Sure.
Quoted 8 lines
xen/common/page_alloc.c struct page_info *alloc_domheap_pages( · line 2521
Quoted 5 lines
xen/common/page_alloc.c +5
-0+* then assign them to one specific domain #d. +* It is the equivalent of alloc_domheap_pages for static memory. +*/ +struct page_info *alloc_domstatic_pages( + struct domain *d, unsigned long nr_pfns, paddr_t start,s/nr_pfns/nf_mfns/. Also, I would the third parameter to be an
mfn_t.
Sure.
Quoted 68 lines
xen/include/xen/mm.h unsigned long __must_check
Quoted 51 lines
xen/common/page_alloc.c +43
-0+ unsigned int memflags) +{ +struct page_info *pg =NULL ; +unsigned long dma_size; + +ASSERT (!in_irq ()); + +if ( memflags & MEMF_no_owner ) + memflags |= MEMF_no_refcount; + +if ( !dma_bitsize ) + memflags &= ~MEMF_no_dma; +else + { + dma_size =1ul <<bits_to_zone (dma_bitsize); +/* Starting address shall meet the DMA limitation. */ +if ( dma_size && start < dma_size ) +return NULL ; + } + + pg =alloc_staticmem_pages (nr_pfns, start, memflags); +if ( !pg ) +return NULL ; + +if ( d && !(memflags & MEMF_no_owner) ) + { +if ( memflags & MEMF_no_refcount ) + { +unsigned long i; + +for ( i =0 ; i < nr_pfns; i++ ) + pg[i].count_info = PGC_extra; + } +if (assign_pages (d, pg, nr_pfns, memflags) ) + { +free_staticmem_pages (pg, nr_pfns, memflags & MEMF_no_scrub); +return NULL ; + } + } + +return pg; +} +void free_domheap_pages (struct page_info *pg,unsigned int order) { struct domain *d = page_get_owner(pg); diff --git
a/xen/include/xen/mm.hb/xen/include/xen/mm.hindexdcf9daaa46..e45987f0ed100644xen/include/xen/mm.h +0
-0@@ -111,6 +111,10 @@ unsigned long __must_checkdomain_adjust_tot_pages(struct domain *d,
xen/include/xen/mm.h unsigned long __must_check · line 111
Quoted 1 line
xen/include/xen/mm.h +0
-0int domain_set_outstanding_pages(struct domain *d, unsigned longpages);
Quoted 11 lines
xen/include/xen/mm.h +4
-0void get_outstanding_claims (uint64_t *free_pages,uint64_t *outstanding_pages); +/* Static Memory */ +struct page_info *alloc_domstatic_pages (struct domain *d, +unsigned long nr_pfns,paddr_t start,unsigned int memflags); +/* Domain suballocator. These functions are *not* interrupt-safe.*/ void init_domheap_pages (paddr_t ps,paddr_t pe);struct
page_info*alloc_domheap_pages(Cheers,
Quoted 2 lines
--
Julien Grall
Cheers,
Penny
PATCH 8/10 xen/arm: introduce reserved_page_list
In reply to Penny ZhengSince page_list under struct domain refers to linked pages as gueast RAM allocated from heap, it should not include reserved pages of static memory.
The number of PGC_reserved pages assigned to a domain is tracked in a new 'reserved_pages' counter. Also introduce a new reserved_page_list to link pages of static memory. Let page_to_list return reserved_page_list, when flag is PGC_reserved.
Later, when domain get destroyed or restarted, those new values will help relinquish memory to proper place, not been given back to heap.
--- xen/common/domain.c | 1 + xen/common/page_alloc.c | 7 +++++-- xen/include/xen/sched.h | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-)
xen/common/domain.c +1 -0
@@ -578,6 +578,7 @@ struct domain *domain_create(domid_t domid,INIT_PAGE_LIST_HEAD (&d->page_list);INIT_PAGE_LIST_HEAD (&d->extra_page_list);INIT_PAGE_LIST_HEAD (&d->xenpage_list); +INIT_PAGE_LIST_HEAD (&d->reserved_page_list);spin_lock_init (&d->node_affinity_lock); d->node_affinity =NODE_MASK_ALL ;
xen/common/page_alloc.c +5 -2
@@ -2410,7 +2410,7 @@ int assign_pages(for ( i =0 ; i < nr_pfns; i++ ) { -ASSERT (!(pg[i].count_info & ~PGC_extra)); +ASSERT (!(pg[i].count_info & ~(PGC_extra | PGC_reserved)));if ( pg[i].count_info & PGC_extra ) extra_pages++; }
@@ -2439,6 +2439,9 @@ int assign_pages( } } +if ( pg[0 ].count_info & PGC_reserved ) + d->reserved_pages += nr_pfns; +if ( !(memflags & MEMF_no_refcount) &&unlikely (domain_adjust_tot_pages (d, nr_pfns) == nr_pfns) )get_knownalive_domain (d);
@@ -2452,7 +2455,7 @@ int assign_pages(page_set_reserved_owner (&pg[i], d);smp_wmb ();/* Domain pointer must be visible before updating refcnt. */ pg[i].count_info = - (pg[i].count_info & PGC_extra) | PGC_allocated |1 ; + (pg[i].count_info & (PGC_extra | PGC_reserved)) | PGC_allocated |1 ;page_list_add_tail (&pg[i],page_to_list (d, &pg[i])); }
xen/include/xen/sched.h +5 -0
@@ -368,6 +368,7 @@ struct domainstruct page_list_head page_list;/* linked list */ struct page_list_head extra_page_list;/* linked list (size extra_pages) */ struct page_list_head xenpage_list;/* linked list (size xenheap_pages) */ +struct page_list_head reserved_page_list;/* linked list (size reserved pages) */ /* * This field should only be directly accessed by domain_adjust_tot_pages()
@@ -379,6 +380,7 @@ struct domainunsigned int outstanding_pages;/* pages claimed but not possessed */ unsigned int max_pages;/* maximum value for domain_tot_pages() */ unsigned int extra_pages;/* pages not included in domain_tot_pages() */ +unsigned int reserved_pages;/* pages of static memory */ atomic_t shr_pages;/* shared pages */ atomic_t paged_pages;/* paged-out pages */
@@ -588,6 +590,9 @@ static inline struct page_list_head *page_to_list(if ( pg->count_info & PGC_extra )return &d->extra_page_list; +if ( pg->count_info & PGC_reserved ) +return &d->reserved_page_list; +return &d->page_list; }
Signature · 1 line
2.25.1
Re: [PATCH 08/10] xen/arm: introduce reserved_page_list
Quoted 11 lines · Penny Zheng
Since
page_listunder struct domain refers to linked pages as gueast RAM allocated from heap, it should not include reserved pages of static memory.The number of
PGC_reservedpages assigned to a domain is tracked in a new 'reserved_pages' counter. Also introduce a newreserved_page_listto link pages of static memory. Letpage_to_listreturnreserved_page_list, when flag isPGC_reserved.Later, when domain get destroyed or restarted, those new values will help relinquish memory to proper place, not been given back to heap.
Quoted 6 lines
Signed-off-by Penny Zheng <[email protected]>--- xen/common/domain.c | 1 + xen/common/page_alloc.c | 7 +++++-- xen/include/xen/sched.h | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-)
This contradicts the title's prefix: There's no Arm-specific change here at all. But imo the title is correct, and the changes should be Arm-specific. There's no point having struct domain fields on e.g. x86 which aren't used there at all.
Quoted 12 lines
xen/common/page_alloc.c +1
-1@@ -2410,7 +2410,7 @@ int assign_pages(for ( i =0 ; i < nr_pfns; i++ ) { -ASSERT (!(pg[i].count_info & ~PGC_extra)); +ASSERT (!(pg[i].count_info & ~(PGC_extra | PGC_reserved)));if ( pg[i].count_info & PGC_extra ) extra_pages++; }
xen/common/page_alloc.c int assign_pages( · line 2443
Quoted 5 lines
xen/common/page_alloc.c +2
-0@@ -2439,6 +2439,9 @@ int assign_pages( } } +if ( pg[0 ].count_info & PGC_reserved ) + d->reserved_pages += nr_pfns;
I guess this again will fail to build on x86.
xen/common/page_alloc.c static inline struct page_list_head *page_to_list( · line 594
Quoted 6 lines
xen/common/page_alloc.c +2
-0@@ -588,6 +590,9 @@ static inline struct page_list_head *page_to_list(if ( pg->count_info & PGC_extra )return &d->extra_page_list; +if ( pg->count_info & PGC_reserved ) +return &d->reserved_page_list;
Same here.
Jan
RE: [PATCH 08/10] xen/arm: introduce reserved_page_list
Hi Jan
Quoted 29 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:39 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 08/10] xen/arm: introducereserved_page_listQuoted 2 lines · Penny Zheng
Since
page_listunder struct domain refers to linked pages as gueast RAM allocated from heap, it should not include reserved pages of staticmemory.
Quoted 9 lines
The number of
PGC_reservedpages assigned to a domain is tracked in a new 'reserved_pages' counter. Also introduce a newreserved_page_listto link pages of static memory. Letpage_to_listreturnreserved_page_list, when flag isPGC_reserved.Later, when domain get destroyed or restarted, those new values will help relinquish memory to proper place, not been given back to heap.
Quoted 6 lines
Signed-off-by Penny Zheng <[email protected]>--- xen/common/domain.c | 1 + xen/common/page_alloc.c | 7 +++++-- xen/include/xen/sched.h | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-)
Quoted 4 lines
This contradicts the title's prefix: There's no Arm-specific change here at all. But imo the title is correct, and the changes should be Arm-specific. There's no point having struct domain fields on e.g. x86 which aren't used there at all.
Yep, you're right.
I'll add ifdefs in the following changes.
Quoted 25 lines
Quoted 13 lines
xen/common/page_alloc.c +2
-1@@ -2410,7 +2410,7 @@ int assign_pages(for ( i =0 ; i < nr_pfns; i++ ) { -ASSERT (!(pg[i].count_info & ~PGC_extra)); +ASSERT (!(pg[i].count_info & ~(PGC_extra | + PGC_reserved)));if ( pg[i].count_info & PGC_extra ) extra_pages++; }xen/common/page_alloc.c int assign_pages( · line 2443
Quoted 5 lines
xen/common/page_alloc.c +2
-0@@ -2439,6 +2439,9 @@ int assign_pages( } } +if ( pg[0 ].count_info & PGC_reserved ) + d->reserved_pages += nr_pfns;I guess this again will fail to build on x86.
Quoted 4 lines
xen/common/page_alloc.c +0
-0@@ -588,6 +590,9 @@ static inline struct page_list_head *page_to_list(if ( pg->count_info & PGC_extra )return &d->extra_page_list;
Quoted 6 lines
xen/common/page_alloc.c static inline struct page_list_head *page_to_list( · line 594
Quoted 2 lines
xen/common/page_alloc.c +2
-0+if ( pg->count_info & PGC_reserved ) +return &d->reserved_page_list;Same here.
Jan
Thanks
Penny
Re: [PATCH 08/10] xen/arm: introduce reserved_page_list
Quoted 31 lines · Penny Zheng
Hi Jan
Quoted 29 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:39 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 08/10] xen/arm: introducereserved_page_listQuoted 2 lines · Penny Zheng
Since
page_listunder struct domain refers to linked pages as gueast RAM allocated from heap, it should not include reserved pages of staticmemory.
Quoted 15 lines
The number of
PGC_reservedpages assigned to a domain is tracked in a new 'reserved_pages' counter. Also introduce a newreserved_page_listto link pages of static memory. Letpage_to_listreturnreserved_page_list, when flag isPGC_reserved.Later, when domain get destroyed or restarted, those new values will help relinquish memory to proper place, not been given back to heap.
Signed-off-by Penny Zheng <[email protected]>--- xen/common/domain.c | 1 + xen/common/page_alloc.c | 7 +++++-- xen/include/xen/sched.h | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-)
Quoted 7 lines
Quoted 4 lines
This contradicts the title's prefix: There's no Arm-specific change here at all. But imo the title is correct, and the changes should be Arm-specific. There's no point having struct domain fields on e.g. x86 which aren't used there at all.
Yep, you're right.
I'll add ifdefs in the following changes.
As necessary, please. Moving stuff to Arm-specific files would be preferable.
Jan
RE: [PATCH 08/10] xen/arm: introduce reserved_page_list
Hi Jan
Quoted 47 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 7:25 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 08/10] xen/arm: introducereserved_page_listQuoted 8 lines · Penny Zheng
Hi Jan
Quoted 6 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 18, 2021 3:39 PM
To: Penny Zheng <[email protected]>
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>; xen-Quoted 17 lines
Quoted 17 lines
[email protected]; [email protected]
Subject: Re: [PATCH 08/10] xen/arm: introducereserved_page_listQuoted 3 lines · Penny Zheng
Since
page_listunder struct domain refers to linked pages as gueast RAM allocated from heap, it should not include reserved pages of staticmemory.
Quoted 9 lines
The number of
PGC_reservedpages assigned to a domain is tracked in a new 'reserved_pages' counter. Also introduce a newreserved_page_listto link pages of static memory. Letpage_to_listreturnreserved_page_list, when flag isPGC_reserved.Later, when domain get destroyed or restarted, those new values will help relinquish memory to proper place, not been given back to heap.
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Signed-off-by Penny Zheng <[email protected]>--- xen/common/domain.c | 1 + xen/common/page_alloc.c | 7 +++++-- xen/include/xen/sched.h | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-)This contradicts the title's prefix: There's no Arm-specific change here at
all.
Quoted 2 lines
Quoted 2 lines
But imo the title is correct, and the changes should be Arm-specific. There's no point having struct domain fields on e.g. x86 which aren't used
Quoted 8 lines
there at all.
Quoted 4 lines
Quoted 1 line
Yep, you're right.
I'll add ifdefs in the following changes.As necessary, please. Moving stuff to Arm-specific files would be preferable.
Sure, I'll add a new CONFIG_STATICMEM to include all related functions and variables. Thx
Quoted 1 line
Jan
Cheers
Penny Zheng
Re: [PATCH 08/10] xen/arm: introduce reserved_page_list
In reply to Penny ZhengHi Penny,
Quoted 1 line · Penny Zheng
Since
page_listunder struct domain refers to linked pages as gueast RAM
s/gueast/guest/
Quoted 1 line
allocated from heap, it should not include reserved pages of static memory.
You already have PGC_reserved to indicate they are "static memory". So why do you need yet another list?
Quoted 33 lines
The number of
PGC_reservedpages assigned to a domain is tracked in a new 'reserved_pages' counter. Also introduce a newreserved_page_listto link pages of static memory. Letpage_to_listreturnreserved_page_list, when flag isPGC_reserved.Later, when domain get destroyed or restarted, those new values will help relinquish memory to proper place, not been given back to heap.
Signed-off-by Penny Zheng <[email protected]>--- xen/common/domain.c | 1 + xen/common/page_alloc.c | 7 +++++-- xen/include/xen/sched.h | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-)xen/common/domain.c +1
-0@@ -578,6 +578,7 @@ struct domain *domain_create(domid_t domid,INIT_PAGE_LIST_HEAD (&d->page_list);INIT_PAGE_LIST_HEAD (&d->extra_page_list);INIT_PAGE_LIST_HEAD (&d->xenpage_list); +INIT_PAGE_LIST_HEAD (&d->reserved_page_list);spin_lock_init (&d->node_affinity_lock); d->node_affinity =NODE_MASK_ALL ;xen/common/page_alloc.c +0
-0
xen/common/page_alloc.c int assign_pages( · line 2413
Quoted 5 lines
xen/common/page_alloc.c +1
-1@@ -2410,7 +2410,7 @@ int assign_pages(for ( i =0 ; i < nr_pfns; i++ ) { -ASSERT (!(pg[i].count_info & ~PGC_extra)); +ASSERT (!(pg[i].count_info & ~(PGC_extra | PGC_reserved)));
I think this change belongs to the previous patch.
xen/common/page_alloc.c int assign_pages( · line 2443
Quoted 9 lines
xen/common/page_alloc.c +2
-0if ( pg[i].count_info & PGC_extra ) extra_pages++; }@@ -2439,6 +2439,9 @@ int assign_pages( } } +if ( pg[0 ].count_info & PGC_reserved ) + d->reserved_pages += nr_pfns;
reserved_pages doesn't seem to be ever read or decremented. So why do you need it?
xen/common/page_alloc.c int assign_pages( · line 2458
Quoted 10 lines
xen/common/page_alloc.c +2
-1+if ( !(memflags & MEMF_no_refcount) &&unlikely (domain_adjust_tot_pages (d, nr_pfns) == nr_pfns) )get_knownalive_domain (d);@@ -2452,7 +2455,7 @@ int assign_pages(page_set_reserved_owner (&pg[i], d);smp_wmb ();/* Domain pointer must be visible before updating refcnt. */ pg[i].count_info = - (pg[i].count_info & PGC_extra) | PGC_allocated |1 ; + (pg[i].count_info & (PGC_extra | PGC_reserved)) | PGC_allocated |1 ;
Same here.
Quoted 25 lines
xen/common/page_alloc.c +0
-0page_list_add_tail (&pg[i],page_to_list (d, &pg[i])); }xen/include/xen/sched.h +2
-0@@ -368,6 +368,7 @@ struct domainstruct page_list_head page_list;/* linked list */ struct page_list_head extra_page_list;/* linked list (size extra_pages) */ struct page_list_head xenpage_list;/* linked list (size xenheap_pages) */ +struct page_list_head reserved_page_list;/* linked list (size reserved pages) */ /* * This field should only be directly accessed by domain_adjust_tot_pages() @@ -379,6 +380,7 @@ struct domainunsigned int outstanding_pages;/* pages claimed but not possessed */ unsigned int max_pages;/* maximum value for domain_tot_pages() */ unsigned int extra_pages;/* pages not included in domain_tot_pages() */ +unsigned int reserved_pages;/* pages of static memory */ atomic_t shr_pages;/* shared pages */ atomic_t paged_pages;/* paged-out pages */
xen/include/xen/sched.h static inline struct page_list_head *page_to_list( · line 598
Quoted 9 lines
xen/include/xen/sched.h +3
-0@@ -588,6 +590,9 @@ static inline struct page_list_head *page_to_list(if ( pg->count_info & PGC_extra )return &d->extra_page_list; +if ( pg->count_info & PGC_reserved ) +return &d->reserved_page_list; +return &d->page_list; }
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 08/10] xen/arm: introduce reserved_page_list
Hi Julien
Quoted 9 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 7:02 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 08/10] xen/arm: introducereserved_page_list
Quoted 8 lines
Hi Penny,
Quoted 2 lines · Penny Zheng
Since
page_listunder struct domain refers to linked pages as gueast RAMs/gueast/guest/
Thx~
Quoted 39 lines
Quoted 1 line
allocated from heap, it should not include reserved pages of static memory.
You already have
PGC_reservedto indicate they are "static memory". So why do you need yet another list?Quoted 34 lines
The number of
PGC_reservedpages assigned to a domain is tracked in a new 'reserved_pages' counter. Also introduce a newreserved_page_listto link pages of static memory. Letpage_to_listreturnreserved_page_list, when flag isPGC_reserved.Later, when domain get destroyed or restarted, those new values will help relinquish memory to proper place, not been given back to heap.
Signed-off-by Penny Zheng <[email protected]>--- xen/common/domain.c | 1 + xen/common/page_alloc.c | 7 +++++-- xen/include/xen/sched.h | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-)xen/common/domain.c index renamed from xen/common/domain.c +0
-0
6b71c6d6a9..c38afd2969100644xen/common/domain.c +1
-0@@ -578,6 +578,7 @@ struct domain *domain_create(domid_t domid,INIT_PAGE_LIST_HEAD (&d->page_list);INIT_PAGE_LIST_HEAD (&d->extra_page_list);INIT_PAGE_LIST_HEAD (&d->xenpage_list); +INIT_PAGE_LIST_HEAD (&d->reserved_page_list);spin_lock_init (&d->node_affinity_lock); d->node_affinity = NODE_MASK_ALL; diff --git
a/xen/common/page_alloc.cb/xen/common/page_alloc.cindexf1f1296a61..e3f07ec6c5100644xen/common/page_alloc.c +0
-0@@ -2410,7 +2410,7 @@ int assign_pages(
Quoted 7 lines
xen/common/page_alloc.c int assign_pages(
Quoted 5 lines
xen/common/page_alloc.c +2
-1for ( i =0 ; i < nr_pfns; i++ ) { -ASSERT (!(pg[i].count_info & ~PGC_extra)); +ASSERT (!(pg[i].count_info & ~(PGC_extra | + PGC_reserved)));I think this change belongs to the previous patch.
Ok. It will be re-organized into previous commit of "xen/arm: intruduce alloc_domstatic_pages"
Quoted 7 lines
Quoted 7 lines
xen/common/page_alloc.c +0
-0if ( pg[i].count_info & PGC_extra ) extra_pages++; }@@ -2439,6 +2439,9 @@ int assign_pages( } }
Quoted 6 lines
xen/common/page_alloc.c int assign_pages( · line 2443
Quoted 2 lines
xen/common/page_alloc.c +2
-0+if ( pg[0 ].count_info & PGC_reserved ) + d->reserved_pages += nr_pfns;
reserved_pagesdoesn't seem to be ever read or decremented. So why do you need it?
Yeah, I may delete it from this Patch Serie.
Like I addressed in before commits:
"when implementing rebooting domain on static allocation, memory will be relinquished and right now, all shall be freed back to heap, which is not suitable for static memory here. relinquish_memory(d, &d->page_list) --> put_page --> free_domheap_page
For pages in PGC_reserved, now, I am considering that, other than giving it back to heap, maybe creating a new global struct page_info*[DOMID] value to hold.
So it is better to have a new field in struct page_info, as follows, to hold such info.
/* Page is reserved. */
struct {
/*
* Reserved Owner of this page,
* if this page is reserved to a specific domain.
*/
domid_t reserved_owner;
} reserved;"
So I will delete here, and re-import when implementing rebooting domain on static allocation.
Quoted 8 lines
xen/common/page_alloc.c int assign_pages( · line 2456
Quoted 7 lines
xen/common/page_alloc.c +1
-0+if ( !(memflags & MEMF_no_refcount) &&unlikely (domain_adjust_tot_pages (d, nr_pfns) == nr_pfns) )get_knownalive_domain (d);@@ -2452,7 +2455,7 @@ int assign_pages(page_set_reserved_owner (&pg[i], d);smp_wmb ();/* Domain pointer must be visible before updating refcnt. */
Quoted 6 lines
xen/common/page_alloc.c int assign_pages(
Quoted 4 lines
xen/common/page_alloc.c +2
-1pg[i].count_info = - (pg[i].count_info & PGC_extra) | PGC_allocated |1 ; + (pg[i].count_info & (PGC_extra | PGC_reserved)) | + PGC_allocated |1 ;Same here.
I'll re-organize it to the previous commit.
Quoted 43 lines
Quoted 16 lines
xen/common/page_alloc.c +0
-0page_list_add_tail (&pg[i],page_to_list (d, &pg[i])); }xen/include/xen/sched.h index renamed from xen/include/xen/sched.h +0
-03982167144..b6333ed8bb 100644
xen/include/xen/sched.h +0
-0@@ -368,6 +368,7 @@ struct domainstruct page_list_head page_list;/* linked list */ struct page_list_head extra_page_list;/* linked list (size extra_pages) */ struct page_list_head xenpage_list;/* linked list (size
xenheap_pages) */
+ structpage_list_headreserved_page_list; /* linked list (size
+ reserved pages) */Quoted 4 lines
/*
* This field should only be directly accessed bydomain_adjust_tot_pages()@@ -379,6 +380,7 @@ struct domain
unsigned intoutstanding_pages; /* pages claimed but not possessed*/
Quoted 1 line
unsigned int
max_pages; /* maximum value for
domain_tot_pages()*/Quoted 1 line
unsigned int
extra_pages; /* pages not included in
domain_tot_pages()*/Quoted 6 lines
xen/include/xen/sched.h +1
-0+unsigned int reserved_pages;/* pages of static memory */ atomic_t shr_pages;/* shared pages */ atomic_t paged_pages;/* paged-out pages */ xen/include/xen/sched.h static inline struct page_list_head *page_to_list( · line 598
Quoted 9 lines
xen/include/xen/sched.h +3
-0@@ -588,6 +590,9 @@ static inline struct page_list_head *page_to_list(if ( pg->count_info & PGC_extra )return &d->extra_page_list; +if ( pg->count_info & PGC_reserved ) +return &d->reserved_page_list; +return &d->page_list; }Cheers,
Quoted 2 lines
--
Julien Grall
Cheers
Penny Zheng
PATCH 9/10 xen/arm: parse `xen,static-mem` info during domain construction
In reply to Penny ZhengThis commit parses xen,static-mem device tree property, to acquire static memory info reserved for this domain, when constructing domain during boot-up.
Related info shall be stored in new static_mem value under per domain struct arch_domain.
Right now, the implementation of allocate_static_memory is missing, and will be introduced later. It just BUG() out at the moment.
--- xen/arch/arm/domain_build.c | 58 ++++++++++++++++++++++++++++++++---- xen/include/asm-arm/domain.h | 3 ++ 2 files changed, 56 insertions(+), 5 deletions(-)
xen/arch/arm/domain_build.c +53 -5
@@ -2424,17 +2424,61 @@ static int __init construct_domU(struct domain *d, {struct kernel_info kinfo = {};int rc; -u64 mem; +u64 mem, static_mem_size =0 ; +const struct dt_property *prop; +u32 static_mem_len; +bool static_mem = false; + +/* +* Guest RAM could be of static memory from static allocation, +* which will be specified through "xen,static-mem" property. +*/ + prop =dt_find_property (node,"xen,static-mem" , &static_mem_len); +if ( prop ) + { +const __be32 *cell; +u32 addr_cells =2 , size_cells =2 , reg_cells; +u64 start, size; +int i, banks; + static_mem = true; + +dt_property_read_u32 (node,"#address-cells" , &addr_cells); +dt_property_read_u32 (node,"#size-cells" , &size_cells); +BUG_ON (size_cells >2 || addr_cells >2 ); + reg_cells = addr_cells + size_cells; + + cell = (const __be32 *)prop->value; + banks = static_mem_len / (reg_cells *sizeof (u32)); +BUG_ON (banks >NR_MEM_BANKS ); + +for ( i =0 ; i < banks; i++ ) + { +device_tree_get_reg (&cell, addr_cells, size_cells, &start, &size); + d->arch.static_mem.bank[i].start = start; + d->arch.static_mem.bank[i].size = size; + static_mem_size += size; + +printk (XENLOG_INFO +"Static Memory Bank[%d] for Domain %pd:" +"0x%" PRIx64"-0x%" PRIx64"\n" , + i, d, + d->arch.static_mem.bank[i].start, + d->arch.static_mem.bank[i].start + + d->arch.static_mem.bank[i].size); + } + d->arch.static_mem.nr_banks = banks; + } rc =dt_property_read_u64 (node,"memory" , &mem); -if ( !rc ) +if ( !static_mem && !rc ) {printk ("Error building DomU: cannot read \"memory\" property\n" );return -EINVAL ; } - kinfo.unassigned_mem = (paddr_t )mem *SZ_1K ; + kinfo.unassigned_mem = static_mem ? static_mem_size : (paddr_t )mem *SZ_1K ; -printk ("*** LOADING DOMU cpus=%u memory=%" PRIx64"KB ***\n" , d->max_vcpus, mem); +printk ("*** LOADING DOMU cpus=%u memory=%" PRIx64"KB ***\n" , + d->max_vcpus, (kinfo.unassigned_mem) >>10 ); kinfo.vpl011 =dt_property_read_bool (node,"vpl011" );
@@ -2452,7 +2496,11 @@ static int __init construct_domU(struct domain *d,/* type must be set before allocate memory */ d->arch.type = kinfo.type;#endif -allocate_memory (d, &kinfo); +if ( static_mem ) +/* allocate_static_memory(d, &kinfo); */ +BUG (); +else +allocate_memory (d, &kinfo); rc =prepare_dtb_domU (d, &kinfo);if ( rc <0 )
xen/include/asm-arm/domain.h +3 -0
@@ -10,6 +10,7 @@#include <asm/gic.h> #include <asm/vgic.h> #include <asm/vpl011.h> +#include <asm/setup.h> #include <public/hvm/params.h> struct hvm_domain
@@ -89,6 +90,8 @@ struct arch_domain#ifdef CONFIG_TEE void *tee;#endif + +struct meminfo static_mem; } __cacheline_aligned;struct arch_vcpu
Signature · 1 line
2.25.1
Re: [PATCH 09/10] xen/arm: parse `xen,static-mem` info during domain construction
Hi Penny,
Quoted 6 lines · Penny Zheng
This commit parses
xen,static-memdevice tree property, to acquire static memory info reserved for this domain, when constructing domain during boot-up.Related info shall be stored in new
static_memvalue under per domain structarch_domain.
So far, this seems to only be used during boot. So can't this be kept in the kinfo structure?
Quoted 53 lines
Right now, the implementation of
allocate_static_memoryis missing, and will be introduced later. It justBUG()out at the moment.Signed-off-by Penny Zheng <[email protected]>--- xen/arch/arm/domain_build.c | 58 ++++++++++++++++++++++++++++++++---- xen/include/asm-arm/domain.h | 3 ++ 2 files changed, 56 insertions(+), 5 deletions(-)xen/arch/arm/domain_build.c +34
-1@@ -2424,17 +2424,61 @@ static int __init construct_domU(struct domain *d, {struct kernel_info kinfo = {};int rc; -u64 mem; +u64 mem, static_mem_size =0 ; +const struct dt_property *prop; +u32 static_mem_len; +bool static_mem = false; + +/* +* Guest RAM could be of static memory from static allocation, +* which will be specified through "xen,static-mem" property. +*/ + prop =dt_find_property (node,"xen,static-mem" , &static_mem_len); +if ( prop ) + { +const __be32 *cell; +u32 addr_cells =2 , size_cells =2 , reg_cells; +u64 start, size; +int i, banks; + static_mem = true; + +dt_property_read_u32 (node,"#address-cells" , &addr_cells); +dt_property_read_u32 (node,"#size-cells" , &size_cells); +BUG_ON (size_cells >2 || addr_cells >2 ); + reg_cells = addr_cells + size_cells; + + cell = (const __be32 *)prop->value; + banks = static_mem_len / (reg_cells *sizeof (u32)); +BUG_ON (banks >NR_MEM_BANKS ); + +for ( i =0 ; i < banks; i++ ) + { +device_tree_get_reg (&cell, addr_cells, size_cells, &start, &size); + d->arch.static_mem.bank[i].start = start; + d->arch.static_mem.bank[i].size = size; + static_mem_size += size; +
xen/arch/arm/domain_build.c static int __init construct_domU(struct domain *d, · line 2470
Quoted 10 lines
xen/arch/arm/domain_build.c +10
-0+printk (XENLOG_INFO +"Static Memory Bank[%d] for Domain %pd:" +"0x%" PRIx64"-0x%" PRIx64"\n" , + i, d, + d->arch.static_mem.bank[i].start, + d->arch.static_mem.bank[i].start + + d->arch.static_mem.bank[i].size); + } + d->arch.static_mem.nr_banks = banks; + }
Could we allocate the memory as we parse?
Quoted 44 lines
xen/arch/arm/domain_build.c +9
-4rc =dt_property_read_u64 (node,"memory" , &mem); -if ( !rc ) +if ( !static_mem && !rc ) {printk ("Error building DomU: cannot read \"memory\" property\n" );return -EINVAL ; } - kinfo.unassigned_mem = (paddr_t )mem *SZ_1K ; + kinfo.unassigned_mem = static_mem ? static_mem_size : (paddr_t )mem *SZ_1K ; -printk ("*** LOADING DOMU cpus=%u memory=%" PRIx64"KB ***\n" , d->max_vcpus, mem); +printk ("*** LOADING DOMU cpus=%u memory=%" PRIx64"KB ***\n" , + d->max_vcpus, (kinfo.unassigned_mem) >>10 ); kinfo.vpl011 =dt_property_read_bool (node,"vpl011" );@@ -2452,7 +2496,11 @@ static int __init construct_domU(struct domain *d,/* type must be set before allocate memory */ d->arch.type = kinfo.type;#endif -allocate_memory (d, &kinfo); +if ( static_mem ) +/* allocate_static_memory(d, &kinfo); */ +BUG (); +else +allocate_memory (d, &kinfo); rc =prepare_dtb_domU (d, &kinfo);if ( rc <0 )xen/include/asm-arm/domain.h +1
-0@@ -10,6 +10,7 @@#include <asm/gic.h> #include <asm/vgic.h> #include <asm/vpl011.h> +#include <asm/setup.h> #include <public/hvm/params.h> struct hvm_domain
xen/include/asm-arm/domain.h struct arch_domain · line 97
Quoted 8 lines
xen/include/asm-arm/domain.h +2
-0@@ -89,6 +90,8 @@ struct arch_domain#ifdef CONFIG_TEE void *tee;#endif + +struct meminfo static_mem; } __cacheline_aligned;struct arch_vcpu
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 09/10] xen/arm: parse `xen,static-mem` info during domain construction
Hi Julien
Quoted 17 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 8:09 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 09/10] xen/arm: parsexen,static-meminfo during domain constructionHi Penny,
Quoted 4 lines · Penny Zheng
This commit parses
xen,static-memdevice tree property, to acquire static memory info reserved for this domain, when constructing domain during boot-up.
Quoted 6 lines
Quoted 2 lines
Related info shall be stored in new
static_memvalue under per domain structarch_domain.So far, this seems to only be used during boot. So can't this be kept in the kinfo structure?
Sure, I'll store it in kinfo
Quoted 59 lines
Quoted 7 lines
Right now, the implementation of
allocate_static_memoryis missing, and will be introduced later. It justBUG()out at the moment.Signed-off-by Penny Zheng <[email protected]>--- xen/arch/arm/domain_build.c | 58++++++++++++++++++++++++++++++++----
xen/arch/arm/domain_build.c static int __init construct_domU(struct domain
Quoted 8 lines
xen/include/asm-arm/domain.h | 3 ++ 2 files changed, 56 insertions(+), 5 deletions(-)xen/arch/arm/domain_build.c +0
-0@@ -2424,17 +2424,61 @@ static int __init construct_domU(struct domain*d,
Quoted 42 lines
xen/arch/arm/domain_build.c +38
-1{struct kernel_info kinfo = {};int rc; -u64 mem; +u64 mem, static_mem_size =0 ; +const struct dt_property *prop; +u32 static_mem_len; +bool static_mem = false; + +/* +* Guest RAM could be of static memory from static allocation, +* which will be specified through "xen,static-mem" property. +*/ + prop =dt_find_property (node,"xen,static-mem" , &static_mem_len); +if ( prop ) + { +const __be32 *cell; +u32 addr_cells =2 , size_cells =2 , reg_cells; +u64 start, size; +int i, banks; + static_mem = true; + +dt_property_read_u32 (node,"#address-cells" , &addr_cells); +dt_property_read_u32 (node,"#size-cells" , &size_cells); +BUG_ON (size_cells >2 || addr_cells >2 ); + reg_cells = addr_cells + size_cells; + + cell = (const __be32 *)prop->value; + banks = static_mem_len / (reg_cells *sizeof (u32)); +BUG_ON (banks >NR_MEM_BANKS ); + +for ( i =0 ; i < banks; i++ ) + { +device_tree_get_reg (&cell, addr_cells, size_cells, &start, &size); + d->arch.static_mem.bank[i].start = start; + d->arch.static_mem.bank[i].size = size; + static_mem_size += size; + + printk(XENLOG_INFO + "Static Memory Bank[%d] for Domain %pd:" + "0x%"PRIx64"-0x%"PRIx64"\n", + i, d,
Quoted 9 lines
xen/arch/arm/domain_build.c static int __init construct_domU(struct domain *d, · line 2470
Quoted 6 lines
xen/arch/arm/domain_build.c +6
-0+ d->arch.static_mem.bank[i].start, + d->arch.static_mem.bank[i].start + + d->arch.static_mem.bank[i].size); + } + d->arch.static_mem.nr_banks = banks; + }Could we allocate the memory as we parse?
Ok. I'll try.
Quoted 53 lines
xen/arch/arm/domain_build.c static int __init construct_domU(struct domain
Quoted 20 lines
xen/arch/arm/domain_build.c +5
-3rc =dt_property_read_u64 (node,"memory" , &mem); -if ( !rc ) +if ( !static_mem && !rc ) {printk ("Error building DomU: cannot read \"memory\" property\n" );return -EINVAL ; } - kinfo.unassigned_mem = (paddr_t )mem *SZ_1K ; + kinfo.unassigned_mem = static_mem ? static_mem_size : + (paddr_t )mem *SZ_1K ; -printk ("*** LOADING DOMU cpus=%u memory=%" PRIx64"KB ***\n" , d- max_vcpus, mem); +printk ("*** LOADING DOMU cpus=%u memory=%" PRIx64"KB ***\n" , + d->max_vcpus, (kinfo.unassigned_mem) >>10 ); kinfo.vpl011 =dt_property_read_bool (node,"vpl011" );@@ -2452,7 +2496,11 @@ static int __init construct_domU(struct domain*d,
Quoted 32 lines
xen/arch/arm/domain_build.c +5
-1/* type must be set before allocate memory */ d->arch.type = kinfo.type;#endif -allocate_memory (d, &kinfo); +if ( static_mem ) +/* allocate_static_memory(d, &kinfo); */ +BUG (); +else +allocate_memory (d, &kinfo); rc =prepare_dtb_domU (d, &kinfo);if ( rc <0 )(quoted diff) +0
-0
b/xen/include/asm-arm/domain.hindexc9277b5c6d..81b8eb453c100644xen/include/asm-arm/domain.h +3
-0@@ -10,6 +10,7 @@#include <asm/gic.h> #include <asm/vgic.h> #include <asm/vpl011.h> +#include <asm/setup.h> #include <public/hvm/params.h> struct hvm_domain @@ -89,6 +90,8 @@ struct arch_domain#ifdef CONFIG_TEE void *tee;#endif + +struct meminfo static_mem; } __cacheline_aligned;
Quoted 7 lines
xen/include/asm-arm/domain.h struct arch_domain · line 97
Quoted 2 lines
xen/include/asm-arm/domain.h +0
-0struct arch_vcpu Cheers,
--
Julien Grall
Cheers
Penny
PATCH 10/10 xen/arm: introduce allocate_static_memory
In reply to Penny ZhengThis commit introduces allocate_static_memory to allocate static memory as guest RAM for domain on Static Allocation.
It uses alloc_domstatic_pages to allocate pre-defined static memory banks for this domain, and uses guest_physmap_add_page to set up P2M table, guest starting at fixed GUEST_RAM0_BASE, GUEST_RAM1_BASE.
--- xen/arch/arm/domain_build.c | 157 +++++++++++++++++++++++++++++++++++- 1 file changed, 155 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +155 -2
@@ -437,6 +437,50 @@ static bool __init allocate_bank_memory(struct domain *d,return true; } +/* +* #ram_index and #ram_index refer to the index and starting address of guest +* memory kank stored in kinfo->mem. +* Static memory at #smfn of #tot_size shall be mapped #sgfn, and +* #sgfn will be next guest address to map when returning. +*/ +static bool __init allocate_static_bank_memory (struct domain *d, +struct kernel_info *kinfo, +int ram_index, +paddr_t ram_addr, +gfn_t * sgfn, +mfn_t smfn, +paddr_t tot_size) +{ +int res; +struct membank *bank; +paddr_t _size = tot_size; + + bank = &kinfo->mem.bank[ram_index]; + bank->start = ram_addr; + bank->size = bank->size + tot_size; + +while ( tot_size >0 ) + { +unsigned int order =get_allocation_size (tot_size); + + res =guest_physmap_add_page (d, *sgfn, smfn, order); +if ( res ) + { +dprintk (XENLOG_ERR ,"Failed map pages to DOMU: %d" , res); +return false; + } + + *sgfn =gfn_add (*sgfn,1UL << order); + smfn =mfn_add (smfn,1UL << order); + tot_size -= (1ULL << (PAGE_SHIFT + order)); + } + + kinfo->mem.nr_banks = ram_index +1 ; + kinfo->unassigned_mem -= _size; + +return true; +} +static void __init allocate_memory (struct domain *d,struct kernel_info *kinfo) {unsigned int i;
@@ -480,6 +524,116 @@ fail: (unsigned long)kinfo->unassigned_mem >> 10); } +/* Allocate memory from static memory as RAM for one specific domain d. */ +static void __init allocate_static_memory (struct domain *d, +struct kernel_info *kinfo) +{ +int nr_banks, _banks =0 ; +size_t ram0_size =GUEST_RAM0_SIZE , ram1_size =GUEST_RAM1_SIZE ; +paddr_t bank_start, bank_size; +gfn_t sgfn; +mfn_t smfn; + + kinfo->mem.nr_banks =0 ; + sgfn =gaddr_to_gfn (GUEST_RAM0_BASE ); + nr_banks = d->arch.static_mem.nr_banks; +ASSERT (nr_banks >=0 ); + +if ( kinfo->unassigned_mem <=0 ) + goto fail; + +while ( _banks < nr_banks ) + { + bank_start = d->arch.static_mem.bank[_banks].start; + smfn =maddr_to_mfn (bank_start); + bank_size = d->arch.static_mem.bank[_banks].size; + +if ( !alloc_domstatic_pages (d, bank_size >>PAGE_SHIFT , bank_start,0 ) ) + { +printk (XENLOG_ERR +"%pd: cannot allocate static memory" +"(0x%" PRIx64" - 0x%" PRIx64")" , + d, bank_start, bank_start + bank_size); + goto fail; + } + +/* +* By default, it shall be mapped to the fixed guest RAM address +* `GUEST_RAM0_BASE`, `GUEST_RAM1_BASE`. +* Starting from RAM0(GUEST_RAM0_BASE). +*/ +if ( ram0_size ) + { +/* RAM0 at most holds GUEST_RAM0_SIZE. */ +if ( ram0_size >= bank_size ) + { +if ( !allocate_static_bank_memory (d, kinfo, +0 ,GUEST_RAM0_BASE , + &sgfn, smfn, bank_size) ) + goto fail; + + ram0_size = ram0_size - bank_size; + _banks++; +continue ; + } +else /* bank_size > ram0_size */ + { +if ( !allocate_static_bank_memory (d, kinfo, +0 ,GUEST_RAM0_BASE , + &sgfn, smfn, ram0_size) ) + goto fail; + +/* The whole RAM0 is consumed. */ + ram0_size -= ram0_size; +/* This bank hasn't been totally mapped, seeking to RAM1. */ + bank_size = bank_size - ram0_size; + smfn =mfn_add (smfn, ram0_size >>PAGE_SHIFT ); + sgfn =gaddr_to_gfn (GUEST_RAM1_BASE ); + } + } + +if ( ram1_size >= bank_size ) + { +if ( !allocate_static_bank_memory (d, kinfo, +1 ,GUEST_RAM1_BASE , + &sgfn, smfn, bank_size) ) + goto fail; + + ram1_size = ram1_size - bank_size; + _banks++; +continue ; + } +else +/* +* If RAM1 still couldn't meet the requirement, +* no way to seek for now. +*/ + goto fail; + } + +if ( kinfo->unassigned_mem ) + goto fail; + +for (int i =0 ; i < kinfo->mem.nr_banks; i++ ) + { +printk (XENLOG_INFO "%pd BANK[%d] %#" PRIpaddr"-%#" PRIpaddr" (%ldMB)\n" , + d, + i, + kinfo->mem.bank[i].start, + kinfo->mem.bank[i].start + kinfo->mem.bank[i].size, +/* Don't want format this as PRIpaddr (16 digit hex) */ + (unsigned long )(kinfo->mem.bank[i].size >>20 )); + } + +return ; + +fail: +panic ("Failed to allocate requested domain memory." +/* Don't want format this as PRIpaddr (16 digit hex) */ +" %ldKB unallocated. Fix the VMs configurations.\n" , + (unsigned long )kinfo->unassigned_mem >>10 ); +} +static int __init write_properties (struct domain *d,struct kernel_info *kinfo,const struct dt_device_node *node) {
@@ -2497,8 +2651,7 @@ static int __init construct_domU(struct domain *d, d->arch.type = kinfo.type;#endif if ( static_mem ) -/* allocate_static_memory(d, &kinfo); */ -BUG (); +allocate_static_memory (d, &kinfo);else allocate_memory (d, &kinfo);
Signature · 1 line
2.25.1
Re: [PATCH 10/10] xen/arm: introduce allocate_static_memory
Hi Penny,
Quoted 19 lines · Penny Zheng
This commit introduces
allocate_static_memoryto allocate static memory as guest RAM for domain on Static Allocation.It uses
alloc_domstatic_pagesto allocate pre-defined static memory banks for this domain, and usesguest_physmap_add_pageto set up P2M table, guest starting at fixedGUEST_RAM0_BASE,GUEST_RAM1_BASE.Signed-off-by Penny Zheng <[email protected]>--- xen/arch/arm/domain_build.c | 157 +++++++++++++++++++++++++++++++++++- 1 file changed, 155 insertions(+), 2 deletions(-)xen/arch/arm/domain_build.c +0
-0@@ -437,6 +437,50 @@ static bool __init allocate_bank_memory(struct domain *d,return true; }
xen/arch/arm/domain_build.c static bool __init allocate_bank_memory(struct domain *d, · line 448
Quoted 10 lines
xen/arch/arm/domain_build.c +9
-0+/* +* #ram_index and #ram_index refer to the index and starting address of guest +* memory kank stored in kinfo->mem. +* Static memory at #smfn of #tot_size shall be mapped #sgfn, and +* #sgfn will be next guest address to map when returning. +*/ +static bool __init allocate_static_bank_memory(struct domain *d, + struct kernel_info *kinfo, + int ram_index,
Please use unsigned.
xen/arch/arm/domain_build.c static bool __init allocate_bank_memory(struct domain *d, · line 450
Quoted 2 lines
xen/arch/arm/domain_build.c +2
-0+paddr_t ram_addr, + gfn_t* sgfn,
I am confused, what is the difference between ram_addr and sgfn?
Quoted 37 lines
xen/arch/arm/domain_build.c +33
-0+mfn_t smfn, + paddr_t tot_size) +{ + int res; +struct membank *bank; +paddr_t _size = tot_size; + + bank = &kinfo->mem.bank[ram_index]; + bank->start = ram_addr; + bank->size = bank->size + tot_size; + +while ( tot_size >0 ) + { +unsigned int order =get_allocation_size (tot_size); + + res =guest_physmap_add_page (d, *sgfn, smfn, order); +if ( res ) + { +dprintk (XENLOG_ERR ,"Failed map pages to DOMU: %d" , res); +return false; + } + + *sgfn =gfn_add (*sgfn,1UL << order); + smfn =mfn_add (smfn,1UL << order); + tot_size -= (1ULL << (PAGE_SHIFT + order)); + } + + kinfo->mem.nr_banks = ram_index +1 ; + kinfo->unassigned_mem -= _size; + +return true; +} +static void __init allocate_memory (struct domain *d,struct kernel_info *kinfo) {unsigned int i;
xen/arch/arm/domain_build.c fail: · line 531
Quoted 8 lines
xen/arch/arm/domain_build.c +5
-0@@ -480,6 +524,116 @@ fail: (unsigned long)kinfo->unassigned_mem >> 10); } +/* Allocate memory from static memory as RAM for one specific domain d. */ +static void __init allocate_static_memory (struct domain *d, +struct kernel_info *kinfo) +{ +int nr_banks, _banks =0 ;
AFAICT, _banks is the index in the array. I think it would be clearer if it is caller 'bank' or 'idx'.
Quoted 8 lines
xen/arch/arm/domain_build.c +8
-0+size_t ram0_size =GUEST_RAM0_SIZE , ram1_size =GUEST_RAM1_SIZE ; +paddr_t bank_start, bank_size; +gfn_t sgfn; +mfn_t smfn; + + kinfo->mem.nr_banks =0 ; + sgfn =gaddr_to_gfn (GUEST_RAM0_BASE ); + nr_banks = d->arch.static_mem.nr_banks;
xen/arch/arm/domain_build.c fail: · line 549
Quoted 10 lines
xen/arch/arm/domain_build.c +10
-0+ASSERT (nr_banks >=0 ); + +if ( kinfo->unassigned_mem <=0 ) + goto fail; + +while ( _banks < nr_banks ) + { + bank_start = d->arch.static_mem.bank[_banks].start; + smfn =maddr_to_mfn (bank_start); + bank_size = d->arch.static_mem.bank[_banks].size;
The variable name are slightly confusing because it doesn't tell whether this is physical are guest RAM. You might want to consider to prefix them with p (resp. g) for physical (resp. guest) RAM.
xen/arch/arm/domain_build.c fail: · line 555
Quoted 6 lines
xen/arch/arm/domain_build.c +6
-0+ +if ( !alloc_domstatic_pages (d, bank_size >>PAGE_SHIFT , bank_start,0 ) ) + { + printk(XENLOG_ERR + "%pd: cannot allocate static memory" + "(0x%"PRIx64" - 0x%"PRIx64")",
bank_start and bank_size are both paddr_t. So this should be PRIpaddr.
xen/arch/arm/domain_build.c fail: · line 564
Quoted 9 lines
xen/arch/arm/domain_build.c +9
-0+ d, bank_start, bank_start + bank_size); + goto fail; + } + +/* +* By default, it shall be mapped to the fixed guest RAM address +* `GUEST_RAM0_BASE`, `GUEST_RAM1_BASE`. +* Starting from RAM0(GUEST_RAM0_BASE). +*/
Ok. So you are first trying to exhaust the guest bank 0 and then moved to bank 1. This wasn't entirely clear from the design document.
I am fine with that, but in this case, the developper should not need to know that (in fact this is not part of the ABI).
Regarding this code, I am a bit concerned about the scalability if we introduce a second bank.
Can we have an array of the possible guest banks and increment the index when exhausting the current bank?
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 10/10] xen/arm: introduce allocate_static_memory
Hi Julien
Quoted 47 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 8:06 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 10/10] xen/arm: introduceallocate_static_memoryHi Penny,
Quoted 10 lines · Penny Zheng
This commit introduces
allocate_static_memoryto allocate static memory as guest RAM for domain on Static Allocation.It uses
alloc_domstatic_pagesto allocate pre-defined static memory banks for this domain, and usesguest_physmap_add_pageto set up P2M table, guest starting at fixedGUEST_RAM0_BASE,GUEST_RAM1_BASE.Signed-off-by Penny Zheng <[email protected]>--- xen/arch/arm/domain_build.c | 157+++++++++++++++++++++++++++++++++++-
xen/arch/arm/domain_build.c static bool __init allocate_bank_memory(struct
Quoted 7 lines
1 file changed, 155 insertions(+), 2 deletions(-)xen/arch/arm/domain_build.c +0
-0@@ -437,6 +437,50 @@ static bool __init allocate_bank_memory(structdomain *d,
xen/arch/arm/domain_build.c static bool __init allocate_bank_memory(struct domain *d, · line 448
Quoted 13 lines
xen/arch/arm/domain_build.c +10
-0return true; } +/* +* #ram_index and #ram_index refer to the index and starting address +of guest +* memory kank stored in kinfo->mem. +* Static memory at #smfn of #tot_size shall be mapped #sgfn, and +* #sgfn will be next guest address to map when returning. +*/ +static bool __init allocate_static_bank_memory(struct domain *d, + struct kernel_info *kinfo, + int ram_index,Please use unsigned.
Quoted 5 lines
xen/arch/arm/domain_build.c static bool __init allocate_bank_memory(struct domain *d, · line 450
Quoted 2 lines
xen/arch/arm/domain_build.c +2
-0+paddr_t ram_addr, + gfn_t* sgfn,I am confused, what is the difference between
ram_addrand sgfn?
We need to constructing kinfo->mem(guest RAM banks) here, and we are indexing in static_mem(physical ram banks). Multiple physical ram banks consist of one guest ram bank(like, GUEST_RAM0).
ram_addr here will either be GUEST_RAM0_BASE, or GUEST_RAM1_BASE, for now. I kinds struggled in how to name it. And maybe it shall not be a parameter here.
Maybe I should switch.. case.. on the ram_index, if its 0, its GUEST_RAM0_BASE, And if its 1, its GUEST_RAM1_BASE.
Quoted 40 lines
Quoted 23 lines
xen/arch/arm/domain_build.c +23
-0+mfn_t smfn, + paddr_t tot_size) { + int res; +struct membank *bank; +paddr_t _size = tot_size; + + bank = &kinfo->mem.bank[ram_index]; + bank->start = ram_addr; + bank->size = bank->size + tot_size; + +while ( tot_size >0 ) + { +unsigned int order =get_allocation_size (tot_size); + + res =guest_physmap_add_page (d, *sgfn, smfn, order); +if ( res ) + { +dprintk (XENLOG_ERR ,"Failed map pages to DOMU: %d" , res); +return false; + } + + *sgfn =gfn_add (*sgfn,1UL << order); + smfn =mfn_add (smfn,1UL << order);xen/arch/arm/domain_build.c static bool __init allocate_bank_memory(struct domain *d,
Quoted 10 lines
xen/arch/arm/domain_build.c +9
-0+ tot_size -= (1ULL << (PAGE_SHIFT + order)); + } + + kinfo->mem.nr_banks = ram_index +1 ; + kinfo->unassigned_mem -= _size; + +return true; +} + static void __init allocate_memory(struct domain *d, struct kernel_info*kinfo)
Quoted 6 lines
xen/arch/arm/domain_build.c +0
-0{unsigned int i;@@ -480,6 +524,116 @@ fail: (unsigned long)kinfo->unassigned_mem >> 10); }
Quoted 9 lines
xen/arch/arm/domain_build.c fail: · line 531
Quoted 5 lines
xen/arch/arm/domain_build.c +5
-0+/* Allocate memory from static memory as RAM for one specific domain +d. */ static void __init allocate_static_memory (struct domain *d, +struct kernel_info +*kinfo) { +int nr_banks, _banks =0 ;AFAICT,
_banksis the index in the array. I think it would be clearer if it is caller 'bank' or 'idx'.
Sure, I’ll use the 'bank' here.
Quoted 14 lines
Quoted 14 lines
xen/arch/arm/domain_build.c +14
-0+size_t ram0_size =GUEST_RAM0_SIZE , ram1_size =GUEST_RAM1_SIZE ; +paddr_t bank_start, bank_size; +gfn_t sgfn; +mfn_t smfn; + + kinfo->mem.nr_banks =0 ; + sgfn =gaddr_to_gfn (GUEST_RAM0_BASE ); + nr_banks = d->arch.static_mem.nr_banks; +ASSERT (nr_banks >=0 ); + +if ( kinfo->unassigned_mem <=0 ) + goto fail; + +while ( _banks < nr_banks )
Quoted 8 lines
xen/arch/arm/domain_build.c fail: · line 549
Quoted 4 lines
xen/arch/arm/domain_build.c +4
-0+ { + bank_start = d->arch.static_mem.bank[_banks].start; + smfn =maddr_to_mfn (bank_start); + bank_size = d->arch.static_mem.bank[_banks].size;The variable name are slightly confusing because it doesn't tell whether this is physical are guest RAM. You might want to consider to prefix them with p (resp. g) for physical (resp. guest) RAM.
Sure, I'll rename to make it more clearly.
Quoted 10 lines
xen/arch/arm/domain_build.c fail: · line 551
Quoted 3 lines
xen/arch/arm/domain_build.c +2
-0+ + if ( !alloc_domstatic_pages(d, bank_size >> PAGE_SHIFT, bank_start,0) )
xen/arch/arm/domain_build.c fail: · line 555
Quoted 4 lines
xen/arch/arm/domain_build.c +4
-0+ { + printk(XENLOG_ERR + "%pd: cannot allocate static memory" + "(0x%"PRIx64" - 0x%"PRIx64")",
bank_startandbank_sizeare bothpaddr_t. So this should be PRIpaddr.
Sure, I'll change
Quoted 14 lines
xen/arch/arm/domain_build.c fail: · line 564
Quoted 10 lines
xen/arch/arm/domain_build.c +9
-0+ d, bank_start, bank_start + bank_size); + goto fail; + } + +/* +* By default, it shall be mapped to the fixed guest RAM address +* `GUEST_RAM0_BASE`, `GUEST_RAM1_BASE`. +* Starting from RAM0(GUEST_RAM0_BASE). +*/ Ok. So you are first trying to exhaust the guest bank 0 and then moved to bank 1. This wasn't entirely clear from the design document.
Quoted 9 lines
I am fine with that, but in this case, the developper should not need to know that (in fact this is not part of the ABI).
Regarding this code, I am a bit concerned about the scalability if we introduce a second bank.
Can we have an array of the possible guest banks and increment the index when exhausting the current bank?
Correct me if I understand wrongly,
What you suggest here is that we make an array of guest banks, right now, including GUEST_RAM0 and GUEST_RAM1. And if later, adding more guest banks, it will not bring scalability problem here, right?
Quoted 4 lines
Cheers,
--
Julien Grall
Cheers
Penny Zheng
Re: [PATCH 10/10] xen/arm: introduce allocate_static_memory
Quoted 59 lines · Penny Zheng
Hi Julien
Quoted 47 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 8:06 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 10/10] xen/arm: introduceallocate_static_memoryHi Penny,
Quoted 10 lines · Penny Zheng
This commit introduces
allocate_static_memoryto allocate static memory as guest RAM for domain on Static Allocation.It uses
alloc_domstatic_pagesto allocate pre-defined static memory banks for this domain, and usesguest_physmap_add_pageto set up P2M table, guest starting at fixedGUEST_RAM0_BASE,GUEST_RAM1_BASE.Signed-off-by Penny Zheng <[email protected]>--- xen/arch/arm/domain_build.c | 157+++++++++++++++++++++++++++++++++++-
xen/arch/arm/domain_build.c static bool __init allocate_bank_memory(struct
Quoted 7 lines
1 file changed, 155 insertions(+), 2 deletions(-)xen/arch/arm/domain_build.c +0
-0@@ -437,6 +437,50 @@ static bool __init allocate_bank_memory(structdomain *d,
xen/arch/arm/domain_build.c static bool __init allocate_bank_memory(struct domain *d, · line 448
Quoted 13 lines
xen/arch/arm/domain_build.c +10
-0return true; } +/* +* #ram_index and #ram_index refer to the index and starting address +of guest +* memory kank stored in kinfo->mem. +* Static memory at #smfn of #tot_size shall be mapped #sgfn, and +* #sgfn will be next guest address to map when returning. +*/ +static bool __init allocate_static_bank_memory(struct domain *d, + struct kernel_info *kinfo, + int ram_index,Please use unsigned.
Quoted 5 lines
xen/arch/arm/domain_build.c static bool __init allocate_bank_memory(struct domain *d, · line 450
Quoted 2 lines
xen/arch/arm/domain_build.c +2
-0+paddr_t ram_addr, + gfn_t* sgfn,I am confused, what is the difference between
ram_addrand sgfn?We need to constructing
kinfo->mem(guest RAM banks)here, and we are indexing instatic_mem(physical ram banks). Multiple physical ram banks consist of one guest rambank(like, GUEST_RAM0).
Quoted 6 lines
ram_addrhere will either beGUEST_RAM0_BASE, orGUEST_RAM1_BASE, for now. I kinds struggled in how to name it. And maybe it shall not be a parameter here.Maybe I should switch.. case.. on the
ram_index, if its 0, itsGUEST_RAM0_BASE, And if its 1, itsGUEST_RAM1_BASE.
You only need to set kinfo->mem.bank[ram_index].start once. This is when you know the bank is first used.
AFAICT, this function will map the memory for a range start at ``sgfn``. It doesn't feel this belongs to the function.
The same remark is valid for kinfo->mem.nr_banks.
Quoted 114 lines
Quoted 40 lines
Quoted 23 lines
xen/arch/arm/domain_build.c +23
-0+mfn_t smfn, + paddr_t tot_size) { + int res; +struct membank *bank; +paddr_t _size = tot_size; + + bank = &kinfo->mem.bank[ram_index]; + bank->start = ram_addr; + bank->size = bank->size + tot_size; + +while ( tot_size >0 ) + { +unsigned int order =get_allocation_size (tot_size); + + res =guest_physmap_add_page (d, *sgfn, smfn, order); +if ( res ) + { +dprintk (XENLOG_ERR ,"Failed map pages to DOMU: %d" , res); +return false; + } + + *sgfn =gfn_add (*sgfn,1UL << order); + smfn =mfn_add (smfn,1UL << order);xen/arch/arm/domain_build.c static bool __init allocate_bank_memory(struct domain *d,
Quoted 10 lines
xen/arch/arm/domain_build.c +9
-0+ tot_size -= (1ULL << (PAGE_SHIFT + order)); + } + + kinfo->mem.nr_banks = ram_index +1 ; + kinfo->unassigned_mem -= _size; + +return true; +} + static void __init allocate_memory(struct domain *d, struct kernel_info*kinfo)
Quoted 6 lines
xen/arch/arm/domain_build.c +0
-0{unsigned int i;@@ -480,6 +524,116 @@ fail: (unsigned long)kinfo->unassigned_mem >> 10); }Quoted 9 lines
xen/arch/arm/domain_build.c fail: · line 531
Quoted 5 lines
xen/arch/arm/domain_build.c +5
-0+/* Allocate memory from static memory as RAM for one specific domain +d. */ static void __init allocate_static_memory (struct domain *d, +struct kernel_info +*kinfo) { +int nr_banks, _banks =0 ;AFAICT,
_banksis the index in the array. I think it would be clearer if it is caller 'bank' or 'idx'.Sure, I’ll use the 'bank' here.
Quoted 14 lines
Quoted 14 lines
xen/arch/arm/domain_build.c +14
-0+size_t ram0_size =GUEST_RAM0_SIZE , ram1_size =GUEST_RAM1_SIZE ; +paddr_t bank_start, bank_size; +gfn_t sgfn; +mfn_t smfn; + + kinfo->mem.nr_banks =0 ; + sgfn =gaddr_to_gfn (GUEST_RAM0_BASE ); + nr_banks = d->arch.static_mem.nr_banks; +ASSERT (nr_banks >=0 ); + +if ( kinfo->unassigned_mem <=0 ) + goto fail; + +while ( _banks < nr_banks )Quoted 8 lines
xen/arch/arm/domain_build.c fail: · line 549
Quoted 4 lines
xen/arch/arm/domain_build.c +4
-0+ { + bank_start = d->arch.static_mem.bank[_banks].start; + smfn =maddr_to_mfn (bank_start); + bank_size = d->arch.static_mem.bank[_banks].size;The variable name are slightly confusing because it doesn't tell whether this is physical are guest RAM. You might want to consider to prefix them with p (resp. g) for physical (resp. guest) RAM.
Sure, I'll rename to make it more clearly.
Quoted 10 lines
xen/arch/arm/domain_build.c fail: · line 551
Quoted 3 lines
xen/arch/arm/domain_build.c +2
-0+ + if ( !alloc_domstatic_pages(d, bank_size >> PAGE_SHIFT, bank_start,0) )
xen/arch/arm/domain_build.c fail: · line 555
Quoted 4 lines
xen/arch/arm/domain_build.c +4
-0+ { + printk(XENLOG_ERR + "%pd: cannot allocate static memory" + "(0x%"PRIx64" - 0x%"PRIx64")",
bank_startandbank_sizeare bothpaddr_t. So this should be PRIpaddr.Sure, I'll change
Quoted 14 lines
xen/arch/arm/domain_build.c fail: · line 564
Quoted 10 lines
xen/arch/arm/domain_build.c +9
-0+ d, bank_start, bank_start + bank_size); + goto fail; + } + +/* +* By default, it shall be mapped to the fixed guest RAM address +* `GUEST_RAM0_BASE`, `GUEST_RAM1_BASE`. +* Starting from RAM0(GUEST_RAM0_BASE). +*/ Ok. So you are first trying to exhaust the guest bank 0 and then moved to bank 1. This wasn't entirely clear from the design document.
Quoted 9 lines
I am fine with that, but in this case, the developper should not need to know that (in fact this is not part of the ABI).
Regarding this code, I am a bit concerned about the scalability if we introduce a second bank.
Can we have an array of the possible guest banks and increment the index when exhausting the current bank?
Quoted 5 lines
Correct me if I understand wrongly,
What you suggest here is that we make an array of guest banks, right now, including
GUEST_RAM0andGUEST_RAM1. And if later, adding more guest banks, it will not bring scalability problem here, right?
Yes. This should also reduce the current complexity of the code.
Cheers,
Signature · 1 line
Julien Grall
RE: [PATCH 10/10] xen/arm: introduce allocate_static_memory
Hi Julien
Quoted 79 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Thursday, May 20, 2021 4:10 AM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 10/10] xen/arm: introduceallocate_static_memoryQuoted 52 lines · Penny Zheng
Hi Julien
Quoted 50 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: Tuesday, May 18, 2021 8:06 PM
To: Penny Zheng <[email protected]>; [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; nd <[email protected]>
Subject: Re: [PATCH 10/10] xen/arm: introduceallocate_static_memoryHi Penny,
Quoted 10 lines · Penny Zheng
This commit introduces
allocate_static_memoryto allocate static memory as guest RAM for domain on Static Allocation.It uses
alloc_domstatic_pagesto allocate pre-defined static memory banks for this domain, and usesguest_physmap_add_pageto set up P2M table, guest starting at fixedGUEST_RAM0_BASE,GUEST_RAM1_BASE.Signed-off-by Penny Zheng <[email protected]>--- xen/arch/arm/domain_build.c | 157+++++++++++++++++++++++++++++++++++-
xen/arch/arm/domain_build.c static bool __init allocate_bank_memory(struct
Quoted 7 lines
1 file changed, 155 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/xen/arch/arm/domain_build.cindex30b55588b7..9f662313ad100644xen/arch/arm/domain_build.c +0
-0@@ -437,6 +437,50 @@ static bool __init allocate_bank_memory(structdomain *d,
xen/arch/arm/domain_build.c static bool __init allocate_bank_memory(struct domain *d, · line 448
Quoted 13 lines
xen/arch/arm/domain_build.c +10
-0return true; } +/* +* #ram_index and #ram_index refer to the index and starting +address of guest +* memory kank stored in kinfo->mem. +* Static memory at #smfn of #tot_size shall be mapped #sgfn, and +* #sgfn will be next guest address to map when returning. +*/ +static bool __init allocate_static_bank_memory(struct domain *d, + struct kernel_info *kinfo, + int ram_index,Please use unsigned.
Quoted 2 lines
xen/arch/arm/domain_build.c +2
-0+paddr_t ram_addr, + gfn_t* sgfn,Quoted 8 lines
Quoted 2 lines
I am confused, what is the difference between
ram_addrand sgfn?We need to constructing
kinfo->mem(guest RAM banks)here, and we are indexing instatic_mem(physical ram banks). Multiple physical ram banks consist of one guest rambank(like, GUEST_RAM0).
ram_addrhere will either beGUEST_RAM0_BASE, orGUEST_RAM1_BASE,for
Quoted 5 lines
now. I kinds struggled in how to name it. And maybe it shall not be a parameter here.
Maybe I should switch.. case.. on the
ram_index, if its 0, itsGUEST_RAM0_BASE, And if its 1, itsGUEST_RAM1_BASE.
Quoted 8 lines
You only need to set kinfo->mem.bank[ram_index].start once. This is when you know the bank is first used.
AFAICT, this function will map the memory for a range start at ``sgfn``. It doesn't feel this belongs to the function.
The same remark is valid for
kinfo->mem.nr_banks.
Ok. I finally totally understand what you suggest here.
I'll try to let the action related to setting kinfo->mem.bank[ram_index].start/ kinfo->mem.bank[ram_index].size/ kinfo->mem. nr_banks out of this function, and only keep the simple functionality of mapping the memory for a range start at ``sgfn``.
Quoted 123 lines
Quoted 116 lines
Quoted 41 lines
Quoted 33 lines
xen/arch/arm/domain_build.c +32
-0+mfn_t smfn, + paddr_t tot_size) { + int res; +struct membank *bank; +paddr_t _size = tot_size; + + bank = &kinfo->mem.bank[ram_index]; + bank->start = ram_addr; + bank->size = bank->size + tot_size; + +while ( tot_size >0 ) + { +unsigned int order =get_allocation_size (tot_size); + + res =guest_physmap_add_page (d, *sgfn, smfn, order); +if ( res ) + { +dprintk (XENLOG_ERR ,"Failed map pages to DOMU: %d" , res); +return false; + } + + *sgfn =gfn_add (*sgfn,1UL << order); + smfn =mfn_add (smfn,1UL << order); + tot_size -= (1ULL << (PAGE_SHIFT + order)); + } + + kinfo->mem.nr_banks = ram_index +1 ; + kinfo->unassigned_mem -= _size; + +return true; +} + static void __init allocate_memory(struct domain *d, structQuoted 1 line
kernel_info*kinfo)
Quoted 6 lines
{ unsigned int i;xen/arch/arm/domain_build.c +0
-0@@ -480,6 +524,116 @@ fail: (unsigned long)kinfo->unassigned_mem >> 10); }Quoted 9 lines
xen/arch/arm/domain_build.c fail: · line 531
Quoted 5 lines
xen/arch/arm/domain_build.c +5
-0+/* Allocate memory from static memory as RAM for one specific +domain d. */ static void __init allocate_static_memory (struct domain *d, +struct kernel_info +*kinfo) { +int nr_banks, _banks =0 ;AFAICT,
_banksis the index in the array. I think it would be clearer if it is caller 'bank' or 'idx'.Sure, I’ll use the 'bank' here.
Quoted 14 lines
Quoted 14 lines
xen/arch/arm/domain_build.c +14
-0+size_t ram0_size =GUEST_RAM0_SIZE , ram1_size =GUEST_RAM1_SIZE ; +paddr_t bank_start, bank_size; +gfn_t sgfn; +mfn_t smfn; + + kinfo->mem.nr_banks =0 ; + sgfn =gaddr_to_gfn (GUEST_RAM0_BASE ); + nr_banks = d->arch.static_mem.nr_banks; +ASSERT (nr_banks >=0 ); + +if ( kinfo->unassigned_mem <=0 ) + goto fail; + +while ( _banks < nr_banks )Quoted 8 lines
xen/arch/arm/domain_build.c fail: · line 549
Quoted 4 lines
xen/arch/arm/domain_build.c +4
-0+ { + bank_start = d->arch.static_mem.bank[_banks].start; + smfn =maddr_to_mfn (bank_start); + bank_size = d->arch.static_mem.bank[_banks].size;The variable name are slightly confusing because it doesn't tell whether this is physical are guest RAM. You might want to consider to prefix them with p (resp. g) for physical (resp. guest) RAM.
Sure, I'll rename to make it more clearly.
Quoted 11 lines
xen/arch/arm/domain_build.c fail: · line 552
Quoted 4 lines
xen/arch/arm/domain_build.c +3
-0+ + if ( !alloc_domstatic_pages(d, bank_size >> PAGE_SHIFT, + bank_start,0) )
xen/arch/arm/domain_build.c fail: · line 555
Quoted 4 lines
xen/arch/arm/domain_build.c +4
-0+ { + printk(XENLOG_ERR + "%pd: cannot allocate static memory" + "(0x%"PRIx64" - 0x%"PRIx64")",
bank_startandbank_sizeare bothpaddr_t. So this should be PRIpaddr.Sure, I'll change
Quoted 14 lines
xen/arch/arm/domain_build.c fail: · line 564
Quoted 10 lines
xen/arch/arm/domain_build.c +9
-0+ d, bank_start, bank_start + bank_size); + goto fail; + } + +/* +* By default, it shall be mapped to the fixed guest RAM address +* `GUEST_RAM0_BASE`, `GUEST_RAM1_BASE`. +* Starting from RAM0(GUEST_RAM0_BASE). +*/ Ok. So you are first trying to exhaust the guest bank 0 and then moved to bank 1. This wasn't entirely clear from the design document.
Quoted 9 lines
I am fine with that, but in this case, the developper should not need to know that (in fact this is not part of the ABI).
Regarding this code, I am a bit concerned about the scalability if we introduce a second bank.
Can we have an array of the possible guest banks and increment the index when exhausting the current bank?
Quoted 6 lines
Correct me if I understand wrongly,
What you suggest here is that we make an array of guest banks, right now, including
GUEST_RAM0andGUEST_RAM1. And if later, adding more guest banks, it will not bring scalability problem here, right?
Quoted 6 lines
Yes. This should also reduce the current complexity of the code.
Cheers,
--
Julien Grall
Cheers
Penny