Skip to contentSkip to conversation

Improvements to domain creation

PATCH In review Andrew Cooper 7 participants 63 messages Aug 13, 2018 – Sep 5, 2018 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

v2 cover Improvements to domain creation

The main purpose of this series is to move the allocation of d->vcpu[] into XEN_DOMCTL_createdomain, which resolves a longstanding issue since Xen 4.0 whereby the toolstack can cause NULL pointer deferences in Xen by issuing hypercalls in an unexpected order.

Due to the way cleanup is currently performed, XEN_DOMCTL_max_vcpus is still required at this point. Further hypervisor cleanup and rearrangement is going to be required before the hypercall can be dropped.

This series can be found in git form here:
http://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen.git;a=shortlog;h=refs/heads/xen-create-v1

v2 has had comprehensive testing in XenServer, but is only build tested for ARM.

Andrew Cooper (12):
tools/ocaml: Pass a full domctl_create_config into stub_xc_domain_create()
tools: Rework xc_domain_create() to take a full xen_domctl_createdomain xen/domctl: Merge set_max_evtchn into createdomain
xen/evtchn: Pass max_evtchn_port into evtchn_init()
tools: Pass grant table limits to XEN_DOMCTL_set_gnttab_limits xen/gnttab: Pass max_{grant,maptrack}_frames into grant_table_create() xen/domctl: Remove XEN_DOMCTL_set_gnttab_limits
xen/gnttab: Fold grant_table_{create,set_limits}() into grant_table_init() xen/domain: Call arch_domain_create() as early as possible in domain_create()
tools: Pass max_vcpus to XEN_DOMCTL_createdomain
xen/dom0: Arrange for dom0_cfg to contain the real max_vcpus value xen/domain: Allocate d->vcpu[] in domain_create()

 tools/flask/policy/modules/dom0.te   |   4 +-
 tools/flask/policy/modules/xen.if    |   4 +-
 tools/helpers/init-xenstore-domain.c |  39 ++++++-------
 tools/libxc/include/xenctrl.h        |  31 +----------
 tools/libxc/xc_domain.c              |  55 ++-----------------
 tools/libxl/libxl_arch.h             |   4 +-
 tools/libxl/libxl_arm.c              |  16 +++---
 tools/libxl/libxl_create.c           |  28 ++++++----
 tools/libxl/libxl_dom.c              |  13 -----
 tools/libxl/libxl_x86.c              |  10 ++--
 tools/ocaml/libs/xc/xenctrl.ml       |  18 +++++-
 tools/ocaml/libs/xc/xenctrl.mli      |  17 +++++-
 tools/ocaml/libs/xc/xenctrl_stubs.c  |  63 +++++++++++++++------
 tools/python/xen/lowlevel/xc/xc.c    |  42 ++++++++++----
 xen/arch/arm/domain_build.c          |  13 +++--
 xen/arch/arm/setup.c                 |  17 +++++-
 xen/arch/arm/vgic.c                  |  11 +---
 xen/arch/arm/vgic/vgic.c             |  22 +-------
 xen/arch/x86/dom0_build.c            |   7 ---
 xen/arch/x86/setup.c                 |   5 ++
 xen/common/domain.c                  |  57 ++++++++++++-------
 xen/common/domctl.c                  |  50 +----------------
 xen/common/event_channel.c           |   7 +--
 xen/common/grant_table.c             | 103 +++++++++--------------------------
 xen/include/asm-arm/grant_table.h    |  12 ----
 xen/include/asm-x86/grant_table.h    |   5 --
 xen/include/asm-x86/setup.h          |   2 -
 xen/include/public/domctl.h          |  30 ++++------
 xen/include/xen/domain.h             |   3 +
 xen/include/xen/grant_table.h        |   8 +--
 xen/include/xen/sched.h              |   2 +-
 xen/xsm/flask/hooks.c                |   6 --
 xen/xsm/flask/policy/access_vectors  |   4 --
 33 files changed, 281 insertions(+), 427 deletions(-)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v2 1/12 tools/ocaml: Pass a full domctl_create_config into stub_xc_domain_create()

The underlying C function is about to make the same change, and the structure is going to gain extra fields.

---
v2:
* Fix indirection bug with xen_x86_arch_domctlconfig

---
 tools/ocaml/libs/xc/xenctrl.ml      | 14 +++++++---
 tools/ocaml/libs/xc/xenctrl.mli     | 13 +++++++---
 tools/ocaml/libs/xc/xenctrl_stubs.c | 52 ++++++++++++++++++++++++-------------
 3 files changed, 55 insertions(+), 24 deletions(-)
tools/ocaml/libs/xc/xenctrl.ml +11 -3
index b3b33bb..3b7526e 100644
@@ -56,6 +56,16 @@ type arch_domainconfig =
 	| ARM of xen_arm_arch_domainconfig
 	| X86 of xen_x86_arch_domainconfig
 
+type domain_create_flag = CDF_HVM | CDF_HAP
+
+type domctl_create_config =
+{
+	ssidref: int32;
+	handle: string;
+	flags: domain_create_flag list;
+	arch: arch_domainconfig;
+}
+
 type domaininfo =
 {
 	domid             : domid;
@@ -120,8 +130,6 @@ type compile_info =
 
 type shutdown_reason = Poweroff | Reboot | Suspend | Crash | Watchdog | Soft_reset
 
-type domain_create_flag = CDF_HVM | CDF_HAP
-
 exception Error of string
 
 type handle
@@ -135,7 +143,7 @@ let with_intf f =
 	interface_close xc;
 	r
 
-external domain_create: handle -> int32 -> domain_create_flag list -> string -> arch_domainconfig -> domid
+external domain_create: handle -> domctl_create_config -> domid
        = "stub_xc_domain_create"
 
 external domain_sethandle: handle -> domid -> string -> unit
tools/ocaml/libs/xc/xenctrl.mli +10 -3
index 35303ab..d103a33 100644
@@ -49,6 +49,15 @@ type arch_domainconfig =
   | ARM of xen_arm_arch_domainconfig
   | X86 of xen_x86_arch_domainconfig
 
+type domain_create_flag = CDF_HVM | CDF_HAP
+
+type domctl_create_config = {
+  ssidref: int32;
+  handle: string;
+  flags: domain_create_flag list;
+  arch: arch_domainconfig;
+}
+
 type domaininfo = {
   domid : domid;
   dying : bool;
@@ -91,14 +100,12 @@ type compile_info = {
 }
 type shutdown_reason = Poweroff | Reboot | Suspend | Crash | Watchdog | Soft_reset
 
-type domain_create_flag = CDF_HVM | CDF_HAP
-
 exception Error of string
 type handle
 external interface_open : unit -> handle = "stub_xc_interface_open"
 external interface_close : handle -> unit = "stub_xc_interface_close"
 val with_intf : (handle -> 'a) -> 'a
-external domain_create : handle -> int32 -> domain_create_flag list -> string -> arch_domainconfig -> domid
+external domain_create : handle -> domctl_create_config -> domid
   = "stub_xc_domain_create"
 external domain_sethandle : handle -> domid -> string -> unit = "stub_xc_domain_sethandle"
 external domain_max_vcpus : handle -> domid -> int -> unit
tools/ocaml/libs/xc/xenctrl_stubs.c +34 -18

78 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

PATCH v2 2/12 tools: Rework xc_domain_create() to take a full xen_domctl_createdomain

In reply to Andrew Cooper

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.

---
CC: Marek Marczykowski-Górecki <[email protected]>

---
 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(-)
tools/helpers/init-xenstore-domain.c +7 -9
index 8453be2..785e570 100644
@@ -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");
tools/libxc/include/xenctrl.h +2 -4
index dd7d8a9..2c4ac32 100644
@@ -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
tools/libxc/xc_domain.c +4 -27
index 57e18ee..0124cea 100644
@@ -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;
 }
tools/libxl/libxl_arch.h +2 -2
index 74a5af3..c8ccaaf 100644
@@ -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
tools/libxl/libxl_arm.c +8 -8
index 8af9f6f..2a25201 100644
@@ -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;
     }
 
tools/libxl/libxl_create.c +12 -11
index 1ccb3e3..dd9d8c8 100644
@@ -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;
     }
tools/libxl/libxl_x86.c +5 -5
index ab88562..6f670b0 100644
@@ -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;
 }
tools/ocaml/libs/xc/xenctrl_stubs.c +1 -2
index dbe9c3e..1206eae 100644
@@ -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)
tools/python/xen/lowlevel/xc/xc.c +20 -8
index 5ade127..5a2923a 100644
@@ -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 )
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw

PATCH v2 3/12 xen/domctl: Merge set_max_evtchn into createdomain

In reply to Andrew Cooper

set_max_evtchn is somewhat weird. It was introduced with the event_fifo work, but has never been used. Still, it is a bounding on resources consumed by the event channel infrastructure, and should be part of createdomain, rather than editable after the fact.

Drop XEN_DOMCTL_set_max_evtchn completely (including XSM hooks and libxc wrappers), and retain the functionality in XEN_DOMCTL_createdomain.

---
CC: Jan Beulich <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Marek Marczykowski-Górecki <[email protected]>

Hypervisor side cleanup is present in a later patch

v2:
* Use int rather than int32 for Ocaml stubs

---
 tools/flask/policy/modules/dom0.te   |  2 +-
 tools/flask/policy/modules/xen.if    |  2 +-
 tools/helpers/init-xenstore-domain.c |  1 +
 tools/libxc/include/xenctrl.h        | 12 ------------
 tools/libxc/xc_domain.c              | 11 -----------
 tools/libxl/libxl_create.c           |  2 ++
 tools/libxl/libxl_dom.c              |  7 -------
 tools/ocaml/libs/xc/xenctrl.ml       |  1 +
 tools/ocaml/libs/xc/xenctrl.mli      |  1 +
 tools/ocaml/libs/xc/xenctrl_stubs.c  |  5 ++++-
 tools/python/xen/lowlevel/xc/xc.c    |  1 +
 xen/common/domctl.c                  |  9 +++------
 xen/include/public/domctl.h          | 19 ++++++++-----------
 xen/xsm/flask/hooks.c                |  3 ---
 xen/xsm/flask/policy/access_vectors  |  2 --
 15 files changed, 23 insertions(+), 55 deletions(-)
tools/flask/policy/modules/dom0.te +1 -1
index bf794d9..4eb3843 100644
@@ -38,7 +38,7 @@ allow dom0_t dom0_t:domain {
 	getpodtarget setpodtarget set_misc_info set_virq_handler
 };
 allow dom0_t dom0_t:domain2 {
-	set_cpuid gettsc settsc setscheduler set_max_evtchn set_vnumainfo
+	set_cpuid gettsc settsc setscheduler set_vnumainfo
 	get_vnumainfo psr_cmt_op psr_alloc set_gnttab_limits
 };
 allow dom0_t dom0_t:resource { add remove };
tools/flask/policy/modules/xen.if +1 -1
index 7aefd00..61b0e76 100644
@@ -51,7 +51,7 @@ define(`create_domain_common', `
 			getvcpuinfo getaddrsize getaffinity setaffinity
 			settime setdomainhandle getvcpucontext set_misc_info };
 	allow $1 $2:domain2 { set_cpuid settsc setscheduler setclaim
-			set_max_evtchn set_vnumainfo get_vnumainfo cacheflush
+			set_vnumainfo get_vnumainfo cacheflush
 			psr_cmt_op psr_alloc soft_reset set_gnttab_limits
 			resource_map };
 	allow $1 $2:security check_context;
tools/helpers/init-xenstore-domain.c +1 -0
index 785e570..89c329c 100644
@@ -66,6 +66,7 @@ static int build(xc_interface *xch)
     struct xen_domctl_createdomain config = {
         .ssidref = SECINITSID_DOMU,
         .flags = XEN_DOMCTL_CDF_xs_domain,
+        .max_evtchn_port = -1, /* No limit. */
     };
 
     xs_fd = open("/dev/xen/xenbus_backend", O_RDWR);
tools/libxc/include/xenctrl.h +0 -12
index 2c4ac32..c626984 100644
@@ -1082,18 +1082,6 @@ int xc_domain_set_access_required(xc_interface *xch,
 int xc_domain_set_virq_handler(xc_interface *xch, uint32_t domid, int virq);
 
 /**
- * Set the maximum event channel port a domain may bind.
- *
- * This does not affect ports that are already bound.
- *
- * @param xch a handle to an open hypervisor interface
- * @param domid the domain id
- * @param max_port maximum port number
- */
-int xc_domain_set_max_evtchn(xc_interface *xch, uint32_t domid,
-                             uint32_t max_port);
-
-/**
  * Set the maximum number of grant frames and maptrack frames a domain
  * can have. Must be used at domain setup time and only then.
  *
tools/libxc/xc_domain.c +0 -11
index 0124cea..2bc695c 100644
@@ -2256,17 +2256,6 @@ int xc_domain_set_virq_handler(xc_interface *xch, uint32_t domid, int virq)
     return do_domctl(xch, &domctl);
 }
 
-int xc_domain_set_max_evtchn(xc_interface *xch, uint32_t domid,
-                             uint32_t max_port)
-{
-    DECLARE_DOMCTL;
-
-    domctl.cmd = XEN_DOMCTL_set_max_evtchn;
-    domctl.domain = domid;
-    domctl.u.set_max_evtchn.max_port = max_port;
-    return do_domctl(xch, &domctl);
-}
-
 int xc_domain_set_gnttab_limits(xc_interface *xch, uint32_t domid,
                                 uint32_t grant_frames,
                                 uint32_t maptrack_frames)
tools/libxl/libxl_create.c +2 -0
index dd9d8c8..b7b44e2 100644
@@ -554,6 +554,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
 
     /* convenience aliases */
     libxl_domain_create_info *info = &d_config->c_info;
+    libxl_domain_build_info *b_info = &d_config->b_info;
 
     uuid_string = libxl__uuid2string(gc, info->uuid);
     if (!uuid_string) {
@@ -565,6 +566,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
     if (!libxl_domid_valid_guest(*domid)) {
         struct xen_domctl_createdomain create = {
             .ssidref = info->ssidref,
+            .max_evtchn_port = b_info->event_channels,
         };
 
         if (info->type != LIBXL_DOMAIN_TYPE_PV) {
tools/libxl/libxl_dom.c +0 -7
index c8a1dc7..eb401cf 100644
@@ -590,13 +590,6 @@ int libxl__build_post(libxl__gc *gc, uint32_t domid,
     if (rc)
         return rc;
 
-    rc = xc_domain_set_max_evtchn(ctx->xch, domid, info->event_channels);
-    if (rc) {
-        LOG(ERROR, "Failed to set event channel limit to %d (%d)",
-            info->event_channels, rc);
-        return ERROR_FAIL;
-    }
-
     libxl_cpuid_apply_policy(ctx, domid);
     if (info->cpuid != NULL)
         libxl_cpuid_set(ctx, domid, info->cpuid);
tools/ocaml/libs/xc/xenctrl.ml +1 -0
index 3b7526e..219355a 100644
@@ -63,6 +63,7 @@ type domctl_create_config =
 	ssidref: int32;
 	handle: string;
 	flags: domain_create_flag list;
+	max_evtchn_port: int;
 	arch: arch_domainconfig;
 }
 
tools/ocaml/libs/xc/xenctrl.mli +1 -0
index d103a33..c0c724b 100644
@@ -55,6 +55,7 @@ type domctl_create_config = {
   ssidref: int32;
   handle: string;
   flags: domain_create_flag list;
+  max_evtchn_port: int;
   arch: arch_domainconfig;
 }
 
tools/ocaml/libs/xc/xenctrl_stubs.c +4 -1
index 1206eae..9c8457b 100644
@@ -128,12 +128,14 @@ CAMLprim value stub_xc_domain_create(value xch, value config)
 #define VAL_SSIDREF             Field(config, 0)
 #define VAL_HANDLE              Field(config, 1)
 #define VAL_FLAGS               Field(config, 2)
-#define VAL_ARCH                Field(config, 3)
+#define VAL_MAX_EVTCHN_PORT     Field(config, 3)
+#define VAL_ARCH                Field(config, 4)
 
 	uint32_t domid = 0;
 	int result;
 	struct xen_domctl_createdomain cfg = {
 		.ssidref = Int32_val(VAL_SSIDREF),
+		.max_evtchn_port = Int_val(VAL_MAX_EVTCHN_PORT),
 	};
 
 	domain_handle_of_uuid_string(cfg.handle, String_val(VAL_HANDLE));
@@ -169,6 +171,7 @@ CAMLprim value stub_xc_domain_create(value xch, value config)
 	}
 
 #undef VAL_ARCH
+#undef VAL_MAX_EVTCHN_PORT
 #undef VAL_FLAGS
 #undef VAL_HANDLE
 #undef VAL_SSIDREF
tools/python/xen/lowlevel/xc/xc.c +1 -0
index 5a2923a..4dc6d1c 100644
@@ -125,6 +125,7 @@ static PyObject *pyxc_domain_create(XcObject *self,
             0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
             0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
         },
+        .max_evtchn_port = -1, /* No limit. */
     };
 
     static char *kwd_list[] = { "domid", "ssidref", "handle", "flags", "target", NULL };
xen/common/domctl.c +3 -6
index c86dc21..3a68fc9 100644
@@ -540,6 +540,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             break;
         }
 
+        d->max_evtchn_port = min_t(unsigned int,
+                                   op->u.createdomain.max_evtchn_port, INT_MAX);
+
         ret = 0;
         op->domain = d->domain_id;
         copyback = 1;
@@ -1103,12 +1106,6 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
         ret = set_global_virq_handler(d, op->u.set_virq_handler.virq);
         break;
 
-    case XEN_DOMCTL_set_max_evtchn:
-        d->max_evtchn_port = min_t(unsigned int,
-                                   op->u.set_max_evtchn.max_port,
-                                   INT_MAX);
-        break;
-
     case XEN_DOMCTL_setvnumainfo:
     {
         struct vnuma_info *vnuma;
xen/include/public/domctl.h +8 -11
index 5c3916c..a945382 100644
@@ -65,6 +65,13 @@ struct xen_domctl_createdomain {
 #define _XEN_DOMCTL_CDF_xs_domain     4
 #define XEN_DOMCTL_CDF_xs_domain      (1U<<_XEN_DOMCTL_CDF_xs_domain)
     uint32_t flags;
+
+    /*
+     * Various domain limits, which impact the quantity of resources (global
+     * mapping space, xenheap, etc) a guest may consume.
+     */
+    uint32_t max_evtchn_port;
+
     struct xen_arch_domainconfig arch;
 };
 
@@ -875,15 +882,6 @@ struct xen_domctl_set_broken_page_p2m {
 };
 
 /*
- * XEN_DOMCTL_set_max_evtchn: sets the maximum event channel port
- * number the guest may use.  Use this limit the amount of resources
- * (global mapping space, xenheap) a guest may use for event channels.
- */
-struct xen_domctl_set_max_evtchn {
-    uint32_t max_port;
-};
-
-/*
  * ARM: Clean and invalidate caches associated with given region of
  * guest memory.
  */
@@ -1163,7 +1161,7 @@ struct xen_domctl {
 #define XEN_DOMCTL_set_broken_page_p2m           67
 #define XEN_DOMCTL_setnodeaffinity               68
 #define XEN_DOMCTL_getnodeaffinity               69
-#define XEN_DOMCTL_set_max_evtchn                70
+/* #define XEN_DOMCTL_set_max_evtchn             70 - Moved into XEN_DOMCTL_createdomain */
 #define XEN_DOMCTL_cacheflush                    71
 #define XEN_DOMCTL_get_vcpu_msrs                 72
 #define XEN_DOMCTL_set_vcpu_msrs                 73
@@ -1224,7 +1222,6 @@ struct xen_domctl {
         struct xen_domctl_set_access_required access_required;
         struct xen_domctl_audit_p2m         audit_p2m;
         struct xen_domctl_set_virq_handler  set_virq_handler;
-        struct xen_domctl_set_max_evtchn    set_max_evtchn;
         struct xen_domctl_gdbsx_memio       gdbsx_guest_memio;
         struct xen_domctl_set_broken_page_p2m set_broken_page_p2m;
         struct xen_domctl_cacheflush        cacheflush;
xen/xsm/flask/hooks.c +0 -3
index 7a3ccfa..a4fbe62 100644
@@ -728,9 +728,6 @@ static int flask_domctl(struct domain *d, int cmd)
     case XEN_DOMCTL_audit_p2m:
         return current_has_perm(d, SECCLASS_HVM, HVM__AUDIT_P2M);
 
-    case XEN_DOMCTL_set_max_evtchn:
-        return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SET_MAX_EVTCHN);
-
     case XEN_DOMCTL_cacheflush:
         return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__CACHEFLUSH);
 
xen/xsm/flask/policy/access_vectors +0 -2
index c5d8548..b768870 100644
@@ -222,8 +222,6 @@ class domain2
     setscheduler
 # XENMEM_claim_pages
     setclaim
-# XEN_DOMCTL_set_max_evtchn
-    set_max_evtchn
 # XEN_DOMCTL_cacheflush
     cacheflush
 # Creation of the hardware domain when it is not dom0
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 3/12
#4 lore raw

Re: [PATCH v2 03/12] xen/domctl: Merge set_max_evtchn into createdomain

Quoted 5 lines · Andrew Cooper

set_max_evtchn is somewhat weird. It was introduced with the event_fifo work, but has never been used. Still, it is a bounding on resources consumed by the event channel infrastructure, and should be part of createdomain, rather than editable after the fact.

Quoted 7 lines

Drop XEN_DOMCTL_set_max_evtchn completely (including XSM hooks and libxc wrappers), and retain the functionality in XEN_DOMCTL_createdomain.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

PATCH v2 4/12 xen/evtchn: Pass max_evtchn_port into evtchn_init()

In reply to Andrew Cooper

... rather than setting it up once domain_create() has completed. This involves constructing a default value for dom0.

No practical change in functionality.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/arch/arm/setup.c       | 4 +++-
 xen/arch/x86/setup.c       | 1 +
 xen/common/domain.c        | 2 +-
 xen/common/domctl.c        | 3 ---
 xen/common/event_channel.c | 4 ++--
 xen/include/xen/sched.h    | 2 +-
 6 files changed, 8 insertions(+), 8 deletions(-)
xen/arch/arm/setup.c +3 -1
index 7d40a84..45f3841 100644
@@ -691,7 +691,9 @@ void __init start_xen(unsigned long boot_phys_offset,
     const char *cmdline;
     struct bootmodule *xen_bootmodule;
     struct domain *dom0;
-    struct xen_domctl_createdomain dom0_cfg = {};
+    struct xen_domctl_createdomain dom0_cfg = {
+        .max_evtchn_port = -1,
+    };
 
     dcache_line_bytes = read_dcache_line_bytes();
 
xen/arch/x86/setup.c +1 -0
index 8301de8..015099f 100644
@@ -681,6 +681,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     };
     struct xen_domctl_createdomain dom0_cfg = {
         .flags = XEN_DOMCTL_CDF_s3_integrity,
+        .max_evtchn_port = -1,
     };
 
     /* Critical region without IDT or TSS.  Any fault is deadly! */
xen/common/domain.c +1 -1
index 749722b..171d25e 100644
@@ -362,7 +362,7 @@ struct domain *domain_create(domid_t domid,
 
         radix_tree_init(&d->pirq_tree);
 
-        if ( (err = evtchn_init(d)) != 0 )
+        if ( (err = evtchn_init(d, config->max_evtchn_port)) != 0 )
             goto fail;
         init_status |= INIT_evtchn;
 
xen/common/domctl.c +0 -3
index 3a68fc9..0ef554a 100644
@@ -540,9 +540,6 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             break;
         }
 
-        d->max_evtchn_port = min_t(unsigned int,
-                                   op->u.createdomain.max_evtchn_port, INT_MAX);
-
         ret = 0;
         op->domain = d->domain_id;
         copyback = 1;
xen/common/event_channel.c +2 -2
index c620465..41cbbae 100644
@@ -1284,10 +1284,10 @@ void evtchn_check_pollers(struct domain *d, unsigned int port)
     }
 }
 
-int evtchn_init(struct domain *d)
+int evtchn_init(struct domain *d, unsigned int max_port)
 {
     evtchn_2l_init(d);
-    d->max_evtchn_port = INT_MAX;
+    d->max_evtchn_port = min_t(unsigned int, max_port, INT_MAX);
 
     d->evtchn = alloc_evtchn_bucket(d, 0);
     if ( !d->evtchn )
xen/include/xen/sched.h +1 -1
index 3c35473..51ceebe 100644
@@ -134,7 +134,7 @@ struct evtchn
 #endif
 } __attribute__((aligned(64)));
 
