Skip to contentSkip to conversation

arm: dom0: allow static memory configuration

RFC PATCH In review Grygorii Strashko 3 participants 4 messages Feb 12, 2025 – Feb 13, 2025

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 arm: dom0: allow static memory configuration

The Arm Xen allocates memory to place Dom0 following the logic described in allocate_memory_11() function which is a bit complicated with major requirement to place Dom0 within the first 128MB of RAM and below 4G. But this doesn't guarantee it will be placed at the same physical base address even between two boots with different configuration (changing the Kernel image size or Initrd size may cause Dom0 base address to change).

In case of "thin Dom0" use case, when Dom0 implemented with RTOS like Zephyr, which doesn't use dynamic device-tree parsing, such behavior causes a lot of inconvenience as it is required to perform modification and recompiling of Zephyr image to adjust memory layout.

It also prevents from using Initrd with Zephyr, for example, as it's expected to be placed at known, fixed address in memory.

This RFC patch introduces the possibility to place Dom0 at fixed physical base address, by checking if "chosen" node contains property "xen,static-mem" and placs Dom0 exactly at the specified memory chunk.

The implementation follows the same approach as for the static, direct-mapped guest domain in case of dom0less boot.

---
 docs/misc/arm/device-tree/booting.txt | 20 ++++++++++++++++++++
 xen/arch/arm/domain_build.c           | 12 +++++++++---
 xen/common/device-tree/bootfdt.c      | 14 ++++++++++++++
 3 files changed, 43 insertions(+), 3 deletions(-)
docs/misc/arm/device-tree/booting.txt +20 -0
index 9c881baccc19..485dcb82de8c 100644
@@ -448,6 +448,26 @@ device-tree:
 This will reserve a 512MB region starting at the host physical address
 0x30000000 to be exclusively used by DomU1.
 
