All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Smith" <dpsmith@apertussolutions.com>
To: xen-devel@lists.xenproject.org
Cc: "Daniel P. Smith" <dpsmith@apertussolutions.com>,
	scott.davis@starlab.io, christopher.clark@starlab.io,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	George Dunlap <george.dunlap@citrix.com>,
	Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>
Subject: [PATCH v1 17/18] builder: introduce domain builder hypfs tree
Date: Wed,  6 Jul 2022 17:04:52 -0400	[thread overview]
Message-ID: <20220706210454.30096-18-dpsmith@apertussolutions.com> (raw)
In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com>

This enables domain builder to construct a hypfs tree to expose relevant domain
creation information for use by the boot domain and/or the runtime system.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Reviewed-by: Christopher Clark <christopher.clark@starlab.io>
---
 xen/common/domain-builder/Kconfig  |  11 ++
 xen/common/domain-builder/Makefile |   1 +
 xen/common/domain-builder/core.c   |   3 +
 xen/common/domain-builder/hypfs.c  | 193 +++++++++++++++++++++++++++++
 xen/include/xen/domain_builder.h   |  13 ++
 5 files changed, 221 insertions(+)
 create mode 100644 xen/common/domain-builder/hypfs.c

diff --git a/xen/common/domain-builder/Kconfig b/xen/common/domain-builder/Kconfig
index 0232e1ed8a..4b98cccfab 100644
--- a/xen/common/domain-builder/Kconfig
+++ b/xen/common/domain-builder/Kconfig
@@ -22,4 +22,15 @@ config MULTIDOM_BUILDER
 
 	  If unsure, say N.
 
+config BUILDER_HYPFS
+	bool "Domain builder hypfs support (UNSUPPORTED)" if UNSUPPORTED
+	depends on HYPFS
+	---help---
+	  Exposes the domain builder construction information
+	  through hypfs.
+
+	  This feature is currently experimental.
+
+	  If unsure, say N.
+
 endmenu
diff --git a/xen/common/domain-builder/Makefile b/xen/common/domain-builder/Makefile
index 9561602502..7aa2ea2a53 100644
--- a/xen/common/domain-builder/Makefile
+++ b/xen/common/domain-builder/Makefile
@@ -1,2 +1,3 @@
 obj-$(CONFIG_BUILDER_FDT) += fdt.o
+obj-$(CONFIG_HYPFS) += hypfs.o
 obj-y += core.o
diff --git a/xen/common/domain-builder/core.c b/xen/common/domain-builder/core.c
index c6a268eb96..f41ca3ed35 100644
--- a/xen/common/domain-builder/core.c
+++ b/xen/common/domain-builder/core.c
@@ -134,6 +134,9 @@ uint32_t __init builder_create_domains(struct boot_info *info)
         /* Free temporary buffers. */
         discard_initial_images();
 
+    if ( IS_ENABLED(CONFIG_BUILDER_HYPFS) )
+        builder_hypfs(info);
+
     return build_count;
 }
 