-int  evtchn_init(struct domain *d); /* from domain_create */
+int  evtchn_init(struct domain *d, unsigned int max_port);
 void evtchn_destroy(struct domain *d); /* from domain_kill */
 void evtchn_destroy_final(struct domain *d); /* from complete_domain_destroy */
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 4/12
#6 lore raw

Re: [PATCH v2 04/12] xen/evtchn: Pass max_evtchn_port into evtchn_init()

Quoted 6 lines · Andrew Cooper

... rather than setting it up once domain_create() has completed. This involves constructing a default value for dom0.

No practical change in functionality.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v2 4/12
#7 lore raw

Re: [PATCH v2 04/12] xen/evtchn: Pass max_evtchn_port into evtchn_init()

In reply to Andrew Cooper
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.08.18 at 12:01, <[email protected]> wrote:

... rather than setting it up once domain_create() has completed. This involves constructing a default value for dom0.

No practical change in functionality.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v2 4/12
#8 lore raw

Re: [PATCH v2 04/12] xen/evtchn: Pass max_evtchn_port into evtchn_init()

In reply to Andrew Cooper

Hi Andrew,

Quoted 6 lines · Andrew Cooper

... rather than setting it up once domain_create() has completed. This involves constructing a default value for dom0.

No practical change in functionality.

For the Arm bits:

Cheers,

Quoted 99 lines

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

---
  xen/arch/arm/setup.c       | 4 +++-
  xen/arch/x86/setup.c       | 1 +
  xen/common/domain.c        | 2 +-
  xen/common/domctl.c        | 3 ---
  xen/common/event_channel.c | 4 ++--
  xen/include/xen/sched.h    | 2 +-
  6 files changed, 8 insertions(+), 8 deletions(-)
xen/arch/arm/setup.c +3 -1
index 7d40a84..45f3841 100644
@@ -691,7 +691,9 @@ void __init start_xen(unsigned long boot_phys_offset,
      const char *cmdline;
      struct bootmodule *xen_bootmodule;
      struct domain *dom0;
-    struct xen_domctl_createdomain dom0_cfg = {};
+    struct xen_domctl_createdomain dom0_cfg = {
+        .max_evtchn_port = -1,
+    };
 
      dcache_line_bytes = read_dcache_line_bytes();
 
xen/arch/x86/setup.c +1 -0
index 8301de8..015099f 100644
@@ -681,6 +681,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      };
      struct xen_domctl_createdomain dom0_cfg = {
          .flags = XEN_DOMCTL_CDF_s3_integrity,
+        .max_evtchn_port = -1,
      };
 
      /* Critical region without IDT or TSS.  Any fault is deadly! */
xen/common/domain.c +1 -1
index 749722b..171d25e 100644
@@ -362,7 +362,7 @@ struct domain *domain_create(domid_t domid,
 
          radix_tree_init(&d->pirq_tree);
 
-        if ( (err = evtchn_init(d)) != 0 )
+        if ( (err = evtchn_init(d, config->max_evtchn_port)) != 0 )
              goto fail;
          init_status |= INIT_evtchn;
 
xen/common/domctl.c +0 -3
index 3a68fc9..0ef554a 100644
@@ -540,9 +540,6 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
              break;
          }
 
-        d->max_evtchn_port = min_t(unsigned int,
-                                   op->u.createdomain.max_evtchn_port, INT_MAX);
-
          ret = 0;
          op->domain = d->domain_id;
          copyback = 1;
xen/common/event_channel.c +2 -2
index c620465..41cbbae 100644
@@ -1284,10 +1284,10 @@ void evtchn_check_pollers(struct domain *d, unsigned int port)
      }
  }
 
-int evtchn_init(struct domain *d)
+int evtchn_init(struct domain *d, unsigned int max_port)
  {
      evtchn_2l_init(d);
-    d->max_evtchn_port = INT_MAX;
+    d->max_evtchn_port = min_t(unsigned int, max_port, INT_MAX);
 
      d->evtchn = alloc_evtchn_bucket(d, 0);
      if ( !d->evtchn )
xen/include/xen/sched.h +1 -1
index 3c35473..51ceebe 100644
@@ -134,7 +134,7 @@ struct evtchn
  #endif
  } __attribute__((aligned(64)));
 
-int  evtchn_init(struct domain *d); /* from domain_create */
+int  evtchn_init(struct domain *d, unsigned int max_port);
  void evtchn_destroy(struct domain *d); /* from domain_kill */
  void evtchn_destroy_final(struct domain *d); /* from complete_domain_destroy */
 
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#9 lore raw

PATCH v2 5/12 tools: Pass grant table limits to XEN_DOMCTL_set_gnttab_limits

In reply to Andrew Cooper

XEN_DOMCTL_set_gnttab_limits is a fairly new hypercall, and is strictly mandatory. As it pertains to domain limits, it should be provided at createdomain time.

In preparation to remove the hypercall, extend xen_domctl_createdomain with the fields and arrange for all callers to pass appropriate details. There is no change in construction behaviour yet, but later patches will rearrange the hypervisor internals, then delete the hypercall.

---
CC: Marek Marczykowski-Górecki <[email protected]>

v2:
* Split out of previous v1 patch to avoid the post-domain-create error path. Retain appropriate acks.
* Use int rather than int32 in the ocaml stubs.

---
 tools/helpers/init-xenstore-domain.c | 16 ++++++++++------
 tools/libxl/libxl_create.c           |  2 ++
 tools/ocaml/libs/xc/xenctrl.ml       |  2 ++
 tools/ocaml/libs/xc/xenctrl.mli      |  2 ++
 tools/ocaml/libs/xc/xenctrl_stubs.c  |  8 +++++++-
 tools/python/xen/lowlevel/xc/xc.c    |  2 ++
 xen/include/public/domctl.h          |  2 ++
 7 files changed, 27 insertions(+), 7 deletions(-)
tools/helpers/init-xenstore-domain.c +10 -6
index 89c329c..cd27edc 100644
@@ -67,6 +67,14 @@ static int build(xc_interface *xch)
         .ssidref = SECINITSID_DOMU,
         .flags = XEN_DOMCTL_CDF_xs_domain,
         .max_evtchn_port = -1, /* No limit. */
+
+        /*
+         * 1 grant frame is enough: we don't need many grants.
+         * Mini-OS doesn't like less than 4, though, so use 4.
+         * 128 maptrack frames: 256 entries per frame, enough for 32768 domains.
+         */
+        .max_grant_frames = 4,
+        .max_maptrack_frames = 128,
     };
 
     xs_fd = open("/dev/xen/xenbus_backend", O_RDWR);
@@ -104,12 +112,8 @@ static int build(xc_interface *xch)
         fprintf(stderr, "xc_domain_setmaxmem failed\n");
         goto err;
     }
-    /*
-     * 1 grant frame is enough: we don't need many grants.
-     * Mini-OS doesn't like less than 4, though, so use 4.
-     * 128 maptrack frames: 256 entries per frame, enough for 32768 domains.
-     */
-    rv = xc_domain_set_gnttab_limits(xch, domid, 4, 128);
+    rv = xc_domain_set_gnttab_limits(xch, domid, config.max_grant_frames,
+                                     config.max_maptrack_frames);
     if ( rv )
     {
         fprintf(stderr, "xc_domain_set_gnttab_limits failed\n");
tools/libxl/libxl_create.c +2 -0
index b7b44e2..8b755e4 100644
@@ -567,6 +567,8 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
         struct xen_domctl_createdomain create = {
             .ssidref = info->ssidref,
             .max_evtchn_port = b_info->event_channels,
+            .max_grant_frames = b_info->max_grant_frames,
+            .max_maptrack_frames = b_info->max_maptrack_frames,
         };
 
         if (info->type != LIBXL_DOMAIN_TYPE_PV) {
tools/ocaml/libs/xc/xenctrl.ml +2 -0
index 219355a..42f45c4 100644
@@ -64,6 +64,8 @@ type domctl_create_config =
 	handle: string;
 	flags: domain_create_flag list;
 	max_evtchn_port: int;
+	max_grant_frames: int;
+	max_maptrack_frames: int;
 	arch: arch_domainconfig;
 }
 
tools/ocaml/libs/xc/xenctrl.mli +2 -0
index c0c724b..0db5816 100644
@@ -56,6 +56,8 @@ type domctl_create_config = {
   handle: string;
   flags: domain_create_flag list;
   max_evtchn_port: int;
+  max_grant_frames: int;
+  max_maptrack_frames: int;
   arch: arch_domainconfig;
 }
 
tools/ocaml/libs/xc/xenctrl_stubs.c +7 -1
index 9c8457b..a9759e0 100644
@@ -129,13 +129,17 @@ CAMLprim value stub_xc_domain_create(value xch, value config)
 #define VAL_HANDLE              Field(config, 1)
 #define VAL_FLAGS               Field(config, 2)
 #define VAL_MAX_EVTCHN_PORT     Field(config, 3)
-#define VAL_ARCH                Field(config, 4)
+#define VAL_MAX_GRANT_FRAMES    Field(config, 4)
+#define VAL_MAX_MAPTRACK_FRAMES Field(config, 5)
+#define VAL_ARCH                Field(config, 6)
 
 	uint32_t domid = 0;
 	int result;
 	struct xen_domctl_createdomain cfg = {
 		.ssidref = Int32_val(VAL_SSIDREF),
 		.max_evtchn_port = Int_val(VAL_MAX_EVTCHN_PORT),
+		.max_grant_frames = Int_val(VAL_MAX_GRANT_FRAMES),
+		.max_maptrack_frames = Int_val(VAL_MAX_MAPTRACK_FRAMES),
 	};
 
 	domain_handle_of_uuid_string(cfg.handle, String_val(VAL_HANDLE));
@@ -171,6 +175,8 @@ CAMLprim value stub_xc_domain_create(value xch, value config)
 	}
 
 #undef VAL_ARCH
+#undef VAL_MAX_MAPTRACK_FRAMES
+#undef VAL_MAX_GRANT_FRAMES
 #undef VAL_MAX_EVTCHN_PORT
 #undef VAL_FLAGS
 #undef VAL_HANDLE
tools/python/xen/lowlevel/xc/xc.c +2 -0
index 4dc6d1c..6bd58ec 100644
@@ -126,6 +126,8 @@ static PyObject *pyxc_domain_create(XcObject *self,
             0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
         },
         .max_evtchn_port = -1, /* No limit. */
+        .max_grant_frames = 32,
+        .max_maptrack_frames = 1024,
     };
 
     static char *kwd_list[] = { "domid", "ssidref", "handle", "flags", "target", NULL };
xen/include/public/domctl.h +2 -0
index a945382..676e686 100644
@@ -71,6 +71,8 @@ struct xen_domctl_createdomain {
      * mapping space, xenheap, etc) a guest may consume.
      */
     uint32_t max_evtchn_port;
+    uint32_t max_grant_frames;
+    uint32_t max_maptrack_frames;
 
     struct xen_arch_domainconfig arch;
 };
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#10 lore raw

PATCH v2 6/12 xen/gnttab: Pass max_{grant, maptrack}_frames into grant_table_create()

In reply to Andrew Cooper

... rather than setting the limits up after domain_create() has completed.

This removes all the gnttab infrastructure for calculating the number of dom0 grant frames, opting instead to require the dom0 construction code to pass a sane value in via the configuration.

In practice, this now means that there is never a partially constructed grant table for a reference-able domain.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

v2:
* Split/rearrange to avoid the post-domain-create error path.

---
 xen/arch/arm/domain_build.c       |  3 ++-
 xen/arch/arm/setup.c              | 12 ++++++++++++
 xen/arch/x86/setup.c              |  3 +++
 xen/common/domain.c               |  3 ++-
 xen/common/grant_table.c          | 16 +++-------------
 xen/include/asm-arm/grant_table.h | 12 ------------
 xen/include/asm-x86/grant_table.h |  5 -----
 xen/include/xen/grant_table.h     |  6 ++----
 8 files changed, 24 insertions(+), 36 deletions(-)
xen/arch/arm/domain_build.c +2 -1
index 1351572..737e0f3 100644
@@ -2079,7 +2079,8 @@ static void __init find_gnttab_region(struct domain *d,
      * enough space for a large grant table
      */
     kinfo->gnttab_start = __pa(_stext);
-    kinfo->gnttab_size = gnttab_dom0_frames() << PAGE_SHIFT;
+    kinfo->gnttab_size = min_t(unsigned int, opt_max_grant_frames,
+                               PFN_DOWN(_etext - _stext)) << PAGE_SHIFT;
 
 #ifdef CONFIG_ARM_32
     /*
xen/arch/arm/setup.c +12 -0
index 45f3841..3d3b30c 100644
@@ -20,6 +20,7 @@
 #include <xen/compile.h>
 #include <xen/device_tree.h>
 #include <xen/domain_page.h>
+#include <xen/grant_table.h>
 #include <xen/types.h>
 #include <xen/string.h>
 #include <xen/serial.h>
@@ -693,6 +694,17 @@ void __init start_xen(unsigned long boot_phys_offset,
     struct domain *dom0;
     struct xen_domctl_createdomain dom0_cfg = {
         .max_evtchn_port = -1,
+
+        /*
+         * The region used by Xen on the memory will never be mapped in DOM0
+         * memory layout. Therefore it can be used for the grant table.
+         *
+         * Only use the text section as it's always present and will contain
+         * enough space for a large grant table
+         */
+        .max_grant_frames = min_t(unsigned int, opt_max_grant_frames,
+                                  PFN_DOWN(_etext - _stext)),
+        .max_maptrack_frames = opt_max_maptrack_frames,
     };
 
     dcache_line_bytes = read_dcache_line_bytes();
xen/arch/x86/setup.c +3 -0
index 015099f..2cfae89 100644
@@ -1,6 +1,7 @@
 #include <xen/init.h>
 #include <xen/lib.h>
 #include <xen/err.h>
+#include <xen/grant_table.h>
 #include <xen/sched.h>
 #include <xen/sched-if.h>
 #include <xen/domain.h>
@@ -682,6 +683,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     struct xen_domctl_createdomain dom0_cfg = {
         .flags = XEN_DOMCTL_CDF_s3_integrity,
         .max_evtchn_port = -1,
+        .max_grant_frames = opt_max_grant_frames,
+        .max_maptrack_frames = opt_max_maptrack_frames,
     };
 
     /* Critical region without IDT or TSS.  Any fault is deadly! */
