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 21 of 24] libxc: convert hvmop interfaces over to hyp

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 21 of 24] libxc: convert hvmop interfaces over to hypercall buffers
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Mon, 06 Sep 2010 14:38:41 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Mon, 06 Sep 2010 07:08:48 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1283780300@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 1283779691 -3600
# Node ID 413c6e963a87945e05a8fc1eb761c1e976445d9c
# Parent  68dfe4921429a857123a5f926f30b54abf3f5f80
libxc: convert hvmop interfaces over to hypercall buffers

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

diff -r 68dfe4921429 -r 413c6e963a87 tools/libxc/xc_domain.c
--- a/tools/libxc/xc_domain.c   Mon Sep 06 14:28:11 2010 +0100
+++ b/tools/libxc/xc_domain.c   Mon Sep 06 14:28:11 2010 +0100
@@ -914,38 +914,42 @@ int xc_set_hvm_param(xc_interface *handl
 int xc_set_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned 
long value)
 {
     DECLARE_HYPERCALL;
-    xen_hvm_param_t arg;
+    DECLARE_HYPERCALL_BUFFER(xen_hvm_param_t, arg);
     int rc;
+
+    arg = xc_hypercall_buffer_alloc(handle, arg, sizeof(*arg));
+    if ( arg == NULL )
+        return -1;
 
     hypercall.op     = __HYPERVISOR_hvm_op;
     hypercall.arg[0] = HVMOP_set_param;
-    hypercall.arg[1] = (unsigned long)&arg;
-    arg.domid = dom;
-    arg.index = param;
-    arg.value = value;
-    if ( lock_pages(handle, &arg, sizeof(arg)) != 0 )
-        return -1;
+    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(arg);
+    arg->domid = dom;
+    arg->index = param;
+    arg->value = value;
     rc = do_xen_hypercall(handle, &hypercall);
-    unlock_pages(handle, &arg, sizeof(arg));
+    xc_hypercall_buffer_free(handle, arg);
     return rc;
 }
 
 int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned 
long *value)
 {
     DECLARE_HYPERCALL;
-    xen_hvm_param_t arg;
+    DECLARE_HYPERCALL_BUFFER(xen_hvm_param_t, arg);
     int rc;
+
+    arg = xc_hypercall_buffer_alloc(handle, arg, sizeof(*arg));
+    if ( arg == NULL )
+        return -1;
 
     hypercall.op     = __HYPERVISOR_hvm_op;
     hypercall.arg[0] = HVMOP_get_param;
-    hypercall.arg[1] = (unsigned long)&arg;
-    arg.domid = dom;
-    arg.index = param;
-    if ( lock_pages(handle, &arg, sizeof(arg)) != 0 )
-        return -1;
+    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(arg);
+    arg->domid = dom;
+    arg->index = param;
     rc = do_xen_hypercall(handle, &hypercall);
-    unlock_pages(handle, &arg, sizeof(arg));
-    *value = arg.value;
+    *value = arg->value;
+    xc_hypercall_buffer_free(handle, arg);
     return rc;
 }
 
