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

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 12 of 25] libxc: convert hvmop interfaces over to hypercall buffers
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Thu, 21 Oct 2010 11:58:55 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Thu, 21 Oct 2010 04:18:46 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1287658723@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 1287650255 -3600
# Node ID a688a8de1cf73954974b9dcc46304e9dcc981068
# Parent  9986007519dce12dd0503f88cc32f415a5f11c3d
libxc: convert hvmop interfaces over to hypercall buffers

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

diff -r 9986007519dc -r a688a8de1cf7 tools/libxc/xc_domain.c
--- a/tools/libxc/xc_domain.c   Thu Oct 21 09:37:35 2010 +0100
+++ b/tools/libxc/xc_domain.c   Thu Oct 21 09:37:35 2010 +0100
@@ -1027,38 +1027,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 9986007519dc -r a688a8de1cf7 tools/libxc/xc_misc.c
--- a/tools/libxc/xc_misc.c     Thu Oct 21 09:37:35 2010 +0100
+++ b/tools/libxc/xc_misc.c     Thu Oct 21 09:37:35 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;
+        PERROR("Could not allocate memory for xc_hvm_set_pci_intx_level 
hypercall");
+        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;
+        PERROR("Could not allocate memory for xc_hvm_set_isa_irq_level 
hypercall");
+        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 allocate memory for xc_hvm_set_pci_link_route 
hypercall");
+        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 bounce memory for xc_hvm_track_dirty_vram 
hypercall");
+        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 allocate memory for xc_hvm_modified_memory 
hypercall");
+        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 allocate memory for xc_hvm_set_mem_type hypercall");
+        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>