Skip to contentSkip to conversation

common dom0less updates

PATCH Superseded Oleksii Kurochko 4 participants 18 messages May 13, 2025 – May 15, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover common dom0less updates

This patch series refactor construct_domU() by moving back some Arm-specific changes to Arm code as they aren't used now by other architectures.

Introduce arch_contruct_domU() to cover arch specific steps of a guest domain construction.

Add ARM dependency for CONFIG_STATIC_MEMORY as, at the moment, it it supported only for Arm.

Move make_chosen_node() to common code as nothing Arm specific is in the current implementation of Arm's make_chosen_node().

Xen CI testing: https://gitlab.com/xen-project/people/olkur/xen/-/pipelines/1815213130

Oleksii Kurochko (3):
xen: restrict CONFIG_STATIC_MEMORY to ARM xen/dom0less: refactor architecture-specific DomU construction xen/dom0less: move make_chosen_node() to common code

 xen/arch/arm/dom0less-build.c            | 42 +++++++++----
 xen/arch/arm/domain_build.c              | 46 --------------
 xen/common/Kconfig                       |  2 +-
 xen/common/device-tree/dom0less-build.c  | 76 +++++++++++++++---------
 xen/include/asm-generic/dom0less-build.h |  3 +-
 5 files changed, 83 insertions(+), 86 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/3 xen: restrict CONFIG_STATIC_MEMORY to ARM

Now that CONFIG_DOM0LESS_BOOT has been moved to common code and is planned to be supported by other architectures (e.g., RISC-V), the dependency for CONFIG_STATIC_MEMORY needs to be updated.
Since CONFIG_STATIC_MEMORY is currently only supported on ARM, its dependency should explicitly reflect that.

---
 xen/common/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/Kconfig +1 -1
index bf7b081ad0..5f4a16e113 100644
@@ -148,7 +148,7 @@ config NUMA
 
 config STATIC_MEMORY
 	bool "Static Allocation Support (UNSUPPORTED)" if UNSUPPORTED
-	depends on DOM0LESS_BOOT
+	depends on DOM0LESS_BOOT && ARM
 	help
 	  Static Allocation refers to system or sub-system(domains) for
 	  which memory areas are pre-defined by configuration using physical
Signature · 1 line
2.49.0
#3 lore raw

PATCH 2/3 xen/dom0less: refactor architecture-specific DomU construction

In reply to Oleksii Kurochko

Refactor construct_domU() to improve architecture separation and reduce reliance on ARM-specific logic in common code:
- Drop set_domain_type() from generic code. This function is specific to ARM and serves no purpose on other architectures like RISC-V, which lack the arch.type field in kernel_info.
- Introduce arch_construct_domU() to encapsulate architecture-specific DomU construction steps.
- Implement arch_construct_domU() for ARM. This includes:
- Setting the domain type for CONFIG_ARM64.
- Handling static memory allocation if xen,static-mem is present in the device tree.
- Processing static shared memory.
- Move call of make_resv_memory_node() to Arm's make_arch_nodes() as this call is specific to CONFIG_STATIC_SHM which is ARM specific, at least, now.

This cleanup avoids empty stubs on other architectures and moves ARM-specific logic into arch code where it belongs.

Also, don't loose a return value of functions called in Arm's make_arch_nodes().

---
 xen/arch/arm/dom0less-build.c            | 42 +++++++++++++++++-------
 xen/common/device-tree/dom0less-build.c  | 30 ++---------------
 xen/include/asm-generic/dom0less-build.h |  3 +-
 3 files changed, 36 insertions(+), 39 deletions(-)
xen/arch/arm/dom0less-build.c +31 -11
index a49764f0ad..592173268f 100644
@@ -220,9 +220,14 @@ int __init make_arch_nodes(struct kernel_info *kinfo)
 {
     int ret;
 
+    ret = make_resv_memory_node(kinfo, GUEST_ROOT_ADDRESS_CELLS,
+                                GUEST_ROOT_SIZE_CELLS);
+    if ( ret )
+        return ret;
+
     ret = make_psci_node(kinfo->fdt);
     if ( ret )
-        return -EINVAL;
+        return ret;
 
     if ( kinfo->arch.vpl011 )
     {
@@ -230,26 +235,41 @@ int __init make_arch_nodes(struct kernel_info *kinfo)
         ret = make_vpl011_uart_node(kinfo);
 #endif
         if ( ret )
-            return -EINVAL;
+            return ret;
     }
 
     return 0;
 }
 
-/* TODO: make arch.type generic ? */
-#ifdef CONFIG_ARM_64
-void __init set_domain_type(struct domain *d, struct kernel_info *kinfo)
+int __init arch_construct_domU(struct kernel_info *kinfo,
+                               const struct dt_device_node *node)
 {
+    int rc = 0;
+    struct domain *d = kinfo->d;
+
+#ifdef CONFIG_ARM_64
     /* type must be set before allocate memory */
     d->arch.type = kinfo->arch.type;
-}
-#else
-void __init set_domain_type(struct domain *d, struct kernel_info *kinfo)
-{
-    /* Nothing to do */
-}
 #endif
 
+    if ( !is_hardware_domain(d) )
+    {
+        if ( dt_find_property(node, "xen,static-mem", NULL) )
+        {
+            if ( !is_domain_direct_mapped(d) )
+                allocate_static_memory(d, kinfo, node);
+            else
+                assign_static_memory_11(d, kinfo, node);
+        }
+
+        rc = process_shm(d, kinfo, node);
+        if ( rc < 0 )
+            return rc;
+    }
+
+    return rc;
+}
+
 int __init init_vuart(struct domain *d, struct kernel_info *kinfo,
                       const struct dt_device_node *node)
 {
xen/common/device-tree/dom0less-build.c +3 -27
index 2c56f13771..f6aabc2093 100644
@@ -28,14 +28,6 @@
 #include <asm/dom0less-build.h>
 #include <asm/setup.h>
 
-#if __has_include(<asm/static-memory.h>)
-#   include <asm/static-memory.h>
-#endif
-
-#if __has_include(<asm/static-shmem.h>)
-#   include <asm/static-shmem.h>
-#endif
-
 #define XENSTORE_PFN_LATE_ALLOC UINT64_MAX
 
 static domid_t __initdata xs_domid = DOMID_INVALID;
@@ -507,12 +499,6 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo)
     if ( ret )
         goto err;
 
