]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
tools/libxenforeignmemory: add a call to restrict the handle
authorPaul Durrant <paul.durrant@citrix.com>
Wed, 22 Mar 2017 11:25:25 +0000 (11:25 +0000)
committerWei Liu <wei.liu2@citrix.com>
Fri, 24 Mar 2017 12:23:47 +0000 (12:23 +0000)
Commit 8ef5f344d061 "tools/libxendevicemodel: add a call to restrict the
handle" added a function to the devicemodel interface to restrict
operations through the API to a specific domain, where a capable under-
lying privcmd driver exists.

This patch adds similar functionality to the xenforeignmemory API. This
will be necessary (as much as xendevicemodel restriction) for limiting
the scope of device models to specific domains.

NOTE: My patch to the linux kernel [1] added the appropriate checks to
      the foreign memory ioctls.

[1] https://git.kernel.org/cgit/linux/kernel/git/ostr/linux.git/commit/?id=4610d240

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/libs/foreignmemory/core.c
tools/libs/foreignmemory/freebsd.c
tools/libs/foreignmemory/include/xenforeignmemory.h
tools/libs/foreignmemory/libxenforeignmemory.map
tools/libs/foreignmemory/linux.c
tools/libs/foreignmemory/minios.c
tools/libs/foreignmemory/netbsd.c
tools/libs/foreignmemory/private.h
tools/libs/foreignmemory/solaris.c

index a872b9555d8f98aceda96ce307df7c5765778e70..0ebd4293b1fc0172d4d641545dabe79ec75a0488 100644 (file)
@@ -106,6 +106,12 @@ int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
     return osdep_xenforeignmemory_unmap(fmem, addr, num);
 }
 
+int xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                              domid_t domid)
+{
+    return osdep_xenforeignmemory_restrict(fmem, domid);
+}
+
 /*
  * Local variables:
  * mode: C
index ef08b6c4affb8ec7d771dde4275ccb42b224d2c9..f6cd08c4c0b1466b9b1046e195c5ae9fc4c12704 100644 (file)
@@ -96,6 +96,13 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
     return munmap(addr, num << PAGE_SHIFT);
 }
 
+int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                                    domid_t domid)
+{
+    errno = -EOPNOTSUPP;
+    return -1;
+}
+
 /*
  * Local variables:
  * mode: C
index 92b9277b75ed23e633d7628323a0e3caad0e81b6..d5be6481de6c0c52b30b3f71b4a555aa19604450 100644 (file)
@@ -115,6 +115,17 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom,
 int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
                            void *addr, size_t pages);
 
+/**
+ * This function restricts the use of this handle to the specified
+ * domain.
+ *
+ * @parm fmem handle to the open foreignmemory interface
+ * @parm domid the domain id
+ * @return 0 on success, -1 on failure.
+ */
+int xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                              domid_t domid);
+
 #endif
 
 /*
index df206b3cfbcf63a1ac75709b09ee7dd53fc3acdc..5c9806cf284fb06a6e00e054241939efd067a5cf 100644 (file)
@@ -4,5 +4,6 @@ VERS_1.0 {
                xenforeignmemory_close;
                xenforeignmemory_map;
                xenforeignmemory_unmap;
+               xenforeignmemory_restrict;
        local: *; /* Do not expose anything by default */
 };
index 423c7441bc87959fc9f87ef166162efe4ce451b8..320bb212fd7cf150a1f8bcf80b291d77dfc0ffd8 100644 (file)
@@ -272,6 +272,12 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
     return munmap(addr, num << PAGE_SHIFT);
 }
 
+int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                                    domid_t domid)
+{
+    return ioctl(fmem->fd, IOCTL_PRIVCMD_RESTRICT, &domid);
+}
+
 /*
  * Local variables:
  * mode: C
index 6dc97bda68fad405ab7fe14e15f21edec8521ed0..2dd491066305419649fa4dae6eaa8cdf612c53cb 100644 (file)
@@ -58,6 +58,13 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
     return munmap(addr, num << PAGE_SHIFT);
 }
 
+int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                                    domid_t domid)
+{
+    errno = -EOPNOTSUPP;
+    return -1;
+}
+
 /*
  * Local variables:
  * mode: C
index 08f49640b89baa6ed8840d2d64626e8b7c9ab17f..af3a1a4a0d8dc3044cb2757d0e7121c95cac0def 100644 (file)
@@ -100,6 +100,13 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
     return munmap(addr, num*XC_PAGE_SIZE);
 }
 
+int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                                    domid_t domid)
+{
+    errno = -EOPNOTSUPP;
+    return -1;
+}
+
 /*
  * Local variables:
  * mode: C
index 9cc7814e1679b913737304c443ab0a8024312e98..ed7ec7a43fd30317fddca7b90b2d8cf06ac975b0 100644 (file)
@@ -32,6 +32,9 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
 int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
                                  void *addr, size_t num);
 
+int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                                    domid_t domid);
+
 #if defined(__NetBSD__) || defined(__sun__)
 /* Strictly compat for those two only only */
 void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom,
index e925a291226ddacc6c8187d5038a3385bde7584d..fe7bb45e9e7336b05af466ef1bb2275252e247c0 100644 (file)
@@ -98,6 +98,13 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
     return munmap(addr, num*XC_PAGE_SIZE);
 }
 
+int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                                    domid_t domid)
+{
+    errno = -EOPNOTSUPP;
+    return -1;
+}
+
 /*
  * Local variables:
  * mode: C