Skip to contentSkip to conversation

Hyperlaunch x86 Dom0 launch

RFC In review Daniel P. Smith 3 participants 14 messages Dec 17, 2021 – Dec 20, 2021

lore
Share & tools
lore
#0 lore raw

cover Hyperlaunch x86 Dom0 launch

This RFC is to provide the base approach of how hyperlaunch would integrate into the x86 start sequence with the specific intention to vet the implementation approach early. What this RFC provides is a working implementation of hyperlaunch for x86 that is capable of strictly starting a Dom0 configuration. Even so the majority of the remaining hyperlaunch work will be focused on domain construction and enabling the transient boot domain (DomB) ability.

It is important to note that for this RFC patch set the work was split into smaller commits to ease review. When the first hyperlaunch patch set is submitted for acceptance, it is expected to see 5-7 rolled up and 9 & 10 also rolled up.

There are a couple of areas that explicitly need review and discussion and the commit message for a patch with one of these in them has the details, which will be repeated here for them to also all be centralized for comment.

- For hyperlaunch it has become necessary to track decompression headroom at an individual boot module level. The most sensible place for this information on x86 is in the module_t structure. The challenge encountered with this is that Xen's multiboot support is implemented by reusing MB module_t structure as a common structure for MB and MB2. Early in Xen's x86 startup the multiboot chain is copied(MB)/converted(MB2) into the trampoline data heap. To minimize change for this RFC the MB module_t reserved field was split into a bitfield to allow it to serve the existing usage of the field (relocation flag) and for headroom tracking. While this provided a clean solution, it is viewed as a short term solution. A suggestion might be to unify the existing architectures' representation of a boot module and refactor x86's reloc.c to convert MB and MB2 module descriptions into this common representation. This would have the added benefit of reducing the static allocations currently being used for hyperlaunch.

- When enabling device tree for use with x86, it exposed some arch specific code in the device tree code in common and shared includes. Specifically both Arm and x86 define a struct device but are totally different structures. The device tree code uses references to Arm's version of struct device which creates a conflict when the device tree code is used under x86. It was also found that generic device tree code was currently in the Arm arch tree. Patch 4 contains a work around for the first issue and patch 7 copies the reusable device tree parsing code from Arm arch for local/internal usage. Each patch provides a few additional details and ultimately a generalized solution for both problems is the preferable approach versus a minimal solution for enabling hyperlaunch

- To ease getting a Dom0 construction working under hyperlaunch the existing create_dom0() function was exposed and reused. This was for the RFC only and will be dropped in lieu of hyperlaunch gaining its own more general domain creation function.

Christopher Clark (2):
introduce hyperlaunch kconfig and core
is_system_domain: replace open-coded instances

Daniel P. Smith (8):
multiboot: moving headroom to per module_t
device-tree: split agnostic device-tree from arm
hyperlaunch: update device tree documentation
hyperlaunch: add structures to hold parsed dtb
hyperlaunch: add parsing of dtb
hyperlaunch: make create_dom0 externally callable
hyperlaunch: add domain creation logic
hyperlaunch: integrate dtb parse and domain creation

 .../designs/launch/hyperlaunch-devicetree.rst | 448 ++++++++++-------
 xen/arch/x86/boot/reloc.c                     |   1 +
 xen/arch/x86/cpu/vpmu.c                       |   2 +-
 xen/arch/x86/include/asm/setup.h              |   5 +
 xen/arch/x86/setup.c                          |  75 +--
 xen/common/Kconfig                            |  15 +
 xen/common/Makefile                           |   5 +-
 xen/common/device_tree.c                      |   2 +
 xen/common/domctl.c                           |   2 +-
 xen/common/sched/core.c                       |   4 +-
 xen/common/setup.c                            | 450 ++++++++++++++++++
 xen/include/xen/device_tree.h                 |   4 +
 xen/include/xen/multiboot.h                   |   3 +-
 xen/include/xen/sched.h                       |   5 +
 xen/include/xen/setup.h                       | 131 +++++
 15 files changed, 948 insertions(+), 204 deletions(-)
 create mode 100644 xen/common/setup.c
 create mode 100644 xen/include/xen/setup.h
Signature · 1 line
2.20.1
#1 lore raw

RFC 1/10 introduce hyperlaunch kconfig and core

From: Christopher Clark <[email protected]>

Add a CONFIG_HYPERLAUNCH to allow enabling/disabling the hyperlaunch code paths. Introduce an initial use of the hyperlaunch_enabled variable to suppress the warning about multiple initrd candidates when multiboot modules are detected when the hyperlaunch boolean is true.

Added to common code since this option will apply to all architectures.

---
 xen/arch/x86/setup.c    |  4 +++-
 xen/common/Kconfig      | 10 ++++++++++
 xen/common/Makefile     |  1 +
 xen/common/setup.c      |  8 ++++++++
 xen/include/xen/setup.h | 14 ++++++++++++++
 5 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 xen/common/setup.c
 create mode 100644 xen/include/xen/setup.h
xen/arch/x86/setup.c +3 -1
index f40a9fe5d3..190d7aefb5 100644
@@ -26,6 +26,7 @@
 #include <xen/nodemask.h>
 #include <xen/virtual_region.h>
 #include <xen/watchdog.h>
+#include <xen/setup.h>
 #include <public/version.h>
 #ifdef CONFIG_COMPAT
 #include <compat/platform.h>
@@ -1891,7 +1892,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
            cpu_has_nx ? "" : "not ");
 
     initrdidx = find_first_bit(module_map, mbi->mods_count);
-    if ( bitmap_weight(module_map, mbi->mods_count) > 1 )
+    if ( !hyperlaunch_enabled &&
+         bitmap_weight(module_map, mbi->mods_count) > 1 )
         printk(XENLOG_WARNING
                "Multiple initrd candidates, picking module #%u\n",
                initrdidx);
xen/common/Kconfig +10 -0
index db687b1785..5e6aad644e 100644
@@ -331,6 +331,16 @@ config ARGO
 
 	  If unsure, say N.
 
+config HYPERLAUNCH
+	bool "Hyperlaunch support (UNSUPPORTED)" if UNSUPPORTED
+	---help---
+	  Enables launch of multiple VMs at host boot as an alternative
+	  method of starting a Xen system.
+
+	  This feature is currently experimental.
+
+	  If unsure, say N.
+
 source "common/sched/Kconfig"
 
 config CRYPTO
xen/common/Makefile +1 -0
index 141d7d40d3..a6337e065a 100644
@@ -35,6 +35,7 @@ obj-y += rangeset.o
 obj-y += radix-tree.o
 obj-y += rcupdate.o
 obj-y += rwlock.o
+obj-y += setup.o
 obj-y += shutdown.o
 obj-y += softirq.o
 obj-y += smp.o
xen/common/setup.c new file +8 -0
new file mode 100644
index 0000000000..e18ea14fe0
@@ -0,0 +1,8 @@
+#include <xen/types.h>
+#include <xen/init.h>
+
+#ifdef CONFIG_HYPERLAUNCH
+
+bool __initdata hyperlaunch_enabled;
+
+#endif
xen/include/xen/setup.h new file +14 -0
new file mode 100644
index 0000000000..6fbe87860e
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef XEN_SETUP_H
+#define XEN_SETUP_H
+
+#include <asm/setup.h>
+
+#ifdef CONFIG_HYPERLAUNCH
+extern bool hyperlaunch_enabled;
+#else
+#define hyperlaunch_enabled false
+#endif
+
+#endif /* XEN_SETUP_H */
Signature · 1 line
2.20.1
#2 lore raw

RFC 2/10 is_system_domain: replace open-coded instances

In reply to Daniel P. Smith

From: Christopher Clark <[email protected]>

There were several instances of open-coded domid range checking. This commit replaces those with the is_system_domain inline function.

---
 xen/arch/x86/cpu/vpmu.c | 2 +-
 xen/common/domctl.c     | 2 +-
 xen/common/sched/core.c | 4 ++--
 xen/include/xen/sched.h | 5 +++++
 4 files changed, 9 insertions(+), 4 deletions(-)