diff --git a/xen/common/domain-builder/hypfs.c b/xen/common/domain-builder/hypfs.c
new file mode 100644
index 0000000000..28f8b13d85
--- /dev/null
+++ b/xen/common/domain-builder/hypfs.c
@@ -0,0 +1,193 @@
+#include <xen/bootinfo.h>
+#include <xen/domain_builder.h>
+#include <xen/hypfs.h>
+#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/list.h>
+#include <xen/string.h>
+#include <xen/xmalloc.h>
+
+#define INIT_HYPFS_DIR(var, nam)                 \
+    var.e.type = XEN_HYPFS_TYPE_DIR;             \
+    var.e.encoding = XEN_HYPFS_ENC_PLAIN;        \
+    var.e.name = (nam);                          \
+    var.e.size = 0;                              \
+    var.e.max_size = 0;                          \
+    INIT_LIST_HEAD(&var.e.list);                 \
+    var.e.funcs = (&hypfs_dir_funcs);            \
+    INIT_LIST_HEAD(&var.dirlist)
+
+#define INIT_HYPFS_FIXEDSIZE(var, typ, nam, contvar, fn, wr) \
+    var.e.type = (typ);                                      \
+    var.e.encoding = XEN_HYPFS_ENC_PLAIN;                    \
+    var.e.name = (nam);                                      \
+    var.e.size = sizeof(contvar);                            \
+    var.e.max_size = (wr) ? sizeof(contvar) : 0;             \
+    var.e.funcs = (fn);                                      \
+    var.u.content = &(contvar)
+
+#define INIT_HYPFS_UINT(var, nam, contvar)                       \
+    INIT_HYPFS_FIXEDSIZE(var, XEN_HYPFS_TYPE_UINT, nam, contvar, \
+                         &hypfs_leaf_ro_funcs, 0)
+
+#define INIT_HYPFS_BOOL(var, nam, contvar)                       \
+    INIT_HYPFS_FIXEDSIZE(var, XEN_HYPFS_TYPE_BOOL, nam, contvar, \
+                         &hypfs_leaf_ro_funcs, 0)
+
+#define INIT_HYPFS_VARSIZE(var, typ, nam, msz, fn) \
+    var.e.type = (typ) ;                           \
+    var.e.encoding = XEN_HYPFS_ENC_PLAIN;          \
+    var.e.name = (nam);                            \
+    var.e.max_size = (msz);                        \
+    var.e.funcs = (fn)
+
+#define INIT_HYPFS_STRING(var, nam)               \
+    INIT_HYPFS_VARSIZE(var, XEN_HYPFS_TYPE_STRING, nam, 0, &hypfs_leaf_ro_funcs)
+
+struct device_node {
+    struct hypfs_entry_dir dir;
+
+    uint32_t evtchn;
+    struct hypfs_entry_leaf evtchn_leaf;
+
+    xen_pfn_t mfn;
+    struct hypfs_entry_leaf mfn_leaf;
+};
+
+struct domain_node {
+    char dir_name[HYPFS_DYNDIR_ID_NAMELEN];
+    struct hypfs_entry_dir dir;
+
+    char uuid[40];
+    struct hypfs_entry_leaf uuid_leaf;
+
+    uint16_t functions;
+    struct hypfs_entry_leaf func_leaf;
+
+    uint32_t ncpus;
+    struct hypfs_entry_leaf ncpus_leaf;
+
+    uint32_t mem_size;
+    struct hypfs_entry_leaf mem_sz_leaf;
+
+    uint32_t mem_max;
+    struct hypfs_entry_leaf mem_mx_leaf;
+
+    bool constructed;
+    struct hypfs_entry_leaf const_leaf;
+
+    struct device_node xs;
+
+    struct hypfs_entry_dir dev_dir;
+
+    struct device_node con_dev;
+};
+
+static struct hypfs_entry_dir __read_mostly *builder_dir;
+static struct domain_node __read_mostly *entries;
+
+static int __init alloc_hypfs(struct boot_info *info)
+{
+    if ( !(builder_dir = (struct hypfs_entry_dir *)xmalloc_bytes(
+                        sizeof(struct hypfs_entry_dir))) )
+    {
+        printk(XENLOG_WARNING "%s: unable to allocate hypfs dir\n", __func__);
+        return -ENOMEM;
+    }
+
+    builder_dir->e.type = XEN_HYPFS_TYPE_DIR;
+    builder_dir->e.encoding = XEN_HYPFS_ENC_PLAIN;
+    builder_dir->e.name = "builder";
+    builder_dir->e.size = 0;
+    builder_dir->e.max_size = 0;
+    INIT_LIST_HEAD(&builder_dir->e.list);
+    builder_dir->e.funcs = &hypfs_dir_funcs;
+    INIT_LIST_HEAD(&builder_dir->dirlist);
+
+    if ( !(entries = (struct domain_node *)xmalloc_bytes(
+                        sizeof(struct domain_node) * info->builder->nr_doms)) )
+    {
+        printk(XENLOG_WARNING "%s: unable to allocate hypfs nodes\n", __func__);
+        return -ENOMEM;
+    }
+
+    return 0;
+}
+
+void __init builder_hypfs(struct boot_info *info)
+{
+    int i;
+
+    printk("Domain Builder: creating hypfs nodes\n");
+
+    if ( alloc_hypfs(info) != 0 )
+        return;
+
+    for ( i = 0; i < info->builder->nr_doms; i++ )
+    {
+        struct domain_node *e = &entries[i];
+        struct boot_domain *bd = &info->builder->domains[i];
+        uint8_t *uuid = bd->uuid;
+
+        snprintf(e->dir_name, sizeof(e->dir_name), "%d", bd->domid);
+
+        snprintf(e->uuid, sizeof(e->uuid), "%08x-%04x-%04x-%04x-%04x%08x",
+                 *(uint32_t *)uuid, *(uint16_t *)(uuid+4),
+                 *(uint16_t *)(uuid+6), *(uint16_t *)(uuid+8),
+                 *(uint16_t *)(uuid+10), *(uint32_t *)(uuid+12));
+
+        e->functions = bd->functions;
+        e->constructed = bd->constructed;
+
+        e->ncpus = bd->ncpus;
+        e->mem_size = (bd->meminfo.mem_size.nr_pages * PAGE_SIZE)/1024;
+        e->mem_max = (bd->meminfo.mem_max.nr_pages * PAGE_SIZE)/1024;
+
+        e->xs.evtchn = bd->store.evtchn;
+        e->xs.mfn = bd->store.mfn;
+
+        e->con_dev.evtchn = bd->console.evtchn;
+        e->con_dev.mfn = bd->console.mfn;
+
+        /* Initialize and construct builder hypfs tree */
+        INIT_HYPFS_DIR(e->dir, e->dir_name);
+        INIT_HYPFS_DIR(e->xs.dir, "xenstore");
+        INIT_HYPFS_DIR(e->dev_dir, "devices");
+        INIT_HYPFS_DIR(e->con_dev.dir, "console");
+
+        INIT_HYPFS_STRING(e->uuid_leaf, "uuid");
+        hypfs_string_set_reference(&e->uuid_leaf, e->uuid);
+        INIT_HYPFS_UINT(e->func_leaf, "functions", e->functions);
+        INIT_HYPFS_UINT(e->ncpus_leaf, "ncpus", e->ncpus);
+        INIT_HYPFS_UINT(e->mem_sz_leaf, "mem_size", e->mem_size);
+        INIT_HYPFS_UINT(e->mem_mx_leaf, "mem_max", e->mem_max);
+        INIT_HYPFS_BOOL(e->const_leaf, "constructed", e->constructed);
+
+        INIT_HYPFS_UINT(e->xs.evtchn_leaf, "evtchn", e->xs.evtchn);
+        INIT_HYPFS_UINT(e->xs.mfn_leaf, "mfn", e->xs.mfn);
+
+        INIT_HYPFS_UINT(e->con_dev.evtchn_leaf, "evtchn", e->con_dev.evtchn);
+        INIT_HYPFS_UINT(e->con_dev.mfn_leaf, "mfn", e->con_dev.mfn);
+
+        hypfs_add_leaf(&e->con_dev.dir, &e->con_dev.evtchn_leaf, true);
+        hypfs_add_leaf(&e->con_dev.dir, &e->con_dev.mfn_leaf, true);
+        hypfs_add_dir(&e->dev_dir, &e->con_dev.dir, true);
+
+        hypfs_add_dir(&e->dir, &e->dev_dir, true);
+
+        hypfs_add_leaf(&e->xs.dir, &e->xs.evtchn_leaf, true);
+        hypfs_add_leaf(&e->xs.dir, &e->xs.mfn_leaf, true);
+        hypfs_add_dir(&e->dir, &e->xs.dir, true);
+
+        hypfs_add_leaf(&e->dir, &e->uuid_leaf, true);
+        hypfs_add_leaf(&e->dir, &e->func_leaf, true);
+        hypfs_add_leaf(&e->dir, &e->ncpus_leaf, true);
+        hypfs_add_leaf(&e->dir, &e->mem_sz_leaf, true);
+        hypfs_add_leaf(&e->dir, &e->mem_mx_leaf, true);
+        hypfs_add_leaf(&e->dir, &e->const_leaf, true);
+
+        hypfs_add_dir(builder_dir, &e->dir, true);
+    }
+
+    hypfs_add_dir(&hypfs_root, builder_dir, true);
+}
diff --git a/xen/include/xen/domain_builder.h b/xen/include/xen/domain_builder.h
index f9e43c9689..086968b0fe 100644
--- a/xen/include/xen/domain_builder.h
+++ b/xen/include/xen/domain_builder.h
@@ -72,4 +72,17 @@ int alloc_system_evtchn(
     const struct boot_info *info, struct boot_domain *bd);
 void arch_create_dom(const struct boot_info *bi, struct boot_domain *bd);
 
