]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
domctl: improve device assignment structure layout and use
authorJan Beulich <jbeulich@suse.com>
Tue, 13 Jun 2017 08:39:52 +0000 (10:39 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 13 Jun 2017 08:39:52 +0000 (10:39 +0200)
Avoid needless gaps. Make flags field mandatory for all three
operations (and rename it to fit the intended future purpose of
possibly holding more than just one flag).

Also correct a typo in a related domctl.h comment.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <julien.grall@arm.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/libxc/xc_domain.c
xen/drivers/passthrough/device_tree.c
xen/drivers/passthrough/pci.c
xen/include/public/domctl.h

index a447405903ff5c2323eb26818fc081af7a9f62fd..b1a286ecf4ce0813ba58e9e652d87783826b5ef5 100644 (file)
@@ -1488,7 +1488,7 @@ int xc_assign_device(
     xc_interface *xch,
     uint32_t domid,
     uint32_t machine_sbdf,
-    uint32_t flag)
+    uint32_t flags)
 {
     DECLARE_DOMCTL;
 
@@ -1496,7 +1496,7 @@ int xc_assign_device(
     domctl.domain = domid;
     domctl.u.assign_device.dev = XEN_DOMCTL_DEV_PCI;
     domctl.u.assign_device.u.pci.machine_sbdf = machine_sbdf;
-    domctl.u.assign_device.flag = flag;
+    domctl.u.assign_device.flags = flags;
 
     return do_domctl(xch, &domctl);
 }
@@ -1547,6 +1547,7 @@ int xc_test_assign_device(
     domctl.domain = domid;
     domctl.u.assign_device.dev = XEN_DOMCTL_DEV_PCI;
     domctl.u.assign_device.u.pci.machine_sbdf = machine_sbdf;
+    domctl.u.assign_device.flags = 0;
 
     return do_domctl(xch, &domctl);
 }
@@ -1562,6 +1563,7 @@ int xc_deassign_device(
     domctl.domain = domid;
     domctl.u.assign_device.dev = XEN_DOMCTL_DEV_PCI;
     domctl.u.assign_device.u.pci.machine_sbdf = machine_sbdf;
+    domctl.u.assign_device.flags = 0;
 
     return do_domctl(xch, &domctl);
 }
@@ -1588,7 +1590,7 @@ int xc_assign_dt_device(
      * DT doesn't own any RDM so actually DT has nothing to do
      * for any flag and here just fix that as 0.
      */
-    domctl.u.assign_device.flag = 0;
+    domctl.u.assign_device.flags = 0;
     set_xen_guest_handle(domctl.u.assign_device.u.dt.path, path);
 
     rc = do_domctl(xch, &domctl);
@@ -1617,6 +1619,7 @@ int xc_test_assign_dt_device(
     domctl.u.assign_device.dev = XEN_DOMCTL_DEV_DT;
     domctl.u.assign_device.u.dt.size = size;
     set_xen_guest_handle(domctl.u.assign_device.u.dt.path, path);
+    domctl.u.assign_device.flags = 0;
 
     rc = do_domctl(xch, &domctl);
 
@@ -1644,6 +1647,7 @@ int xc_deassign_dt_device(
     domctl.u.assign_device.dev = XEN_DOMCTL_DEV_DT;
     domctl.u.assign_device.u.dt.size = size;
     set_xen_guest_handle(domctl.u.assign_device.u.dt.path, path);
+    domctl.u.assign_device.flags = 0;
 
     rc = do_domctl(xch, &domctl);
 
index 79bf8bf5edb813c89902f5d8e5b30fd48681ba2b..99ed49ecd82abe7347db83250397ff761ca341ab 100644 (file)
@@ -147,11 +147,9 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d,
         if ( domctl->u.assign_device.dev != XEN_DOMCTL_DEV_DT )
             break;
 
-        if ( unlikely(d->is_dying) )
-        {
-            ret = -EINVAL;
+        ret = -EINVAL;
+        if ( d->is_dying || domctl->u.assign_device.flags )
             break;
-        }
 
         ret = dt_find_node_by_gpath(domctl->u.assign_device.u.dt.path,
                                     domctl->u.assign_device.u.dt.size,
@@ -176,6 +174,10 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d,
         if ( domctl->u.assign_device.dev != XEN_DOMCTL_DEV_DT )
             break;
 
+        ret = -EINVAL;
+        if ( domctl->u.assign_device.flags )
+            break;
+
         ret = dt_find_node_by_gpath(domctl->u.assign_device.u.dt.path,
                                     domctl->u.assign_device.u.dt.size,
                                     &dev);
@@ -197,6 +199,10 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d,
         if ( domctl->u.assign_device.dev != XEN_DOMCTL_DEV_DT )
             break;
 
+        ret = -EINVAL;
+        if ( domctl->u.assign_device.flags )
+            break;
+
         ret = dt_find_node_by_gpath(domctl->u.assign_device.u.dt.path,
                                     domctl->u.assign_device.u.dt.size,
                                     &dev);
index c8e2d2d9a9c4bda48d68d15869853c4733788b4e..6e7126b2e86de1ea467f5ff12e4fccfb01001b40 100644 (file)
@@ -1540,12 +1540,13 @@ int iommu_do_pci_domctl(
 {
     u16 seg;
     u8 bus, devfn;
-    u32 flag;
     int ret = 0;
     uint32_t machine_sbdf;
 
     switch ( domctl->cmd )
     {
+        unsigned int flags;
+
     case XEN_DOMCTL_get_device_group:
     {
         u32 max_sdevs;
@@ -1583,6 +1584,10 @@ int iommu_do_pci_domctl(
         if ( domctl->u.assign_device.dev != XEN_DOMCTL_DEV_PCI )
             break;
 
+        ret = -EINVAL;
+        if ( domctl->u.assign_device.flags )
+            break;
+
         machine_sbdf = domctl->u.assign_device.u.pci.machine_sbdf;
 
         ret = xsm_test_assign_device(XSM_HOOK, machine_sbdf);
@@ -1614,11 +1619,10 @@ int iommu_do_pci_domctl(
         if ( domctl->u.assign_device.dev != XEN_DOMCTL_DEV_PCI )
             break;
 
-        if ( unlikely(d->is_dying) )
-        {
-            ret = -EINVAL;
+        ret = -EINVAL;
+        flags = domctl->u.assign_device.flags;
+        if ( d->is_dying || (flags & ~XEN_DOMCTL_DEV_RDM_RELAXED) )
             break;
-        }
 
         machine_sbdf = domctl->u.assign_device.u.pci.machine_sbdf;
 
@@ -1629,15 +1633,9 @@ int iommu_do_pci_domctl(
         seg = machine_sbdf >> 16;
         bus = PCI_BUS(machine_sbdf);
         devfn = PCI_DEVFN2(machine_sbdf);
-        flag = domctl->u.assign_device.flag;
-        if ( flag & ~XEN_DOMCTL_DEV_RDM_RELAXED )
-        {
-            ret = -EINVAL;
-            break;
-        }
 
         ret = device_assigned(seg, bus, devfn) ?:
-              assign_device(d, seg, bus, devfn, flag);
+              assign_device(d, seg, bus, devfn, flags);
         if ( ret == -ERESTART )
             ret = hypercall_create_continuation(__HYPERVISOR_domctl,
                                                 "h", u_domctl);
@@ -1661,6 +1659,10 @@ int iommu_do_pci_domctl(
         if ( domctl->u.assign_device.dev != XEN_DOMCTL_DEV_PCI )
             break;
 
+        ret = -EINVAL;
+        if ( domctl->u.assign_device.flags )
+            break;
+
         machine_sbdf = domctl->u.assign_device.u.pci.machine_sbdf;
 
         ret = xsm_deassign_device(XSM_HOOK, d, machine_sbdf);
index 515c603dbce7ccfd0b7610dc4889545ab83d8f06..3f3b3ebaee1962248e2a0ebb4e165e509a84d4cc 100644 (file)
@@ -511,14 +511,17 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_sendtrigger_t);
  * XEN_DOMCTL_deassign_device: The behavior of this DOMCTL differs
  * between the different type of device:
  *  - PCI device (XEN_DOMCTL_DEV_PCI) will be reassigned to DOM0
- *  - DT device (XEN_DOMCTL_DT_PCI) will left unassigned. DOM0
+ *  - DT device (XEN_DOMCTL_DEV_DT) will left unassigned. DOM0
  *  will have to call XEN_DOMCTL_assign_device in order to use the
  *  device.
  */
 #define XEN_DOMCTL_DEV_PCI      0
 #define XEN_DOMCTL_DEV_DT       1
 struct xen_domctl_assign_device {
+    /* IN */
     uint32_t dev;   /* XEN_DOMCTL_DEV_* */
+    uint32_t flags;
+#define XEN_DOMCTL_DEV_RDM_RELAXED      1 /* assign only */
     union {
         struct {
             uint32_t machine_sbdf;   /* machine PCI ID of assigned device */
@@ -528,9 +531,6 @@ struct xen_domctl_assign_device {
             XEN_GUEST_HANDLE_64(char) path; /* path to the device tree node */
         } dt;
     } u;
-    /* IN */
-#define XEN_DOMCTL_DEV_RDM_RELAXED      1
-    uint32_t  flag;   /* flag of assigned device */
 };
 typedef struct xen_domctl_assign_device xen_domctl_assign_device_t;
 DEFINE_XEN_GUEST_HANDLE(xen_domctl_assign_device_t);