xen/common/domain.c +2 -1
index 171d25e..1dcab8d 100644
@@ -366,7 +366,8 @@ struct domain *domain_create(domid_t domid,
             goto fail;
         init_status |= INIT_evtchn;
 
-        if ( (err = grant_table_create(d)) != 0 )
+        if ( (err = grant_table_create(d, config->max_grant_frames,
+                                       config->max_maptrack_frames)) != 0 )
             goto fail;
         init_status |= INIT_gnttab;
 
xen/common/grant_table.c +3 -13
index 8b843b1..3200542 100644
@@ -3563,9 +3563,8 @@ do_grant_table_op(
 #include "compat/grant_table.c"
 #endif
 
-int
-grant_table_create(
-    struct domain *d)
+int grant_table_create(struct domain *d, unsigned int max_grant_frames,
+                       unsigned int max_maptrack_frames)
 {
     struct grant_table *t;
     int ret = 0;
@@ -3583,11 +3582,7 @@ grant_table_create(
     t->domain = d;
     d->grant_table = t;
 
-    if ( d->domain_id == 0 )
-    {
-        ret = grant_table_init(d, t, gnttab_dom0_frames(),
-                               opt_max_maptrack_frames);
-    }
+    ret = grant_table_set_limits(d, max_maptrack_frames, max_maptrack_frames);
 
     return ret;
 }
@@ -4045,11 +4040,6 @@ static int __init gnttab_usage_init(void)
 }
 __initcall(gnttab_usage_init);
 
-unsigned int __init gnttab_dom0_frames(void)
-{
-    return min(opt_max_grant_frames, gnttab_dom0_max());
-}
-
 /*
  * Local variables:
  * mode: C
xen/include/asm-arm/grant_table.h +0 -12
index 9c2c815..ee11c38 100644
@@ -23,18 +23,6 @@ void gnttab_mark_dirty(struct domain *d, mfn_t mfn);
 #define gnttab_create_status_page(d, t, i) do {} while (0)
 #define gnttab_release_host_mappings(domain) 1
 
-/*
- * The region used by Xen on the memory will never be mapped in DOM0
- * memory layout. Therefore it can be used for the grant table.
- *
- * Only use the text section as it's always present and will contain
- * enough space for a large grant table
- */
-static inline unsigned int gnttab_dom0_max(void)
-{
-    return PFN_DOWN(_etext - _stext);
-}
-
 #define gnttab_init_arch(gt)                                             \
 ({                                                                       \
     unsigned int ngf_ = (gt)->max_grant_frames;                          \
xen/include/asm-x86/grant_table.h +0 -5
index 76ec5dd..761a8c3 100644
@@ -39,11 +39,6 @@ static inline int replace_grant_host_mapping(uint64_t addr, mfn_t frame,
     return replace_grant_pv_mapping(addr, frame, new_addr, flags);
 }
 
-static inline unsigned int gnttab_dom0_max(void)
-{
-    return UINT_MAX;
-}
-
 #define gnttab_init_arch(gt) 0
 #define gnttab_destroy_arch(gt) do {} while ( 0 )
 #define gnttab_set_frame_gfn(gt, st, idx, gfn) do {} while ( 0 )
xen/include/xen/grant_table.h +2 -4
index c881414..b46bb0a 100644
@@ -35,8 +35,8 @@ extern unsigned int opt_max_grant_frames;
 extern unsigned int opt_max_maptrack_frames;
 
 /* Create/destroy per-domain grant table context. */
-int grant_table_create(
-    struct domain *d);
+int grant_table_create(struct domain *d, unsigned int max_grant_frames,
+                       unsigned int max_maptrack_frames);
 void grant_table_destroy(
     struct domain *d);
 void grant_table_init_vcpu(struct vcpu *v);
@@ -63,6 +63,4 @@ int gnttab_get_shared_frame(struct domain *d, unsigned long idx,
 int gnttab_get_status_frame(struct domain *d, unsigned long idx,
                             mfn_t *mfn);
 
-unsigned int gnttab_dom0_frames(void);
-
 #endif /* __XEN_GRANT_TABLE_H__ */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 6/12
#11 lore raw

Re: [PATCH v2 06/12] xen/gnttab: Pass max_{grant, maptrack}_frames into grant_table_create()

Quoted 59 lines · Andrew Cooper

... rather than setting the limits up after domain_create() has completed.

This removes all the gnttab infrastructure for calculating the number of dom0 grant frames, opting instead to require the dom0 construction code to pass a sane value in via the configuration.

In practice, this now means that there is never a partially constructed grant table for a reference-able domain.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

v2:
* Split/rearrange to avoid the post-domain-create error path.

---
 xen/arch/arm/domain_build.c       |  3 ++-
 xen/arch/arm/setup.c              | 12 ++++++++++++
 xen/arch/x86/setup.c              |  3 +++
 xen/common/domain.c               |  3 ++-
 xen/common/grant_table.c          | 16 +++-------------
 xen/include/asm-arm/grant_table.h | 12 ------------
 xen/include/asm-x86/grant_table.h |  5 -----
 xen/include/xen/grant_table.h     |  6 ++----
 8 files changed, 24 insertions(+), 36 deletions(-)
xen/arch/arm/domain_build.c +2 -1
index 1351572..737e0f3 100644
@@ -2079,7 +2079,8 @@ static void __init find_gnttab_region(struct domain *d,
      * enough space for a large grant table
      */
     kinfo->gnttab_start = __pa(_stext);
-    kinfo->gnttab_size = gnttab_dom0_frames() << PAGE_SHIFT;
+    kinfo->gnttab_size = min_t(unsigned int, opt_max_grant_frames,
+                               PFN_DOWN(_etext - _stext)) << PAGE_SHIFT;
 
 #ifdef CONFIG_ARM_32
     /*
xen/arch/arm/setup.c +1 -0
index 45f3841..3d3b30c 100644
@@ -20,6 +20,7 @@
 #include <xen/compile.h>
 #include <xen/device_tree.h>
 #include <xen/domain_page.h>
+#include <xen/grant_table.h>
 #include <xen/types.h>
 #include <xen/string.h>
 #include <xen/serial.h>
@@ -693,6 +694,17 @@ void __init start_xen(unsigned long boot_phys_offset,
     struct domain *dom0;
     struct xen_domctl_createdomain dom0_cfg = {
         .max_evtchn_port = -1,

xen/arch/arm/setup.c void __init start_xen(unsigned long boot_phys_offset, · line 706

Quoted 10 lines
xen/arch/arm/setup.c +10 -0
+
+        /*
+         * The region used by Xen on the memory will never be mapped in DOM0
+         * memory layout. Therefore it can be used for the grant table.
+         *
+         * Only use the text section as it's always present and will contain
+         * enough space for a large grant table
+         */
+        .max_grant_frames = min_t(unsigned int, opt_max_grant_frames,
+                                  PFN_DOWN(_etext - _stext)),

You have this calculation here and in the chunk above. Maybe you want to keep gnttab_dom0_max (or something similar with the min included) in order to avoid open coding this calculation twice?

The rest LGTM:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v2 6/12
#12 lore raw

Re: [PATCH v2 06/12] xen/gnttab: Pass max_{grant, maptrack}_frames into grant_table_create()

In reply to Andrew Cooper
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 13.08.18 at 12:01, <[email protected]> wrote:

... rather than setting the limits up after domain_create() has completed.

This removes all the gnttab infrastructure for calculating the number of dom0 grant frames, opting instead to require the dom0 construction code to pass a sane value in via the configuration.

In practice, this now means that there is never a partially constructed grant table for a reference-able domain.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#13 lore raw

Re: [PATCH v2 06/12] xen/gnttab: Pass max_{grant, maptrack}_frames into grant_table_create()

In reply to Andrew Cooper

Hi Andrew,

Quoted 34 lines · Andrew Cooper

... rather than setting the limits up after domain_create() has completed.

This removes all the gnttab infrastructure for calculating the number of dom0 grant frames, opting instead to require the dom0 construction code to pass a sane value in via the configuration.

In practice, this now means that there is never a partially constructed grant table for a reference-able domain.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

v2:
* Split/rearrange to avoid the post-domain-create error path.

---
  xen/arch/arm/domain_build.c       |  3 ++-
  xen/arch/arm/setup.c              | 12 ++++++++++++
  xen/arch/x86/setup.c              |  3 +++
  xen/common/domain.c               |  3 ++-
  xen/common/grant_table.c          | 16 +++-------------
  xen/include/asm-arm/grant_table.h | 12 ------------
  xen/include/asm-x86/grant_table.h |  5 -----
  xen/include/xen/grant_table.h     |  6 ++----
  8 files changed, 24 insertions(+), 36 deletions(-)
xen/arch/arm/domain_build.c +0 -0
index 1351572..737e0f3 100644

xen/arch/arm/domain_build.c static void __init find_gnttab_region(struct domain *d, · line 2083

Quoted 6 lines
xen/arch/arm/domain_build.c +2 -1
@@ -2079,7 +2079,8 @@ static void __init find_gnttab_region(struct domain *d,
       * enough space for a large grant table
       */
      kinfo->gnttab_start = __pa(_stext);
-    kinfo->gnttab_size = gnttab_dom0_frames() << PAGE_SHIFT;
+    kinfo->gnttab_size = min_t(unsigned int, opt_max_grant_frames,
+                               PFN_DOWN(_etext - _stext)) << PAGE_SHIFT;

I agree with Jan's comment on v1 that there is a risk someone will update the size here but ...

Quoted 19 lines
xen/arch/arm/domain_build.c +0 -0
  #ifdef CONFIG_ARM_32
      /*
xen/arch/arm/setup.c +1 -0
index 45f3841..3d3b30c 100644
@@ -20,6 +20,7 @@
  #include <xen/compile.h>
  #include <xen/device_tree.h>
  #include <xen/domain_page.h>
+#include <xen/grant_table.h>
  #include <xen/types.h>
  #include <xen/string.h>
  #include <xen/serial.h>
@@ -693,6 +694,17 @@ void __init start_xen(unsigned long boot_phys_offset,
      struct domain *dom0;
      struct xen_domctl_createdomain dom0_cfg = {
          .max_evtchn_port = -1,

xen/arch/arm/setup.c void __init start_xen(unsigned long boot_phys_offset, · line 706

Quoted 10 lines
xen/arch/arm/setup.c +10 -0
+
+        /*
+         * The region used by Xen on the memory will never be mapped in DOM0
+         * memory layout. Therefore it can be used for the grant table.
+         *
+         * Only use the text section as it's always present and will contain
+         * enough space for a large grant table
+         */
+        .max_grant_frames = min_t(unsigned int, opt_max_grant_frames,
+                                  PFN_DOWN(_etext - _stext)),

... not here. So I would prefer if we either keep an helper to find the size of pass that size around to domain_build. Do we store the size in the domain information?

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#14 lore raw

Re: [PATCH v2 06/12] xen/gnttab: Pass max_{grant, maptrack}_frames into grant_table_create()

Quoted 82 lines · Julien Grall

Hi Andrew,

Quoted 38 lines · Andrew Cooper

... rather than setting the limits up after domain_create() has completed.

This removes all the gnttab infrastructure for calculating the number of dom0
grant frames, opting instead to require the dom0 construction code to pass a
sane value in via the configuration.

In practice, this now means that there is never a partially constructed grant
table for a reference-able domain.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

v2:
  * Split/rearrange to avoid the post-domain-create error path.
---
  xen/arch/arm/domain_build.c       |  3 ++- xen/arch/arm/setup.c              | 12 ++++++++++++ xen/arch/x86/setup.c              |  3 +++ xen/common/domain.c               |  3 ++- xen/common/grant_table.c          | 16 +++------------- xen/include/asm-arm/grant_table.h | 12 ------------ xen/include/asm-x86/grant_table.h |  5 ----- xen/include/xen/grant_table.h     |  6 ++----

  8 files changed, 24 insertions(+), 36 deletions(-)
xen/arch/arm/domain_build.c +0 -0
index 1351572..737e0f3 100644

xen/arch/arm/domain_build.c static void __init find_gnttab_region(struct · line 2085

Quoted 8 lines
xen/arch/arm/domain_build.c +2 -1
@@ -2079,7 +2079,8 @@ static void __init find_gnttab_region(struct
 domain *d,
        * enough space for a large grant table
        */
       kinfo->gnttab_start = __pa(_stext);
-    kinfo->gnttab_size = gnttab_dom0_frames() << PAGE_SHIFT;
+    kinfo->gnttab_size = min_t(unsigned int, opt_max_grant_frames,
+                               PFN_DOWN(_etext - _stext)) <<
 PAGE_SHIFT;

I agree with Jan's comment on v1 that there is a risk someone will update the size here but ...

Quoted 27 lines
xen/arch/arm/domain_build.c +0 -0
     #ifdef CONFIG_ARM_32

      /*

xen/arch/arm/setup.c +4 -0
index 45f3841..3d3b30c 100644
@@ -20,6 +20,7 @@
   #include <xen/compile.h>
   #include <xen/device_tree.h>
   #include <xen/domain_page.h>
+#include <xen/grant_table.h>
   #include <xen/types.h>
   #include <xen/string.h>
   #include <xen/serial.h>
@@ -693,6 +694,17 @@ void __init start_xen(unsigned long
 boot_phys_offset,
       struct domain *dom0;
       struct xen_domctl_createdomain dom0_cfg = {
           .max_evtchn_port = -1,
+
+        /*
+         * The region used by Xen on the memory will never be mapped

in DOM0
+         * memory layout. Therefore it can be used for the grant table. +         *
+         * Only use the text section as it's always present and will contain

Quoted 8 lines
Quoted 4 lines

+         * enough space for a large grant table
+         */
+        .max_grant_frames = min_t(unsigned int, opt_max_grant_frames, +                                  PFN_DOWN(_etext - _stext)),

... not here. So I would prefer if we either keep an helper to find the size of pass that size around to domain_build. Do we store the size in the domain information?

I have to admit that I'm somewhat perplexed by ARM's find_gnttab_region(), and I'm not sure why it exists.

The value is available from d->grant_table.max_grant_frames but ISTR finding that the order of construction meant that it wasn't available when needed (although this was all from code inspection, so I could very easily be wrong).

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#15 lore raw

Re: [PATCH v2 06/12] xen/gnttab: Pass max_{grant, maptrack}_frames into grant_table_create()

Hi Andrew,

Quoted 92 lines · Andrew Cooper
Quoted 82 lines · Julien Grall

Hi Andrew,

Quoted 38 lines · Andrew Cooper

... rather than setting the limits up after domain_create() has completed.

This removes all the gnttab infrastructure for calculating the number of dom0
grant frames, opting instead to require the dom0 construction code to pass a
sane value in via the configuration.

In practice, this now means that there is never a partially constructed grant
table for a reference-able domain.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

v2:
  * Split/rearrange to avoid the post-domain-create error path.

---
   xen/arch/arm/domain_build.c       |  3 ++-
   xen/arch/arm/setup.c              | 12 ++++++++++++
   xen/arch/x86/setup.c              |  3 +++
   xen/common/domain.c               |  3 ++-
   xen/common/grant_table.c          | 16 +++-------------
   xen/include/asm-arm/grant_table.h | 12 ------------
   xen/include/asm-x86/grant_table.h |  5 -----
   xen/include/xen/grant_table.h     |  6 ++----
   8 files changed, 24 insertions(+), 36 deletions(-)
xen/arch/arm/domain_build.c +0 -0
index 1351572..737e0f3 100644

xen/arch/arm/domain_build.c static void __init find_gnttab_region(struct · line 2085

Quoted 8 lines
xen/arch/arm/domain_build.c +2 -1
@@ -2079,7 +2079,8 @@ static void __init find_gnttab_region(struct
 domain *d,
        * enough space for a large grant table
        */
       kinfo->gnttab_start = __pa(_stext);
-    kinfo->gnttab_size = gnttab_dom0_frames() << PAGE_SHIFT;
+    kinfo->gnttab_size = min_t(unsigned int, opt_max_grant_frames,
+                               PFN_DOWN(_etext - _stext)) <<
 PAGE_SHIFT;

I agree with Jan's comment on v1 that there is a risk someone will update the size here but ...

Quoted 27 lines
xen/arch/arm/domain_build.c +0 -0
     #ifdef CONFIG_ARM_32

      /*

xen/arch/arm/setup.c +4 -0
index 45f3841..3d3b30c 100644
@@ -20,6 +20,7 @@
   #include <xen/compile.h>
   #include <xen/device_tree.h>
   #include <xen/domain_page.h>
+#include <xen/grant_table.h>
   #include <xen/types.h>
   #include <xen/string.h>
   #include <xen/serial.h>
@@ -693,6 +694,17 @@ void __init start_xen(unsigned long
 boot_phys_offset,
       struct domain *dom0;
       struct xen_domctl_createdomain dom0_cfg = {
           .max_evtchn_port = -1,
+
+        /*
+         * The region used by Xen on the memory will never be mapped

in DOM0
+         * memory layout. Therefore it can be used for the grant table. +         *
+         * Only use the text section as it's always present and will contain

Quoted 8 lines
Quoted 4 lines

+         * enough space for a large grant table
+         */
+        .max_grant_frames = min_t(unsigned int, opt_max_grant_frames, +                                  PFN_DOWN(_etext - _stext)),

... not here. So I would prefer if we either keep an helper to find the size of pass that size around to domain_build. Do we store the size in the domain information?

Quoted 2 lines

I have to admit that I'm somewhat perplexed by ARM's find_gnttab_region(), and I'm not sure why it exists.

Dom0 is using the host memory layout that may differ between platforms. So there is not a region address that would fit everyone.

This function is here to find at boot a suitable region in the layout where the OS can map the grant-table. The result will be written in the firmware table.

Quoted 5 lines

The value is available from d->grant_table.max_grant_frames but ISTR finding that the order of construction meant that it wasn't available when needed (although this was all from code inspection, so I could very easily be wrong).

I think it should be fine for Dom0 as find_gnttab_region is called from construct_dom0 and d->grant_table.max_grant_frames would be set before via domain_create().

Assuming d->grant_table.max_grant_frames can only be 0 before initialization, I would potentially add a BUG_ON(!d->grant_table.max_grant_frames) to make sure this always stay like that.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#16 lore raw

Re: [PATCH v2 06/12] xen/gnttab: Pass max_{grant, maptrack}_frames into grant_table_create()

Quoted 54 lines · Julien Grall

Hi Andrew,

Quoted 37 lines
Quoted 28 lines
Quoted 28 lines

     #ifdef CONFIG_ARM_32
       /*

xen/arch/arm/setup.c +4 -0
index 45f3841..3d3b30c 100644
@@ -20,6 +20,7 @@
    #include <xen/compile.h>
    #include <xen/device_tree.h>
    #include <xen/domain_page.h>
+#include <xen/grant_table.h>
    #include <xen/types.h>
    #include <xen/string.h>
    #include <xen/serial.h>
@@ -693,6 +694,17 @@ void __init start_xen(unsigned long
 boot_phys_offset,
        struct domain *dom0;
        struct xen_domctl_createdomain dom0_cfg = {
            .max_evtchn_port = -1,
+
+        /*
+         * The region used by Xen on the memory will never be mapped

in DOM0
+         * memory layout. Therefore it can be used for the grant table.
+         *
+         * Only use the text section as it's always present and will contain

Quoted 8 lines
Quoted 4 lines

+         * enough space for a large grant table
+         */
+        .max_grant_frames = min_t(unsigned int, opt_max_grant_frames, +                                  PFN_DOWN(_etext - _stext)),

... not here. So I would prefer if we either keep an helper to find the size of pass that size around to domain_build. Do we store the size in the domain information?

Quoted 2 lines

I have to admit that I'm somewhat perplexed by ARM's find_gnttab_region(), and I'm not sure why it exists.

Dom0 is using the host memory layout that may differ between platforms. So there is not a region address that would fit everyone.

This function is here to find at boot a suitable region in the layout where the OS can map the grant-table. The result will be written in the firmware table.

Quoted 5 lines

The value is available from d->grant_table.max_grant_frames but ISTR finding that the order of construction meant that it wasn't available when needed (although this was all from code inspection, so I could very easily be wrong).

Quoted 8 lines

I think it should be fine for Dom0 as find_gnttab_region is called from construct_dom0 and d->grant_table.max_grant_frames would be set before via domain_create().

Assuming d->grant_table.max_grant_frames can only be 0 before initialization, I would potentially add a BUG_ON(!d->grant_table.max_grant_frames) to make sure this always stay like that.

Actually, I remember now what the problem was.  d->grant_table is an opaque type, so .max_grant_frames can't be accessed.

One of my indented bits of cleanup here is to remove the gnttab_dom0_frames() function, because it has no business living in the core grant_table.c

Would you be happy if I replaced gnttab_dom0_max() in asm-arm with gnttab_dom0_frames() which accounts for the exiting min(), and means that domain_build.c will be ultimately unchanged?

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#17 lore raw

Re: [PATCH v2 06/12] xen/gnttab: Pass max_{grant, maptrack}_frames into grant_table_create()

Hi Andrew,

Quoted 10 lines · Andrew Cooper

Actually, I remember now what the problem was.  d->grant_table is an opaque type, so .max_grant_frames can't be accessed.

One of my indented bits of cleanup here is to remove the gnttab_dom0_frames() function, because it has no business living in the core grant_table.c

Would you be happy if I replaced gnttab_dom0_max() in asm-arm with gnttab_dom0_frames() which accounts for the exiting min(), and means that domain_build.c will be ultimately unchanged?

I would be happy with such change.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#18 lore raw

PATCH v3 6/12 xen/gnttab: Pass max_{grant, maptrack}_frames into grant_table_create()

In reply to Andrew Cooper

... rather than setting the limits up after domain_create() has completed.

This removes the common gnttab infrastructure for calculating the number of dom0 grant frames (as the common grant table code is not an appropriate place for it to live), opting instead to require the dom0 construction code to pass a sane value in via the configuration.

In practice, this now means that there is never a partially constructed grant table for a reference-able domain.

---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

v2:
* Split/rearrange to avoid the post-domain-create error path.
v3:
* Retain gnttab_dom0_frames() for ARM. Sadly needs to be a macro as opt_max_grant_frames isn't declared until later in xen/grant_table.h

---
 xen/arch/arm/setup.c              |  3 +++
 xen/arch/x86/setup.c              |  3 +++
 xen/common/domain.c               |  3 ++-
 xen/common/grant_table.c          | 16 +++-------------
 xen/include/asm-arm/grant_table.h |  6 ++----
 xen/include/asm-x86/grant_table.h |  5 -----
 xen/include/xen/grant_table.h     |  6 ++----
 7 files changed, 15 insertions(+), 27 deletions(-)
xen/arch/arm/setup.c +3 -0
index 45f3841..501a9d5 100644
@@ -20,6 +20,7 @@
 #include <xen/compile.h>
 #include <xen/device_tree.h>
 #include <xen/domain_page.h>
+#include <xen/grant_table.h>
 #include <xen/types.h>
 #include <xen/string.h>
 #include <xen/serial.h>
@@ -693,6 +694,8 @@ void __init start_xen(unsigned long boot_phys_offset,
     struct domain *dom0;
     struct xen_domctl_createdomain dom0_cfg = {
         .max_evtchn_port = -1,
+        .max_grant_frames = gnttab_dom0_frames(),
+        .max_maptrack_frames = opt_max_maptrack_frames,
     };
 
     dcache_line_bytes = read_dcache_line_bytes();
xen/arch/x86/setup.c +3 -0
index dd11815..8440643 100644
@@ -1,6 +1,7 @@
 #include <xen/init.h>
 #include <xen/lib.h>
 #include <xen/err.h>
+#include <xen/grant_table.h>
 #include <xen/sched.h>
 #include <xen/sched-if.h>
 #include <xen/domain.h>
@@ -682,6 +683,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     struct xen_domctl_createdomain dom0_cfg = {
         .flags = XEN_DOMCTL_CDF_s3_integrity,
         .max_evtchn_port = -1,
+        .max_grant_frames = opt_max_grant_frames,
+        .max_maptrack_frames = opt_max_maptrack_frames,
     };
 
     /* Critical region without IDT or TSS.  Any fault is deadly! */
xen/common/domain.c +2 -1
index 171d25e..1dcab8d 100644
@@ -366,7 +366,8 @@ struct domain *domain_create(domid_t domid,
             goto fail;
         init_status |= INIT_evtchn;
 
-        if ( (err = grant_table_create(d)) != 0 )
+        if ( (err = grant_table_create(d, config->max_grant_frames,
+                                       config->max_maptrack_frames)) != 0 )
             goto fail;
         init_status |= INIT_gnttab;
 
xen/common/grant_table.c +3 -13
index ad55cfa..f08341e 100644
@@ -3567,9 +3567,8 @@ do_grant_table_op(
 #include "compat/grant_table.c"
 #endif
 
-int
-grant_table_create(
-    struct domain *d)
+int grant_table_create(struct domain *d, unsigned int max_grant_frames,
+                       unsigned int max_maptrack_frames)
 {
     struct grant_table *t;
     int ret = 0;
@@ -3587,11 +3586,7 @@ grant_table_create(
     t->domain = d;
     d->grant_table = t;
 
-    if ( d->domain_id == 0 )
-    {
-        ret = grant_table_init(d, t, gnttab_dom0_frames(),
-                               opt_max_maptrack_frames);
-    }
+    ret = grant_table_set_limits(d, max_maptrack_frames, max_maptrack_frames);
 
     return ret;
 }
@@ -4049,11 +4044,6 @@ static int __init gnttab_usage_init(void)
 }
 __initcall(gnttab_usage_init);
 
-unsigned int __init gnttab_dom0_frames(void)
-{
-    return min(opt_max_grant_frames, gnttab_dom0_max());
-}
-
 /*
  * Local variables:
  * mode: C
xen/include/asm-arm/grant_table.h +2 -4
index 5113b91..d8fde01 100644
@@ -30,10 +30,8 @@ void gnttab_mark_dirty(struct domain *d, mfn_t mfn);
  * Only use the text section as it's always present and will contain
  * enough space for a large grant table
  */
-static inline unsigned int gnttab_dom0_max(void)
-{
-    return PFN_DOWN(_etext - _stext);
-}
+#define gnttab_dom0_frames()                                             \
+    min_t(unsigned int, opt_max_grant_frames, PFN_DOWN(_etext - _stext))
 
 #define gnttab_init_arch(gt)                                             \
 ({                                                                       \
xen/include/asm-x86/grant_table.h +0 -5
index 76ec5dd..761a8c3 100644
@@ -39,11 +39,6 @@ static inline int replace_grant_host_mapping(uint64_t addr, mfn_t frame,
     return replace_grant_pv_mapping(addr, frame, new_addr, flags);
 }
 
-static inline unsigned int gnttab_dom0_max(void)
-{
-    return UINT_MAX;
-}
-
 #define gnttab_init_arch(gt) 0
 #define gnttab_destroy_arch(gt) do {} while ( 0 )
 #define gnttab_set_frame_gfn(gt, st, idx, gfn) do {} while ( 0 )
xen/include/xen/grant_table.h +2 -4
index c881414..b46bb0a 100644
@@ -35,8 +35,8 @@ extern unsigned int opt_max_grant_frames;
 extern unsigned int opt_max_maptrack_frames;
 
 /* Create/destroy per-domain grant table context. */
-int grant_table_create(
-    struct domain *d);
+int grant_table_create(struct domain *d, unsigned int max_grant_frames,
+                       unsigned int max_maptrack_frames);
 void grant_table_destroy(
     struct domain *d);
 void grant_table_init_vcpu(struct vcpu *v);
@@ -63,6 +63,4 @@ int gnttab_get_shared_frame(struct domain *d, unsigned long idx,
 int gnttab_get_status_frame(struct domain *d, unsigned long idx,
                             mfn_t *mfn);
 
-unsigned int gnttab_dom0_frames(void);
-
 #endif /* __XEN_GRANT_TABLE_H__ */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v3 6/12
#19 lore raw

Re: [PATCH v3 6/12] xen/gnttab: Pass max_{grant, maptrack}_frames into grant_table_create()

Hi Andrew,

Quoted 7 lines · Andrew Cooper

... rather than setting the limits up after domain_create() has completed.

This removes the common gnttab infrastructure for calculating the number of dom0 grant frames (as the common grant table code is not an appropriate place for it to live), opting instead to require the dom0 construction code to pass a sane value in via the configuration.

Quoted 6 lines

In practice, this now means that there is never a partially constructed grant table for a reference-able domain.

Cheers,

Quoted 173 lines

---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

v2:
* Split/rearrange to avoid the post-domain-create error path.
v3:
* Retain gnttab_dom0_frames() for ARM. Sadly needs to be a macro as opt_max_grant_frames isn't declared until later in xen/grant_table.h

---
  xen/arch/arm/setup.c              |  3 +++
  xen/arch/x86/setup.c              |  3 +++
  xen/common/domain.c               |  3 ++-
  xen/common/grant_table.c          | 16 +++-------------
  xen/include/asm-arm/grant_table.h |  6 ++----
  xen/include/asm-x86/grant_table.h |  5 -----
  xen/include/xen/grant_table.h     |  6 ++----
  7 files changed, 15 insertions(+), 27 deletions(-)
xen/arch/arm/setup.c +3 -0
index 45f3841..501a9d5 100644
@@ -20,6 +20,7 @@
  #include <xen/compile.h>
  #include <xen/device_tree.h>
  #include <xen/domain_page.h>
+#include <xen/grant_table.h>
  #include <xen/types.h>
  #include <xen/string.h>
  #include <xen/serial.h>
@@ -693,6 +694,8 @@ void __init start_xen(unsigned long boot_phys_offset,
      struct domain *dom0;
      struct xen_domctl_createdomain dom0_cfg = {
          .max_evtchn_port = -1,
+        .max_grant_frames = gnttab_dom0_frames(),
+        .max_maptrack_frames = opt_max_maptrack_frames,
      };
 
      dcache_line_bytes = read_dcache_line_bytes();
xen/arch/x86/setup.c +3 -0
index dd11815..8440643 100644
@@ -1,6 +1,7 @@
  #include <xen/init.h>
  #include <xen/lib.h>
  #include <xen/err.h>
+#include <xen/grant_table.h>
  #include <xen/sched.h>
  #include <xen/sched-if.h>
  #include <xen/domain.h>
@@ -682,6 +683,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      struct xen_domctl_createdomain dom0_cfg = {
          .flags = XEN_DOMCTL_CDF_s3_integrity,
          .max_evtchn_port = -1,
+        .max_grant_frames = opt_max_grant_frames,
+        .max_maptrack_frames = opt_max_maptrack_frames,
      };
 
      /* Critical region without IDT or TSS.  Any fault is deadly! */
xen/common/domain.c +2 -1
index 171d25e..1dcab8d 100644
@@ -366,7 +366,8 @@ struct domain *domain_create(domid_t domid,
              goto fail;
          init_status |= INIT_evtchn;
 
-        if ( (err = grant_table_create(d)) != 0 )
+        if ( (err = grant_table_create(d, config->max_grant_frames,
+                                       config->max_maptrack_frames)) != 0 )
              goto fail;
          init_status |= INIT_gnttab;
 
xen/common/grant_table.c +3 -13
index ad55cfa..f08341e 100644
@@ -3567,9 +3567,8 @@ do_grant_table_op(
  #include "compat/grant_table.c"
  #endif
 
-int
-grant_table_create(
-    struct domain *d)
+int grant_table_create(struct domain *d, unsigned int max_grant_frames,
+                       unsigned int max_maptrack_frames)
  {
      struct grant_table *t;
      int ret = 0;
@@ -3587,11 +3586,7 @@ grant_table_create(
      t->domain = d;
      d->grant_table = t;
 
-    if ( d->domain_id == 0 )
-    {
-        ret = grant_table_init(d, t, gnttab_dom0_frames(),
-                               opt_max_maptrack_frames);
-    }
+    ret = grant_table_set_limits(d, max_maptrack_frames, max_maptrack_frames);
 
      return ret;
  }
@@ -4049,11 +4044,6 @@ static int __init gnttab_usage_init(void)
  }
  __initcall(gnttab_usage_init);
 
-unsigned int __init gnttab_dom0_frames(void)
-{
-    return min(opt_max_grant_frames, gnttab_dom0_max());
-}
-
  /*
   * Local variables:
   * mode: C
xen/include/asm-arm/grant_table.h +2 -4
index 5113b91..d8fde01 100644
@@ -30,10 +30,8 @@ void gnttab_mark_dirty(struct domain *d, mfn_t mfn);
   * Only use the text section as it's always present and will contain
   * enough space for a large grant table
   */
-static inline unsigned int gnttab_dom0_max(void)
-{
-    return PFN_DOWN(_etext - _stext);
-}
+#define gnttab_dom0_frames()                                             \
+    min_t(unsigned int, opt_max_grant_frames, PFN_DOWN(_etext - _stext))
 
  #define gnttab_init_arch(gt)                                             \
  ({                                                                       \
xen/include/asm-x86/grant_table.h +0 -5
index 76ec5dd..761a8c3 100644
@@ -39,11 +39,6 @@ static inline int replace_grant_host_mapping(uint64_t addr, mfn_t frame,
      return replace_grant_pv_mapping(addr, frame, new_addr, flags);
  }
 
-static inline unsigned int gnttab_dom0_max(void)
-{
-    return UINT_MAX;
-}
-
  #define gnttab_init_arch(gt) 0
  #define gnttab_destroy_arch(gt) do {} while ( 0 )
  #define gnttab_set_frame_gfn(gt, st, idx, gfn) do {} while ( 0 )
xen/include/xen/grant_table.h +2 -4
index c881414..b46bb0a 100644
@@ -35,8 +35,8 @@ extern unsigned int opt_max_grant_frames;
  extern unsigned int opt_max_maptrack_frames;
 
  /* Create/destroy per-domain grant table context. */
-int grant_table_create(
-    struct domain *d);
+int grant_table_create(struct domain *d, unsigned int max_grant_frames,
+                       unsigned int max_maptrack_frames);
  void grant_table_destroy(
      struct domain *d);
  void grant_table_init_vcpu(struct vcpu *v);
@@ -63,6 +63,4 @@ int gnttab_get_shared_frame(struct domain *d, unsigned long idx,
  int gnttab_get_status_frame(struct domain *d, unsigned long idx,
                              mfn_t *mfn);
 
-unsigned int gnttab_dom0_frames(void);
-
  #endif /* __XEN_GRANT_TABLE_H__ */
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#20 lore raw

PATCH v2 7/12 xen/domctl: Remove XEN_DOMCTL_set_gnttab_limits

In reply to Andrew Cooper

Now that XEN_DOMCTL_createdomain handles the grant table limits, remove XEN_DOMCTL_set_gnttab_limits (including XSM hooks and libxc wrappers).

---
CC: Jan Beulich <[email protected]>

v2:
* Split/rearrange to avoid the post-domain-create error path. Retain appropriate acks.

---
 tools/flask/policy/modules/dom0.te   |  2 +-
 tools/flask/policy/modules/xen.if    |  2 +-
 tools/helpers/init-xenstore-domain.c |  7 -------
 tools/libxc/include/xenctrl.h        | 13 -------------
 tools/libxc/xc_domain.c              | 13 -------------
 tools/libxl/libxl_dom.c              |  6 ------
 xen/common/domctl.c                  |  5 -----
 xen/include/public/domctl.h          |  8 +-------
 xen/xsm/flask/hooks.c                |  3 ---
 xen/xsm/flask/policy/access_vectors  |  2 --
 10 files changed, 3 insertions(+), 58 deletions(-)
tools/flask/policy/modules/dom0.te +1 -1
index 4eb3843..dfdcdcd 100644
@@ -39,7 +39,7 @@ allow dom0_t dom0_t:domain {
 };
 allow dom0_t dom0_t:domain2 {
 	set_cpuid gettsc settsc setscheduler set_vnumainfo
-	get_vnumainfo psr_cmt_op psr_alloc set_gnttab_limits
+	get_vnumainfo psr_cmt_op psr_alloc
 };
 allow dom0_t dom0_t:resource { add remove };
 
tools/flask/policy/modules/xen.if +1 -1
index 61b0e76..4e06cfc 100644
@@ -52,7 +52,7 @@ define(`create_domain_common', `
 			settime setdomainhandle getvcpucontext set_misc_info };
 	allow $1 $2:domain2 { set_cpuid settsc setscheduler setclaim
 			set_vnumainfo get_vnumainfo cacheflush
-			psr_cmt_op psr_alloc soft_reset set_gnttab_limits
+			psr_cmt_op psr_alloc soft_reset
 			resource_map };
 	allow $1 $2:security check_context;
 	allow $1 $2:shadow enable;
tools/helpers/init-xenstore-domain.c +0 -7
index cd27edc..4771750 100644
@@ -112,13 +112,6 @@ static int build(xc_interface *xch)
         fprintf(stderr, "xc_domain_setmaxmem failed\n");
         goto err;
     }
-    rv = xc_domain_set_gnttab_limits(xch, domid, config.max_grant_frames,
-                                     config.max_maptrack_frames);
-    if ( rv )
-    {
-        fprintf(stderr, "xc_domain_set_gnttab_limits failed\n");
-        goto err;
-    }
     rv = xc_domain_set_memmap_limit(xch, domid, limit_kb);
     if ( rv )
     {
tools/libxc/include/xenctrl.h +0 -13
index c626984..bb75bcc 100644
@@ -1081,19 +1081,6 @@ int xc_domain_set_access_required(xc_interface *xch,
  */
 int xc_domain_set_virq_handler(xc_interface *xch, uint32_t domid, int virq);
 
-/**
- * Set the maximum number of grant frames and maptrack frames a domain
- * can have. Must be used at domain setup time and only then.
- *
- * @param xch a handle to an open hypervisor interface
- * @param domid the domain id
- * @param grant_frames max. number of grant frames
- * @param maptrack_frames max. number of maptrack frames
- */
-int xc_domain_set_gnttab_limits(xc_interface *xch, uint32_t domid,
-                                uint32_t grant_frames,
-                                uint32_t maptrack_frames);
-
 /*
  * CPUPOOL MANAGEMENT FUNCTIONS
  */
tools/libxc/xc_domain.c +0 -13
index 2bc695c..e8d0734 100644
@@ -2256,19 +2256,6 @@ int xc_domain_set_virq_handler(xc_interface *xch, uint32_t domid, int virq)
     return do_domctl(xch, &domctl);
 }
 
-int xc_domain_set_gnttab_limits(xc_interface *xch, uint32_t domid,
-                                uint32_t grant_frames,
-                                uint32_t maptrack_frames)
-{
-    DECLARE_DOMCTL;
-
-    domctl.cmd = XEN_DOMCTL_set_gnttab_limits;
-    domctl.domain = domid;
-    domctl.u.set_gnttab_limits.grant_frames = grant_frames;
-    domctl.u.set_gnttab_limits.maptrack_frames = maptrack_frames;
-    return do_domctl(xch, &domctl);
-}
-
 /* Plumbing Xen with vNUMA topology */
 int xc_domain_setvnuma(xc_interface *xch,
                        uint32_t domid,
tools/libxl/libxl_dom.c +0 -6
index eb401cf..8a8a32c 100644
@@ -358,12 +358,6 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
         return ERROR_FAIL;
     }
 
-    if (xc_domain_set_gnttab_limits(ctx->xch, domid, info->max_grant_frames,
-                                    info->max_maptrack_frames) != 0) {
-        LOG(ERROR, "Couldn't set grant table limits");
-        return ERROR_FAIL;
-    }
-
     /*
      * Check if the domain has any CPU or node affinity already. If not, try
      * to build up the latter via automatic NUMA placement. In fact, in case
xen/common/domctl.c +0 -5
index 0ef554a..58e51b2 100644
@@ -1129,11 +1129,6 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             copyback = 1;
         break;
 
-    case XEN_DOMCTL_set_gnttab_limits:
-        ret = grant_table_set_limits(d, op->u.set_gnttab_limits.grant_frames,
-                                     op->u.set_gnttab_limits.maptrack_frames);
-        break;
-
     default:
         ret = arch_do_domctl(op, d, u_domctl);
         break;
xen/include/public/domctl.h +1 -7
index 676e686..e01fe06 100644
@@ -1069,11 +1069,6 @@ struct xen_domctl_psr_alloc {
     uint64_t data;      /* IN/OUT */
 };
 
-struct xen_domctl_set_gnttab_limits {
-    uint32_t grant_frames;     /* IN */
-    uint32_t maptrack_frames;  /* IN */
-};
-
 /* XEN_DOMCTL_vuart_op */
 struct xen_domctl_vuart_op {
 #define XEN_DOMCTL_VUART_OP_INIT  0
@@ -1172,7 +1167,7 @@ struct xen_domctl {
 #define XEN_DOMCTL_monitor_op                    77
 #define XEN_DOMCTL_psr_alloc                     78
 #define XEN_DOMCTL_soft_reset                    79
-#define XEN_DOMCTL_set_gnttab_limits             80
+/* #define XEN_DOMCTL_set_gnttab_limits          80 - Moved into XEN_DOMCTL_createdomain */
 #define XEN_DOMCTL_vuart_op                      81
 #define XEN_DOMCTL_gdbsx_guestmemio            1000
 #define XEN_DOMCTL_gdbsx_pausevcpu             1001
@@ -1233,7 +1228,6 @@ struct xen_domctl {
         struct xen_domctl_psr_cmt_op        psr_cmt_op;
         struct xen_domctl_monitor_op        monitor_op;
         struct xen_domctl_psr_alloc         psr_alloc;
-        struct xen_domctl_set_gnttab_limits set_gnttab_limits;
         struct xen_domctl_vuart_op          vuart_op;
         uint8_t                             pad[128];
     } u;
xen/xsm/flask/hooks.c +0 -3
index a4fbe62..500af2c 100644
@@ -742,9 +742,6 @@ static int flask_domctl(struct domain *d, int cmd)
     case XEN_DOMCTL_soft_reset:
         return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SOFT_RESET);
 
-    case XEN_DOMCTL_set_gnttab_limits:
-        return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SET_GNTTAB_LIMITS);
-
     default:
         return avc_unknown_permission("domctl", cmd);
     }
xen/xsm/flask/policy/access_vectors +0 -2
index b768870..d01a7a0 100644
@@ -246,8 +246,6 @@ class domain2
     mem_sharing
 # XEN_DOMCTL_psr_alloc
     psr_alloc
-# XEN_DOMCTL_set_gnttab_limits
-    set_gnttab_limits
 # XENMEM_resource_map
     resource_map
 }
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 7/12
#21 lore raw

Re: [PATCH v2 07/12] xen/domctl: Remove XEN_DOMCTL_set_gnttab_limits

Quoted 6 lines · Andrew Cooper

Now that XEN_DOMCTL_createdomain handles the grant table limits, remove XEN_DOMCTL_set_gnttab_limits (including XSM hooks and libxc wrappers).

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#22 lore raw

PATCH v2 8/12 xen/gnttab: Fold grant_table_{create, set_limits}() into grant_table_init()

In reply to Andrew Cooper

Now that the max_{grant,maptrack}_frames are specified from the very beginning of grant table construction, the various initialisation functions can be folded together and simplified as a result.

Leave grant_table_init() as the public interface, which is more consistent with other subsystems.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

v2:
* Fix the cleanup path to avoid memory leaks.

---
 xen/common/domain.c           |  4 +-
 xen/common/grant_table.c      | 93 +++++++++++++------------------------------
 xen/include/xen/grant_table.h |  6 +--
 3 files changed, 31 insertions(+), 72 deletions(-)
xen/common/domain.c +2 -2
index 1dcab8d..be51426 100644
@@ -366,8 +366,8 @@ struct domain *domain_create(domid_t domid,
             goto fail;
         init_status |= INIT_evtchn;
 
-        if ( (err = grant_table_create(d, config->max_grant_frames,
-                                       config->max_maptrack_frames)) != 0 )
+        if ( (err = grant_table_init(d, config->max_grant_frames,
+                                     config->max_maptrack_frames)) != 0 )
             goto fail;
         init_status |= INIT_gnttab;
 
xen/common/grant_table.c +27 -66

130 lines not on this page · raw message

xen/include/xen/grant_table.h +2 -4
index b46bb0a..12e8a4b 100644
@@ -35,13 +35,11 @@ extern unsigned int opt_max_grant_frames;
 extern unsigned int opt_max_maptrack_frames;
 
 /* Create/destroy per-domain grant table context. */
-int grant_table_create(struct domain *d, unsigned int max_grant_frames,
-                       unsigned int max_maptrack_frames);
+int grant_table_init(struct domain *d, unsigned int max_grant_frames,
+                     unsigned int max_maptrack_frames);
 void grant_table_destroy(
     struct domain *d);
 void grant_table_init_vcpu(struct vcpu *v);
-int grant_table_set_limits(struct domain *d, unsigned int grant_frames,
-                           unsigned int maptrack_frames);
 
 /*
  * Check if domain has active grants and log first 10 of them.
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 8/12
#23 lore raw

Re: [PATCH v2 08/12] xen/gnttab: Fold grant_table_{create, set_limits}() into grant_table_init()

Quoted 8 lines · Andrew Cooper

Now that the max_{grant,maptrack}_frames are specified from the very beginning of grant table construction, the various initialisation functions can be folded together and simplified as a result.

Leave grant_table_init() as the public interface, which is more consistent with other subsystems.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v2 8/12
#24 lore raw

Re: [PATCH v2 08/12] xen/gnttab: Fold grant_table_{create, set_limits}() into grant_table_init()

In reply to Andrew Cooper
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.08.18 at 12:01, <[email protected]> wrote:

Now that the max_{grant,maptrack}_frames are specified from the very beginning of grant table construction, the various initialisation functions can be folded together and simplified as a result.

Leave grant_table_init() as the public interface, which is more consistent with other subsystems.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#25 lore raw

PATCH v2 9/12 xen/domain: Call arch_domain_create() as early as possible in domain_create()

In reply to Andrew Cooper

This is in preparation to set up d->max_cpus and d->vcpu[] in domain_create(), and allow later parts of domain construction to have access to the values.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/common/domain.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
xen/common/domain.c +17 -17
index be51426..0c44f27 100644
@@ -322,6 +322,23 @@ struct domain *domain_create(domid_t domid,
         else
             d->guest_type = guest_type_pv;
 
+        if ( !is_hardware_domain(d) )
+            d->nr_pirqs = nr_static_irqs + extra_domU_irqs;
+        else
+            d->nr_pirqs = extra_hwdom_irqs ? nr_static_irqs + extra_hwdom_irqs
+                                           : arch_hwdom_irqs(domid);
+        if ( d->nr_pirqs > nr_irqs )
+            d->nr_pirqs = nr_irqs;
+
+        radix_tree_init(&d->pirq_tree);
+    }
+
+    if ( (err = arch_domain_create(d, config)) != 0 )
+        goto fail;
+    init_status |= INIT_arch;
+
+    if ( !is_idle_domain(d) )
+    {
         watchdog_domain_init(d);
         init_status |= INIT_watchdog;
 
@@ -352,16 +369,6 @@ struct domain *domain_create(domid_t domid,
         d->controller_pause_count = 1;
         atomic_inc(&d->pause_count);
 
-        if ( !is_hardware_domain(d) )
-            d->nr_pirqs = nr_static_irqs + extra_domU_irqs;
-        else
-            d->nr_pirqs = extra_hwdom_irqs ? nr_static_irqs + extra_hwdom_irqs
-                                           : arch_hwdom_irqs(domid);
-        if ( d->nr_pirqs > nr_irqs )
-            d->nr_pirqs = nr_irqs;
-
-        radix_tree_init(&d->pirq_tree);
-
         if ( (err = evtchn_init(d, config->max_evtchn_port)) != 0 )
             goto fail;
         init_status |= INIT_evtchn;
@@ -376,14 +383,7 @@ struct domain *domain_create(domid_t domid,
         d->pbuf = xzalloc_array(char, DOMAIN_PBUF_SIZE);
         if ( !d->pbuf )
             goto fail;
-    }
-
-    if ( (err = arch_domain_create(d, config)) != 0 )
-        goto fail;
-    init_status |= INIT_arch;
 
-    if ( !is_idle_domain(d) )
-    {
         if ( (err = sched_init_domain(d, 0)) != 0 )
             goto fail;
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 9/12
#26 lore raw

Re: [PATCH v2 09/12] xen/domain: Call arch_domain_create() as early as possible in domain_create()

Quoted 18 lines · Andrew Cooper

This is in preparation to set up d->max_cpus and d->vcpu[] in domain_create(), and allow later parts of domain construction to have access to the values.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/common/domain.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
xen/common/domain.c +0 -0
index be51426..0c44f27 100644

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

Quoted 10 lines
xen/common/domain.c +7 -0
@@ -322,6 +322,23 @@ struct domain *domain_create(domid_t domid,
         else
             d->guest_type = guest_type_pv;
 
+        if ( !is_hardware_domain(d) )
+            d->nr_pirqs = nr_static_irqs + extra_domU_irqs;
+        else
+            d->nr_pirqs = extra_hwdom_irqs ? nr_static_irqs + extra_hwdom_irqs
+                                           : arch_hwdom_irqs(domid);
+        if ( d->nr_pirqs > nr_irqs )
+            d->nr_pirqs = nr_irqs;

d->nr_pirqs = min(d->nr_pirqs, nr_irqs);

LGTM:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v2 9/12
#27 lore raw

Re: [PATCH v2 09/12] xen/domain: Call arch_domain_create() as early as possible in domain_create()

In reply to Andrew Cooper
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 13.08.18 at 12:01, <[email protected]> wrote:

This is in preparation to set up d->max_cpus and d->vcpu[] in domain_create(), and allow later parts of domain construction to have access to the values.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#28 lore raw

Rats nest with domain pirq initialisation

In reply to Andrew Cooper

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

Quoted 42 lines · Andrew Cooper

This is in preparation to set up d->max_cpus and d->vcpu[] in domain_create(), and allow later parts of domain construction to have access to the values.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/common/domain.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
xen/common/domain.c +17 -0
index be51426..0c44f27 100644
@@ -322,6 +322,23 @@ struct domain *domain_create(domid_t domid,
         else
             d->guest_type = guest_type_pv;
 
+        if ( !is_hardware_domain(d) )
+            d->nr_pirqs = nr_static_irqs + extra_domU_irqs;
+        else
+            d->nr_pirqs = extra_hwdom_irqs ? nr_static_irqs + extra_hwdom_irqs
+                                           : arch_hwdom_irqs(domid);
+        if ( d->nr_pirqs > nr_irqs )
+            d->nr_pirqs = nr_irqs;
+
+        radix_tree_init(&d->pirq_tree);
+    }
+
+    if ( (err = arch_domain_create(d, config)) != 0 )
+        goto fail;
+    init_status |= INIT_arch;
+
+    if ( !is_idle_domain(d) )
+    {
         watchdog_domain_init(d);
         init_status |= INIT_watchdog;
 
@@ -352,16 +369,6 @@ struct domain *domain_create(domid_t domid,

Between these two hunks is:

        d->iomem_caps = rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex);
        d->irq_caps   = rangeset_new(d, "Interrupts", 0);

which is important, because it turns out that x86's arch_domain_destroy() depends on d->irq_caps already being initialised.

The path which blows up is:

arch_domain_destroy()
  free_domain_pirqs()
    unmap_domain_pirq()
      irq_deny_access() rangeset_remove_singleton((d)->irq_caps, i)

Unlike the boolean-nature rangeset_contains_*() helpers, I don't think it is reasonable to make rangeset_remove_*() tolerate a NULL rangeset.

The behaviour of automatically revoking irq access is dubious at best. It is asymmetric with the XEN_DOMCTL_irq_permission, and a caller would reasonably expect not to have to re-grant identical permissions as the irq is mapped/unmapped.  Does anyone know why we have this suspect behaviour in the first place?

One way or another, this path needs to become idempotent, but simply throwing some NULL pointer checks into unmap_domain_pirq() doesn't feel like the right thing to do.

A separate mess is that we appear to allocate full pirq structures for all legacy irqs for every single domain, in init_domain_irq_mapping(). At the very least, this is wasteful as very few domains get access to real hardware in the first place.

The other thing I notice is that alloc_pirq_struct() is downright dangerous, as it deliberately tries to allocate half a struct pirq for the !hvm case.  I can only assume this is a space saving measure, but there is absolutely no help in the commit message which introduced it (c/s c24536b636f).

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#29 lore raw

Re: Rats nest with domain pirq initialisation

Quoted 47 lines
Quoted 1 line
Quoted 1 line · On 04.09.18 at 20:44, <[email protected]> wrote:

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

Quoted 42 lines · Andrew Cooper

This is in preparation to set up d->max_cpus and d->vcpu[] in domain_create(), and allow later parts of domain construction to have access to the values.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/common/domain.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
xen/common/domain.c +17 -0
index be51426..0c44f27 100644
@@ -322,6 +322,23 @@ struct domain *domain_create(domid_t domid,
         else
             d->guest_type = guest_type_pv;
 
+        if ( !is_hardware_domain(d) )
+            d->nr_pirqs = nr_static_irqs + extra_domU_irqs;
+        else
+            d->nr_pirqs = extra_hwdom_irqs ? nr_static_irqs + extra_hwdom_irqs
+                                           : arch_hwdom_irqs(domid);
+        if ( d->nr_pirqs > nr_irqs )
+            d->nr_pirqs = nr_irqs;
+
+        radix_tree_init(&d->pirq_tree);
+    }
+
+    if ( (err = arch_domain_create(d, config)) != 0 )
+        goto fail;
+    init_status |= INIT_arch;
+
+    if ( !is_idle_domain(d) )
+    {
         watchdog_domain_init(d);
         init_status |= INIT_watchdog;
 
@@ -352,16 +369,6 @@ struct domain *domain_create(domid_t domid,

Between these two hunks is:

Quoted 5 lines
        d->iomem_caps = rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex);
        d->irq_caps   = rangeset_new(d, "Interrupts", 0);

which is important, because it turns out that x86's arch_domain_destroy() depends on d->irq_caps already being initialised.

Moving this up looks reasonable to me. "Simple" initialization can certainly be done early (i.e. before arch_domain_create()), don't you think?

Quoted 7 lines

The path which blows up is:

arch_domain_destroy()
free_domain_pirqs()

    unmap_domain_pirq()
      irq_deny_access()
        rangeset_remove_singleton((d)->irq_caps, i)

But what IRQ do we find to unmap here? There can't be any that have been mapped, when ->irq_caps is still NULL. IOW I don't currently see how domain_pirq_to_irq() would legitimately return a positive value at this point in time, yet that's what guards the calls to unmap_domain_pirq().

Quoted 2 lines

Unlike the boolean-nature rangeset_contains_*() helpers, I don't think it is reasonable to make rangeset_remove_*() tolerate a NULL rangeset.

+1

Quoted 5 lines

The behaviour of automatically revoking irq access is dubious at best. It is asymmetric with the XEN_DOMCTL_irq_permission, and a caller would reasonably expect not to have to re-grant identical permissions as the irq is mapped/unmapped. Does anyone know why we have this suspect behaviour in the first place?

Wasn't it that it was symmetric originally, and the grant/map side has been split perhaps a couple of years ago? If so, the unmap side splitting was perhaps simply missed?

Quoted 3 lines

One way or another, this path needs to become idempotent, but simply throwing some NULL pointer checks into unmap_domain_pirq() doesn't feel like the right thing to do.

As per above - I think either free_domain_pirqs() should gain a single such NULL check, or domain_pirq_to_irq() should be made sure doesn't return positive values prior to ->irq_caps having been set up.

Quoted 4 lines

A separate mess is that we appear to allocate full pirq structures for all legacy irqs for every single domain, in init_domain_irq_mapping(). At the very least, this is wasteful as very few domains get access to real hardware in the first place.

I vaguely recall there was some hope to get rid of this, but I don't recall the prereqs necessary.

Quoted 5 lines

The other thing I notice is that alloc_pirq_struct() is downright dangerous, as it deliberately tries to allocate half a struct pirq for the !hvm case. I can only assume this is a space saving measure, but there is absolutely no help in the commit message which introduced it (c/s c24536b636f).

Space saving, yes. Just like it is forbidden to access d->arch.hvm for a PV d, accessing pirq->arch.hvm is forbidden to access for a PV domain's pirq. What point is there to allocate the space then?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#30 lore raw

Re: Rats nest with domain pirq initialisation

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines · On 05.09.18 at 09:24, <[email protected]> wrote:
Quoted 1 line · On 04.09.18 at 20:44, <[email protected]> wrote:

Unlike the boolean-nature rangeset_contains_*() helpers, I don't think it is reasonable to make rangeset_remove_*() tolerate a NULL rangeset.

+1

Hmm, upon further thought: rangeset_remove_*() is a no-op on an empty rangeset. Making it bail on a NULL one would therefore seem like not so unreasonable a thing.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#31 lore raw

Re: Rats nest with domain pirq initialisation

In reply to Jan Beulich
Quoted 46 lines · Jan Beulich
Quoted 46 lines
Quoted 1 line
Quoted 1 line · On 04.09.18 at 20:44, <[email protected]> wrote:

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

Quoted 42 lines · Andrew Cooper

This is in preparation to set up d->max_cpus and d->vcpu[] in domain_create(), and allow later parts of domain construction to have access to the values.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/common/domain.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
xen/common/domain.c +17 -0
index be51426..0c44f27 100644
@@ -322,6 +322,23 @@ struct domain *domain_create(domid_t domid,
         else
             d->guest_type = guest_type_pv;
 
+        if ( !is_hardware_domain(d) )
+            d->nr_pirqs = nr_static_irqs + extra_domU_irqs;
+        else
+            d->nr_pirqs = extra_hwdom_irqs ? nr_static_irqs + extra_hwdom_irqs
+                                           : arch_hwdom_irqs(domid);
+        if ( d->nr_pirqs > nr_irqs )
+            d->nr_pirqs = nr_irqs;
+
+        radix_tree_init(&d->pirq_tree);
+    }
+
+    if ( (err = arch_domain_create(d, config)) != 0 )
+        goto fail;
+    init_status |= INIT_arch;
+
+    if ( !is_idle_domain(d) )
+    {
         watchdog_domain_init(d);
         init_status |= INIT_watchdog;
 
@@ -352,16 +369,6 @@ struct domain *domain_create(domid_t domid,

Between these two hunks is:

Quoted 8 lines
Quoted 5 lines
        d->iomem_caps = rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex);
        d->irq_caps   = rangeset_new(d, "Interrupts", 0);

which is important, because it turns out that x86's arch_domain_destroy() depends on d->irq_caps already being initialised.

Moving this up looks reasonable to me. "Simple" initialization can certainly be done early (i.e. before arch_domain_create()), don't you think?

No - that defeats the purpose of making the destroy path idempotent. For us to remove the max_vcpus hypercall, _domain_destroy() must be capable of correctly cleaning up a domain from any state of initialisation, including if the relevant init calls haven't been made yet.

These rangeset_new() calls cannot move earlier than the first action which might fail (which is the XSM init call to get the security label correct).

Quoted 8 lines
Quoted 8 lines

The path which blows up is:

arch_domain_destroy()
free_domain_pirqs()

    unmap_domain_pirq()
      irq_deny_access()
        rangeset_remove_singleton((d)->irq_caps, i)
Quoted 4 lines

But what IRQ do we find to unmap here? There can't be any that have been mapped, when ->irq_caps is still NULL. IOW I don't currently see how domain_pirq_to_irq() would legitimately return a positive value at this point in time, yet that's what guards the calls to unmap_domain_pirq().

It is pirq 2 which explodes, which is the first of the redundant pirq structures allocated for legacy routing.

I'm not sure I understand this code well enough to comment on why domain_pirq_to_irq() returns a positive value at this point, but I'm going to go out on a limb and suggest it might be related to our unnecessary(?) preallocation.

Quoted 5 lines
Quoted 3 lines

Unlike the boolean-nature rangeset_contains_*() helpers, I don't think it is reasonable to make rangeset_remove_*() tolerate a NULL rangeset.

+1

Quoted 8 lines
Quoted 5 lines

The behaviour of automatically revoking irq access is dubious at best. It is asymmetric with the XEN_DOMCTL_irq_permission, and a caller would reasonably expect not to have to re-grant identical permissions as the irq is mapped/unmapped. Does anyone know why we have this suspect behaviour in the first place?

Wasn't it that it was symmetric originally, and the grant/map side has been split perhaps a couple of years ago? If so, the unmap side splitting was perhaps simply missed?

Perhaps?  I don't know the answers to these.

Quoted 8 lines
Quoted 4 lines

One way or another, this path needs to become idempotent, but simply throwing some NULL pointer checks into unmap_domain_pirq() doesn't feel like the right thing to do.

As per above - I think either free_domain_pirqs() should gain a single such NULL check, or domain_pirq_to_irq() should be made sure doesn't return positive values prior to ->irq_caps having been set up.

Quoted 6 lines
Quoted 4 lines

A separate mess is that we appear to allocate full pirq structures for all legacy irqs for every single domain, in init_domain_irq_mapping(). At the very least, this is wasteful as very few domains get access to real hardware in the first place.

I vaguely recall there was some hope to get rid of this, but I don't recall the prereqs necessary.

I'm beginning to regret looking at this code.  Whatever is going on, it looks like it is far more complicated than it needs to be.

It would help if there were even some comments...

Quoted 8 lines
Quoted 5 lines

The other thing I notice is that alloc_pirq_struct() is downright dangerous, as it deliberately tries to allocate half a struct pirq for the !hvm case. I can only assume this is a space saving measure, but there is absolutely no help in the commit message which introduced it (c/s c24536b636f).

Space saving, yes. Just like it is forbidden to access d->arch.hvm for a PV d, accessing pirq->arch.hvm is forbidden to access for a PV domain's pirq. What point is there to allocate the space then?

Because when the code inevitably gets things wrong, you only read/corrupt your own pirq structure, rather than whichever object happens to be allocated adjacently.  Most likely, this will be tlsf metadata.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#32 lore raw

Re: Rats nest with domain pirq initialisation

Quoted 55 lines
Quoted 1 line
Quoted 1 line · On 05.09.18 at 14:04, <[email protected]> wrote:
Quoted 23 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 04.09.18 at 20:44, <[email protected]> wrote:
Quoted 21 lines · Andrew Cooper

This is in preparation to set up d->max_cpus and d->vcpu[] in domain_create(), and allow later parts of domain construction to have access to the values.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/common/domain.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
xen/common/domain.c +0 -0
index be51426..0c44f27 100644
@@ -322,6 +322,23 @@ struct domain *domain_create(domid_t domid,
         else
             d->guest_type = guest_type_pv;
 
Quoted 4 lines
Quoted 4 lines

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

Quoted 4 lines
xen/common/domain.c +4 -0
+        if ( !is_hardware_domain(d) )
+            d->nr_pirqs = nr_static_irqs + extra_domU_irqs;
+        else
+            d->nr_pirqs = extra_hwdom_irqs ? nr_static_irqs + 

extra_hwdom_irqs

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
xen/common/domain.c +13 -0
+                                           : arch_hwdom_irqs(domid);
+        if ( d->nr_pirqs > nr_irqs )
+            d->nr_pirqs = nr_irqs;
+
+        radix_tree_init(&d->pirq_tree);
+    }
+
+    if ( (err = arch_domain_create(d, config)) != 0 )
+        goto fail;
+    init_status |= INIT_arch;
+
+    if ( !is_idle_domain(d) )
+    {
         watchdog_domain_init(d);
         init_status |= INIT_watchdog;
 
Quoted 4 lines
Quoted 4 lines

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

Quoted 1 line
xen/common/domain.c +0 -0
@@ -352,16 +369,6 @@ struct domain *domain_create(domid_t domid,

Between these two hunks is:

        d->iomem_caps = rangeset_new(d, "I/O Memory", 

RANGESETF_prettyprint_hex);

Quoted 4 lines
Quoted 4 lines
        d->irq_caps   = rangeset_new(d, "Interrupts", 0);

which is important, because it turns out that x86's arch_domain_destroy() depends on d->irq_caps already being initialised.

Quoted 8 lines
Quoted 3 lines

Moving this up looks reasonable to me. "Simple" initialization can certainly be done early (i.e. before arch_domain_create()), don't you think?

No - that defeats the purpose of making the destroy path idempotent. For us to remove the max_vcpus hypercall, _domain_destroy() must be capable of correctly cleaning up a domain from any state of initialisation, including if the relevant init calls haven't been made yet.

I agree up to here.

Quoted 3 lines

These rangeset_new() calls cannot move earlier than the first action which might fail (which is the XSM init call to get the security label correct).

But I must be overlooking something crucial here: If _domain_destroy() was idempotent, how does it matter at what point the rangesets get initialized?

Quoted 12 lines
Quoted 11 lines
Quoted 7 lines

The path which blows up is:

arch_domain_destroy()
free_domain_pirqs()

    unmap_domain_pirq()
      irq_deny_access()
        rangeset_remove_singleton((d)->irq_caps, i)

But what IRQ do we find to unmap here? There can't be any that have been mapped, when ->irq_caps is still NULL. IOW I don't currently see how domain_pirq_to_irq() would legitimately return a positive value at this point in time, yet that's what guards the calls to unmap_domain_pirq().

Quoted 7 lines

It is pirq 2 which explodes, which is the first of the redundant pirq structures allocated for legacy routing.

I'm not sure I understand this code well enough to comment on why domain_pirq_to_irq() returns a positive value at this point, but I'm going to go out on a limb and suggest it might be related to our unnecessary(?) preallocation.

I've meanwhile considered this as the reason, too. And iirc the pre-allocation is because guests (including Dom0) bypass some of the setup they would do for non-legacy IRQs. This may have been just a XenoLinux (mis)behavior, but even then I'm not convinced we could easily alter things.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#33 lore raw

Re: Rats nest with domain pirq initialisation

Quoted 62 lines · Jan Beulich
Quoted 55 lines
Quoted 1 line
Quoted 1 line · On 05.09.18 at 14:04, <[email protected]> wrote:
Quoted 23 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 04.09.18 at 20:44, <[email protected]> wrote:
Quoted 21 lines · Andrew Cooper

This is in preparation to set up d->max_cpus and d->vcpu[] in domain_create(), and allow later parts of domain construction to have access to the values.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/common/domain.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
xen/common/domain.c +0 -0
index be51426..0c44f27 100644
@@ -322,6 +322,23 @@ struct domain *domain_create(domid_t domid,
         else
             d->guest_type = guest_type_pv;
 
Quoted 4 lines
Quoted 4 lines

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

Quoted 4 lines
xen/common/domain.c +4 -0
+        if ( !is_hardware_domain(d) )
+            d->nr_pirqs = nr_static_irqs + extra_domU_irqs;
+        else
+            d->nr_pirqs = extra_hwdom_irqs ? nr_static_irqs + 

extra_hwdom_irqs

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
xen/common/domain.c +13 -0
+                                           : arch_hwdom_irqs(domid);
+        if ( d->nr_pirqs > nr_irqs )
+            d->nr_pirqs = nr_irqs;
+
+        radix_tree_init(&d->pirq_tree);
+    }
+
+    if ( (err = arch_domain_create(d, config)) != 0 )
+        goto fail;
+    init_status |= INIT_arch;
+
+    if ( !is_idle_domain(d) )
+    {
         watchdog_domain_init(d);
         init_status |= INIT_watchdog;
 
Quoted 4 lines
Quoted 4 lines

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

Quoted 1 line
xen/common/domain.c +0 -0
@@ -352,16 +369,6 @@ struct domain *domain_create(domid_t domid,

Between these two hunks is:

        d->iomem_caps = rangeset_new(d, "I/O Memory", 

RANGESETF_prettyprint_hex);

Quoted 4 lines
Quoted 4 lines
        d->irq_caps   = rangeset_new(d, "Interrupts", 0);

which is important, because it turns out that x86's arch_domain_destroy() depends on d->irq_caps already being initialised.

Quoted 7 lines
Quoted 3 lines

Moving this up looks reasonable to me. "Simple" initialization can certainly be done early (i.e. before arch_domain_create()), don't you think?

No - that defeats the purpose of making the destroy path idempotent. For us to remove the max_vcpus hypercall, _domain_destroy() must be capable of correctly cleaning up a domain from any state of initialisation, including if the relevant init calls haven't been made yet.

Quoted 8 lines

I agree up to here.

Quoted 3 lines

These rangeset_new() calls cannot move earlier than the first action which might fail (which is the XSM init call to get the security label correct).

But I must be overlooking something crucial here: If _domain_destroy() was idempotent, how does it matter at what point the rangesets get initialized?

_domain_destroy() is idempotent (for the very small quantity of state it currently looks after).  The problem is that arch_domain_destroy() is not idempotent, and needs needs to become so, and moving the rangeset_new() calls as you originally suggested is not a fix for arch_domain_destroy()'s idempotency bug.

Quoted 19 lines
Quoted 12 lines
Quoted 8 lines
Quoted 8 lines

The path which blows up is:

arch_domain_destroy()
free_domain_pirqs()

    unmap_domain_pirq()
      irq_deny_access()
        rangeset_remove_singleton((d)->irq_caps, i)
Quoted 4 lines

But what IRQ do we find to unmap here? There can't be any that have been mapped, when ->irq_caps is still NULL. IOW I don't currently see how domain_pirq_to_irq() would legitimately return a positive value at this point in time, yet that's what guards the calls to unmap_domain_pirq().

Quoted 7 lines

It is pirq 2 which explodes, which is the first of the redundant pirq structures allocated for legacy routing.

I'm not sure I understand this code well enough to comment on why domain_pirq_to_irq() returns a positive value at this point, but I'm going to go out on a limb and suggest it might be related to our unnecessary(?) preallocation.

Quoted 5 lines

I've meanwhile considered this as the reason, too. And iirc the pre-allocation is because guests (including Dom0) bypass some of the setup they would do for non-legacy IRQs. This may have been just a XenoLinux (mis)behavior, but even then I'm not convinced we could easily alter things.

Bypass which setup?  One way or another they have to bind the irq before it can be used, so I still don't see why any structure preallocation is needed.  (Reservation of legacy irq numbers, perahps.)

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#34 lore raw

Re: Rats nest with domain pirq initialisation

Quoted 28 lines · Andrew Cooper
Quoted 21 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 05.09.18 at 14:04, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 04.09.18 at 20:44, <[email protected]> wrote:

The path which blows up is:

arch_domain_destroy()
free_domain_pirqs()

    unmap_domain_pirq()
      irq_deny_access()
        rangeset_remove_singleton((d)->irq_caps, i)
Quoted 4 lines

But what IRQ do we find to unmap here? There can't be any that have been mapped, when ->irq_caps is still NULL. IOW I don't currently see how domain_pirq_to_irq() would legitimately return a positive value at this point in time, yet that's what guards the calls to unmap_domain_pirq().

Quoted 7 lines

It is pirq 2 which explodes, which is the first of the redundant pirq structures allocated for legacy routing.

I'm not sure I understand this code well enough to comment on why domain_pirq_to_irq() returns a positive value at this point, but I'm going to go out on a limb and suggest it might be related to our unnecessary(?) preallocation.

Quoted 5 lines

I've meanwhile considered this as the reason, too. And iirc the pre-allocation is because guests (including Dom0) bypass some of the setup they would do for non-legacy IRQs. This may have been just a XenoLinux (mis)behavior, but even then I'm not convinced we could easily alter things.

Quoted 3 lines

Bypass which setup?  One way or another they have to bind the irq before it can be used, so I still don't see why any structure preallocation is needed.  (Reservation of legacy irq numbers, perahps.)

For PIRQs you need to first allocate a PIRQ, then configure it and bind the PIRQ to an event channel. I have no idea, but it wouldn't seem that weird that old Dom0 kernels would assume that legacy IRQs (<16) are already allocated, and just configure and bind them.

Last time I looked when working on legacy PVH support for FreeBSD pvops Linux would correctly allocate legacy PIRQs before attempting to bind them, but I haven't looked at classic xenolinux Dom0 kernels.

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#35 lore raw

PATCH v2 10/12 tools: Pass max_vcpus to XEN_DOMCTL_createdomain

In reply to Andrew Cooper

XEN_DOMCTL_max_vcpus is a mandatory hypercall, but nothing actually prevents a toolstack from unpausing a domain with no vcpus.

Originally, d->vcpus[] was an embedded array in struct domain, but c/s fb442e217 "x86_64: allow more vCPU-s per guest" in Xen 4.0 altered it to being dynamically allocated. A side effect of this is that d->vcpu[] is NULL until XEN_DOMCTL_max_vcpus has completed, but a lot of hypercalls blindly dereference it.

Even today, the behaviour of XEN_DOMCTL_max_vcpus is a mandatory singleton call which can't change the number of vcpus once a value has been chosen.

In preparation to remote the hypercall, extend xen_domctl_createdomain with the a max_vcpus field and arrange for all callers to pass the appropriate value. There is no change in construction behaviour yet, but later patches will rearrange the hypervisor internals.

For the python stubs, extend the domain_create keyword list to take a max_vcpus parameter, in lieu of deleting the pyxc_domain_max_vcpus function.

---
CC: Marek Marczykowski-Górecki <[email protected]>

v2:
* Split out of previous v1 patch to avoid the post-domain-create error path. Retain appropriate acks.
* Use int rather than int32 in the ocaml stubs.

---
 tools/helpers/init-xenstore-domain.c |  3 ++-
 tools/libxl/libxl_create.c           |  1 +
 tools/ocaml/libs/xc/xenctrl.ml       |  1 +
 tools/ocaml/libs/xc/xenctrl.mli      |  1 +
 tools/ocaml/libs/xc/xenctrl_stubs.c  | 11 +++++++----
 tools/python/xen/lowlevel/xc/xc.c    |  9 ++++++---
 xen/include/public/domctl.h          |  1 +
 7 files changed, 19 insertions(+), 8 deletions(-)
tools/helpers/init-xenstore-domain.c +2 -1
index 4771750..3236d14 100644
@@ -66,6 +66,7 @@ static int build(xc_interface *xch)
     struct xen_domctl_createdomain config = {
         .ssidref = SECINITSID_DOMU,
         .flags = XEN_DOMCTL_CDF_xs_domain,
+        .max_vcpus = 1,
         .max_evtchn_port = -1, /* No limit. */
 
         /*
@@ -100,7 +101,7 @@ static int build(xc_interface *xch)
         fprintf(stderr, "xc_domain_create failed\n");
         goto err;
     }
-    rv = xc_domain_max_vcpus(xch, domid, 1);
+    rv = xc_domain_max_vcpus(xch, domid, config.max_vcpus);
     if ( rv )
     {
         fprintf(stderr, "xc_domain_max_vcpus failed\n");
tools/libxl/libxl_create.c +1 -0
index 8b755e4..6067630 100644
@@ -566,6 +566,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
     if (!libxl_domid_valid_guest(*domid)) {
         struct xen_domctl_createdomain create = {
             .ssidref = info->ssidref,
+            .max_vcpus = b_info->max_vcpus,
             .max_evtchn_port = b_info->event_channels,
             .max_grant_frames = b_info->max_grant_frames,
             .max_maptrack_frames = b_info->max_maptrack_frames,
tools/ocaml/libs/xc/xenctrl.ml +1 -0
index 42f45c4..40fbd37 100644
@@ -63,6 +63,7 @@ type domctl_create_config =
 	ssidref: int32;
 	handle: string;
 	flags: domain_create_flag list;
+	max_vcpus: int;
 	max_evtchn_port: int;
 	max_grant_frames: int;
 	max_maptrack_frames: int;
tools/ocaml/libs/xc/xenctrl.mli +1 -0
index 0db5816..906ce94 100644
@@ -55,6 +55,7 @@ type domctl_create_config = {
   ssidref: int32;
   handle: string;
   flags: domain_create_flag list;
+  max_vcpus: int;
   max_evtchn_port: int;
   max_grant_frames: int;
   max_maptrack_frames: int;
tools/ocaml/libs/xc/xenctrl_stubs.c +7 -4
index a9759e0..04b3561 100644
@@ -128,15 +128,17 @@ CAMLprim value stub_xc_domain_create(value xch, value config)
 #define VAL_SSIDREF             Field(config, 0)
 #define VAL_HANDLE              Field(config, 1)
 #define VAL_FLAGS               Field(config, 2)
-#define VAL_MAX_EVTCHN_PORT     Field(config, 3)
-#define VAL_MAX_GRANT_FRAMES    Field(config, 4)
-#define VAL_MAX_MAPTRACK_FRAMES Field(config, 5)
-#define VAL_ARCH                Field(config, 6)
+#define VAL_MAX_VCPUS           Field(config, 3)
+#define VAL_MAX_EVTCHN_PORT     Field(config, 4)
+#define VAL_MAX_GRANT_FRAMES    Field(config, 5)
+#define VAL_MAX_MAPTRACK_FRAMES Field(config, 6)
+#define VAL_ARCH                Field(config, 7)
 
 	uint32_t domid = 0;
 	int result;
 	struct xen_domctl_createdomain cfg = {
 		.ssidref = Int32_val(VAL_SSIDREF),
+		.max_vcpus = Int_val(VAL_MAX_VCPUS),
 		.max_evtchn_port = Int_val(VAL_MAX_EVTCHN_PORT),
 		.max_grant_frames = Int_val(VAL_MAX_GRANT_FRAMES),
 		.max_maptrack_frames = Int_val(VAL_MAX_MAPTRACK_FRAMES),
@@ -178,6 +180,7 @@ CAMLprim value stub_xc_domain_create(value xch, value config)
 #undef VAL_MAX_MAPTRACK_FRAMES
 #undef VAL_MAX_GRANT_FRAMES
 #undef VAL_MAX_EVTCHN_PORT
+#undef VAL_MAX_VCPUS
 #undef VAL_FLAGS
 #undef VAL_HANDLE
 #undef VAL_SSIDREF
tools/python/xen/lowlevel/xc/xc.c +6 -3
index 6bd58ec..b137d5a 100644
@@ -125,16 +125,19 @@ static PyObject *pyxc_domain_create(XcObject *self,
             0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
             0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
         },
+        .max_vcpus = 1,
         .max_evtchn_port = -1, /* No limit. */
         .max_grant_frames = 32,
         .max_maptrack_frames = 1024,
     };
 
-    static char *kwd_list[] = { "domid", "ssidref", "handle", "flags", "target", NULL };
+    static char *kwd_list[] = { "domid", "ssidref", "handle", "flags",
+                                "target", "max_vcpus", NULL };
 
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiOii", kwd_list,
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiOiii", kwd_list,
                                       &dom, &config.ssidref, &pyhandle,
-                                      &config.flags, &target))
+                                      &config.flags, &target,
+                                      &config.max_vcpus) )
         return NULL;
     if ( pyhandle != NULL )
     {
xen/include/public/domctl.h +1 -0
index e01fe06..d48454b 100644
@@ -70,6 +70,7 @@ struct xen_domctl_createdomain {
      * Various domain limits, which impact the quantity of resources (global
      * mapping space, xenheap, etc) a guest may consume.
      */
+    uint32_t max_vcpus;
     uint32_t max_evtchn_port;
     uint32_t max_grant_frames;
     uint32_t max_maptrack_frames;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#36 lore raw

PATCH v2 11/12 xen/dom0: Arrange for dom0_cfg to contain the real max_vcpus value

In reply to Andrew Cooper

Make dom0_max_vcpus() a common interface, and implement it on ARM by splitting the existing alloc_dom0_vcpu0() function in half.

As domain_create() doesn't yet set up the vcpu array, the max value is also passed into alloc_dom0_vcpu0(). This is temporary for bisectibility and removed in the following patch.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/arch/arm/domain_build.c | 12 +++++++++---
 xen/arch/arm/setup.c        |  3 ++-
 xen/arch/x86/dom0_build.c   |  5 ++---
 xen/arch/x86/setup.c        |  3 ++-
 xen/include/asm-x86/setup.h |  2 --
 xen/include/xen/domain.h    |  5 ++++-
 6 files changed, 19 insertions(+), 11 deletions(-)
xen/arch/arm/domain_build.c +9 -3
index 737e0f3..f4a1225 100644
@@ -62,17 +62,23 @@ struct map_range_data
  */
 #define DOM0_FDT_EXTRA_SIZE (128 + sizeof(struct fdt_reserve_entry))
 
-struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0)
+unsigned int __init dom0_max_vcpus(void)
 {
     if ( opt_dom0_max_vcpus == 0 )
         opt_dom0_max_vcpus = num_online_cpus();
     if ( opt_dom0_max_vcpus > MAX_VIRT_CPUS )
         opt_dom0_max_vcpus = MAX_VIRT_CPUS;
 
-    dom0->vcpu = xzalloc_array(struct vcpu *, opt_dom0_max_vcpus);
+    return opt_dom0_max_vcpus;
+}
+
+struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0,
+                                     unsigned int max_vcpus)
+{
+    dom0->vcpu = xzalloc_array(struct vcpu *, max_vcpus);
     if ( !dom0->vcpu )
         return NULL;
-    dom0->max_vcpus = opt_dom0_max_vcpus;
+    dom0->max_vcpus = max_vcpus;
 
     return alloc_vcpu(dom0, 0, 0);
 }
xen/arch/arm/setup.c +2 -1
index 3d3b30c..72e42e8 100644
@@ -860,9 +860,10 @@ void __init start_xen(unsigned long boot_phys_offset,
     /* The vGIC for DOM0 is exactly emulating the hardware GIC */
     dom0_cfg.arch.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
     dom0_cfg.arch.nr_spis = gic_number_lines() - 32;
+    dom0_cfg.max_vcpus = dom0_max_vcpus();
 
     dom0 = domain_create(0, &dom0_cfg, true);
-    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
+    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0, dom0_cfg.max_vcpus) == NULL) )
             panic("Error creating domain 0");
 
     if ( construct_dom0(dom0) != 0)
xen/arch/x86/dom0_build.c +2 -3
index b744791..b42eac3 100644
@@ -199,10 +199,9 @@ unsigned int __init dom0_max_vcpus(void)
     return max_vcpus;
 }
 
-struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0)
+struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0,
+                                     unsigned int max_vcpus)
 {
-    unsigned int max_vcpus = dom0_max_vcpus();
-
     dom0->node_affinity = dom0_nodes;
     dom0->auto_node_affinity = !dom0_nr_pxms;
 
xen/arch/x86/setup.c +2 -1
index 2cfae89..46dcc71 100644
@@ -1689,10 +1689,11 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         dom0_cfg.arch.emulation_flags |=
             XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI;
     }
+    dom0_cfg.max_vcpus = dom0_max_vcpus();
 
     /* Create initial domain 0. */
     dom0 = domain_create(get_initial_domain_id(), &dom0_cfg, !pv_shim);
-    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
+    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0, dom0_cfg.max_vcpus) == NULL) )
         panic("Error creating domain 0");
 
     /* Grab the DOM0 command line. */
xen/include/asm-x86/setup.h +0 -2
index b2bf16c..42fddeb 100644
@@ -44,8 +44,6 @@ unsigned long initial_images_nrpages(nodeid_t node);
 void discard_initial_images(void);
 void *bootstrap_map(const module_t *mod);
 
-unsigned int dom0_max_vcpus(void);
-
 int xen_in_range(unsigned long mfn);
 
 void microcode_grab_module(
xen/include/xen/domain.h +4 -1
index f35e360..651205d 100644
@@ -15,7 +15,10 @@ typedef union {
 
 struct vcpu *alloc_vcpu(
     struct domain *d, unsigned int vcpu_id, unsigned int cpu_id);
-struct vcpu *alloc_dom0_vcpu0(struct domain *dom0);
+
+unsigned int dom0_max_vcpus(void);
+struct vcpu *alloc_dom0_vcpu0(struct domain *dom0, unsigned int max_vcpus);
+
 int vcpu_reset(struct vcpu *);
 int vcpu_up(struct vcpu *v);
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 11/12
#37 lore raw

Re: [PATCH v2 11/12] xen/dom0: Arrange for dom0_cfg to contain the real max_vcpus value

Quoted 9 lines · Andrew Cooper

Make dom0_max_vcpus() a common interface, and implement it on ARM by splitting the existing alloc_dom0_vcpu0() function in half.

As domain_create() doesn't yet set up the vcpu array, the max value is also passed into alloc_dom0_vcpu0(). This is temporary for bisectibility and removed in the following patch.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v2 11/12
#38 lore raw

Re: [PATCH v2 11/12] xen/dom0: Arrange for dom0_cfg to contain the real max_vcpus value

In reply to Andrew Cooper
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.08.18 at 12:01, <[email protected]> wrote:

Make dom0_max_vcpus() a common interface, and implement it on ARM by splitting the existing alloc_dom0_vcpu0() function in half.

As domain_create() doesn't yet set up the vcpu array, the max value is also passed into alloc_dom0_vcpu0(). This is temporary for bisectibility and removed in the following patch.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#39 lore raw

PATCH v2 12/12 xen/domain: Allocate d->vcpu[] in domain_create()

In reply to Andrew Cooper

For ARM, the call to arch_domain_create() needs to have completed before domain_max_vcpus() will return the correct upper bound.

For each arch's dom0's, drop the temporary max_vcpus parameter, and allocation of dom0->vcpu.

With d->max_vcpus now correctly configured before evtchn_init(), the poll mask can be constructed suitably for the domain, rather than for the worst-case setting.

Due to the evtchn_init() fixes, it no longer calls domain_max_vcpus(), and ARM's two implementations of vgic_max_vcpus() no longer need work around the out-of-order call.

From this point on, d->max_vcpus and d->vcpus[] are valid for any domain which can be looked up by domid.

The XEN_DOMCTL_max_vcpus hypercall is modified to reject any call attempt with max != d->max_vcpus, which does match the older semantics (not that it is obvious from the code). The logic to allocate d->vcpu[] is dropped, but at this point the hypercall still needs making to allocate each vcpu.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

v2:
* Allocate in domain_create() rather than arch_domain_create().
* Retain domain_max_vcpus().

---
 xen/arch/arm/domain_build.c |  8 +-------
 xen/arch/arm/setup.c        |  2 +-
 xen/arch/arm/vgic.c         | 11 +----------
 xen/arch/arm/vgic/vgic.c    | 22 +---------------------
 xen/arch/x86/dom0_build.c   |  8 +-------
 xen/arch/x86/setup.c        |  2 +-
 xen/common/domain.c         | 18 ++++++++++++++++++
 xen/common/domctl.c         | 39 +--------------------------------------
 xen/common/event_channel.c  |  3 +--
 xen/include/xen/domain.h    |  2 +-
 10 files changed, 27 insertions(+), 88 deletions(-)
xen/arch/arm/domain_build.c +1 -7
index f4a1225..6f45e56 100644
@@ -72,14 +72,8 @@ unsigned int __init dom0_max_vcpus(void)
     return opt_dom0_max_vcpus;
 }
 
-struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0,
-                                     unsigned int max_vcpus)
+struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0)
 {
-    dom0->vcpu = xzalloc_array(struct vcpu *, max_vcpus);
-    if ( !dom0->vcpu )
-        return NULL;
-    dom0->max_vcpus = max_vcpus;
-
     return alloc_vcpu(dom0, 0, 0);
 }
 
xen/arch/arm/setup.c +1 -1
index 72e42e8..a3e1ef7 100644
@@ -863,7 +863,7 @@ void __init start_xen(unsigned long boot_phys_offset,
     dom0_cfg.max_vcpus = dom0_max_vcpus();
 
     dom0 = domain_create(0, &dom0_cfg, true);
-    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0, dom0_cfg.max_vcpus) == NULL) )
+    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
             panic("Error creating domain 0");
 
     if ( construct_dom0(dom0) != 0)
xen/arch/arm/vgic.c +1 -10
index 7a2c455..5a4f082 100644
@@ -669,16 +669,7 @@ void vgic_free_virq(struct domain *d, unsigned int virq)
 
 unsigned int vgic_max_vcpus(const struct domain *d)
 {
-    /*
-     * Since evtchn_init would call domain_max_vcpus for poll_mask
-     * allocation when the vgic_ops haven't been initialised yet,
-     * we return MAX_VIRT_CPUS if d->arch.vgic.handler is null.
-     */
-    if ( !d->arch.vgic.handler )
-        return MAX_VIRT_CPUS;
-    else
-        return min_t(unsigned int, MAX_VIRT_CPUS,
-                     d->arch.vgic.handler->max_vcpus);
+    return min_t(unsigned int, MAX_VIRT_CPUS, d->arch.vgic.handler->max_vcpus);
 }
 
 /*
xen/arch/arm/vgic/vgic.c +1 -21
index 832632a..4124817 100644
@@ -951,27 +951,7 @@ void vgic_sync_hardware_irq(struct domain *d,
 
 unsigned int vgic_max_vcpus(const struct domain *d)
 {
-    unsigned int vgic_vcpu_limit;
-
-    switch ( d->arch.vgic.version )
-    {
-    case GIC_INVALID:
-        /*
-         * Since evtchn_init would call domain_max_vcpus for poll_mask
-         * allocation before the VGIC has been initialised, we need to
-         * return some safe value in this case. As this is for allocation
-         * purposes, go with the maximum value.
-         */
-        vgic_vcpu_limit = MAX_VIRT_CPUS;
-        break;
-    case GIC_V2:
-        vgic_vcpu_limit = VGIC_V2_MAX_CPUS;
-        break;
-    default:
-        BUG();
-    }
-
-    return min_t(unsigned int, MAX_VIRT_CPUS, vgic_vcpu_limit);
+    return min_t(unsigned int, MAX_VIRT_CPUS, d->arch.vgic.handler->max_vcpus);
 }
 
 #ifdef CONFIG_GICV3
xen/arch/x86/dom0_build.c +1 -7
index b42eac3..423fdec 100644
@@ -199,17 +199,11 @@ unsigned int __init dom0_max_vcpus(void)
     return max_vcpus;
 }
 
-struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0,
-                                     unsigned int max_vcpus)
+struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0)
 {
     dom0->node_affinity = dom0_nodes;
     dom0->auto_node_affinity = !dom0_nr_pxms;
 
-    dom0->vcpu = xzalloc_array(struct vcpu *, max_vcpus);
-    if ( !dom0->vcpu )
-        return NULL;
-    dom0->max_vcpus = max_vcpus;
-
     return dom0_setup_vcpu(dom0, 0,
                            cpumask_last(&dom0_cpus) /* so it wraps around to first pcpu */);
 }
xen/arch/x86/setup.c +1 -1
index 46dcc71..532aca7 100644
@@ -1693,7 +1693,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     /* Create initial domain 0. */
     dom0 = domain_create(get_initial_domain_id(), &dom0_cfg, !pv_shim);
-    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0, dom0_cfg.max_vcpus) == NULL) )
+    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
         panic("Error creating domain 0");
 
     /* Grab the DOM0 command line. */
