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 3/3] xenpaging: updated code to use safer mem_event API's for setup and teardown.
Date: Thu, 14 Aug 2014 02:21:40 +0530	[thread overview]
Message-ID: <1407963100-18796-4-git-send-email-myselfdushyantbehl@gmail.com> (raw)
In-Reply-To: <1407963100-18796-1-git-send-email-myselfdushyantbehl@gmail.com>

tools/libxc/xc_mem_paging.c: updated mem_paging enable and disable API's to use
the mem event enable and disable routines. The mem event API's take care of
security issues mentioned in XSA-99 and also provide more coarse grained behaviour.

tools/xenpaging/xenpaging.c: added calls to the new API's and removed the code
which duplicated the new API behaviour.

Signed-off-by: Dushyant Behl <myselfdushyantbehl@gmail.com>
---
 tools/libxc/xc_mem_paging.c | 34 ++++++++++++++---------------
 tools/libxc/xenctrl.h       | 14 ++++++++++--
 tools/xenpaging/xenpaging.c | 52 ++++++---------------------------------------
 3 files changed, 36 insertions(+), 64 deletions(-)

diff --git a/tools/libxc/xc_mem_paging.c b/tools/libxc/xc_mem_paging.c
index 8aa7d4d..826bdb7 100644
--- a/tools/libxc/xc_mem_paging.c
+++ b/tools/libxc/xc_mem_paging.c
@@ -23,28 +23,28 @@
 
 #include "xc_private.h"
 
-
+/*
+ * Enables mem_paging and sets arg ring page equal to mapped page.
+ * Will return 0 on success and -errno on error.
+ */
 int xc_mem_paging_enable(xc_interface *xch, domid_t domain_id,
-                         uint32_t *port)
+                         uint32_t *port,  void *ring_page,
+                         mem_event_back_ring_t *back_ring)
 {
-    if ( !port )
-    {
-        errno = EINVAL;
-        return -1;
-    }
-        
-    return xc_mem_event_control(xch, domain_id,
-                                XEN_DOMCTL_MEM_EVENT_OP_PAGING_ENABLE,
-                                XEN_DOMCTL_MEM_EVENT_OP_PAGING,
-                                port);
+    return xc_mem_event_enable(xch, domain_id,
+                               HVM_PARAM_PAGING_RING_PFN,
+                               port, ring_page, back_ring);
 }
 
-int xc_mem_paging_disable(xc_interface *xch, domid_t domain_id)
+/*
+ * Disable mem_paging and unmap ring page.
+ * Will return 0 on success and -errno on error.
+ */
+int xc_mem_paging_disable(xc_interface *xch, domid_t domain_id, void *ring_page)
 {
-    return xc_mem_event_control(xch, domain_id,
-                                XEN_DOMCTL_MEM_EVENT_OP_PAGING_DISABLE,
-                                XEN_DOMCTL_MEM_EVENT_OP_PAGING,
-                                NULL);
+    return xc_mem_event_teardown(xch, domain_id,
+                                 HVM_PARAM_ACCESS_RING_PFN,
+                                 ring_page);
 }
 
 int xc_mem_paging_nominate(xc_interface *xch, domid_t domain_id, unsigned long gfn)
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index cfd6019..6acbfa9 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -2244,8 +2244,18 @@ int xc_tmem_restore_extra(xc_interface *xch, int dom, int fd);
  * Hardware-Assisted Paging (i.e. Intel EPT, AMD NPT). Moreover, AMD NPT
  * support is considered experimental.
  */
-int xc_mem_paging_enable(xc_interface *xch, domid_t domain_id, uint32_t *port);
-int xc_mem_paging_disable(xc_interface *xch, domid_t domain_id);
+/*
+ * Enables mem_paging and sets arg ring page equal to mapped page.
+ * returns 0 on success and -errno on error.
+ */
+int xc_mem_paging_enable(xc_interface *xch, domid_t domain_id,
+                         uint32_t *port,  void *ring_page,
+                         mem_event_back_ring_t *back_ring);
+/*
+ * Disables mem_paging and unmaps ring page.
+ * returns 0 on success and -errno on error.
+ */
+int xc_mem_paging_disable(xc_interface *xch, domid_t domain_id, void *ring_page);
 int xc_mem_paging_nominate(xc_interface *xch, domid_t domain_id,
                            unsigned long gfn);
 int xc_mem_paging_evict(xc_interface *xch, domid_t domain_id, unsigned long gfn);
