[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v2 2/3] mem_event: Added new helper API to teardown mem event setup and unmap ring_page.



On Sun, Aug 24, 2014 at 5:26 PM, Dushyant Behl <myselfdushyantbehl@xxxxxxxxx> wrote:
tools/libxc/xc_mem_event.c: Added new generic API to teardown mem event setup,
the API supports hvm params PAGING, ACCESS and SHARING and also completes the
obvious job of unmapping ring_page.

tools/libxc/xc_mem_access.c: Modified mem_event_disable to use the new teardown API.

tools/tests/xen-access/: Updated code to use the new API's.

Signed-off-by: Dushyant Behl <myselfdushyantbehl@xxxxxxxxx>
---
Âtools/libxc/xc_mem_access.c    Â| 9 +++----
Âtools/libxc/xc_mem_event.c     | 53 +++++++++++++++++++++++++++++++++++++
Âtools/libxc/xc_private.h      | 8 ++++++
Âtools/libxc/xenctrl.h       Â| 5 ++--
Âtools/tests/xen-access/xen-access.c |Â 6 ++---
Â5 files changed, 69 insertions(+), 12 deletions(-)
Reviewed-by: Andres Lagar-Cavilla <andres@xxxxxxxxxxxxxxxx

diff --git a/tools/libxc/xc_mem_access.c b/tools/libxc/xc_mem_access.c
index 89050be..29835c3 100644
--- a/tools/libxc/xc_mem_access.c
+++ b/tools/libxc/xc_mem_access.c
@@ -33,12 +33,11 @@ int xc_mem_access_enable(xc_interface *xch, domid_t domain_id,
                port, ring_page, back_ring);
Â}

-int xc_mem_access_disable(xc_interface *xch, domid_t domain_id)
+int xc_mem_access_disable(xc_interface *xch, domid_t domain_id, void *ring_page)
Â{
-Â Â return xc_mem_event_control(xch, domain_id,
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â XEN_DOMCTL_MEM_EVENT_OP_ACCESS_DISABLE,
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â XEN_DOMCTL_MEM_EVENT_OP_ACCESS,
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â NULL);
+Â Â return xc_mem_event_disable(xch, domain_id,
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â HVM_PARAM_ACCESS_RING_PFN,
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ring_page);
Â}

Âint xc_mem_access_resume(xc_interface *xch, domid_t domain_id)
diff --git a/tools/libxc/xc_mem_event.c b/tools/libxc/xc_mem_event.c
index cdbeca8..b6ae7d0 100644
--- a/tools/libxc/xc_mem_event.c
+++ b/tools/libxc/xc_mem_event.c
@@ -200,3 +200,56 @@ int xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,

  Âreturn rc1;
