xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Aravindh Puthiyaparambil <aravindp@cisco.com>
To: xen-devel@lists.xenproject.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>,
	Ian Campbell <ian.campbell@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH RFC 2/2] tools/libxc: Make the mem_access APIs generic
Date: Tue,  8 Apr 2014 22:50:07 -0700	[thread overview]
Message-ID: <1397022607-1704-3-git-send-email-aravindp@cisco.com> (raw)
In-Reply-To: <1397022607-1704-1-git-send-email-aravindp@cisco.com>

This patch does the following:
1. Add new xc_[sg]et_mem_access APIs.
2. Make xc_hvm_[sg]et_mem_access call the newer xc_[sg]et_mem_access
APIs and mark them as deprecated.
3. Make the upper bound for the number of pages to UINT_MAX for
xc_set_mem_access()

Signed-off-by: Aravindh Puthiyaparambil <aravindp@cisco.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>

diff --git a/tools/libxc/xc_mem_access.c b/tools/libxc/xc_mem_access.c
index a50c145..2617c0e 100644
--- a/tools/libxc/xc_mem_access.c
+++ b/tools/libxc/xc_mem_access.c
@@ -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,59 @@ int xc_mem_access_disable(xc_interface *xch, domid_t domain_id)
                                 NULL);
 }
 
+static int xc_mem_access_memop(xc_interface *xch, domid_t domid,
+                               xen_mem_access_op_t *mao)
+{
+    mao->domid = domid;
+
+    return do_memory_op(xch, XENMEM_access_op, mao, sizeof(*mao));
+}
+
 int xc_mem_access_resume(xc_interface *xch, domid_t domain_id, unsigned long gfn)
 {
-    return xc_mem_event_memop(xch, domain_id,
-                                XENMEM_access_op_resume,
-                                XENMEM_access_op,
-                                gfn, NULL);
+    xen_mem_access_op_t mao;
+
+    memset(&mao, 0, sizeof(mao));
+    mao.op = XENMEM_access_op_resume;
+
+    return xc_mem_access_memop(xch, domain_id, &mao);
+}
+
+int xc_set_mem_access(xc_interface *xch,
+                      domid_t domain_id,
+                      xenmem_access_t mem_access,
+                      uint64_t first_pfn,
+                      uint32_t nr)
+{
+    xen_mem_access_op_t mao;
+
+    mao.op = XENMEM_access_op_set_access;
+    mao.domid         = domain_id;
+    mao.xenmem_access = mem_access;
+    mao.pfn           = first_pfn;
+    mao.nr            = nr;
+
+    return xc_mem_access_memop(xch, domain_id, &mao);
+}
+
+int xc_get_mem_access(xc_interface *xch,
+                      domid_t domain_id,
+                      uint64_t pfn,
+                      xenmem_access_t* mem_access)
+{
+    xen_mem_access_op_t mao;
+    int rc;
+
+    mao.op          = XENMEM_access_op_get_access;
+    mao.domid       = domain_id;
+    mao.pfn         = pfn;
+
+    rc = xc_mem_access_memop(xch, domain_id, &mao);
+
+    if ( !rc )
+        *mem_access = mao.xenmem_access;
+
+    return rc;
 }
 
 /*
diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
index 3303454..c38fb94 100644
--- a/tools/libxc/xc_misc.c
+++ b/tools/libxc/xc_misc.c
@@ -19,7 +19,9 @@
  */
 
 #include "xc_private.h"
+#include <limits.h>
 #include <xen/hvm/hvm_op.h>