diff -r 68dfe4921429 -r 413c6e963a87 tools/libxc/xc_misc.c
--- a/tools/libxc/xc_misc.c     Mon Sep 06 14:28:11 2010 +0100
+++ b/tools/libxc/xc_misc.c     Mon Sep 06 14:28:11 2010 +0100
@@ -299,18 +299,19 @@ int xc_hvm_set_pci_intx_level(
     unsigned int level)
 {
     DECLARE_HYPERCALL;
-    struct xen_hvm_set_pci_intx_level _arg, *arg = &_arg;
+    DECLARE_HYPERCALL_BUFFER(struct xen_hvm_set_pci_intx_level, arg);
     int rc;
 
-    if ( (rc = hcall_buf_prep(xch, (void **)&arg, sizeof(*arg))) != 0 )
+    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
+    if ( arg == NULL )
     {
         PERROR("Could not lock memory");
-        return rc;
+        return -1;
     }
 
     hypercall.op     = __HYPERVISOR_hvm_op;
     hypercall.arg[0] = HVMOP_set_pci_intx_level;
-    hypercall.arg[1] = (unsigned long)arg;
+    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(arg);
 
     arg->domid  = dom;
     arg->domain = domain;
@@ -321,7 +322,7 @@ int xc_hvm_set_pci_intx_level(
 
     rc = do_xen_hypercall(xch, &hypercall);
 
-    hcall_buf_release(xch, (void **)&arg, sizeof(*arg));
+    xc_hypercall_buffer_free(xch, arg);
 
     return rc;
 }
@@ -332,18 +333,19 @@ int xc_hvm_set_isa_irq_level(
     unsigned int level)
 {
     DECLARE_HYPERCALL;
-    struct xen_hvm_set_isa_irq_level _arg, *arg = &_arg;
+    DECLARE_HYPERCALL_BUFFER(struct xen_hvm_set_isa_irq_level, arg);
     int rc;
 
-    if ( (rc = hcall_buf_prep(xch, (void **)&arg, sizeof(*arg))) != 0 )
+    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
+    if ( arg == NULL )
     {
         PERROR("Could not lock memory");
-        return rc;
+        return -1;
     }
 
     hypercall.op     = __HYPERVISOR_hvm_op;
     hypercall.arg[0] = HVMOP_set_isa_irq_level;
-    hypercall.arg[1] = (unsigned long)arg;
+    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(arg);
 
     arg->domid   = dom;
     arg->isa_irq = isa_irq;
@@ -351,7 +353,7 @@ int xc_hvm_set_isa_irq_level(
 
     rc = do_xen_hypercall(xch, &hypercall);
 
-    hcall_buf_release(xch, (void **)&arg, sizeof(*arg));
+    xc_hypercall_buffer_free(xch, arg);
 
     return rc;
 }
@@ -360,26 +362,27 @@ int xc_hvm_set_pci_link_route(
     xc_interface *xch, domid_t dom, uint8_t link, uint8_t isa_irq)
 {
     DECLARE_HYPERCALL;
-    struct xen_hvm_set_pci_link_route arg;
+    DECLARE_HYPERCALL_BUFFER(struct xen_hvm_set_pci_link_route, arg);
     int rc;
+
+    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
+    if ( arg == NULL )
+    {
+        PERROR("Could not lock memory");
+        return -1;
+    }
 
     hypercall.op     = __HYPERVISOR_hvm_op;
     hypercall.arg[0] = HVMOP_set_pci_link_route;
-    hypercall.arg[1] = (unsigned long)&arg;
+    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(arg);
 
-    arg.domid   = dom;
-    arg.link    = link;
-    arg.isa_irq = isa_irq;
-
-    if ( (rc = lock_pages(xch, &arg, sizeof(arg))) != 0 )
-    {
-        PERROR("Could not lock memory");
-        return rc;
-    }
+    arg->domid   = dom;
+    arg->link    = link;
+    arg->isa_irq = isa_irq;
 
     rc = do_xen_hypercall(xch, &hypercall);
 
-    unlock_pages(xch, &arg, sizeof(arg));
+    xc_hypercall_buffer_free(xch, arg);
 
     return rc;
 }
@@ -390,28 +393,32 @@ int xc_hvm_track_dirty_vram(
     unsigned long *dirty_bitmap)
 {
     DECLARE_HYPERCALL;
-    struct xen_hvm_track_dirty_vram arg;
+    DECLARE_HYPERCALL_BOUNCE(dirty_bitmap, (nr+31) / 32, 
XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
+    DECLARE_HYPERCALL_BUFFER(struct xen_hvm_track_dirty_vram, arg);
     int rc;
+
+    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
+    if ( arg == NULL || xc_hypercall_bounce_pre(xch, dirty_bitmap) )
+    {
+        PERROR("Could not lock memory");
+        rc = -1;
+        goto out;
+    }
 
     hypercall.op     = __HYPERVISOR_hvm_op;
     hypercall.arg[0] = HVMOP_track_dirty_vram;
-    hypercall.arg[1] = (unsigned long)&arg;
+    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(arg);
 
-    arg.domid     = dom;
-    arg.first_pfn = first_pfn;
-    arg.nr        = nr;
-    set_xen_guest_handle(arg.dirty_bitmap, (uint8_t *)dirty_bitmap);
-
-    if ( (rc = lock_pages(xch, &arg, sizeof(arg))) != 0 )
-    {
-        PERROR("Could not lock memory");
-        return rc;
-    }
+    arg->domid     = dom;
+    arg->first_pfn = first_pfn;
+    arg->nr        = nr;
+    xc_set_xen_guest_handle(arg->dirty_bitmap, dirty_bitmap);
 
     rc = do_xen_hypercall(xch, &hypercall);
 
-    unlock_pages(xch, &arg, sizeof(arg));
-
+out:
+    xc_hypercall_buffer_free(xch, arg);
+    xc_hypercall_bounce_post(xch, dirty_bitmap);
     return rc;
 }
 
@@ -419,26 +426,27 @@ int xc_hvm_modified_memory(
     xc_interface *xch, domid_t dom, uint64_t first_pfn, uint64_t nr)
 {
     DECLARE_HYPERCALL;
-    struct xen_hvm_modified_memory arg;
+    DECLARE_HYPERCALL_BUFFER(struct xen_hvm_modified_memory, arg);
     int rc;
+
+    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
+    if ( arg == NULL )
+    {
+        PERROR("Could not lock memory");
+        return -1;
+    }
 
     hypercall.op     = __HYPERVISOR_hvm_op;
     hypercall.arg[0] = HVMOP_modified_memory;
-    hypercall.arg[1] = (unsigned long)&arg;
+    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(arg);
 
-    arg.domid     = dom;
-    arg.first_pfn = first_pfn;
-    arg.nr        = nr;
-
-    if ( (rc = lock_pages(xch, &arg, sizeof(arg))) != 0 )
-    {
-        PERROR("Could not lock memory");
-        return rc;
-    }
+    arg->domid     = dom;
+    arg->first_pfn = first_pfn;
+    arg->nr        = nr;
 
     rc = do_xen_hypercall(xch, &hypercall);
 
-    unlock_pages(xch, &arg, sizeof(arg));
+    xc_hypercall_buffer_free(xch, arg);
 
     return rc;
 }
@@ -447,27 +455,28 @@ int xc_hvm_set_mem_type(
     xc_interface *xch, domid_t dom, hvmmem_type_t mem_type, uint64_t 
first_pfn, uint64_t nr)
 {
     DECLARE_HYPERCALL;
-    struct xen_hvm_set_mem_type arg;
+    DECLARE_HYPERCALL_BUFFER(struct xen_hvm_set_mem_type, arg);
     int rc;
+
+    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
+    if ( arg == NULL )
+    {
+        PERROR("Could not lock memory");
+        return -1;
+    }
+
+    arg->domid        = dom;
+    arg->hvmmem_type  = mem_type;
+    arg->first_pfn    = first_pfn;
+    arg->nr           = nr;
 
     hypercall.op     = __HYPERVISOR_hvm_op;
     hypercall.arg[0] = HVMOP_set_mem_type;
-    hypercall.arg[1] = (unsigned long)&arg;
-
-    arg.domid        = dom;
-    arg.hvmmem_type  = mem_type;
-    arg.first_pfn    = first_pfn;
-    arg.nr           = nr;
-
-    if ( (rc = lock_pages(xch, &arg, sizeof(arg))) != 0 )
-    {
-        PERROR("Could not lock memory");
-        return rc;
-    }
+    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(arg);
 
     rc = do_xen_hypercall(xch, &hypercall);
 
-    unlock_pages(xch, &arg, sizeof(arg));
+    xc_hypercall_buffer_free(xch, arg);
 
     return rc;
 }

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

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