When constructing a disaggregated Xen system, there are certain domains with
particular capabilities that must be present and running at start-of-day. The
hardware domain is absolutely required, while a xenstore domain is mostly
required.

The function build_core_domains is introduced to encapsulate the construction
of the core domains.

Signed-off-by: Daniel P. Smith <dpsm...@apertussolutions.com>

---

Changes in RFCv2:
- rewrote build_core_domains due address the reordering event channel creation
---
 xen/arch/x86/domain-builder/core.c     | 66 +++++++++++++++++++++++---
 xen/arch/x86/include/asm/boot-domain.h |  2 +
 2 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/domain-builder/core.c 
b/xen/arch/x86/domain-builder/core.c
index 4eaf3a111208..af79792b5316 100644
--- a/xen/arch/x86/domain-builder/core.c
+++ b/xen/arch/x86/domain-builder/core.c
@@ -3,24 +3,76 @@
  * Copyright (C) 2025, Apertus Solutions, LLC
  */
 
+#include <xen/bug.h>
 #include <xen/domain-builder.h>
 #include <xen/init.h>
 #include <xen/lib.h>
 
 #include <asm/bootinfo.h>
+#include <asm/pv/shim.h>
+
+static int  __init build_core_domains(struct boot_info *bi)
+{
+    int count = 0;
+    struct boot_domain *bd;
+    int hw, xs;
+
+    hw = first_boot_domain_index(bi, DOMAIN_CAPS_HARDWARE);
+    if ( hw > MAX_NR_BOOTDOMS )
+        panic("%s: hardware domain missing\n", __func__);
+    else
+    {
+        bd = &bi->domains[hw];
+
+        arch_create_dom(bi, bd);
+        if ( bd->d )
+        {
+            bd->constructed = true;
+            count++;
+        }
+    }
+
+    xs = first_boot_domain_index(bi, DOMAIN_CAPS_XENSTORE);
+    if ( xs > MAX_NR_BOOTDOMS )
+        printk(XENLOG_WARNING "No xenstore domain was defined\n");
+    else
+    {
+        if ( !bi->domains[xs].constructed )
+        {
+            bd = &bi->domains[xs];
+
+            arch_create_dom(bi, bd);
+            if ( bd->d )
+            {
+                bd->constructed = true;
+                count++;
+            }
+        }
+    }
+
+    ASSERT(count <= bi->nr_domains);
+
+    return count;
+}
 
 unsigned int __init builder_create_domains(struct boot_info *bi)
 {
     unsigned int build_count = 0;
-    struct boot_domain *bd = &bi->domains[0];
-
-    if ( bd->capabilities & DOMAIN_CAPS_HARDWARE && bd->kernel == NULL )
-        panic("%s: hardware domain missing kernel\n", __func__);
 
+    if ( bi->nr_domains == 0 )
+        panic("%s: no domains defined\n", __func__);
 
-    arch_create_dom(bi, bd);
-    if ( bd->d )
-        build_count++;
+    if ( pv_shim )
+    {
+        arch_create_dom(bi, &bi->domains[0]);
+        if ( bi->domains[0].d )
+        {
+            bi->domains[0].constructed = true;
+            build_count++;
+        }
+    }
+    else
+        build_count = build_core_domains(bi);
 
     arch_builder_finalize(bi);
 
diff --git a/xen/arch/x86/include/asm/boot-domain.h 
b/xen/arch/x86/include/asm/boot-domain.h
index 66f3a71fd597..41246f31acce 100644
--- a/xen/arch/x86/include/asm/boot-domain.h
+++ b/xen/arch/x86/include/asm/boot-domain.h
@@ -36,6 +36,8 @@ struct boot_domain {
     struct domain *d;
 
     xen_pfn_t xs_page, cons_page;
+
+    bool constructed;
 };
 
 static inline bool __init has_dom0_caps(const struct boot_domain *bd)
-- 
2.30.2


Reply via email to