xen/common/domain.c +18 -0
index 0c44f27..902276d 100644
@@ -339,6 +339,19 @@ struct domain *domain_create(domid_t domid,
 
     if ( !is_idle_domain(d) )
     {
+        /* Check d->max_vcpus and allocate d->vcpu[]. */
+        err = -EINVAL;
+        if ( config->max_vcpus < 1 ||
+             config->max_vcpus > domain_max_vcpus(d) )
+            goto fail;
+
+        err = -ENOMEM;
+        d->vcpu = xzalloc_array(struct vcpu *, config->max_vcpus);
+        if ( !d->vcpu )
+            goto fail;
+
+        d->max_vcpus = config->max_vcpus;
+
         watchdog_domain_init(d);
         init_status |= INIT_watchdog;
 
@@ -423,6 +436,11 @@ struct domain *domain_create(domid_t domid,
 
     sched_destroy_domain(d);
 
+    if ( d->max_vcpus )
+    {
+        d->max_vcpus = 0;
+        XFREE(d->vcpu);
+    }
     if ( init_status & INIT_arch )
         arch_domain_destroy(d);
     if ( init_status & INIT_gnttab )
xen/common/domctl.c +1 -38
index 58e51b2..ee0983d 100644
@@ -554,16 +554,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 
         ret = -EINVAL;
         if ( (d == current->domain) || /* no domain_pause() */
-             (max > domain_max_vcpus(d)) )
+             (max != d->max_vcpus) )   /* max_vcpus set up in createdomain */
             break;
 
-        /* Until Xenoprof can dynamically grow its vcpu-s array... */
-        if ( d->xenoprof )
-        {
-            ret = -EAGAIN;
-            break;
-        }
-
         /* Needed, for example, to ensure writable p.t. state is synced. */
         domain_pause(d);
 
@@ -581,38 +574,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             }
         }
 
