Skip to contentSkip to conversation

ARM split hardware and control domains

PATCH Superseded Jason Andryuk 4 participants 21 messages Mar 31, 2025 – Apr 2, 2025

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover ARM split hardware and control domains

This series implements separation of dom0 into separate hardware and control domains. It uses the capabilities idea from Hyperlaunch - hardware, control, and xenstore. It's been tested with dom1 as control, dom2 as a domU, and dom3 as hardware and xenstore.

To keep things more managable, this v2 is only the ARM hypervisor changes, and one associated init-dom0less change. The series is slightly re-ordered to move xenstore changes ahead of adding the capabilities.

Setting hardware domain as domid 0 is removed.

I've been unable to run a combined control/xenstore. Linux console output stops shortly after the domain determines it should be XS_LOCAL. I have not investigated further.

Daniel P. Smith (1):
xen: introduce hardware domain create flag

Jason Andryuk (5):
xen/arm: dom0less hwdom construction xen/arm: dom0less delay xenstore initialization xen/arm: dom0less seed xenstore grant table entry tools/init-dom0less: Only seed legacy xenstore grants xen/arm: Add capabilities to dom0less

 docs/misc/arm/device-tree/booting.txt     |  11 ++
 tools/helpers/init-dom0less.c             |  10 +-
 xen/arch/arm/dom0less-build.c             | 167 ++++++++++++++++------
 xen/arch/arm/domain.c                     |   3 +-
 xen/arch/arm/domain_build.c               |  14 +-
 xen/arch/arm/include/asm/dom0less-build.h |   2 +
 xen/arch/arm/include/asm/domain_build.h   |   3 +-
 xen/arch/x86/setup.c                      |   3 +-
 xen/common/domain.c                       |   6 +-
 xen/common/grant_table.c                  |  15 ++
 xen/include/public/bootfdt.h              |  31 ++++
 xen/include/xen/domain.h                  |   2 +
 xen/include/xen/grant_table.h             |   9 ++
 13 files changed, 221 insertions(+), 55 deletions(-)
 create mode 100644 xen/include/public/bootfdt.h
Signature · 1 line
2.49.0
#1 lore raw

PATCH v2 1/6 xen: introduce hardware domain create flag

From: "Daniel P. Smith" <[email protected]>

Add and use a new internal create domain flag to specify the hardware domain. This removes the hardcoding of domid 0 as the hardware domain.

This allows more flexibility with domain creation.

---
v2:
() around binary &
Only allow late_hwdom for dom0

---
 xen/arch/arm/domain_build.c | 2 +-
 xen/arch/x86/setup.c        | 3 ++-
 xen/common/domain.c         | 6 +++++-
 xen/include/xen/domain.h    | 2 ++
 4 files changed, 10 insertions(+), 3 deletions(-)
xen/arch/arm/domain_build.c +1 -1
index 2b5b433183..051c48329a 100644
@@ -2366,7 +2366,7 @@ void __init create_dom0(void)
         .max_maptrack_frames = -1,
         .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version),
     };
-    unsigned int flags = CDF_privileged;
+    unsigned int flags = CDF_privileged | CDF_hardware;
     int rc;
 
     /* The vGIC for DOM0 is exactly emulating the hardware GIC */
xen/arch/x86/setup.c +2 -1
index d70abb7e0c..67d399c469 100644
@@ -1018,7 +1018,8 @@ static struct domain *__init create_dom0(struct boot_info *bi)
 
     /* Create initial domain.  Not d0 for pvshim. */
     domid = get_initial_domain_id();
-    d = domain_create(domid, &dom0_cfg, pv_shim ? 0 : CDF_privileged);
+    d = domain_create(domid, &dom0_cfg,
+                      pv_shim ? 0 : CDF_privileged | CDF_hardware);
     if ( IS_ERR(d) )
         panic("Error creating d%u: %ld\n", domid, PTR_ERR(d));
 