xen/arch/x86/cpu/vpmu.c +1 -1
index 8ec4547bed..179f3dcc5a 100644
@@ -188,7 +188,7 @@ void vpmu_do_interrupt(struct cpu_user_regs *regs)
      * in XENPMU_MODE_ALL, for everyone.
      */
     if ( (vpmu_mode & XENPMU_MODE_ALL) ||
-         (sampled->domain->domain_id >= DOMID_FIRST_RESERVED) )
+         (is_system_domain(sampled->domain)) )
     {
         sampling = choose_hwdom_vcpu();
         if ( !sampling )
xen/common/domctl.c +1 -1
index 879a2adcbe..67021cc54b 100644
@@ -536,7 +536,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
         if ( !d )
         {
             ret = -EINVAL;
-            if ( op->domain >= DOMID_FIRST_RESERVED )
+            if ( is_system_domain_id(op->domain) )
                 break;
 
             rcu_read_lock(&domlist_read_lock);
xen/common/sched/core.c +2 -2
index 8f4b1ca10d..6ea8bcf62f 100644
@@ -821,7 +821,7 @@ int sched_init_domain(struct domain *d, unsigned int poolid)
     int ret;
 
     ASSERT(d->cpupool == NULL);
-    ASSERT(d->domain_id < DOMID_FIRST_RESERVED);
+    ASSERT(!is_system_domain(d));
 
     if ( (ret = cpupool_add_domain(d, poolid)) )
         return ret;
@@ -845,7 +845,7 @@ int sched_init_domain(struct domain *d, unsigned int poolid)
 
 void sched_destroy_domain(struct domain *d)
 {
-    ASSERT(d->domain_id < DOMID_FIRST_RESERVED);
+    ASSERT(!is_system_domain(d));
 
     if ( d->cpupool )
     {
xen/include/xen/sched.h +5 -0
index 28146ee404..1df09bcb77 100644
@@ -613,6 +613,11 @@ extern struct vcpu *idle_vcpu[NR_CPUS];
 #define is_idle_domain(d) ((d)->domain_id == DOMID_IDLE)
 #define is_idle_vcpu(v)   (is_idle_domain((v)->domain))
 
+static inline bool is_system_domain_id(domid_t id)
+{
+    return (id >= DOMID_FIRST_RESERVED);
+}
+
 static inline bool is_system_domain(const struct domain *d)
 {
     return d->domain_id >= DOMID_FIRST_RESERVED;
Signature · 1 line
2.20.1
#3 lore raw

Re: [RFC 02/10] is_system_domain: replace open-coded instances

Quoted 7 lines · Daniel P. Smith

From: Christopher Clark <[email protected]>

There were several instances of open-coded domid range checking. This commit replaces those with the is_system_domain inline function.

Ah - probably my fault.  When I added is_system_domain(), I didn't think to scan for other opencodes - I was guts deep in the domain creation logic.

In addition to the ones you've got here...

xen/arch/x86/cpu/mcheck/mce.c:1521
xen/common/domain.c:586
common/domctl.c:55, 411 and 421

according to git grep DOMID_FIRST_RESERVED

xen/arch/x86/cpu/vpmu.c void vpmu_do_interrupt(struct cpu_user_regs *regs) · line 191

Quoted 10 lines
xen/arch/x86/cpu/vpmu.c +1 -1
index 8ec4547bed..179f3dcc5a 100644
@@ -188,7 +188,7 @@ void vpmu_do_interrupt(struct cpu_user_regs *regs)
      * in XENPMU_MODE_ALL, for everyone.
      */
     if ( (vpmu_mode & XENPMU_MODE_ALL) ||
-         (sampled->domain->domain_id >= DOMID_FIRST_RESERVED) )
+         (is_system_domain(sampled->domain)) )

Can drop one set of brackets now.

Quoted 6 lines
xen/include/xen/sched.h +0 -0
index 28146ee404..1df09bcb77 100644
@@ -613,6 +613,11 @@ extern struct vcpu *idle_vcpu[NR_CPUS];
 #define is_idle_domain(d) ((d)->domain_id == DOMID_IDLE)

xen/include/xen/sched.h extern struct vcpu *idle_vcpu[NR_CPUS]; · line 623

Quoted 10 lines
xen/include/xen/sched.h +5 -0
 #define is_idle_vcpu(v)   (is_idle_domain((v)->domain))
 
+static inline bool is_system_domain_id(domid_t id)
+{
+    return (id >= DOMID_FIRST_RESERVED);
+}
+
 static inline bool is_system_domain(const struct domain *d)
 {
     return d->domain_id >= DOMID_FIRST_RESERVED;

is_system_domain() wants implementing in terms of is_system_domain_id().

That said, could I talk you into is_system_domid() as a better name?

This is all sufficiently trivial that I'm tempted to fix on commit if you'd like.  This patch is cleanup that stands on its own merit, and isn't tied to hyperlaunch specifically.

~Andrew

#4 lore raw

Re: [RFC 02/10] is_system_domain: replace open-coded instances

Quoted 12 lines · Andrew Cooper
Quoted 7 lines · Daniel P. Smith

From: Christopher Clark <[email protected]>

There were several instances of open-coded domid range checking. This commit replaces those with the is_system_domain inline function.

Ah - probably my fault.  When I added is_system_domain(), I didn't think to scan for other opencodes - I was guts deep in the domain creation logic.

Quoted 7 lines

In addition to the ones you've got here...

xen/arch/x86/cpu/mcheck/mce.c:1521
xen/common/domain.c:586
common/domctl.c:55, 411 and 421

according to git grep DOMID_FIRST_RESERVED

confirmed and replaced

Quoted 4 lines
Quoted 4 lines
xen/arch/x86/cpu/vpmu.c +0 -0
index 8ec4547bed..179f3dcc5a 100644
Quoted 8 lines

xen/arch/x86/cpu/vpmu.c void vpmu_do_interrupt(struct cpu_user_regs *regs) · line 191

Quoted 6 lines
xen/arch/x86/cpu/vpmu.c +1 -1
@@ -188,7 +188,7 @@ void vpmu_do_interrupt(struct cpu_user_regs *regs)
       * in XENPMU_MODE_ALL, for everyone.
       */
      if ( (vpmu_mode & XENPMU_MODE_ALL) ||
-         (sampled->domain->domain_id >= DOMID_FIRST_RESERVED) )
+         (is_system_domain(sampled->domain)) )

Can drop one set of brackets now.

ack

Quoted 8 lines
Quoted 8 lines
xen/include/xen/sched.h +0 -0
index 28146ee404..1df09bcb77 100644
@@ -613,6 +613,11 @@ extern struct vcpu *idle_vcpu[NR_CPUS];
  #define is_idle_domain(d) ((d)->domain_id == DOMID_IDLE)
  #define is_idle_vcpu(v)   (is_idle_domain((v)->domain))
 
Quoted 10 lines

xen/include/xen/sched.h extern struct vcpu *idle_vcpu[NR_CPUS]; · line 623

Quoted 8 lines
xen/include/xen/sched.h +5 -0
+static inline bool is_system_domain_id(domid_t id)
+{
+    return (id >= DOMID_FIRST_RESERVED);
+}
+
  static inline bool is_system_domain(const struct domain *d)
  {
      return d->domain_id >= DOMID_FIRST_RESERVED;

is_system_domain() wants implementing in terms of is_system_domain_id().

ack

Quoted 1 line

That said, could I talk you into is_system_domid() as a better name?

ack

Quoted 3 lines

This is all sufficiently trivial that I'm tempted to fix on commit if you'd like.  This patch is cleanup that stands on its own merit, and isn't tied to hyperlaunch specifically.

I will send the revised version later today as a standalone patch.

v/r,
dps

Acked-by on v1 2/10
#5 lore raw

Re: [RFC 02/10] is_system_domain: replace open-coded instances

In reply to Daniel P. Smith
Quoted 6 lines · Daniel P. Smith

From: Christopher Clark <[email protected]>

There were several instances of open-coded domid range checking. This commit
replaces those with the is_system_domain inline function.

Quoted 8 lines

---
 xen/arch/x86/cpu/vpmu.c | 2 +-
 xen/common/domctl.c     | 2 +-
 xen/common/sched/core.c | 4 ++--
 xen/include/xen/sched.h | 5 +++++

The */sched* bits:

But with a strong preference for renaming is_system_domain_id() to is_system_domid(), as Andrew suggested.

Regards

Signature · 6 lines
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)
#6 lore raw

RFC 3/10 multiboot: moving headroom to per module_t

In reply to Daniel P. Smith

Hyperlaunch will require multiple modules to be allocated headroom. Therefore a headroom variable has been added to module_t for tracking headroom on a per module_t basis. To provide backwards compatibility with multiboot, the reserved field was bitfield split to allow it to continue to be used to flag module was relocated and to add to track the headroom needed when being relocated.

RFC Note: The approach taken here was to produce something that was acceptable but likely not the ultimate solution. A more complete solution would likely be one that looked to unify a cross-architecture approach to represent the material provided by bootloaders.

---
 xen/arch/x86/boot/reloc.c   |  1 +
 xen/arch/x86/setup.c        | 17 ++++++++---------
 xen/include/xen/multiboot.h |  3 ++-
 3 files changed, 11 insertions(+), 10 deletions(-)
xen/arch/x86/boot/reloc.c +1 -0
index 4f4039bb7c..9c68777db3 100644
@@ -250,6 +250,7 @@ static multiboot_info_t *mbi2_reloc(u32 mbi_in)
             mbi_out_mods[mod_idx].mod_end = get_mb2_data(tag, module, mod_end);
             ptr = get_mb2_string(tag, module, cmdline);
             mbi_out_mods[mod_idx].string = copy_string(ptr);
+            mbi_out_mods[mod_idx].headroom = 0;
             mbi_out_mods[mod_idx].reserved = 0;
             ++mod_idx;
             break;
xen/arch/x86/setup.c +8 -9
index 190d7aefb5..4bf84c17e4 100644
@@ -855,7 +855,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     unsigned int initrdidx, num_parked = 0;
     multiboot_info_t *mbi;
     module_t *mod;
-    unsigned long nr_pages, raw_max_page, modules_headroom, module_map[1];
+    unsigned long nr_pages, raw_max_page, module_map[1];
     int i, j, e820_warn = 0, bytes = 0;
     unsigned long eb_start, eb_end;
     bool acpi_boot_table_init_done = false, relocated = false;
@@ -1158,7 +1158,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext;
     }
 
-    modules_headroom = bzimage_headroom(bootstrap_map(mod), mod->mod_end);
+    mod->headroom = bzimage_headroom(bootstrap_map(mod), mod->mod_end);
     bootstrap_map(NULL);
 
 #ifndef highmem_start
@@ -1321,8 +1321,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         /* Is the region suitable for relocating the multiboot modules? */
         for ( j = mbi->mods_count - 1; j >= 0; j-- )
         {
-            unsigned long headroom = j ? 0 : modules_headroom;
-            unsigned long size = PAGE_ALIGN(headroom + mod[j].mod_end);
+            unsigned long size = PAGE_ALIGN(mod[j].headroom + mod[j].mod_end);
 
             if ( mod[j].reserved )
                 continue;
@@ -1335,14 +1334,14 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                 continue;
 
             if ( s < end &&
-                 (headroom ||
+                 (mod[j].headroom ||
                   ((end - size) >> PAGE_SHIFT) > mod[j].mod_start) )
             {
-                move_memory(end - size + headroom,
+                move_memory(end - size + mod[j].headroom,
                             (uint64_t)mod[j].mod_start << PAGE_SHIFT,
                             mod[j].mod_end, 0);
                 mod[j].mod_start = (end - size) >> PAGE_SHIFT;
-                mod[j].mod_end += headroom;
+                mod[j].mod_end += mod[j].headroom;
                 mod[j].reserved = 1;
             }
         }
@@ -1369,7 +1368,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 #endif
     }
 
-    if ( modules_headroom && !mod->reserved )
+    if ( mod->headroom && !mod->reserved )
         panic("Not enough memory to relocate the dom0 kernel image\n");
     for ( i = 0; i < mbi->mods_count; ++i )
     {
@@ -1902,7 +1901,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * We're going to setup domain0 using the module(s) that we stashed safely
      * above our heap. The second module, if present, is an initrd ramdisk.
      */
-    dom0 = create_dom0(mod, modules_headroom,
+    dom0 = create_dom0(mod, mod->headroom,
                        initrdidx < mbi->mods_count ? mod + initrdidx : NULL,
                        kextra, loader);
     if ( !dom0 )
xen/include/xen/multiboot.h +2 -1
index d1b43e1183..0ae37dfa2b 100644
@@ -108,7 +108,8 @@ typedef struct {
     u32 mod_start;
     u32 mod_end;
     u32 string;
-    u32 reserved;
+    u32 reserved:1;
+    u32 headroom:31;
 } module_t;
 
 /* The memory map. Be careful that the offset 0 is base_addr_low
Signature · 1 line
2.20.1
#7 lore raw

RFC 4/10 device-tree: split agnostic device-tree from arm

In reply to Daniel P. Smith

This commit is purely for RFC to highlight some concerns and changes necessary in order for hyperlaunch to utilize device tree as the boot configuration container.

Despite being in common, the core device tree support enabled through CONFIG_HAS_DEVICE_TREE will not build for an x86 configuration. This is due to the fact that despite struct device appearing to be intended as a common data structure is in fact unique on x86 and Arm. There is code in xen/common/device_tree.c and include/xen/iommu.h that uses struct members found in Arm's struct device that are not present in x86's version. This obviously ends in compilation errors when enabling CONFIG_HAS_DEVICE_TREE on x86.

As a result this commit seeks to separate between requiring the ability to parse DTB files and obtaining hardware definition from those DTB files. The Kconfig parameter CORE_DEVICE_TREE was introduced for when only the former is necessary and not the latter. It specifically allows for the inclusion of the device tree parsing code without enabling the areas that make use of Arm specific struct device.

For the RFC when the Arm specific struct device is referenced within device tree parsing code, check for Arm has been added as an interim solution until a long term solution, that is beyond the scope of the hyperlaunch patch set, can be proposed and implemented.

---
 xen/common/Kconfig            | 5 +++++
 xen/common/Makefile           | 4 ++--
 xen/common/device_tree.c      | 2 ++
 xen/include/xen/device_tree.h | 4 ++++
 4 files changed, 13 insertions(+), 2 deletions(-)
xen/common/Kconfig +5 -0
index 5e6aad644e..aece21c9e5 100644
@@ -31,8 +31,12 @@ config HAS_ALTERNATIVE
 config HAS_COMPAT
 	bool
 
+config CORE_DEVICE_TREE
+	bool
+
 config HAS_DEVICE_TREE
 	bool
+	select CORE_DEVICE_TREE
 
 config HAS_EX_TABLE
 	bool
@@ -333,6 +337,7 @@ config ARGO
 
 config HYPERLAUNCH
 	bool "Hyperlaunch support (UNSUPPORTED)" if UNSUPPORTED
+	select CORE_DEVICE_TREE
 	---help---
 	  Enables launch of multiple VMs at host boot as an alternative
 	  method of starting a Xen system.
xen/common/Makefile +2 -2
index a6337e065a..f22aec72a0 100644
@@ -4,7 +4,7 @@ obj-$(CONFIG_HYPFS_CONFIG) += config_data.o
 obj-$(CONFIG_CORE_PARKING) += core_parking.o
 obj-y += cpu.o
 obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o
-obj-$(CONFIG_HAS_DEVICE_TREE) += device_tree.o
+obj-$(CONFIG_CORE_DEVICE_TREE) += device_tree.o
 obj-$(CONFIG_IOREQ_SERVER) += dm.o
 obj-y += domain.o
 obj-y += event_2l.o
@@ -73,7 +73,7 @@ obj-y += sched/
 obj-$(CONFIG_UBSAN) += ubsan/
 
 obj-$(CONFIG_NEEDS_LIBELF) += libelf/
-obj-$(CONFIG_HAS_DEVICE_TREE) += libfdt/
+obj-$(CONFIG_CORE_DEVICE_TREE) += libfdt/
 
 CONF_FILE := $(if $(patsubst /%,,$(KCONFIG_CONFIG)),$(BASEDIR)/)$(KCONFIG_CONFIG)
 config.gz: $(CONF_FILE)
xen/common/device_tree.c +2 -0
index 4aae281e89..d92fad2998 100644
@@ -2012,9 +2012,11 @@ static unsigned long __init unflatten_dt_node(const void *fdt,
             ((char *)pp->value)[sz - 1] = 0;
             dt_dprintk("fixed up name for %s -> %s\n", pathp,
                        (char *)pp->value);
+#ifdef CONFIG_ARM
             /* Generic device initialization */
             np->dev.type = DEV_DT;
             np->dev.of_node = np;
+#endif
         }
     }
     if ( allnextpp )
xen/include/xen/device_tree.h +4 -0
index fd6cd00b43..ca9f7672e9 100644
@@ -101,9 +101,12 @@ struct dt_device_node {
      */
     struct list_head domain_list;
 
+#ifdef CONFIG_ARM
     struct device dev;
+#endif
 };
 
+#ifdef CONFIG_ARM
 #define dt_to_dev(dt_node)  (&(dt_node)->dev)
 
 static inline struct dt_device_node *dev_to_dt(struct device *dev)
@@ -112,6 +115,7 @@ static inline struct dt_device_node *dev_to_dt(struct device *dev)
 
     return container_of(dev, struct dt_device_node, dev);
 }
+#endif
 
 #define MAX_PHANDLE_ARGS 16
 struct dt_phandle_args {
Signature · 1 line
2.20.1
#8 lore raw

RFC 5/10 hyperlaunch: update device tree documentation

In reply to Daniel P. Smith

This commit is to update the hyperlaunch device tree documentation to align with the DTB parsing implementation.

---
 .../designs/launch/hyperlaunch-devicetree.rst | 448 +++++++++++-------
 1 file changed, 278 insertions(+), 170 deletions(-)
docs/designs/launch/hyperlaunch-devicetree.rst +278 -170
index b49c98cfbd..7be23b9e71 100644
@@ -13,12 +13,263 @@ difference is the introduction of the ``hypervisor`` node that is under the
 2. Allows for the domain construction information to easily be sanitized by
    simple removing the ``/chosen/hypervisor`` node.
 
+
+The Hypervisor node
+-------------------
+
+The ``hypervisor`` node is a top level container for the domains that will be built
+by hypervisor on start up. The node will be named ``hypervisor``  with a ``compatible``
+property to identify which hypervisors the configuration is intended. The hypervisor
+node will consist of one or more config nodes and one or more domain nodes.
+
+Properties
+""""""""""
+
+compatible
+  Identifies which hypervisors the configuration is compatible. Required.
+
+  Format: "hypervisor,<hypervisor name>", e.g "hypervisor,xen"
+
+Child Nodes
+"""""""""""
+
+* config
+* domain
+
+Config Node
+-----------
+
+A ``config`` node is for passing configuration data and identifying any boot
+modules that is of interest to the hypervisor.  For example this would be where
+Xen would be informed of microcode or XSM policy locations. Each ``config``
+node will require a unique device-tree compliant name as there may be one or
+more ``config`` nodes present in a single dtb file. To identify which
+hypervisor the configuration is intended, the required ``compatible`` property
+must be present.
+
+While the config node is not meant to replace the hypervisor commandline, there
+may be cases where it is better suited for passing configuration details at
+boot time.  This additional information may be carried in properties assigned
+to a ``config`` node. If there are any boot modules that are intended for the
+hypervisor, then a ``module`` child node should be provided to identify the
+boot module.
+
+Properties
+""""""""""
+
+compatible
+  Identifies the hypervisor the confiugration is intended. Required.
+
+  Format: "<hypervisor name>,config", e.g "xen,config"
+
+Child Nodes
+"""""""""""
+
+* module
+
+Domain Node
+-----------
+
+A ``domain`` node is for describing the construction of a domain. Since there
+may be one or more domain nodes, each one requires a unique, DTB compliant name
+and a ``compatible`` property to identify as a domain node.
+
+A ``domain`` node  may provide a ``domid`` property which will be used as the
+requested domain id for the domain with a value of “0” signifying to use the
+next available domain id, which is the default behavior if omitted. It should
+be noted that a domain configuration is not able to request a domid of “0”.
+Beyond that a domain node may have any of the following optional properties.
+
+Properties
+""""""""""
+
+compatible
+  Identifies the node as a domain node and for which hypervisor. Required.
+
+  Format: "<hypervisor name>,domain", e.g "xen,domain"
+
+domid
+  Identifies the domid requested to assign to the domain.
+
+  Format: Integer, e.g <0>
+
+permissions
+  This sets what Discretionary Access Control permissions
+  a domain is assigned. Optional, default is none.
+
+  Format: Bitfield, e.g <3> or <0x00000003>
+
+          PERMISSION_NONE          (0)
+          PERMISSION_CONTROL       (1 << 0)
+          PERMISSION_HARDWARE      (1 << 1)
+
+functions
+  This identifies what system functions a domain will fulfill.
+  Optional, the default is none.
+
+  Format: Bitfield, e.g <3221225487> or <0xC0000007>
+
+          FUNCTION_NONE            (0)
+          FUNCTION_BOOT            (1 << 0)
+          FUNCTION_CRASH           (1 << 1)
+          FUNCTION_CONSOLE         (1 << 2)
+          FUNCTION_XENSTORE        (1 << 30)
+          FUNCTION_LEGACY_DOM0     (1 << 31)
+
+.. note::  The `functions` bits that have been selected to indicate
+   ``FUNCTION_XENSTORE`` and ``FUNCTION_LEGACY_DOM0`` are the last two bits
+   (30, 31) such that should these features ever be fully replaced or retired,
+   the flags may be dropped without leaving a gap in the flag set.
+
+mode
+  The mode the domain will be executed under. Required.
+
+  Format: Bitfield, e.g <5> or <0x00000005>
+
+          MODE_PARAVIRTUALIZED     (1 << 0) PV | PVH/HVM
+          MODE_ENABLE_DEVICE_MODEL (1 << 1) HVM | PVH
+          MODE_LONG                (1 << 2) 64 BIT | 32 BIT
+
+domain-uuid
+  A globally unique identifier for the domain. Optional,
+  the default is NULL.
+
+  Format: Byte Array, e.g [B3 FB 98 FB 8F 9F 67 A3]
+
+cpus
+  The number of vCPUs to be assigned to the domain. Optional,
+  the default is “1”.
+
+  Format: Integer, e.g <0>
+
+memory
+  The amount of memory to assign to the domain, in KBs. This field uses a DTB
+  Reg which contains a start and size. For memory allocation start may or may
+  not have significance but size will always be used for the amount of memory
+  Required.
+
+  Format: DTB Reg <min:start size>, [<max: start size>], e.g. <0x0 0x20000>
+
+security-id
+  The security identity to be assigned to the domain when XSM
+  is the access control mechanism being used. Optional,
+  the default is “system_u:system_r:domU_t”.
+
+  Format: string, e.g. "system_u:system_r:domU_t"
+
+Child Nodes
+"""""""""""
+
+* module
+
+Module node
+-----------
+
+This node describes a boot module loaded by the boot loader. A ``module`` node
+will often appear repeatedly and will require a unique and DTB compliant name
+for each instance. The compatible property is required to identify that the
+node is a ``module`` node, the type of boot module, and what it represents.
+
+Depending on the type of boot module, the ``module`` node will require either a
+``mb-index`` or ``module-addr`` property must be present. They provide the boot
+module specific way of locating the boot module in memory.
+
+Properties
+""""""""""
+
+compatible
+  This identifies what the module is and thus what the hypervisor
+  should use the module for during domain construction. Required.
+
+  Format: "module,<module type>"[, "<boot module type>,module"]
+          module type: kernel, ramdisk, device-tree, microcode, xsm-policy,
+                       config
+
+          boot module type: multiboot
+
+mb-index
+  This identifies the index for this module in the multiboot module chain.
+  Required for multiboot environments.
+
+  Format: Integer, e.g. <0>
+
+module-addr
+  This identifies where in memory this module is located. Required for
+  non-multiboot environments.
+
+  Format: DTB Reg <start size>, e.g. <0x0 0x20000>
+
+bootargs
+  This is used to provide the boot params to kernel modules.
+
+  Format: String, e.g. "ro quiet"
+
+.. note::  The bootargs property is intended for situations where the same kernel multiboot module is used for more than one domain.
+
 Example Configuration
 ---------------------
 
-Below are two example device tree definitions for the hypervisor node. The
-first is an example of a multiboot-based configuration for x86 and the second
-is a module-based configuration for Arm.
+Below are examples device tree definitions for the hypervisor node. The first
+is an example of booting a dom0 only configuration. Afterh that are a
+multiboot-based configuration for x86 and a module-based configuration for Arm.
+
+Multiboot x86 Configuration Dom0-only:
+""""""""""""""""""""""""""""""""""""""
+The following dts file can be provided to the Device Tree compiler, ``dtc``, to
+produce a dtb file. 
+::
+
+  /dts-v1/;
+
+  / {
+      chosen {
+          hypervisor {
+              compatible = "hypervisor,xen";
+
+              dom0 {
+                  compatible = "xen,domain";
+
+                  domid = <0>;
+
+                  permissions = <3>;
+                  functions = <0xC000000F>;
+                  mode = <5>;
+
+                  domain-uuid = [B3 FB 98 FB 8F 9F 67 A3 8A 6E 62 5A 09 13 F0 8C];                                               
+
+                  cpus = <1>;
+                  memory = <0x0 0x20000000>;
+
+                  kernel {
+                      compatible = "module,kernel", "multiboot,module";
+                      mb-index = <1>;
+                  };
+              };
+
+          };
+      };
+  };
+
+The resulting dtb file, in this case dom0-only.dtb, can then be used with a
+GRUB menuentry as such,
+::
+
+  menuentry 'Devuan GNU/Linux, with Xen hyperlaunch' {
+        insmod part_gpt
+        insmod ext2
+        set root='hd0,gpt2'
+
+        echo    'Loading Xen hyperlaunch ...'
+
+        multiboot2      /xen.gz placeholder sync_console
+        echo    'Loading Dom0 hyperlaunch dtb ...'
+        module2 --nounzip   /dom0-only.dtb
+        echo    'Loading Linux 5.4.36+ ...'
+        module2 /vmlinuz-5.4.36+ placeholder root=/dev/mapper/test01--vg-root ro  quiet
+        echo    'Loading initial ramdisk ...'
+        module2 --nounzip   /initrd.img-5.4.36+
+  }
+
 
 Multiboot x86 Configuration:
 """"""""""""""""""""""""""""
@@ -31,87 +282,66 @@ Multiboot x86 Configuration:
         compatible = “hypervisor,xen”
 
         // Configuration container
-        config {
+        xen-config {
             compatible = "xen,config";
 
-            module {
+            microcode {
                 compatible = "module,microcode", "multiboot,module";
                 mb-index = <1>;
             };
 
-            module {
+            policy {
                 compatible = "module,xsm-policy", "multiboot,module";
                 mb-index = <2>;
             };
         };
 
         // Boot Domain definition
-        domain {
+        domB {
             compatible = "xen,domain";
 
             domid = <0x7FF5>;
 
-            // FUNCTION_NONE            (0)
-            // FUNCTION_BOOT            (1 << 0)
-            // FUNCTION_CRASH           (1 << 1)
-            // FUNCTION_CONSOLE         (1 << 2)
-            // FUNCTION_XENSTORE        (1 << 30)
-            // FUNCTION_LEGACY_DOM0     (1 << 31)
             functions = <0x00000001>;
 
             memory = <0x0 0x20000>;
             cpus = <1>;
-            module {
+
+            kernel {
                 compatible = "module,kernel", "multiboot,module";
                 mb-index = <3>;
             };
-
-            module {
+            initrd {
                 compatible = "module,ramdisk", "multiboot,module";
                 mb-index = <4>;
             };
-            module {
+            dom-config {
                 compatible = "module,config", "multiboot,module";
                 mb-index = <5>;
             };
 
         // Classic Dom0 definition
-        domain {
+        dom0 {
             compatible = "xen,domain";
 
             domid = <0>;
 
-            // PERMISSION_NONE          (0)
-            // PERMISSION_CONTROL       (1 << 0)
-            // PERMISSION_HARDWARE      (1 << 1)
             permissions = <3>;
-
-            // FUNCTION_NONE            (0)
-            // FUNCTION_BOOT            (1 << 0)
-            // FUNCTION_CRASH           (1 << 1)
-            // FUNCTION_CONSOLE         (1 << 2)
-            // FUNCTION_XENSTORE        (1 << 30)
-            // FUNCTION_LEGACY_DOM0     (1 << 31)
             functions = <0xC0000006>;
-
-            // MODE_PARAVIRTUALIZED     (1 << 0) /* PV | PVH/HVM */
-            // MODE_ENABLE_DEVICE_MODEL (1 << 1) /* HVM | PVH */
-            // MODE_LONG                (1 << 2) /* 64 BIT | 32 BIT */
             mode = <5>; /* 64 BIT, PV */
 
-            // UUID
             domain-uuid = [B3 FB 98 FB 8F 9F 67 A3];
 
             cpus = <1>;
             memory = <0x0 0x20000>;
-            security-id = “dom0_t;
+            security-id = “system_u:system_r:dom0_t;
 
-            module {
+            kernel {
                 compatible = "module,kernel", "multiboot,module";
                 mb-index = <6>;
                 bootargs = "console=hvc0";
             };
-            module {
+            initrd {
                 compatible = "module,ramdisk", "multiboot,module";
                 mb-index = <7>;
             };
@@ -137,15 +367,15 @@ Module Arm Configuration:
         compatible = “hypervisor,xen”
 
         // Configuration container
-        config {
+        xen-config {
             compatible = "xen,config";
 
-            module {
+            microcode {
                 compatible = "module,microcode”;
                 module-addr = <0x0000ff00 0x80>;
             };
 
-            module {
+            policy {
                 compatible = "module,xsm-policy";
                 module-addr = <0x0000ff00 0x80>;
 
@@ -153,72 +383,51 @@ Module Arm Configuration:
         };
 
         // Boot Domain definition
-        domain {
+        domB {
             compatible = "xen,domain";
 
             domid = <0x7FF5>;
 
-            // FUNCTION_NONE            (0)
-            // FUNCTION_BOOT            (1 << 0)
-            // FUNCTION_CRASH           (1 << 1)
-            // FUNCTION_CONSOLE         (1 << 2)
-            // FUNCTION_XENSTORE        (1 << 30)
-            // FUNCTION_LEGACY_DOM0     (1 << 31)
             functions = <0x00000001>;
 
             memory = <0x0 0x20000>;
             cpus = <1>;
-            module {
+
+            kernel {
                 compatible = "module,kernel";
                 module-addr = <0x0000ff00 0x80>;
             };
-
-            module {
+            initrd {
                 compatible = "module,ramdisk";
                 module-addr = <0x0000ff00 0x80>;
             };
-            module {
+            dom-config {
                 compatible = "module,config";
                 module-addr = <0x0000ff00 0x80>;
             };
 
         // Classic Dom0 definition
-        domain@0 {
+        dom0 {
             compatible = "xen,domain";
 
             domid = <0>;
 
-            // PERMISSION_NONE          (0)
-            // PERMISSION_CONTROL       (1 << 0)
-            // PERMISSION_HARDWARE      (1 << 1)
             permissions = <3>;
-
-            // FUNCTION_NONE            (0)
-            // FUNCTION_BOOT            (1 << 0)
-            // FUNCTION_CRASH           (1 << 1)
-            // FUNCTION_CONSOLE         (1 << 2)
-            // FUNCTION_XENSTORE        (1 << 30)
-            // FUNCTION_LEGACY_DOM0     (1 << 31)
             functions = <0xC0000006>;
-
-            // MODE_PARAVIRTUALIZED     (1 << 0) /* PV | PVH/HVM */
-            // MODE_ENABLE_DEVICE_MODEL (1 << 1) /* HVM | PVH */
-            // MODE_LONG                (1 << 2) /* 64 BIT | 32 BIT */
             mode = <5>; /* 64 BIT, PV */
 
-            // UUID
             domain-uuid = [B3 FB 98 FB 8F 9F 67 A3];
 
             cpus = <1>;
             memory = <0x0 0x20000>;
-            security-id = “dom0_t”;
+            security-id = “system_u:system_r:dom0_t”;
 
-            module {
+            kernel {
                 compatible = "module,kernel";
                 module-addr = <0x0000ff00 0x80>;
                 bootargs = "console=hvc0";
             };
-            module {
+            intird {
                 compatible = "module,ramdisk";
                 module-addr = <0x0000ff00 0x80>;
             };
@@ -240,104 +449,3 @@ provided to Xen using the standard method currently in use. The remaining
 modules would need to be loaded in the respective addresses specified in the
 `module-addr` property.
 
-
-The Hypervisor node
--------------------
-
-The hypervisor node is a top level container for the domains that will be built
-by hypervisor on start up. On the ``hypervisor`` node the ``compatible``
-property is used to identify the type of hypervisor node present..
-
-compatible
-  Identifies the type of node. Required.
-
-The Config node
----------------
-
-A config node is for detailing any modules that are of interest to Xen itself.
-For example this would be where Xen would be informed of microcode or XSM
-policy locations. If the modules are multiboot modules and are able to be
-located by index within the module chain, the ``mb-index`` property should be
-used to specify the index in the multiboot module chain.. If the module will be
-located by physical memory address, then the ``module-addr`` property should be
-used to identify the location and size of the module.
-
-compatible
-  Identifies the type of node. Required.
-
-The Domain node
----------------
-
-A domain node is for describing the construction of a domain. It may provide a
-domid property which will be used as the requested domain id for the domain
-with a value of “0” signifying to use the next available domain id, which is
-the default behavior if omitted. A domain configuration is not able to request
-a domid of “0”. After that a domain node may have any of the following
-parameters,
-
-compatible
-  Identifies the type of node. Required.
-
-domid
-  Identifies the domid requested to assign to the domain. Required.
-
-permissions
-  This sets what Discretionary Access Control permissions
-  a domain is assigned. Optional, default is none.
-
-functions
-  This identifies what system functions a domain will fulfill.
-  Optional, the default is none.
-
-.. note::  The `functions` bits that have been selected to indicate
-   ``FUNCTION_XENSTORE`` and ``FUNCTION_LEGACY_DOM0`` are the last two bits
-   (30, 31) such that should these features ever be fully retired, the flags may
-   be dropped without leaving a gap in the flag set.
-
-mode
-  The mode the domain will be executed under. Required.
-
-domain-uuid
-  A globally unique identifier for the domain. Optional,
-  the default is NULL.
-
-cpus
-  The number of vCPUs to be assigned to the domain. Optional,
-  the default is “1”.
-
-memory
-  The amount of memory to assign to the domain, in KBs.
-  Required.
-
-security-id
-  The security identity to be assigned to the domain when XSM
-  is the access control mechanism being used. Optional,
-  the default is “domu_t”.
-
-The Module node
----------------
-
-This node describes a boot module loaded by the boot loader. The required
-compatible property follows the format: module,<type> where type can be
-“kernel”, “ramdisk”, “device-tree”, “microcode”, “xsm-policy” or “config”. In
-the case the module is a multiboot module, the additional property string
-“multiboot,module” may be present. One of two properties is required and
-identifies how to locate the module. They are the mb-index, used for multiboot
-modules, and the module-addr for memory address based location.
-
-compatible
-  This identifies what the module is and thus what the hypervisor
-  should use the module for during domain construction. Required.
-
-mb-index
-  This identifies the index for this module in the multiboot module chain.
-  Required for multiboot environments.
-
-module-addr
-  This identifies where in memory this module is located. Required for
-  non-multiboot environments.
-
-bootargs
-  This is used to provide the boot params to kernel modules.
-
-.. note::  The bootargs property is intended for situations where the same kernel multiboot module is used for more than one domain.
Signature · 1 line
2.20.1
#9 lore raw

RFC 6/10 hyperlaunch: add structures to hold parsed dtb

In reply to Daniel P. Smith

Hyperlaunch builds from dom0less' struct bootmodule as the representation of a boot module provided by a bootloader. From there it expands to cover the representations proposed in the hyperlaunch design documentation.

---
 xen/include/xen/setup.h | 81 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)
xen/include/xen/setup.h +81 -0
index 6fbe87860e..69ea042716 100644
@@ -5,6 +5,87 @@
 
 #include <asm/setup.h>
 
+/* Reusing Dom0less definitions */
+typedef enum {
+    BOOTMOD_XEN,
+    BOOTMOD_FDT,
+    BOOTMOD_KERNEL,
+    BOOTMOD_RAMDISK,
+    BOOTMOD_MICROCODE,
+    BOOTMOD_XSM,
+    BOOTMOD_GUEST_DTB,
+    BOOTMOD_GUEST_CONF,
+    BOOTMOD_UNKNOWN
+}  bootmodule_kind;
+
+struct bootmodule {
+    bootmodule_kind kind;
+    bool domU;
+    paddr_t start;
+    paddr_t size;
+};
+
+/* End reuse */
+
+struct memrange {
+    paddr_t start;
+    paddr_t size;
+};
+
+/* Currently only two config modules supported, microcode and xsm policy */
+#define HL_MAX_CONFIG_MODULES 2
+struct bootconfig {
+    uint16_t nr_mods;
+    struct bootmodule mods[HL_MAX_CONFIG_MODULES];
+};
+
+struct bootdomain {
+#define HL_PERMISSION_NONE          (0)
+#define HL_PERMISSION_CONTROL       (1 << 0)
+#define HL_PERMISSION_HARDWARE      (1 << 1)
+    uint32_t permissions;
+
+#define HL_FUNCTION_NONE            (0)
+#define HL_FUNCTION_BOOT            (1 << 0)
+#define HL_FUNCTION_CRASH           (1 << 1)
+#define HL_FUNCTION_CONSOLE         (1 << 2)
+#define HL_FUNCTION_XENSTORE        (1 << 30)
+#define HL_FUNCTION_LEGACY_DOM0     (1 << 31)
+    uint32_t functions;
+
+#define HL_MODE_PARAVIRTUALIZED     (1 << 0) /* PV | PVH/HVM */
+#define HL_MODE_ENABLE_DEVICE_MODEL (1 << 1) /* HVM | PVH */
+#define HL_MODE_LONG                (1 << 2) /* 64 BIT | 32 BIT */
+    uint32_t mode;
+
+    domid_t domid;
+    uint8_t uuid[16];
+
+    uint32_t ncpus;
+    bool maxmem_set;
+    struct memrange memrange[2]; /* 0: min; 1: max */
+
+#define HL_MAX_SECID_LEN 64
+    unsigned char secid[HL_MAX_SECID_LEN];
+
+#define HL_MAX_DOMAIN_MODULES 3
+    uint16_t nr_mods;
+    struct bootmodule modules[HL_MAX_DOMAIN_MODULES];
+#define HL_MAX_CMDLINE_LEN 1024
+    unsigned char cmdline[HL_MAX_CMDLINE_LEN];
+};
+
+struct hyperlaunch_config {
+    const void *fdt;
+#ifdef CONFIG_MULTIBOOT
+    module_t *mods;
+#endif
+    struct bootconfig config;
+#define HL_MAX_BOOT_DOMAINS 64
+    uint16_t nr_doms;
+    struct bootdomain domains[HL_MAX_BOOT_DOMAINS];
+};
+
 #ifdef CONFIG_HYPERLAUNCH
 extern bool hyperlaunch_enabled;
 #else
Signature · 1 line
2.20.1
#10 lore raw

RFC 7/10 hyperlaunch: add parsing of dtb

In reply to Daniel P. Smith

This commit implements the parsing of a hyperlaunch device tree. It is implemented to support a device tree containing any number of Config nodes and Domain nodes.

RFC Note: Xen supports working with flattened device trees (FDT), DTB files, and unflattened device trees, in-memory structures. The library libfdt provides low-level interaction with FDTs with higher order functions spread between arch/arm/bootfdt.c and a few in device_tree.c. While there are some FDT handlers in device_tree.c, it primarily provides the functionality for handling unflattened device trees.

For this RFC the general higher order FDT functions in bootfdt.c usable by hyperlaunch were duplicated into common/setup.c for hyperlaunch usage. Longer term it would be desired to see all reusable FDT functions centralized in common separate from the unflattened device tree handling code in device_tree.c.

---
 xen/common/setup.c      | 367 +++++++++++++++++++++++++++++++++++++++-
 xen/include/xen/setup.h |  22 ++-
 2 files changed, 387 insertions(+), 2 deletions(-)
xen/common/setup.c +366 -1
index e18ea14fe0..af2b1a422d 100644
@@ -1,8 +1,373 @@
-#include <xen/types.h>
+#include <xen/pci.h> /* needed by device_tree.h */
+#include <xen/device_tree.h>
 #include <xen/init.h>
+#include <xen/libfdt/libfdt.h>
+#include <xen/multiboot.h>
+#include <xen/setup.h>
+#include <xen/types.h>
 
 #ifdef CONFIG_HYPERLAUNCH
 
 bool __initdata hyperlaunch_enabled;
+static struct hyperlaunch_config __initdata hl_config;
+
+/* Reusing from arch/arm/bootfdt.c */
+
+static bool __init device_tree_node_compatible(const void *fdt, int node,
+                                               const char *match)
+{
+    int len, l;
+    int mlen;
+    const void *prop;
+
+    mlen = strlen(match);
+
+    prop = fdt_getprop(fdt, node, "compatible", &len);
+    if ( prop == NULL )
+        return false;
+
+    while ( len > 0 ) {
+        if ( !dt_compat_cmp(prop, match) )
+            return true;
+        l = strlen(prop) + 1;
+        prop += l;
+        len -= l;
+    }
+
+    return false;
+}
+
+static void __init device_tree_get_reg(
+    const __be32 **cell, uint32_t address_cells, uint32_t size_cells,
+    uint64_t *start, uint64_t *size)
+{
+    *start = dt_next_cell(address_cells, cell);
+    *size = dt_next_cell(size_cells, cell);
+}
+
+static uint32_t __init device_tree_get_u32(
+    const void *fdt, int node, const char *prop_name, u32 dflt)
+{
+    const struct fdt_property *prop;
+
+    prop = fdt_get_property(fdt, node, prop_name, NULL);
+    if ( !prop || prop->len < sizeof(u32) )
+        return dflt;
+
+    return fdt32_to_cpu(*(uint32_t*)prop->data);
+}
+
+/**
+ * device_tree_for_each_node - iterate over all device tree sub-nodes
+ * @fdt: flat device tree.
+ * @node: parent node to start the search from
+ * @func: function to call for each sub-node.
+ * @data: data to pass to @func.
+ *
+ * Any nodes nested at DEVICE_TREE_MAX_DEPTH or deeper are ignored.
+ *
+ * Returns 0 if all nodes were iterated over successfully.  If @func
+ * returns a value different from 0, that value is returned immediately.
+ */
+int __init device_tree_for_each_node(
+    const void *fdt, int node, device_tree_node_func func, void *data)
+{
+    /*
+     * We only care about relative depth increments, assume depth of
+     * node is 0 for simplicity.
+     */
+    int depth = 0;
+    const int first_node = node;
+    u32 address_cells[DEVICE_TREE_MAX_DEPTH];
+    u32 size_cells[DEVICE_TREE_MAX_DEPTH];
+    int ret;
+
+    do {
+        const char *name = fdt_get_name(fdt, node, NULL);
+        u32 as, ss;
+
+        if ( depth >= DEVICE_TREE_MAX_DEPTH )
+        {
+            printk("Warning: device tree node `%s' is nested too deep\n",
+                   name);
+            continue;
+        }
+
+        as = depth > 0 ? address_cells[depth-1] : DT_ROOT_NODE_ADDR_CELLS_DEFAULT;
+        ss = depth > 0 ? size_cells[depth-1] : DT_ROOT_NODE_SIZE_CELLS_DEFAULT;
+
+        address_cells[depth] = device_tree_get_u32(fdt, node,
+                                                   "#address-cells", as);
+        size_cells[depth] = device_tree_get_u32(fdt, node,
+                                                "#size-cells", ss);
+
+        /* skip the first node */
+        if ( node != first_node )
+        {
+            ret = func(fdt, node, name, depth, as, ss, data);
+            if ( ret != 0 )
+                return ret;
+        }
+
+        node = fdt_next_node(fdt, node, &depth);
+    } while ( node >= 0 && depth > 0 );
+
+    return 0;
+}
+
+/* End reuse */
+
+static bool read_module(
+    const void *fdt, int node, uint32_t address_cells, uint32_t size_cells,
+    struct hyperlaunch_config *config, struct bootmodule *bm)
+{
+    const struct fdt_property *prop;
+    const __be32 *cell;
+    bootmodule_kind kind = BOOTMOD_UNKNOWN;
+    int len;
+
+    if ( device_tree_node_compatible(fdt, node, "module,kernel") )
+        kind = BOOTMOD_KERNEL;
+
+    if ( device_tree_node_compatible(fdt, node, "module,ramdisk") )
+        kind = BOOTMOD_RAMDISK;
+
+    if ( device_tree_node_compatible(fdt, node, "module,microcode") )
+        kind = BOOTMOD_MICROCODE;
+
+    if ( device_tree_node_compatible(fdt, node, "module,xsm-policy") )
+        kind = BOOTMOD_XSM;
+
+    if ( device_tree_node_compatible(fdt, node, "module,config") )
+        kind = BOOTMOD_GUEST_CONF;
+
+    if ( device_tree_node_compatible(fdt, node, "multiboot,module") )
+    {
+#ifdef CONFIG_MULTIBOOT
+        uint32_t idx;
+
+        idx = (uint32_t)device_tree_get_u32(fdt, node, "mb-index", 0);
+        if ( idx == 0 )
+            return false;
+
+        bm->kind = kind;
+        /* under multiboot, start will just hold pointer to module entry */
+        bm->start = (paddr_t)(&config->mods[idx]);
+
+        return true;
+#else
+        return false;
+#endif
+    }
+
+    prop = fdt_get_property(fdt, node, "module-addr", &len);
+    if ( !prop )
+        return false;
+
+    if ( len < dt_cells_to_size(address_cells + size_cells) )
+        return false;
+
+    cell = (const __be32 *)prop->data;
+    device_tree_get_reg(
+        &cell, address_cells, size_cells, &(bm->start), &(bm->size));
+    bm->kind = kind;
+
+    return true;
+}
+
+static int process_config_node(
+    const void *fdt, int node, const char *name, int depth,
+    uint32_t address_cells, uint32_t size_cells, void *data)
+{
+    struct hyperlaunch_config *config = (struct hyperlaunch_config *)data;
+    uint16_t *count;
+    int node_next;
+
+    if ( !config )
+        return -1;
+
+    for ( node_next = fdt_first_subnode(fdt, node),
+          count = &(config->config.nr_mods);
+          node_next > 0;
+          node_next = fdt_next_subnode(fdt, node_next),
+          (*count)++ )
+    {
+        struct bootmodule *next_bm;
+
+        if ( *count >= HL_MAX_CONFIG_MODULES )
+        {
+            printk("Warning: truncating to %d hyperlaunch config modules\n",
+                   HL_MAX_CONFIG_MODULES);
+            return 0;
+        }
+
+        next_bm = &config->config.mods[*count];
+        read_module(fdt, node_next, address_cells, size_cells, config, next_bm);
+    }
+
+    return 0;
+}
+
+static int process_domain_node(
+    const void *fdt, int node, const char *name, int depth,
+    uint32_t address_cells, uint32_t size_cells, void *data)
+{
+    struct hyperlaunch_config *config = (struct hyperlaunch_config *)data;
+    const struct fdt_property *prop;
+    struct bootdomain *domain;
+    uint16_t *count;
+    const __be32 *cell;
+    int node_next, i, plen;
+
+    if ( !config )
+        return -1;
+
+    domain = &config->domains[config->nr_doms];
+
+    domain->domid = (domid_t)device_tree_get_u32(fdt, node, "domid", 0);
+    domain->permissions = device_tree_get_u32(fdt, node, "permissions", 0);
+    domain->functions = device_tree_get_u32(fdt, node, "functions", 0);
+    domain->mode = device_tree_get_u32(fdt, node, "mode", 0);
+
+    prop = fdt_get_property(fdt, node, "domain-uuid", &plen);
+    if ( prop )
+        for ( i=0; i < sizeof(domain->uuid) % sizeof(uint32_t); i++ )
+            *(domain->uuid + i) = fdt32_to_cpu((uint32_t)prop->data[i]);
+
+    domain->ncpus = device_tree_get_u32(fdt, node, "cpus", 1);
+
+    prop = fdt_get_property(fdt, node, "memory", &plen);
+    if ( !prop )
+        panic("node %s missing `memory' property\n", name);
+
+    /* TODO: convert to support reading up to two values from mem prop, min and max */
+    cell = (const __be32 *)prop->data;
+    device_tree_get_reg(&cell, address_cells, size_cells,
+                        &domain->memrange[0].start, &domain->memrange[0].size);
+
+    prop = fdt_get_property(fdt, node, "security-id",
+                                &plen);
+    if ( prop )
+    {
+        int size = fdt32_to_cpu(prop->len);
+        size = size > HL_MAX_SECID_LEN ?
+                HL_MAX_SECID_LEN : size;
+        memcpy(domain->secid, prop->data, size);
+    }
+
+    for ( node_next = fdt_first_subnode(fdt, node),
+          count = &(domain->nr_mods);
+          node_next > 0;
+          node_next = fdt_next_subnode(fdt, node_next),
+          (*count)++ )
+    {
+        struct bootmodule *next_bm;
+
+        if ( name == NULL )
+            continue;
+
+        if ( *count >= HL_MAX_DOMAIN_MODULES )
+        {
+            printk("Warning: truncating to %d hyperlaunch domain modules"
+                   " for %dth domain\n", HL_MAX_DOMAIN_MODULES,
+                   config->nr_doms);
+            break;
+        }
+
+        if ( device_tree_node_compatible(fdt, node_next, "module,kernel") )
+        {
+            prop = fdt_get_property(fdt, node_next, "bootargs", &plen);
+            if ( prop )
+            {
+                int size = fdt32_to_cpu(prop->len);
+                size = size > HL_MAX_CMDLINE_LEN ? HL_MAX_CMDLINE_LEN : size;
+                memcpy(domain->cmdline, prop->data, size);
+            }
+        }
+
+        next_bm = &domain->modules[*count];
+        read_module(fdt, node_next, address_cells, size_cells, config, next_bm);
+    }
+
+    config->nr_doms++;
+
+    return 0;
+}
+
+static int __init hl_scan_node(
+    const void *fdt, int node, const char *name, int depth, u32 address_cells,
+    u32 size_cells, void *data)
+{
+    int rc = -1;
+
+    /* skip nodes that are not direct children of the hyperlaunch node */
+    if ( depth > 1 )
+        return 0;
+
+    if ( device_tree_node_compatible(fdt, node, "xen,config") )
+        rc = process_config_node(fdt, node, name, depth,
+                                 address_cells, size_cells, data);
+    else if ( device_tree_node_compatible(fdt, node, "xen,domain") )
+        rc = process_domain_node(fdt, node, name, depth,
+                                 address_cells, size_cells, data);
+
+    if ( rc < 0 )
+        printk("hyperlaunch fdt: node `%s': parsing failed\n", name);
+
+    return rc;
+}
+
+/* hyperlaunch_init:
+ *   Attempts to initialize hyperlaunch config
+ *
+ * Returns:
+ *   -1: Not a valid DTB
+ *    0: Valid DTB but not a valid hyperlaunch device tree
+ *    1: Valid hyperlaunch device tree
+ */
+int __init hyperlaunch_init(const void *fdt)
+{
+    int hl_node, ret;
+
+    ret = fdt_check_header(fdt);
+    if ( ret < 0 )
+        return -1;
+
+    hl_node = fdt_path_offset(fdt, "/chosen/hypervisor");
+    if ( hl_node < 0 )
+        return 0;
+
+    ret = device_tree_for_each_node(fdt, hl_node, hl_scan_node, &hl_config);
+    if ( ret > 0 )
+        return 0;
+
+    hyperlaunch_enabled = true;
+
+    return 1;
+}
+
+#ifdef CONFIG_MULTIBOOT
+bool __init hyperlaunch_mb_init(module_t *mods)
+{
+    bool ret = false;
+    /* fdt is required to be module 0 */
+    void *fdt = _p(mods->mod_start);
+
+    hl_config.mods = mods;
+
+    switch ( hyperlaunch_init(fdt) )
+    {
+    case 1:
+        ret = true;
+    case -1:
+        break;
+    case 0:
+    default:
+        panic("HYPERLAUNCH: nonrecoverable error occured processing DTB\n");
+    }
+
+    return ret;
+}
+#endif
 
 #endif
xen/include/xen/setup.h +21 -1
index 69ea042716..fd4c23c08f 100644
@@ -88,8 +88,28 @@ struct hyperlaunch_config {
 
 #ifdef CONFIG_HYPERLAUNCH
 extern bool hyperlaunch_enabled;
-#else
+
+int __init hyperlaunch_init(const void *fdt);
+
+#ifdef CONFIG_MULTIBOOT
+bool __init hyperlaunch_mb_init(module_t *mods);
+#endif
+
+#else /* CONFIG_HYPERLAUNCH */
+
 #define hyperlaunch_enabled false
+
+static inline int __init hyperlaunch_init(const void *fdt)
+{
+    return 0;
+}
+
+#ifdef CONFIG_MULTIBOOT
+static inline bool __init hyperlaunch_mb_init(module_t *mods)
+{
+    return false;
+}
 #endif
 
+#endif /* CONFIG_HYPERLAUNCH */
 #endif /* XEN_SETUP_H */
Signature · 1 line
2.20.1
#11 lore raw

RFC 8/10 hyperlaunch: make create_dom0 externally callable

In reply to Daniel P. Smith

This commit is for the RFC only to enable a quick demonstration of starting Xen via hyperlaunch. Final version of hyperlaunch will have its own domain construction function that will replace the RFC usage of create_dom0.

---
 xen/arch/x86/include/asm/setup.h | 5 +++++
 xen/arch/x86/setup.c             | 8 ++++----
 2 files changed, 9 insertions(+), 4 deletions(-)
xen/arch/x86/include/asm/setup.h +5 -0
index 7dc03b6b8d..71f5aaa9b1 100644
@@ -34,6 +34,11 @@ static inline void vesa_init(void) {};
 static inline void vesa_mtrr_init(void) {};
 #endif
 
+struct domain *__init create_dom0(const module_t *image,
+                                  unsigned long headroom,
+                                  module_t *initrd, const char *kextra,
+                                  const char *loader);
+
 int construct_dom0(
     struct domain *d,
     const module_t *kernel, unsigned long kernel_headroom,
xen/arch/x86/setup.c +4 -4
index 4bf84c17e4..bee221d5ee 100644
@@ -755,10 +755,10 @@ static unsigned int __init copy_bios_e820(struct e820entry *map, unsigned int li
     return n;
 }
 
-static struct domain *__init create_dom0(const module_t *image,
-                                         unsigned long headroom,
-                                         module_t *initrd, const char *kextra,
-                                         const char *loader)
+struct domain *__init create_dom0(const module_t *image,
+                                  unsigned long headroom,
+                                  module_t *initrd, const char *kextra,
+                                  const char *loader)
 {
     struct xen_domctl_createdomain dom0_cfg = {
         .flags = IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity : 0,
Signature · 1 line
2.20.1
#12 lore raw

RFC 9/10 hyperlaunch: add domain creation logic

In reply to Daniel P. Smith

This commit introduces the skeleton of hyperlaunch domain construction mechanics and adds the preliminary ability to construct dom0.

---
 xen/common/setup.c      | 77 +++++++++++++++++++++++++++++++++++++++++
 xen/include/xen/setup.h | 16 +++++++++
 2 files changed, 93 insertions(+)
xen/common/setup.c +77 -0
index af2b1a422d..cd24f60297 100644
@@ -1,3 +1,4 @@
+#include <asm/bzimage.h> /* for bzimage_headroom */
 #include <xen/pci.h> /* needed by device_tree.h */
 #include <xen/device_tree.h>
 #include <xen/init.h>
@@ -368,6 +369,82 @@ bool __init hyperlaunch_mb_init(module_t *mods)
 
     return ret;
 }
+
+void __init hyperlaunch_mb_headroom(void)
+{
+    int i,j;
+
+    for( i = 0; i < hl_config.nr_doms; i++ )
+    {
+        for ( j = 0; j < hl_config.domains[i].nr_mods; j++ )
+        {
+            if ( hl_config.domains[i].modules[j].kind == BOOTMOD_KERNEL )
+            {
+                module_t *kern =
+                    (module_t *)_p(hl_config.domains[i].modules[j].start);
+
+                kern->headroom = bzimage_headroom(bootstrap_map(kern),
+                                                  kern->mod_end);
+                bootstrap_map(NULL);
+            }
+        }
+    }
+}
 #endif
 
+uint32_t __init hyperlaunch_create_domains(
+    struct domain **hwdom, const char *kextra, const char *loader)
+{
+    uint32_t dom_count = 0, functions_used = 0;
+    int i;
+
+    *hwdom = NULL;
+
+    for ( i = 0; i < hl_config.nr_doms; i++ )
+    {
+        struct bootdomain *d = &(hl_config.domains[i]);
+
+        /* build a legacy dom0 and set it as the hwdom */
+        if ( (d->functions & HL_FUNCTION_LEGACY_DOM0) &&
+             !(functions_used & HL_FUNCTION_LEGACY_DOM0) )
+        {
+            module_t *image = NULL, *initrd = NULL;
+            int j;
+
+            for ( j = 0; j < d->nr_mods; j++ )
+            {
+                if ( d->modules[j].kind == BOOTMOD_KERNEL )
+                    image = (module_t *)_p(d->modules[j].start);
+
+                if ( d->modules[j].kind == BOOTMOD_RAMDISK )
+                    initrd = (module_t *)_p(d->modules[j].start);
+
+                if ( image && initrd )
+                    break;
+            }
+
+            if ( image == NULL )
+                return 0;
+
+#ifdef CONFIG_MULTIBOOT
+            *hwdom = create_dom0(image, image->headroom, initrd, kextra,
+                                 loader);
+#endif
+            if ( *hwdom )
+            {
+                functions_used |= HL_FUNCTION_LEGACY_DOM0;
+                dom_count++;
+            }
+            else
+                panic("HYPERLAUNCH: "
+                      "Dom0 config present but dom0 construction failed\n");
+        }
+        else
+            printk(XENLOG_WARNING "hyperlaunch: "
+                   "currently only supports classic dom0 construction");
+    }
+
+    return dom_count;
+}
+
 #endif
xen/include/xen/setup.h +16 -0
index fd4c23c08f..3833867470 100644
@@ -93,8 +93,12 @@ int __init hyperlaunch_init(const void *fdt);
 
 #ifdef CONFIG_MULTIBOOT
 bool __init hyperlaunch_mb_init(module_t *mods);
+void __init hyperlaunch_mb_headroom(void);
 #endif
 
+uint32_t __init hyperlaunch_create_domains(
+    struct domain **hwdom, const char *kextra, const char *loader);
+
 #else /* CONFIG_HYPERLAUNCH */
 
 #define hyperlaunch_enabled false
@@ -109,7 +113,19 @@ static inline bool __init hyperlaunch_mb_init(module_t *mods)
 {
     return false;
 }
+
+void __init hyperlaunch_mb_headroom(void)
+{
+    return;
+}
 #endif
 
+static inline uint32_t __init hyperlaunch_create_domains(
+    struct domain **hwdom, const char *kextra, const char *loader)
+{
+    return 0;
+}
+
 #endif /* CONFIG_HYPERLAUNCH */
+
 #endif /* XEN_SETUP_H */
Signature · 1 line
2.20.1
#13 lore raw

RFC 10/10 hyperlaunch: integrate dtb parse and domain creation

In reply to Daniel P. Smith

This commit introduces into x86 start_xen the detection and parsing of a hyperlaunch DTB file and then using that information to construct the domains contained in the hyperlaunch configuration.

---
 xen/arch/x86/setup.c | 54 ++++++++++++++++++++++++++++++--------------
 1 file changed, 37 insertions(+), 17 deletions(-)
xen/arch/x86/setup.c +37 -17
index bee221d5ee..c007c421b0 100644
@@ -1020,6 +1020,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     bitmap_fill(module_map, mbi->mods_count);
     __clear_bit(0, module_map); /* Dom0 kernel is always first */
 
+    if ( hyperlaunch_mb_init(mod) )
+        printk(XENLOG_INFO "Hyperlaunch enabled\n");
+
     if ( pvh_boot )
     {
         /* pvh_init() already filled in e820_raw */
@@ -1142,6 +1145,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
             panic("Bootloader didn't honor module alignment request\n");
         mod[i].mod_end -= mod[i].mod_start;
         mod[i].mod_start >>= PAGE_SHIFT;
+        mod[i].headroom = 0;
         mod[i].reserved = 0;
     }
 
@@ -1158,8 +1162,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext;
     }
 
-    mod->headroom = bzimage_headroom(bootstrap_map(mod), mod->mod_end);
-    bootstrap_map(NULL);
+    if ( hyperlaunch_enabled ) {
+        hyperlaunch_mb_headroom();
+    } else {
+        mod->headroom = bzimage_headroom(bootstrap_map(mod), mod->mod_end);
+        bootstrap_map(NULL);
+    }
 
 #ifndef highmem_start
     /* Don't allow split below 4Gb. */
@@ -1890,22 +1898,34 @@ void __init noreturn __start_xen(unsigned long mbi_p)
            cpu_has_nx ? XENLOG_INFO : XENLOG_WARNING "Warning: ",
            cpu_has_nx ? "" : "not ");
 
-    initrdidx = find_first_bit(module_map, mbi->mods_count);
-    if ( !hyperlaunch_enabled &&
-         bitmap_weight(module_map, mbi->mods_count) > 1 )
-        printk(XENLOG_WARNING
-               "Multiple initrd candidates, picking module #%u\n",
-               initrdidx);
+    if ( hyperlaunch_enabled )
+    {
+        uint32_t ndoms;
 
-    /*
-     * We're going to setup domain0 using the module(s) that we stashed safely
-     * above our heap. The second module, if present, is an initrd ramdisk.
-     */
-    dom0 = create_dom0(mod, mod->headroom,
-                       initrdidx < mbi->mods_count ? mod + initrdidx : NULL,
-                       kextra, loader);
-    if ( !dom0 )
-        panic("Could not set up DOM0 guest OS\n");
+        printk(XENLOG_INFO "Hyperlaunch starting domain construction...\n");
+        ndoms = hyperlaunch_create_domains(&dom0, kextra, loader);
+        if ( ndoms == 0 )
+            panic("Hyperlaunch could not set up the domains\n");
+
+        printk(XENLOG_INFO "Hyperlaunch created %u domains\n", ndoms);
+    } else {
+        initrdidx = find_first_bit(module_map, mbi->mods_count);
+        if ( bitmap_weight(module_map, mbi->mods_count) > 1 )
+            printk(XENLOG_WARNING
+                   "Multiple initrd candidates, picking module #%u\n",
+                   initrdidx);
+
+        /*
+         * We're going to setup domain0 using the module(s) that we stashed
+         * safely above our heap. The second module, if present, is an initrd
+         * ramdisk.
+         */
+        dom0 = create_dom0(mod, mod->headroom,
+                           initrdidx < mbi->mods_count ? mod + initrdidx : NULL,
+                           kextra, loader);
+        if ( !dom0 )
+            panic("Could not set up DOM0 guest OS\n");
+    }
 
     heap_init_late();
 
Signature · 1 line
2.20.1