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

[Xen-devel] [PATCH RFC v2 4/4] tool/xen-access: Add support for PV domains



Add support to the xen-access test program for it to work with PV domains.

Signed-off-by: Aravindh Puthiyaprambil <aravindp@xxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>

---
Changes from RFC v1:
Add call to xc_set_mem_access_default().
PV ring page setup is now done as part of xc_mem_access_enable() due to
xsa-99.

 tools/tests/xen-access/xen-access.c | 104 +++++++++++++++++++++---------------
 1 file changed, 62 insertions(+), 42 deletions(-)

diff --git a/tools/tests/xen-access/xen-access.c 
b/tools/tests/xen-access/xen-access.c
index 090df5f..02ea0c9 100644
--- a/tools/tests/xen-access/xen-access.c
+++ b/tools/tests/xen-access/xen-access.c
@@ -114,7 +114,8 @@ typedef struct xenaccess {
 } xenaccess_t;
 
 static int interrupted;
-bool evtchn_bind = 0, evtchn_open = 0, mem_access_enable = 0;
+static bool evtchn_bind = 0, evtchn_open = 0, mem_access_enable = 0, hvm = 0,
+            pv_cleanup = 0;
 
 static void close_handler(int sig)
 {
@@ -173,7 +174,7 @@ int xenaccess_teardown(xc_interface *xch, xenaccess_t 
*xenaccess)
     if ( xenaccess->mem_event.ring_page )
         munmap(xenaccess->mem_event.ring_page, XC_PAGE_SIZE);
 
-    if ( mem_access_enable )
+    if ( mem_access_enable  || (!hvm && pv_cleanup) )
     {
         rc = xc_mem_access_disable(xenaccess->xc_handle,
                                    xenaccess->mem_event.domain_id);
@@ -241,6 +242,27 @@ xenaccess_t *xenaccess_init(xc_interface **xch_r, domid_t 
domain_id)
     /* Set domain id */
     xenaccess->mem_event.domain_id = domain_id;
 
+    /* Get domaininfo */
+    xenaccess->domain_info = malloc(sizeof(xc_domaininfo_t));
+    if ( xenaccess->domain_info == NULL )
+    {
+        ERROR("Error allocating memory for domain info");
+        goto err;
+    }
+
+    rc = xc_domain_getinfolist(xenaccess->xc_handle, domain_id, 1,
+                               xenaccess->domain_info);
+    if ( rc != 1 )
+    {
+        ERROR("Error getting domain info");
+        goto err;
+    }
+
+    if ( xenaccess->domain_info->flags & XEN_DOMINF_hvm_guest )
+        hvm = 1;
+    else
+        pv_cleanup = 1;
+
     /* Initialise lock */
     mem_event_ring_lock_init(&xenaccess->mem_event);
 
@@ -293,24 +315,6 @@ xenaccess_t *xenaccess_init(xc_interface **xch_r, domid_t 
domain_id)
                    (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 )
-    {
-        ERROR("Error allocating memory for domain info");
-        goto err;
-    }
-
-    rc = xc_domain_getinfolist(xenaccess->xc_handle, domain_id, 1,
-                               xenaccess->domain_info);
-    if ( rc != 1 )
-    {
-        ERROR("Error getting domain info");
-        goto err;
-    }
-
-    DPRINTF("max_pages = %"PRIx64"\n", xenaccess->domain_info->max_pages);
-
     return xenaccess;
 
  err:
@@ -485,30 +489,38 @@ int main(int argc, char *argv[])
     }
 
     /* Set the default access type and convert all pages to it */
-    rc = xc_set_mem_access(xch, domain_id, default_access, ~0ull, 0);
-    if ( rc < 0 )
-    {
-        ERROR("Error %d setting default mem access type\n", rc);
-        goto exit;
-    }
+    if ( hvm )
+        rc = xc_set_mem_access(xch, domain_id, default_access, ~0ull, 0);
+    else
+        rc = xc_set_mem_access_default(xch, domain_id, default_access);
 
-    rc = xc_set_mem_access(xch, domain_id, default_access, 0,
-                           xenaccess->domain_info->max_pages);
     if ( rc < 0 )
     {
-        ERROR("Error %d setting all memory to access type %d\n", rc,
-              default_access);
+        ERROR("Error %d setting default mem access type\n", rc);
         goto exit;
     }
 
-    if ( int3 )
-        rc = xc_hvm_param_set(xch, domain_id, HVM_PARAM_MEMORY_EVENT_INT3, 
HVMPME_mode_sync);
-    else
-        rc = xc_hvm_param_set(xch, domain_id, HVM_PARAM_MEMORY_EVENT_INT3, 
HVMPME_mode_disabled);
-    if ( rc < 0 )
+    if ( hvm )
     {
-        ERROR("Error %d setting int3 mem_event\n", rc);
-        goto exit;
+        rc = xc_set_mem_access(xch, domain_id, default_access, 0,
+                               xenaccess->domain_info->max_pages);
+        if ( rc < 0 )
+        {
+            ERROR("Error %d setting all memory to access type %d\n", rc,
+                  default_access);
+            goto exit;
+        }
+        if ( int3 )
+            rc = xc_hvm_param_set(xch, domain_id, HVM_PARAM_MEMORY_EVENT_INT3,
+                                  HVMPME_mode_sync);
+        else
+            rc = xc_hvm_param_set(xch, domain_id, HVM_PARAM_MEMORY_EVENT_INT3,
+                                  HVMPME_mode_disabled);
+        if ( rc < 0 )
+        {
+            ERROR("Error %d setting int3 mem_event\n", rc);
+            goto exit;
+        }
     }
 
     /* Wait for access */
@@ -519,11 +531,19 @@ int main(int argc, char *argv[])
             DPRINTF("xenaccess shutting down on signal %d\n", interrupted);
 
             /* Unregister for every event */
-            rc = xc_set_mem_access(xch, domain_id, XENMEM_access_rwx, ~0ull, 
0);
-            rc = xc_set_mem_access(xch, domain_id, XENMEM_access_rwx, 0,
-                                   xenaccess->domain_info->max_pages);
-            rc = xc_hvm_param_set(xch, domain_id, HVM_PARAM_MEMORY_EVENT_INT3, 
HVMPME_mode_disabled);
-
+            if ( hvm )
+            {
+                rc = xc_set_mem_access(xch, domain_id, XENMEM_access_rwx, 
~0ull,
+                                       0);
+                rc = xc_set_mem_access(xch, domain_id, XENMEM_access_rwx, 0,
+                                       xenaccess->domain_info->max_pages);
+                rc = xc_hvm_param_set(xch, domain_id,
+                                      HVM_PARAM_MEMORY_EVENT_INT3,
+                                      HVMPME_mode_disabled);
+            }
+            else
+                rc = xc_set_mem_access_default(xch, domain_id,
+                                               XENMEM_access_rwx);
             shutting_down = 1;
         }
 
-- 
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®.