xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Dushyant Behl <myselfdushyantbehl@gmail.com>
To: xen-devel@lists.xen.org
Cc: David Scott <dave.scott@eu.citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Andres Lagar Cavilla <andres.lagarcavilla@gmail.com>,
	Dushyant Behl <myselfdushyantbehl@gmail.com>,
	Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH v0 1/3] mem_access: modifications to mem_event enable API.
Date: Thu, 14 Aug 2014 02:21:38 +0530	[thread overview]
Message-ID: <1407963100-18796-2-git-send-email-myselfdushyantbehl@gmail.com> (raw)
In-Reply-To: <1407963100-18796-1-git-send-email-myselfdushyantbehl@gmail.com>

tools/libxc/:
1. Modified the API xc_mem_event_enable to initialize
   shared ring to communicate with the hypervisor along with enabling mem_event.
2. Added memset to clear the ring_page of any bogus input before enabling any events.
3. Replaced calls to deprecated function xc_map_foreign_batch with calls
   to xc_map_foreign_bulk. The function xc_map_foreign_bulk has a cleaner
   error reporting interface than xc_map_foreign_batch.
4. The API xc_mem_event_enable is now modified to return int rather than void *,
   this was done to synchronize this API's behaviour with other mem_event API's.

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

tools/ocaml/libs/xc/xenctrl_stubs.c: Changed the name of a macro from RING_SIZE
to BUF_RING_SIZE because the earlier name collided with xen shared ring
deinitions in io/ring.h

Signed-off-by: Dushyant Behl <myselfdushyantbehl@gmail.com>
---
 tools/libxc/xc_mem_access.c         |  8 ++++--
 tools/libxc/xc_mem_event.c          | 49 +++++++++++++++++++++++++++----------
 tools/libxc/xc_private.h            | 10 +++++---
 tools/libxc/xenctrl.h               |  9 ++++---
 tools/ocaml/libs/xc/xenctrl_stubs.c |  6 ++---
 tools/tests/xen-access/xen-access.c | 17 +++++--------
 6 files changed, 64 insertions(+), 35 deletions(-)

diff --git a/tools/libxc/xc_mem_access.c b/tools/libxc/xc_mem_access.c
index 461f0e9..89050be 100644
--- a/tools/libxc/xc_mem_access.c
+++ b/tools/libxc/xc_mem_access.c
@@ -24,9 +24,13 @@
 #include "xc_private.h"
 #include <xen/memory.h>
 
-void *xc_mem_access_enable(xc_interface *xch, domid_t domain_id, uint32_t *port)
+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)
 {
-    return xc_mem_event_enable(xch, domain_id, HVM_PARAM_ACCESS_RING_PFN, port);
+    return xc_mem_event_enable(xch, domain_id,
+                               HVM_PARAM_ACCESS_RING_PFN,
+                               port, ring_page, back_ring);
 }
 
 int xc_mem_access_disable(xc_interface *xch, domid_t domain_id)
diff --git a/tools/libxc/xc_mem_event.c b/tools/libxc/xc_mem_event.c
index faf1cc6..3525a83 100644
--- a/tools/libxc/xc_mem_event.c
+++ b/tools/libxc/xc_mem_event.c
@@ -22,6 +22,7 @@
  */
 
 #include "xc_private.h"
+#include <xen/mem_event.h>
 
 int xc_mem_event_control(xc_interface *xch, domid_t domain_id, unsigned int op,
                          unsigned int mode, uint32_t *port)
@@ -56,19 +57,27 @@ int xc_mem_event_memop(xc_interface *xch, domid_t domain_id,
     return do_memory_op(xch, mode, &meo, sizeof(meo));
 }
 