xen/common/domain.c +5 -1
index 585fd726a9..b3eb589872 100644
@@ -820,11 +820,15 @@ struct domain *domain_create(domid_t domid,
     d->is_privileged = flags & CDF_privileged;
 
     /* Sort out our idea of is_hardware_domain(). */
-    if ( domid == 0 || domid == hardware_domid )
+    if ( (flags & CDF_hardware) || domid == hardware_domid )
     {
         if ( hardware_domid < 0 || hardware_domid >= DOMID_FIRST_RESERVED )
             panic("The value of hardware_dom must be a valid domain ID\n");
 
+        /* late_hwdom is only allowed for dom0. */
+        if ( hardware_domain && hardware_domain->domain_id )
+            return ERR_PTR(-EINVAL);
+
         old_hwdom = hardware_domain;
         hardware_domain = d;
     }
xen/include/xen/domain.h +2 -0
index 83069de501..9be18d16b9 100644
@@ -52,6 +52,8 @@ domid_t get_initial_domain_id(void);
 #else
 #define CDF_staticmem            0
 #endif
+/* This is the hardware domain.  Only 1 allowed. */
+#define CDF_hardware             (1U << 3)
 
 #define is_domain_direct_mapped(d) ((d)->cdf & CDF_directmap)
 #define is_domain_using_staticmem(d) ((d)->cdf & CDF_staticmem)
Signature · 1 line
2.49.0
Reviewed-by on v2 1/6
#2 lore raw

Re: [PATCH v2 1/6] xen: introduce hardware domain create flag

xen/common/domain.c struct domain *domain_create(domid_t domid, · line 823

Quoted 8 lines · Jason Andryuk
xen/common/domain.c +1 -1
@@ -820,11 +820,15 @@ struct domain *domain_create(domid_t domid,
     d->is_privileged = flags & CDF_privileged;
 
     /* Sort out our idea of is_hardware_domain(). */
-    if ( domid == 0 || domid == hardware_domid )
+    if ( (flags & CDF_hardware) || domid == hardware_domid )

Since it's || here ...

xen/common/domain.c struct domain *domain_create(domid_t domid, · line 834

Quoted 11 lines
xen/common/domain.c +4 -0
     {
         if ( hardware_domid < 0 || hardware_domid >= DOMID_FIRST_RESERVED )
             panic("The value of hardware_dom must be a valid domain ID\n");
 
+        /* late_hwdom is only allowed for dom0. */
+        if ( hardware_domain && hardware_domain->domain_id )
+            return ERR_PTR(-EINVAL);
+
         old_hwdom = hardware_domain;
         hardware_domain = d;
     }

... doesn't this code then also need to set CDF_hardware if it's unset in the function argument? Then:

Jan

#3 lore raw

Re: [PATCH v2 1/6] xen: introduce hardware domain create flag

Quoted 24 lines · Jan Beulich

xen/common/domain.c struct domain *domain_create(domid_t domid, · line 823

Quoted 8 lines · Jason Andryuk
xen/common/domain.c +1 -1
@@ -820,11 +820,15 @@ struct domain *domain_create(domid_t domid,
      d->is_privileged = flags & CDF_privileged;
 
      /* Sort out our idea of is_hardware_domain(). */
-    if ( domid == 0 || domid == hardware_domid )
+    if ( (flags & CDF_hardware) || domid == hardware_domid )

Since it's || here ...

xen/common/domain.c struct domain *domain_create(domid_t domid, · line 834

Quoted 11 lines
xen/common/domain.c +4 -0
      {
          if ( hardware_domid < 0 || hardware_domid >= DOMID_FIRST_RESERVED )
              panic("The value of hardware_dom must be a valid domain ID\n");
 
+        /* late_hwdom is only allowed for dom0. */
+        if ( hardware_domain && hardware_domain->domain_id )
+            return ERR_PTR(-EINVAL);
+
          old_hwdom = hardware_domain;
          hardware_domain = d;
      }
Quoted 2 lines

... doesn't this code then also need to set CDF_hardware if it's unset in the function argument?

I don't think it matters today - later construction depends on the value of hardware_domain. Which is also used for the check underlying is_hardware_domain().

But I agree that it makes sense to set it here in case the use of CDF_hardware expands in the future.

Quoted 2 lines

Then:

Thanks,
Jason

#4 lore raw

Re: [PATCH v2 1/6] xen: introduce hardware domain create flag

Quoted 28 lines · Jason Andryuk
Quoted 24 lines · Jan Beulich

xen/common/domain.c struct domain *domain_create(domid_t domid, · line 823

Quoted 8 lines · Jason Andryuk
xen/common/domain.c +1 -1
@@ -820,11 +820,15 @@ struct domain *domain_create(domid_t domid,
      d->is_privileged = flags & CDF_privileged;
 
      /* Sort out our idea of is_hardware_domain(). */
-    if ( domid == 0 || domid == hardware_domid )
+    if ( (flags & CDF_hardware) || domid == hardware_domid )

Since it's || here ...

xen/common/domain.c struct domain *domain_create(domid_t domid, · line 834

Quoted 11 lines
xen/common/domain.c +4 -0
      {
          if ( hardware_domid < 0 || hardware_domid >= DOMID_FIRST_RESERVED )
              panic("The value of hardware_dom must be a valid domain ID\n");
 
+        /* late_hwdom is only allowed for dom0. */
+        if ( hardware_domain && hardware_domain->domain_id )
+            return ERR_PTR(-EINVAL);
+
          old_hwdom = hardware_domain;
          hardware_domain = d;
      }
Quoted 2 lines

... doesn't this code then also need to set CDF_hardware if it's unset in the function argument?

Quoted 6 lines

I don't think it matters today - later construction depends on the value of hardware_domain. Which is also used for the check underlying is_hardware_domain().

But I agree that it makes sense to set it here in case the use of CDF_hardware expands in the future.

If we don't do this now, it'll be quite likely that it'll be forgotten later. Hardly anyone actually tests late-hwdom these days, afaict. It may also matter if someone looks at e.g. a dump of Xen after a crash.

Jan

#5 lore raw

PATCH v2 2/6 xen/arm: dom0less hwdom construction

In reply to Jason Andryuk

When creating a hardware domain, have the dom0less code call construct_hwdom() which is shared with the dom0 code. The hardware domain requires building that best matches the dom0 build path. Re-use it to keep them in sync.

The device tree node of the dom0less config is now passed into construct_hwdom(). dom0 uses /chosen for process_shm while a hwdom will use the value from its dom0less device tree node.

---
 xen/arch/arm/dom0less-build.c           | 57 ++++++++++++++-----------
 xen/arch/arm/domain_build.c             | 10 +++--
 xen/arch/arm/include/asm/domain_build.h |  3 +-
 3 files changed, 42 insertions(+), 28 deletions(-)
xen/arch/arm/dom0less-build.c +33 -24
index 573b0d25ae..e25d7bd468 100644
@@ -911,36 +911,45 @@ static int __init construct_domU(struct domain *d,
     /* type must be set before allocate memory */
     d->arch.type = kinfo.type;
 #endif
-    if ( !dt_find_property(node, "xen,static-mem", NULL) )
-        allocate_memory(d, &kinfo);
-    else 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;
-
-    /*
-     * Base address and irq number are needed when creating vpl011 device
-     * tree node in prepare_dtb_domU, so initialization on related variables
-     * shall be done first.
-     */
-    if ( kinfo.vpl011 )
+    if ( is_hardware_domain(d) )
     {
-        rc = domain_vpl011_init(d, NULL);
+        rc = construct_hwdom(&kinfo, node);
         if ( rc < 0 )
             return rc;
     }
+    else
+    {
+        if ( !dt_find_property(node, "xen,static-mem", NULL) )
+            allocate_memory(d, &kinfo);
+        else if ( !is_domain_direct_mapped(d) )
+            allocate_static_memory(d, &kinfo, node);
+        else
+            assign_static_memory_11(d, &kinfo, node);
 
-    rc = prepare_dtb_domU(d, &kinfo);
-    if ( rc < 0 )
-        return rc;
+        rc = process_shm(d, &kinfo, node);
+        if ( rc < 0 )
+            return rc;
 
-    rc = construct_domain(d, &kinfo);
-    if ( rc < 0 )
-        return rc;
+        /*
+         * Base address and irq number are needed when creating vpl011 device
+         * tree node in prepare_dtb_domU, so initialization on related variables
+         * shall be done first.
+         */
+        if ( kinfo.vpl011 )
+        {
+            rc = domain_vpl011_init(d, NULL);
+            if ( rc < 0 )
+                return rc;
+        }
+
+        rc = prepare_dtb_domU(d, &kinfo);
+        if ( rc < 0 )
+            return rc;
+
+        rc = construct_domain(d, &kinfo);
+        if ( rc < 0 )
+            return rc;
+    }
 
     domain_vcpu_affinity(d, node);
 
xen/arch/arm/domain_build.c +7 -3
index 051c48329a..b3a396c2fc 100644
@@ -2305,10 +2305,11 @@ static int __init construct_dom0(struct domain *d)
     if ( rc < 0 )
         return rc;
 
-    return construct_hwdom(&kinfo);
+    return construct_hwdom(&kinfo, NULL);
 }
 
-int __init construct_hwdom(struct kernel_info *kinfo)
+int __init construct_hwdom(struct kernel_info *kinfo,
+                           const struct dt_device_node *node)
 {
     struct domain *d = kinfo->d;
     int rc;
@@ -2325,7 +2326,10 @@ int __init construct_hwdom(struct kernel_info *kinfo)
     else
         allocate_memory(d, kinfo);
 
-    rc = process_shm_chosen(d, kinfo);
+    if ( node )
+        rc = process_shm(d, kinfo, node);
+    else
+        rc = process_shm_chosen(d, kinfo);
     if ( rc < 0 )
         return rc;
 
xen/arch/arm/include/asm/domain_build.h +2 -1
index 134290853c..17619c875d 100644
@@ -13,7 +13,8 @@ bool allocate_bank_memory(struct kernel_info *kinfo, gfn_t sgfn,
                           paddr_t tot_size);
 void allocate_memory(struct domain *d, struct kernel_info *kinfo);
 int construct_domain(struct domain *d, struct kernel_info *kinfo);
-int construct_hwdom(struct kernel_info *kinfo);
+int construct_hwdom(struct kernel_info *kinfo,
+                    const struct dt_device_node *node);
 int domain_fdt_begin_node(void *fdt, const char *name, uint64_t unit);
 int make_chosen_node(const struct kernel_info *kinfo);
 int make_cpus_node(const struct domain *d, void *fdt);
Signature · 1 line
2.49.0
#6 lore raw

Re: [PATCH v2 2/6] xen/arm: dom0less hwdom construction

Quoted 109 lines · Jason Andryuk

When creating a hardware domain, have the dom0less code call construct_hwdom() which is shared with the dom0 code. The hardware domain requires building that best matches the dom0 build path. Re-use it to keep them in sync.

The device tree node of the dom0less config is now passed into construct_hwdom(). dom0 uses /chosen for process_shm while a hwdom will use the value from its dom0less device tree node.

---
 xen/arch/arm/dom0less-build.c           | 57 ++++++++++++++-----------
 xen/arch/arm/domain_build.c             | 10 +++--
 xen/arch/arm/include/asm/domain_build.h |  3 +-
 3 files changed, 42 insertions(+), 28 deletions(-)
xen/arch/arm/dom0less-build.c +33 -24
index 573b0d25ae..e25d7bd468 100644
@@ -911,36 +911,45 @@ static int __init construct_domU(struct domain *d,
     /* type must be set before allocate memory */
     d->arch.type = kinfo.type;
 #endif
-    if ( !dt_find_property(node, "xen,static-mem", NULL) )
-        allocate_memory(d, &kinfo);
-    else 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;
-
-    /*
-     * Base address and irq number are needed when creating vpl011 device
-     * tree node in prepare_dtb_domU, so initialization on related variables
-     * shall be done first.
-     */
-    if ( kinfo.vpl011 )
+    if ( is_hardware_domain(d) )
     {
-        rc = domain_vpl011_init(d, NULL);
+        rc = construct_hwdom(&kinfo, node);
         if ( rc < 0 )
             return rc;
     }
+    else
+    {
+        if ( !dt_find_property(node, "xen,static-mem", NULL) )
+            allocate_memory(d, &kinfo);
+        else if ( !is_domain_direct_mapped(d) )
+            allocate_static_memory(d, &kinfo, node);
+        else
+            assign_static_memory_11(d, &kinfo, node);
 
-    rc = prepare_dtb_domU(d, &kinfo);
-    if ( rc < 0 )
-        return rc;
+        rc = process_shm(d, &kinfo, node);
+        if ( rc < 0 )
+            return rc;
 
-    rc = construct_domain(d, &kinfo);
-    if ( rc < 0 )
-        return rc;
+        /*
+         * Base address and irq number are needed when creating vpl011 device
+         * tree node in prepare_dtb_domU, so initialization on related variables
+         * shall be done first.
+         */
+        if ( kinfo.vpl011 )
+        {
+            rc = domain_vpl011_init(d, NULL);
+            if ( rc < 0 )
+                return rc;
+        }
+
+        rc = prepare_dtb_domU(d, &kinfo);
+        if ( rc < 0 )
+            return rc;
+
+        rc = construct_domain(d, &kinfo);
+        if ( rc < 0 )
+            return rc;
+    }
 
     domain_vcpu_affinity(d, node);
 
xen/arch/arm/domain_build.c +3 -2
index 051c48329a..b3a396c2fc 100644
@@ -2305,10 +2305,11 @@ static int __init construct_dom0(struct domain *d)
     if ( rc < 0 )
         return rc;
 
-    return construct_hwdom(&kinfo);
+    return construct_hwdom(&kinfo, NULL);
 }
 
-int __init construct_hwdom(struct kernel_info *kinfo)
+int __init construct_hwdom(struct kernel_info *kinfo,
+                           const struct dt_device_node *node)
 {
     struct domain *d = kinfo->d;
     int rc;

xen/arch/arm/domain_build.c int __init construct_hwdom(struct kernel_info *kinfo) · line 2332

Quoted 8 lines
xen/arch/arm/domain_build.c +4 -1
@@ -2325,7 +2326,10 @@ int __init construct_hwdom(struct kernel_info *kinfo)
     else
         allocate_memory(d, kinfo);
 
-    rc = process_shm_chosen(d, kinfo);
+    if ( node )
+        rc = process_shm(d, kinfo, node);
+    else
+        rc = process_shm_chosen(d, kinfo);

I think we can avoid this if/else. I see no reason to keep process_shm_chosen. We could check in process_shm, whether node is NULL and then grab /chosen node. I'll try to send a patch shortly.

Rest LGTM.

~Michal

#7 lore raw

PATCH v2 3/6 xen/arm: dom0less delay xenstore initialization

In reply to Jason Andryuk

To allocate the xenstore event channel and initialize the grant table entry, the xenstore domid is neeed. A dom0 is created before the domUs, so it is normally available through hardware_domain. With capabilities and dom0less, the xenstore domain may not be created first.

Keep the population of the page and HVM_PARAM_STORE_PFN in the normal domain construction, but delay event channel creation and grant seeding to after all domUs are created. HVM_PARAM_STORE_PFN now serves as indication to setup xenstore since the device tree is no longer immediately available. 0 means no xenstore. ~0ULL means legacy so only the event channel needs setup, and any other value means to seed the page.

dom0 needs to set xs_domid when it is serving as the xenstore domain.

The domain running xenstored needs to be the handler for VIRQ_DOM_EXC, so set that as well - it otherwise defaults to hardware domain.

---
v2:
Re-order ahead of seeding.
Fix created type in commit message
Change set_xs_domid to set_xs_domain
Set xenstore domain as VIRQ_DOM_EXC handler

---
 xen/arch/arm/dom0less-build.c             | 67 +++++++++++++++++------
 xen/arch/arm/domain_build.c               |  2 +
 xen/arch/arm/include/asm/dom0less-build.h |  2 +
 3 files changed, 53 insertions(+), 18 deletions(-)
xen/arch/arm/dom0less-build.c +49 -18
index e25d7bd468..a46f292c1f 100644
@@ -20,6 +20,15 @@
 #include <asm/static-memory.h>
 #include <asm/static-shmem.h>
 
+static domid_t __initdata xs_domid = DOMID_INVALID;
+static bool __initdata need_xenstore;
+
+void __init set_xs_domain(struct domain *d)
+{
+    xs_domid = d->domain_id;
+    set_global_virq_handler(d, VIRQ_DOM_EXC);
+}
+
 bool __init is_dom0less_mode(void)
 {
     struct bootmodules *mods = &bootinfo.modules;
@@ -694,7 +703,7 @@ static int __init alloc_xenstore_evtchn(struct domain *d)
     int rc;
 
     alloc.dom = d->domain_id;
-    alloc.remote_dom = hardware_domain->domain_id;
+    alloc.remote_dom = xs_domid;
     rc = evtchn_alloc_unbound(&alloc, 0);
     if ( rc )
     {
@@ -760,16 +769,10 @@ static int __init alloc_xenstore_params(struct kernel_info *kinfo)
     struct domain *d = kinfo->d;
     int rc = 0;
 
-    if ( kinfo->dom0less_feature & (DOM0LESS_XENSTORE | DOM0LESS_XS_LEGACY) )
-    {
-        ASSERT(hardware_domain);
-        rc = alloc_xenstore_evtchn(d);
-        if ( rc < 0 )
-            return rc;
+    if ( (kinfo->dom0less_feature & (DOM0LESS_XENSTORE | DOM0LESS_XS_LEGACY))
+                                 == (DOM0LESS_XENSTORE | DOM0LESS_XS_LEGACY) )
         d->arch.hvm.params[HVM_PARAM_STORE_PFN] = ~0ULL;
-    }
-
-    if ( kinfo->dom0less_feature & DOM0LESS_XENSTORE )
+    else if ( kinfo->dom0less_feature & DOM0LESS_XENSTORE )
     {
         rc = alloc_xenstore_page(d);
         if ( rc < 0 )
@@ -841,6 +844,30 @@ static void __init domain_vcpu_affinity(struct domain *d,
     }
 }
 
+static void __init initialize_domU_xenstore(void)
+{
+    struct domain *d;
+
+    if ( xs_domid == DOMID_INVALID )
+        return;
+
+    for_each_domain( d )
+    {
+        unsigned long gfn = d->arch.hvm.params[HVM_PARAM_STORE_PFN];
+        int rc;
+
+        if ( gfn == 0 )
+            continue;
+
+        if ( is_xenstore_domain(d) )
+            continue;
+
+        rc = alloc_xenstore_evtchn(d);
+        if ( rc < 0 )
+            panic("%pd: Failed to allocate xenstore_evtchn\n", d);
+    }
+}
+
 static int __init construct_domU(struct domain *d,
                                  const struct dt_device_node *node)
 {
@@ -881,17 +908,13 @@ static int __init construct_domU(struct domain *d,
          rc == -ENODATA ||
          (rc == 0 && !strcmp(dom0less_enhanced, "enabled")) )
     {
-        if ( hardware_domain )
-            kinfo.dom0less_feature = DOM0LESS_ENHANCED;
-        else
-            panic("At the moment, Xenstore support requires dom0 to be present\n");
+        need_xenstore = true;
+        kinfo.dom0less_feature = DOM0LESS_ENHANCED;
     }
     else if ( rc == 0 && !strcmp(dom0less_enhanced, "legacy") )
     {
-        if ( hardware_domain )
-            kinfo.dom0less_feature = DOM0LESS_ENHANCED_LEGACY;
-        else
-            panic("At the moment, Xenstore support requires dom0 to be present\n");
+        need_xenstore = true;
+        kinfo.dom0less_feature = DOM0LESS_ENHANCED_LEGACY;
     }
     else if ( rc == 0 && !strcmp(dom0less_enhanced, "no-xenstore") )
         kinfo.dom0less_feature = DOM0LESS_ENHANCED_NO_XS;
@@ -1138,7 +1161,15 @@ void __init create_domUs(void)
         if ( rc )
             panic("Could not set up domain %s (rc = %d)\n",
                   dt_node_name(node), rc);
+
+        if ( d_cfg.flags & XEN_DOMCTL_CDF_xs_domain )
+            set_xs_domain(d);
     }
+
+    if ( need_xenstore && xs_domid == DOMID_INVALID )
+        panic("xenstore requested, but xenstore domain not present\n");
+
+    initialize_domU_xenstore();
 }
 
 /*
xen/arch/arm/domain_build.c +2 -0
index b3a396c2fc..d99ca7b43f 100644
@@ -2408,6 +2408,8 @@ void __init create_dom0(void)
     rc = construct_dom0(dom0);
     if ( rc )
         panic("Could not set up DOM0 guest OS (rc = %d)\n", rc);
+
+    set_xs_domain(dom0);
 }
 
 /*
xen/arch/arm/include/asm/dom0less-build.h +2 -0
index 5864944bda..b0e41a1954 100644
@@ -9,6 +9,7 @@
 
 void create_domUs(void);
 bool is_dom0less_mode(void);
+void set_xs_domain(struct domain *d);
 
 #else /* !CONFIG_DOM0LESS_BOOT */
 
@@ -17,6 +18,7 @@ static inline bool is_dom0less_mode(void)
 {
     return false;
 }
+static inline void set_xs_domain(struct domain *d) {}
 
 #endif /* CONFIG_DOM0LESS_BOOT */
 
Signature · 1 line
2.49.0
Reviewed-by on v2 3/6
#8 lore raw

Re: [PATCH v2 3/6] xen/arm: dom0less delay xenstore initialization

Quoted 86 lines · Jason Andryuk

To allocate the xenstore event channel and initialize the grant table entry, the xenstore domid is neeed. A dom0 is created before the domUs, so it is normally available through hardware_domain. With capabilities and dom0less, the xenstore domain may not be created first.

Keep the population of the page and HVM_PARAM_STORE_PFN in the normal domain construction, but delay event channel creation and grant seeding to after all domUs are created. HVM_PARAM_STORE_PFN now serves as indication to setup xenstore since the device tree is no longer immediately available. 0 means no xenstore. ~0ULL means legacy so only the event channel needs setup, and any other value means to seed the page.

dom0 needs to set xs_domid when it is serving as the xenstore domain.

The domain running xenstored needs to be the handler for VIRQ_DOM_EXC, so set that as well - it otherwise defaults to hardware domain.

---
v2:
Re-order ahead of seeding.
Fix created type in commit message
Change set_xs_domid to set_xs_domain
Set xenstore domain as VIRQ_DOM_EXC handler

---
 xen/arch/arm/dom0less-build.c             | 67 +++++++++++++++++------
 xen/arch/arm/domain_build.c               |  2 +
 xen/arch/arm/include/asm/dom0less-build.h |  2 +
 3 files changed, 53 insertions(+), 18 deletions(-)
xen/arch/arm/dom0less-build.c +13 -10
index e25d7bd468..a46f292c1f 100644
@@ -20,6 +20,15 @@
 #include <asm/static-memory.h>
 #include <asm/static-shmem.h>
 
+static domid_t __initdata xs_domid = DOMID_INVALID;
+static bool __initdata need_xenstore;
+
+void __init set_xs_domain(struct domain *d)
+{
+    xs_domid = d->domain_id;
+    set_global_virq_handler(d, VIRQ_DOM_EXC);
+}
+
 bool __init is_dom0less_mode(void)
 {
     struct bootmodules *mods = &bootinfo.modules;
@@ -694,7 +703,7 @@ static int __init alloc_xenstore_evtchn(struct domain *d)
     int rc;
 
     alloc.dom = d->domain_id;
-    alloc.remote_dom = hardware_domain->domain_id;
+    alloc.remote_dom = xs_domid;
     rc = evtchn_alloc_unbound(&alloc, 0);
     if ( rc )
     {
@@ -760,16 +769,10 @@ static int __init alloc_xenstore_params(struct kernel_info *kinfo)
     struct domain *d = kinfo->d;
     int rc = 0;
 
-    if ( kinfo->dom0less_feature & (DOM0LESS_XENSTORE | DOM0LESS_XS_LEGACY) )
-    {
-        ASSERT(hardware_domain);
-        rc = alloc_xenstore_evtchn(d);
-        if ( rc < 0 )
-            return rc;
+    if ( (kinfo->dom0less_feature & (DOM0LESS_XENSTORE | DOM0LESS_XS_LEGACY))
+                                 == (DOM0LESS_XENSTORE | DOM0LESS_XS_LEGACY) )
         d->arch.hvm.params[HVM_PARAM_STORE_PFN] = ~0ULL;
-    }
-
-    if ( kinfo->dom0less_feature & DOM0LESS_XENSTORE )
+    else if ( kinfo->dom0less_feature & DOM0LESS_XENSTORE )
     {
         rc = alloc_xenstore_page(d);
         if ( rc < 0 )
@@ -841,6 +844,30 @@ static void __init domain_vcpu_affinity(struct domain *d,
     }
 }
 

xen/arch/arm/dom0less-build.c static void __init domain_vcpu_affinity(struct domain *d, · line 856

Quoted 10 lines
xen/arch/arm/dom0less-build.c +10 -0
+static void __init initialize_domU_xenstore(void)
+{
+    struct domain *d;
+
+    if ( xs_domid == DOMID_INVALID )
+        return;
+
+    for_each_domain( d )
+    {
+        unsigned long gfn = d->arch.hvm.params[HVM_PARAM_STORE_PFN];

This should be uint64_t. With that change:

Quoted 17 lines
xen/arch/arm/dom0less-build.c +14 -0
+        int rc;
+
+        if ( gfn == 0 )
+            continue;
+
+        if ( is_xenstore_domain(d) )
+            continue;
+
+        rc = alloc_xenstore_evtchn(d);
+        if ( rc < 0 )
+            panic("%pd: Failed to allocate xenstore_evtchn\n", d);
+    }
+}
+
 static int __init construct_domU(struct domain *d,
                                  const struct dt_device_node *node)
 {
#9 lore raw

PATCH v2 4/6 xen/arm: dom0less seed xenstore grant table entry

In reply to Jason Andryuk

xenstored maps other domains' xenstore pages. Currently this relies on init-dom0less or xl to seed the grants from Dom0. With split hardware/control/xenstore domains, this is problematic since we don't want the hardware domain to be able to map other domains' resources without their permission. Instead have the hypervisor seed the grant table entry for every dom0less domain. The grant is then accessible as normal.

This works with C xenstored. OCaml xenstored does not use grants and would fail to foreign map the page.

---
v2:
Tweak commit message
Mark gnttab_seed_entry() __init and put inside CONFIG_DOM0LESS_BOOT Add ASSERT(!d->creation_finished) and ASSERT(gt->gt_version == 1); const struct domain & struct grant_table

---
 xen/arch/arm/dom0less-build.c |  4 ++++
 xen/common/grant_table.c      | 15 +++++++++++++++
 xen/include/xen/grant_table.h |  9 +++++++++
 3 files changed, 28 insertions(+)
xen/arch/arm/dom0less-build.c +4 -0
index a46f292c1f..fc515c9852 100644
@@ -865,6 +865,10 @@ static void __init initialize_domU_xenstore(void)
         rc = alloc_xenstore_evtchn(d);
         if ( rc < 0 )
             panic("%pd: Failed to allocate xenstore_evtchn\n", d);
+
+        if ( gfn != ~0ULL )
+            gnttab_seed_entry(d, GNTTAB_RESERVED_XENSTORE, xs_domid,
+                              gfn, GTF_permit_access);
     }
 }
 
xen/common/grant_table.c +15 -0
index 6c77867f8c..2fb3679447 100644
@@ -4346,6 +4346,21 @@ static void gnttab_usage_print(struct domain *rd)
         printk("no active grant table entries\n");
 }
 
+#ifdef CONFIG_DOM0LESS_BOOT
+void __init gnttab_seed_entry(const struct domain *d, unsigned int idx,
+                              domid_t be_domid, uint64_t frame,
+                              unsigned int flags)
+{
+    const struct grant_table *gt = d->grant_table;
+
+    ASSERT(!d->creation_finished);
+    ASSERT(gt->gt_version == 1);
+    shared_entry_v1(gt, idx).flags = flags;
+    shared_entry_v1(gt, idx).domid = be_domid;
+    shared_entry_v1(gt, idx).frame = frame;
+}
+#endif
+
 static void cf_check gnttab_usage_print_all(unsigned char key)
 {
     struct domain *d;
xen/include/xen/grant_table.h +9 -0
index 50edfecfb6..a17f1787da 100644
@@ -45,6 +45,11 @@ void grant_table_destroy(
     struct domain *d);
 void grant_table_init_vcpu(struct vcpu *v);
 
+/* Seed a gnttab entry for Hyperlaunch/dom0less. */
+void __init gnttab_seed_entry(const struct domain *d, unsigned int idx,
+                              domid_t be_domid, uint64_t frame,
+                              unsigned int flags);
+
 /*
  * Check if domain has active grants and log first 10 of them.
  */
@@ -85,6 +90,10 @@ static inline void grant_table_destroy(struct domain *d) {}
 
 static inline void grant_table_init_vcpu(struct vcpu *v) {}
 
+static inline void gnttab_seed_entry(struct domain *d, int idx,
+                                     domid_t be_domid, uint64_t frame,
+                                     unsigned int flags) {}
+
 static inline void grant_table_warn_active_grants(struct domain *d) {}
 
 static inline int gnttab_release_mappings(struct domain *d) { return 0; }
Signature · 1 line
2.49.0
#10 lore raw

Re: [PATCH v2 4/6] xen/arm: dom0less seed xenstore grant table entry

Quoted 7 lines · Jason Andryuk

xenstored maps other domains' xenstore pages. Currently this relies on init-dom0less or xl to seed the grants from Dom0. With split hardware/control/xenstore domains, this is problematic since we don't want the hardware domain to be able to map other domains' resources without their permission. Instead have the hypervisor seed the grant table entry for every dom0less domain. The grant is then accessible as normal.

Yet aiui the original idea was to specifically not do this in the hypervisor. I agree it shouldn't be the hardware domain, but what's wrong with having the control domain do that? It is what is responsible for creating new domains as well. The question of where to do that when there's no control domain must also have been solved already (without me knowing the answer), as that's where init-dom0less must be running.

Quoted 2 lines

This works with C xenstored. OCaml xenstored does not use grants and would fail to foreign map the page.

From the sentence it's not clear whether this is unchanged behavior or a deliberate regression.

xen/arch/arm/dom0less-build.c static void __init initialize_domU_xenstore(void) · line 869

Quoted 8 lines
xen/arch/arm/dom0less-build.c +2 -0
@@ -865,6 +865,10 @@ static void __init initialize_domU_xenstore(void)
         rc = alloc_xenstore_evtchn(d);
         if ( rc < 0 )
             panic("%pd: Failed to allocate xenstore_evtchn\n", d);
+
+        if ( gfn != ~0ULL )

Is this an odd open-coding of INVALID_GFN? And even if not - why ULL when "gfn" is unsigned long? The way you have it the condition will always be false on Arm32, if I'm not mistaken.

Quoted 4 lines
xen/common/grant_table.c +0 -0
@@ -4346,6 +4346,21 @@ static void gnttab_usage_print(struct domain *rd)
         printk("no active grant table entries\n");

xen/common/grant_table.c static void gnttab_usage_print(struct domain *rd) · line 4356

Quoted 10 lines
xen/common/grant_table.c +8 -0
 }
 
+#ifdef CONFIG_DOM0LESS_BOOT
+void __init gnttab_seed_entry(const struct domain *d, unsigned int idx,
+                              domid_t be_domid, uint64_t frame,
+                              unsigned int flags)
+{
+    const struct grant_table *gt = d->grant_table;
+
+    ASSERT(!d->creation_finished);

While I don't mind the assertion, it's a little funny to see such in an __init function.

xen/common/grant_table.c static void gnttab_usage_print(struct domain *rd) · line 4358

Quoted 2 lines
xen/common/grant_table.c +2 -0
+    ASSERT(gt->gt_version == 1);
+    shared_entry_v1(gt, idx).flags = flags;

Does this really need to be a function parameter? The sole caller passes a constant (GTF_permit_access).

xen/include/xen/grant_table.h void grant_table_destroy( · line 49

Quoted 8 lines
xen/include/xen/grant_table.h +2 -0
@@ -45,6 +45,11 @@ void grant_table_destroy(
     struct domain *d);
 void grant_table_init_vcpu(struct vcpu *v);
 
+/* Seed a gnttab entry for Hyperlaunch/dom0less. */
+void __init gnttab_seed_entry(const struct domain *d, unsigned int idx,

No __init on declarations please. They have no effect (as long as the definition properly has the attribute) and hence are only at risk of going stale.

Jan

#11 lore raw

Re: [PATCH v2 4/6] xen/arm: dom0less seed xenstore grant table entry

Quoted 9 lines · Jan Beulich
Quoted 7 lines · Jason Andryuk

xenstored maps other domains' xenstore pages. Currently this relies on init-dom0less or xl to seed the grants from Dom0. With split hardware/control/xenstore domains, this is problematic since we don't want the hardware domain to be able to map other domains' resources without their permission. Instead have the hypervisor seed the grant table entry for every dom0less domain. The grant is then accessible as normal.

Quoted 6 lines

Yet aiui the original idea was to specifically not do this in the hypervisor. I agree it shouldn't be the hardware domain, but what's wrong with having the control domain do that? It is what is responsible for creating new domains as well. The question of where to do that when there's no control domain must also have been solved already (without me knowing the answer), as that's where init-dom0less must be running.

dom0less does not allow configuring a domU to have xenstore without using dom0 today. This series changes the dependency to the xenstore domain.

I want to move away from relying on the control domain to set up xenstore connections. Domain boot can achieve more parallelism if xenstore domain can independently configure its connections. If xenstore connections need to wait until dom0/control userspace runs, that is a measurable delay.

From the permission side, with a preseeded grant, and the event channel places in the xenstore_domain_interface page, a xenstore domain can connect and introduce existing domains when it starts up without needing additional permissions.

Generally, I'm looking at making xenstored perform more configuration on its own. It doesn't matter for dom0, but it will help for dom0less/Hyperlaunch. Seeding grants from the hypervisor is a small change, but it helps remove dependencies for xenstore.

Quoted 5 lines
Quoted 2 lines

This works with C xenstored. OCaml xenstored does not use grants and would fail to foreign map the page.

From the sentence it's not clear whether this is unchanged behavior or
a deliberate regression.

I was trying to highlight existing compatibility. xenstored uses grants, so it can take advantage of the pre-seeded grant and therefore does not need privilege to map foreign pages. OCaml does not use grants, so this seeding is irrelevant. With a combined hardware|xenstore domain, C xenstored using grants works, but Ocaml does not.

Quoted 4 lines
Quoted 4 lines
xen/arch/arm/dom0less-build.c +0 -0
@@ -865,6 +865,10 @@ static void __init initialize_domU_xenstore(void)
          rc = alloc_xenstore_evtchn(d);
Quoted 8 lines

xen/arch/arm/dom0less-build.c static void __init initialize_domU_xenstore(void) · line 869

Quoted 4 lines
xen/arch/arm/dom0less-build.c +2 -0
          if ( rc < 0 )
              panic("%pd: Failed to allocate xenstore_evtchn\n", d);
+
+        if ( gfn != ~0ULL )

Is this an odd open-coding of INVALID_GFN? And even if not - why ULL when "gfn" is unsigned long? The way you have it the condition will always be false on Arm32, if I'm not mistaken.

I'll have to double check that. Thanks.

Quoted 6 lines
Quoted 6 lines
xen/common/grant_table.c +0 -0
@@ -4346,6 +4346,21 @@ static void gnttab_usage_print(struct domain *rd)
          printk("no active grant table entries\n");
  }
 
Quoted 11 lines

xen/common/grant_table.c static void gnttab_usage_print(struct domain *rd) · line 4356

Quoted 8 lines
xen/common/grant_table.c +8 -0
+#ifdef CONFIG_DOM0LESS_BOOT
+void __init gnttab_seed_entry(const struct domain *d, unsigned int idx,
+                              domid_t be_domid, uint64_t frame,
+                              unsigned int flags)
+{
+    const struct grant_table *gt = d->grant_table;
+
+    ASSERT(!d->creation_finished);

While I don't mind the assertion, it's a little funny to see such in an __init function.

This check was added in response to v1 comment. Yes, I too considered just relying on __init, but the ASSERT explicitly checks the desired property holds.

Quoted 5 lines

xen/common/grant_table.c static void gnttab_usage_print(struct domain *rd) · line 4358

Quoted 2 lines
xen/common/grant_table.c +2 -0
+    ASSERT(gt->gt_version == 1);
+    shared_entry_v1(gt, idx).flags = flags;

Does this really need to be a function parameter? The sole caller passes a constant (GTF_permit_access).

I suppose it could be dropped. The toolstack side passes flags, which I mirrored when writing this.

Quoted 11 lines

xen/include/xen/grant_table.h void grant_table_destroy( · line 49

Quoted 8 lines
xen/include/xen/grant_table.h +2 -0
@@ -45,6 +45,11 @@ void grant_table_destroy(
      struct domain *d);
  void grant_table_init_vcpu(struct vcpu *v);
 
+/* Seed a gnttab entry for Hyperlaunch/dom0less. */
+void __init gnttab_seed_entry(const struct domain *d, unsigned int idx,

No __init on declarations please. They have no effect (as long as the definition properly has the attribute) and hence are only at risk of going stale.

Oh, okay. I thought they were necessary, but clear I am wrong.

Thanks,
Jason

#12 lore raw

Re: [PATCH v2 4/6] xen/arm: dom0less seed xenstore grant table entry

Quoted 8 lines · Jason Andryuk
Quoted 6 lines · Jan Beulich
Quoted 2 lines · Jason Andryuk

This works with C xenstored. OCaml xenstored does not use grants and would fail to foreign map the page.

From the sentence it's not clear whether this is unchanged behavior or
a deliberate regression.

Quoted 6 lines

I was trying to highlight existing compatibility. xenstored uses grants, so it can take advantage of the pre-seeded grant and therefore does not need privilege to map foreign pages. OCaml does not use grants, so this seeding is irrelevant. With a combined hardware|xenstore domain, C xenstored using grants works, but Ocaml does not.

IOW oxenstored works in all-mighty Dom0 only now, and that doesn't change? This would be fine. Re-wording the sentence to become unambiguous (towards possibly admitting to deliberately introduce a regression) would seem desirable though.

Jan

#13 lore raw

Re: [PATCH v2 4/6] xen/arm: dom0less seed xenstore grant table entry

In reply to Jan Beulich
Quoted 14 lines · Jan Beulich

xen/arch/arm/dom0less-build.c static void __init initialize_domU_xenstore(void) · line 869

Quoted 8 lines · Jason Andryuk
xen/arch/arm/dom0less-build.c +2 -0
@@ -865,6 +865,10 @@ static void __init initialize_domU_xenstore(void)
          rc = alloc_xenstore_evtchn(d);
          if ( rc < 0 )
              panic("%pd: Failed to allocate xenstore_evtchn\n", d);
+
+        if ( gfn != ~0ULL )

Is this an odd open-coding of INVALID_GFN? And even if not - why ULL when "gfn" is unsigned long? The way you have it the condition will always be false on Arm32, if I'm not mistaken.

The gfn is pulled out of the HVM_PARAMS, which is a uint64_t. It is set like:

d->arch.hvm.params[HVM_PARAM_STORE_PFN] = ~0ULL;

But pulled out by:

unsigned long gfn = d->arch.hvm.params[HVM_PARAM_STORE_PFN];

So your comment highlights that unsigned long is incorrect for ARM32.

While I realize fixed types are discouraged, I'd prefer to use uint64_t for the replacement. That is the type of HVM_PARAMS, and uint64_t is used on the init-dom0less side as well. Using unsigned long long to get a 64bit value on ARM32 seems less clear to me.

Thanks,
Jason

#14 lore raw

Re: [PATCH v2 4/6] xen/arm: dom0less seed xenstore grant table entry

Quoted 22 lines · Jason Andryuk
Quoted 14 lines · Jan Beulich

xen/arch/arm/dom0less-build.c static void __init initialize_domU_xenstore(void) · line 869

Quoted 8 lines · Jason Andryuk
xen/arch/arm/dom0less-build.c +2 -0
@@ -865,6 +865,10 @@ static void __init initialize_domU_xenstore(void)
          rc = alloc_xenstore_evtchn(d);
          if ( rc < 0 )
              panic("%pd: Failed to allocate xenstore_evtchn\n", d);
+
+        if ( gfn != ~0ULL )

Is this an odd open-coding of INVALID_GFN? And even if not - why ULL when "gfn" is unsigned long? The way you have it the condition will always be false on Arm32, if I'm not mistaken.

The gfn is pulled out of the HVM_PARAMS, which is a uint64_t. It is set like:

d->arch.hvm.params[HVM_PARAM_STORE_PFN] = ~0ULL;

But pulled out by:

Quoted 8 lines

unsigned long gfn = d->arch.hvm.params[HVM_PARAM_STORE_PFN];

So your comment highlights that unsigned long is incorrect for ARM32.

While I realize fixed types are discouraged, I'd prefer to use uint64_t for the replacement. That is the type of HVM_PARAMS, and uint64_t is used on the init-dom0less side as well. Using unsigned long long to get a 64bit value on ARM32 seems less clear to me.

The types that correspond to hypercall struct field types should match the hypercall struct field types.

I think gfn should be uint64_t to match the definition of params.

Similarly among the arguments of gnttab_seed_entry, flags should be uint16_t and I think frame should be uint32_t. This last one I am confused why you defined it as uint64_t, maybe I am missing something.

#15 lore raw

Re: [PATCH v2 4/6] xen/arm: dom0less seed xenstore grant table entry

Quoted 32 lines · Stefano Stabellini
Quoted 22 lines · Jason Andryuk
Quoted 14 lines · Jan Beulich

xen/arch/arm/dom0less-build.c static void __init initialize_domU_xenstore(void) · line 869

Quoted 8 lines · Jason Andryuk
xen/arch/arm/dom0less-build.c +2 -0
@@ -865,6 +865,10 @@ static void __init initialize_domU_xenstore(void)
           rc = alloc_xenstore_evtchn(d);
           if ( rc < 0 )
               panic("%pd: Failed to allocate xenstore_evtchn\n", d);
+
+        if ( gfn != ~0ULL )

Is this an odd open-coding of INVALID_GFN? And even if not - why ULL when "gfn" is unsigned long? The way you have it the condition will always be false on Arm32, if I'm not mistaken.

The gfn is pulled out of the HVM_PARAMS, which is a uint64_t. It is set like:

d->arch.hvm.params[HVM_PARAM_STORE_PFN] = ~0ULL;

But pulled out by:

Quoted 8 lines

unsigned long gfn = d->arch.hvm.params[HVM_PARAM_STORE_PFN];

So your comment highlights that unsigned long is incorrect for ARM32.

While I realize fixed types are discouraged, I'd prefer to use uint64_t for the replacement. That is the type of HVM_PARAMS, and uint64_t is used on the init-dom0less side as well. Using unsigned long long to get a 64bit value on ARM32 seems less clear to me.

Quoted 8 lines

The types that correspond to hypercall struct field types should match the hypercall struct field types.

I think gfn should be uint64_t to match the definition of params.

Similarly among the arguments of gnttab_seed_entry, flags should be uint16_t and I think frame should be uint32_t. This last one I am confused why you defined it as uint64_t, maybe I am missing something.

With Jan's suggestion, I am dropping flags.

Yes, frame should be uin32_t since it is filling in a grant table v1 entry, and that is limited to 32bit frame numbers. If the frame number is >32bits, then the grant can't be seeded. I guess I'll put a check in the caller to ensure that. Looking at the supported guest memory maximums, 32bit gfns should be enough to cover all the limits. > 16TiB would be needed to exceed a 32bit frame number.

Regards,
Jason

#16 lore raw

PATCH v2 5/6 tools/init-dom0less: Only seed legacy xenstore grants

In reply to Jason Andryuk

The hardware domain is unable to seed a control domain, but we want the control domain to use xenstore. Rely on the hypervisor to seed dom0less grant table entries for Xenstore, so this seeding is unnecessary.

However, that only works for the new xenstore late init. The legacy protocol which uses init-dom0less to populate the page still needs to seed the grant.

---
 tools/helpers/init-dom0less.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/helpers/init-dom0less.c +5 -5
index 17579fe2e8..91edf17b6c 100644
@@ -286,12 +286,12 @@ static int init_domain(struct xs_handle *xsh,
                 xenstore_pfn);
         if (rc < 0)
             return rc;
-    }
 
-    rc = xc_dom_gnttab_seed(xch, info->domid, true,
-                            (xen_pfn_t)-1, xenstore_pfn, 0, 0);
-    if (rc)
-        err(1, "xc_dom_gnttab_seed");
+        rc = xc_dom_gnttab_seed(xch, info->domid, true,
+                                (xen_pfn_t)-1, xenstore_pfn, 0, 0);
+        if (rc)
+               err(1, "xc_dom_gnttab_seed");
+    }
 
     libxl_uuid_generate(&uuid);
     xc_domain_sethandle(xch, info->domid, libxl_uuid_bytearray(&uuid));
Signature · 1 line
2.49.0
#17 lore raw

PATCH v2 6/6 xen/arm: Add capabilities to dom0less

In reply to Jason Andryuk

Add capabilities property to dom0less to allow building a disaggregated system. Only a single hardware domain and single xenstore domain can be specified. Multiple control domains are possible.

Introduce bootfdt.h to contain these constants.

When using the hardware or xenstore capabilities, adjust the grant and event channel limits similar to dom0.

For a hardware domain, require an IOMMU and disallow specifying a vpl011 console or nr_spis.

---
v2:
Fix comment style
Make DOMAIN_CAPS_* unsigned
Remove forced directmap & iommu
Require iommu with use of hardware domain
Limit to a single xenstore domain

There is overlap with hyperlaunch. The numeric values are the same. Hyperlaunch doesn't expose the values in a public header as done here. Is this to be expected for dom0less? It seems most of dom0less isn't in a header, but just in docs.

Hyperlaunch uses BUILD_CAPS_, but I chose DOMAIN_CAPS_ since there are domain-level capabilities.

Only a single xenstore and hardware domain make sense. Hardware domain receiving all hardware can only have a single domain.

For Xenstore, the logic latches the single xs_domid and uses that for all domains. Also, only a single domain can register for VIRQ_DOM_EXC.

---
 docs/misc/arm/device-tree/booting.txt | 11 ++++++++
 xen/arch/arm/dom0less-build.c         | 39 +++++++++++++++++++++++++++
 xen/arch/arm/domain.c                 |  3 ++-
 xen/include/public/bootfdt.h          | 31 +++++++++++++++++++++
 4 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100644 xen/include/public/bootfdt.h
docs/misc/arm/device-tree/booting.txt +11 -0
index ac781c9cc8..490c792ddf 100644
@@ -167,6 +167,17 @@ with the following properties:
     Refer to docs/misc/cache_coloring.rst for syntax. This option is applicable
     only to Arm64 guests.
 
+- capabilities
+    Optional.  A bit field of domain capabilities for a disaggregated
+    system.  A traditional dom0 has all all of these capabilities, and a
+    domU has none of them.
+
+    0x1 DOMAIN_CAPS_CONTROL  - A privileged, control domain
+    0x2 DOMAIN_CAPS_HARDWARE - The hardware domain - there can be only 1
+    0x4 DOMAIN_CAPS_XENSTORE - The xenstore domain - there can be only 1
+
+    The default is no capabilities.
+
 - vpl011
 
     An empty property to enable/disable a virtual pl011 for the guest to
xen/arch/arm/dom0less-build.c +39 -0
index fc515c9852..1cb6c170a7 100644
@@ -12,6 +12,7 @@
 #include <xen/sizes.h>
 #include <xen/vmap.h>
 
+#include <public/bootfdt.h>
 #include <public/io/xs_wire.h>
 
 #include <asm/arm64/sve.h>
@@ -906,6 +907,8 @@ static int __init construct_domU(struct domain *d,
            d->max_vcpus, mem);
 
     kinfo.vpl011 = dt_property_read_bool(node, "vpl011");
+    if ( kinfo.vpl011 && is_hardware_domain(d) )
+        panic("hardware domain cannot specify vpl011\n");
 
     rc = dt_property_read_string(node, "xen,enhanced", &dom0less_enhanced);
     if ( rc == -EILSEQ ||
@@ -1020,6 +1023,40 @@ void __init create_domUs(void)
         if ( (max_init_domid + 1) >= DOMID_FIRST_RESERVED )
             panic("No more domain IDs available\n");
 
+        if ( dt_property_read_u32(node, "capabilities", &val) )
+        {
+            if ( val & ~DOMAIN_CAPS_MASK )
+                panic("Invalid capabilities (%"PRIx32")\n", val);
+
+            if ( val & DOMAIN_CAPS_CONTROL )
+                flags |= CDF_privileged;
+
+            if ( val & DOMAIN_CAPS_HARDWARE )
+            {
+                if ( hardware_domain )
+                    panic("Only 1 hardware domain can be specified! (%pd)\n",
+                           hardware_domain);
+
+                if ( !iommu_enabled )
+                    panic("iommu required for dom0less hardware domain\n");
+
+                d_cfg.max_grant_frames = gnttab_dom0_frames();
+                d_cfg.max_evtchn_port = -1;
+                flags |= CDF_hardware;
+                iommu = true;
+            }
+
+            if ( val & DOMAIN_CAPS_XENSTORE )
+            {
+                if ( xs_domid != DOMID_INVALID )
+                    panic("Only 1 xenstore domain can be specified! (%u)\n",
+                          xs_domid);
+
+                d_cfg.flags |= XEN_DOMCTL_CDF_xs_domain;
+                d_cfg.max_evtchn_port = -1;
+            }
+        }
+
         if ( dt_find_property(node, "xen,static-mem", NULL) )
         {
             if ( llc_coloring_enabled )
@@ -1082,6 +1119,8 @@ void __init create_domUs(void)
                 d_cfg.arch.nr_spis = MAX(d_cfg.arch.nr_spis,
                                          vpl011_virq - 32 + 1);
         }
+        else if ( flags & CDF_hardware )
+            panic("nr_spis cannot be specified for hardware domain\n");
 
         /* Get the optional property domain-cpupool */
         cpupool_node = dt_parse_phandle(node, "domain-cpupool", 0);
xen/arch/arm/domain.c +2 -1
index 3ba959f866..dc4b4e84c1 100644
@@ -608,7 +608,8 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
 {
     unsigned int max_vcpus;
     unsigned int flags_required = (XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap);
-    unsigned int flags_optional = (XEN_DOMCTL_CDF_iommu | XEN_DOMCTL_CDF_vpmu);
+    unsigned int flags_optional = (XEN_DOMCTL_CDF_iommu | XEN_DOMCTL_CDF_vpmu |
+                                   XEN_DOMCTL_CDF_xs_domain );
     unsigned int sve_vl_bits = sve_decode_vl(config->arch.sve_vl);
 
     if ( (config->flags & ~flags_optional) != flags_required )
xen/include/public/bootfdt.h new file +31 -0
new file mode 100644
index 0000000000..86c46b42a9
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Xen Device Tree boot information
+ *
+ * Information for configuring Xen domains created at boot time.
+ */
+
+#ifndef __XEN_PUBLIC_BOOTFDT_H__
+#define __XEN_PUBLIC_BOOTFDT_H__
+
+/*
+ * Domain Capabilities specified in the "capabilities" property.  Use of
+ * this property allows splitting up the monolithic dom0 into separate,
+ * less privileged components.  A regular domU has no capabilities
+ * (which is the default if nothing is specified).  A traditional dom0
+ * has all three capabilities.
+ */
+
+/* Control/Privileged domain capable of affecting other domains. */
+#define DOMAIN_CAPS_CONTROL  (1U << 0)
+/*
+ * Hardware domain controlling physical hardware.  Typically providing
+ * backends to other domains.
+ */
+#define DOMAIN_CAPS_HARDWARE (1U << 1)
+/* Xenstore domain. */
+#define DOMAIN_CAPS_XENSTORE (1U << 2)
+#define DOMAIN_CAPS_MASK     (DOMAIN_CAPS_CONTROL | DOMAIN_CAPS_HARDWARE | \
+                              DOMAIN_CAPS_XENSTORE)
+
+#endif /* __XEN_PUBLIC_BOOTFDT_H__ */
Signature · 1 line
2.49.0
#18 lore raw

Re: [PATCH v2 6/6] xen/arm: Add capabilities to dom0less

Quoted 47 lines · Jason Andryuk

Add capabilities property to dom0less to allow building a disaggregated system. Only a single hardware domain and single xenstore domain can be specified. Multiple control domains are possible.

Introduce bootfdt.h to contain these constants.

When using the hardware or xenstore capabilities, adjust the grant and event channel limits similar to dom0.

For a hardware domain, require an IOMMU and disallow specifying a vpl011 console or nr_spis.

---
v2:
Fix comment style
Make DOMAIN_CAPS_* unsigned
Remove forced directmap & iommu
Require iommu with use of hardware domain
Limit to a single xenstore domain

There is overlap with hyperlaunch. The numeric values are the same. Hyperlaunch doesn't expose the values in a public header as done here. Is this to be expected for dom0less? It seems most of dom0less isn't in a header, but just in docs.

Hyperlaunch uses BUILD_CAPS_, but I chose DOMAIN_CAPS_ since there are domain-level capabilities.

Only a single xenstore and hardware domain make sense. Hardware domain receiving all hardware can only have a single domain.

For Xenstore, the logic latches the single xs_domid and uses that for all domains. Also, only a single domain can register for VIRQ_DOM_EXC.

---
 docs/misc/arm/device-tree/booting.txt | 11 ++++++++
 xen/arch/arm/dom0less-build.c         | 39 +++++++++++++++++++++++++++
 xen/arch/arm/domain.c                 |  3 ++-
 xen/include/public/bootfdt.h          | 31 +++++++++++++++++++++
 4 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100644 xen/include/public/bootfdt.h
docs/misc/arm/device-tree/booting.txt +0 -0
index ac781c9cc8..490c792ddf 100644

docs/misc/arm/device-tree/booting.txt with the following properties: · line 171

Quoted 5 lines
docs/misc/arm/device-tree/booting.txt +2 -0
@@ -167,6 +167,17 @@ with the following properties:
     Refer to docs/misc/cache_coloring.rst for syntax. This option is applicable
     only to Arm64 guests.
 
+- capabilities
+    Optional.  A bit field of domain capabilities for a disaggregated

Please reword as:

Optional. A 32-bit integer representing a bit field...

That is because there is no native bit field type in device tree.

Quoted 43 lines
docs/misc/arm/device-tree/booting.txt +9 -0
+    system.  A traditional dom0 has all all of these capabilities, and a
+    domU has none of them.
+
+    0x1 DOMAIN_CAPS_CONTROL  - A privileged, control domain
+    0x2 DOMAIN_CAPS_HARDWARE - The hardware domain - there can be only 1
+    0x4 DOMAIN_CAPS_XENSTORE - The xenstore domain - there can be only 1
+
+    The default is no capabilities.
+
 - vpl011
 
     An empty property to enable/disable a virtual pl011 for the guest to
xen/arch/arm/dom0less-build.c +9 -0
index fc515c9852..1cb6c170a7 100644
@@ -12,6 +12,7 @@
 #include <xen/sizes.h>
 #include <xen/vmap.h>
 
+#include <public/bootfdt.h>
 #include <public/io/xs_wire.h>
 
 #include <asm/arm64/sve.h>
@@ -906,6 +907,8 @@ static int __init construct_domU(struct domain *d,
            d->max_vcpus, mem);
 
     kinfo.vpl011 = dt_property_read_bool(node, "vpl011");
+    if ( kinfo.vpl011 && is_hardware_domain(d) )
+        panic("hardware domain cannot specify vpl011\n");
 
     rc = dt_property_read_string(node, "xen,enhanced", &dom0less_enhanced);
     if ( rc == -EILSEQ ||
@@ -1020,6 +1023,40 @@ void __init create_domUs(void)
         if ( (max_init_domid + 1) >= DOMID_FIRST_RESERVED )
             panic("No more domain IDs available\n");
 
+        if ( dt_property_read_u32(node, "capabilities", &val) )
+        {
+            if ( val & ~DOMAIN_CAPS_MASK )
+                panic("Invalid capabilities (%"PRIx32")\n", val);
+
+            if ( val & DOMAIN_CAPS_CONTROL )

xen/arch/arm/dom0less-build.c void __init create_domUs(void) · line 1041

Quoted 10 lines
xen/arch/arm/dom0less-build.c +10 -0
+                flags |= CDF_privileged;
+
+            if ( val & DOMAIN_CAPS_HARDWARE )
+            {
+                if ( hardware_domain )
+                    panic("Only 1 hardware domain can be specified! (%pd)\n",
+                           hardware_domain);
+
+                if ( !iommu_enabled )
+                    panic("iommu required for dom0less hardware domain\n");

The panic is OK if "direct-map" is not specified. We need to check for direct-map before panic'ing.

Other than these two comments it looks good to me.

Quoted 84 lines
xen/arch/arm/dom0less-build.c +20 -0
+
+                d_cfg.max_grant_frames = gnttab_dom0_frames();
+                d_cfg.max_evtchn_port = -1;
+                flags |= CDF_hardware;
+                iommu = true;
+            }
+
+            if ( val & DOMAIN_CAPS_XENSTORE )
+            {
+                if ( xs_domid != DOMID_INVALID )
+                    panic("Only 1 xenstore domain can be specified! (%u)\n",
+                          xs_domid);
+
+                d_cfg.flags |= XEN_DOMCTL_CDF_xs_domain;
+                d_cfg.max_evtchn_port = -1;
+            }
+        }
+
         if ( dt_find_property(node, "xen,static-mem", NULL) )
         {
             if ( llc_coloring_enabled )
@@ -1082,6 +1119,8 @@ void __init create_domUs(void)
                 d_cfg.arch.nr_spis = MAX(d_cfg.arch.nr_spis,
                                          vpl011_virq - 32 + 1);
         }
+        else if ( flags & CDF_hardware )
+            panic("nr_spis cannot be specified for hardware domain\n");
 
         /* Get the optional property domain-cpupool */
         cpupool_node = dt_parse_phandle(node, "domain-cpupool", 0);
xen/arch/arm/domain.c +2 -1
index 3ba959f866..dc4b4e84c1 100644
@@ -608,7 +608,8 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
 {
     unsigned int max_vcpus;
     unsigned int flags_required = (XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap);
-    unsigned int flags_optional = (XEN_DOMCTL_CDF_iommu | XEN_DOMCTL_CDF_vpmu);
+    unsigned int flags_optional = (XEN_DOMCTL_CDF_iommu | XEN_DOMCTL_CDF_vpmu |
+                                   XEN_DOMCTL_CDF_xs_domain );
     unsigned int sve_vl_bits = sve_decode_vl(config->arch.sve_vl);
 
     if ( (config->flags & ~flags_optional) != flags_required )
xen/include/public/bootfdt.h new file +31 -0
new file mode 100644
index 0000000000..86c46b42a9
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Xen Device Tree boot information
+ *
+ * Information for configuring Xen domains created at boot time.
+ */
+
+#ifndef __XEN_PUBLIC_BOOTFDT_H__
+#define __XEN_PUBLIC_BOOTFDT_H__
+
+/*
+ * Domain Capabilities specified in the "capabilities" property.  Use of
+ * this property allows splitting up the monolithic dom0 into separate,
+ * less privileged components.  A regular domU has no capabilities
+ * (which is the default if nothing is specified).  A traditional dom0
+ * has all three capabilities.
+ */
+
+/* Control/Privileged domain capable of affecting other domains. */
+#define DOMAIN_CAPS_CONTROL  (1U << 0)
+/*
+ * Hardware domain controlling physical hardware.  Typically providing
+ * backends to other domains.
+ */
+#define DOMAIN_CAPS_HARDWARE (1U << 1)
+/* Xenstore domain. */
+#define DOMAIN_CAPS_XENSTORE (1U << 2)
+#define DOMAIN_CAPS_MASK     (DOMAIN_CAPS_CONTROL | DOMAIN_CAPS_HARDWARE | \
+                              DOMAIN_CAPS_XENSTORE)
+
+#endif /* __XEN_PUBLIC_BOOTFDT_H__ */
Signature · 1 line
2.49.0
#19 lore raw

Re: [PATCH v2 6/6] xen/arm: Add capabilities to dom0less

Quoted 52 lines · Stefano Stabellini
Quoted 51 lines · Jason Andryuk

Add capabilities property to dom0less to allow building a disaggregated system. Only a single hardware domain and single xenstore domain can be specified. Multiple control domains are possible.

Introduce bootfdt.h to contain these constants.

When using the hardware or xenstore capabilities, adjust the grant and event channel limits similar to dom0.

For a hardware domain, require an IOMMU and disallow specifying a vpl011 console or nr_spis.

---
v2:
Fix comment style
Make DOMAIN_CAPS_* unsigned
Remove forced directmap & iommu
Require iommu with use of hardware domain
Limit to a single xenstore domain

There is overlap with hyperlaunch. The numeric values are the same. Hyperlaunch doesn't expose the values in a public header as done here. Is this to be expected for dom0less? It seems most of dom0less isn't in a header, but just in docs.

Hyperlaunch uses BUILD_CAPS_, but I chose DOMAIN_CAPS_ since there are domain-level capabilities.

Only a single xenstore and hardware domain make sense. Hardware domain receiving all hardware can only have a single domain.

For Xenstore, the logic latches the single xs_domid and uses that for all domains. Also, only a single domain can register for VIRQ_DOM_EXC.
---

xen/arch/arm/dom0less-build.c +11 -0
@@ -1020,6 +1023,40 @@ void __init create_domUs(void)
          if ( (max_init_domid + 1) >= DOMID_FIRST_RESERVED )
              panic("No more domain IDs available\n");
 
+        if ( dt_property_read_u32(node, "capabilities", &val) )
+        {
+            if ( val & ~DOMAIN_CAPS_MASK )
+                panic("Invalid capabilities (%"PRIx32")\n", val);
+
+            if ( val & DOMAIN_CAPS_CONTROL )
+                flags |= CDF_privileged;
+
+            if ( val & DOMAIN_CAPS_HARDWARE )
+            {
+                if ( hardware_domain )
Quoted 8 lines

xen/arch/arm/dom0less-build.c void __init create_domUs(void) · line 1041

Quoted 5 lines
xen/arch/arm/dom0less-build.c +5 -0
+                    panic("Only 1 hardware domain can be specified! (%pd)\n",
+                           hardware_domain);
+
+                if ( !iommu_enabled )
+                    panic("iommu required for dom0less hardware domain\n");

The panic is OK if "direct-map" is not specified. We need to check for direct-map before panic'ing.

Ok, I guess I misunderstood Julien's comment - I thought he wanted to require an iommu. I can re-work it.

!direct-map && !iommu will panic. Any other combination of direct-map and iommu will be allowed.

Hmmm, "passthrough" and "multiboot,device-tree" are essentially ignored for hwdom right now. I'll require them to be unset for hwdom.

Regards,
Jason

#20 lore raw

Re: [PATCH v2 6/6] xen/arm: Add capabilities to dom0less

Quoted 63 lines · Jason Andryuk
Quoted 53 lines · Stefano Stabellini
Quoted 52 lines · Jason Andryuk

Add capabilities property to dom0less to allow building a disaggregated system. Only a single hardware domain and single xenstore domain can be specified. Multiple control domains are possible.

Introduce bootfdt.h to contain these constants.

When using the hardware or xenstore capabilities, adjust the grant and event channel limits similar to dom0.

For a hardware domain, require an IOMMU and disallow specifying a vpl011 console or nr_spis.

---
v2:
Fix comment style
Make DOMAIN_CAPS_* unsigned
Remove forced directmap & iommu
Require iommu with use of hardware domain
Limit to a single xenstore domain

There is overlap with hyperlaunch. The numeric values are the same. Hyperlaunch doesn't expose the values in a public header as done here. Is this to be expected for dom0less? It seems most of dom0less isn't in a header, but just in docs.

Hyperlaunch uses BUILD_CAPS_, but I chose DOMAIN_CAPS_ since there are domain-level capabilities.

Only a single xenstore and hardware domain make sense. Hardware domain receiving all hardware can only have a single domain.

For Xenstore, the logic latches the single xs_domid and uses that for all domains. Also, only a single domain can register for VIRQ_DOM_EXC.
---

xen/arch/arm/dom0less-build.c +11 -0
@@ -1020,6 +1023,40 @@ void __init create_domUs(void)
          if ( (max_init_domid + 1) >= DOMID_FIRST_RESERVED )
              panic("No more domain IDs available\n");
  +        if ( dt_property_read_u32(node, "capabilities", &val) )
+        {
+            if ( val & ~DOMAIN_CAPS_MASK )
+                panic("Invalid capabilities (%"PRIx32")\n", val);
+
+            if ( val & DOMAIN_CAPS_CONTROL )
+                flags |= CDF_privileged;
+
+            if ( val & DOMAIN_CAPS_HARDWARE )
+            {
+                if ( hardware_domain )
+                    panic("Only 1 hardware domain can be specified!
 (%pd)\n",
Quoted 8 lines

xen/arch/arm/dom0less-build.c void __init create_domUs(void)

Quoted 5 lines
xen/arch/arm/dom0less-build.c +4 -0
+                           hardware_domain);
+
+                if ( !iommu_enabled )
+                    panic("iommu required for dom0less hardware
 domain\n");

The panic is OK if "direct-map" is not specified. We need to check for direct-map before panic'ing.

Quoted 2 lines

Ok, I guess I misunderstood Julien's comment - I thought he wanted to require an iommu. I can re-work it.

There are some subtleties here that it is best to clarify.

Julien asked for the hardware domain not to imply 1:1 memory mapping. If the hardware domain has memory not mapped 1:1, then the IOMMU is required. However, a user could still explicitly request the hardware domain to be 1:1 mapped with the direct-map property, in that case the IOMMU is optional.

Quoted 2 lines

!direct-map && !iommu will panic. Any other combination of direct-map and iommu will be allowed.

I think that's correct

Quoted 2 lines

Hmmm, "passthrough" and "multiboot,device-tree" are essentially ignored for hwdom right now. I'll require them to be unset for hwdom.

Good idea