-#ifdef CONFIG_STATIC_SHM
-    ret = make_resv_memory_node(kinfo, addrcells, sizecells);
-    if ( ret )
-        goto err;
-#endif
-
     /*
      * domain_handle_dtb_bootmodule has to be called before the rest of
      * the device tree is generated because it depends on the value of
@@ -787,7 +773,9 @@ static int __init construct_domU(struct domain *d,
     if ( rc < 0 )
         return rc;
 
-    set_domain_type(d, &kinfo);
+    rc = arch_construct_domU(&kinfo, node);
+    if ( rc )
+        return rc;
 
     if ( is_hardware_domain(d) )
     {
@@ -799,18 +787,6 @@ static int __init construct_domU(struct domain *d,
     {
         if ( !dt_find_property(node, "xen,static-mem", NULL) )
             allocate_memory(d, &kinfo);
-#ifdef CONFIG_STATIC_MEMORY
-        else if ( !is_domain_direct_mapped(d) )
-            allocate_static_memory(d, &kinfo, node);
-        else
-            assign_static_memory_11(d, &kinfo, node);
-#endif
-
-#ifdef CONFIG_STATIC_SHM
-        rc = process_shm(d, &kinfo, node);
-        if ( rc < 0 )
-            return rc;
-#endif
 
         rc = init_vuart(d, &kinfo, node);
         if ( rc < 0 )
xen/include/asm-generic/dom0less-build.h +2 -1
index e0ad0429ec..78142e71ca 100644
@@ -56,7 +56,8 @@ int init_vuart(struct domain *d, struct kernel_info *kinfo,
 int make_intc_domU_node(struct kernel_info *kinfo);
 int make_arch_nodes(struct kernel_info *kinfo);
 
-void set_domain_type(struct domain *d, struct kernel_info *kinfo);
+int arch_construct_domU(struct kernel_info *kinfo,
+                        const struct dt_device_node *node);
 
 int init_intc_phandle(struct kernel_info *kinfo, const char *name,
                       const int node_next, const void *pfdt);
Signature · 1 line
2.49.0
#15 lore raw

PATCH 3/3 xen/dom0less: move make_chosen_node() to common code

In reply to Oleksii Kurochko

The current implementation of make_chosen_node() does not contain any architecture-specific logic. Therefore, move it from arch-specific files to common code.

At this stage, there is no need to introduce an arch_make_chosen_node(), as no architecture-specific customization is required.

This change avoids duplication and simplifies future maintenance for architectures like RISC-V and ARM.

---
 xen/arch/arm/domain_build.c             | 46 -------------------------
 xen/common/device-tree/dom0less-build.c | 46 +++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 46 deletions(-)
xen/arch/arm/domain_build.c +0 -46
index b189a7cfae..9e71cc8cef 100644
@@ -1470,52 +1470,6 @@ int __init make_timer_node(const struct kernel_info *kinfo)
     return res;
 }
 
-/*
- * This function is used as part of the device tree generation for Dom0
- * on ACPI systems, and DomUs started directly from Xen based on device
- * tree information.
- */
-int __init make_chosen_node(const struct kernel_info *kinfo)
-{
-    int res;
-    const char *bootargs = NULL;
-    const struct bootmodule *initrd = kinfo->initrd_bootmodule;
-    void *fdt = kinfo->fdt;
-
-    dt_dprintk("Create chosen node\n");
-    res = fdt_begin_node(fdt, "chosen");
-    if ( res )
-        return res;
-
-    if ( kinfo->cmdline && kinfo->cmdline[0] )
-    {
-        bootargs = &kinfo->cmdline[0];
-        res = fdt_property(fdt, "bootargs", bootargs, strlen(bootargs) + 1);
-        if ( res )
-           return res;
-    }
-
-    /*
-     * If the bootloader provides an initrd, we must create a placeholder
-     * for the initrd properties. The values will be replaced later.
-     */
-    if ( initrd && initrd->size )
-    {
-        u64 a = 0;
-        res = fdt_property(kinfo->fdt, "linux,initrd-start", &a, sizeof(a));
-        if ( res )
-            return res;
-
-        res = fdt_property(kinfo->fdt, "linux,initrd-end", &a, sizeof(a));
-        if ( res )
-            return res;
-    }
-
-    res = fdt_end_node(fdt);
-
-    return res;
-}
-
 static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
                               struct dt_device_node *node,
                               p2m_type_t p2mt)
xen/common/device-tree/dom0less-build.c +46 -0

52 lines not on this page · raw message

Signature · 1 line
2.49.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH v1 1/3] xen: restrict CONFIG_STATIC_MEMORY to ARM

In reply to Oleksii Kurochko
Quoted 7 lines · Oleksii Kurochko

Now that CONFIG_DOM0LESS_BOOT has been moved to common code and is planned to be supported by other architectures (e.g., RISC-V), the dependency for CONFIG_STATIC_MEMORY needs to be updated.
Since CONFIG_STATIC_MEMORY is currently only supported on ARM, its dependency should explicitly reflect that.

~Michal

Reviewed-by on v1 3/3
#16 lore raw

Re: [PATCH v1 3/3] xen/dom0less: move make_chosen_node() to common code

In reply to Oleksii Kurochko
Quoted 11 lines · Oleksii Kurochko

The current implementation of make_chosen_node() does not contain any architecture-specific logic. Therefore, move it from arch-specific files to common code.

At this stage, there is no need to introduce an arch_make_chosen_node(), as no architecture-specific customization is required.

