WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 14 of 25] libxc: convert tmem interface over to hyper

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 14 of 25] libxc: convert tmem interface over to hypercall buffers
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Fri, 22 Oct 2010 15:15:56 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Fri, 22 Oct 2010 07:48:22 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1287756942@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1287756891 -3600
# Node ID f9d7420fae6d3f4a324cd783ab56ea5a158cf664
# Parent  441891ba02392f7ac7ca215569eab45023b8c9cc
libxc: convert tmem interface over to hypercall buffers

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r 441891ba0239 -r f9d7420fae6d tools/libxc/xc_tmem.c
--- a/tools/libxc/xc_tmem.c     Fri Oct 22 15:14:51 2010 +0100
+++ b/tools/libxc/xc_tmem.c     Fri Oct 22 15:14:51 2010 +0100
@@ -25,21 +25,23 @@ static int do_tmem_op(xc_interface *xch,
 {
     int ret;
     DECLARE_HYPERCALL;
+    DECLARE_HYPERCALL_BOUNCE(op, sizeof(*op), XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
+
+    if ( xc_hypercall_bounce_pre(xch, op) )
+    {
+        PERROR("Could not bounce buffer for tmem op hypercall");
+        return -EFAULT;
+    }
 
     hypercall.op = __HYPERVISOR_tmem_op;
-    hypercall.arg[0] = (unsigned long)op;
-    if (lock_pages(xch, op, sizeof(*op)) != 0)
-    {
-        PERROR("Could not lock memory for Xen hypercall");
-        return -EFAULT;
-    }
+    hypercall.arg[0] = HYPERCALL_BUFFER_AS_ARG(op);
     if ((ret = do_xen_hypercall(xch, &hypercall)) < 0)
     {
         if ( errno == EACCES )
             DPRINTF("tmem operation failed -- need to"
                     " rebuild the user-space tool set?\n");
     }
-    unlock_pages(xch, op, sizeof(*op));
+    xc_hypercall_bounce_post(xch, op);
 
     return ret;
 }
@@ -54,13 +56,13 @@ int xc_tmem_control(xc_interface *xch,
                     void *buf)
 {
     tmem_op_t op;
+    DECLARE_HYPERCALL_BOUNCE(buf, arg1, XC_HYPERCALL_BUFFER_BOUNCE_OUT);
     int rc;
 
     op.cmd = TMEM_CONTROL;
     op.pool_id = pool_id;
     op.u.ctrl.subop = subop;
     op.u.ctrl.cli_id = cli_id;
-    set_xen_guest_handle(op.u.ctrl.buf,buf);
     op.u.ctrl.arg1 = arg1;
     op.u.ctrl.arg2 = arg2;
     /* use xc_tmem_control_oid if arg3 is required */
@@ -68,25 +70,28 @@ int xc_tmem_control(xc_interface *xch,
     op.u.ctrl.oid[1] = 0;
     op.u.ctrl.oid[2] = 0;
 
-    if (subop == TMEMC_LIST) {
-        if ((arg1 != 0) && (lock_pages(xch, buf, arg1) != 0))
-        {
-            PERROR("Could not lock memory for Xen hypercall");
-            return -ENOMEM;
-        }
-    }
-
 #ifdef VALGRIND
     if (arg1 != 0)
         memset(buf, 0, arg1);
 #endif
 
+    if ( subop == TMEMC_LIST && arg1 != 0 )
+    {
+        if ( buf == NULL )
+            return -EINVAL;
+        if ( xc_hypercall_bounce_pre(xch, buf) )
+        {
+            PERROR("Could not bounce buffer for tmem control hypercall");
+            return -ENOMEM;
+        }
+    }
+
+    xc_set_xen_guest_handle(op.u.ctrl.buf, buf);
+
     rc = do_tmem_op(xch, &op);
 
-    if (subop == TMEMC_LIST) {
-        if (arg1 != 0)
-            unlock_pages(xch, buf, arg1);
-    }
+    if (subop == TMEMC_LIST && arg1 != 0)
+            xc_hypercall_bounce_post(xch, buf);
 
     return rc;
 }
@@ -101,6 +106,7 @@ int xc_tmem_control_oid(xc_interface *xc
                         void *buf)
 {
     tmem_op_t op;
+    DECLARE_HYPERCALL_BOUNCE(buf, arg1, XC_HYPERCALL_BUFFER_BOUNCE_OUT);
     int rc;
 
     op.cmd = TMEM_CONTROL;
@@ -114,25 +120,28 @@ int xc_tmem_control_oid(xc_interface *xc
     op.u.ctrl.oid[1] = oid.oid[1];
     op.u.ctrl.oid[2] = oid.oid[2];
 
-    if (subop == TMEMC_LIST) {
-        if ((arg1 != 0) && (lock_pages(xch, buf, arg1) != 0))
-        {
-            PERROR("Could not lock memory for Xen hypercall");
-            return -ENOMEM;
-        }
-    }
-
 #ifdef VALGRIND
     if (arg1 != 0)
         memset(buf, 0, arg1);
 #endif
 
+    if ( subop == TMEMC_LIST && arg1 != 0 )
+    {
+        if ( buf == NULL )
+            return -EINVAL;
+        if ( xc_hypercall_bounce_pre(xch, buf) )
+        {
+            PERROR("Could not bounce buffer for tmem control (OID) hypercall");
+            return -ENOMEM;
+        }
+    }
+
+    xc_set_xen_guest_handle(op.u.ctrl.buf, buf);
+
     rc = do_tmem_op(xch, &op);
 
-    if (subop == TMEMC_LIST) {
-        if (arg1 != 0)
-            unlock_pages(xch, buf, arg1);
-    }
+    if (subop == TMEMC_LIST && arg1 != 0)
+            xc_hypercall_bounce_post(xch, buf);
 
     return rc;
 }

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>