+#ifdef CONFIG_HYPFS
+
+void builder_hypfs(struct boot_info *info);
+
+#else
+
+static inline void builder_hypfs(struct boot_info *info)
+{
+    return;
+}
+
+#endif
+
 #endif /* XEN_DOMAIN_BUILDER_H */
-- 
2.20.1



  parent reply	other threads:[~2022-07-06 21:18 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-06 21:04 [PATCH v1 00/18] Hyperlaunch Daniel P. Smith
2022-07-06 21:04 ` [PATCH v1 01/18] kconfig: allow configuration of maximum modules Daniel P. Smith
2022-07-07  1:44   ` Henry Wang
2022-07-15 19:16   ` Julien Grall
2022-07-19 16:36     ` Daniel P. Smith
2022-07-26 18:07       ` Julien Grall
2022-07-27  6:12         ` Jan Beulich
2022-07-19  9:32   ` Jan Beulich
2022-07-19 17:02     ` Daniel P. Smith
2022-07-20  7:27       ` Jan Beulich
2022-07-22 15:00         ` Daniel P. Smith
2022-07-06 21:04 ` [PATCH v1 02/18] introduction of generalized boot info Daniel P. Smith
2022-07-15 19:25   ` Julien Grall
2022-07-20 18:32     ` Daniel P. Smith
2022-07-19 13:11   ` Jan Beulich
2022-07-21 14:28     ` Daniel P. Smith
2022-07-21 16:00       ` Jan Beulich
2022-07-21 16:00       ` Jan Beulich
2022-07-22 16:01         ` Daniel P. Smith
2022-07-25  7:05           ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 03/18] x86: adopt new boot info structures Daniel P. Smith
2022-07-19 13:19   ` Jan Beulich
2022-07-22 12:34     ` Daniel P. Smith
2022-07-06 21:04 ` [PATCH v1 04/18] x86: refactor entrypoints to new boot info Daniel P. Smith
2022-07-18 13:58   ` Smith, Jackson
2022-07-22 12:59     ` Daniel P. Smith
2022-07-06 21:04 ` [PATCH v1 05/18] x86: refactor xen cmdline into general framework Daniel P. Smith
2022-07-19 13:26   ` Jan Beulich
2022-07-22 13:12     ` Daniel P. Smith
2022-07-25  7:09       ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 06/18] fdt: make fdt handling reusable across arch Daniel P. Smith
2022-07-07  1:44   ` Henry Wang
2022-07-19  9:36   ` Jan Beulich
2022-07-22 13:18     ` Daniel P. Smith
2022-07-06 21:04 ` [PATCH v1 07/18] docs: update hyperlaunch device tree documentation Daniel P. Smith
2022-07-18 13:57   ` Smith, Jackson
2022-07-22 13:34     ` Daniel P. Smith
2022-07-06 21:04 ` [PATCH v1 08/18] kconfig: introduce domain builder config option Daniel P. Smith
2022-07-07  1:44   ` Henry Wang
2022-07-19 13:29   ` Jan Beulich
2022-07-22 13:47     ` Daniel P. Smith
2022-07-06 21:04 ` [PATCH v1 09/18] x86: introduce abstractions for domain builder Daniel P. Smith
2022-07-26 14:22   ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 10/18] x86: introduce the " Daniel P. Smith
2022-07-18 13:59   ` Smith, Jackson
2022-07-22 14:36     ` Daniel P. Smith
2022-07-22 20:33       ` Smith, Jackson
2022-07-23 10:45         ` Daniel P. Smith
2022-07-26 14:46   ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 11/18] x86: initial conversion to " Daniel P. Smith
2022-07-26 15:01   ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 12/18] x86: convert dom0 creation " Daniel P. Smith
2022-07-27 12:25   ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 13/18] x86: generalize physmap logic Daniel P. Smith
2022-07-27 12:33   ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 14/18] x86: generalize vcpu for domain building Daniel P. Smith
2022-07-27 12:46   ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 15/18] x86: rework domain page allocation Daniel P. Smith
2022-07-27 13:22   ` Jan Beulich
2022-07-06 21:04 ` [PATCH v1 16/18] x86: add pv multidomain construction Daniel P. Smith
2022-07-27 14:12   ` Jan Beulich
2022-07-06 21:04 ` Daniel P. Smith [this message]
2022-07-27 14:30   ` [PATCH v1 17/18] builder: introduce domain builder hypfs tree Jan Beulich
2022-07-06 21:04 ` [PATCH v1 18/18] tools: introduce example late pv helper Daniel P. Smith
2022-07-19 17:06 ` [PATCH v1 00/18] Hyperlaunch Smith, Jackson
2022-07-22 14:51   ` Daniel P. Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220706210454.30096-18-dpsmith@apertussolutions.com \
    --to=dpsmith@apertussolutions.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=christopher.clark@starlab.io \
    --cc=george.dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=scott.davis@starlab.io \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.