+Dom0 Static Allocation
+======================
+
+The Memory can be statically allocated to a Dom0 using the property
+"xen,static-mem" defined under the "\chosen" node. This options allows to use
+RTOS as the dom0 kernel, which support only static memory layout.
+
+Below is an DT example:
+
+    / {
+        chosen {
+            #address-cells = <0x1>;
+            #size-cells = <0x1>;
+            xen,static-mem = <0x50000000 0x8000000>;
+            ...
+    };
+
+This will reserve a 128MB region starting at the host physical address
+0x50000000 to be exclusively used by Dom0.
+
 Static Event Channel
 ====================
 The event channel communication will be established statically between two
xen/arch/arm/domain_build.c +9 -3
index 7b47abade196..8ee280614813 100644
@@ -31,6 +31,7 @@
 #include <asm/cpufeature.h>
 #include <asm/dom0less-build.h>
 #include <asm/domain_build.h>
+#include <asm/static-memory.h>
 #include <asm/static-shmem.h>
 #include <xen/event.h>
 
@@ -2272,6 +2273,7 @@ int __init construct_domain(struct domain *d, struct kernel_info *kinfo)
 static int __init construct_dom0(struct domain *d)
 {
     struct kernel_info kinfo = KERNEL_INFO_INIT;
+    const struct dt_device_node *chosen = dt_find_node_by_path("/chosen");
     int rc;
 
     /* Sanity! */
@@ -2305,10 +2307,14 @@ static int __init construct_dom0(struct domain *d)
     d->arch.type = kinfo.type;
 #endif
     find_gnttab_region(d, &kinfo);
-    if ( is_domain_direct_mapped(d) )
-        allocate_memory_11(d, &kinfo);
-    else
+    if ( is_domain_direct_mapped(d) ) {
+        if ( !dt_find_property(chosen, "xen,static-mem", NULL) )
+            allocate_memory_11(d, &kinfo);
+        else
+            assign_static_memory_11(d, &kinfo, chosen);
+    } else {
         allocate_memory(d, &kinfo);
+    }
 
     rc = process_shm_chosen(d, &kinfo);
     if ( rc < 0 )
xen/common/device-tree/bootfdt.c +14 -0
index 529c91e603ab..563a5436fac0 100644
@@ -413,6 +413,20 @@ static int __init process_chosen_node(const void *fdt, int node,
         using_static_heap = true;
     }
 
+    if ( fdt_get_property(fdt, node, "xen,static-mem", NULL) )
+    {
+        int rc;
+
+        printk("Checking for static static-mem in /chosen\n");
+
+        rc = device_tree_get_meminfo(fdt, node, "xen,static-mem",
+                                     address_cells, size_cells,
+                                     bootinfo_get_reserved_mem(),
+                                     MEMBANK_STATIC_DOMAIN);
+        if ( rc )
+            return rc;
+    }
+
     printk("Checking for initrd in /chosen\n");
 
     prop = fdt_get_property(fdt, node, "linux,initrd-start", &len);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 15 lines · Grygorii Strashko

The Arm Xen allocates memory to place Dom0 following the logic described in allocate_memory_11() function which is a bit complicated with major requirement to place Dom0 within the first 128MB of RAM and below 4G. But this doesn't guarantee it will be placed at the same physical base address even between two boots with different configuration (changing the Kernel image size or Initrd size may cause Dom0 base address to change).

In case of "thin Dom0" use case, when Dom0 implemented with RTOS like Zephyr, which doesn't use dynamic device-tree parsing, such behavior causes a lot of inconvenience as it is required to perform modification and recompiling of Zephyr image to adjust memory layout.

It also prevents from using Initrd with Zephyr, for example, as it's expected to be placed at known, fixed address in memory.

Quoted 8 lines

This RFC patch introduces the possibility to place Dom0 at fixed physical base address, by checking if "chosen" node contains property "xen,static-mem" and placs Dom0 exactly at the specified memory chunk.

The implementation follows the same approach as for the static, direct-mapped guest domain in case of dom0less boot.

I fully support this idea and the addition of static memory support to Dom0. However, I would suggest a different approach regarding the device tree binding. Specifically, I would prefer to avoid introducing additional top-level properties for Dom0 under /chosen.

Instead, we should create a domain node for Dom0 under /chosen, like we do for other DomUs. Jason is currently working on adding a capability properties to the Dom0less domain nodes, allowing us to specify whether a domain is the hardware domain, the control domain, or both (effectively making it Dom0). Once this is in place, we can use static-mem for Dom0 in the same way as always.

Quoted 103 lines
---
 docs/misc/arm/device-tree/booting.txt | 20 ++++++++++++++++++++
 xen/arch/arm/domain_build.c           | 12 +++++++++---
 xen/common/device-tree/bootfdt.c      | 14 ++++++++++++++
 3 files changed, 43 insertions(+), 3 deletions(-)
docs/misc/arm/device-tree/booting.txt +20 -0
index 9c881baccc19..485dcb82de8c 100644
@@ -448,6 +448,26 @@ device-tree:
 This will reserve a 512MB region starting at the host physical address
 0x30000000 to be exclusively used by DomU1.
 
+Dom0 Static Allocation
+======================
+
+The Memory can be statically allocated to a Dom0 using the property
+"xen,static-mem" defined under the "\chosen" node. This options allows to use
+RTOS as the dom0 kernel, which support only static memory layout.
+
+Below is an DT example:
+
+    / {
+        chosen {
+            #address-cells = <0x1>;
+            #size-cells = <0x1>;
+            xen,static-mem = <0x50000000 0x8000000>;
+            ...
+    };
+
+This will reserve a 128MB region starting at the host physical address
+0x50000000 to be exclusively used by Dom0.
+
 Static Event Channel
 ====================
 The event channel communication will be established statically between two
xen/arch/arm/domain_build.c +9 -3
index 7b47abade196..8ee280614813 100644
@@ -31,6 +31,7 @@
 #include <asm/cpufeature.h>
 #include <asm/dom0less-build.h>
 #include <asm/domain_build.h>
+#include <asm/static-memory.h>
 #include <asm/static-shmem.h>
 #include <xen/event.h>
 
@@ -2272,6 +2273,7 @@ int __init construct_domain(struct domain *d, struct kernel_info *kinfo)
 static int __init construct_dom0(struct domain *d)
 {
     struct kernel_info kinfo = KERNEL_INFO_INIT;
+    const struct dt_device_node *chosen = dt_find_node_by_path("/chosen");
     int rc;
 
     /* Sanity! */
@@ -2305,10 +2307,14 @@ static int __init construct_dom0(struct domain *d)
     d->arch.type = kinfo.type;
 #endif
     find_gnttab_region(d, &kinfo);
-    if ( is_domain_direct_mapped(d) )
-        allocate_memory_11(d, &kinfo);
-    else
+    if ( is_domain_direct_mapped(d) ) {
+        if ( !dt_find_property(chosen, "xen,static-mem", NULL) )
+            allocate_memory_11(d, &kinfo);
+        else
+            assign_static_memory_11(d, &kinfo, chosen);
+    } else {
         allocate_memory(d, &kinfo);
+    }
 
     rc = process_shm_chosen(d, &kinfo);
     if ( rc < 0 )
xen/common/device-tree/bootfdt.c +14 -0
index 529c91e603ab..563a5436fac0 100644
@@ -413,6 +413,20 @@ static int __init process_chosen_node(const void *fdt, int node,
         using_static_heap = true;
     }
 
+    if ( fdt_get_property(fdt, node, "xen,static-mem", NULL) )
+    {
+        int rc;
+
+        printk("Checking for static static-mem in /chosen\n");
+
+        rc = device_tree_get_meminfo(fdt, node, "xen,static-mem",
+                                     address_cells, size_cells,
+                                     bootinfo_get_reserved_mem(),
+                                     MEMBANK_STATIC_DOMAIN);
+        if ( rc )
+            return rc;
+    }
+
     printk("Checking for initrd in /chosen\n");
 
     prop = fdt_get_property(fdt, node, "linux,initrd-start", &len);
Signature · 1 line
2.34.1
#2 lore raw

Hi Stefano,

Quoted 23 lines · Stefano Stabellini
Quoted 22 lines · Grygorii Strashko

The Arm Xen allocates memory to place Dom0 following the logic described in allocate_memory_11() function which is a bit complicated with major requirement to place Dom0 within the first 128MB of RAM and below 4G. But this doesn't guarantee it will be placed at the same physical base address even between two boots with different configuration (changing the Kernel image size or Initrd size may cause Dom0 base address to change).

In case of "thin Dom0" use case, when Dom0 implemented with RTOS like Zephyr, which doesn't use dynamic device-tree parsing, such behavior causes a lot of inconvenience as it is required to perform modification and recompiling of Zephyr image to adjust memory layout.

It also prevents from using Initrd with Zephyr, for example, as it's expected to be placed at known, fixed address in memory.

This RFC patch introduces the possibility to place Dom0 at fixed physical base address, by checking if "chosen" node contains property "xen,static-mem" and places Dom0 exactly at the specified memory chunk.

The implementation follows the same approach as for the static, direct-mapped guest domain in case of dom0less boot.

Quoted 6 lines
Quoted 1 line

I fully support this idea and the addition of static memory support to Dom0. However, I would suggest a different approach regarding the device tree binding. Specifically, I would prefer to avoid introducing additional top-level properties for Dom0 under /chosen.

That's was major point declaring it RFC.

Quoted 7 lines

Instead, we should create a domain node for Dom0 under /chosen, like we do for other DomUs. Jason is currently working on adding a capability properties to the Dom0less domain nodes, allowing us to specify whether a domain is the hardware domain, the control domain, or both (effectively making it Dom0). Once this is in place, we can use static-mem for Dom0 in the same way as always.

Good to here that, I assume it can wait (a bit) then.

But please note that our requirement here to allow static memory for both dom0less and non-dom0less boot, so here is the question - will bindings and dom0/hwdom/control domain setup be generic?

Honestly, for ARM, the discrepancies between boot modes and Xen DT definitions (and actually toolstack) are very confusing :( And now there is also hyperlaunch on the horizon :(

[...]

BR,
-grygorii

#3 lore raw
Quoted 46 lines · Grygorii Strashko

Hi Stefano,

Quoted 26 lines · Stefano Stabellini
Quoted 25 lines · Grygorii Strashko

The Arm Xen allocates memory to place Dom0 following the logic described in
allocate_memory_11() function which is a bit complicated with major requirement to place Dom0 within the first 128MB of RAM and below 4G. But this doesn't guarantee it will be placed at the same physical base address even between two boots with different configuration (changing the Kernel image size or Initrd size may cause Dom0 base address to change).

In case of "thin Dom0" use case, when Dom0 implemented with RTOS like Zephyr, which doesn't use dynamic device-tree parsing, such behavior causes a lot of inconvenience as it is required to perform modification and
recompiling of Zephyr image to adjust memory layout.

It also prevents from using Initrd with Zephyr, for example, as it's expected to be placed at known, fixed address in memory.

This RFC patch introduces the possibility to place Dom0 at fixed physical base address, by checking if "chosen" node contains property "xen,static-mem" and places Dom0 exactly at the specified memory chunk.

The implementation follows the same approach as for the static, direct-mapped
guest domain in case of dom0less boot.

Quoted 6 lines
Quoted 1 line

I fully support this idea and the addition of static memory support to Dom0. However, I would suggest a different approach regarding the device tree binding. Specifically, I would prefer to avoid introducing additional top-level properties for Dom0 under /chosen.

That's was major point declaring it RFC.

Quoted 7 lines

Instead, we should create a domain node for Dom0 under /chosen, like we do for other DomUs. Jason is currently working on adding a capability properties to the Dom0less domain nodes, allowing us to specify whether a domain is the hardware domain, the control domain, or both (effectively making it Dom0). Once this is in place, we can use static-mem for Dom0 in the same way as always.

Quoted 7 lines

Good to here that, I assume it can wait (a bit) then.

But please note that our requirement here to allow static memory for both dom0less and
non-dom0less boot, so here is the question - will bindings and dom0/hwdom/control
domain setup be generic?

Yes, they should be generic.

Quoted 3 lines

Honestly, for ARM, the discrepancies between boot modes and Xen DT definitions (and actually toolstack) are very confusing :( And now there is also hyperlaunch on the horizon :(

The good news is that we managed to align the hyperlaunch DT with the dom0less DT and they are now compatible in the last incarnation of the patch series. The ability to use the dom0less domain nodes (not the legacy dom0 nodes) and still be able to specify a dom0 is something that hyperlaunch had from the start and will be of great benefit to ARM as well.