This change avoids duplication and simplifies future maintenance for architectures like RISC-V and ARM.

[snip]

Quoted 3 lines

+/*
+ * This function is used as part of the device tree generation for Dom0
+ * on ACPI systems, and DomUs started directly from Xen based on device

Might be worth adding (on Arm) after 'ACPI systems'. Could be done on commit.

~Michal

Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH v1 2/3] xen/dom0less: refactor architecture-specific DomU construction

In reply to Oleksii Kurochko
Quoted 70 lines · Oleksii Kurochko

Refactor construct_domU() to improve architecture separation and reduce reliance on ARM-specific logic in common code:
- Drop set_domain_type() from generic code. This function is specific to ARM and serves no purpose on other architectures like RISC-V, which lack the arch.type field in kernel_info.
- Introduce arch_construct_domU() to encapsulate architecture-specific DomU construction steps.
- Implement arch_construct_domU() for ARM. This includes:
- Setting the domain type for CONFIG_ARM64.
- Handling static memory allocation if xen,static-mem is present in the device tree.
- Processing static shared memory.
- Move call of make_resv_memory_node() to Arm's make_arch_nodes() as this call is specific to CONFIG_STATIC_SHM which is ARM specific, at least, now.

This cleanup avoids empty stubs on other architectures and moves ARM-specific logic into arch code where it belongs.

Also, don't loose a return value of functions called in Arm's make_arch_nodes().

---
 xen/arch/arm/dom0less-build.c            | 42 +++++++++++++++++-------
 xen/common/device-tree/dom0less-build.c  | 30 ++---------------
 xen/include/asm-generic/dom0less-build.h |  3 +-
 3 files changed, 36 insertions(+), 39 deletions(-)
xen/arch/arm/dom0less-build.c +12 -5
index a49764f0ad..592173268f 100644
@@ -220,9 +220,14 @@ int __init make_arch_nodes(struct kernel_info *kinfo)
 {
     int ret;
 
+    ret = make_resv_memory_node(kinfo, GUEST_ROOT_ADDRESS_CELLS,
+                                GUEST_ROOT_SIZE_CELLS);
+    if ( ret )
+        return ret;
+
     ret = make_psci_node(kinfo->fdt);
     if ( ret )
-        return -EINVAL;
+        return ret;
 
     if ( kinfo->arch.vpl011 )
     {
@@ -230,26 +235,41 @@ int __init make_arch_nodes(struct kernel_info *kinfo)
         ret = make_vpl011_uart_node(kinfo);
 #endif
         if ( ret )
-            return -EINVAL;
+            return ret;
     }
 
     return 0;
 }
 
-/* TODO: make arch.type generic ? */
-#ifdef CONFIG_ARM_64
-void __init set_domain_type(struct domain *d, struct kernel_info *kinfo)
+int __init arch_construct_domU(struct kernel_info *kinfo,
+                               const struct dt_device_node *node)
 {
+    int rc = 0;
+    struct domain *d = kinfo->d;
+

xen/arch/arm/dom0less-build.c int __init make_arch_nodes(struct kernel_info *kinfo) · line 253

Quoted 10 lines
xen/arch/arm/dom0less-build.c +1 -6
+#ifdef CONFIG_ARM_64
     /* type must be set before allocate memory */
     d->arch.type = kinfo->arch.type;
-}
-#else
-void __init set_domain_type(struct domain *d, struct kernel_info *kinfo)
-{
-    /* Nothing to do */
-}
 #endif

NIT: I think it would be nicer to do

if ( is_hardware_domain(d) )

    return rc;

but it is also OK as below

Quoted 100 lines
xen/arch/arm/dom0less-build.c +18 -0
+    if ( !is_hardware_domain(d) )
+    {
+        if ( dt_find_property(node, "xen,static-mem", NULL) )
+        {
+            if ( !is_domain_direct_mapped(d) )
+                allocate_static_memory(d, kinfo, node);
+            else
+                assign_static_memory_11(d, kinfo, node);
+        }
+
+        rc = process_shm(d, kinfo, node);
+        if ( rc < 0 )
+            return rc;
+    }
+
+    return rc;
+}
+
 int __init init_vuart(struct domain *d, struct kernel_info *kinfo,
                       const struct dt_device_node *node)
 {
xen/common/device-tree/dom0less-build.c +3 -27
index 2c56f13771..f6aabc2093 100644
@@ -28,14 +28,6 @@
 #include <asm/dom0less-build.h>
 #include <asm/setup.h>
 
-#if __has_include(<asm/static-memory.h>)
-#   include <asm/static-memory.h>
-#endif
-
-#if __has_include(<asm/static-shmem.h>)
-#   include <asm/static-shmem.h>
-#endif
-
 #define XENSTORE_PFN_LATE_ALLOC UINT64_MAX
 
 static domid_t __initdata xs_domid = DOMID_INVALID;
@@ -507,12 +499,6 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo)
     if ( ret )
         goto err;
 