-        /* We cannot reduce maximum VCPUs. */
-        ret = -EINVAL;
-        if ( (max < d->max_vcpus) && (d->vcpu[max] != NULL) )
-            goto maxvcpu_out;
-
-        /*
-         * For now don't allow increasing the vcpu count from a non-zero
-         * value: This code and all readers of d->vcpu would otherwise need
-         * to be converted to use RCU, but at present there's no tools side
-         * code path that would issue such a request.
-         */
-        ret = -EBUSY;
-        if ( (d->max_vcpus > 0) && (max > d->max_vcpus) )
-            goto maxvcpu_out;
-
         ret = -ENOMEM;
         online = cpupool_domain_cpumask(d);
-        if ( max > d->max_vcpus )
-        {
-            struct vcpu **vcpus;
-
-            BUG_ON(d->vcpu != NULL);
-            BUG_ON(d->max_vcpus != 0);
-
-            if ( (vcpus = xzalloc_array(struct vcpu *, max)) == NULL )
-                goto maxvcpu_out;
-
-            /* Install vcpu array /then/ update max_vcpus. */
-            d->vcpu = vcpus;
-            smp_wmb();
-            d->max_vcpus = max;
-        }
 
         for ( i = 0; i < max; i++ )
         {
xen/common/event_channel.c +1 -2
index 41cbbae..381f30e 100644
@@ -1303,8 +1303,7 @@ int evtchn_init(struct domain *d, unsigned int max_port)
     evtchn_from_port(d, 0)->state = ECS_RESERVED;
 
 #if MAX_VIRT_CPUS > BITS_PER_LONG
-    d->poll_mask = xzalloc_array(unsigned long,
-                                 BITS_TO_LONGS(domain_max_vcpus(d)));
+    d->poll_mask = xzalloc_array(unsigned long, BITS_TO_LONGS(d->max_vcpus));
     if ( !d->poll_mask )
     {
         free_evtchn_bucket(d, d->evtchn);
xen/include/xen/domain.h +1 -1
index 651205d..ce31999 100644
@@ -17,7 +17,7 @@ struct vcpu *alloc_vcpu(
     struct domain *d, unsigned int vcpu_id, unsigned int cpu_id);
 
 unsigned int dom0_max_vcpus(void);
-struct vcpu *alloc_dom0_vcpu0(struct domain *dom0, unsigned int max_vcpus);
+struct vcpu *alloc_dom0_vcpu0(struct domain *dom0);
 
 int vcpu_reset(struct vcpu *);
 int vcpu_up(struct vcpu *v);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 12/12
#40 lore raw

Re: [PATCH v2 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 121 lines · Andrew Cooper

For ARM, the call to arch_domain_create() needs to have completed before domain_max_vcpus() will return the correct upper bound.

For each arch's dom0's, drop the temporary max_vcpus parameter, and allocation of dom0->vcpu.

With d->max_vcpus now correctly configured before evtchn_init(), the poll mask can be constructed suitably for the domain, rather than for the worst-case setting.

Due to the evtchn_init() fixes, it no longer calls domain_max_vcpus(), and ARM's two implementations of vgic_max_vcpus() no longer need work around the out-of-order call.

From this point on, d->max_vcpus and d->vcpus[] are valid for any domain which can be looked up by domid.

The XEN_DOMCTL_max_vcpus hypercall is modified to reject any call attempt with max != d->max_vcpus, which does match the older semantics (not that it is obvious from the code). The logic to allocate d->vcpu[] is dropped, but at this point the hypercall still needs making to allocate each vcpu.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

v2:
* Allocate in domain_create() rather than arch_domain_create().
* Retain domain_max_vcpus().

---
 xen/arch/arm/domain_build.c |  8 +-------
 xen/arch/arm/setup.c        |  2 +-
 xen/arch/arm/vgic.c         | 11 +----------
 xen/arch/arm/vgic/vgic.c    | 22 +---------------------
 xen/arch/x86/dom0_build.c   |  8 +-------
 xen/arch/x86/setup.c        |  2 +-
 xen/common/domain.c         | 18 ++++++++++++++++++
 xen/common/domctl.c         | 39 +--------------------------------------
 xen/common/event_channel.c  |  3 +--
 xen/include/xen/domain.h    |  2 +-
 10 files changed, 27 insertions(+), 88 deletions(-)
xen/arch/arm/domain_build.c +1 -7
index f4a1225..6f45e56 100644
@@ -72,14 +72,8 @@ unsigned int __init dom0_max_vcpus(void)
     return opt_dom0_max_vcpus;
 }
 
-struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0,
-                                     unsigned int max_vcpus)
+struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0)
 {
-    dom0->vcpu = xzalloc_array(struct vcpu *, max_vcpus);
-    if ( !dom0->vcpu )
-        return NULL;
-    dom0->max_vcpus = max_vcpus;
-
     return alloc_vcpu(dom0, 0, 0);
 }
 
