tools/libxc: Make the mem_access APIs generic
authorAravindh Puthiyaparambil <aravindp@cisco.com>
Wed, 16 Apr 2014 00:25:23 +0000 (17:25 -0700)
committerTim Deegan <tim@xen.org>
Thu, 24 Apr 2014 11:06:55 +0000 (12:06 +0100)
Add new xc_[sg]et_mem_access() APIs.

Signed-off-by: Aravindh Puthiyaparambil <aravindp@cisco.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxc/xc_mem_access.c
tools/libxc/xenctrl.h

index a50c1453251a42f8dcf3a729f4261e959d786764..f436e69f40027a20483361eb5cbc499834750b02 100644 (file)
@@ -22,7 +22,7 @@
  */
 
 #include "xc_private.h"
-
+#include <xen/memory.h>
 
 int xc_mem_access_enable(xc_interface *xch, domid_t domain_id,
                          uint32_t *port)
@@ -47,12 +47,54 @@ int xc_mem_access_disable(xc_interface *xch, domid_t domain_id)
                                 NULL);
 }
 
-int xc_mem_access_resume(xc_interface *xch, domid_t domain_id, unsigned long gfn)
+int xc_mem_access_resume(xc_interface *xch, domid_t domain_id)
+{
+    xen_mem_access_op_t mao =
+    {
+        .op    = XENMEM_access_op_resume,
+        .domid = domain_id
+    };
+
+    return do_memory_op(xch, XENMEM_access_op, &mao, sizeof(mao));
+}
+
+int xc_set_mem_access(xc_interface *xch,
+                      domid_t domain_id,
+                      xenmem_access_t access,
+                      uint64_t first_pfn,
+                      uint32_t nr)
 {
-    return xc_mem_event_memop(xch, domain_id,
-                                XENMEM_access_op_resume,
-                                XENMEM_access_op,
-                                gfn, NULL);
+    xen_mem_access_op_t mao =
+    {
+        .op     = XENMEM_access_op_set_access,
+        .domid  = domain_id,
+        .access = access,
+        .pfn    = first_pfn,
+        .nr     = nr
+    };
+
+    return do_memory_op(xch, XENMEM_access_op, &mao, sizeof(mao));
+}
+
+int xc_get_mem_access(xc_interface *xch,
+                      domid_t domain_id,
+                      uint64_t pfn,
+                      xenmem_access_t *access)
+{
+    int rc;
+    xen_mem_access_op_t mao =
+    {
+        .op    = XENMEM_access_op_get_access,
+        .domid = domain_id,
+        .pfn   = pfn
+    };
+
+    rc = do_memory_op(xch, XENMEM_access_op, &mao, sizeof(mao));
+
+    if ( rc == 0 )
+        *access = mao.access;
+
+    return rc;
 }
 
 /*
index e3a32f2d6ed708684e1dce3c74f8d97c900c9155..3513ddb627a861c3374edaba0fb2acf3749c42c2 100644 (file)
@@ -2059,8 +2059,22 @@ int xc_mem_paging_load(xc_interface *xch, domid_t domain_id,
  */
 int xc_mem_access_enable(xc_interface *xch, domid_t domain_id, uint32_t *port);
 int xc_mem_access_disable(xc_interface *xch, domid_t domain_id);
-int xc_mem_access_resume(xc_interface *xch, domid_t domain_id,
-                         unsigned long gfn);
+int xc_mem_access_resume(xc_interface *xch, domid_t domain_id);
+
+/*
+ * Set a range of memory to a specific access.
+ * Allowed types are XENMEM_access_default, XENMEM_access_n, any combination of
+ * XENMEM_access_ + (rwx), and XENMEM_access_rx2rw
+ */
+int xc_set_mem_access(xc_interface *xch, domid_t domain_id,
+                      xenmem_access_t access, uint64_t first_pfn,
+                      uint32_t nr);
+
+/*
+ * Gets the mem access for the given page (returned in access on success)
+ */
+int xc_get_mem_access(xc_interface *xch, domid_t domain_id,
+                      uint64_t pfn, xenmem_access_t *access);
 
 /***
  * Memory sharing operations.