-#ifdef CONFIG_STATIC_SHM
-    ret = make_resv_memory_node(kinfo, addrcells, sizecells);
-    if ( ret )
-        goto err;
-#endif
-
     /*
      * domain_handle_dtb_bootmodule has to be called before the rest of
      * the device tree is generated because it depends on the value of
@@ -787,7 +773,9 @@ static int __init construct_domU(struct domain *d,
     if ( rc < 0 )
         return rc;
 
-    set_domain_type(d, &kinfo);
+    rc = arch_construct_domU(&kinfo, node);
+    if ( rc )
+        return rc;
 
     if ( is_hardware_domain(d) )
     {
@@ -799,18 +787,6 @@ static int __init construct_domU(struct domain *d,
     {
         if ( !dt_find_property(node, "xen,static-mem", NULL) )
             allocate_memory(d, &kinfo);
-#ifdef CONFIG_STATIC_MEMORY
-        else if ( !is_domain_direct_mapped(d) )
-            allocate_static_memory(d, &kinfo, node);
-        else
-            assign_static_memory_11(d, &kinfo, node);
-#endif
-
-#ifdef CONFIG_STATIC_SHM
-        rc = process_shm(d, &kinfo, node);
-        if ( rc < 0 )
-            return rc;
-#endif
 
         rc = init_vuart(d, &kinfo, node);
         if ( rc < 0 )
xen/include/asm-generic/dom0less-build.h +2 -1
index e0ad0429ec..78142e71ca 100644
@@ -56,7 +56,8 @@ int init_vuart(struct domain *d, struct kernel_info *kinfo,
 int make_intc_domU_node(struct kernel_info *kinfo);
 int make_arch_nodes(struct kernel_info *kinfo);
 
-void set_domain_type(struct domain *d, struct kernel_info *kinfo);
+int arch_construct_domU(struct kernel_info *kinfo,
+                        const struct dt_device_node *node);
 
 int init_intc_phandle(struct kernel_info *kinfo, const char *name,
                       const int node_next, const void *pfdt);
Signature · 1 line
2.49.0
Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH v1 2/3] xen/dom0less: refactor architecture-specific DomU construction

In reply to Oleksii Kurochko
Quoted 16 lines · Oleksii Kurochko

Refactor construct_domU() to improve architecture separation and reduce reliance on ARM-specific logic in common code:
- Drop set_domain_type() from generic code. This function is specific to ARM and serves no purpose on other architectures like RISC-V, which lack the arch.type field in kernel_info.
- Introduce arch_construct_domU() to encapsulate architecture-specific DomU construction steps.
- Implement arch_construct_domU() for ARM. This includes:
- Setting the domain type for CONFIG_ARM64.
- Handling static memory allocation if xen,static-mem is present in the device tree.
- Processing static shared memory.
- Move call of make_resv_memory_node() to Arm's make_arch_nodes() as this call is specific to CONFIG_STATIC_SHM which is ARM specific, at least, now.

Quoted 7 lines

This cleanup avoids empty stubs on other architectures and moves ARM-specific logic into arch code where it belongs.

Also, don't loose a return value of functions called in Arm's make_arch_nodes().

Thanks, it looks better now.

Quoted 1 line

possibly with the remark from Stefano fixed.

~Michal

#7 lore raw

Re: [PATCH v1 2/3] xen/dom0less: refactor architecture-specific DomU construction

In reply to Oleksii Kurochko

Hi Oleksii,

Quoted 5 lines · Oleksii Kurochko

Refactor construct_domU() to improve architecture separation and reduce reliance on ARM-specific logic in common code:
- Drop set_domain_type() from generic code. This function is specific to ARM and serves no purpose on other architectures like RISC-V, which lack the arch.type field in kernel_info.

So you will only ever boot one type of domain on RISC-V? IOW, no 32-bit or else?

Quoted 10 lines

- Introduce arch_construct_domU() to encapsulate architecture-specific DomU construction steps.
- Implement arch_construct_domU() for ARM. This includes:
- Setting the domain type for CONFIG_ARM64.
- Handling static memory allocation if xen,static-mem is present in the device tree.
- Processing static shared memory.
- Move call of make_resv_memory_node() to Arm's make_arch_nodes() as this call is specific to CONFIG_STATIC_SHM which is ARM specific, at least, now.

This looks shortsighted. If there is a plan to use CONFIG_STATIC_SHM on RISC-V (I don't see why not today), then I think the code should stick in common/ even if it is not fully usable
yet (that's the whole point of have CONFIG_* options).

Cheers,

Signature · 1 line
Julien Grall
#17 lore raw

Re: [PATCH v1 3/3] xen/dom0less: move make_chosen_node() to common code

In reply to Orzel, Michal

Hi Michal,

Quoted 14 lines · Michal
Quoted 11 lines · Oleksii Kurochko

The current implementation of make_chosen_node() does not contain any architecture-specific logic. Therefore, move it from arch-specific files to common code.

At this stage, there is no need to introduce an arch_make_chosen_node(), as no architecture-specific customization is required.

This change avoids duplication and simplifies future maintenance for architectures like RISC-V and ARM.

Quoted 8 lines

[snip]

Quoted 3 lines

+/*
+ * This function is used as part of the device tree generation for Dom0
+ * on ACPI systems, and DomUs started directly from Xen based on device

Might be worth adding (on Arm) after 'ACPI systems'. Could be done on commit.

Please don't. This will become stale otherwise as soon as RISC-V is started to use it. Instead, we should say (on platform where CONFIG_ACPI=y).

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw

Re: [PATCH v1 2/3] xen/dom0less: refactor architecture-specific DomU construction

In reply to Stefano Stabellini
Quoted 83 lines · Stefano Stabellini
Quoted 70 lines · Oleksii Kurochko

Refactor construct_domU() to improve architecture separation and reduce reliance on ARM-specific logic in common code:
- Drop set_domain_type() from generic code. This function is specific to ARM and serves no purpose on other architectures like RISC-V, which lack the arch.type field in kernel_info.
- Introduce arch_construct_domU() to encapsulate architecture-specific DomU construction steps.
- Implement arch_construct_domU() for ARM. This includes:
- Setting the domain type for CONFIG_ARM64.
- Handling static memory allocation if xen,static-mem is present in the device tree.
- Processing static shared memory.
- Move call of make_resv_memory_node() to Arm's make_arch_nodes() as this call is specific to CONFIG_STATIC_SHM which is ARM specific, at least, now.

This cleanup avoids empty stubs on other architectures and moves ARM-specific logic into arch code where it belongs.

Also, don't loose a return value of functions called in Arm's make_arch_nodes().

---
  xen/arch/arm/dom0less-build.c            | 42 +++++++++++++++++-------
  xen/common/device-tree/dom0less-build.c  | 30 ++---------------
  xen/include/asm-generic/dom0less-build.h |  3 +-
  3 files changed, 36 insertions(+), 39 deletions(-)
xen/arch/arm/dom0less-build.c +12 -5
index a49764f0ad..592173268f 100644
@@ -220,9 +220,14 @@ int __init make_arch_nodes(struct kernel_info *kinfo)
  {
      int ret;
 
+    ret = make_resv_memory_node(kinfo, GUEST_ROOT_ADDRESS_CELLS,
+                                GUEST_ROOT_SIZE_CELLS);
+    if ( ret )
+        return ret;
+
      ret = make_psci_node(kinfo->fdt);
      if ( ret )
-        return -EINVAL;
+        return ret;
 
      if ( kinfo->arch.vpl011 )
      {
@@ -230,26 +235,41 @@ int __init make_arch_nodes(struct kernel_info *kinfo)
          ret = make_vpl011_uart_node(kinfo);
  #endif
          if ( ret )
-            return -EINVAL;
+            return ret;
      }
 
      return 0;
  }
 
-/* TODO: make arch.type generic ? */
-#ifdef CONFIG_ARM_64
-void __init set_domain_type(struct domain *d, struct kernel_info *kinfo)
+int __init arch_construct_domU(struct kernel_info *kinfo,
+                               const struct dt_device_node *node)
  {
+    int rc = 0;
+    struct domain *d = kinfo->d;
+

xen/arch/arm/dom0less-build.c int __init make_arch_nodes(struct kernel_info *kinfo) · line 253

Quoted 10 lines
xen/arch/arm/dom0less-build.c +1 -6
+#ifdef CONFIG_ARM_64
      /* type must be set before allocate memory */
      d->arch.type = kinfo->arch.type;
-}
-#else
-void __init set_domain_type(struct domain *d, struct kernel_info *kinfo)
-{
-    /* Nothing to do */
-}
  #endif