+#include <xen/memory.h>
 
 int xc_get_max_cpus(xc_interface *xch)
 {
@@ -594,64 +596,18 @@ int xc_hvm_set_mem_type(
 }
 
 int xc_hvm_set_mem_access(
-    xc_interface *xch, domid_t dom, hvmmem_access_t mem_access, uint64_t first_pfn, uint64_t nr)
+    xc_interface *xch, domid_t dom, hvmmem_access_t mem_access,
+    uint64_t first_pfn, uint64_t nr)
 {
-    DECLARE_HYPERCALL;
-    DECLARE_HYPERCALL_BUFFER(struct xen_hvm_set_mem_access, arg);
-    int rc;
-
-    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-    if ( arg == NULL )
-    {
-        PERROR("Could not allocate memory for xc_hvm_set_mem_access hypercall");
-        return -1;
-    }
-
-    arg->domid         = dom;
-    arg->hvmmem_access = mem_access;
-    arg->first_pfn     = first_pfn;
-    arg->nr            = nr;
-
-    hypercall.op     = __HYPERVISOR_hvm_op;
-    hypercall.arg[0] = HVMOP_set_mem_access;
-    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(arg);
-
-    rc = do_xen_hypercall(xch, &hypercall);
-
-    xc_hypercall_buffer_free(xch, arg);
-
-    return rc;
+    if ( nr > UINT_MAX )
+        return -EINVAL;
+    return xc_set_mem_access(xch, dom, mem_access, first_pfn, nr);
 }
 
 int xc_hvm_get_mem_access(
     xc_interface *xch, domid_t dom, uint64_t pfn, hvmmem_access_t* mem_access)
 {
-    DECLARE_HYPERCALL;
-    DECLARE_HYPERCALL_BUFFER(struct xen_hvm_get_mem_access, arg);
-    int rc;
-
-    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-    if ( arg == NULL )
-    {
-        PERROR("Could not allocate memory for xc_hvm_get_mem_access hypercall");
-        return -1;
-    }
-
-    arg->domid       = dom;
-    arg->pfn         = pfn;
-
-    hypercall.op     = __HYPERVISOR_hvm_op;
-    hypercall.arg[0] = HVMOP_get_mem_access;
-    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(arg);
-
-    rc = do_xen_hypercall(xch, &hypercall);
-
-    if ( !rc )
-        *mem_access = arg->hvmmem_access;
-
-    xc_hypercall_buffer_free(xch, arg);
-
-    return rc;
+    return xc_get_mem_access(xch, dom, pfn, (xenmem_access_t *)mem_access);
 }
 
 int xc_hvm_inject_trap(
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index e3a32f2..2fc6743 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -1730,14 +1730,17 @@ int xc_hvm_set_mem_type(
 
 /*
  * Set a range of memory to a specific access.
+ * Maximum value of nr is UINT_MAX
  * Allowed types are HVMMEM_access_default, HVMMEM_access_n, any combination of 
  * HVM_access_ + (rwx), and HVM_access_rx2rw
+ * Please note that this API has been deprecated by xc_set_mem_access()
  */
 int xc_hvm_set_mem_access(
     xc_interface *xch, domid_t dom, hvmmem_access_t memaccess, uint64_t first_pfn, uint64_t nr);
 
 /*
  * Gets the mem access for the given page (returned in memacess on success)
+ * Please note that this API has been deprecated by xc_get_mem_access()
  */
 int xc_hvm_get_mem_access(
     xc_interface *xch, domid_t dom, uint64_t pfn, hvmmem_access_t* memaccess);
@@ -2062,6 +2065,21 @@ 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);
 
+/*
+ * 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 mem_access, uint64_t first_pfn,
+                      uint32_t nr);
+
+/*
+ * Gets the mem access for the given page (returned in mem_acess on success)
+ */
+int xc_get_mem_access(xc_interface *xch, domid_t domain_id,
+                      uint64_t pfn, xenmem_access_t* mem_access);
+
 /***
  * Memory sharing operations.
  *
-- 
1.8.3.2

  parent reply	other threads:[~2014-04-09  5:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-09  5:50 [PATCH RFC 0/2] Make mem_access APIs and hypercalls generic Aravindh Puthiyaparambil
2014-04-09  5:50 ` [PATCH RFC 1/2] x86/mem_access: Make the mem_access ops generic Aravindh Puthiyaparambil
2014-04-09  8:53   ` Jan Beulich
2014-04-10  0:39     ` Aravindh Puthiyaparambil (aravindp)
2014-04-10  6:17       ` Jan Beulich
2014-04-09  5:50 ` Aravindh Puthiyaparambil [this message]
2014-04-09  8:23   ` [PATCH RFC 2/2] tools/libxc: Make the mem_access APIs generic Ian Campbell
2014-04-09  8:58     ` Jan Beulich
2014-04-09  9:06       ` Ian Campbell
2014-04-10  0:43         ` Aravindh Puthiyaparambil (aravindp)
2014-04-10  0:43     ` Aravindh Puthiyaparambil (aravindp)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1397022607-1704-3-git-send-email-aravindp@cisco.com \
    --to=aravindp@cisco.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).