libxc: hypercall buffers
RFC PATCH 1/1 libxc: hypercall buffers
libxc currently locks various on-stack data structures present on the stack using mlock(2) in order to try and make them safe for passing to hypercalls (which requires the memory to be mapped)
There are several issues with this approach:
1) mlock/munlock do not nest, therefore mlocking multiple pieces of data on the stack which happen to share a page causes everything to be unlocked on the first munlock not the last. This is likely to be currently OK for the uses in libxc taken in isolation but could impact any caller of libxc which uses mlock itself.
2) mlocking only parts of the stack is considered by many to be a dubious, if strictly speaking allowed by the relevant specifications, use of mlock.
3) mlock may not provide the required semantics needed for hypercall safe memory. mlock simply ensures that there cvan be no major faults (page faults requiring I/O to satisfy) but does not necessarily rule out minor faults (e.g. due to page migration)
The following introduces an explicit hypercall-safe memory pool API which includes support for bouncing user-supplied memory buffers into suitable memory.
This series addresses (1) and (2) but does not directly address (3) other than by encapsulating the code which acquires hypercall safe memory into one place where it can be more easily fixed.
There is also the slightly separate issue of code which forgets to lock buffers as necessary and therefor this series overrides the Xen guest-handle interfaces to attempt to improve compile-time checking for the correct use of the memory pool. This scheme works for the pointers contained within hypercall argument structures but doesn't catch the actual hypercall arguments themselves. I'm open to suggestions on how to extend it cleanly to catch those cases.
This RFC series only partially translates over to the the new scheme. It is intended that the final series end with a patch which effectively does s/xc_set_xen_guest_handle/set_xen_guest_handle/g in order to catch future errors (it should also remove the now redundant hcall_buf_prep and hcall_buf_release calls and assiciated infrastructure).
The RFC has already grown to many more patches than I originally intended so I'd like to solicit some comments on the basic premise, usability of the interface etc, before I dig down and convert/cleanup the rest.
I've tried in this initial pass to keep the locking/bouncing at the same level of the call stack. There seems to be several opportunities for pushing this up or down to reduce unnecessary bouncing. While it would be nice to avoid exposing the explicit allocation to users of libxc (by using bounce buffers at all public interfaces) I do not think this will be possible for performance reasons in many cases. Already there are several users of libxc which lock their own buffers.
PATCH 1/1 xen: define raw version of set_xen_guest_handle
# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1283778426 -3600
# Node ID f3b0732b41af4dd3218e59dae6e0a005c323774f # Parent 8848895e50ded4d37879bf63635f5774d9dc4959
xen: define raw version of set_xen_guest_handle
allows users to define more complex (e.g. type-safer) variations on set_xen_guest_handle if they wish.
xen/include/public/arch-ia64.h +2 -1
@@ -49,10 +49,11 @@#define XEN_GUEST_HANDLE (name) __guest_handle_ ## name#define XEN_GUEST_HANDLE_64 (name) XEN_GUEST_HANDLE(name)#define uint64_aligned_t uint64_t -#define set_xen_guest_handle (hnd, val) do { (hnd).p = val; } while (0) +#define set_xen_guest_handle_raw (hnd, val) do { (hnd).p = val; } while (0)#ifdef __XEN_TOOLS__#define get_xen_guest_handle (val, hnd) do { val = (hnd).p; } while (0)#endif +#define set_xen_guest_handle (hnd, val) set_xen_guest_handle_raw(hnd, val)#ifndef __ASSEMBLY__typedef unsigned long xen_pfn_t ;
xen/include/public/arch-x86/xen-x86_32.h +2 -2
@@ -108,8 +108,8 @@ __guest_handle_ ## name; \ typedef struct { union { type *p; uint64_aligned_t q; }; } \ __guest_handle_64_ ## name -#undef set_xen_guest_handle -#define set_xen_guest_handle (hnd, val) \ +#undef set_xen_guest_handle_raw +#define set_xen_guest_handle_raw (hnd, val) \ do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0; \ (hnd).p = val; \ } while ( 0 )
xen/include/public/arch-x86/xen.h +2 -1
@@ -44,10 +44,11 @@#define DEFINE_XEN_GUEST_HANDLE (name) __DEFINE_XEN_GUEST_HANDLE(name, name)#define __XEN_GUEST_HANDLE (name) __guest_handle_ ## name#define XEN_GUEST_HANDLE (name) __XEN_GUEST_HANDLE(name) -#define set_xen_guest_handle (hnd, val) do { (hnd).p = val; } while (0) +#define set_xen_guest_handle_raw (hnd, val) do { (hnd).p = val; } while (0)#ifdef __XEN_TOOLS__#define get_xen_guest_handle (val, hnd) do { val = (hnd).p; } while (0)#endif +#define set_xen_guest_handle (hnd, val) set_xen_guest_handle_raw(hnd, val)#if defined(__i386__)#include "xen-x86_32.h"
PATCH 1/1 libxc: flask: use (un)lock pages rather than open coding m(un)lock
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779690 -3600
# Node ID 89333e9d1d90fba9e5a493ae4f541a956a04e3c0
# Parent f3b0732b41af4dd3218e59dae6e0a005c323774f
libxc: flask: use (un)lock pages rather than open coding m(un)lock.
Allows us to do away with safe_unlock and merge into unlock_pages.
tools/libxc/xc_flask.c +2 -2
@@ -44,7 +44,7 @@ int xc_flask_op(xc_interface *xch, flask hypercall.op = __HYPERVISOR_xsm_op; hypercall.arg[0 ] = (unsigned long )op; -if (mlock (op,sizeof (*op)) !=0 ) +if (lock_pages (op,sizeof (*op)) !=0 ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out;
@@ -56,7 +56,7 @@ int xc_flask_op(xc_interface *xch, flaskfprintf (stderr,"XSM operation failed!\n" ); } -safe_munlock (op,sizeof (*op)); +unlock_pages (op,sizeof (*op)); out:return ret;
tools/libxc/xc_private.c +3 -1
@@ -218,7 +218,9 @@ void unlock_pages(void *addr, size_t lenvoid *laddr = (void *)((unsigned long )addr &PAGE_MASK );size_t llen = (len + ((unsigned long )addr - (unsigned long )laddr) +PAGE_SIZE -1 ) &PAGE_MASK ; -safe_munlock (laddr, llen); +int saved_errno = errno; + (void )munlock (laddr, llen); + errno = saved_errno; }static pthread_key_t hcall_buf_pkey;
tools/libxc/xc_private.h +0 -7
@@ -105,13 +105,6 @@ void unlock_pages(void *addr, size_t lenint hcall_buf_prep (void **addr,size_t len);void hcall_buf_release (void **addr,size_t len); - -static inline void safe_munlock (const void *addr,size_t len) -{ -int saved_errno = errno; - (void )munlock (addr, len); - errno = saved_errno; -}int do_xen_hypercall (xc_interface *xch,privcmd_hypercall_t *hypercall);
PATCH 1/1 libxc: pass an xc_interface handle to page locking functions
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID 7e23b1acc3f23c9f06c88b6f4480a614c49c9a96 # Parent 89333e9d1d90fba9e5a493ae4f541a956a04e3c0
libxc: pass an xc_interface handle to page locking functions
tools/libxc/xc_acm.c +2 -2
@@ -92,7 +92,7 @@ int xc_acm_op(xc_interface *xch, int cmd hypercall.op = __HYPERVISOR_xsm_op; hypercall.arg[0 ] = (unsigned long )&acmctl; -if (lock_pages (&acmctl,sizeof (acmctl)) !=0 ) +if (lock_pages (xch, &acmctl,sizeof (acmctl)) !=0 ) {PERROR ("Could not lock memory for Xen hypercall" );return -EFAULT ;
@@ -103,7 +103,7 @@ int xc_acm_op(xc_interface *xch, int cmdDPRINTF ("acmctl operation failed -- need to" " rebuild the user-space tool set?\n" ); } -unlock_pages (&acmctl,sizeof (acmctl)); +unlock_pages (xch, &acmctl,sizeof (acmctl));switch (cmd) {case ACMOP_getdecision: {
tools/libxc/xc_cpupool.c +4 -4
@@ -85,13 +85,13 @@ int xc_cpupool_getinfo(xc_interface *xchset_xen_guest_handle (sysctl.u.cpupool_op.cpumap.bitmap, local); sysctl.u.cpupool_op.cpumap.nr_cpus =sizeof (info->cpumap) *8 ; -if ( (err =lock_pages (local,sizeof (local))) !=0 ) +if ( (err =lock_pages (xch, local,sizeof (local))) !=0 ) {PERROR ("Could not lock memory for Xen hypercall" );break ; } err =do_sysctl_save (xch, &sysctl); -unlock_pages (local,sizeof (local)); +unlock_pages (xch, local,sizeof (local));if ( err <0 )break ;
@@ -161,14 +161,14 @@ int xc_cpupool_freeinfo(xc_interface *xcset_xen_guest_handle (sysctl.u.cpupool_op.cpumap.bitmap, local); sysctl.u.cpupool_op.cpumap.nr_cpus =sizeof (*cpumap) *8 ; -if ( (err =lock_pages (local,sizeof (local))) !=0 ) +if ( (err =lock_pages (xch, local,sizeof (local))) !=0 ) {PERROR ("Could not lock memory for Xen hypercall" );return err; } err =do_sysctl_save (xch, &sysctl); -unlock_pages (local,sizeof (local)); +unlock_pages (xch, local,sizeof (local));if (err <0 )return err;
tools/libxc/xc_domain.c +31 -31
222 lines not on this page · raw message
tools/libxc/xc_domain_restore.c +3 -3
@@ -1181,13 +1181,13 @@ int xc_domain_restore(xc_interface *xch,memset (ctx->p2m_batch,0 ,ROUNDUP (MAX_BATCH_SIZE *sizeof (xen_pfn_t),PAGE_SHIFT )); -if (lock_pages (region_mfn,sizeof (xen_pfn_t) *MAX_BATCH_SIZE ) ) +if (lock_pages (xch, region_mfn,sizeof (xen_pfn_t) *MAX_BATCH_SIZE ) ) {PERROR ("Could not lock region_mfn" ); goto out; } -if (lock_pages (ctx->p2m_batch,sizeof (xen_pfn_t) *MAX_BATCH_SIZE ) ) +if (lock_pages (xch, ctx->p2m_batch,sizeof (xen_pfn_t) *MAX_BATCH_SIZE ) ) {ERROR ("Could not lock p2m_batch" ); goto out;
@@ -1547,7 +1547,7 @@ int xc_domain_restore(xc_interface *xch, } } -if (lock_pages (&ctxt,sizeof (ctxt)) ) +if (lock_pages (xch, &ctxt,sizeof (ctxt)) ) {PERROR ("Unable to lock ctxt" );return 1 ;
tools/libxc/xc_domain_save.c +3 -3
@@ -1046,14 +1046,14 @@ int xc_domain_save(xc_interface *xch, inmemset (to_send,0xff ,BITMAP_SIZE ); -if (lock_pages (to_send,BITMAP_SIZE ) ) +if (lock_pages (xch, to_send,BITMAP_SIZE ) ) {PERROR ("Unable to lock to_send" );return 1 ; }/* (to fix is local only) */ -if (lock_pages (to_skip,BITMAP_SIZE ) ) +if (lock_pages (xch, to_skip,BITMAP_SIZE ) ) {PERROR ("Unable to lock to_skip" );return 1 ;
@@ -1091,7 +1091,7 @@ int xc_domain_save(xc_interface *xch, inmemset (pfn_type,0 ,ROUNDUP (MAX_BATCH_SIZE *sizeof (*pfn_type),PAGE_SHIFT )); -if (lock_pages (pfn_type,MAX_BATCH_SIZE *sizeof (*pfn_type)) ) +if (lock_pages (xch, pfn_type,MAX_BATCH_SIZE *sizeof (*pfn_type)) ) {PERROR ("Unable to lock pfn_type array" ); goto out;
tools/libxc/xc_evtchn.c +2 -2
@@ -33,7 +33,7 @@ static int do_evtchn_op(xc_interface *xc hypercall.arg[0 ] = cmd; hypercall.arg[1 ] = (unsigned long )arg; -if (lock_pages (arg, arg_size) !=0 ) +if (lock_pages (xch, arg, arg_size) !=0 ) {PERROR ("do_evtchn_op: arg lock failed" ); goto out;
@@ -42,7 +42,7 @@ static int do_evtchn_op(xc_interface *xcif ((ret =do_xen_hypercall (xch, &hypercall)) <0 && !silently_fail)ERROR ("do_evtchn_op: HYPERVISOR_event_channel_op failed: %d" , ret); -unlock_pages (arg, arg_size); +unlock_pages (xch, arg, arg_size); out:return ret; }
tools/libxc/xc_flask.c +2 -2
@@ -44,7 +44,7 @@ int xc_flask_op(xc_interface *xch, flask hypercall.op = __HYPERVISOR_xsm_op; hypercall.arg[0 ] = (unsigned long )op; -if (lock_pages (op,sizeof (*op)) !=0 ) +if (lock_pages (xch, op,sizeof (*op)) !=0 ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out;
@@ -56,7 +56,7 @@ int xc_flask_op(xc_interface *xch, flaskfprintf (stderr,"XSM operation failed!\n" ); } -unlock_pages (op,sizeof (*op)); +unlock_pages (xch, op,sizeof (*op)); out:return ret;
tools/libxc/xc_linux.c +4 -4
@@ -618,7 +618,7 @@ int xc_gnttab_op(xc_interface *xch, int hypercall.arg[1 ] = (unsigned long )op; hypercall.arg[2 ] = count; -if (lock_pages (op, count* op_size) !=0 ) +if (lock_pages (xch, op, count* op_size) !=0 ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out1;
@@ -626,7 +626,7 @@ int xc_gnttab_op(xc_interface *xch, int ret =do_xen_hypercall (xch, &hypercall); -unlock_pages (op, count * op_size); +unlock_pages (xch, op, count * op_size); out1:return ret;
@@ -670,7 +670,7 @@ static void *_gnttab_map_table(xc_interf *gnt_num = query.nr_frames * (PAGE_SIZE /sizeof (grant_entry_v1_t) ); frame_list =malloc (query.nr_frames *sizeof (unsigned long )); -if ( !frame_list ||lock_pages (frame_list, +if ( !frame_list ||lock_pages (xch, frame_list, query.nr_frames *sizeof (unsigned long )) ) {ERROR ("Alloc/lock frame_list in xc_gnttab_map_table\n" );
@@ -714,7 +714,7 @@ err: err:if ( frame_list ) { -unlock_pages (frame_list, query.nr_frames *sizeof (unsigned long )); +unlock_pages (xch, frame_list, query.nr_frames *sizeof (unsigned long ));free (frame_list); }if ( pfn_list )
tools/libxc/xc_misc.c +20 -20
@@ -42,7 +42,7 @@ int xc_readconsolering(xc_interface *xch sysctl.u.readconsole.incremental = incremental; } -if ( (ret =lock_pages (buffer, nr_chars)) !=0 ) +if ( (ret =lock_pages (xch, buffer, nr_chars)) !=0 )return ret;if ( (ret =do_sysctl (xch, &sysctl)) ==0 )
@@ -52,7 +52,7 @@ int xc_readconsolering(xc_interface *xch *pindex = sysctl.u.readconsole.index; } -unlock_pages (buffer, nr_chars); +unlock_pages (xch, buffer, nr_chars);return ret; }
@@ -66,12 +66,12 @@ int xc_send_debug_keys(xc_interface *xchset_xen_guest_handle (sysctl.u.debug_keys.keys, keys); sysctl.u.debug_keys.nr_keys = len; -if ( (ret =lock_pages (keys, len)) !=0 ) +if ( (ret =lock_pages (xch, keys, len)) !=0 )return ret; ret =do_sysctl (xch, &sysctl); -unlock_pages (keys, len); +unlock_pages (xch, keys, len);return ret; }
@@ -154,7 +154,7 @@ int xc_mca_op(xc_interface *xch, structDECLARE_HYPERCALL ; mc->interface_version =XEN_MCA_INTERFACE_VERSION ; -if (lock_pages (mc,sizeof (mc)) ) +if (lock_pages (xch, mc,sizeof (mc)) ) {PERROR ("Could not lock xen_mc memory" );return -EINVAL ;
@@ -163,7 +163,7 @@ int xc_mca_op(xc_interface *xch, struct hypercall.op = __HYPERVISOR_mca; hypercall.arg[0 ] = (unsigned long )mc; ret =do_xen_hypercall (xch, &hypercall); -unlock_pages (mc,sizeof (mc)); +unlock_pages (xch, mc,sizeof (mc)); return ret; }#endif
@@ -227,12 +227,12 @@ int xc_getcpuinfo(xc_interface *xch, int sysctl.u.getcpuinfo.max_cpus = max_cpus;set_xen_guest_handle (sysctl.u.getcpuinfo.info, info); -if ( (rc =lock_pages (info, max_cpus*sizeof (*info))) !=0 ) +if ( (rc =lock_pages (xch, info, max_cpus*sizeof (*info))) !=0 )return rc; rc =do_sysctl (xch, &sysctl); -unlock_pages (info, max_cpus*sizeof (*info)); +unlock_pages (xch, info, max_cpus*sizeof (*info));if ( nr_cpus ) *nr_cpus = sysctl.u.getcpuinfo.nr_cpus;
@@ -250,7 +250,7 @@ int xc_hvm_set_pci_intx_level(struct xen_hvm_set_pci_intx_level _arg, *arg = &_arg;int rc; -if ( (rc =hcall_buf_prep ((void **)&arg,sizeof (*arg))) !=0 ) +if ( (rc =hcall_buf_prep (xch, (void **)&arg,sizeof (*arg))) !=0 ) {PERROR ("Could not lock memory" );return rc;
@@ -269,7 +269,7 @@ int xc_hvm_set_pci_intx_level( rc =do_xen_hypercall (xch, &hypercall); -hcall_buf_release ((void **)&arg,sizeof (*arg)); +hcall_buf_release (xch, (void **)&arg,sizeof (*arg));return rc; }
@@ -283,7 +283,7 @@ int xc_hvm_set_isa_irq_level(struct xen_hvm_set_isa_irq_level _arg, *arg = &_arg;int rc; -if ( (rc =hcall_buf_prep ((void **)&arg,sizeof (*arg))) !=0 ) +if ( (rc =hcall_buf_prep (xch, (void **)&arg,sizeof (*arg))) !=0 ) {PERROR ("Could not lock memory" );return rc;
@@ -299,7 +299,7 @@ int xc_hvm_set_isa_irq_level( rc =do_xen_hypercall (xch, &hypercall); -hcall_buf_release ((void **)&arg,sizeof (*arg)); +hcall_buf_release (xch, (void **)&arg,sizeof (*arg));return rc; }
@@ -319,7 +319,7 @@ int xc_hvm_set_pci_link_route( arg.link = link; arg.isa_irq = isa_irq; -if ( (rc =lock_pages (&arg,sizeof (arg))) !=0 ) +if ( (rc =lock_pages (xch, &arg,sizeof (arg))) !=0 ) {PERROR ("Could not lock memory" );return rc;
@@ -327,7 +327,7 @@ int xc_hvm_set_pci_link_route( rc =do_xen_hypercall (xch, &hypercall); -unlock_pages (&arg,sizeof (arg)); +unlock_pages (xch, &arg,sizeof (arg));return rc; }
@@ -350,7 +350,7 @@ int xc_hvm_track_dirty_vram( arg.nr = nr;set_xen_guest_handle (arg.dirty_bitmap, (uint8_t *)dirty_bitmap); -if ( (rc =lock_pages (&arg,sizeof (arg))) !=0 ) +if ( (rc =lock_pages (xch, &arg,sizeof (arg))) !=0 ) {PERROR ("Could not lock memory" );return rc;
@@ -358,7 +358,7 @@ int xc_hvm_track_dirty_vram( rc =do_xen_hypercall (xch, &hypercall); -unlock_pages (&arg,sizeof (arg)); +unlock_pages (xch, &arg,sizeof (arg));return rc; }
@@ -378,7 +378,7 @@ int xc_hvm_modified_memory( arg.first_pfn = first_pfn; arg.nr = nr; -if ( (rc =lock_pages (&arg,sizeof (arg))) !=0 ) +if ( (rc =lock_pages (xch, &arg,sizeof (arg))) !=0 ) {PERROR ("Could not lock memory" );return rc;
@@ -386,7 +386,7 @@ int xc_hvm_modified_memory( rc =do_xen_hypercall (xch, &hypercall); -unlock_pages (&arg,sizeof (arg)); +unlock_pages (xch, &arg,sizeof (arg));return rc; }
@@ -407,7 +407,7 @@ int xc_hvm_set_mem_type( arg.first_pfn = first_pfn; arg.nr = nr; -if ( (rc =lock_pages (&arg,sizeof (arg))) !=0 ) +if ( (rc =lock_pages (xch, &arg,sizeof (arg))) !=0 ) {PERROR ("Could not lock memory" );return rc;
@@ -415,7 +415,7 @@ int xc_hvm_set_mem_type( rc =do_xen_hypercall (xch, &hypercall); -unlock_pages (&arg,sizeof (arg)); +unlock_pages (xch, &arg,sizeof (arg));return rc; }
tools/libxc/xc_offline_page.c +8 -8
@@ -71,7 +71,7 @@ int xc_mark_page_online(xc_interface *xcif ( !status || (end < start) )return -EINVAL ; -if (lock_pages (status,sizeof (uint32_t )*(end - start +1 ))) +if (lock_pages (xch, status,sizeof (uint32_t )*(end - start +1 ))) {ERROR ("Could not lock memory for xc_mark_page_online\n" );return -EINVAL ;
@@ -84,7 +84,7 @@ int xc_mark_page_online(xc_interface *xcset_xen_guest_handle (sysctl.u.page_offline.status, status); ret =xc_sysctl (xch, &sysctl); -unlock_pages (status,sizeof (uint32_t )*(end - start +1 )); +unlock_pages (xch, status,sizeof (uint32_t )*(end - start +1 ));return ret; }
@@ -98,7 +98,7 @@ int xc_mark_page_offline(xc_interface *xif ( !status || (end < start) )return -EINVAL ; -if (lock_pages (status,sizeof (uint32_t )*(end - start +1 ))) +if (lock_pages (xch, status,sizeof (uint32_t )*(end - start +1 ))) {ERROR ("Could not lock memory for xc_mark_page_offline" );return -EINVAL ;
@@ -111,7 +111,7 @@ int xc_mark_page_offline(xc_interface *xset_xen_guest_handle (sysctl.u.page_offline.status, status); ret =xc_sysctl (xch, &sysctl); -unlock_pages (status,sizeof (uint32_t )*(end - start +1 )); +unlock_pages (xch, status,sizeof (uint32_t )*(end - start +1 ));return ret; }
@@ -125,7 +125,7 @@ int xc_query_page_offline_status(xc_inteif ( !status || (end < start) )return -EINVAL ; -if (lock_pages (status,sizeof (uint32_t )*(end - start +1 ))) +if (lock_pages (xch, status,sizeof (uint32_t )*(end - start +1 ))) {ERROR ("Could not lock memory for xc_query_page_offline_status\n" );return -EINVAL ;
@@ -138,7 +138,7 @@ int xc_query_page_offline_status(xc_inteset_xen_guest_handle (sysctl.u.page_offline.status, status); ret =xc_sysctl (xch, &sysctl); -unlock_pages (status,sizeof (uint32_t )*(end - start +1 )); +unlock_pages (xch, status,sizeof (uint32_t )*(end - start +1 ));return ret; }
@@ -291,7 +291,7 @@ static int init_mem_info(xc_interface *x minfo->pfn_type[i] =pfn_to_mfn (i, minfo->p2m_table, minfo->guest_width); -if (lock_pages (minfo->pfn_type, minfo->p2m_size *sizeof (*minfo->pfn_type)) ) +if (lock_pages (xch, minfo->pfn_type, minfo->p2m_size *sizeof (*minfo->pfn_type)) ) {ERROR ("Unable to lock pfn_type array" ); goto failed;
@@ -310,7 +310,7 @@ static int init_mem_info(xc_interface *xreturn 0 ; unlock: -unlock_pages (minfo->pfn_type, minfo->p2m_size *sizeof (*minfo->pfn_type)); +unlock_pages (xch, minfo->pfn_type, minfo->p2m_size *sizeof (*minfo->pfn_type)); failed:if (minfo->pfn_type) {
tools/libxc/xc_pm.c +19 -19
@@ -53,14 +53,14 @@ int xc_pm_get_pxstat(xc_interface *xch,if ( (ret =xc_pm_get_max_px (xch, cpuid, &max_px)) !=0 )return ret; -if ( (ret =lock_pages (pxpt->trans_pt, +if ( (ret =lock_pages (xch, pxpt->trans_pt, max_px * max_px *sizeof (uint64_t ))) !=0 )return ret; -if ( (ret =lock_pages (pxpt->pt, +if ( (ret =lock_pages (xch, pxpt->pt, max_px *sizeof (struct xc_px_val ))) !=0 ) { -unlock_pages (pxpt->trans_pt, max_px * max_px *sizeof (uint64_t )); +unlock_pages (xch, pxpt->trans_pt, max_px * max_px *sizeof (uint64_t ));return ret; }
@@ -75,8 +75,8 @@ int xc_pm_get_pxstat(xc_interface *xch, ret =xc_sysctl (xch, &sysctl);if ( ret ) { -unlock_pages (pxpt->trans_pt, max_px * max_px *sizeof (uint64_t )); -unlock_pages (pxpt->pt, max_px *sizeof (struct xc_px_val )); +unlock_pages (xch, pxpt->trans_pt, max_px * max_px *sizeof (uint64_t )); +unlock_pages (xch, pxpt->pt, max_px *sizeof (struct xc_px_val ));return ret; }
@@ -85,8 +85,8 @@ int xc_pm_get_pxstat(xc_interface *xch, pxpt->last = sysctl.u.get_pmstat.u.getpx.last; pxpt->cur = sysctl.u.get_pmstat.u.getpx.cur; -unlock_pages (pxpt->trans_pt, max_px * max_px *sizeof (uint64_t )); -unlock_pages (pxpt->pt, max_px *sizeof (struct xc_px_val )); +unlock_pages (xch, pxpt->trans_pt, max_px * max_px *sizeof (uint64_t )); +unlock_pages (xch, pxpt->pt, max_px *sizeof (struct xc_px_val ));return ret; }
@@ -128,11 +128,11 @@ int xc_pm_get_cxstat(xc_interface *xch,if ( (ret =xc_pm_get_max_cx (xch, cpuid, &max_cx)) ) goto unlock_0; -if ( (ret =lock_pages (cxpt,sizeof (struct xc_cx_stat ))) ) +if ( (ret =lock_pages (xch, cxpt,sizeof (struct xc_cx_stat ))) ) goto unlock_0; -if ( (ret =lock_pages (cxpt->triggers, max_cx *sizeof (uint64_t ))) ) +if ( (ret =lock_pages (xch, cxpt->triggers, max_cx *sizeof (uint64_t ))) ) goto unlock_1; -if ( (ret =lock_pages (cxpt->residencies, max_cx *sizeof (uint64_t ))) ) +if ( (ret =lock_pages (xch, cxpt->residencies, max_cx *sizeof (uint64_t ))) ) goto unlock_2; sysctl.cmd = XEN_SYSCTL_get_pmstat;
@@ -155,11 +155,11 @@ int xc_pm_get_cxstat(xc_interface *xch, cxpt->cc6 = sysctl.u.get_pmstat.u.getcx.cc6; unlock_3: -unlock_pages (cxpt->residencies, max_cx *sizeof (uint64_t )); +unlock_pages (xch, cxpt->residencies, max_cx *sizeof (uint64_t )); unlock_2: -unlock_pages (cxpt->triggers, max_cx *sizeof (uint64_t )); +unlock_pages (xch, cxpt->triggers, max_cx *sizeof (uint64_t )); unlock_1: -unlock_pages (cxpt,sizeof (struct xc_cx_stat )); +unlock_pages (xch, cxpt,sizeof (struct xc_cx_stat )); unlock_0:return ret; }
@@ -200,13 +200,13 @@ int xc_get_cpufreq_para(xc_interface *xc (!user_para->scaling_available_governors) )return -EINVAL ; -if ( (ret =lock_pages (user_para->affected_cpus, +if ( (ret =lock_pages (xch, user_para->affected_cpus, user_para->cpu_num *sizeof (uint32_t ))) ) goto unlock_1; -if ( (ret =lock_pages (user_para->scaling_available_frequencies, +if ( (ret =lock_pages (xch, user_para->scaling_available_frequencies, user_para->freq_num *sizeof (uint32_t ))) ) goto unlock_2; -if ( (ret =lock_pages (user_para->scaling_available_governors, +if ( (ret =lock_pages (xch, user_para->scaling_available_governors, user_para->gov_num *CPUFREQ_NAME_LEN *sizeof (char ))) ) goto unlock_3;
@@ -263,13 +263,13 @@ int xc_get_cpufreq_para(xc_interface *xc } unlock_4: -unlock_pages (user_para->scaling_available_governors, +unlock_pages (xch, user_para->scaling_available_governors, user_para->gov_num *CPUFREQ_NAME_LEN *sizeof (char )); unlock_3: -unlock_pages (user_para->scaling_available_frequencies, +unlock_pages (xch, user_para->scaling_available_frequencies, user_para->freq_num *sizeof (uint32_t )); unlock_2: -unlock_pages (user_para->affected_cpus, +unlock_pages (xch, user_para->affected_cpus, user_para->cpu_num *sizeof (uint32_t )); unlock_1:return ret;
tools/libxc/xc_private.c +42 -40
274 lines not on this page · raw message
tools/libxc/xc_private.h +10 -10
@@ -100,11 +100,11 @@ void xc_report_progress_step(xc_interfacvoid *xc_memalign (size_t alignment,size_t size); -int lock_pages (void *addr,size_t len); -void unlock_pages (void *addr,size_t len); +int lock_pages (xc_interface *xch,void *addr,size_t len); +void unlock_pages (xc_interface *xch,void *addr,size_t len); -int hcall_buf_prep (void **addr,size_t len); -void hcall_buf_release (void **addr,size_t len); +int hcall_buf_prep (xc_interface *xch,void **addr,size_t len); +void hcall_buf_release (xc_interface *xch,void **addr,size_t len);int do_xen_hypercall (xc_interface *xch,privcmd_hypercall_t *hypercall);
@@ -125,7 +125,7 @@ static inline int do_physdev_op(xc_interDECLARE_HYPERCALL ; -if (hcall_buf_prep (&op, len) !=0 ) +if (hcall_buf_prep (xch, &op, len) !=0 ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out1;
@@ -142,7 +142,7 @@ static inline int do_physdev_op(xc_inter " rebuild the user-space tool set?\n"); } -hcall_buf_release (&op, len); +hcall_buf_release (xch, &op, len); out1:return ret;
@@ -153,7 +153,7 @@ static inline int do_domctl(xc_interfaceint ret =-1 ;DECLARE_HYPERCALL ; -if (hcall_buf_prep ((void **)&domctl,sizeof (*domctl)) !=0 ) +if (hcall_buf_prep (xch, (void **)&domctl,sizeof (*domctl)) !=0 ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out1;
@@ -171,7 +171,7 @@ static inline int do_domctl(xc_interface " rebuild the user-space tool set?\n"); } -hcall_buf_release ((void **)&domctl,sizeof (*domctl)); +hcall_buf_release (xch, (void **)&domctl,sizeof (*domctl)); out1:return ret;
@@ -182,7 +182,7 @@ static inline int do_sysctl(xc_interfaceint ret =-1 ;DECLARE_HYPERCALL ; -if (hcall_buf_prep ((void **)&sysctl,sizeof (*sysctl)) !=0 ) +if (hcall_buf_prep (xch, (void **)&sysctl,sizeof (*sysctl)) !=0 ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out1;
@@ -200,7 +200,7 @@ static inline int do_sysctl(xc_interface " rebuild the user-space tool set?\n"); } -hcall_buf_release ((void **)&sysctl,sizeof (*sysctl)); +hcall_buf_release (xch, (void **)&sysctl,sizeof (*sysctl)); out1:return ret;
tools/libxc/xc_resume.c +2 -2
@@ -196,7 +196,7 @@ static int xc_domain_resume_any(xc_inter goto out; } -if (lock_pages (&ctxt,sizeof (ctxt)) ) +if (lock_pages (xch, &ctxt,sizeof (ctxt)) ) {ERROR ("Unable to lock ctxt" ); goto out;
@@ -235,7 +235,7 @@ static int xc_domain_resume_any(xc_inter#if defined(__i386__) || defined(__x86_64__) out: -unlock_pages ((void *)&ctxt,sizeof ctxt); +unlock_pages (xch, (void *)&ctxt,sizeof ctxt);if (p2m)munmap (p2m,P2M_FL_ENTRIES *PAGE_SIZE );if (p2m_frame_list)
tools/libxc/xc_tbuf.c +2 -2
@@ -129,7 +129,7 @@ int xc_tbuf_set_cpu_mask(xc_interface *xset_xen_guest_handle (sysctl.u.tbuf_op.cpu_mask.bitmap, bytemap); sysctl.u.tbuf_op.cpu_mask.nr_cpus =sizeof (bytemap) *8 ; -if (lock_pages (&bytemap,sizeof (bytemap)) !=0 ) +if (lock_pages (xch, &bytemap,sizeof (bytemap)) !=0 ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out;
@@ -137,7 +137,7 @@ int xc_tbuf_set_cpu_mask(xc_interface *x ret =do_sysctl (xch, &sysctl); -unlock_pages (&bytemap,sizeof (bytemap)); +unlock_pages (xch, &bytemap,sizeof (bytemap)); out:return ret;
tools/libxc/xc_tmem.c +4 -4
@@ -28,7 +28,7 @@ static int do_tmem_op(xc_interface *xch, hypercall.op = __HYPERVISOR_tmem_op; hypercall.arg[0 ] = (unsigned long )op; -if (lock_pages (op,sizeof (*op)) !=0 ) +if (lock_pages (xch, op,sizeof (*op)) !=0 ) {PERROR ("Could not lock memory for Xen hypercall" );return -EFAULT ;
@@ -39,7 +39,7 @@ static int do_tmem_op(xc_interface *xch,DPRINTF ("tmem operation failed -- need to" " rebuild the user-space tool set?\n" ); } -unlock_pages (op,sizeof (*op)); +unlock_pages (xch, op,sizeof (*op));return ret; }
@@ -66,7 +66,7 @@ int xc_tmem_control(xc_interface *xch, op.u.ctrl.arg3 = arg3;if (subop ==TMEMC_LIST ) { -if ((arg1 !=0 ) && (lock_pages (buf, arg1) !=0 )) +if ((arg1 !=0 ) && (lock_pages (xch, buf, arg1) !=0 )) {PERROR ("Could not lock memory for Xen hypercall" );return -ENOMEM ;
@@ -82,7 +82,7 @@ int xc_tmem_control(xc_interface *xch,if (subop ==TMEMC_LIST ) {if (arg1 !=0 ) -unlock_pages (buf, arg1); +unlock_pages (xch, buf, arg1); }return rc;
PATCH 1/1 libxc: Remove unnecessary double indirection from xc_readconsolering
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID 8ad75cd961a081ce4ba60c97899b13112d7a5f3f
# Parent 7e23b1acc3f23c9f06c88b6f4480a614c49c9a96
libxc: Remove unnecessary double indirection from xc_readconsolering
tools/console/daemon/io.c +1 -1
@@ -887,7 +887,7 @@ static void handle_hv_logs(void)if ((port =xc_evtchn_pending (xce_handle)) ==-1 )return ; -if (xc_readconsolering (xch, &bufptr, &size,0 ,1 , &index) ==0 && size >0 ) { +if (xc_readconsolering (xch, bufptr, &size,0 ,1 , &index) ==0 && size >0 ) {int logret;if (log_time_hv) logret = write_with_timestamp(log_hv_fd, buffer, size,
tools/libxc/xc_misc.c +1 -2
@@ -22,13 +22,12 @@#include <xen/hvm/hvm_op.h> int xc_readconsolering (xc_interface *xch, -char **pbuffer, +char *buffer,unsigned int *pnr_chars,int clear,int incremental,uint32_t *pindex) {int ret;DECLARE_SYSCTL ; -char *buffer = *pbuffer;unsigned int nr_chars = *pnr_chars; sysctl.cmd = XEN_SYSCTL_readconsole;
tools/libxc/xenctrl.h +1 -1
@@ -729,7 +729,7 @@ int xc_physdev_pci_access_modify(xc_inte int enable);int xc_readconsolering (xc_interface *xch, -char **pbuffer, +char *buffer,unsigned int *pnr_chars,int clear,int incremental,uint32_t *pindex);
tools/libxl/libxl.c +1 -1
@@ -3162,7 +3162,7 @@ int libxl_xen_console_read_line(libxl_ctint ret;memset (cr->buffer,0 , cr->size); - ret =xc_readconsolering (ctx->xch, &cr->buffer, &cr->count, + ret =xc_readconsolering (ctx->xch, cr->buffer, &cr->count, cr->clear, cr->incremental, &cr->index);if (ret <0 ) {XL_LOG_ERRNO (ctx,XL_LOG_ERROR ,"reading console ring buffer" );
tools/python/xen/lowlevel/xc/xc.c +2 -2
@@ -1116,7 +1116,7 @@ static PyObject *pyxc_readconsolering(Xc !str )return NULL ; - ret =xc_readconsolering (self->xc_handle, &str, &count, clear, + ret =xc_readconsolering (self->xc_handle, str, &count, clear, incremental, &index);if ( ret <0 )return pyxc_error_to_exception (self->xc_handle);
@@ -1133,7 +1133,7 @@ static PyObject *pyxc_readconsolering(Xc str = ptr + count; count = size - count; - ret =xc_readconsolering (self->xc_handle, &str, &count, clear, + ret =xc_readconsolering (self->xc_handle, str, &count, clear,1 , &index);if ( ret <0 )break ;
PATCH 1/1 libxc: use correct size of struct xen_mc
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1283779691 -3600
# Node ID b4aa42793b8a8434aa3d7371e22e86dcca4f5a7a # Parent 8ad75cd961a081ce4ba60c97899b13112d7a5f3f
libxc: use correct size of struct xen_mc
We want the size of the struct not the pointer (although rounding up to page size in lock_pages probably saves us).
tools/libxc/xc_misc.c +2 -2
@@ -153,7 +153,7 @@ int xc_mca_op(xc_interface *xch, structDECLARE_HYPERCALL ; mc->interface_version =XEN_MCA_INTERFACE_VERSION ; -if (lock_pages (xch, mc,sizeof (mc)) ) +if (lock_pages (xch, mc,sizeof (*mc)) ) {PERROR ("Could not lock xen_mc memory" );return -EINVAL ;
@@ -162,7 +162,7 @@ int xc_mca_op(xc_interface *xch, struct hypercall.op = __HYPERVISOR_mca; hypercall.arg[0 ] = (unsigned long )mc; ret =do_xen_hypercall (xch, &hypercall); -unlock_pages (xch, mc,sizeof (mc)); +unlock_pages (xch, mc,sizeof (*mc)); return ret; }#endif
PATCH 1/1 libxc: add to xc_domain_maximum_gpfn
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID e79d9a42c67e1d03f79d40529b2578578a5aa547 # Parent b4aa42793b8a8434aa3d7371e22e86dcca4f5a7a
libxc: add to xc_domain_maximum_gpfn
to replace various open-coded calls to XENMEM_maximum_gpfn
tools/libxc/ia64/xc_ia64_linux_save.c +1 -1
@@ -487,7 +487,7 @@ xc_domain_save(xc_interface *xch, int io goto out; } - p2m_size =xc_memory_op (xch, XENMEM_maximum_gpfn, &dom) +1 ; + p2m_size =xc_domain_maximum_gpfn (xch, dom);/* This is expected by xm restore. */ if (write_exact (io_fd, &p2m_size,sizeof (unsigned long ))) {
tools/libxc/ia64/xc_ia64_stubs.c +3 -3
@@ -114,7 +114,7 @@ xc_ia64_copy_memmap(xc_interface *xch, uint ret; - gpfn_max_prev =xc_memory_op (xch, XENMEM_maximum_gpfn, &domid); + gpfn_max_prev =xc_domain_maximum_gpfn (xch, domid);if (gpfn_max_prev <0 )return -1 ;
@@ -143,7 +143,7 @@ xc_ia64_copy_memmap(xc_interface *xch, u goto again; } - gpfn_max_post =xc_memory_op (xch, XENMEM_maximum_gpfn, &domid); + gpfn_max_post =xc_domain_maximum_gpfn (xch, domid);if (gpfn_max_prev <0 ) {free (memmap_info);return -1 ;
@@ -190,7 +190,7 @@ xc_ia64_map_foreign_p2m(xc_interface *xcint ret;int saved_errno; - gpfn_max =xc_memory_op (xch, XENMEM_maximum_gpfn, &dom); + gpfn_max =xc_domain_maximum_gpfn (xch, dom);if (gpfn_max <0 )return NULL ; p2m_size =
tools/libxc/xc_core_x86.c +2 -7
@@ -40,11 +40,6 @@ xc_core_arch_gpfn_may_present(struct xc_ } -static int nr_gpfns (xc_interface *xch,domid_t domid) -{ -return xc_memory_op (xch, XENMEM_maximum_gpfn, &domid) +1 ; -} -int xc_core_arch_auto_translated_physmap (const xc_dominfo_t *info) {
@@ -57,7 +52,7 @@ xc_core_arch_memory_map_get(xc_interfacexc_core_memory_map_t **mapp, unsigned int *nr_entries) { - unsigned long p2m_size = nr_gpfns(xch, info->domid); + unsigned long p2m_size = xc_domain_maximum_gpfn(xch, info->domid);xc_core_memory_map_t *map; map =malloc (sizeof (*map));
@@ -92,7 +87,7 @@ xc_core_arch_map_p2m_rw(xc_interface *xcint err;int i; - dinfo->p2m_size =nr_gpfns (xch, info->domid); + dinfo->p2m_size =xc_domain_maximum_gpfn (xch, info->domid);if ( dinfo->p2m_size < info->nr_pages ) {ERROR ("p2m_size < nr_pages -1 (%lx < %lx" , dinfo->p2m_size, info->nr_pages -1 );
tools/libxc/xc_domain.c +5 -0
@@ -578,6 +578,11 @@ int xc_domain_get_tsc_info(xc_interfacereturn rc; } + +int xc_domain_maximum_gpfn (xc_interface *xch,domid_t domid) +{ +return xc_memory_op (xch, XENMEM_maximum_gpfn, &domid) +1 ; +} int xc_domain_memory_increase_reservation(xc_interface *xch, uint32_t domid,
tools/libxc/xc_domain_save.c +1 -1
@@ -979,7 +979,7 @@ int xc_domain_save(xc_interface *xch, in }/* Get the size of the P2M table */ - dinfo->p2m_size =xc_memory_op (xch, XENMEM_maximum_gpfn, &dom) +1 ; + dinfo->p2m_size =xc_domain_maximum_gpfn (xch, dom);if ( dinfo->p2m_size > ~XEN_DOMCTL_PFINFO_LTAB_MASK ) {
tools/libxc/xenctrl.h +3 -0
@@ -784,6 +784,9 @@ int xc_domain_get_tsc_info(xc_interface uint32_t *incarnation);int xc_domain_disable_migrate (xc_interface *xch,uint32_t domid); + +int xc_domain_maximum_gpfn (xc_interface *xch,domid_t domid); + int xc_domain_memory_increase_reservation(xc_interface *xch, uint32_t domid,
PATCH 1/1 libxc: replace open-coded use of XENMEM_decrease_reservation
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID 4d8b7ca524c7aeace21ba151cb21c784b268ae5f # Parent e79d9a42c67e1d03f79d40529b2578578a5aa547
libxc: replace open-coded use of XENMEM_decrease_reservation
tools/libxc/xc_domain_restore.c +1 -9
@@ -1529,15 +1529,7 @@ int xc_domain_restore(xc_interface *xch,if ( nr_frees >0 ) { -struct xen_memory_reservation reservation = { - .nr_extents = nr_frees, - .extent_order =0 , - .domid = dom - }; -set_xen_guest_handle (reservation.extent_start, tailbuf.u.pv.pfntab); - -if ( (frc =xc_memory_op (xch, XENMEM_decrease_reservation, - &reservation)) != nr_frees ) +if ( (frc =xc_domain_memory_decrease_reservation (xch, dom, nr_frees,0 , tailbuf.u.pv.pfntab)) != nr_frees ) {PERROR ("Could not decrease reservation : %d" , frc); goto out;
PATCH 1/1 libxc: simplify performance counters API
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1283779691 -3600
# Node ID 8e9ada79914009870ea06339eb4211519a43a927 # Parent 4d8b7ca524c7aeace21ba151cb21c784b268ae5f
libxc: simplify performance counters API
Current function has heavily overloaded semantics for the various arguments. Separate out into more specific functions.
tools/libxc/xc_misc.c +32 -9
@@ -167,20 +167,29 @@ int xc_mca_op(xc_interface *xch, struct }#endif -int xc_perfc_control (xc_interface *xch, -uint32_t opcode, -xc_perfc_desc_t *desc, -xc_perfc_val_t *val, -int *nbr_desc, -int *nbr_val) +int xc_perfc_reset (xc_interface *xch) +{ +DECLARE_SYSCTL ; + + sysctl.cmd = XEN_SYSCTL_perfc_op; + sysctl.u.perfc_op.cmd = XEN_SYSCTL_PERFCOP_reset; +set_xen_guest_handle (sysctl.u.perfc_op.desc,NULL ); +set_xen_guest_handle (sysctl.u.perfc_op.val,NULL ); + +return do_sysctl (xch, &sysctl); +} + +int xc_perfc_query_number (xc_interface *xch, +int *nbr_desc, +int *nbr_val) {int rc;DECLARE_SYSCTL ; sysctl.cmd = XEN_SYSCTL_perfc_op; - sysctl.u.perfc_op.cmd = opcode; -set_xen_guest_handle (sysctl.u.perfc_op.desc, desc); -set_xen_guest_handle (sysctl.u.perfc_op.val, val); + sysctl.u.perfc_op.cmd = XEN_SYSCTL_PERFCOP_query; +set_xen_guest_handle (sysctl.u.perfc_op.desc,NULL ); +set_xen_guest_handle (sysctl.u.perfc_op.val,NULL ); rc =do_sysctl (xch, &sysctl);
@@ -190,6 +199,20 @@ int xc_perfc_control(xc_interface *xch, *nbr_val = sysctl.u.perfc_op.nr_vals;return rc; +} + +int xc_perfc_query (xc_interface *xch, +xc_perfc_desc_t *desc, +xc_perfc_val_t *val) +{ +DECLARE_SYSCTL ; + + sysctl.cmd = XEN_SYSCTL_perfc_op; + sysctl.u.perfc_op.cmd = XEN_SYSCTL_PERFCOP_query; +set_xen_guest_handle (sysctl.u.perfc_op.desc, desc); +set_xen_guest_handle (sysctl.u.perfc_op.val, val); + +return do_sysctl (xch, &sysctl); } int xc_lockprof_control(xc_interface *xch,
tools/libxc/xenctrl.h +7 -6
@@ -849,14 +849,15 @@ unsigned long xc_make_page_below_4G(xc_itypedef xen_sysctl_perfc_desc_t xc_perfc_desc_t ;typedef xen_sysctl_perfc_val_t xc_perfc_val_t ; +int xc_perfc_reset (xc_interface *xch); +int xc_perfc_query_number (xc_interface *xch, +int *nbr_desc, +int *nbr_val);/* IMPORTANT: The caller is responsible for mlock()'ing the @desc and @val arrays. */ -int xc_perfc_control (xc_interface *xch, -uint32_t op, -xc_perfc_desc_t *desc, -xc_perfc_val_t *val, -int *nbr_desc, -int *nbr_val); +int xc_perfc_query (xc_interface *xch, +xc_perfc_desc_t *desc, +xc_perfc_val_t *val);typedef xen_sysctl_lockprof_data_t xc_lockprof_data_t ;/* IMPORTANT: The caller is responsible for mlock()'ing the @data array. */
tools/misc/xenperf.c +3 -6
@@ -137,8 +137,7 @@ int main(int argc, char *argv[])if ( reset ) { -if (xc_perfc_control (xc_handle, XEN_SYSCTL_PERFCOP_reset, -NULL ,NULL ,NULL ,NULL ) !=0 ) +if (xc_perfc_reset (xc_handle) !=0 ) {fprintf (stderr,"Error reseting performance counters: %d (%s)\n" , errno,strerror (errno));
@@ -148,8 +147,7 @@ int main(int argc, char *argv[])return 0 ; } -if (xc_perfc_control (xc_handle, XEN_SYSCTL_PERFCOP_query, -NULL ,NULL , &num_desc, &num_val) !=0 ) +if (xc_perfc_query_number (xc_handle, &num_desc, &num_val) !=0 ) {fprintf (stderr,"Error getting number of perf counters: %d (%s)\n" , errno,strerror (errno));
@@ -169,8 +167,7 @@ int main(int argc, char *argv[])exit (-1 ); } -if (xc_perfc_control (xc_handle, XEN_SYSCTL_PERFCOP_query, - pcd, pcv,NULL ,NULL ) !=0 ) +if (xc_perfc_query (xc_handle, pcd, pcv) !=0 ) {fprintf (stderr,"Error getting perf counter: %d (%s)\n" , errno,strerror (errno));
PATCH 1/1 libxc: simplify lock profiling API
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1283779691 -3600
# Node ID 7b45202f78cd82d320fb32fea67c0a618697baec # Parent 8e9ada79914009870ea06339eb4211519a43a927
libxc: simplify lock profiling API
Current function has heavily overloaded semantics for the various arguments. Separate out into more specific functions.
tools/libxc/xc_misc.c +32 -8
@@ -215,8 +215,35 @@ int xc_perfc_query(xc_interface *xch,return do_sysctl (xch, &sysctl); } -int xc_lockprof_control (xc_interface *xch, -uint32_t opcode, +int xc_lockprof_reset (xc_interface *xch) +{ +DECLARE_SYSCTL ; + + sysctl.cmd = XEN_SYSCTL_lockprof_op; + sysctl.u.lockprof_op.cmd = XEN_SYSCTL_LOCKPROF_reset; +set_xen_guest_handle (sysctl.u.lockprof_op.data,NULL ); + +return do_sysctl (xch, &sysctl); +} + +int xc_lockprof_query_number (xc_interface *xch, +uint32_t *n_elems) +{ +int rc; +DECLARE_SYSCTL ; + + sysctl.cmd = XEN_SYSCTL_lockprof_op; + sysctl.u.lockprof_op.cmd = XEN_SYSCTL_LOCKPROF_query; +set_xen_guest_handle (sysctl.u.lockprof_op.data,NULL ); + + rc =do_sysctl (xch, &sysctl); + + *n_elems = sysctl.u.lockprof_op.nr_elem; + +return rc; +} + +int xc_lockprof_query (xc_interface *xch,uint32_t *n_elems,uint64_t *time,xc_lockprof_data_t *data)
@@ -225,16 +252,13 @@ int xc_lockprof_control(xc_interface *xcDECLARE_SYSCTL ; sysctl.cmd = XEN_SYSCTL_lockprof_op; - sysctl.u.lockprof_op.cmd = opcode; - sysctl.u.lockprof_op.max_elem = n_elems ? *n_elems :0 ; + sysctl.u.lockprof_op.cmd = XEN_SYSCTL_LOCKPROF_query; + sysctl.u.lockprof_op.max_elem = *n_elems;set_xen_guest_handle (sysctl.u.lockprof_op.data, data); rc =do_sysctl (xch, &sysctl); -if (n_elems) - *n_elems = sysctl.u.lockprof_op.nr_elem; -if (time) - *time = sysctl.u.lockprof_op.time; + *n_elems = sysctl.u.lockprof_op.nr_elem;return rc; }
tools/libxc/xenctrl.h +7 -5
@@ -860,12 +860,14 @@ int xc_perfc_query(xc_interface *xch, xc_perfc_val_t *val);typedef xen_sysctl_lockprof_data_t xc_lockprof_data_t ; +int xc_lockprof_reset (xc_interface *xch); +int xc_lockprof_query_number (xc_interface *xch, +uint32_t *n_elems);/* IMPORTANT: The caller is responsible for mlock()'ing the @data array. */ -int xc_lockprof_control (xc_interface *xch, -uint32_t opcode, -uint32_t *n_elems, -uint64_t *time, -xc_lockprof_data_t *data); +int xc_lockprof_query (xc_interface *xch, +uint32_t *n_elems, +uint64_t *time, +xc_lockprof_data_t *data);/** * Memory maps a range within one domain to a local address range. Mappings
tools/misc/xenlockprof.c +3 -6
@@ -60,8 +60,7 @@ int main(int argc, char *argv[])if ( argc >1 ) { -if (xc_lockprof_control (xc_handle, XEN_SYSCTL_LOCKPROF_reset,NULL , -NULL ,NULL ) !=0 ) +if (xc_lockprof_reset (xc_handle) !=0 ) {fprintf (stderr,"Error reseting profile data: %d (%s)\n" , errno,strerror (errno));
@@ -71,8 +70,7 @@ int main(int argc, char *argv[]) } n =0 ; -if (xc_lockprof_control (xc_handle, XEN_SYSCTL_LOCKPROF_query, &n, -NULL ,NULL ) !=0 ) +if (xc_lockprof_query_number (xc_handle, &n) !=0 ) {fprintf (stderr,"Error getting number of profile records: %d (%s)\n" , errno,strerror (errno));
@@ -89,8 +87,7 @@ int main(int argc, char *argv[]) } i = n; -if (xc_lockprof_control (xc_handle, XEN_SYSCTL_LOCKPROF_query, &i, - &time, data) !=0 ) +if (xc_lockprof_query (xc_handle, &i, &time, data) !=0 ) {fprintf (stderr,"Error getting profile records: %d (%s)\n" , errno,strerror (errno));
PATCH 1/1 libxc: infrastructure for hypercall safe data buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1283779691 -3600
# Node ID bf7fb64762eb7decea9a6804460f0f966496ba07 # Parent 7b45202f78cd82d320fb32fea67c0a618697baec
libxc: infrastructure for hypercall safe data buffers.
tools/libxc/Makefile +1 -0
@@ -27,6 +27,7 @@ CTRL_SRCS-y += xc_mem_event.c CTRL_SRCS-y += xc_mem_event.c CTRL_SRCS-y += xc_mem_paging.c CTRL_SRCS-y += xc_memshr.c +CTRL_SRCS-y += xc_hcall_buf.c CTRL_SRCS-y += xtl_core.c CTRL_SRCS-y += xtl_logger_stdio.c CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
tools/libxc/xc_hcall_buf.c new file +147 -0
147 lines not on this page · raw message
tools/libxc/xc_private.h +56 -0
62 lines not on this page · raw message
tools/libxc/xenctrl.h +143 -0
149 lines not on this page · raw message
PATCH 1/1 libxc: convert xc_version over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1283779691 -3600
# Node ID f3b26cbd7eb5cc0ce7321aaae9eefb821192e86f # Parent bf7fb64762eb7decea9a6804460f0f966496ba07
libxc: convert xc_version over to hypercall buffers
tools/libxc/xc_private.c +16 -12
@@ -629,42 +629,46 @@ int xc_sysctl(xc_interface *xch, structint xc_version (xc_interface *xch,int cmd,void *arg) { -int rc, argsize =0 ; +DECLARE_HYPERCALL_BOUNCE (arg,0 ,XC_HYPERCALL_BUFFER_BOUNCE_OUT );/* Size unknown until cmd decoded */ +size_t sz =0 ; +int rc;switch ( cmd ) {case XENVER_extraversion: - argsize =sizeof (xen_extraversion_t); + sz =sizeof (xen_extraversion_t);break ;case XENVER_compile_info: - argsize =sizeof (xen_compile_info_t); + sz =sizeof (xen_compile_info_t);break ;case XENVER_capabilities: - argsize =sizeof (xen_capabilities_info_t); + sz =sizeof (xen_capabilities_info_t);break ;case XENVER_changeset: - argsize =sizeof (xen_changeset_info_t); + sz =sizeof (xen_changeset_info_t);break ;case XENVER_platform_parameters: - argsize =sizeof (xen_platform_parameters_t); + sz =sizeof (xen_platform_parameters_t);break ; } -if ( (argsize !=0 ) && (lock_pages (xch, arg, argsize) !=0 ) ) +HYPERCALL_BOUNCE_SET_SIZE (arg, sz); + +if ( (sz !=0 ) &&xc_hypercall_bounce_pre (xch, arg) ) {PERROR ("Could not lock memory for version hypercall" );return -ENOMEM ; }#ifdef VALGRIND -if (argsize !=0 ) -memset (arg,0 , argsize); +if (sz !=0 ) +memset (hypercall_bounce_get (bounce),0 , sz);#endif - rc =do_xen_version (xch, cmd, arg); + rc =do_xen_version (xch, cmd,HYPERCALL_BUFFER (arg)); -if ( argsize !=0 ) -unlock_pages (xch, arg, argsize); +if ( sz !=0 ) +xc_hypercall_bounce_post (xch, arg);return rc; }
tools/libxc/xc_private.h +3 -2
@@ -164,13 +164,14 @@ void xc__hypercall_bounce_post(xc_interfint do_xen_hypercall (xc_interface *xch,privcmd_hypercall_t *hypercall); -static inline int do_xen_version (xc_interface *xch,int cmd,void *dest) +static inline int do_xen_version (xc_interface *xch,int cmd,xc_hypercall_buffer_t *dest) {DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER_ARGUMENT (dest); hypercall.op = __HYPERVISOR_xen_version; hypercall.arg[0 ] = (unsigned long ) cmd; - hypercall.arg[1 ] = (unsigned long ) dest; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (dest);return do_xen_hypercall (xch, &hypercall); }
PATCH 1/1 libxc: convert domctl interfaces over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID 7f735088ac1d169d140d978441c772b62083fae0 # Parent f3b26cbd7eb5cc0ce7321aaae9eefb821192e86f
libxc: convert domctl interfaces over to hypercall buffers
(defer save/restore and shadow related interfaces til a later patch)
tools/libxc/ia64/xc_ia64_stubs.c +1 -1
@@ -46,7 +46,7 @@ xc_ia64_get_pfn_list(xc_interface *xch, domctl.u.getmemlist.max_pfns = nr_pages; domctl.u.getmemlist.start_pfn = start_page; domctl.u.getmemlist.num_pfns =0 ; -set_xen_guest_handle (domctl.u.getmemlist.buffer, pfn_buf); +xc_set_xen_guest_handle (domctl.u.getmemlist.buffer, pfn_buf);if (lock_pages (pfn_buf, nr_pages *sizeof (xen_pfn_t)) !=0 ) {PERROR ("Could not lock pfn list buffer" );
tools/libxc/xc_dom_boot.c +12 -6
@@ -61,9 +61,10 @@ static int setup_hypercall_page(struct xreturn rc; } -static int launch_vm (xc_interface *xch,domid_t domid,void *ctxt) +static int launch_vm (xc_interface *xch,domid_t domid,xc_hypercall_buffer_t *ctxt) {DECLARE_DOMCTL ; +DECLARE_HYPERCALL_BUFFER_ARGUMENT (ctxt);int rc;xc_dom_printf (xch,"%s: called, ctxt=%p" , __FUNCTION__, ctxt);
@@ -71,7 +72,7 @@ static int launch_vm(xc_interface *xch, domctl.cmd = XEN_DOMCTL_setvcpucontext; domctl.domain = domid; domctl.u.vcpucontext.vcpu =0 ; -set_xen_guest_handle (domctl.u.vcpucontext.ctxt, ctxt); +xc_set_xen_guest_handle (domctl.u.vcpucontext.ctxt, ctxt); rc =do_domctl (xch, &domctl);if ( rc !=0 ) xc_dom_panic(xch, XC_INTERNAL_ERROR,
@@ -202,8 +203,12 @@ int xc_dom_boot_image(struct xc_dom_imagint xc_dom_boot_image (struct xc_dom_image *dom) {DECLARE_DOMCTL ; -vcpu_guest_context_any_t ctxt; +DECLARE_HYPERCALL_BUFFER (vcpu_guest_context_any_t, ctxt);int rc; + + ctxt =xc_hypercall_buffer_alloc (dom->xch, ctxt,sizeof (*ctxt)); +if ( ctxt ==NULL ) +return -1 ;DOMPRINTF_CALLED (dom->xch);
@@ -260,12 +265,13 @@ int xc_dom_boot_image(struct xc_dom_imagreturn rc;/* let the vm run */ -memset (&ctxt,0 ,sizeof (ctxt)); -if ( (rc = dom->arch_hooks->vcpu (dom, &ctxt)) !=0 ) +memset (ctxt,0 ,sizeof (ctxt)); +if ( (rc = dom->arch_hooks->vcpu (dom, ctxt)) !=0 )return rc;xc_dom_unmap_all (dom); - rc =launch_vm (dom->xch, dom->guest_domid, &ctxt); + rc =launch_vm (dom->xch, dom->guest_domid,HYPERCALL_BUFFER (ctxt)); +xc_hypercall_buffer_free (dom->xch, ctxt);return rc; }
tools/libxc/xc_domain.c +70 -71
285 lines not on this page · raw message
tools/libxc/xc_private.c +16 -8
@@ -322,12 +322,18 @@ int xc_get_pfn_type_batch(xc_interface *int xc_get_pfn_type_batch (xc_interface *xch,uint32_t dom,unsigned int num,xen_pfn_t *arr) { +int rc;DECLARE_DOMCTL ; +DECLARE_HYPERCALL_BOUNCE (arr,sizeof (*arr) * num,XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); +if (xc_hypercall_bounce_pre (xch, arr) ) +return -1 ; domctl.cmd = XEN_DOMCTL_getpageframeinfo3; domctl.domain = (domid_t )dom; domctl.u.getpageframeinfo3.num = num; -set_xen_guest_handle (domctl.u.getpageframeinfo3.array, arr); -return do_domctl (xch, &domctl); +xc_set_xen_guest_handle (domctl.u.getpageframeinfo3.array, arr); + rc =do_domctl (xch, &domctl); +xc_hypercall_bounce_post (xch, arr); +return rc; } int xc_mmuext_op(
@@ -557,25 +563,27 @@ int xc_get_pfn_list(xc_interface *xch, unsigned long max_pfns) {DECLARE_DOMCTL ; +DECLARE_HYPERCALL_BOUNCE (pfn_buf, max_pfns *sizeof (*pfn_buf),XC_HYPERCALL_BUFFER_BOUNCE_OUT );int ret; - domctl.cmd = XEN_DOMCTL_getmemlist; - domctl.domain = (domid_t )domid; - domctl.u.getmemlist.max_pfns = max_pfns; -set_xen_guest_handle (domctl.u.getmemlist.buffer, pfn_buf);#ifdef VALGRIND memset (pfn_buf,0 , max_pfns *sizeof (*pfn_buf));#endif -if (lock_pages (xch, pfn_buf, max_pfns *sizeof (*pfn_buf)) !=0 ) +if (xc_hypercall_bounce_pre (xch, pfn_buf) ) {PERROR ("xc_get_pfn_list: pfn_buf lock failed" );return -1 ; } + domctl.cmd = XEN_DOMCTL_getmemlist; + domctl.domain = (domid_t )domid; + domctl.u.getmemlist.max_pfns = max_pfns; +xc_set_xen_guest_handle (domctl.u.getmemlist.buffer, pfn_buf); + ret =do_domctl (xch, &domctl); -unlock_pages (xch, pfn_buf, max_pfns *sizeof (*pfn_buf)); +xc_hypercall_bounce_post (xch, pfn_buf);return (ret <0 ) ?-1 : domctl.u.getmemlist.num_pfns; }
tools/libxc/xc_private.h +6 -6
@@ -209,17 +209,18 @@ static inline int do_domctl(xc_interface {int ret =-1 ;DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BOUNCE (domctl,sizeof (*domctl),XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); -if (hcall_buf_prep (xch, (void **)&domctl,sizeof (*domctl)) !=0 ) + domctl->interface_version =XEN_DOMCTL_INTERFACE_VERSION ; + +if (xc_hypercall_bounce_pre (xch, domctl) ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out1; } - domctl->interface_version =XEN_DOMCTL_INTERFACE_VERSION ; - hypercall.op = __HYPERVISOR_domctl; - hypercall.arg[0 ] = (unsigned long )domctl; + hypercall.arg[0 ] =HYPERCALL_BUFFER_AS_ARG (domctl);if ( (ret =do_xen_hypercall (xch, &hypercall)) <0 ) {
@@ -228,8 +229,7 @@ static inline int do_domctl(xc_interface " rebuild the user-space tool set?\n"); } -hcall_buf_release (xch, (void **)&domctl,sizeof (*domctl)); - +xc_hypercall_bounce_post (xch, domctl); out1:return ret; }
tools/libxc/xc_resume.c +0 -7
@@ -196,12 +196,6 @@ static int xc_domain_resume_any(xc_inter goto out; } -if (lock_pages (xch, &ctxt,sizeof (ctxt)) ) - { -ERROR ("Unable to lock ctxt" ); - goto out; - } -if (xc_vcpu_getcontext (xch, domid,0 , &ctxt) ) {ERROR ("Could not get vcpu context" );
@@ -235,7 +229,6 @@ static int xc_domain_resume_any(xc_inter#if defined(__i386__) || defined(__x86_64__) out: -unlock_pages (xch, (void *)&ctxt,sizeof ctxt);if (p2m)munmap (p2m,P2M_FL_ENTRIES *PAGE_SIZE );if (p2m_frame_list)
PATCH 1/1 libxc: convert shadow domctl interfaces and save/restore over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID 2a5e84fe718ae25e91785643388411b70d4c013b
# Parent 7f735088ac1d169d140d978441c772b62083fae0
libxc: convert shadow domctl interfaces and save/restore over to hypercall buffers
tools/libxc/xc_domain.c +6 -3
@@ -404,7 +404,7 @@ int xc_shadow_control(xc_interface *xch, int xc_shadow_control(xc_interface *xch, uint32_t domid, unsigned int sop, - unsigned long *dirty_bitmap, + xc_hypercall_buffer_t *dirty_bitmap, unsigned long pages, unsigned long *mb, uint32_t mode,
@@ -412,14 +412,17 @@ int xc_shadow_control(xc_interface *xch, {int rc;DECLARE_DOMCTL ; +DECLARE_HYPERCALL_BUFFER_ARGUMENT (dirty_bitmap); + domctl.cmd = XEN_DOMCTL_shadow_op; domctl.domain = (domid_t )domid; domctl.u.shadow_op.op = sop; domctl.u.shadow_op.pages = pages; domctl.u.shadow_op.mb = mb ? *mb :0 ; domctl.u.shadow_op.mode = mode; -set_xen_guest_handle (domctl.u.shadow_op.dirty_bitmap, - (uint8_t *)dirty_bitmap); +if (dirty_bitmap !=NULL ) +xc_set_xen_guest_handle (domctl.u.shadow_op.dirty_bitmap, + dirty_bitmap); rc =do_domctl (xch, &domctl);
tools/libxc/xc_domain_restore.c +27 -23
135 lines not on this page · raw message
tools/libxc/xc_domain_save.c +15 -25
@@ -411,7 +411,7 @@ static int print_stats(xc_interface *xchstatic int analysis_phase (xc_interface *xch,uint32_t domid,struct save_ctx *ctx, -unsigned long *arr,int runs) +xc_hypercall_buffer_t *arr,int runs) {long long start, now;xc_shadow_op_stats_t stats;
@@ -915,7 +915,9 @@ int xc_domain_save(xc_interface *xch, in- that should be sent this iteration (unless later marked as skip); - to skip this iteration because already dirty; - to fixup by sending at the end if not already resent; */ -unsigned long *to_send =NULL , *to_skip =NULL , *to_fix =NULL ; + DECLARE_HYPERCALL_BUFFER(unsigned long, to_skip); + DECLARE_HYPERCALL_BUFFER(unsigned long, to_send); +unsigned long *to_fix =NULL ;xc_shadow_op_stats_t stats;
@@ -1034,9 +1036,9 @@ int xc_domain_save(xc_interface *xch, in sent_last_iter = dinfo->p2m_size;/* Setup to_send / to_fix and to_skip bitmaps */ - to_send =xc_memalign (PAGE_SIZE ,ROUNDUP (BITMAP_SIZE ,PAGE_SHIFT )); + to_send =xc_hypercall_buffer_alloc_pages (xch, to_send,NRPAGES (BITMAP_SIZE )); + to_skip =xc_hypercall_buffer_alloc_pages (xch, to_skip,NRPAGES (BITMAP_SIZE )); to_fix =calloc (1 ,BITMAP_SIZE ); - to_skip =xc_memalign (PAGE_SIZE ,ROUNDUP (BITMAP_SIZE ,PAGE_SHIFT ));if ( !to_send || !to_fix || !to_skip ) {
@@ -1046,20 +1048,7 @@ int xc_domain_save(xc_interface *xch, inmemset (to_send,0xff ,BITMAP_SIZE ); -if (lock_pages (xch, to_send,BITMAP_SIZE ) ) - { -PERROR ("Unable to lock to_send" ); -return 1 ; - } - -/* (to fix is local only) */ -if (lock_pages (xch, to_skip,BITMAP_SIZE ) ) - { -PERROR ("Unable to lock to_skip" ); -return 1 ; - } - -if ( hvm ) +if ( hvm ) {/* Need another buffer for HVM context */ hvm_buf_size =xc_domain_hvm_getcontext (xch, dom,0 ,0 );
@@ -1076,7 +1065,7 @@ int xc_domain_save(xc_interface *xch, in } } -analysis_phase (xch, dom, ctx, to_skip,0 ); +analysis_phase (xch, dom, ctx,HYPERCALL_BUFFER (to_skip),0 ); pfn_type =xc_memalign (PAGE_SIZE ,ROUNDUP (MAX_BATCH_SIZE *sizeof (*pfn_type),PAGE_SHIFT ));
@@ -1188,7 +1177,7 @@ int xc_domain_save(xc_interface *xch, in/* Slightly wasteful to peek the whole array evey time, but this is fast enough for the moment. */ frc =xc_shadow_control ( - xch, dom,XEN_DOMCTL_SHADOW_OP_PEEK , to_skip, + xch, dom,XEN_DOMCTL_SHADOW_OP_PEEK ,HYPERCALL_BUFFER (to_skip), dinfo->p2m_size,NULL ,0 ,NULL );if ( frc != dinfo->p2m_size ) {
@@ -1528,8 +1517,8 @@ int xc_domain_save(xc_interface *xch, in } -if (xc_shadow_control (xch, dom, -XEN_DOMCTL_SHADOW_OP_CLEAN , to_send, +if (xc_shadow_control (xch, dom, +XEN_DOMCTL_SHADOW_OP_CLEAN ,HYPERCALL_BUFFER (to_send), dinfo->p2m_size,NULL ,0 , &stats) != dinfo->p2m_size ) {PERROR ("Error flushing shadow PT" );
@@ -1857,7 +1846,7 @@ int xc_domain_save(xc_interface *xch, inprint_stats (xch, dom,0 , &stats,1 );if (xc_shadow_control (xch, dom, -XEN_DOMCTL_SHADOW_OP_CLEAN , to_send, +XEN_DOMCTL_SHADOW_OP_CLEAN ,HYPERCALL_BUFFER (to_send), dinfo->p2m_size,NULL ,0 , &stats) != dinfo->p2m_size ) {PERROR ("Error flushing shadow PT" );
@@ -1888,12 +1877,13 @@ int xc_domain_save(xc_interface *xch, inif ( ctx->live_m2p )munmap (ctx->live_m2p,M2P_SIZE (ctx->max_mfn)); +xc_hypercall_buffer_free_pages (xch, to_send,NRPAGES (BITMAP_SIZE )); +xc_hypercall_buffer_free_pages (xch, to_skip,NRPAGES (BITMAP_SIZE )); +free (pfn_type);free (pfn_batch);free (pfn_err); -free (to_send);free (to_fix); -free (to_skip);DPRINTF ("Save exit rc=%d\n" ,rc);
tools/libxc/xenctrl.h +1 -1
@@ -610,7 +610,7 @@ int xc_shadow_control(xc_interface *xch, int xc_shadow_control(xc_interface *xch, uint32_t domid, unsigned int sop, - unsigned long *dirty_bitmap, + xc_hypercall_buffer_t *dirty_bitmap, unsigned long pages, unsigned long *mb, uint32_t mode,
tools/libxc/xg_private.h +1 -0
@@ -157,6 +157,7 @@ typedef l4_pgentry_64_t l4_pgentry_t;#define PAGE_MASK_IA64 (~(PAGE_SIZE_IA64-1))#define ROUNDUP (_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1)) +#define NRPAGES (x) (ROUNDUP(x, PAGE_SHIFT) >> PAGE_SHIFT)/* XXX SMH: following skanky macros rely on variable p2m_size being set */
PATCH 1/1 libxc: convert sysctl interfaces over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID 92e9795d06413325c84f2220cf33c0dd831e8355 # Parent 2a5e84fe718ae25e91785643388411b70d4c013b
libxc: convert sysctl interfaces over to hypercall buffers
tools/libxc/xc_cpupool.c +20 -18
@@ -72,8 +72,14 @@ int xc_cpupool_getinfo(xc_interface *xchint err =0 ;int p;uint32_t poolid = first_poolid; -uint8_t local[sizeof (info->cpumap)];DECLARE_SYSCTL ; +DECLARE_HYPERCALL_BUFFER (uint8_t, local); + + local =xc_hypercall_buffer_alloc (xch, local,sizeof (info->cpumap)); +if ( local ==NULL ) { +PERROR ("Could not allocate locked memory for Xen hypercall" ); +return -ENOMEM ; + }memset (info,0 , n_max *sizeof (xc_cpupoolinfo_t));
@@ -82,17 +88,10 @@ int xc_cpupool_getinfo(xc_interface *xch sysctl.cmd = XEN_SYSCTL_cpupool_op; sysctl.u.cpupool_op.op =XEN_SYSCTL_CPUPOOL_OP_INFO ; sysctl.u.cpupool_op.cpupool_id = poolid; -set_xen_guest_handle (sysctl.u.cpupool_op.cpumap.bitmap, local); +xc_set_xen_guest_handle (sysctl.u.cpupool_op.cpumap.bitmap, local); sysctl.u.cpupool_op.cpumap.nr_cpus =sizeof (info->cpumap) *8 ; -if ( (err =lock_pages (xch, local,sizeof (local))) !=0 ) - { -PERROR ("Could not lock memory for Xen hypercall" ); -break ; - } err =do_sysctl_save (xch, &sysctl); -unlock_pages (xch, local,sizeof (local)); -if ( err <0 )break ;
@@ -103,6 +102,8 @@ int xc_cpupool_getinfo(xc_interface *xch poolid = sysctl.u.cpupool_op.cpupool_id +1 ; info++; } + +xc_hypercall_buffer_free (xch, local);if ( p ==0 )return err;
@@ -153,27 +154,28 @@ int xc_cpupool_freeinfo(xc_interface *xc uint64_t *cpumap) {int err; -uint8_t local[sizeof (*cpumap)];DECLARE_SYSCTL ; +DECLARE_HYPERCALL_BUFFER (uint8_t, local); + + local =xc_hypercall_buffer_alloc (xch, local,sizeof (*cpumap)); +if ( local ==NULL ) { +PERROR ("Could not allocate locked memory for Xen hypercall" ); +return -ENOMEM ; + } sysctl.cmd = XEN_SYSCTL_cpupool_op; sysctl.u.cpupool_op.op =XEN_SYSCTL_CPUPOOL_OP_FREEINFO ; -set_xen_guest_handle (sysctl.u.cpupool_op.cpumap.bitmap, local); +xc_set_xen_guest_handle (sysctl.u.cpupool_op.cpumap.bitmap, local); sysctl.u.cpupool_op.cpumap.nr_cpus =sizeof (*cpumap) *8 ; -if ( (err =lock_pages (xch, local,sizeof (local))) !=0 ) - { -PERROR ("Could not lock memory for Xen hypercall" ); -return err; - } - err =do_sysctl_save (xch, &sysctl); -unlock_pages (xch, local,sizeof (local));if (err <0 )return err;bitmap_byte_to_64 (cpumap, local,sizeof (local) *8 ); +xc_hypercall_buffer_free (xch, local); +return 0 ; }
tools/libxc/xc_domain.c +4 -3
@@ -245,21 +245,22 @@ int xc_domain_getinfolist(xc_interface * {int ret =0 ;DECLARE_SYSCTL ; +DECLARE_HYPERCALL_BOUNCE (info, max_domains*sizeof (*info),XC_HYPERCALL_BUFFER_BOUNCE_OUT ); -if (lock_pages (xch, info, max_domains*sizeof (xc_domaininfo_t)) !=0 ) +if (xc_hypercall_bounce_pre (xch, info) )return -1 ; sysctl.cmd = XEN_SYSCTL_getdomaininfolist; sysctl.u.getdomaininfolist.first_domain = first_domain; sysctl.u.getdomaininfolist.max_domains = max_domains; -set_xen_guest_handle (sysctl.u.getdomaininfolist.buffer, info); +xc_set_xen_guest_handle (sysctl.u.getdomaininfolist.buffer, info);if (xc_sysctl (xch, &sysctl) <0 ) ret =-1 ;else ret = sysctl.u.getdomaininfolist.num_domains; -unlock_pages (xch, info, max_domains*sizeof (xc_domaininfo_t)); +xc_hypercall_bounce_post (xch, info);return ret; }
tools/libxc/xc_misc.c +38 -32
164 lines not on this page · raw message
tools/libxc/xc_offline_page.c +12 -9
@@ -66,12 +66,13 @@ int xc_mark_page_online(xc_interface *xc unsigned long end, uint32_t *status) {DECLARE_SYSCTL ; +DECLARE_HYPERCALL_BOUNCE (status,sizeof (uint32_t )*(end - start +1 ),XC_HYPERCALL_BUFFER_BOUNCE_BOTH );int ret =-1 ;if ( !status || (end < start) )return -EINVAL ; -if (lock_pages (xch, status,sizeof (uint32_t )*(end - start +1 ))) +if (xc_hypercall_bounce_pre (xch, status) ) {ERROR ("Could not lock memory for xc_mark_page_online\n" );return -EINVAL ;
@@ -81,10 +82,10 @@ int xc_mark_page_online(xc_interface *xc sysctl.u.page_offline.start = start; sysctl.u.page_offline.cmd = sysctl_page_online; sysctl.u.page_offline.end = end; -set_xen_guest_handle (sysctl.u.page_offline.status, status); +xc_set_xen_guest_handle (sysctl.u.page_offline.status, status); ret =xc_sysctl (xch, &sysctl); -unlock_pages (xch, status,sizeof (uint32_t )*(end - start +1 )); +xc_hypercall_bounce_post (xch, status);return ret; }
@@ -93,12 +94,13 @@ int xc_mark_page_offline(xc_interface *x unsigned long end, uint32_t *status) {DECLARE_SYSCTL ; +DECLARE_HYPERCALL_BOUNCE (status,sizeof (uint32_t )*(end - start +1 ),XC_HYPERCALL_BUFFER_BOUNCE_BOTH );int ret =-1 ;if ( !status || (end < start) )return -EINVAL ; -if (lock_pages (xch, status,sizeof (uint32_t )*(end - start +1 ))) +if (xc_hypercall_bounce_pre (xch, status) ) {ERROR ("Could not lock memory for xc_mark_page_offline" );return -EINVAL ;
@@ -108,10 +110,10 @@ int xc_mark_page_offline(xc_interface *x sysctl.u.page_offline.start = start; sysctl.u.page_offline.cmd = sysctl_page_offline; sysctl.u.page_offline.end = end; -set_xen_guest_handle (sysctl.u.page_offline.status, status); +xc_set_xen_guest_handle (sysctl.u.page_offline.status, status); ret =xc_sysctl (xch, &sysctl); -unlock_pages (xch, status,sizeof (uint32_t )*(end - start +1 )); +xc_hypercall_bounce_post (xch, status);return ret; }
@@ -120,12 +122,13 @@ int xc_query_page_offline_status(xc_inte unsigned long end, uint32_t *status) {DECLARE_SYSCTL ; +DECLARE_HYPERCALL_BOUNCE (status,sizeof (uint32_t )*(end - start +1 ),XC_HYPERCALL_BUFFER_BOUNCE_BOTH );int ret =-1 ;if ( !status || (end < start) )return -EINVAL ; -if (lock_pages (xch, status,sizeof (uint32_t )*(end - start +1 ))) +if (xc_hypercall_bounce_pre (xch, status) ) {ERROR ("Could not lock memory for xc_query_page_offline_status\n" );return -EINVAL ;
@@ -135,10 +138,10 @@ int xc_query_page_offline_status(xc_inte sysctl.u.page_offline.start = start; sysctl.u.page_offline.cmd = sysctl_query_page_offline; sysctl.u.page_offline.end = end; -set_xen_guest_handle (sysctl.u.page_offline.status, status); +xc_set_xen_guest_handle (sysctl.u.page_offline.status, status); ret =xc_sysctl (xch, &sysctl); -unlock_pages (xch, status,sizeof (uint32_t )*(end - start +1 )); +xc_hypercall_bounce_post (xch, status);return ret; }
tools/libxc/xc_pm.c +49 -46
187 lines not on this page · raw message
tools/libxc/xc_private.h +6 -7
@@ -238,18 +238,18 @@ static inline int do_sysctl(xc_interface {int ret =-1 ;DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BOUNCE (sysctl,sizeof (*sysctl),XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); -if (hcall_buf_prep (xch, (void **)&sysctl,sizeof (*sysctl)) !=0 ) + sysctl->interface_version =XEN_SYSCTL_INTERFACE_VERSION ; + +if (xc_hypercall_bounce_pre (xch, sysctl) ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out1; } - sysctl->interface_version =XEN_SYSCTL_INTERFACE_VERSION ; - hypercall.op = __HYPERVISOR_sysctl; - hypercall.arg[0 ] = (unsigned long )sysctl; - + hypercall.arg[0 ] =HYPERCALL_BUFFER_AS_ARG (sysctl);if ( (ret =do_xen_hypercall (xch, &hypercall)) <0 ) {if ( errno ==EACCES )
@@ -257,8 +257,7 @@ static inline int do_sysctl(xc_interface " rebuild the user-space tool set?\n"); } -hcall_buf_release (xch, (void **)&sysctl,sizeof (*sysctl)); - +xc_hypercall_bounce_post (xch, sysctl); out1:return ret; }
tools/libxc/xc_tbuf.c +9 -9
@@ -116,9 +116,15 @@ int xc_tbuf_set_cpu_mask(xc_interface *xint xc_tbuf_set_cpu_mask (xc_interface *xch,uint32_t mask) {DECLARE_SYSCTL ; +DECLARE_HYPERCALL_BUFFER (uint8_t, bytemap);int ret =-1 ;uint64_t mask64 = mask; -uint8_t bytemap[sizeof (mask64)]; + + bytemap =xc_hypercall_buffer_alloc (xch, bytemap,sizeof (mask64)); + { +PERROR ("Could not lock memory for Xen hypercall" ); + goto out; + } sysctl.cmd = XEN_SYSCTL_tbuf_op; sysctl.interface_version =XEN_SYSCTL_INTERFACE_VERSION ;
@@ -126,18 +132,12 @@ int xc_tbuf_set_cpu_mask(xc_interface *xbitmap_64_to_byte (bytemap, &mask64,sizeof (mask64) *8 ); -set_xen_guest_handle (sysctl.u.tbuf_op.cpu_mask.bitmap, bytemap); +xc_set_xen_guest_handle (sysctl.u.tbuf_op.cpu_mask.bitmap, bytemap); sysctl.u.tbuf_op.cpu_mask.nr_cpus =sizeof (bytemap) *8 ; - -if (lock_pages (xch, &bytemap,sizeof (bytemap)) !=0 ) - { -PERROR ("Could not lock memory for Xen hypercall" ); - goto out; - } ret =do_sysctl (xch, &sysctl); -unlock_pages (xch, &bytemap,sizeof (bytemap)); +xc_hypercall_buffer_free (xch, bytemap); out:return ret;
tools/libxc/xenctrl.h +3 -6
@@ -996,21 +996,18 @@ int xc_perfc_query_number(xc_interface *int xc_perfc_query_number (xc_interface *xch,int *nbr_desc,int *nbr_val); -/* IMPORTANT: The caller is responsible for mlock()'ing the @desc and @val -arrays. */ int xc_perfc_query (xc_interface *xch, -xc_perfc_desc_t *desc, -xc_perfc_val_t *val); +xc_hypercall_buffer_t *desc, +xc_hypercall_buffer_t *val);typedef xen_sysctl_lockprof_data_t xc_lockprof_data_t ;int xc_lockprof_reset (xc_interface *xch);int xc_lockprof_query_number (xc_interface *xch,uint32_t *n_elems); -/* IMPORTANT: The caller is responsible for mlock()'ing the @data array. */ int xc_lockprof_query (xc_interface *xch,uint32_t *n_elems,uint64_t *time, -xc_lockprof_data_t *data); +xc_hypercall_buffer_t *data);/** * Memory maps a range within one domain to a local address range. Mappings
tools/misc/xenlockprof.c +6 -22
@@ -18,22 +18,6 @@#include <string.h> #include <inttypes.h> -static int lock_pages (void *addr,size_t len) -{ -int e =0 ; -#ifndef __sun__ - e =mlock (addr, len); -#endif -return (e); -} - -static void unlock_pages (void *addr,size_t len) -{ -#ifndef __sun__ -munlock (addr, len); -#endif -} -int main (int argc,char *argv[]) {xc_interface *xc_handle;
@@ -41,7 +25,7 @@ int main(int argc, char *argv[])uint64_t time;double l, b, sl, sb;char name[60 ]; -xc_lockprof_data_t *data; +DECLARE_HYPERCALL_BUFFER (xc_lockprof_data_t, data);if ( (argc >2 ) || ((argc ==2 ) && (strcmp (argv[1 ],"-r" ) !=0 )) ) {
@@ -78,8 +62,8 @@ int main(int argc, char *argv[]) } n +=32 ;/* just to be sure */ - data =malloc (sizeof (*data) * n); -if ( (data ==NULL ) || (lock_pages (data,sizeof (*data) * n) !=0 ) ) + data =xc_hypercall_buffer_alloc (xc_handle, data,sizeof (*data) * n); +if ( data ==NULL ) {fprintf (stderr,"Could not alloc or lock buffers: %d (%s)\n" , errno,strerror (errno));
@@ -87,14 +71,12 @@ int main(int argc, char *argv[]) } i = n; -if (xc_lockprof_query (xc_handle, &i, &time, data) !=0 ) +if (xc_lockprof_query (xc_handle, &i, &time,HYPERCALL_BUFFER (data)) !=0 ) {fprintf (stderr,"Error getting profile records: %d (%s)\n" , errno,strerror (errno));return 1 ; } - -unlock_pages (data,sizeof (*data) * n);if ( i > n ) {
@@ -132,5 +114,7 @@ int main(int argc, char *argv[])printf ("total locked time: %20.9fs\n" , sl);printf ("total blocked time: %20.9fs\n" , sb); +xc_hypercall_buffer_free (xc_handle, data); +return 0 ; }
tools/misc/xenperf.c +8 -28
@@ -68,28 +68,12 @@ const char *hypercall_name_table[64] = };#undef X -static int lock_pages (void *addr,size_t len) -{ -int e =0 ; -#ifndef __sun__ - e =mlock (addr, len); -#endif -return (e); -} - -static void unlock_pages (void *addr,size_t len) -{ -#ifndef __sun__ -munlock (addr, len); -#endif -} -int main (int argc,char *argv[]) {int i, j;xc_interface *xc_handle; -xc_perfc_desc_t *pcd; -xc_perfc_val_t *pcv; +DECLARE_HYPERCALL_BUFFER (xc_perfc_desc_t, pcd); +DECLARE_HYPERCALL_BUFFER (xc_perfc_val_t, pcv);xc_perfc_val_t *val;int num_desc, num_val;unsigned int sum, reset =0 , full =0 , pretty =0 ;
@@ -154,28 +138,22 @@ int main(int argc, char *argv[])return 1 ; } - pcd =malloc (sizeof (*pcd) * num_desc); - pcv =malloc (sizeof (*pcv) * num_val); + pcd =xc_hypercall_buffer_alloc (xc_handle, pcd,sizeof (*pcd) * num_desc); + pcv =xc_hypercall_buffer_alloc (xc_handle, pcv,sizeof (*pcv) * num_val); -if ( pcd ==NULL - ||lock_pages (pcd,sizeof (*pcd) * num_desc) !=0 - || pcv ==NULL - ||lock_pages (pcv,sizeof (*pcv) * num_val) !=0 ) +if ( pcd ==NULL || pcv ==NULL ) {fprintf (stderr,"Could not alloc or lock buffers: %d (%s)\n" , errno,strerror (errno));exit (-1 ); } -if (xc_perfc_query (xc_handle, pcd, pcv) !=0 ) +if (xc_perfc_query (xc_handle,HYPERCALL_BUFFER (pcd),HYPERCALL_BUFFER (pcv)) !=0 ) {fprintf (stderr,"Error getting perf counter: %d (%s)\n" , errno,strerror (errno));return 1 ; } - -unlock_pages (pcd,sizeof (*pcd) * num_desc); -unlock_pages (pcv,sizeof (*pcv) * num_val); val = pcv;for ( i =0 ; i < num_desc; i++ )
@@ -221,5 +199,7 @@ int main(int argc, char *argv[]) val += pcd[i].nr_vals; } +xc_hypercall_buffer_free (xc_handle, pcd); +xc_hypercall_buffer_free (xc_handle, pcv);return 0 ; }
PATCH 1/1 libxc: convert watchdog interface over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID 44b73f8b623f9e9567d0188f1fa1a566f4e00b1b # Parent 92e9795d06413325c84f2220cf33c0dd831e8355
libxc: convert watchdog interface over to hypercall buffers
tools/libxc/xc_domain.c +10 -9
@@ -378,24 +378,25 @@ int xc_watchdog(xc_interface *xch, uint32_t timeout) {int ret =-1 ; -sched_watchdog_t arg;DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (sched_watchdog_t, arg); - hypercall.op = __HYPERVISOR_sched_op; - hypercall.arg[0 ] = (unsigned long )SCHEDOP_watchdog; - hypercall.arg[1 ] = (unsigned long )&arg; - arg.id = id; - arg.timeout = timeout; - -if (lock_pages (xch, &arg,sizeof (arg)) !=0 ) + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out1; } + hypercall.op = __HYPERVISOR_sched_op; + hypercall.arg[0 ] = (unsigned long )SCHEDOP_watchdog; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->id = id; + arg->timeout = timeout; + ret =do_xen_hypercall (xch, &hypercall); -unlock_pages (xch, &arg,sizeof (arg)); +xc_hypercall_buffer_free (xch, arg); out1:return ret;
PATCH 1/1 libxc: convert acm interfaces over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1283779691 -3600
# Node ID c42a409a5c56732462d9effa844ebc2f7d06ba60 # Parent 44b73f8b623f9e9567d0188f1fa1a566f4e00b1b
libxc: convert acm interfaces over to hypercall buffers
tools/libxc/xc_acm.c +21 -18
@@ -27,12 +27,19 @@ int xc_acm_op(xc_interface *xch, int cmd {int ret;DECLARE_HYPERCALL ; -struct xen_acmctl acmctl; + DECLARE_HYPERCALL_BUFFER(struct xen_acmctl, acmctl); + + acmctl =xc_hypercall_buffer_alloc (xch, acmctl,sizeof (*acmctl)); +if ( acmctl ==NULL ) + { +PERROR ("Could not lock memory for Xen hypercall" ); +return -EFAULT ; + }switch (cmd) {case ACMOP_setpolicy: {struct acm_setpolicy *setpolicy = (struct acm_setpolicy *)arg; -memcpy (&acmctl.u.setpolicy, +memcpy (&acmctl->u.setpolicy, setpolicy,sizeof (struct acm_setpolicy )); }
@@ -40,7 +47,7 @@ int xc_acm_op(xc_interface *xch, int cmdcase ACMOP_getpolicy: {struct acm_getpolicy *getpolicy = (struct acm_getpolicy *)arg; -memcpy (&acmctl.u.getpolicy, +memcpy (&acmctl->u.getpolicy, getpolicy,sizeof (struct acm_getpolicy )); }
@@ -48,7 +55,7 @@ int xc_acm_op(xc_interface *xch, int cmdcase ACMOP_dumpstats: {struct acm_dumpstats *dumpstats = (struct acm_dumpstats *)arg; -memcpy (&acmctl.u.dumpstats, +memcpy (&acmctl->u.dumpstats, dumpstats,sizeof (struct acm_dumpstats )); }
@@ -56,7 +63,7 @@ int xc_acm_op(xc_interface *xch, int cmdcase ACMOP_getssid: {struct acm_getssid *getssid = (struct acm_getssid *)arg; -memcpy (&acmctl.u.getssid, +memcpy (&acmctl->u.getssid, getssid,sizeof (struct acm_getssid )); }
@@ -64,7 +71,7 @@ int xc_acm_op(xc_interface *xch, int cmdcase ACMOP_getdecision: {struct acm_getdecision *getdecision = (struct acm_getdecision *)arg; -memcpy (&acmctl.u.getdecision, +memcpy (&acmctl->u.getdecision, getdecision,sizeof (struct acm_getdecision )); }
@@ -72,7 +79,7 @@ int xc_acm_op(xc_interface *xch, int cmdcase ACMOP_chgpolicy: {struct acm_change_policy *change_policy = (struct acm_change_policy *)arg; -memcpy (&acmctl.u.change_policy, +memcpy (&acmctl->u.change_policy, change_policy,sizeof (struct acm_change_policy )); }
@@ -80,40 +87,36 @@ int xc_acm_op(xc_interface *xch, int cmdcase ACMOP_relabeldoms: {struct acm_relabel_doms *relabel_doms = (struct acm_relabel_doms *)arg; -memcpy (&acmctl.u.relabel_doms, +memcpy (&acmctl->u.relabel_doms, relabel_doms,sizeof (struct acm_relabel_doms )); }break ; } - acmctl.cmd = cmd; - acmctl.interface_version =ACM_INTERFACE_VERSION ; + acmctl->cmd = cmd; + acmctl->interface_version =ACM_INTERFACE_VERSION ; hypercall.op = __HYPERVISOR_xsm_op; - hypercall.arg[0 ] = (unsigned long )&acmctl; -if (lock_pages (xch, &acmctl,sizeof (acmctl)) !=0 ) - { -PERROR ("Could not lock memory for Xen hypercall" ); -return -EFAULT ; - } + hypercall.arg[0 ] =HYPERCALL_BUFFER_AS_ARG (acmctl);if ( (ret =do_xen_hypercall (xch, &hypercall)) <0 ) {if ( errno ==EACCES )DPRINTF ("acmctl operation failed -- need to" " rebuild the user-space tool set?\n" ); } -unlock_pages (xch, &acmctl,sizeof (acmctl));switch (cmd) {case ACMOP_getdecision: {struct acm_getdecision *getdecision = (struct acm_getdecision *)arg;memcpy (getdecision, - &acmctl.u.getdecision, + &acmctl->u.getdecision,sizeof (struct acm_getdecision ));break ; } } + +xc_hypercall_buffer_free (xch, acmctl);return ret; }
PATCH 1/1 libxc: convert evtchn interfaces over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID 0a24ab4ac4a43f4b36feea9e7c5ddd72b5f23872 # Parent c42a409a5c56732462d9effa844ebc2f7d06ba60
libxc: convert evtchn interfaces over to hypercall buffers
tools/libxc/xc_evtchn.c +7 -8
@@ -22,31 +22,30 @@#include "xc_private.h" -static int do_evtchn_op (xc_interface *xch,int cmd,void *arg,size_t arg_size,int silently_fail) {int ret =-1 ;DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BOUNCE (arg, arg_size,XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); - hypercall.op = __HYPERVISOR_event_channel_op; - hypercall.arg[0 ] = cmd; - hypercall.arg[1 ] = (unsigned long )arg; - -if (lock_pages (xch, arg, arg_size) !=0 ) +if (xc_hypercall_bounce_pre (xch, arg) ) {PERROR ("do_evtchn_op: arg lock failed" ); goto out; } + hypercall.op = __HYPERVISOR_event_channel_op; + hypercall.arg[0 ] = cmd; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); +if ((ret =do_xen_hypercall (xch, &hypercall)) <0 && !silently_fail)ERROR ("do_evtchn_op: HYPERVISOR_event_channel_op failed: %d" , ret); -unlock_pages (xch, arg, arg_size); +xc_hypercall_bounce_post (xch, arg); out:return ret; } - evtchn_port_or_error_t xc_evtchn_alloc_unbound(xc_interface *xch,
PATCH 1/1 libxc: convert schedop interfaces over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID d781e6711016a2f15b276499b2ebbd69b16d5dfe # Parent 0a24ab4ac4a43f4b36feea9e7c5ddd72b5f23872
libxc: convert schedop interfaces over to hypercall buffers
tools/libxc/xc_domain.c +10 -9
@@ -85,24 +85,25 @@ int xc_domain_shutdown(xc_interface *xch int reason) {int ret =-1 ; -sched_remote_shutdown_t arg;DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (sched_remote_shutdown_t, arg); - hypercall.op = __HYPERVISOR_sched_op; - hypercall.arg[0 ] = (unsigned long )SCHEDOP_remote_shutdown; - hypercall.arg[1 ] = (unsigned long )&arg; - arg.domain_id = domid; - arg.reason = reason; - -if (lock_pages (xch, &arg,sizeof (arg)) !=0 ) + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out1; } + hypercall.op = __HYPERVISOR_sched_op; + hypercall.arg[0 ] = (unsigned long )SCHEDOP_remote_shutdown; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + arg->domain_id = domid; + arg->reason = reason; + ret =do_xen_hypercall (xch, &hypercall); -unlock_pages (xch, &arg,sizeof (arg)); +xc_hypercall_buffer_free (xch, arg); out1:return ret;
PATCH 1/1 libxc: convert physdevop interface over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID 30ca51399b65a029af07904ba9b0529ac99c0754 # Parent d781e6711016a2f15b276499b2ebbd69b16d5dfe
libxc: convert physdevop interface over to hypercall buffers
tools/libxc/xc_private.h +5 -6
@@ -179,10 +179,10 @@ static inline int do_physdev_op(xc_interstatic inline int do_physdev_op (xc_interface *xch,int cmd,void *op,size_t len) {int ret =-1 ; +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BOUNCE (op, len,XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); -DECLARE_HYPERCALL ; - -if (hcall_buf_prep (xch, &op, len) !=0 ) +if (xc_hypercall_bounce_pre (xch, op) ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out1;
@@ -190,7 +190,7 @@ static inline int do_physdev_op(xc_inter hypercall.op = __HYPERVISOR_physdev_op; hypercall.arg[0 ] = (unsigned long ) cmd; - hypercall.arg[1 ] = (unsigned long ) op; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (op);if ( (ret =do_xen_hypercall (xch, &hypercall)) <0 ) {
@@ -199,8 +199,7 @@ static inline int do_physdev_op(xc_inter " rebuild the user-space tool set?\n"); } -hcall_buf_release (xch, &op, len); - +xc_hypercall_bounce_post (xch, op); out1:return ret; }
PATCH 1/1 libxc: convert flask interfaces over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID 68dfe4921429a857123a5f926f30b54abf3f5f80 # Parent 30ca51399b65a029af07904ba9b0529ac99c0754
libxc: convert flask interfaces over to hypercall buffers
tools/libxc/xc_flask.c +6 -5
@@ -40,15 +40,16 @@ int xc_flask_op(xc_interface *xch, flask {int ret =-1 ;DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BOUNCE (op,sizeof (*op),XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); - hypercall.op = __HYPERVISOR_xsm_op; - hypercall.arg[0 ] = (unsigned long )op; - -if (lock_pages (xch, op,sizeof (*op)) !=0 ) +if (xc_hypercall_bounce_pre (xch, op) ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out; } + + hypercall.op = __HYPERVISOR_xsm_op; + hypercall.arg[0 ] =HYPERCALL_BUFFER_AS_ARG (op);if ( (ret =do_xen_hypercall (xch, &hypercall)) <0 ) {
@@ -56,7 +57,7 @@ int xc_flask_op(xc_interface *xch, flaskfprintf (stderr,"XSM operation failed!\n" ); } -unlock_pages (xch, op,sizeof (*op)); +xc_hypercall_bounce_post (xch, op); out:return ret;
PATCH 1/1 libxc: convert hvmop interfaces over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID 413c6e963a87945e05a8fc1eb761c1e976445d9c # Parent 68dfe4921429a857123a5f926f30b54abf3f5f80
libxc: convert hvmop interfaces over to hypercall buffers
tools/libxc/xc_domain.c +20 -16
@@ -914,38 +914,42 @@ int xc_set_hvm_param(xc_interface *handlint 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; }
tools/libxc/xc_misc.c +71 -62
228 lines not on this page · raw message
PATCH 1/1 libxc: convert mca interface over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1283779691 -3600
# Node ID 649c4386d5904838f801d30e908b0f3bb1387d2c # Parent 413c6e963a87945e05a8fc1eb761c1e976445d9c
libxc: convert mca interface over to hypercall buffers
tools/libxc/xc_misc.c +6 -5
@@ -153,18 +153,19 @@ int xc_mca_op(xc_interface *xch, struct {int ret =0 ;DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BOUNCE (mc,sizeof (*mc),XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); - mc->interface_version =XEN_MCA_INTERFACE_VERSION ; -if (lock_pages (xch, mc,sizeof (*mc)) ) +if (xc_hypercall_bounce_pre (xch, mc) ) {PERROR ("Could not lock xen_mc memory" ); -return -EINVAL ; +return -1 ; } + mc->interface_version =XEN_MCA_INTERFACE_VERSION ; hypercall.op = __HYPERVISOR_mca; - hypercall.arg[0 ] = (unsigned long )mc; + hypercall.arg[0 ] =HYPERCALL_BUFFER_AS_ARG (mc); ret =do_xen_hypercall (xch, &hypercall); -unlock_pages (xch, mc,sizeof (*mc)); +xc_hypercall_bounce_post (xch, mc);return ret; }#endif
PATCH 1/1 libxc: convert tmem interface over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1283779691 -3600
# Node ID afdedd2e14c342a381094df14de9446636780283 # Parent 649c4386d5904838f801d30e908b0f3bb1387d2c
libxc: convert tmem interface over to hypercall buffers
tools/libxc/xc_tmem.c +24 -17
@@ -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 ); - hypercall.op = __HYPERVISOR_tmem_op; - hypercall.arg[0 ] = (unsigned long )op; -if (lock_pages (xch, op,sizeof (*op)) !=0 ) +if (xc_hypercall_bounce_pre (xch, op) ) {PERROR ("Could not lock memory for Xen hypercall" );return -EFAULT ; } + + hypercall.op = __HYPERVISOR_tmem_op; + 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,36 +56,41 @@ 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; op.u.ctrl.arg3 = arg3; - -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 ( arg1 !=0 ) + { +if ( buf ==NULL ) +return -EINVAL ; +if (xc_hypercall_bounce_pre (xch, buf) ) + { +PERROR ("Could not lock memory for Xen hypercall" ); +return -ENOMEM ; + } + +xc_set_xen_guest_handle (op.u.ctrl.buf, buf); + } +else +xc_set_xen_guest_handle (op.u.ctrl.buf,HYPERCALL_BUFFER_NULL ); + rc =do_tmem_op (xch, &op); -if (subop ==TMEMC_LIST ) { -if (arg1 !=0 ) -unlock_pages (xch, buf, arg1); - } +if (arg1 !=0 ) +xc_hypercall_bounce_post (xch, buf);return rc; }
PATCH 1/1 libxc: convert gnttab interfaces over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1283779691 -3600
# Node ID b0a0fd294854b3a0bf778125c85e56702ffecbc2 # Parent afdedd2e14c342a381094df14de9446636780283
libxc: convert gnttab interfaces over to hypercall buffers
tools/libxc/xc_linux.c +13 -18
@@ -612,21 +612,22 @@ int xc_gnttab_op(xc_interface *xch, int {int ret =0 ;DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BOUNCE (op, count * op_size,XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); - hypercall.op = __HYPERVISOR_grant_table_op; - hypercall.arg[0 ] = cmd; - hypercall.arg[1 ] = (unsigned long )op; - hypercall.arg[2 ] = count; - -if (lock_pages (xch, op, count* op_size) !=0 ) +if (xc_hypercall_bounce_pre (xch, op) ) {PERROR ("Could not lock memory for Xen hypercall" ); goto out1; } + hypercall.op = __HYPERVISOR_grant_table_op; + hypercall.arg[0 ] = cmd; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (op); + hypercall.arg[2 ] = count; + ret =do_xen_hypercall (xch, &hypercall); -unlock_pages (xch, op, count * op_size); +xc_hypercall_bounce_post (xch, op); out1:return ret;
@@ -651,7 +652,7 @@ static void *_gnttab_map_table(xc_interfint rc, i;struct gnttab_query_size query;struct gnttab_setup_table setup; -unsigned long *frame_list =NULL ; + DECLARE_HYPERCALL_BUFFER(unsigned long, frame_list);xen_pfn_t *pfn_list =NULL ;grant_entry_v1_t *gnt =NULL ;
@@ -669,13 +670,10 @@ static void *_gnttab_map_table(xc_interf *gnt_num = query.nr_frames * (PAGE_SIZE /sizeof (grant_entry_v1_t) ); - frame_list =malloc (query.nr_frames *sizeof (unsigned long )); -if ( !frame_list ||lock_pages (xch, frame_list, - query.nr_frames *sizeof (unsigned long )) ) + frame_list =xc_hypercall_buffer_alloc (xch, frame_list, query.nr_frames *sizeof (unsigned long )); +if ( !frame_list ) {ERROR ("Alloc/lock frame_list in xc_gnttab_map_table\n" ); -if ( frame_list ) -free (frame_list);return NULL ; }
@@ -688,7 +686,7 @@ static void *_gnttab_map_table(xc_interf setup.dom = domid; setup.nr_frames = query.nr_frames; -set_xen_guest_handle (setup.frame_list, frame_list); +xc_set_xen_guest_handle (setup.frame_list, frame_list);/* XXX Any race with other setup_table hypercall? */ rc = xc_gnttab_op(xch, GNTTABOP_setup_table, &setup, sizeof(setup),
@@ -713,10 +711,7 @@ static void *_gnttab_map_table(xc_interf err:if ( frame_list ) - { -unlock_pages (xch, frame_list, query.nr_frames *sizeof (unsigned long )); -free (frame_list); - } +xc_hypercall_buffer_free (xch, frame_list);if ( pfn_list )free (pfn_list);
Quoted 5 lines · Ian Campbell
The RFC has already grown to many more patches than I originally intended so I'd like to solicit some comments on the basic premise, usability of the interface etc, before I dig down and convert/cleanup the rest.
To that end patch 10 of 24 and one or two of the subsequent patches selected at random are the ones worth looking at...
Ian.
Re: [PATCH 10 of 24] libxc: infrastructure for hypercall safe data buffers
In reply to Ian CampbellQuoted 81 lines · Ian Campbell
# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1283779691 -3600
# Node IDbf7fb64762eb7decea9a6804460f0f966496ba07# Parent7b45202f78cd82d320fb32fea67c0a618697baec
libxc: infrastructure for hypercall safe data buffers.Signed-off-by Ian Campbell <[email protected]>diff -r
7b45202f78cd-rbf7fb64762ebtools/libxc/Makefiletools/libxc/Makefile +1
-0@@ -27,6 +27,7 @@ CTRL_SRCS-y += xc_mem_event.c CTRL_SRCS-y += xc_mem_event.c CTRL_SRCS-y += xc_mem_paging.c CTRL_SRCS-y += xc_memshr.c +CTRL_SRCS-y += xc_hcall_buf.c CTRL_SRCS-y += xtl_core.c CTRL_SRCS-y += xtl_logger_stdio.c CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.cdiff -r
7b45202f78cd-rbf7fb64762ebtools/libxc/xc_hcall_buf.ctools/libxc/xc_hcall_buf.c new file +57
-0@@ -0,0 +1,147 @@ +/* +* Copyright (c) 2010, Citrix Systems, Inc. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; +* version 2.1 of the License. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include <inttypes.h> +#include "xc_private.h" +#include "xg_private.h" + +DECLARE_NAMED_HYPERCALL_BUFFER (HYPERCALL_BUFFER_NULL ); + +void *xc__hypercall_buffer_alloc_pages (xc_interface *xch,xc_hypercall_buffer_t *b,int nr_pages) +{ +size_t size = nr_pages *PAGE_SIZE ; +void *p; +#if defined(_POSIX_C_SOURCE) && !defined(__sun__) +int ret; + ret =posix_memalign (&p,PAGE_SIZE , size); +if (ret !=0 ) +return NULL ; +#elif defined(__NetBSD__) || defined(__OpenBSD__) + p =valloc (size); +#else + p =memalign (PAGE_SIZE , size); +#endif + +if (!p) +return NULL ; + +#ifndef __sun__ +if (mlock (p, size) <0 ) + { +free (p); +return NULL ; + } +#endif + + b->hbuf = p; + +memset (p,0 , size); +return b->hbuf; +} + +void xc__hypercall_buffer_free_pages (xc_interface *xch,xc_hypercall_buffer_t *b,int nr_pages)
tools/libxc/xc_hcall_buf.c line 67
Quoted 10 lines
tools/libxc/xc_hcall_buf.c new file +10
-0+{ +if ( b->hbuf ==NULL ) +return ; + +#ifndef __sun__ + (void )munlock (b->hbuf, nr_pages *PAGE_SIZE ); +#endif + +free (b->hbuf); +}
How does this end up making the memory suitable for passing to Xen? Where does it get locked down in the non-__sun__ case? And why just __sun__ here?
Is there any way to make memory hypercall-safe with existing syscalls, or does/will it end up copying from this memory into the kernel before issuing the hypercall? Or adding some other mechanism for pinning down the pages?
J
Re: [PATCH 10 of 24] libxc: infrastructure for hypercall safe data buffers
Quoted 3 lines · Jeremy Fitzhardinge
How does this end up making the memory suitable for passing to Xen? Where does it get locked down in the non-__sun__ case? And why just
__sun__here?
As described in patch 0/24 the series still uses the same mlock mechanism as before to actually obtain "suitable" memory. The __sun__ stuff is the same as before too -- this part was ported direct from the existing bounce implementation in xc_private.c.
This series only:
* ensures that everywhere which should be using special hypercall memory is actually using the correct (or any!) interface to obtain it. Not everywhere was, sometimes by omission but more often because the current implementation will only bounce one buffer at a time and just locks any subsequent nested to bounce attempts in place. The currently implementation also only bounces buffers smaller than 1 page and just locks anything else in place.
* ensures that each buffer is only locked once -- some callchains were (un)locking the same buffer multiple times going down/up the stack (particularly concerning for buffers which are reused)
* removes the use of mlock on portions of the stack, which is considered more dubious than using mlock in general.
* makes it easier to switch to a better mechanism than mlock in the future (i.e. phase 2) by consolidating the magic allocations into one place.
Quoted 4 lines
Is there any way to make memory hypercall-safe with existing syscalls, or does/will it end up copying from this memory into the kernel before issuing the hypercall? Or adding some other mechanism for pinning down the pages?
It's not clear what phase 2 actually is (although phase 3 is clearly profit), I don't think any existing syscalls do what we need. mlock (avoiding the stack) gets pretty close and so far the issues with mlock seem to have been more potential than hurting us in practice, but it pays to be prepared e.g. for more aggressive page migration/coalescing in the future, I think.
It's not possible to copy the necessary buffers in the kernel without adding deep introspection of the necessary hypercalls to the kernel itself, I think we want to avoid this if possible.
Also some of the buffers can be quite large and/or potentially performance sensitive so we would like to retain the ability to allocate the correct sort of memory in userspace from the get go and therefor avoid bouncing at all.
I was thinking we might need to implement some sort of special anonymous mmap on the privcmd device or an ioctl or something along those lines, but I'm open to better suggestions.
Ian.
Ian Campbell writes ("[Xen-devel] [PATCH 00 of 24] [RFC] libxc: hypercall buffers"):
Quoted 6 lines
This RFC series only partially translates over to the the new scheme. It is intended that the final series end with a patch which effectively does s/xc_set_xen_guest_handle/set_xen_guest_handle/g in order to catch future errors (it should also remove the now redundant
hcall_buf_prepandhcall_buf_releasecalls and assiciated infrastructure).
This seems like a good idea. Some of the early parts of your series should probably go in right away, as they're just bugfixes, right ?
Ian.
Quoted 10 lines · Ian Jackson
Ian Campbell writes ("[Xen-devel] [PATCH 00 of 24] [RFC] libxc: hypercall buffers"):
Quoted 6 lines
This RFC series only partially translates over to the the new scheme. It is intended that the final series end with a patch which effectively does s/xc_set_xen_guest_handle/set_xen_guest_handle/g in order to catch future errors (it should also remove the now redundant
hcall_buf_prepandhcall_buf_releasecalls and assiciated infrastructure).This seems like a good idea. Some of the early parts of your series should probably go in right away, as they're just bugfixes, right ?
Yes, although I probably need to just double check they are sane and/or don't rely on later patches for correctness...
Re: [PATCH 10 of 24] libxc: infrastructure for hypercall safe data buffers
In reply to Ian CampbellIan Campbell writes ("Re: [Xen-devel] [PATCH 10 of 24] libxc: infrastructure for hypercall safe data buffers"):
Quoted 6 lines
It's not clear what phase 2 actually is (although phase 3 is clearly profit), I don't think any existing syscalls do what we need. mlock (avoiding the stack) gets pretty close and so far the issues with mlock seem to have been more potential than hurting us in practice, but it pays to be prepared e.g. for more aggressive page migration/coalescing in the future, I think.
Ian and I discussed this extensively on IRC, during which conversation I became convinced that mlock() must do what we want. Having read the code in the kernel I'm not not so sure.
The ordinary userspace access functions are all written to cope with pagefaults and retry the access. So userspace addresses are not in general valid in kernel mode even if you've called functions to try to test them. It's not clear what mlock prevents; does it prevent NUMA page migration ? If not then I think indeed the page could be made not present by one VCPU editing the page tables while another VCPU is entering the hypercall, so that the 2nd VCPU will get a spurious EFAULT.
OTOH: there must be other things that work like Xen - what about user mode device drivers of various kinds ? Do X servers not mlock memory and expect to be able to tell the video card to DMA to it ? etc. I think if linux-kernel think that people haven't assumed that mlock() actually pins the page, they're mistaken - and it's likely to be not just us.
Ian.
Ian Campbell writes ("Re: [Xen-devel] [PATCH 00 of 24] [RFC] libxc: hypercall buffers"):
Quoted 2 lines
Yes, although I probably need to just double check they are sane and/or don't rely on later patches for correctness...
OK, I'll hold off. I have plenty of other things to go in first anyway - rather a backlog, in fact ...
Ian.
Re: [PATCH 10 of 24] libxc: infrastructure for hypercall safe data buffers
In reply to Ian JacksonQuoted 11 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] [PATCH 10 of 24] libxc: infrastructure for hypercall safe data buffers"):
Quoted 6 lines
It's not clear what phase 2 actually is (although phase 3 is clearly profit), I don't think any existing syscalls do what we need. mlock (avoiding the stack) gets pretty close and so far the issues with mlock seem to have been more potential than hurting us in practice, but it pays to be prepared e.g. for more aggressive page migration/coalescing in the future, I think.
Ian and I discussed this extensively on IRC, during which conversation I became convinced that
mlock()must do what we want. Having read the code in the kernel I'm not not so sure.
After we had our discussion some other conversation I had (I forget where/with whom) which made me pretty sure we were wrong as well.
Quoted 4 lines
The ordinary userspace access functions are all written to cope with pagefaults and retry the access. So userspace addresses are not in general valid in kernel mode even if you've called functions to try to test them.
Correct, the difference between a normal userspace access function and a hypercall is that it is possible to inject (and handle) and page fault in the former case whereas we cannot inject a page fault to a VCPU while it is processing a hypercall.
(Maybe it is possible in principle to make all hypercalls restartable such that we can return to the guest in order to inject page faults but its not the case right now and I suspect it would be an enormous amount of work to make it so)
Quoted 5 lines
It's not clear what mlock prevents; does it prevent NUMA
page migration ? If not then I think indeed the page could be made not present by one VCPU editing the page tables while another VCPU is entering the hypercall, so that the 2nd VCPU will get a spurious EFAULT.
I think you are right, these kinds of page faults are possible.
It seems that mlock is only specified to prevent major page faults (i.e. those requiring I/O to service) but doesn't specify anything regarding minor page faults. It ensures that the data is resident in RAM but not necessarily that it is continuously mapped into your virtual address space nor writeable.
Minor page faults could be caused by NUMA migration (as you say), CoW mappings or by the kernel trying to consolidate free memory in order to satisfy a higher order allocation (Linux has recently gained this exact functionality, I believe). I'm sure there are a host of other potential causes too...
It's possible that historically most of these potential minor fault causes were either not implemented in the kernels we were using for domain 0 (e.g. consolidation is pretty new) or not likely to hit in practice (e.g. perhaps libxc's usage patterns make it likely that any CoW mappings are already dealt with by the time the hypercall happens).
Going forward I think it's likely that NUMA migration and memory consolidation and the like will become more widespread.
Quoted 3 lines
OTOH: there must be other things that work like Xen - what about user mode device drivers of various kinds ? Do X servers not mlock memory and expect to be able to tell the video card to DMA to it ? etc.
DMA would require physical (or more strictly DMA) addresses rather than virtual addresses so locking the page into a particular virtual address space doesn't matter all that much from a DMA point of view. I don't think pure user mode device drivers can do DMA, there is always some sort of kernel stub required.
In any case the kernel has been moving away from needing privileged X servers with direct access to hardware in favour of KMS for a while so I'm not sure an appeal to any similarity we may have with that case helps us much.
Quoted 3 lines
I think if linux-kernel think that people haven't assumed that
mlock()actually pins the page, they're mistaken - and it's likely to be not just us.
Unfortunately, I think we're reasonably unique.
Ian.
Re: [PATCH 10 of 24] libxc: infrastructure for hypercall safe data buffers
In reply to Ian JacksonQuoted 4 lines · Ian Jackson
Ian and I discussed this extensively on IRC, during which conversation I became convinced that
mlock()must do what we want. Having read the code in the kernel I'm not not so sure.
Quoted 8 lines
The ordinary userspace access functions are all written to cope with pagefaults and retry the access. So userspace addresses are not in general valid in kernel mode even if you've called functions to try to test them. It's not clear what mlock prevents; does it prevent NUMA page migration ? If not then I think indeed the page could be made not present by one VCPU editing the page tables while another VCPU is entering the hypercall, so that the 2nd VCPU will get a spurious EFAULT.
As IanC said, the only thing mlock() guarantees is that accessing the page won't cause a major fault - ie, need to go to disk to satisfy it. You can and will get minor faults on mlocked pages, as a result of the pte being either non-present or RO. It can be non-present as a result of page migration (not necessarily NUMA migration, just defragging kernel memory to make it possible to allocate higher-order pages), and RO when doing page-dirtiness tracking. And I think they can happen concurrently on different vcpus, so you may end up with a hypercall being able to start reading the memory, but then fail writing back the results.
I think the only way to do this properly is to do ioctls out of kernel memory rather than user process memory. Perhaps the easiest way to do this is add an mmap operation to privcmd which allocates a set of kernel pages and maps them into the process memory, which it can then use as its hypercall buffer. The alternatives would be to copy the argument memory into/out of kernel space around the call, or do some ad-hoc pinning of pages around the call. But if we can arrange for all argument memory to come from a particular buffer, then its easier to just make sure that buffer has the right properties.
Quoted 6 lines
OTOH: there must be other things that work like Xen - what about user mode device drivers of various kinds ? Do X servers not mlock memory and expect to be able to tell the video card to DMA to it ? etc. I think if linux-kernel think that people haven't assumed that
mlock()actually pins the page, they're mistaken - and it's likely to be not just us.
Not really - nothing much depends on keeping a page physically resident and having a pte in a specific state. DMA just cares about physical residency, and you can't do usermode DMA without some way of also getting the physical address of the page, which would mean you've already got some kind of kernel driver. And there would be no way to make such DMA safe anyway (mlock wouldn't protect against a process being killed, for example).
Trying to share memory via virtual addresses with an entity which is entirely external to the kernel is just plain weird.
J