NIT: I think it would be nicer to do

Quoted 6 lines

if ( is_hardware_domain(d) )

     return rc;

but it is also OK as below

Thanks.

It would be really nicer, I'll update that in the next one version.

~ Oleksii

Quoted 102 lines
Quoted 102 lines
xen/arch/arm/dom0less-build.c +18 -0
+    if ( !is_hardware_domain(d) )
+    {
+        if ( dt_find_property(node, "xen,static-mem", NULL) )
+        {
+            if ( !is_domain_direct_mapped(d) )
+                allocate_static_memory(d, kinfo, node);
+            else
+                assign_static_memory_11(d, kinfo, node);
+        }
+
+        rc = process_shm(d, kinfo, node);
+        if ( rc < 0 )
+            return rc;
+    }
+
+    return rc;
+}
+
  int __init init_vuart(struct domain *d, struct kernel_info *kinfo,
                        const struct dt_device_node *node)
  {
xen/common/device-tree/dom0less-build.c +3 -27
index 2c56f13771..f6aabc2093 100644
@@ -28,14 +28,6 @@
  #include <asm/dom0less-build.h>
  #include <asm/setup.h>
 
-#if __has_include(<asm/static-memory.h>)
-#   include <asm/static-memory.h>
-#endif
-
-#if __has_include(<asm/static-shmem.h>)
-#   include <asm/static-shmem.h>
-#endif
-
  #define XENSTORE_PFN_LATE_ALLOC UINT64_MAX
 
  static domid_t __initdata xs_domid = DOMID_INVALID;
@@ -507,12 +499,6 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo)
      if ( ret )
          goto err;
 