-void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
-                          uint32_t *port)
+/*
+ * Enables mem_event and initializes shared ring to communicate with hypervisor
+ * returns 0 if success and if failure returns -errno with
+ * errno properly set to indicate possible error.
+ * param can be HVM_PARAM_PAGING/ACCESS/SHARING_RING_PFN
+ */
+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)
 {
-    void *ring_page = NULL;
     uint64_t pfn;
     xen_pfn_t ring_pfn, mmap_pfn;
     unsigned int op, mode;
-    int rc1, rc2, saved_errno;
+    int rc1, rc2, saved_errno, err;
+
+    ring_page = NULL;
 
     if ( !port )
     {
         errno = EINVAL;
-        return NULL;
+        return -errno;
     }
 
     /* Pause the domain for ring page setup */
@@ -76,7 +85,7 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
     if ( rc1 != 0 )
     {
         PERROR("Unable to pause domain\n");
-        return NULL;
+        return -errno;
     }
 
     /* Get the pfn of the ring page */
@@ -89,9 +98,9 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
 
     ring_pfn = pfn;
     mmap_pfn = pfn;
-    ring_page = xc_map_foreign_batch(xch, domain_id, PROT_READ | PROT_WRITE,
-                                     &mmap_pfn, 1);
-    if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+    ring_page = xc_map_foreign_bulk(xch, domain_id,
+                                    PROT_READ | PROT_WRITE, &mmap_pfn, &err, 1);
+    if ( (err != 0) || (ring_page == NULL) )
     {
         /* Map failed, populate ring page */
         rc1 = xc_domain_populate_physmap_exact(xch, domain_id, 1, 0, 0,
@@ -103,15 +112,23 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
         }
 
         mmap_pfn = ring_pfn;
-        ring_page = xc_map_foreign_batch(xch, domain_id, PROT_READ | PROT_WRITE,
-                                         &mmap_pfn, 1);
-        if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+        ring_page = xc_map_foreign_bulk(xch, domain_id, PROT_READ | PROT_WRITE,
+                                        &mmap_pfn, &err, 1);
+        if ( (err != 0) || (ring_page == NULL) )
         {
             PERROR("Could not map the ring page\n");
+            rc1 = -1;
             goto out;
         }
     }
 
+    /* Clear the ring page */
+    memset(ring_page, 0, PAGE_SIZE);
+
+    /* Initialise ring */
+    SHARED_RING_INIT((mem_event_sring_t *)ring_page);
+    BACK_RING_INIT(back_ring, (mem_event_sring_t *)ring_page, PAGE_SIZE);
+
     switch ( param )
     {
     case HVM_PARAM_PAGING_RING_PFN:
@@ -149,7 +166,12 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
     /* Remove the ring_pfn from the guest's physmap */
     rc1 = xc_domain_decrease_reservation_exact(xch, domain_id, 1, 0, &ring_pfn);
     if ( rc1 != 0 )
+    {
         PERROR("Failed to remove ring page from guest physmap");
+        goto out;
+    }
+
+    rc1 = 0;
 
  out:
     saved_errno = errno;
@@ -169,7 +191,8 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
         ring_page = NULL;
 
         errno = saved_errno;
+        rc1 = -errno;
     }
 
-    return ring_page;
+    return rc1;
 }
diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h
index c50a7c9..cf9b223 100644
--- a/tools/libxc/xc_private.h
+++ b/tools/libxc/xc_private.h
@@ -32,6 +32,7 @@
 #include "xenctrl.h"
 #include "xenctrlosdep.h"
 
+#include <xen/mem_event.h>
 #include <xen/sys/privcmd.h>
 
 #if defined(HAVE_VALGRIND_MEMCHECK_H) && !defined(NDEBUG) && !defined(__MINIOS__)
@@ -377,10 +378,13 @@ int xc_mem_event_memop(xc_interface *xch, domid_t domain_id,
                         unsigned int op, unsigned int mode,
                         uint64_t gfn, void *buffer);
 /*
- * Enables mem_event and returns the mapped ring page indicated by param.
+ * Enables mem_event and initializes shared ring to communicate with hypervisor
+ * sets ring_page equal to mapped page.
+ * Returns 0 if success and if failure returns -errno with errno properly set.
  * param can be HVM_PARAM_PAGING/ACCESS/SHARING_RING_PFN
  */
-void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
-                          uint32_t *port);
+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);
 
 #endif /* __XC_PRIVATE_H__ */
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index 1c5d0db..d21f026 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -47,6 +47,7 @@
 #include <xen/xsm/flask_op.h>
 #include <xen/tmem.h>
 #include <xen/kexec.h>
+#include <xen/mem_event.h>
 
 #include "xentoollog.h"
 