xen/arch/arm/setup.c +1 -1
index 72e42e8..a3e1ef7 100644
@@ -863,7 +863,7 @@ void __init start_xen(unsigned long boot_phys_offset,
     dom0_cfg.max_vcpus = dom0_max_vcpus();
 
     dom0 = domain_create(0, &dom0_cfg, true);
-    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0, dom0_cfg.max_vcpus) == NULL) )
+    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
             panic("Error creating domain 0");
 
     if ( construct_dom0(dom0) != 0)
xen/arch/arm/vgic.c +1 -10
index 7a2c455..5a4f082 100644
@@ -669,16 +669,7 @@ void vgic_free_virq(struct domain *d, unsigned int virq)
 
 unsigned int vgic_max_vcpus(const struct domain *d)
 {
-    /*
-     * Since evtchn_init would call domain_max_vcpus for poll_mask
-     * allocation when the vgic_ops haven't been initialised yet,
-     * we return MAX_VIRT_CPUS if d->arch.vgic.handler is null.
-     */
-    if ( !d->arch.vgic.handler )
-        return MAX_VIRT_CPUS;
-    else
-        return min_t(unsigned int, MAX_VIRT_CPUS,
-                     d->arch.vgic.handler->max_vcpus);
+    return min_t(unsigned int, MAX_VIRT_CPUS, d->arch.vgic.handler->max_vcpus);
 }
 
 /*
xen/arch/arm/vgic/vgic.c +0 -13
index 832632a..4124817 100644
@@ -951,27 +951,7 @@ void vgic_sync_hardware_irq(struct domain *d,
 
 unsigned int vgic_max_vcpus(const struct domain *d)
 {
-    unsigned int vgic_vcpu_limit;
-
-    switch ( d->arch.vgic.version )
-    {
-    case GIC_INVALID:
-        /*
-         * Since evtchn_init would call domain_max_vcpus for poll_mask
-         * allocation before the VGIC has been initialised, we need to
-         * return some safe value in this case. As this is for allocation
-         * purposes, go with the maximum value.
-         */
-        vgic_vcpu_limit = MAX_VIRT_CPUS;
-        break;

xen/arch/arm/vgic/vgic.c void vgic_sync_hardware_irq(struct domain *d, · line 955

Quoted 10 lines
xen/arch/arm/vgic/vgic.c +1 -8
-    case GIC_V2:
-        vgic_vcpu_limit = VGIC_V2_MAX_CPUS;
-        break;
-    default:
-        BUG();
-    }
-
-    return min_t(unsigned int, MAX_VIRT_CPUS, vgic_vcpu_limit);
+    return min_t(unsigned int, MAX_VIRT_CPUS, d->arch.vgic.handler->max_vcpus);
 }

Since both implementations are equal now, can you place this in vgic.h as a static inline function?

With that:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#41 lore raw

Re: [PATCH v2 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Hi,

Quoted 127 lines · Roger Pau Monné
Quoted 126 lines · Andrew Cooper

For ARM, the call to arch_domain_create() needs to have completed before domain_max_vcpus() will return the correct upper bound.

For each arch's dom0's, drop the temporary max_vcpus parameter, and allocation of dom0->vcpu.

With d->max_vcpus now correctly configured before evtchn_init(), the poll mask can be constructed suitably for the domain, rather than for the worst-case setting.

Due to the evtchn_init() fixes, it no longer calls domain_max_vcpus(), and ARM's two implementations of vgic_max_vcpus() no longer need work around the out-of-order call.

From this point on, d->max_vcpus and d->vcpus[] are valid for any domain which
can be looked up by domid.

The XEN_DOMCTL_max_vcpus hypercall is modified to reject any call attempt with max != d->max_vcpus, which does match the older semantics (not that it is obvious from the code). The logic to allocate d->vcpu[] is dropped, but at this point the hypercall still needs making to allocate each vcpu.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>

v2:
* Allocate in domain_create() rather than arch_domain_create().
* Retain domain_max_vcpus().

---
  xen/arch/arm/domain_build.c |  8 +-------
  xen/arch/arm/setup.c        |  2 +-
  xen/arch/arm/vgic.c         | 11 +----------
  xen/arch/arm/vgic/vgic.c    | 22 +---------------------
  xen/arch/x86/dom0_build.c   |  8 +-------
  xen/arch/x86/setup.c        |  2 +-
  xen/common/domain.c         | 18 ++++++++++++++++++
  xen/common/domctl.c         | 39 +--------------------------------------
  xen/common/event_channel.c  |  3 +--
  xen/include/xen/domain.h    |  2 +-
  10 files changed, 27 insertions(+), 88 deletions(-)
xen/arch/arm/domain_build.c +1 -7
index f4a1225..6f45e56 100644
@@ -72,14 +72,8 @@ unsigned int __init dom0_max_vcpus(void)
      return opt_dom0_max_vcpus;
  }
 
-struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0,
-                                     unsigned int max_vcpus)
+struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0)
  {
-    dom0->vcpu = xzalloc_array(struct vcpu *, max_vcpus);
-    if ( !dom0->vcpu )
-        return NULL;
-    dom0->max_vcpus = max_vcpus;
-
      return alloc_vcpu(dom0, 0, 0);
  }
 
xen/arch/arm/setup.c +1 -1
index 72e42e8..a3e1ef7 100644
@@ -863,7 +863,7 @@ void __init start_xen(unsigned long boot_phys_offset,
      dom0_cfg.max_vcpus = dom0_max_vcpus();
 
      dom0 = domain_create(0, &dom0_cfg, true);
-    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0, dom0_cfg.max_vcpus) == NULL) )
+    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
              panic("Error creating domain 0");
 
      if ( construct_dom0(dom0) != 0)
xen/arch/arm/vgic.c +1 -10
index 7a2c455..5a4f082 100644
@@ -669,16 +669,7 @@ void vgic_free_virq(struct domain *d, unsigned int virq)
 
  unsigned int vgic_max_vcpus(const struct domain *d)
  {
-    /*
-     * Since evtchn_init would call domain_max_vcpus for poll_mask
-     * allocation when the vgic_ops haven't been initialised yet,
-     * we return MAX_VIRT_CPUS if d->arch.vgic.handler is null.
-     */
-    if ( !d->arch.vgic.handler )
-        return MAX_VIRT_CPUS;
-    else
-        return min_t(unsigned int, MAX_VIRT_CPUS,
-                     d->arch.vgic.handler->max_vcpus);
+    return min_t(unsigned int, MAX_VIRT_CPUS, d->arch.vgic.handler->max_vcpus);
  }
 
  /*
xen/arch/arm/vgic/vgic.c +0 -18
index 832632a..4124817 100644
@@ -951,27 +951,7 @@ void vgic_sync_hardware_irq(struct domain *d,
 
  unsigned int vgic_max_vcpus(const struct domain *d)
  {
-    unsigned int vgic_vcpu_limit;
-
-    switch ( d->arch.vgic.version )
-    {
-    case GIC_INVALID:
-        /*
-         * Since evtchn_init would call domain_max_vcpus for poll_mask
-         * allocation before the VGIC has been initialised, we need to
-         * return some safe value in this case. As this is for allocation
-         * purposes, go with the maximum value.
-         */
-        vgic_vcpu_limit = MAX_VIRT_CPUS;
-        break;
-    case GIC_V2:
-        vgic_vcpu_limit = VGIC_V2_MAX_CPUS;
-        break;
-    default:
-        BUG();
Quoted 8 lines

xen/arch/arm/vgic/vgic.c void vgic_sync_hardware_irq(struct domain *d, · line 955

Quoted 5 lines
xen/arch/arm/vgic/vgic.c +1 -3
-    }
-
-    return min_t(unsigned int, MAX_VIRT_CPUS, vgic_vcpu_limit);
+    return min_t(unsigned int, MAX_VIRT_CPUS, d->arch.vgic.handler->max_vcpus);
  }

Since both implementations are equal now, can you place this in vgic.h as a static inline function?

vgic/vgic.c is part of the new vGIC implementation (selectable at th e compilation time) and using a different layout for the vgic_dist structure. The structure is described in asm/new_vgic.h and does not store the max vcpus anymore.

Instead, the switch should be retained and only the case GIC_INVALID should be dropped.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#42 lore raw