Â}
+
+/*
+ * Disable mem_event.
+ * Returns 0 on success, if failure returns -1 with errno properly set.
+ * param can be HVM_PARAM_PAGING/ACCESS/SHARING_RING_PFN
+ */
+int xc_mem_event_disable(xc_interface *xch, domid_t domain_id,
+Â Â Â Â Â Â Â Â Â Â Â Â Âint param, void *ring_page)
+{
+Â Â int rc;
+Â Â unsigned int op, mode;
+
+Â Â switch ( param )
+Â Â {
+Â Â Â Â case HVM_PARAM_PAGING_RING_PFN:
+Â Â Â Â Â Â op = XEN_DOMCTL_MEM_EVENT_OP_PAGING_DISABLE;
+Â Â Â Â Â Â mode = XEN_DOMCTL_MEM_EVENT_OP_PAGING;
+Â Â Â Â Â Â break;
+
+Â Â Â Â case HVM_PARAM_ACCESS_RING_PFN:
+Â Â Â Â Â Â op = XEN_DOMCTL_MEM_EVENT_OP_ACCESS_DISABLE;
+Â Â Â Â Â Â mode = XEN_DOMCTL_MEM_EVENT_OP_ACCESS;
+Â Â Â Â Â Â break;
+
+Â Â Â Â case HVM_PARAM_SHARING_RING_PFN:
+Â Â Â Â Â Â op = XEN_DOMCTL_MEM_EVENT_OP_SHARING_DISABLE;
+Â Â Â Â Â Â mode = XEN_DOMCTL_MEM_EVENT_OP_SHARING;
+Â Â Â Â Â Â break;
+
+Â Â Â Â /*
+Â Â Â Â Â* This is for the outside chance that the HVM_PARAM is valid but is invalid
+Â Â Â Â Â* as far as mem_event goes.
+Â Â Â Â Â*/
+Â Â Â Â default:
+Â Â Â Â Â Â errno = EINVAL;
+Â Â Â Â Â Â rc = -1;
+Â Â Â Â Â Â goto out;
+Â Â }
+
+Â Â /* Remove the ring page. */
+Â Â rc = munmap(ring_page, XC_PAGE_SIZE);
+Â Â if ( rc < 0 )
+Â Â Â Â PERROR("Error while munmap of ring_page");
+
+Â Â ring_page = NULL;
+
+Â Â rc = xc_mem_event_control(xch, domain_id, op, mode, NULL);
+Â Â if ( rc != 0 )
+Â Â Â Â PERROR("Failed to disable mem_event\n");
+
+Â out:
+Â Â return rc;
+}
diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h
index 3d455e7..eb07f31 100644
--- a/tools/libxc/xc_private.h
+++ b/tools/libxc/xc_private.h
@@ -387,4 +387,12 @@ int xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
            Âuint32_t *port, void *ring_page,
            Âmem_event_back_ring_t *back_ring);

+/*
+ * Disable mem_event.
+ * Returns 0 on success, if failure returns -1 with errno properly set.
+ * param can be HVM_PARAM_PAGING/ACCESS/SHARING_RING_PFN
+ */
+int xc_mem_event_disable(xc_interface *xch, domid_t domain_id,
+Â Â Â Â Â Â Â Â Â Â Â Â Âint param, void *ring_page);
+
Â#endif /* __XC_PRIVATE_H__ */
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index 9d043d7..546e6f8 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -2259,14 +2259,13 @@ int xc_mem_paging_load(xc_interface *xch, domid_t domain_id,
 */

Â/*
- * Enables mem_access and sets arg ring_page equal to mapped page.
+ * Enables mem_access and sets arg ring page equal to mapped page.
 * Will return 0 on success and -1 on error.
- * Caller has to unmap this page when done.
 */
Âint xc_mem_access_enable(xc_interface *xch, domid_t domain_id,
             uint32_t *port, void *ring_page,
             mem_event_back_ring_t *back_ring);
-int xc_mem_access_disable(xc_interface *xch, domid_t domain_id);
+int xc_mem_access_disable(xc_interface *xch, domid_t domain_id, void *ring_page);
Âint xc_mem_access_resume(xc_interface *xch, domid_t domain_id);

Â/*
diff --git a/tools/tests/xen-access/xen-access.c b/tools/tests/xen-access/xen-access.c
index 9242f86..a4ef578 100644
--- a/tools/tests/xen-access/xen-access.c
+++ b/tools/tests/xen-access/xen-access.c
@@ -170,13 +170,11 @@ int xenaccess_teardown(xc_interface *xch, xenaccess_t *xenaccess)
    Âreturn 0;

  Â/* Tear down domain xenaccess in Xen */
-Â Â if ( xenaccess->mem_event.ring_page )
-Â Â Â Â munmap(xenaccess->mem_event.ring_page, XC_PAGE_SIZE);
-
  Âif ( mem_access_enable )
  Â{
    Ârc = xc_mem_access_disable(xenaccess->xc_handle,
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âxenaccess->mem_event.domain_id);
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âxenaccess->mem_event.domain_id,
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âxenaccess->mem_event.ring_page);
    Âif ( rc != 0 )
    Â{
      ÂERROR("Error tearing down domain xenaccess in xen");
--
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.