-#ifdef CONFIG_STATIC_SHM
-    ret = make_resv_memory_node(kinfo, addrcells, sizecells);
-    if ( ret )
-        goto err;
-#endif
-
      /*
       * domain_handle_dtb_bootmodule has to be called before the rest of
       * the device tree is generated because it depends on the value of
@@ -787,7 +773,9 @@ static int __init construct_domU(struct domain *d,
      if ( rc < 0 )
          return rc;
 
-    set_domain_type(d, &kinfo);
+    rc = arch_construct_domU(&kinfo, node);
+    if ( rc )
+        return rc;
 
      if ( is_hardware_domain(d) )
      {
@@ -799,18 +787,6 @@ static int __init construct_domU(struct domain *d,
      {
          if ( !dt_find_property(node, "xen,static-mem", NULL) )
              allocate_memory(d, &kinfo);
-#ifdef CONFIG_STATIC_MEMORY
-        else if ( !is_domain_direct_mapped(d) )
-            allocate_static_memory(d, &kinfo, node);
-        else
-            assign_static_memory_11(d, &kinfo, node);
-#endif
-
-#ifdef CONFIG_STATIC_SHM
-        rc = process_shm(d, &kinfo, node);
-        if ( rc < 0 )
-            return rc;
-#endif
 
          rc = init_vuart(d, &kinfo, node);
          if ( rc < 0 )
xen/include/asm-generic/dom0less-build.h +2 -1
index e0ad0429ec..78142e71ca 100644
@@ -56,7 +56,8 @@ int init_vuart(struct domain *d, struct kernel_info *kinfo,
  int make_intc_domU_node(struct kernel_info *kinfo);
  int make_arch_nodes(struct kernel_info *kinfo);
 
-void set_domain_type(struct domain *d, struct kernel_info *kinfo);
+int arch_construct_domU(struct kernel_info *kinfo,
+                        const struct dt_device_node *node);
 
  int init_intc_phandle(struct kernel_info *kinfo, const char *name,
                        const int node_next, const void *pfdt);
Signature · 1 line
2.49.0
#8 lore raw

Re: [PATCH v1 2/3] xen/dom0less: refactor architecture-specific DomU construction

In reply to Julien Grall
Quoted 11 lines · Julien Grall

Hi Oleksii,

Quoted 5 lines · Oleksii Kurochko

Refactor construct_domU() to improve architecture separation and reduce reliance on ARM-specific logic in common code:
- Drop set_domain_type() from generic code. This function is specific to ARM and serves no purpose on other architectures like RISC-V, which lack the arch.type field in kernel_info.

So you will only ever boot one type of domain on RISC-V? IOW, no 32-bit or else?

The bitness of the guest and host should match. So, an RV32 host should run RV32 guests, and an RV64 host should run RV64 guests and so on. (I'm not really sure that on RISC-V it is possible to run with RV64 host an RV32 guest, but need to double-check)

Therefore, my plan for RISC-V is to have the following:
#ifdef CONFIG_RISCV_64
#define is_32bit_domain(d) (0)
#define is_64bit_domain(d) (1)
#else
#define is_32bit_domain(d) (1)
#define is_64bit_domain(d) (0)
#endif

With this definition, there's no need to use|(d)->arch.type| for RISC-V.

Quoted 12 lines
Quoted 11 lines

- Introduce arch_construct_domU() to encapsulate architecture-specific DomU construction steps.
- Implement arch_construct_domU() for ARM. This includes:
   - Setting the domain type for CONFIG_ARM64.
   - Handling static memory allocation if xen,static-mem is present in the device tree.
   - Processing static shared memory.
- Move call of make_resv_memory_node() to Arm's make_arch_nodes() as this call is specific to CONFIG_STATIC_SHM which is ARM specific, at least, now.

Quoted 3 lines

This looks shortsighted. If there is a plan to use CONFIG_STATIC_SHM on RISC-V (I don't see why not today), then I think the code should stick in common/ even if it is not fully usable
yet (that's the whole point of have CONFIG_* options).

We don't use this feature in the downstream repo, but I can imagine some cases where it could be useful. So, for now, its use is purely theoretical and it is a reason why I agreed with Michal and returned back these changes to Arm.

~ Oleksii

Nacked-by NAK
#9 lore raw

Re: [PATCH v1 2/3] xen/dom0less: refactor architecture-specific DomU construction

Hi,

Quoted 42 lines · Oleksii Kurochko
Quoted 11 lines · Julien Grall

Hi Oleksii,

Quoted 5 lines · Oleksii Kurochko

Refactor construct_domU() to improve architecture separation and reduce reliance on ARM-specific logic in common code:
- Drop set_domain_type() from generic code. This function is specific to ARM and serves no purpose on other architectures like RISC-V, which lack the arch.type field in kernel_info.

So you will only ever boot one type of domain on RISC-V? IOW, no 32-bit or else?

The bitness of the guest and host should match. So, an RV32 host should run RV32 guests, and an RV64 host should run RV64 guests and so on. (I'm not really sure that on RISC-V it is possible to run with RV64 host an RV32 guest, but need to double-check)

Therefore, my plan for RISC-V is to have the following:
  #ifdef CONFIG_RISCV_64
  #define is_32bit_domain(d) (0)
  #define is_64bit_domain(d) (1)
  #else
  #define is_32bit_domain(d) (1)
  #define is_64bit_domain(d) (0)
  #endif

With this definition, there's no need to use|(d)->arch.type| for RISC-V.

Quoted 12 lines
Quoted 11 lines

- Introduce arch_construct_domU() to encapsulate architecture-specific DomU construction steps.
- Implement arch_construct_domU() for ARM. This includes:
   - Setting the domain type for CONFIG_ARM64.
   - Handling static memory allocation if xen,static-mem is present in the device tree.
   - Processing static shared memory.
- Move call of make_resv_memory_node() to Arm's make_arch_nodes() as this call is specific to CONFIG_STATIC_SHM which is ARM specific, at least, now.

Quoted 6 lines
Quoted 3 lines

This looks shortsighted. If there is a plan to use CONFIG_STATIC_SHM on RISC-V (I don't see why not today), then I think the code should stick in common/ even if it is not fully usable
yet (that's the whole point of have CONFIG_* options).

We don't use this feature in the downstream repo, but I can imagine some cases where it could be useful. So, for now, its use is purely theoretical and it is a reason why I agreed with Michal and returned back these changes to Arm.

I strongly disagree with this statement. If a feature is not architecture specific (like static shared memory), then the code ought to be in common code so it can be re-used by others.

Also, AFAIK, the bulk of the static shared memory code is in common. So it would be rather easy to add support for RISC-V if we wanted to.

Given the code is already in common, it is rather silly to move the code back to Arm for then moving back to common potentially in a few weeks time.

So:

Cheers,

Signature · 1 line
Julien Grall
#10 lore raw

Re: [PATCH v1 2/3] xen/dom0less: refactor architecture-specific DomU construction

Quoted 50 lines · Julien Grall

Hi,

Quoted 47 lines · Oleksii Kurochko
Quoted 11 lines · Julien Grall

Hi Oleksii,

Quoted 5 lines · Oleksii Kurochko

Refactor construct_domU() to improve architecture separation and reduce reliance on ARM-specific logic in common code:
- Drop set_domain_type() from generic code. This function is specific to ARM and serves no purpose on other architectures like RISC-V, which lack the arch.type field in kernel_info.

So you will only ever boot one type of domain on RISC-V? IOW, no 32-bit or else?

The bitness of the guest and host should match. So, an RV32 host should run RV32 guests, and an RV64 host should run RV64 guests and so on. (I'm not really sure that on RISC-V it is possible to run with RV64 host an RV32 guest, but need to double-check)

Therefore, my plan for RISC-V is to have the following:
  #ifdef CONFIG_RISCV_64
  #define is_32bit_domain(d) (0)
  #define is_64bit_domain(d) (1)
  #else
  #define is_32bit_domain(d) (1)
  #define is_64bit_domain(d) (0)
  #endif

With this definition, there's no need to use|(d)->arch.type| for RISC-V.

Quoted 16 lines
Quoted 11 lines

- Introduce arch_construct_domU() to encapsulate architecture-specific DomU construction steps.
- Implement arch_construct_domU() for ARM. This includes:
   - Setting the domain type for CONFIG_ARM64.
   - Handling static memory allocation if xen,static-mem is present in the device tree.
   - Processing static shared memory.
- Move call of make_resv_memory_node() to Arm's make_arch_nodes() as this call is specific to CONFIG_STATIC_SHM which is ARM specific, at least, now.

This looks shortsighted. If there is a plan to use CONFIG_STATIC_SHM on RISC-V (I don't see why not today), then
I think the code should stick in common/ even if it is not fully usable yet (that's the whole point of have CONFIG_* options).

Quoted 8 lines
Quoted 4 lines

We don't use this feature in the downstream repo, but I can imagine some cases where it could be useful. So, for now, its
use is purely theoretical and it is a reason why I agreed with Michal and returned back these changes to Arm.

I strongly disagree with this statement. If a feature is not architecture specific (like static shared memory), then the code ought to be in common code so it can be re-used by others.

But the code is not common. There are still 900 lines in arch spec dir.

Quoted 5 lines

Also, AFAIK, the bulk of the static shared memory code is in common. So it would be rather easy to add support for RISC-V if we wanted to.

Given the code is already in common, it is rather silly to move the code

IMO it should not be made common in the first place. I don't like exposing callers with the big chunk of code sitting in the arch specific directory. My opinion is that they should be exposed at once when the support for other arches appear. Today we ended up with caller protected with #ifdef and the majority of code in arch dir.

Quoted 1 line

back to Arm for then moving back to common potentially in a few weeks time.

What about static memory code? With the recent Oleksii code movement, the inline helpers like allocate_static_memory() became unreachable when the feature is disabled and the main purpose for helpers was to avoid ifdefery.

Quoted 4 lines

So:

Ok. No more discussion from my side then.

~Michal

#11 lore raw

Re: [PATCH v1 2/3] xen/dom0less: refactor architecture-specific DomU construction

Quoted 58 lines · Michal
Quoted 55 lines · Julien Grall

Hi,

Quoted 51 lines · Oleksii Kurochko
Quoted 11 lines · Julien Grall

Hi Oleksii,

Quoted 5 lines · Oleksii Kurochko

Refactor construct_domU() to improve architecture separation and reduce reliance on ARM-specific logic in common code:
- Drop set_domain_type() from generic code. This function is specific to ARM and serves no purpose on other architectures like RISC-V, which lack the arch.type field in kernel_info.

So you will only ever boot one type of domain on RISC-V? IOW, no 32-bit or else?

The bitness of the guest and host should match. So, an RV32 host should run RV32 guests, and an RV64 host should run RV64 guests and so on. (I'm not really sure that on RISC-V it is possible to run with RV64 host an RV32 guest, but need to double-check)

Therefore, my plan for RISC-V is to have the following:
  #ifdef CONFIG_RISCV_64
  #define is_32bit_domain(d) (0)
  #define is_64bit_domain(d) (1)
  #else
  #define is_32bit_domain(d) (1)
  #define is_64bit_domain(d) (0)
  #endif

With this definition, there's no need to use|(d)->arch.type| for RISC-V.

Quoted 12 lines
Quoted 11 lines

- Introduce arch_construct_domU() to encapsulate architecture-specific DomU construction steps.
- Implement arch_construct_domU() for ARM. This includes:
   - Setting the domain type for CONFIG_ARM64.
   - Handling static memory allocation if xen,static-mem is present in the device tree.
   - Processing static shared memory.
- Move call of make_resv_memory_node() to Arm's make_arch_nodes() as this call is specific to CONFIG_STATIC_SHM which is ARM specific, at least, now.

Quoted 4 lines

This looks shortsighted. If there is a plan to use CONFIG_STATIC_SHM on RISC-V (I don't see why not today), then
I think the code should stick in common/ even if it is not fully usable yet (that's the whole point of have CONFIG_* options).

We don't use this feature in the downstream repo, but I can imagine some cases where it could be useful. So, for now, its
use is purely theoretical and it is a reason why I agreed with Michal and returned back these changes to Arm.

Quoted 4 lines
Quoted 3 lines

I strongly disagree with this statement. If a feature is not architecture specific (like static shared memory), then the code ought to be in common code so it can be re-used by others.

But the code is not common. There are still 900 lines in arch spec dir.

Sure. But my point is rather more that static memory is not a feature described by the Arm Arm. Instead, it is a feature of Xen that is ti to device-tree. So inherently there is no reason to be implemented in arch/arm.

Quoted 7 lines
Quoted 5 lines

Also, AFAIK, the bulk of the static shared memory code is in common. So it would be rather easy to add support for RISC-V if we wanted to.

Given the code is already in common, it is rather silly to move the code

IMO it should not be made common in the first place. I don't like exposing callers with the big chunk of code sitting in the arch specific directory.

So the concern is we didn't go far enough rather than the feature should not be implemented in common for other archs, correct?

Quoted 5 lines
Quoted 2 lines

back to Arm for then moving back to common potentially in a few weeks time.

What about static memory code? With the recent Oleksii code movement, the inline helpers like allocate_static_memory() became unreachable when the feature is disabled and the main purpose for helpers was to avoid ifdefery.

Sorry I am not sure which part you are referring to.

Cheers,

Signature · 1 line
Julien Grall
#12 lore raw

Re: [PATCH v1 2/3] xen/dom0less: refactor architecture-specific DomU construction

Quoted 61 lines · Julien Grall
Quoted 58 lines · Michal
Quoted 55 lines · Julien Grall

Hi,

Quoted 51 lines · Oleksii Kurochko
Quoted 11 lines · Julien Grall

Hi Oleksii,

Quoted 5 lines · Oleksii Kurochko

Refactor construct_domU() to improve architecture separation and reduce reliance on ARM-specific logic in common code:
- Drop set_domain_type() from generic code. This function is specific to ARM and serves no purpose on other architectures like RISC-V, which lack the arch.type field in kernel_info.

So you will only ever boot one type of domain on RISC-V? IOW, no 32-bit or else?

The bitness of the guest and host should match. So, an RV32 host should run RV32 guests, and an RV64 host should run RV64 guests and so on. (I'm not really sure that on RISC-V it is possible to run with RV64 host an RV32 guest, but need to double-check)

Therefore, my plan for RISC-V is to have the following:
  #ifdef CONFIG_RISCV_64
  #define is_32bit_domain(d) (0)
  #define is_64bit_domain(d) (1)
  #else
  #define is_32bit_domain(d) (1)
  #define is_64bit_domain(d) (0)
  #endif

With this definition, there's no need to use|(d)->arch.type| for RISC-V.

Quoted 12 lines
Quoted 11 lines

- Introduce arch_construct_domU() to encapsulate architecture-specific DomU construction steps.
- Implement arch_construct_domU() for ARM. This includes:
   - Setting the domain type for CONFIG_ARM64.
   - Handling static memory allocation if xen,static-mem is present in the device tree.
   - Processing static shared memory.
- Move call of make_resv_memory_node() to Arm's make_arch_nodes() as this call is specific to CONFIG_STATIC_SHM which is ARM specific, at least, now.

Quoted 4 lines

This looks shortsighted. If there is a plan to use CONFIG_STATIC_SHM on RISC-V (I don't see why not today), then
I think the code should stick in common/ even if it is not fully usable yet (that's the whole point of have CONFIG_* options).

We don't use this feature in the downstream repo, but I can imagine some cases where it could be useful. So, for now, its
use is purely theoretical and it is a reason why I agreed with Michal and returned back these changes to Arm.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

I strongly disagree with this statement. If a feature is not architecture specific (like static shared memory), then the code ought to be in common code so it can be re-used by others.

But the code is not common. There are still 900 lines in arch spec dir.

Sure. But my point is rather more that static memory is not a feature described by the Arm Arm. Instead, it is a feature of Xen that is ti to device-tree. So inherently there is no reason to be implemented in arch/arm.

I agree, it can and should be made common. But exposing only callers makes no sense at all for me. Callers should be exposed together with feature code movement.

Quoted 11 lines
Quoted 8 lines
Quoted 6 lines

Also, AFAIK, the bulk of the static shared memory code is in common. So it would be rather easy to add support for RISC-V if we wanted to.

Given the code is already in common, it is rather silly to move the code

IMO it should not be made common in the first place. I don't like exposing callers with the big chunk of code sitting in the arch specific directory.

So the concern is we didn't go far enough rather than the feature should not be implemented in common for other archs, correct?

Yes. Oleksii exposed only callers. His intention was not to make static feature common.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

back to Arm for then moving back to common potentially in a few weeks time.

What about static memory code? With the recent Oleksii code movement, the inline helpers like allocate_static_memory() became unreachable when the feature is disabled and the main purpose for helpers was to avoid ifdefery.

Sorry I am not sure which part you are referring to.

With the current code, allocate_static_memory(), assign_static_memory_11() callers (that were moved to common) are protected with #ifdef. This causes the helpers defined in case CONFIG_STATIC_MEMORY is not defined to be unreachable (see static-memory.h).

~Michal

#13 lore raw

Re: [PATCH v1 2/3] xen/dom0less: refactor architecture-specific DomU construction

Quoted 5 lines · Michal
Quoted 3 lines

Sure. But my point is rather more that static memory is not a feature described by the Arm Arm. Instead, it is a feature of Xen that is ti to device-tree. So inherently there is no reason to be implemented in arch/arm.

I agree, it can and should be made common. But exposing only callers makes no sense at all for me. Callers should be exposed together with feature code movement.

[...]

Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

back to Arm for then moving back to common potentially in a few weeks time.

What about static memory code? With the recent Oleksii code movement, the inline helpers like allocate_static_memory() became unreachable when the feature is disabled and the main purpose for helpers was to avoid ifdefery.

Sorry I am not sure which part you are referring to.

With the current code, allocate_static_memory(), assign_static_memory_11() callers (that were moved to common) are protected with #ifdef. This causes the helpers defined in case CONFIG_STATIC_MEMORY is not defined to be unreachable (see static-memory.h).

At a high level I agree with Julien, this is the kind of feature that should be common. In fact, I would even say that I consider the related device tree bindings common. But looking at the code movements and the #ifdef's, I think that as of today, this patch series is improving things.

So my Ack was not at all a statement to say that the feature should be Arm-only. To the contrary. But it was only a practical consideration about the state of the code right now.

I do think that RISC-V should gain support for it at some point and we should share the code as much as possible.

#14 lore raw

Re: [PATCH v1 2/3] xen/dom0less: refactor architecture-specific DomU construction

Quoted 20 lines · Stefano Stabellini
Quoted 5 lines · Michal
Quoted 3 lines

Sure. But my point is rather more that static memory is not a feature described by the Arm Arm. Instead, it is a feature of Xen that is ti to device-tree. So inherently there is no reason to be implemented in arch/arm.

I agree, it can and should be made common. But exposing only callers makes no sense at all for me. Callers should be exposed together with feature code movement.

[...]

Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

back to Arm for then moving back to common potentially in a few weeks time.

What about static memory code? With the recent Oleksii code movement, the inline helpers like allocate_static_memory() became unreachable when the feature is disabled and the main purpose for helpers was to avoid ifdefery.

Sorry I am not sure which part you are referring to.

With the current code, allocate_static_memory(), assign_static_memory_11() callers (that were moved to common) are protected with #ifdef. This causes the helpers defined in case CONFIG_STATIC_MEMORY is not defined to be unreachable (see static-memory.h).

Quoted 5 lines

At a high level I agree with Julien, this is the kind of feature that should be common. In fact, I would even say that I consider the related device tree bindings common. But looking at the code movements and the #ifdef's, I think that as of today, this patch series is improving things.

I've said multiple times already that I also agree that static mem/shmem should be common. It was not the point of this discussion. My only concern is that it should be done in a proper way and not in 5% like it was done recently that also resulted in issues I mentioned above. Therefore I also (hence my tag) believe we should accept it.

~Michal