Re: [PATCH v2 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 36 lines · Julien Grall
Quoted 27 lines
Quoted 27 lines
xen/arch/arm/vgic/vgic.c +0 -9
index 832632a..4124817 100644
@@ -951,27 +951,7 @@ void vgic_sync_hardware_irq(struct domain *d,
     unsigned int vgic_max_vcpus(const struct domain *d)
   {
-    unsigned int vgic_vcpu_limit;
-
-    switch ( d->arch.vgic.version )
-    {
-    case GIC_INVALID:
-        /*
-         * Since evtchn_init would call domain_max_vcpus for poll_mask
-         * allocation before the VGIC has been initialised, we need to
-         * return some safe value in this case. As this is for

allocation
-         * purposes, go with the maximum value.
-         */
-        vgic_vcpu_limit = MAX_VIRT_CPUS;
-        break;
-    case GIC_V2:
-        vgic_vcpu_limit = VGIC_V2_MAX_CPUS;
-        break;
-    default:
-        BUG();
-    }

Quoted 8 lines
Quoted 5 lines

-
-    return min_t(unsigned int, MAX_VIRT_CPUS, vgic_vcpu_limit); +    return min_t(unsigned int, MAX_VIRT_CPUS, d->arch.vgic.handler->max_vcpus);
  }

Since both implementations are equal now, can you place this in vgic.h as a static inline function?

Quoted 7 lines

vgic/vgic.c is part of the new vGIC implementation (selectable at th e compilation time) and using a different layout for the vgic_dist structure. The structure is described in asm/new_vgic.h and does not store the max vcpus anymore.

Instead, the switch should be retained and only the case GIC_INVALID should be dropped.

What about GIC_V3?  VGIC_V3_MAX_CPUS seems to be 255 at the moment.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#43 lore raw

Re: [PATCH v2 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Hi Andrew,

Quoted 42 lines · Andrew Cooper
Quoted 41 lines · Julien Grall
Quoted 27 lines
Quoted 27 lines
xen/arch/arm/vgic/vgic.c +0 -9
index 832632a..4124817 100644
@@ -951,27 +951,7 @@ void vgic_sync_hardware_irq(struct domain *d,
     unsigned int vgic_max_vcpus(const struct domain *d)
   {
-    unsigned int vgic_vcpu_limit;
-
-    switch ( d->arch.vgic.version )
-    {
-    case GIC_INVALID:
-        /*
-         * Since evtchn_init would call domain_max_vcpus for poll_mask
-         * allocation before the VGIC has been initialised, we need to
-         * return some safe value in this case. As this is for

allocation
-         * purposes, go with the maximum value.
-         */
-        vgic_vcpu_limit = MAX_VIRT_CPUS;
-        break;
-    case GIC_V2:
-        vgic_vcpu_limit = VGIC_V2_MAX_CPUS;
-        break;
-    default:
-        BUG();
-    }

Quoted 8 lines
Quoted 5 lines

-
-    return min_t(unsigned int, MAX_VIRT_CPUS, vgic_vcpu_limit); +    return min_t(unsigned int, MAX_VIRT_CPUS, d->arch.vgic.handler->max_vcpus);
  }

Since both implementations are equal now, can you place this in vgic.h as a static inline function?

vgic/vgic.c is part of the new vGIC implementation (selectable at th e compilation time) and using a different layout for the vgic_dist structure. The structure is described in asm/new_vgic.h and does not store the max vcpus anymore.

Quoted 4 lines
Quoted 2 lines

Instead, the switch should be retained and only the case GIC_INVALID should be dropped.

What about GIC_V3?  VGIC_V3_MAX_CPUS seems to be 255 at the moment.

GICv3 is not yet supported by the new vGIC and disabled at compile time. So we should never reach this code with d->arch.vgic.version == GIC_V3.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#44 lore raw

Re: [PATCH v2 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 47 lines · Julien Grall

Hi Andrew,

Quoted 44 lines · Andrew Cooper
Quoted 43 lines · Julien Grall
Quoted 29 lines
Quoted 29 lines
xen/arch/arm/vgic/vgic.c +0 -7
index 832632a..4124817 100644
@@ -951,27 +951,7 @@ void vgic_sync_hardware_irq(struct domain *d,
      unsigned int vgic_max_vcpus(const struct domain *d)
    {
-    unsigned int vgic_vcpu_limit;
-
-    switch ( d->arch.vgic.version )
-    {
-    case GIC_INVALID:
-        /*
-         * Since evtchn_init would call domain_max_vcpus for

poll_mask
-         * allocation before the VGIC has been initialised, we need to
-         * return some safe value in this case. As this is for allocation
-         * purposes, go with the maximum value.
-         */
-        vgic_vcpu_limit = MAX_VIRT_CPUS;
-        break;
-    case GIC_V2:
-        vgic_vcpu_limit = VGIC_V2_MAX_CPUS;
-        break;
-    default:
-        BUG();
-    }

Quoted 8 lines
Quoted 5 lines

-
-    return min_t(unsigned int, MAX_VIRT_CPUS, vgic_vcpu_limit); +    return min_t(unsigned int, MAX_VIRT_CPUS, d->arch.vgic.handler->max_vcpus);
   }

Since both implementations are equal now, can you place this in vgic.h as a static inline function?

vgic/vgic.c is part of the new vGIC implementation (selectable at th e compilation time) and using a different layout for the vgic_dist structure. The structure is described in asm/new_vgic.h and does not store the max vcpus anymore.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Instead, the switch should be retained and only the case GIC_INVALID should be dropped.

What about GIC_V3?  VGIC_V3_MAX_CPUS seems to be 255 at the moment.

GICv3 is not yet supported by the new vGIC and disabled at compile time. So we should never reach this code with d->arch.vgic.version == GIC_V3.

Ok - no problem.  I'll refresh this to just deleting the INVALID case.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#45 lore raw

Re: [PATCH v2 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

In reply to Andrew Cooper

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

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 13.08.18 at 12:01, <[email protected]> wrote:
xen/common/domain.c +5 -0
@@ -423,6 +436,11 @@ struct domain *domain_create(domid_t domid,
 
     sched_destroy_domain(d);
 
+    if ( d->max_vcpus )
+    {
+        d->max_vcpus = 0;
+        XFREE(d->vcpu);
+    }
     if ( init_status & INIT_arch )
         arch_domain_destroy(d);

I'm not sure it is a good idea to free the vcpus this early, in particular before arch_domain_destroy().

Quoted 49 lines
xen/common/domctl.c +1 -31
@@ -554,16 +554,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 
         ret = -EINVAL;
         if ( (d == current->domain) || /* no domain_pause() */
-             (max > domain_max_vcpus(d)) )
+             (max != d->max_vcpus) )   /* max_vcpus set up in createdomain */
             break;
 
-        /* Until Xenoprof can dynamically grow its vcpu-s array... */
-        if ( d->xenoprof )
-        {
-            ret = -EAGAIN;
-            break;
-        }
-
         /* Needed, for example, to ensure writable p.t. state is synced. */
         domain_pause(d);
 
@@ -581,38 +574,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             }
         }
 
-        /* We cannot reduce maximum VCPUs. */
-        ret = -EINVAL;
-        if ( (max < d->max_vcpus) && (d->vcpu[max] != NULL) )
-            goto maxvcpu_out;
-
-        /*
-         * For now don't allow increasing the vcpu count from a non-zero
-         * value: This code and all readers of d->vcpu would otherwise need
-         * to be converted to use RCU, but at present there's no tools side
-         * code path that would issue such a request.
-         */
-        ret = -EBUSY;
-        if ( (d->max_vcpus > 0) && (max > d->max_vcpus) )
-            goto maxvcpu_out;
-
         ret = -ENOMEM;
         online = cpupool_domain_cpumask(d);
-        if ( max > d->max_vcpus )
-        {
-            struct vcpu **vcpus;
-
-            BUG_ON(d->vcpu != NULL);
-            BUG_ON(d->max_vcpus != 0);
-
-            if ( (vcpus = xzalloc_array(struct vcpu *, max)) == NULL )

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 581

Quoted 10 lines
xen/common/domctl.c +0 -7
-                goto maxvcpu_out;
-
-            /* Install vcpu array /then/ update max_vcpus. */
-            d->vcpu = vcpus;
-            smp_wmb();
-            d->max_vcpus = max;
-        }
 
         for ( i = 0; i < max; i++ )
         {

With all of this dropped, I think the domctl should be renamed. By dropping its "max" input at the same time, there would then also no longer be a need to check that the value matches what was stored during domain creation.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#46 lore raw

Re: [PATCH v2 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 13.08.18 at 12:01, <[email protected]> wrote:
xen/common/domain.c +0 -0
@@ -423,6 +436,11 @@ struct domain *domain_create(domid_t domid,
 
     sched_destroy_domain(d);
 
Quoted 9 lines

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

Quoted 7 lines
xen/common/domain.c +5 -0
+    if ( d->max_vcpus )
+    {
+        d->max_vcpus = 0;
+        XFREE(d->vcpu);
+    }
     if ( init_status & INIT_arch )
         arch_domain_destroy(d);

I'm not sure it is a good idea to free the vcpus this early, in particular before arch_domain_destroy().

Actually, this positioning is deliberate, so as not to change the current behaviour of arch_domain_destroy().

Before this patch, d-vcpu[] was guaranteed to be NULL in the arch_domain_destroy() call, and I don't currently trust it to work properly if changed.  All of this cleanup logic needs further improvements.

Quoted 58 lines
Quoted 58 lines
xen/common/domctl.c +1 -38
@@ -554,16 +554,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 
         ret = -EINVAL;
         if ( (d == current->domain) || /* no domain_pause() */
-             (max > domain_max_vcpus(d)) )
+             (max != d->max_vcpus) )   /* max_vcpus set up in createdomain */
             break;
 
-        /* Until Xenoprof can dynamically grow its vcpu-s array... */
-        if ( d->xenoprof )
-        {
-            ret = -EAGAIN;
-            break;
-        }
-
         /* Needed, for example, to ensure writable p.t. state is synced. */
         domain_pause(d);
 
@@ -581,38 +574,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             }
         }
 
-        /* We cannot reduce maximum VCPUs. */
-        ret = -EINVAL;
-        if ( (max < d->max_vcpus) && (d->vcpu[max] != NULL) )
-            goto maxvcpu_out;
-
-        /*
-         * For now don't allow increasing the vcpu count from a non-zero
-         * value: This code and all readers of d->vcpu would otherwise need
-         * to be converted to use RCU, but at present there's no tools side
-         * code path that would issue such a request.
-         */
-        ret = -EBUSY;
-        if ( (d->max_vcpus > 0) && (max > d->max_vcpus) )
-            goto maxvcpu_out;
-
         ret = -ENOMEM;
         online = cpupool_domain_cpumask(d);
-        if ( max > d->max_vcpus )
-        {
-            struct vcpu **vcpus;
-
-            BUG_ON(d->vcpu != NULL);
-            BUG_ON(d->max_vcpus != 0);
-
-            if ( (vcpus = xzalloc_array(struct vcpu *, max)) == NULL )
-                goto maxvcpu_out;
-
-            /* Install vcpu array /then/ update max_vcpus. */
-            d->vcpu = vcpus;
-            smp_wmb();
-            d->max_vcpus = max;
-        }
 
Quoted 6 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 581

Quoted 2 lines
xen/common/domctl.c +0 -0
         for ( i = 0; i < max; i++ )
         {

With all of this dropped, I think the domctl should be renamed. By dropping its "max" input at the same time, there would then also no longer be a need to check that the value matches what was stored during domain creation.

I'm still looking to eventually delete the hypercall, but we need to be able to clean up all domain/vcpu allocations without calling complete_domain_destroy, or rearrange the entry logic so complete_domain_destroy() can be reused for a domain which isn't currently in the domlist.

Unfortunately, I think this is going to be fairly complicated, I think.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#47 lore raw

Re: [PATCH v2 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 15.08.18 at 16:03, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 13.08.18 at 12:01, <[email protected]> wrote:
xen/common/domain.c +0 -0
@@ -423,6 +436,11 @@ struct domain *domain_create(domid_t domid,
 
     sched_destroy_domain(d);
 
Quoted 9 lines

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

Quoted 7 lines
xen/common/domain.c +5 -0
+    if ( d->max_vcpus )
+    {
+        d->max_vcpus = 0;
+        XFREE(d->vcpu);
+    }
     if ( init_status & INIT_arch )
         arch_domain_destroy(d);

I'm not sure it is a good idea to free the vcpus this early, in particular before arch_domain_destroy().

Quoted 6 lines

Actually, this positioning is deliberate, so as not to change the current behaviour of arch_domain_destroy().

Before this patch, d-vcpu[] was guaranteed to be NULL in the arch_domain_destroy() call, and I don't currently trust it to work properly if changed. All of this cleanup logic needs further improvements.

Oh, good point.

Quoted 64 lines
Quoted 57 lines
Quoted 57 lines
xen/common/domctl.c +1 -38
@@ -554,16 +554,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 
         ret = -EINVAL;
         if ( (d == current->domain) || /* no domain_pause() */
-             (max > domain_max_vcpus(d)) )
+             (max != d->max_vcpus) )   /* max_vcpus set up in createdomain */
             break;
 
-        /* Until Xenoprof can dynamically grow its vcpu-s array... */
-        if ( d->xenoprof )
-        {
-            ret = -EAGAIN;
-            break;
-        }
-
         /* Needed, for example, to ensure writable p.t. state is synced. */
         domain_pause(d);
 
@@ -581,38 +574,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             }
         }
 
-        /* We cannot reduce maximum VCPUs. */
-        ret = -EINVAL;
-        if ( (max < d->max_vcpus) && (d->vcpu[max] != NULL) )
-            goto maxvcpu_out;
-
-        /*
-         * For now don't allow increasing the vcpu count from a non-zero
-         * value: This code and all readers of d->vcpu would otherwise need
-         * to be converted to use RCU, but at present there's no tools side
-         * code path that would issue such a request.
-         */
-        ret = -EBUSY;
-        if ( (d->max_vcpus > 0) && (max > d->max_vcpus) )
-            goto maxvcpu_out;
-
         ret = -ENOMEM;
         online = cpupool_domain_cpumask(d);
-        if ( max > d->max_vcpus )
-        {
-            struct vcpu **vcpus;
-
-            BUG_ON(d->vcpu != NULL);
-            BUG_ON(d->max_vcpus != 0);
-
-            if ( (vcpus = xzalloc_array(struct vcpu *, max)) == NULL )
-                goto maxvcpu_out;
-
-            /* Install vcpu array /then/ update max_vcpus. */
-            d->vcpu = vcpus;
-            smp_wmb();
-            d->max_vcpus = max;
-        }
 
Quoted 6 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 581

Quoted 2 lines
xen/common/domctl.c +0 -0
         for ( i = 0; i < max; i++ )
         {

With all of this dropped, I think the domctl should be renamed. By dropping its "max" input at the same time, there would then also no longer be a need to check that the value matches what was stored during domain creation.

Quoted 7 lines

I'm still looking to eventually delete the hypercall, but we need to be able to clean up all domain/vcpu allocations without calling complete_domain_destroy, or rearrange the entry logic so complete_domain_destroy() can be reused for a domain which isn't currently in the domlist.

Unfortunately, I think this is going to be fairly complicated, I think.

Especially when we expect this to take some time, I think it would be quite helpful for the domctl to actually say what it does until then, rather than retaining its current (then misleading) name.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#48 lore raw

Re: [PATCH v2 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 70 lines · Jan Beulich
Quoted 70 lines
Quoted 58 lines
Quoted 58 lines
xen/common/domctl.c +1 -38
@@ -554,16 +554,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 
         ret = -EINVAL;
         if ( (d == current->domain) || /* no domain_pause() */
-             (max > domain_max_vcpus(d)) )
+             (max != d->max_vcpus) )   /* max_vcpus set up in createdomain */
             break;
 
-        /* Until Xenoprof can dynamically grow its vcpu-s array... */
-        if ( d->xenoprof )
-        {
-            ret = -EAGAIN;
-            break;
-        }
-
         /* Needed, for example, to ensure writable p.t. state is synced. */
         domain_pause(d);
 
@@ -581,38 +574,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             }
         }
 
-        /* We cannot reduce maximum VCPUs. */
-        ret = -EINVAL;
-        if ( (max < d->max_vcpus) && (d->vcpu[max] != NULL) )xc_domain_max_vcpus
-            goto maxvcpu_out;
-
-        /*
-         * For now don't allow increasing the vcpu count from a non-zero
-         * value: This code and all readers of d->vcpu would otherwise need
-         * to be converted to use RCU, but at present there's no tools side
-         * code path that would issue such a request.
-         */
-        ret = -EBUSY;
-        if ( (d->max_vcpus > 0) && (max > d->max_vcpus) )
-            goto maxvcpu_out;
-
         ret = -ENOMEM;
         online = cpupool_domain_cpumask(d);
-        if ( max > d->max_vcpus )
-        {
-            struct vcpu **vcpus;
-
-            BUG_ON(d->vcpu != NULL);
-            BUG_ON(d->max_vcpus != 0);
-
-            if ( (vcpus = xzalloc_array(struct vcpu *, max)) == NULL )
-                goto maxvcpu_out;
-
-            /* Install vcpu array /then/ update max_vcpus. */
-            d->vcpu = vcpus;
-            smp_wmb();
-            d->max_vcpus = max;
-        }
 
Quoted 6 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 581

Quoted 2 lines
xen/common/domctl.c +0 -0
         for ( i = 0; i < max; i++ )
         {

With all of this dropped, I think the domctl should be renamed. By dropping its "max" input at the same time, there would then also no longer be a need to check that the value matches what was stored during domain creation.

I'm still looking to eventually delete the hypercall, but we need to be able to clean up all domain/vcpu allocations without calling complete_domain_destroy, or rearrange the entry logic so complete_domain_destroy() can be reused for a domain which isn't currently in the domlist.

Quoted 4 lines
Quoted 1 line

Unfortunately, I think this is going to be fairly complicated, I think.

Especially when we expect this to take some time, I think it would be quite helpful for the domctl to actually say what it does until then, rather than retaining its current (then misleading) name.

Renaming the domctl means renaming xc_domain_max_vcpus(), and the python/ocaml stubs, the latter of which does have external users.

In this case, leaving things unchanged is the least disruptive course of action.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#49 lore raw

Re: [PATCH v2 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 75 lines
Quoted 1 line
Quoted 1 line · On 29.08.18 at 12:36, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 4 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t)

Quoted 4 lines
xen/common/domctl.c +0 -0
@@ -554,16 +554,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) 

u_domctl)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)

Quoted 5 lines
xen/common/domctl.c +1 -1
         ret = -EINVAL;
         if ( (d == current->domain) || /* no domain_pause() */
-             (max > domain_max_vcpus(d)) )
+             (max != d->max_vcpus) )   /* max_vcpus set up in createdomain 

*/

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
xen/common/domctl.c +0 -7
             break;
 
-        /* Until Xenoprof can dynamically grow its vcpu-s array... */
-        if ( d->xenoprof )
-        {
-            ret = -EAGAIN;
-            break;
-        }
-
         /* Needed, for example, to ensure writable p.t. state is synced. */
         domain_pause(d);
 
Quoted 1 line
Quoted 1 line
Quoted 1 line

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t)

Quoted 1 line
xen/common/domctl.c +0 -0
@@ -581,38 +574,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) 

u_domctl)

Quoted 48 lines
Quoted 48 lines
Quoted 36 lines
Quoted 36 lines
xen/common/domctl.c +0 -30
             }
         }
 
-        /* We cannot reduce maximum VCPUs. */
-        ret = -EINVAL;
-        if ( (max < d->max_vcpus) && (d->vcpu[max] != NULL) )xc_domain_max_vcpus
-            goto maxvcpu_out;
-
-        /*
-         * For now don't allow increasing the vcpu count from a non-zero
-         * value: This code and all readers of d->vcpu would otherwise need
-         * to be converted to use RCU, but at present there's no tools side
-         * code path that would issue such a request.
-         */
-        ret = -EBUSY;
-        if ( (d->max_vcpus > 0) && (max > d->max_vcpus) )
-            goto maxvcpu_out;
-
         ret = -ENOMEM;
         online = cpupool_domain_cpumask(d);
-        if ( max > d->max_vcpus )
-        {
-            struct vcpu **vcpus;
-
-            BUG_ON(d->vcpu != NULL);
-            BUG_ON(d->max_vcpus != 0);
-
-            if ( (vcpus = xzalloc_array(struct vcpu *, max)) == NULL )
-                goto maxvcpu_out;
-
-            /* Install vcpu array /then/ update max_vcpus. */
-            d->vcpu = vcpus;
-            smp_wmb();
-            d->max_vcpus = max;
-        }
 
Quoted 6 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 581

Quoted 2 lines
xen/common/domctl.c +0 -0
         for ( i = 0; i < max; i++ )
         {

With all of this dropped, I think the domctl should be renamed. By dropping its "max" input at the same time, there would then also no longer be a need to check that the value matches what was stored during domain creation.

I'm still looking to eventually delete the hypercall, but we need to be able to clean up all domain/vcpu allocations without calling complete_domain_destroy, or rearrange the entry logic so complete_domain_destroy() can be reused for a domain which isn't currently in the domlist.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Unfortunately, I think this is going to be fairly complicated, I think.

Especially when we expect this to take some time, I think it would be quite helpful for the domctl to actually say what it does until then, rather than retaining its current (then misleading) name.

Renaming the domctl means renaming xc_domain_max_vcpus(), and the python/ocaml stubs, the latter of which does have external users.

This is an option, but the libxc and higher layer functions could as well be left alone, perhaps with a comment added to the function you name explaining why its name doesn't match the domctl it uses.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#50 lore raw

Re: [PATCH v2 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 75 lines · Jan Beulich
Quoted 75 lines
Quoted 1 line
Quoted 1 line · On 29.08.18 at 12:36, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 3 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t)

Quoted 3 lines
xen/common/domctl.c +0 -0
@@ -554,16 +554,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) 

u_domctl)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)

Quoted 5 lines
xen/common/domctl.c +1 -1
         ret = -EINVAL;
         if ( (d == current->domain) || /* no domain_pause() */
-             (max > domain_max_vcpus(d)) )
+             (max != d->max_vcpus) )   /* max_vcpus set up in createdomain 

*/

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
xen/common/domctl.c +0 -7
             break;
 
-        /* Until Xenoprof can dynamically grow its vcpu-s array... */
-        if ( d->xenoprof )
-        {
-            ret = -EAGAIN;
-            break;
-        }
-
         /* Needed, for example, to ensure writable p.t. state is synced. */
         domain_pause(d);
 
Quoted 1 line
Quoted 1 line
Quoted 1 line

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t)

Quoted 1 line
xen/common/domctl.c +0 -0
@@ -581,38 +574,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) 

u_domctl)

Quoted 49 lines
Quoted 49 lines
Quoted 36 lines
Quoted 36 lines
xen/common/domctl.c +0 -30
             }
         }
 
-        /* We cannot reduce maximum VCPUs. */
-        ret = -EINVAL;
-        if ( (max < d->max_vcpus) && (d->vcpu[max] != NULL) )xc_domain_max_vcpus
-            goto maxvcpu_out;
-
-        /*
-         * For now don't allow increasing the vcpu count from a non-zero
-         * value: This code and all readers of d->vcpu would otherwise need
-         * to be converted to use RCU, but at present there's no tools side
-         * code path that would issue such a request.
-         */
-        ret = -EBUSY;
-        if ( (d->max_vcpus > 0) && (max > d->max_vcpus) )
-            goto maxvcpu_out;
-
         ret = -ENOMEM;
         online = cpupool_domain_cpumask(d);
-        if ( max > d->max_vcpus )
-        {
-            struct vcpu **vcpus;
-
-            BUG_ON(d->vcpu != NULL);
-            BUG_ON(d->max_vcpus != 0);
-
-            if ( (vcpus = xzalloc_array(struct vcpu *, max)) == NULL )
-                goto maxvcpu_out;
-
-            /* Install vcpu array /then/ update max_vcpus. */
-            d->vcpu = vcpus;
-            smp_wmb();
-            d->max_vcpus = max;
-        }
 
Quoted 6 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 581

Quoted 2 lines
xen/common/domctl.c +0 -0
         for ( i = 0; i < max; i++ )
         {

With all of this dropped, I think the domctl should be renamed. By dropping its "max" input at the same time, there would then also no longer be a need to check that the value matches what was stored during domain creation.

I'm still looking to eventually delete the hypercall, but we need to be able to clean up all domain/vcpu allocations without calling complete_domain_destroy, or rearrange the entry logic so complete_domain_destroy() can be reused for a domain which isn't currently in the domlist.

Unfortunately, I think this is going to be fairly complicated, I think.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Especially when we expect this to take some time, I think it would be quite helpful for the domctl to actually say what it does until then, rather than retaining its current (then misleading) name.

Renaming the domctl means renaming xc_domain_max_vcpus(), and the python/ocaml stubs, the latter of which does have external users.

This is an option, but the libxc and higher layer functions could as well be left alone, perhaps with a comment added to the function you name explaining why its name doesn't match the domctl it uses.

And what good will that do?  You'll now have inconsistent naming, which is worse.

Its either all or nothing, and there are several good reasons to not change everything.  I definitely don't think renaming the infrastructure is a constructive use of my time, or anyone elses for that matter.

I'm open to the idea of leaving a comment by the implementation of
XEN_DOMCTL_max_vcpus: explaining its change in behaviour, but I think that the extent of what is reasonable to do here.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#51 lore raw

Re: [PATCH v2 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 89 lines
Quoted 1 line
Quoted 1 line · On 29.08.18 at 14:29, <[email protected]> wrote:
Quoted 75 lines · Jan Beulich
Quoted 75 lines
Quoted 1 line
Quoted 1 line · On 29.08.18 at 12:36, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 3 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t)

Quoted 3 lines
xen/common/domctl.c +0 -0
@@ -554,16 +554,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) 

u_domctl)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) · line 556

Quoted 5 lines
xen/common/domctl.c +1 -1
         ret = -EINVAL;
         if ( (d == current->domain) || /* no domain_pause() */
-             (max > domain_max_vcpus(d)) )
+             (max != d->max_vcpus) )   /* max_vcpus set up in createdomain 

*/

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
xen/common/domctl.c +0 -7
             break;
 
-        /* Until Xenoprof can dynamically grow its vcpu-s array... */
-        if ( d->xenoprof )
-        {
-            ret = -EAGAIN;
-            break;
-        }
-
         /* Needed, for example, to ensure writable p.t. state is synced. */
         domain_pause(d);
 
Quoted 1 line
Quoted 1 line
Quoted 1 line

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t)

Quoted 1 line
xen/common/domctl.c +0 -0
@@ -581,38 +574,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) 

u_domctl)

Quoted 49 lines
Quoted 49 lines
Quoted 36 lines
Quoted 36 lines
xen/common/domctl.c +0 -30
             }
         }
 
-        /* We cannot reduce maximum VCPUs. */
-        ret = -EINVAL;
-        if ( (max < d->max_vcpus) && (d->vcpu[max] != NULL) )xc_domain_max_vcpus
-            goto maxvcpu_out;
-
-        /*
-         * For now don't allow increasing the vcpu count from a non-zero
-         * value: This code and all readers of d->vcpu would otherwise need
-         * to be converted to use RCU, but at present there's no tools side
-         * code path that would issue such a request.
-         */
-        ret = -EBUSY;
-        if ( (d->max_vcpus > 0) && (max > d->max_vcpus) )
-            goto maxvcpu_out;
-
         ret = -ENOMEM;
         online = cpupool_domain_cpumask(d);
