All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>
Subject: [PATCH v2 02/12] tools: Rework xc_domain_create() to take a full xen_domctl_createdomain
Date: Mon, 13 Aug 2018 11:00:59 +0100	[thread overview]
Message-ID: <1534154469-6076-3-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1534154469-6076-1-git-send-email-andrew.cooper3@citrix.com>

In future patches, the structure will be extended with further information,
and this is far cleaner than adding extra parameters.

The python stubs are the only user which passes NULL for the existing config
option (which is actually the arch substructure).  Therefore, the #ifdefary
moves to compensate.

For libxl, pass the full config object down into
libxl__arch_domain_{prepare,save}_config(), as there are in practice arch
specific settings in the common part of the structure (flags s3_integrity and
oos_off specifically).

No practical change in behaviour.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
---
CC: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
 tools/helpers/init-xenstore-domain.c | 16 +++++++---------
 tools/libxc/include/xenctrl.h        |  6 ++----
 tools/libxc/xc_domain.c              | 31 ++++---------------------------
 tools/libxl/libxl_arch.h             |  4 ++--
 tools/libxl/libxl_arm.c              | 16 ++++++++--------
 tools/libxl/libxl_create.c           | 23 ++++++++++++-----------
 tools/libxl/libxl_x86.c              | 10 +++++-----
 tools/ocaml/libs/xc/xenctrl_stubs.c  |  3 +--
 tools/python/xen/lowlevel/xc/xc.c    | 28 ++++++++++++++++++++--------
 9 files changed, 61 insertions(+), 76 deletions(-)

diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
index 8453be2..785e570 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -60,11 +60,13 @@ static void usage(void)
 static int build(xc_interface *xch)
 {
     char cmdline[512];
-    uint32_t ssid;
-    xen_domain_handle_t handle = { 0 };
     int rv, xs_fd;
     struct xc_dom_image *dom = NULL;
     int limit_kb = (maxmem ? : (memory + 1)) * 1024;
+    struct xen_domctl_createdomain config = {
+        .ssidref = SECINITSID_DOMU,
+        .flags = XEN_DOMCTL_CDF_xs_domain,
+    };
 
     xs_fd = open("/dev/xen/xenbus_backend", O_RDWR);
     if ( xs_fd == -1 )
@@ -75,19 +77,15 @@ static int build(xc_interface *xch)
 
     if ( flask )
     {
-        rv = xc_flask_context_to_sid(xch, flask, strlen(flask), &ssid);
+        rv = xc_flask_context_to_sid(xch, flask, strlen(flask), &config.ssidref);
         if ( rv )
         {
             fprintf(stderr, "xc_flask_context_to_sid failed\n");
             goto err;
         }
     }
-    else
-    {
-        ssid = SECINITSID_DOMU;
-    }
-    rv = xc_domain_create(xch, ssid, handle, XEN_DOMCTL_CDF_xs_domain,
-                          &domid, NULL);
+
+    rv = xc_domain_create(xch, &domid, &config);
     if ( rv )
     {
         fprintf(stderr, "xc_domain_create failed\n");
diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index dd7d8a9..2c4ac32 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -504,10 +504,8 @@ typedef struct xc_vcpu_extstate {
     void *buffer;
 } xc_vcpu_extstate_t;
 
-typedef struct xen_arch_domainconfig xc_domain_configuration_t;
-int xc_domain_create(xc_interface *xch, uint32_t ssidref,
-                     xen_domain_handle_t handle, uint32_t flags,
-                     uint32_t *pdomid, xc_domain_configuration_t *config);
+int xc_domain_create(xc_interface *xch, uint32_t *pdomid,
+                     struct xen_domctl_createdomain *config);
 
 
 /* Functions to produce a dump of a given domain
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index 57e18ee..0124cea 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -26,43 +26,20 @@
 #include <xen/memory.h>
 #include <xen/hvm/hvm_op.h>
 
-int xc_domain_create(xc_interface *xch, uint32_t ssidref,
-                     xen_domain_handle_t handle, uint32_t flags,
-                     uint32_t *pdomid, xc_domain_configuration_t *config)
+int xc_domain_create(xc_interface *xch, uint32_t *pdomid,
+                     struct xen_domctl_createdomain *config)
 {
-    xc_domain_configuration_t lconfig;
     int err;
     DECLARE_DOMCTL;
 
-    if ( config == NULL )
-    {
-        memset(&lconfig, 0, sizeof(lconfig));
-
-#if defined (__i386) || defined(__x86_64__)
-        if ( flags & XEN_DOMCTL_CDF_hvm_guest )
-            lconfig.emulation_flags = (XEN_X86_EMU_ALL & ~XEN_X86_EMU_VPCI);
-#elif defined (__arm__) || defined(__aarch64__)
-        lconfig.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
-        lconfig.nr_spis = 0;
-#else
-#error Architecture not supported
-#endif
-
-        config = &lconfig;
-    }
-
     domctl.cmd = XEN_DOMCTL_createdomain;
     domctl.domain = *pdomid;
-    domctl.u.createdomain.ssidref = ssidref;
-    domctl.u.createdomain.flags   = flags;
-    memcpy(domctl.u.createdomain.handle, handle, sizeof(xen_domain_handle_t));
-    /* xc_domain_configure_t is an alias of arch_domainconfig_t */
-    memcpy(&domctl.u.createdomain.arch, config, sizeof(*config));
+    domctl.u.createdomain = *config;
+
     if ( (err = do_domctl(xch, &domctl)) != 0 )
         return err;
 
     *pdomid = (uint16_t)domctl.domain;
-    memcpy(config, &domctl.u.createdomain.arch, sizeof(*config));
 
     return 0;
 }
diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
index 74a5af3..c8ccaaf 100644
--- a/tools/libxl/libxl_arch.h
+++ b/tools/libxl/libxl_arch.h
@@ -19,14 +19,14 @@
 _hidden
 int libxl__arch_domain_prepare_config(libxl__gc *gc,
                                       libxl_domain_config *d_config,
-                                      xc_domain_configuration_t *xc_config);
+                                      struct xen_domctl_createdomain *config);
 
 /* save the arch specific configuration for the domain */
 _hidden
 int libxl__arch_domain_save_config(libxl__gc *gc,
                                    libxl_domain_config *d_config,
                                    libxl__domain_build_state *state,
-                                   const xc_domain_configuration_t *xc_config);
+                                   const struct xen_domctl_createdomain *config);
 
 /* arch specific internal domain creation function */
 _hidden
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 8af9f6f..2a25201 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -39,7 +39,7 @@ static const char *gicv_to_string(libxl_gic_version gic_version)
 
 int libxl__arch_domain_prepare_config(libxl__gc *gc,
                                       libxl_domain_config *d_config,
-                                      xc_domain_configuration_t *xc_config)
+                                      struct xen_domctl_createdomain *config)
 {
     uint32_t nr_spis = 0;
     unsigned int i;
@@ -86,18 +86,18 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
 
     LOG(DEBUG, "Configure the domain");
 
-    xc_config->nr_spis = nr_spis;
+    config->arch.nr_spis = nr_spis;
     LOG(DEBUG, " - Allocate %u SPIs", nr_spis);
 
     switch (d_config->b_info.arch_arm.gic_version) {
     case LIBXL_GIC_VERSION_DEFAULT:
-        xc_config->gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
+        config->arch.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
         break;
     case LIBXL_GIC_VERSION_V2:
-        xc_config->gic_version = XEN_DOMCTL_CONFIG_GIC_V2;
+        config->arch.gic_version = XEN_DOMCTL_CONFIG_GIC_V2;
         break;
     case LIBXL_GIC_VERSION_V3:
-        xc_config->gic_version = XEN_DOMCTL_CONFIG_GIC_V3;
+        config->arch.gic_version = XEN_DOMCTL_CONFIG_GIC_V3;
         break;
     default:
         LOG(ERROR, "Unknown GIC version %d",
@@ -111,9 +111,9 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
 int libxl__arch_domain_save_config(libxl__gc *gc,
                                    libxl_domain_config *d_config,
                                    libxl__domain_build_state *state,
-                                   const xc_domain_configuration_t *xc_config)
+                                   const struct xen_domctl_createdomain *config)
 {
-    switch (xc_config->gic_version) {
+    switch (config->arch.gic_version) {
     case XEN_DOMCTL_CONFIG_GIC_V2:
         d_config->b_info.arch_arm.gic_version = LIBXL_GIC_VERSION_V2;
         break;
@@ -121,7 +121,7 @@ int libxl__arch_domain_save_config(libxl__gc *gc,
         d_config->b_info.arch_arm.gic_version = LIBXL_GIC_VERSION_V3;
         break;
     default:
-        LOG(ERROR, "Unexpected gic version %u", xc_config->gic_version);
+        LOG(ERROR, "Unexpected gic version %u", config->arch.gic_version);
         return ERROR_FAIL;
     }
 
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 1ccb3e3..dd9d8c8 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -563,35 +563,36 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
 
     /* Valid domid here means we're soft resetting. */
     if (!libxl_domid_valid_guest(*domid)) {
-        int flags = 0;
-        xen_domain_handle_t handle;
-        xc_domain_configuration_t xc_config = {};
+        struct xen_domctl_createdomain create = {
+            .ssidref = info->ssidref,
+        };
 
         if (info->type != LIBXL_DOMAIN_TYPE_PV) {
-            flags |= XEN_DOMCTL_CDF_hvm_guest;
-            flags |= libxl_defbool_val(info->hap) ? XEN_DOMCTL_CDF_hap : 0;
-            flags |= libxl_defbool_val(info->oos) ? 0 : XEN_DOMCTL_CDF_oos_off;
+            create.flags |= XEN_DOMCTL_CDF_hvm_guest;
+            create.flags |=
+                libxl_defbool_val(info->hap) ? XEN_DOMCTL_CDF_hap : 0;
+            create.flags |=
+                libxl_defbool_val(info->oos) ? 0 : XEN_DOMCTL_CDF_oos_off;
         }
 
         /* Ultimately, handle is an array of 16 uint8_t, same as uuid */
-        libxl_uuid_copy(ctx, (libxl_uuid *)handle, &info->uuid);
+        libxl_uuid_copy(ctx, (libxl_uuid *)&create.handle, &info->uuid);
 
-        ret = libxl__arch_domain_prepare_config(gc, d_config, &xc_config);
+        ret = libxl__arch_domain_prepare_config(gc, d_config, &create);
         if (ret < 0) {
             LOGED(ERROR, *domid, "fail to get domain config");
             rc = ERROR_FAIL;
             goto out;
         }
 
-        ret = xc_domain_create(ctx->xch, info->ssidref, handle, flags, domid,
-                               &xc_config);
+        ret = xc_domain_create(ctx->xch, domid, &create);
         if (ret < 0) {
             LOGED(ERROR, *domid, "domain creation fail");
             rc = ERROR_FAIL;
             goto out;
         }
 
-        rc = libxl__arch_domain_save_config(gc, d_config, state, &xc_config);
+        rc = libxl__arch_domain_save_config(gc, d_config, state, &create);
         if (rc < 0)
             goto out;
     }
diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index ab88562..6f670b0 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -5,17 +5,17 @@
 
 int libxl__arch_domain_prepare_config(libxl__gc *gc,
                                       libxl_domain_config *d_config,
-                                      xc_domain_configuration_t *xc_config)
+                                      struct xen_domctl_createdomain *config)
 {
     switch(d_config->c_info.type) {
     case LIBXL_DOMAIN_TYPE_HVM:
-        xc_config->emulation_flags = (XEN_X86_EMU_ALL & ~XEN_X86_EMU_VPCI);
+        config->arch.emulation_flags = (XEN_X86_EMU_ALL & ~XEN_X86_EMU_VPCI);
         break;
     case LIBXL_DOMAIN_TYPE_PVH:
-        xc_config->emulation_flags = XEN_X86_EMU_LAPIC;
+        config->arch.emulation_flags = XEN_X86_EMU_LAPIC;
         break;
     case LIBXL_DOMAIN_TYPE_PV:
-        xc_config->emulation_flags = 0;
+        config->arch.emulation_flags = 0;
         break;
     default:
         abort();
@@ -27,7 +27,7 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
 int libxl__arch_domain_save_config(libxl__gc *gc,
                                    libxl_domain_config *d_config,
                                    libxl__domain_build_state *state,
-                                   const xc_domain_configuration_t *xc_config)
+                                   const struct xen_domctl_createdomain *config)
 {
     return 0;
 }
diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenctrl_stubs.c
index dbe9c3e..1206eae 100644
--- a/tools/ocaml/libs/xc/xenctrl_stubs.c
+++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -174,8 +174,7 @@ CAMLprim value stub_xc_domain_create(value xch, value config)
 #undef VAL_SSIDREF
 
 	caml_enter_blocking_section();
-	result = xc_domain_create(_H(xch), cfg.ssidref, cfg.handle, cfg.flags,
-				  &domid, &cfg.arch);
+	result = xc_domain_create(_H(xch), &domid, &cfg);
 	caml_leave_blocking_section();
 
 	if (result < 0)
diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index 5ade127..5a2923a 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -117,17 +117,21 @@ static PyObject *pyxc_domain_create(XcObject *self,
                                     PyObject *args,
                                     PyObject *kwds)
 {
-    uint32_t dom = 0, ssidref = 0, flags = 0, target = 0;
+    uint32_t dom = 0, target = 0;
     int      ret, i;
     PyObject *pyhandle = NULL;
-    xen_domain_handle_t handle = { 
-        0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
-        0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef };
+    struct xen_domctl_createdomain config = {
+        .handle = {
+            0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
+            0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
+        },
+    };
 
     static char *kwd_list[] = { "domid", "ssidref", "handle", "flags", "target", NULL };
 
     if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiOii", kwd_list,
-                                      &dom, &ssidref, &pyhandle, &flags, &target))
+                                      &dom, &config.ssidref, &pyhandle,
+                                      &config.flags, &target))
         return NULL;
     if ( pyhandle != NULL )
     {
@@ -140,12 +144,20 @@ static PyObject *pyxc_domain_create(XcObject *self,
             PyObject *p = PyList_GetItem(pyhandle, i);
             if ( !PyLongOrInt_Check(p) )
                 goto out_exception;
-            handle[i] = (uint8_t)PyLongOrInt_AsLong(p);
+            config.handle[i] = (uint8_t)PyLongOrInt_AsLong(p);
         }
     }
 
-    if ( (ret = xc_domain_create(self->xc_handle, ssidref,
-                                 handle, flags, &dom, NULL)) < 0 )
+#if defined (__i386) || defined(__x86_64__)
+    if ( config.flags & XEN_DOMCTL_CDF_hvm_guest )
+        config.arch.emulation_flags = (XEN_X86_EMU_ALL & ~XEN_X86_EMU_VPCI);
+#elif defined (__arm__) || defined(__aarch64__)
+    config.arch.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
+#else
+#error Architecture not supported
+#endif
+
+    if ( (ret = xc_domain_create(self->xc_handle, &dom, &config)) < 0 )
         return pyxc_error_to_exception(self->xc_handle);
 
     if ( target )
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-08-13 10:00 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-13 10:00 [PATCH v2 00/12] Improvements to domain creation Andrew Cooper
2018-08-13 10:00 ` [PATCH v2 01/12] tools/ocaml: Pass a full domctl_create_config into stub_xc_domain_create() Andrew Cooper
2018-08-13 10:00 ` Andrew Cooper [this message]
2018-08-13 10:01 ` [PATCH v2 03/12] xen/domctl: Merge set_max_evtchn into createdomain Andrew Cooper
2018-08-14 13:58   ` Roger Pau Monné
2018-08-13 10:01 ` [PATCH v2 04/12] xen/evtchn: Pass max_evtchn_port into evtchn_init() Andrew Cooper
2018-08-14 14:07   ` Roger Pau Monné
2018-08-15 12:45   ` Jan Beulich
2018-08-15 12:57   ` Julien Grall
2018-08-13 10:01 ` [PATCH v2 05/12] tools: Pass grant table limits to XEN_DOMCTL_set_gnttab_limits Andrew Cooper
2018-08-13 10:01 ` [PATCH v2 06/12] xen/gnttab: Pass max_{grant, maptrack}_frames into grant_table_create() Andrew Cooper
2018-08-14 14:17   ` Roger Pau Monné
2018-08-15 12:51   ` Jan Beulich
2018-08-15 13:04   ` Julien Grall
2018-08-15 13:08     ` Andrew Cooper
2018-08-15 13:32       ` Julien Grall
2018-08-15 19:03         ` Andrew Cooper
2018-08-16  8:59           ` Julien Grall
2018-08-29  9:38   ` [PATCH v3 6/12] " Andrew Cooper
2018-08-30 19:40     ` Julien Grall
2018-08-13 10:01 ` [PATCH v2 07/12] xen/domctl: Remove XEN_DOMCTL_set_gnttab_limits Andrew Cooper
2018-08-14 14:19   ` Roger Pau Monné
2018-08-13 10:01 ` [PATCH v2 08/12] xen/gnttab: Fold grant_table_{create, set_limits}() into grant_table_init() Andrew Cooper
2018-08-14 14:31   ` Roger Pau Monné
2018-08-15 12:54   ` Jan Beulich
2018-08-13 10:01 ` [PATCH v2 09/12] xen/domain: Call arch_domain_create() as early as possible in domain_create() Andrew Cooper
2018-08-14 14:37   ` Roger Pau Monné
2018-08-15 12:56   ` Jan Beulich
2018-09-04 18:44   ` Rats nest with domain pirq initialisation Andrew Cooper
2018-09-05  7:24     ` Jan Beulich
2018-09-05 11:38       ` Jan Beulich
2018-09-05 12:04       ` Andrew Cooper
2018-09-05 12:25         ` Jan Beulich
2018-09-05 12:39           ` Andrew Cooper
2018-09-05 15:44             ` Roger Pau Monné
2018-08-13 10:01 ` [PATCH v2 10/12] tools: Pass max_vcpus to XEN_DOMCTL_createdomain Andrew Cooper
2018-08-13 10:01 ` [PATCH v2 11/12] xen/dom0: Arrange for dom0_cfg to contain the real max_vcpus value Andrew Cooper
2018-08-14 15:05   ` Roger Pau Monné
2018-08-15 12:59   ` Jan Beulich
2018-08-13 10:01 ` [PATCH v2 12/12] xen/domain: Allocate d->vcpu[] in domain_create() Andrew Cooper
2018-08-14 15:17   ` Roger Pau Monné
2018-08-15 13:17     ` Julien Grall
2018-08-15 13:50       ` Andrew Cooper
2018-08-15 13:52         ` Julien Grall
2018-08-15 13:56           ` Andrew Cooper
2018-08-15 13:11   ` Jan Beulich
2018-08-15 14:03     ` Andrew Cooper
2018-08-15 15:18       ` Jan Beulich
2018-08-29 10:36         ` Andrew Cooper
2018-08-29 12:10           ` Jan Beulich
2018-08-29 12:29             ` Andrew Cooper
2018-08-29 12:49               ` Jan Beulich
2018-08-29 14:40   ` [PATCH v3 " Andrew Cooper
2018-08-29 15:03     ` Jan Beulich
2018-08-31 10:33       ` Wei Liu
2018-08-31 10:42         ` Jan Beulich
2018-08-31 10:57           ` Julien Grall
2018-08-31 11:00             ` Juergen Gross
2018-08-31 10:58           ` Andrew Cooper
2018-08-30 19:46     ` Julien Grall
2018-08-30 20:04       ` Andrew Cooper
2018-08-14 13:12 ` [PATCH v2 00/12] Improvements to domain creation Christian Lindig
2018-08-14 13:34   ` Andrew Cooper

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=1534154469-6076-3-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=marmarek@invisiblethingslab.com \
    --cc=xen-devel@lists.xen.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.