diff --git a/tools/xenpaging/xenpaging.c b/tools/xenpaging/xenpaging.c
index 82c1ee4..4a841bf 100644
--- a/tools/xenpaging/xenpaging.c
+++ b/tools/xenpaging/xenpaging.c
@@ -337,40 +337,12 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
         PERROR("Could not bind to xenpaging watch\n");
         goto err;
     }
-
-    /* Map the ring page */
-    xc_get_hvm_param(xch, paging->mem_event.domain_id, 
-                        HVM_PARAM_PAGING_RING_PFN, &ring_pfn);
-    mmap_pfn = ring_pfn;
-    paging->mem_event.ring_page = 
-        xc_map_foreign_batch(xch, paging->mem_event.domain_id, 
-                                PROT_READ | PROT_WRITE, &mmap_pfn, 1);
-    if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
-    {
-        /* Map failed, populate ring page */
-        rc = xc_domain_populate_physmap_exact(paging->xc_handle, 
-                                              paging->mem_event.domain_id,
-                                              1, 0, 0, &ring_pfn);
-        if ( rc != 0 )
-        {
-            PERROR("Failed to populate ring gfn\n");
-            goto err;
-        }
-
-        mmap_pfn = ring_pfn;
-        paging->mem_event.ring_page = 
-            xc_map_foreign_batch(xch, paging->mem_event.domain_id, 
-                                    PROT_READ | PROT_WRITE, &mmap_pfn, 1);
-        if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
-        {
-            PERROR("Could not map the ring page\n");
-            goto err;
-        }
-    }
     
-    /* Initialise Xen */
+    /* Enable mem paging and initialize shared ring to communicate with xen. */
     rc = xc_mem_paging_enable(xch, paging->mem_event.domain_id,
-                             &paging->mem_event.evtchn_port);
+                              &paging->mem_event.evtchn_port,
+                              paging->mem_event.ring_page,
+                              &paging->mem_event.back_ring);
     if ( rc != 0 )
     {
         switch ( errno ) {
@@ -413,17 +385,6 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
 
     paging->mem_event.port = rc;
 
-    /* Initialise ring */
-    SHARED_RING_INIT((mem_event_sring_t *)paging->mem_event.ring_page);
-    BACK_RING_INIT(&paging->mem_event.back_ring,
-                   (mem_event_sring_t *)paging->mem_event.ring_page,
-                   PAGE_SIZE);
-
-    /* Now that the ring is set, remove it from the guest's physmap */
-    if ( xc_domain_decrease_reservation_exact(xch, 
-                    paging->mem_event.domain_id, 1, 0, &ring_pfn) )
-        PERROR("Failed to remove ring from guest physmap");
-
     /* Get max_pages from guest if not provided via cmdline */
     if ( !paging->max_pages )
     {
@@ -523,9 +484,10 @@ static void xenpaging_teardown(struct xenpaging *paging)
     xs_unwatch(paging->xs_handle, "@releaseDomain", watch_token);
 
     paging->xc_handle = NULL;
+
     /* Tear down domain paging in Xen */
-    munmap(paging->mem_event.ring_page, PAGE_SIZE);
-    rc = xc_mem_paging_disable(xch, paging->mem_event.domain_id);
+    rc = xc_mem_paging_disable(xch, paging->mem_event.domain_id,
+                               paging->mem_event.ring_page);
     if ( rc != 0 )
     {
         PERROR("Error tearing down domain paging in xen");
-- 
1.9.1

      parent 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 ` [PATCH v0 1/3] mem_access: modifications to mem_event enable API Dushyant Behl
     [not found]   ` <CAGU+auvmQOWp8VH5bt+yh55iyJxLOV6Hd8ZfvAsdyuOOZ3fBNQ@mail.gmail.com>
2014-08-22 22:05     ` 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 ` Dushyant Behl [this message]

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-4-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).