-        if ( max > d->max_vcpus )
-        {
-            struct vcpu **vcpus;
-
-            BUG_ON(d->vcpu != NULL);
-            BUG_ON(d->max_vcpus != 0);
-
-            if ( (vcpus = xzalloc_array(struct vcpu *, max)) == NULL )
-                goto maxvcpu_out;
-
-            /* Install vcpu array /then/ update max_vcpus. */
-            d->vcpu = vcpus;
-            smp_wmb();
-            d->max_vcpus = max;
-        }
 
Quoted 6 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) · line 581

Quoted 2 lines
xen/common/domctl.c +0 -0
         for ( i = 0; i < max; i++ )
         {

With all of this dropped, I think the domctl should be renamed. By dropping its "max" input at the same time, there would then also no longer be a need to check that the value matches what was stored during domain creation.

I'm still looking to eventually delete the hypercall, but we need to be able to clean up all domain/vcpu allocations without calling complete_domain_destroy, or rearrange the entry logic so complete_domain_destroy() can be reused for a domain which isn't currently in the domlist.

Unfortunately, I think this is going to be fairly complicated, I think.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Especially when we expect this to take some time, I think it would be quite helpful for the domctl to actually say what it does until then, rather than retaining its current (then misleading) name.

Renaming the domctl means renaming xc_domain_max_vcpus(), and the python/ocaml stubs, the latter of which does have external users.

This is an option, but the libxc and higher layer functions could as well be left alone, perhaps with a comment added to the function you name explaining why its name doesn't match the domctl it uses.

And what good will that do? You'll now have inconsistent naming, which is worse.

Quoted 7 lines

Its either all or nothing, and there are several good reasons to not change everything. I definitely don't think renaming the infrastructure is a constructive use of my time, or anyone elses for that matter.

I'm open to the idea of leaving a comment by the implementation of
XEN_DOMCTL_max_vcpus: explaining its change in behaviour, but I think that the extent of what is reasonable to do here.

Well, I'll leave it to the other REST maintainers then.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#52 lore raw

PATCH v3 12/12 xen/domain: Allocate d->vcpu[] in domain_create()

In reply to Andrew Cooper

For ARM, the call to arch_domain_create() needs to have completed before domain_max_vcpus() will return the correct upper bound.

For each arch's dom0's, drop the temporary max_vcpus parameter, and allocation of dom0->vcpu.

With d->max_vcpus now correctly configured before evtchn_init(), the poll mask can be constructed suitably for the domain, rather than for the worst-case setting.

Due to the evtchn_init() fixes, it no longer calls domain_max_vcpus(), and ARM's two implementations of vgic_max_vcpus() no longer need work around the out-of-order call.

From this point on, d->max_vcpus and d->vcpus[] are valid for any domain which can be looked up by domid.

The XEN_DOMCTL_max_vcpus hypercall is modified to reject any call attempt with max != d->max_vcpus, which does match the older semantics (not that it is obvious from the code). The logic to allocate d->vcpu[] is dropped, but at this point the hypercall still needs making to allocate each vcpu.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: George Dunlap <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>

v2:
* Allocate in domain_create() rather than arch_domain_create().
* Retain domain_max_vcpus().
v3:
* Only drop the GIC_INVALID case in vgic_max_vcpus().
* Leave a note concerning the new behaviour of XEN_DOMCTL_max_vcpus in the interim before it gets deleted.

---
 xen/arch/arm/domain_build.c |  8 +-------
 xen/arch/arm/setup.c        |  2 +-
 xen/arch/arm/vgic.c         | 11 +----------
 xen/arch/arm/vgic/vgic.c    |  9 ---------
 xen/arch/x86/dom0_build.c   |  8 +-------
 xen/arch/x86/setup.c        |  2 +-
 xen/common/domain.c         | 18 ++++++++++++++++++
 xen/common/domctl.c         | 46 ++++++++-------------------------------------
 xen/common/event_channel.c  |  3 +--
 xen/include/xen/domain.h    |  2 +-
 10 files changed, 33 insertions(+), 76 deletions(-)
xen/arch/arm/domain_build.c +1 -7
index 6900a93..9ceb33d 100644
@@ -72,14 +72,8 @@ unsigned int __init dom0_max_vcpus(void)
     return opt_dom0_max_vcpus;
 }
 
-struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0,
-                                     unsigned int max_vcpus)
+struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0)
 {
-    dom0->vcpu = xzalloc_array(struct vcpu *, max_vcpus);
-    if ( !dom0->vcpu )
-        return NULL;
-    dom0->max_vcpus = max_vcpus;
-
     return alloc_vcpu(dom0, 0, 0);
 }
 
xen/arch/arm/setup.c +1 -1
index 048d5f3..01aaaab 100644
@@ -854,7 +854,7 @@ void __init start_xen(unsigned long boot_phys_offset,
     dom0_cfg.max_vcpus = dom0_max_vcpus();
 
     dom0 = domain_create(0, &dom0_cfg, true);
-    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0, dom0_cfg.max_vcpus) == NULL) )
+    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
             panic("Error creating domain 0");
 
     if ( construct_dom0(dom0) != 0)
xen/arch/arm/vgic.c +1 -10
index 7a2c455..5a4f082 100644
@@ -669,16 +669,7 @@ void vgic_free_virq(struct domain *d, unsigned int virq)
 
 unsigned int vgic_max_vcpus(const struct domain *d)
 {
-    /*
-     * Since evtchn_init would call domain_max_vcpus for poll_mask
-     * allocation when the vgic_ops haven't been initialised yet,
-     * we return MAX_VIRT_CPUS if d->arch.vgic.handler is null.
-     */
-    if ( !d->arch.vgic.handler )
-        return MAX_VIRT_CPUS;
-    else
-        return min_t(unsigned int, MAX_VIRT_CPUS,
-                     d->arch.vgic.handler->max_vcpus);
+    return min_t(unsigned int, MAX_VIRT_CPUS, d->arch.vgic.handler->max_vcpus);
 }
 
 /*
xen/arch/arm/vgic/vgic.c +0 -9
index 832632a..3272952 100644
@@ -955,15 +955,6 @@ unsigned int vgic_max_vcpus(const struct domain *d)
 
     switch ( d->arch.vgic.version )
     {
-    case GIC_INVALID:
-        /*
-         * Since evtchn_init would call domain_max_vcpus for poll_mask
-         * allocation before the VGIC has been initialised, we need to
-         * return some safe value in this case. As this is for allocation
-         * purposes, go with the maximum value.
-         */
-        vgic_vcpu_limit = MAX_VIRT_CPUS;
-        break;
     case GIC_V2:
         vgic_vcpu_limit = VGIC_V2_MAX_CPUS;
         break;
xen/arch/x86/dom0_build.c +1 -7
index b42eac3..423fdec 100644
@@ -199,17 +199,11 @@ unsigned int __init dom0_max_vcpus(void)
     return max_vcpus;
 }
 
-struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0,
-                                     unsigned int max_vcpus)
+struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0)
 {
     dom0->node_affinity = dom0_nodes;
     dom0->auto_node_affinity = !dom0_nr_pxms;
 
-    dom0->vcpu = xzalloc_array(struct vcpu *, max_vcpus);
-    if ( !dom0->vcpu )
-        return NULL;
-    dom0->max_vcpus = max_vcpus;
-
     return dom0_setup_vcpu(dom0, 0,
                            cpumask_last(&dom0_cpus) /* so it wraps around to first pcpu */);
 }
xen/arch/x86/setup.c +1 -1
index 3ffcb7a..c9e66ea 100644
@@ -1701,7 +1701,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     /* Create initial domain 0. */
     dom0 = domain_create(get_initial_domain_id(), &dom0_cfg, !pv_shim);
-    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0, dom0_cfg.max_vcpus) == NULL) )
+    if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
         panic("Error creating domain 0");
 
     /* Grab the DOM0 command line. */
xen/common/domain.c +18 -0
index 8143532..f64ad5f 100644
@@ -338,6 +338,19 @@ struct domain *domain_create(domid_t domid,
 
     if ( !is_idle_domain(d) )
     {
+        /* Check d->max_vcpus and allocate d->vcpu[]. */
+        err = -EINVAL;
+        if ( config->max_vcpus < 1 ||
+             config->max_vcpus > domain_max_vcpus(d) )
+            goto fail;
+
+        err = -ENOMEM;
+        d->vcpu = xzalloc_array(struct vcpu *, config->max_vcpus);
+        if ( !d->vcpu )
+            goto fail;
+
+        d->max_vcpus = config->max_vcpus;
+
         watchdog_domain_init(d);
         init_status |= INIT_watchdog;
 
@@ -422,6 +435,11 @@ struct domain *domain_create(domid_t domid,
 
     sched_destroy_domain(d);
 
+    if ( d->max_vcpus )
+    {
+        d->max_vcpus = 0;
+        XFREE(d->vcpu);
+    }
     if ( init_status & INIT_arch )
         arch_domain_destroy(d);
     if ( init_status & INIT_gnttab )
xen/common/domctl.c +8 -38

68 lines not on this page · raw message

xen/common/event_channel.c +1 -2
index 41cbbae..381f30e 100644
@@ -1303,8 +1303,7 @@ int evtchn_init(struct domain *d, unsigned int max_port)
     evtchn_from_port(d, 0)->state = ECS_RESERVED;
 
 #if MAX_VIRT_CPUS > BITS_PER_LONG
-    d->poll_mask = xzalloc_array(unsigned long,
-                                 BITS_TO_LONGS(domain_max_vcpus(d)));
+    d->poll_mask = xzalloc_array(unsigned long, BITS_TO_LONGS(d->max_vcpus));
     if ( !d->poll_mask )
     {
         free_evtchn_bucket(d, d->evtchn);
xen/include/xen/domain.h +1 -1
index 651205d..ce31999 100644
@@ -17,7 +17,7 @@ struct vcpu *alloc_vcpu(
     struct domain *d, unsigned int vcpu_id, unsigned int cpu_id);
 
 unsigned int dom0_max_vcpus(void);
-struct vcpu *alloc_dom0_vcpu0(struct domain *dom0, unsigned int max_vcpus);
+struct vcpu *alloc_dom0_vcpu0(struct domain *dom0);
 
 int vcpu_reset(struct vcpu *);
 int vcpu_up(struct vcpu *v);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v3 12/12
#53 lore raw

Re: [PATCH v3 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 29.08.18 at 16:40, <[email protected]> wrote:

For ARM, the call to arch_domain_create() needs to have completed before domain_max_vcpus() will return the correct upper bound.

For each arch's dom0's, drop the temporary max_vcpus parameter, and allocation of dom0->vcpu.

With d->max_vcpus now correctly configured before evtchn_init(), the poll mask can be constructed suitably for the domain, rather than for the worst-case setting.

Due to the evtchn_init() fixes, it no longer calls domain_max_vcpus(), and ARM's two implementations of vgic_max_vcpus() no longer need work around the out-of-order call.

From this point on, d->max_vcpus and d->vcpus[] are valid for any domain which can be looked up by domid.

Quoted 6 lines

The XEN_DOMCTL_max_vcpus hypercall is modified to reject any call attempt with max != d->max_vcpus, which does match the older semantics (not that it is obvious from the code). The logic to allocate d->vcpu[] is dropped, but at this point the hypercall still needs making to allocate each vcpu.

in principle, but as said before the lack of renaming of the domctl makes my ack dependent upon some other REST maintainer agreeing with your position there (the more that you've added the comment to the implementation rather than the public header).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#54 lore raw

Re: [PATCH v3 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 23 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 29.08.18 at 16:40, <[email protected]> wrote:

For ARM, the call to arch_domain_create() needs to have completed before domain_max_vcpus() will return the correct upper bound.

For each arch's dom0's, drop the temporary max_vcpus parameter, and allocation of dom0->vcpu.

With d->max_vcpus now correctly configured before evtchn_init(), the poll mask can be constructed suitably for the domain, rather than for the worst-case setting.

Due to the evtchn_init() fixes, it no longer calls domain_max_vcpus(), and ARM's two implementations of vgic_max_vcpus() no longer need work around the out-of-order call.

From this point on, d->max_vcpus and d->vcpus[] are valid for any domain which can be looked up by domid.

The XEN_DOMCTL_max_vcpus hypercall is modified to reject any call attempt with max != d->max_vcpus, which does match the older semantics (not that it is obvious from the code). The logic to allocate d->vcpu[] is dropped, but at this point the hypercall still needs making to allocate each vcpu.

Quoted 7 lines
Quoted 1 line

in principle, but as said before the lack of renaming of the domctl makes my ack dependent upon some other REST maintainer agreeing with your position there (the more that you've added the comment to the implementation rather than the public header).

I don't see much value in renaming something that is due to be removed soon.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#55 lore raw

Re: [PATCH v3 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 31.08.18 at 12:33, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 29.08.18 at 16:40, <[email protected]> wrote:

For ARM, the call to arch_domain_create() needs to have completed before domain_max_vcpus() will return the correct upper bound.

For each arch's dom0's, drop the temporary max_vcpus parameter, and allocation of dom0->vcpu.

With d->max_vcpus now correctly configured before evtchn_init(), the poll mask can be constructed suitably for the domain, rather than for the worst-case setting.

Due to the evtchn_init() fixes, it no longer calls domain_max_vcpus(), and ARM's two implementations of vgic_max_vcpus() no longer need work around the out-of-order call.

From this point on, d->max_vcpus and d->vcpus[] are valid for any domain which can be looked up by domid.

The XEN_DOMCTL_max_vcpus hypercall is modified to reject any call attempt with max != d->max_vcpus, which does match the older semantics (not that it is obvious from the code). The logic to allocate d->vcpu[] is dropped, but at this point the hypercall still needs making to allocate each vcpu.

Quoted 8 lines
Quoted 5 lines

in principle, but as said before the lack of renaming of the domctl makes my ack dependent upon some other REST maintainer agreeing with your position there (the more that you've added the comment to the implementation rather than the public header).

I don't see much value in renaming something that is due to be removed soon.

I would agree if "soon" meant "soon" for sure. But we all know how things get delayed. What I'd like to avoid is shipping 4.12 with a mis-named domctl.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#56 lore raw

Re: [PATCH v3 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

(+ Juergen)

Quoted 33 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 31.08.18 at 12:33, <[email protected]> wrote:
Quoted 30 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 29.08.18 at 16:40, <[email protected]> wrote:

For ARM, the call to arch_domain_create() needs to have completed before domain_max_vcpus() will return the correct upper bound.

For each arch's dom0's, drop the temporary max_vcpus parameter, and allocation of dom0->vcpu.

With d->max_vcpus now correctly configured before evtchn_init(), the poll mask can be constructed suitably for the domain, rather than for the worst-case setting.

Due to the evtchn_init() fixes, it no longer calls domain_max_vcpus(), and ARM's two implementations of vgic_max_vcpus() no longer need work around the out-of-order call.

From this point on, d->max_vcpus and d->vcpus[] are valid for any domain which
can be looked up by domid.

Quoted 6 lines

The XEN_DOMCTL_max_vcpus hypercall is modified to reject any call attempt with max != d->max_vcpus, which does match the older semantics (not that it is obvious from the code). The logic to allocate d->vcpu[] is dropped, but at this point the hypercall still needs making to allocate each vcpu.

in principle, but as said before the lack of renaming of the domctl makes my ack dependent upon some other REST maintainer agreeing with your position there (the more that you've added the comment to the implementation rather than the public header).

Quoted 6 lines
Quoted 2 lines

I don't see much value in renaming something that is due to be removed soon.

I would agree if "soon" meant "soon" for sure. But we all know how things get delayed. What I'd like to avoid is shipping 4.12 with a mis-named domctl.

But that would be a waste of our time today if the DOMCTL is actually removed by Xen 4.12.

Can we delay the renaming until 4.12 freeze? If the removal does not make it, then we can discuss whether we want to rename the DOMCTL.

I guess the Juergen could track and remind us around the code freeze?

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#57 lore raw

Re: [PATCH v3 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 53 lines · Julien Grall

(+ Juergen)

Quoted 43 lines · Jan Beulich
Quoted 43 lines
Quoted 1 line
Quoted 1 line · On 31.08.18 at 12:33, <[email protected]> wrote:
Quoted 40 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 29.08.18 at 16:40, <[email protected]> wrote:

For ARM, the call to arch_domain_create() needs to have completed before
domain_max_vcpus() will return the correct upper bound.

For each arch's dom0's, drop the temporary max_vcpus parameter, and allocation
of dom0->vcpu.

With d->max_vcpus now correctly configured before evtchn_init(), the poll mask
can be constructed suitably for the domain, rather than for the worst-case
setting.

Due to the evtchn_init() fixes, it no longer calls domain_max_vcpus(), and
ARM's two implementations of vgic_max_vcpus() no longer need work around the
out-of-order call.

 From this point on, d->max_vcpus and d->vcpus[] are valid for any domain which
can be looked up by domid.

The XEN_DOMCTL_max_vcpus hypercall is modified to reject any call attempt with
max != d->max_vcpus, which does match the older semantics (not that it is
obvious from the code).  The logic to allocate d->vcpu[] is dropped, but at
this point the hypercall still needs making to allocate each vcpu.

Quoted 1 line

in principle, but as said before the lack of renaming of the domctl makes my ack dependent upon some other REST maintainer agreeing with your position there (the more that you've added the comment to the implementation rather than the public header).

Quoted 6 lines
Quoted 2 lines

I don't see much value in renaming something that is due to be removed soon.

I would agree if "soon" meant "soon" for sure. But we all know how things get delayed. What I'd like to avoid is shipping 4.12 with a mis-named domctl.

Quoted 7 lines

But that would be a waste of our time today if the DOMCTL is actually removed by Xen 4.12.

Can we delay the renaming until 4.12 freeze? If the removal does not make it, then we can discuss whether we want to rename the DOMCTL.

I guess the Juergen could track and remind us around the code freeze?

I'm fine with that.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#58 lore raw

Re: [PATCH v3 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

In reply to Jan Beulich
Quoted 31 lines · Jan Beulich
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 31.08.18 at 12:33, <[email protected]> wrote:
Quoted 29 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 29.08.18 at 16:40, <[email protected]> wrote:

For ARM, the call to arch_domain_create() needs to have completed before domain_max_vcpus() will return the correct upper bound.

For each arch's dom0's, drop the temporary max_vcpus parameter, and allocation of dom0->vcpu.

With d->max_vcpus now correctly configured before evtchn_init(), the poll mask can be constructed suitably for the domain, rather than for the worst-case setting.

Due to the evtchn_init() fixes, it no longer calls domain_max_vcpus(), and ARM's two implementations of vgic_max_vcpus() no longer need work around the out-of-order call.

From this point on, d->max_vcpus and d->vcpus[] are valid for any domain which can be looked up by domid.

Quoted 6 lines

The XEN_DOMCTL_max_vcpus hypercall is modified to reject any call attempt with max != d->max_vcpus, which does match the older semantics (not that it is obvious from the code). The logic to allocate d->vcpu[] is dropped, but at this point the hypercall still needs making to allocate each vcpu.

in principle, but as said before the lack of renaming of the domctl makes my ack dependent upon some other REST maintainer agreeing with your position there (the more that you've added the comment to the implementation rather than the public header).

Quoted 5 lines
Quoted 2 lines

I don't see much value in renaming something that is due to be removed soon.

I would agree if "soon" meant "soon" for sure. But we all know how things get delayed. What I'd like to avoid is shipping 4.12 with a mis-named domctl.

I do intend to get this fixed within the 4.12 timeframe.

However, irrespective of the timeframe, this isn't a hypercall which anyone is realistically going to look at.  If you want to get pedantic about naming, it should have been named set_max_vcpus from the outset.

This is one example where the effort required to adjust the inconsistency completely dwarfs the outcome.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v3 12/12
#59 lore raw

Re: [PATCH v3 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

In reply to Andrew Cooper

Hi Andrew,

Quoted 17 lines · Andrew Cooper

For ARM, the call to arch_domain_create() needs to have completed before domain_max_vcpus() will return the correct upper bound.

For each arch's dom0's, drop the temporary max_vcpus parameter, and allocation of dom0->vcpu.

With d->max_vcpus now correctly configured before evtchn_init(), the poll mask can be constructed suitably for the domain, rather than for the worst-case setting.

Due to the evtchn_init() fixes, it no longer calls domain_max_vcpus(), and ARM's two implementations of vgic_max_vcpus() no longer need work around the out-of-order call.

From this point on, d->max_vcpus and d->vcpus[] are valid for any domain which
can be looked up by domid.

Quoted 6 lines

The XEN_DOMCTL_max_vcpus hypercall is modified to reject any call attempt with max != d->max_vcpus, which does match the older semantics (not that it is obvious from the code). The logic to allocate d->vcpu[] is dropped, but at this point the hypercall still needs making to allocate each vcpu.

With one request below, for the ARM + Common code:

FAOD, I agree with your position to avoid the renaming.

[...]

Quoted 5 lines
xen/common/domctl.c +0 -0
index 58e51b2..8a803b3 100644

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 556

Quoted 10 lines
xen/common/domctl.c +7 -0
@@ -547,6 +547,13 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
          break;
      }
 
+    /*
+     * Note: The parameter passed to XEN_DOMCTL_max_vcpus must match the value
+     * passed to XEN_DOMCTL_createdomain.  This hypercall is in the process of
+     * being removed (once the failure paths in domain_create() have been
+     * improved), but is still required in the short term to allocate the
+     * vcpus themselves.
+     */

This comment might be more useful in the public header. This is usually the first place I would look for description of a domctl.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#60 lore raw

Re: [PATCH v3 12/12] xen/domain: Allocate d->vcpu[] in domain_create()

Quoted 58 lines · Julien Grall

Hi Andrew,

Quoted 31 lines · Andrew Cooper

For ARM, the call to arch_domain_create() needs to have completed before domain_max_vcpus() will return the correct upper bound.

For each arch's dom0's, drop the temporary max_vcpus parameter, and allocation
of dom0->vcpu.

With d->max_vcpus now correctly configured before evtchn_init(), the poll mask
can be constructed suitably for the domain, rather than for the worst-case
setting.

Due to the evtchn_init() fixes, it no longer calls domain_max_vcpus(), and
ARM's two implementations of vgic_max_vcpus() no longer need work around the
out-of-order call.

 From this point on, d->max_vcpus and d->vcpus[] are valid for any domain which
can be looked up by domid.

The XEN_DOMCTL_max_vcpus hypercall is modified to reject any call attempt with
max != d->max_vcpus, which does match the older semantics (not that it is
obvious from the code).  The logic to allocate d->vcpu[] is dropped, but at
this point the hypercall still needs making to allocate each vcpu.

Quoted 1 line

With one request below, for the ARM + Common code:

FAOD, I agree with your position to avoid the renaming.

[...]

Quoted 14 lines
xen/common/domctl.c +0 -0
index 58e51b2..8a803b3 100644
@@ -547,6 +547,13 @@ long
 do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
           break;
       }

  +    /*
+     * Note: The parameter passed to XEN_DOMCTL_max_vcpus must match the value
+     * passed to XEN_DOMCTL_createdomain.  This hypercall is in the process of
+     * being removed (once the failure paths in domain_create() have

Quoted 8 lines
Quoted 5 lines

been
+     * improved), but is still required in the short term to allocate the
+     * vcpus themselves.
+     */

This comment might be more useful in the public header. This is usually the first place I would look for description of a domctl.

Ok - will do.

That said, it is very likely that the next person to read this will be me when I finally remove it (hopefully in 4.12).

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#61 lore raw
In reply to Andrew Cooper
Quoted 2 lines · Andrew Cooper

This series can be found in git form here:
http://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen.git;a=shortlog;h=refs/heads/xen-create-v1

Is this the correct URL? The subject says v2 but this is branch v1.

Looking over the OCaml-related patches, I think they are looking good. Since we would like all code to be safe-string compliant I checked that OCaml values of type string are not being mutated but I would like Andrew to confirm this.

-- Christian

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#62 lore raw
Quoted 6 lines · Christian Lindig
Quoted 3 lines · Andrew Cooper

This series can be found in git form here:

http://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen.git;a=shortlog;h=refs/heads/xen-create-v1

Is this the correct URL? The subject says v2 but this is branch v1.

Oops yes.

http://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen.git;a=shortlog;h=refs/heads/xen-create-v2
works as well, and is the intended URL.

Quoted 5 lines

Looking over the OCaml-related patches, I think they are looking good. Since we would like all code to be safe-string compliant I checked that OCaml values of type string are not being mutated but I would like Andrew to confirm this.

There is no change to any string handling here.  The only string used during the domaincreate hypercall is the UUID string, which is only read by the stubs, not altered.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel