xen/domctl: Merge set_max_evtchn into createdomain
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 27 Feb 2018 17:39:37 +0000 (17:39 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 15 Aug 2018 18:40:28 +0000 (19:40 +0100)
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.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
15 files changed:
tools/flask/policy/modules/dom0.te
tools/flask/policy/modules/xen.if
tools/helpers/init-xenstore-domain.c
tools/libxc/include/xenctrl.h
tools/libxc/xc_domain.c
tools/libxl/libxl_create.c
tools/libxl/libxl_dom.c
tools/ocaml/libs/xc/xenctrl.ml
tools/ocaml/libs/xc/xenctrl.mli
tools/ocaml/libs/xc/xenctrl_stubs.c
tools/python/xen/lowlevel/xc/xc.c
xen/common/domctl.c
xen/include/public/domctl.h
xen/xsm/flask/hooks.c
xen/xsm/flask/policy/access_vectors

index bf794d9bdddbe671bf3e5ceaa8064f68c016b462..4eb3843d52d73d413b1f8b72db4eb75cc238433e 100644 (file)
@@ -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 };
index 7aefd0061e0dc41d5c66af295edacf379f476052..61b0e767150475420d43abde6cb7c56d9b41b638 100644 (file)
@@ -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;
index 785e5704cf187412667a7ec3beed70593859b19d..89c329c7c6b34a10a9f8eaed834b4580914d40b5 100644 (file)
@@ -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);
index 2c4ac329b9f658b248f1d2521fdf94b6adfe7eca..c626984aba446bc6afa774727ed1bc533bfe6520 100644 (file)
@@ -1081,18 +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 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.
index 0124cea8423375bef2288a34df5e45dd5662c778..2bc695c5972ce06ac764b3e05d2eff2c74f8dad2 100644 (file)
@@ -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)
index dd9d8c8c6992d328acbcde1273646ec70c35c4f7..b7b44e280b5ef007b727b81447347ffd5fc64787 100644 (file)
@@ -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) {
index c8a1dc7fd5cea9d2879776b0968e4ab27cf62ef5..eb401cf1d6d6aecbbfd22c9d7c0fe59a7d6af15c 100644 (file)
@@ -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);
index 3b7526e4ae8f9cafa7796afe6fa72bdbd70cf756..219355aefe07fbdd575f4fa24c85f9e5926f2d2a 100644 (file)
@@ -63,6 +63,7 @@ type domctl_create_config =
        ssidref: int32;
        handle: string;
        flags: domain_create_flag list;
+       max_evtchn_port: int;
        arch: arch_domainconfig;
 }
 
index d103a33ee8b79c28796ab4dd95ae193bdae9b9ef..c0c724b09d73cbfeff12a9d4804240cf38d0544e 100644 (file)
@@ -55,6 +55,7 @@ type domctl_create_config = {
   ssidref: int32;
   handle: string;
   flags: domain_create_flag list;
+  max_evtchn_port: int;
   arch: arch_domainconfig;
 }
 
index 0d4c4cb39130caaa1b0dfcd9e8e2ca0f9befb030..f8bdebadb17066bcb62d45129d05bf1a058bf541 100644 (file)
@@ -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
index 5a2923a940539184b57b7e17f12032ef139c6016..4dc6d1ca1e1e70be86c90d029eb06bab6a9add55 100644 (file)
@@ -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 };
index c86dc21e3e43028c7c142c7624d4a57a239607cf..3a68fc91cfde5735afe5d0b413f79a510b457fe7 100644 (file)
@@ -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;
index ad95a8e644f57f139a24ea2f0ce6d20be4912ac3..7fc07cce137f7d66c6258d9f11589a64b01653bb 100644 (file)
@@ -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;
 };
 
@@ -874,15 +881,6 @@ struct xen_domctl_set_broken_page_p2m {
     uint64_aligned_t pfn;
 };
 
-/*
- * 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;
index 7a3ccfad026167301ac32918744d1e8ee9d4e930..a4fbe62ac33c91ad79e9db0a7ecb1c01f6c44999 100644 (file)
@@ -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);
 
index c5d85486d0dcbe07550a8e2b23acaaabe870b34c..b768870f37f58e84263887a46d89a2de647a9825 100644 (file)
@@ -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