@@ -2258,11 +2259,13 @@ int xc_mem_paging_load(xc_interface *xch, domid_t domain_id,
  */
 
 /*
- * Enables mem_access and returns the mapped ring page.
- * Will return NULL on error.
+ * Enables mem_access and sets arg ring page equal to mapped page.
+ * Will return 0 on success and -errno on error.
  * Caller has to unmap this page when done.
  */
-void *xc_mem_access_enable(xc_interface *xch, domid_t domain_id, uint32_t *port);
+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_resume(xc_interface *xch, domid_t domain_id);
 
diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenctrl_stubs.c
index f0810eb..beccb38 100644
--- a/tools/ocaml/libs/xc/xenctrl_stubs.c
+++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -526,12 +526,12 @@ CAMLprim value stub_xc_evtchn_reset(value xch, value domid)
 }
 
 
-#define RING_SIZE 32768
-static char ring[RING_SIZE];
+#define BUF_RING_SIZE 32768
+static char ring[BUF_RING_SIZE];
 
 CAMLprim value stub_xc_readconsolering(value xch)
 {
-	unsigned int size = RING_SIZE - 1;
+	unsigned int size = BUF_RING_SIZE - 1;
 	char *ring_ptr = ring;
 	int retval;
 
diff --git a/tools/tests/xen-access/xen-access.c b/tools/tests/xen-access/xen-access.c
index 090df5f..9242f86 100644
--- a/tools/tests/xen-access/xen-access.c
+++ b/tools/tests/xen-access/xen-access.c
@@ -245,11 +245,12 @@ xenaccess_t *xenaccess_init(xc_interface **xch_r, domid_t domain_id)
     mem_event_ring_lock_init(&xenaccess->mem_event);
 
     /* Enable mem_access */
-    xenaccess->mem_event.ring_page =
-            xc_mem_access_enable(xenaccess->xc_handle,
-                                 xenaccess->mem_event.domain_id,
-                                 &xenaccess->mem_event.evtchn_port);
-    if ( xenaccess->mem_event.ring_page == NULL )
+    rc = xc_mem_access_enable(xenaccess->xc_handle,
+                              xenaccess->mem_event.domain_id,
+                              &xenaccess->mem_event.evtchn_port,
+                              xenaccess->mem_event.ring_page,
+                              &xenaccess->mem_event.back_ring);
+    if ( rc < 0 )
     {
         switch ( errno ) {
             case EBUSY:
@@ -287,12 +288,6 @@ xenaccess_t *xenaccess_init(xc_interface **xch_r, domid_t domain_id)
     evtchn_bind = 1;
     xenaccess->mem_event.port = rc;
 
-    /* Initialise ring */
-    SHARED_RING_INIT((mem_event_sring_t *)xenaccess->mem_event.ring_page);
-    BACK_RING_INIT(&xenaccess->mem_event.back_ring,
-                   (mem_event_sring_t *)xenaccess->mem_event.ring_page,
-                   XC_PAGE_SIZE);
-
     /* Get domaininfo */
     xenaccess->domain_info = malloc(sizeof(xc_domaininfo_t));
     if ( xenaccess->domain_info == NULL )
-- 
1.9.1

  reply	other threads:[~2014-08-13 20:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-13 20:51 [PATCH v0 0/3] Modifications to mem_event_enable API and addition of teardown routine Dushyant Behl
2014-08-13 20:51 ` Dushyant Behl [this message]
     [not found]   ` <CAGU+auvmQOWp8VH5bt+yh55iyJxLOV6Hd8ZfvAsdyuOOZ3fBNQ@mail.gmail.com>
2014-08-22 22:05     ` [PATCH v0 1/3] mem_access: modifications to mem_event enable API Aravindh Puthiyaparambil (aravindp)
2014-08-25  0:16       ` Dushyant Behl
2014-08-25 17:48         ` Aravindh Puthiyaparambil (aravindp)
2014-08-26 17:50       ` Ian Campbell
2014-08-13 20:51 ` [PATCH v0 2/3] mem_event: Added new helper API to teardown mem event setup and unmap ring_page Dushyant Behl
     [not found]   ` <CAGU+auudSP7mXfGzMzhDm4WkwS7icGy_rFCAWHhN85xe_pF=Og@mail.gmail.com>
2014-08-22 22:24     ` Aravindh Puthiyaparambil (aravindp)
2014-08-13 20:51 ` [PATCH v0 3/3] xenpaging: updated code to use safer mem_event API's for setup and teardown Dushyant Behl

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=1407963100-18796-2-git-send-email-myselfdushyantbehl@gmail.com \
    --to=myselfdushyantbehl@gmail.com \
    --cc=andres.lagarcavilla@gmail.com \
    --cc=dave.scott@eu.citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xen.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).