libxc: Hypercall buffers
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 can 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.
The bits which touch ia64 are not even compile tested since I do not have access to a suitable userspace-capable cross compiler.
PATCH 1/1 libxc: infrastructure for hypercall safe data buffers
# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1287650254 -3600
# Node ID a40c36db2a03279fcb6a0525359d6a95de4e4800 # Parent 0b5d85ea10f8fff3f654c564c0e66900e83e8012
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 +160 -0
160 lines not on this page · raw message
tools/libxc/xc_private.h +58 -0
64 lines not on this page · raw message
tools/libxc/xenctrl.h +131 -0
137 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 1287650254 -3600
# Node ID f262590f9b94d9f6da603082748fe9f560becc7d # Parent a40c36db2a03279fcb6a0525359d6a95de4e4800
libxc: convert xc_version over to hypercall buffers
tools/libxc/xc_private.c +17 -13
@@ -569,42 +569,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" ); +PERROR ("Could not bounce buffer 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
@@ -166,13 +166,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 1287650254 -3600
# Node ID 6766a5b07735888ae5c5fdc16cbb4a915a997f05 # Parent f262590f9b94d9f6da603082748fe9f560becc7d
libxc: convert domctl interfaces over to hypercall buffers
(defer save/restore and shadow related interfaces til a later patch)
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 +67 -72
285 lines not on this page · raw message
tools/libxc/xc_private.c +17 -9
@@ -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(
@@ -498,25 +504,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" ); +PERROR ("xc_get_pfn_list: pfn_buf bounce 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 +7 -7
@@ -211,17 +211,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" ); +PERROR ("Could not bounce buffer for domctl 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 ) {
@@ -230,8 +231,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 1287650254 -3600
# Node ID 7a0260895b7f4c596f68cfef0fddd4959e116662
# Parent 6766a5b07735888ae5c5fdc16cbb4a915a997f05
libxc: convert shadow domctl interfaces and save/restore over to hypercall buffers
tools/libxc/ia64/xc_ia64_linux_save.c +9 -20
@@ -432,9 +432,9 @@ xc_domain_save(xc_interface *xch, int ioint last_iter =0 ;/* Bitmap of pages to be sent. */ -unsigned long *to_send =NULL ; + DECLARE_HYPERCALL_BUFFER(unsigned long, to_send);/* Bitmap of pages not to be sent (because dirtied). */ -unsigned long *to_skip =NULL ; + DECLARE_HYPERCALL_BUFFER(unsigned long, to_skip);char *mem;
@@ -542,8 +542,8 @@ xc_domain_save(xc_interface *xch, int io last_iter =0 ; bitmap_size = ((p2m_size +BITS_PER_LONG -1 ) & ~(BITS_PER_LONG -1 )) /8 ; - to_send =malloc (bitmap_size); - to_skip =malloc (bitmap_size); + to_send =xc_hypercall_buffer_alloc (xch, to_send, bitmap_size); + to_skip =xc_hypercall_buffer_alloc (xch, to_skip, bitmap_size);if (!to_send || !to_skip) {ERROR ("Couldn't allocate bitmap array" );
@@ -552,15 +552,6 @@ xc_domain_save(xc_interface *xch, int io/* Initially all the pages must be sent. */ memset (to_send,0xff , bitmap_size); - -if (lock_pages (to_send, bitmap_size)) { -ERROR ("Unable to lock_pages to_send" ); - goto out; - } -if (lock_pages (to_skip, bitmap_size)) { -ERROR ("Unable to lock_pages to_skip" ); - goto out; - }/* Enable qemu-dm logging dirty pages to xen */ if (hvm && !callbacks->switch_qemu_logdirty (dom,1 , callbacks->data)) {
@@ -621,7 +612,7 @@ xc_domain_save(xc_interface *xch, int ioif (!last_iter) {if (xc_shadow_control (xch, dom,XEN_DOMCTL_SHADOW_OP_PEEK , - to_skip, p2m_size, +HYPERCALL_BUFFER (to_skip), p2m_size,NULL ,0 ,NULL ) != p2m_size) {ERROR ("Error peeking shadow bitmap" ); goto out;
@@ -713,7 +704,7 @@ xc_domain_save(xc_interface *xch, int io/* Pages to be sent are pages which were dirty. */ if (xc_shadow_control (xch, dom,XEN_DOMCTL_SHADOW_OP_CLEAN , - to_send, p2m_size, +HYPERCALL_BUFFER (to_send), p2m_size,NULL ,0 ,NULL ) != p2m_size) {ERROR ("Error flushing shadow PT" ); goto out;
@@ -779,7 +770,7 @@ xc_domain_save(xc_interface *xch, int io//print_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), p2m_size,NULL ,0 ,NULL ) != p2m_size ) {ERROR ("Error flushing shadow PT" );
@@ -799,10 +790,8 @@ xc_domain_save(xc_interface *xch, int io } } -unlock_pages (to_send, bitmap_size); -free (to_send); -unlock_pages (to_skip, bitmap_size); -free (to_skip); +xc_hypercall_buffer_free (xch, to_send); +xc_hypercall_buffer_free (xch, to_skip);if (live_shinfo)munmap (live_shinfo,PAGE_SIZE );if (memmap_info)
tools/libxc/xc_domain.c +6 -3
@@ -400,7 +400,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,
@@ -408,14 +408,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;
@@ -909,7 +909,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;
@@ -1038,9 +1040,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 ) {
@@ -1050,20 +1052,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 );
@@ -1080,7 +1069,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 ));
@@ -1192,7 +1181,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 ) {
@@ -1532,8 +1521,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" );
@@ -1861,7 +1850,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" );
@@ -1892,12 +1881,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
@@ -598,7 +598,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 1287650254 -3600
# Node ID 71e4092089af29d01192810e4bd4a732c8ed3933 # Parent 7a0260895b7f4c596f68cfef0fddd4959e116662
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 xc_cpupool_getinfo" ); +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 xc_cpupool_freeinfo" ); +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 +15 -12
@@ -66,14 +66,15 @@ 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" ); +ERROR ("Could not bounce 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,14 +94,15 @@ 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" ); +ERROR ("Could not bounce 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,14 +122,15 @@ 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" ); +ERROR ("Could not bounce 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 +7 -8
@@ -240,18 +240,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" ); +PERROR ("Could not bounce buffer for sysctl 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 )
@@ -259,8 +259,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 allocate memory for xc_tbuf_set_cpu_mask 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
@@ -1022,21 +1022,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 +7 -23
@@ -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,23 +62,21 @@ 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" , +fprintf (stderr,"Could not allocate buffers: %d (%s)\n" , errno,strerror (errno));return 1 ; } 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 +9 -29
@@ -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" , +fprintf (stderr,"Could not allocate 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 1287650254 -3600
# Node ID ff41c37f36487d250e971e54c80cf29dc0d64eac # Parent 71e4092089af29d01192810e4bd4a732c8ed3933
libxc: convert watchdog interface over to hypercall buffers
tools/libxc/xc_domain.c +12 -11
@@ -374,24 +374,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); + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) + { +PERROR ("Could not allocate memory for xc_watchdog hypercall" ); + goto out1; + } 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 ) - { -PERROR ("Could not lock memory for Xen hypercall" ); - goto out1; - } + 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 1287650254 -3600
# Node ID c02e7347dc20e1c2b23a71910dcf623928dbf4ea # Parent ff41c37f36487d250e971e54c80cf29dc0d64eac
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 allocate memory for ACM OP 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 1287650254 -3600
# Node ID 1900730c5bfccbaddf517139c6c4eb390b75237f # Parent c02e7347dc20e1c2b23a71910dcf623928dbf4ea
libxc: convert evtchn interfaces over to hypercall buffers
tools/libxc/xc_evtchn.c +9 -10
@@ -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 ); + +if (xc_hypercall_bounce_pre (xch, arg) ) + { +PERROR ("do_evtchn_op: bouncing arg failed" ); + goto out; + } hypercall.op = __HYPERVISOR_event_channel_op; hypercall.arg[0 ] = cmd; - hypercall.arg[1 ] = (unsigned long )arg; - -if (lock_pages (xch, arg, arg_size) !=0 ) - { -PERROR ("do_evtchn_op: arg lock failed" ); - goto out; - } + 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 1287650254 -3600
# Node ID 584a8eddcea8410026af987a0dbd910852f8f1a9 # Parent 1900730c5bfccbaddf517139c6c4eb390b75237f
libxc: convert schedop interfaces over to hypercall buffers
tools/libxc/xc_domain.c +12 -11
@@ -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); + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) + { +PERROR ("Could not allocate memory for xc_domain_shutdown hypercall" ); + goto out1; + } 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 ) - { -PERROR ("Could not lock memory for Xen hypercall" ); - goto out1; - } + 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 1287650254 -3600
# Node ID a4430532beb9ddc8c48d80b45591fb25a139db8c # Parent 584a8eddcea8410026af987a0dbd910852f8f1a9
libxc: convert physdevop interface over to hypercall buffers
tools/libxc/xc_private.h +6 -7
@@ -181,18 +181,18 @@ 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" ); +PERROR ("Could not bounce memory for physdev hypercall" ); goto out1; } 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 ) {
@@ -201,8 +201,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 1287650255 -3600
# Node ID 9986007519dce12dd0503f88cc32f415a5f11c3d # Parent a4430532beb9ddc8c48d80b45591fb25a139db8c
libxc: convert flask interfaces over to hypercall buffers
tools/libxc/xc_flask.c +9 -8
@@ -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 ); + +if (xc_hypercall_bounce_pre (xch, op) ) + { +PERROR ("Could not bounce memory for flask op hypercall" ); + goto out; + } hypercall.op = __HYPERVISOR_xsm_op; - hypercall.arg[0 ] = (unsigned long )op; - -if (lock_pages (xch, op,sizeof (*op)) !=0 ) - { -PERROR ("Could not lock memory for Xen hypercall" ); - goto out; - } + 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 1287650255 -3600
# Node ID a688a8de1cf73954974b9dcc46304e9dcc981068 # Parent 9986007519dce12dd0503f88cc32f415a5f11c3d
libxc: convert hvmop interfaces over to hypercall buffers
tools/libxc/xc_domain.c +20 -16
@@ -1027,38 +1027,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 +73 -64
230 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 1287650255 -3600
# Node ID 2ef7e26cabd8919f5797a22dbd070a4a189063f1 # Parent a688a8de1cf73954974b9dcc46304e9dcc981068
libxc: convert mca interface over to hypercall buffers
tools/libxc/xc_misc.c +8 -7
@@ -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 ); +if (xc_hypercall_bounce_pre (xch, mc) ) + { +PERROR ("Could not bounce xen_mc memory buffer" ); +return -1 ; + } mc->interface_version =XEN_MCA_INTERFACE_VERSION ; -if (lock_pages (xch, mc,sizeof (*mc)) ) - { -PERROR ("Could not lock xen_mc memory" ); -return -EINVAL ; - } 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 1287650255 -3600
# Node ID f9ce4cbcfbc43e34a14493aff2c7605d17d33439 # Parent 2ef7e26cabd8919f5797a22dbd070a4a189063f1
libxc: convert tmem interface over to hypercall buffers
tools/libxc/xc_tmem.c +41 -32
@@ -25,21 +25,23 @@ static int do_tmem_op(xc_interface *xch, {int ret;DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BOUNCE (op,sizeof (*op),XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); + +if (xc_hypercall_bounce_pre (xch, op) ) + { +PERROR ("Could not bounce buffer for tmem op hypercall" ); +return -EFAULT ; + } hypercall.op = __HYPERVISOR_tmem_op; - hypercall.arg[0 ] = (unsigned long )op; -if (lock_pages (xch, op,sizeof (*op)) !=0 ) - { -PERROR ("Could not lock memory for Xen hypercall" ); -return -EFAULT ; - } + hypercall.arg[0 ] =HYPERCALL_BUFFER_AS_ARG (op);if ((ret =do_xen_hypercall (xch, &hypercall)) <0 ) {if ( errno ==EACCES )DPRINTF ("tmem operation failed -- need to" " rebuild the user-space tool set?\n" ); } -unlock_pages (xch, op,sizeof (*op)); +xc_hypercall_bounce_post (xch, op);return ret; }
@@ -54,13 +56,13 @@ int xc_tmem_control(xc_interface *xch, void *buf) {tmem_op_t op; +DECLARE_HYPERCALL_BOUNCE (buf, arg1,XC_HYPERCALL_BUFFER_BOUNCE_OUT );int rc; op.cmd =TMEM_CONTROL ; op.pool_id = pool_id; op.u.ctrl.subop = subop; op.u.ctrl.cli_id = cli_id; -set_xen_guest_handle (op.u.ctrl.buf,buf); op.u.ctrl.arg1 = arg1; op.u.ctrl.arg2 = arg2;/* use xc_tmem_control_oid if arg3 is required */
@@ -68,25 +70,28 @@ int xc_tmem_control(xc_interface *xch, op.u.ctrl.oid[1 ] =0 ; op.u.ctrl.oid[2 ] =0 ; -if (subop ==TMEMC_LIST ) { -if ((arg1 !=0 ) && (lock_pages (xch, buf, arg1) !=0 )) - { -PERROR ("Could not lock memory for Xen hypercall" ); -return -ENOMEM ; - } - } -#ifdef VALGRIND if (arg1 !=0 )memset (buf,0 , arg1);#endif +if ( subop ==TMEMC_LIST && arg1 !=0 ) + { +if ( buf ==NULL ) +return -EINVAL ; +if (xc_hypercall_bounce_pre (xch, buf) ) + { +PERROR ("Could not bounce buffer for tmem control hypercall" ); +return -ENOMEM ; + } + } + +xc_set_xen_guest_handle (op.u.ctrl.buf, buf); + rc =do_tmem_op (xch, &op); -if (subop ==TMEMC_LIST ) { -if (arg1 !=0 ) -unlock_pages (xch, buf, arg1); - } +if (subop ==TMEMC_LIST && arg1 !=0 ) +xc_hypercall_bounce_post (xch, buf);return rc; }
@@ -101,6 +106,7 @@ int xc_tmem_control_oid(xc_interface *xc void *buf) {tmem_op_t op; +DECLARE_HYPERCALL_BOUNCE (buf, arg1,XC_HYPERCALL_BUFFER_BOUNCE_OUT );int rc; op.cmd =TMEM_CONTROL ;
@@ -114,25 +120,28 @@ int xc_tmem_control_oid(xc_interface *xc op.u.ctrl.oid[1 ] = oid.oid[1 ]; op.u.ctrl.oid[2 ] = oid.oid[2 ]; -if (subop ==TMEMC_LIST ) { -if ((arg1 !=0 ) && (lock_pages (xch, buf, arg1) !=0 )) - { -PERROR ("Could not lock memory for Xen hypercall" ); -return -ENOMEM ; - } - } -#ifdef VALGRIND if (arg1 !=0 )memset (buf,0 , arg1);#endif +if ( subop ==TMEMC_LIST && arg1 !=0 ) + { +if ( buf ==NULL ) +return -EINVAL ; +if (xc_hypercall_bounce_pre (xch, buf) ) + { +PERROR ("Could not bounce buffer for tmem control (OID) hypercall" ); +return -ENOMEM ; + } + } + +xc_set_xen_guest_handle (op.u.ctrl.buf, buf); + rc =do_tmem_op (xch, &op); -if (subop ==TMEMC_LIST ) { -if (arg1 !=0 ) -unlock_pages (xch, buf, arg1); - } +if (subop ==TMEMC_LIST && arg1 !=0 ) +xc_hypercall_bounce_post (xch, buf);return rc; }
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 1287650255 -3600
# Node ID 9e1e5016ca8e1ff2314daac8457059dc0a5ef549 # Parent f9ce4cbcfbc43e34a14493aff2c7605d17d33439
libxc: convert gnttab interfaces over to hypercall buffers
tools/libxc/xc_linux.c +16 -21
@@ -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 ); + +if (xc_hypercall_bounce_pre (xch, op) ) + { +PERROR ("Could not bounce buffer for grant table op hypercall" ); + goto out1; + } hypercall.op = __HYPERVISOR_grant_table_op; hypercall.arg[0 ] = cmd; - hypercall.arg[1 ] = (unsigned long )op; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (op); hypercall.arg[2 ] = count; - -if (lock_pages (xch, op, count* op_size) !=0 ) - { -PERROR ("Could not lock memory for Xen hypercall" ); - goto out1; - } 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,26 +670,23 @@ 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); +ERROR ("Could not allocate frame_list in xc_gnttab_map_table\n" );return NULL ; } pfn_list =malloc (query.nr_frames *sizeof (xen_pfn_t));if ( !pfn_list ) { -ERROR ("Could not lock pfn_list in xc_gnttab_map_table\n" ); +ERROR ("Could not allocate pfn_list in xc_gnttab_map_table\n" ); goto err; } 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);
tools/libxc/xenctrl.h +1 -1
@@ -1290,7 +1290,7 @@ int xc_gnttab_set_max_grants(xc_interfacint xc_gnttab_op (xc_interface *xch,int cmd,void * op,int op_size,int count); -/* Logs iff lock_pages failes, otherwise doesn't. */ +/* Logs iff hypercall bounce fails, otherwise doesn't. */ int xc_gnttab_get_version (xc_interface *xch,int domid);/* Never logs */ grant_entry_v1_t *xc_gnttab_map_table_v1 (xc_interface *xch,int domid,int *gnt_num);
PATCH 1/1 libxc: convert memory op interface over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1287650255 -3600
# Node ID 38b752b683f3aec13669c1019e6637e3d3aeb434 # Parent 9e1e5016ca8e1ff2314daac8457059dc0a5ef549
libxc: convert memory op interface over to hypercall buffers
tools/libxc/xc_domain.c +46 -38
@@ -468,31 +468,30 @@ int xc_domain_set_memmap_limit(xc_interf unsigned long map_limitkb) {int rc; -struct xen_foreign_memory_map fmap = { .domid = domid, .map = { .nr_entries =1 } }; + DECLARE_HYPERCALL_BUFFER(struct e820entry, e820); -struct e820entry e820 = { - .addr =0 , - .size = (uint64_t )map_limitkb <<10 , - .type =E820_RAM - }; + e820 =xc_hypercall_buffer_alloc (xch, e820,sizeof (*e820)); -set_xen_guest_handle (fmap.map.buffer, &e820); +if ( e820 ==NULL ) + { +PERROR ("Could not allocate memory for xc_domain_set_memmap_limit hypercall" ); +return -1 ; + } -if (lock_pages (xch, &e820,sizeof (e820)) ) - { -PERROR ("Could not lock memory for Xen hypercall" ); - rc =-1 ; - goto out; - } + e820->addr =0 ; + e820->size = (uint64_t )map_limitkb <<10 ; + e820->type =E820_RAM ; + +xc_set_xen_guest_handle (fmap.map.buffer, e820); rc =do_memory_op (xch, XENMEM_set_memory_map, &fmap,sizeof (fmap)); - out: -unlock_pages (xch, &e820,sizeof (e820)); +xc_hypercall_buffer_free (xch, e820); +return rc; }#else
@@ -587,6 +586,7 @@ int xc_domain_increase_reservation(xc_in xen_pfn_t *extent_start) {int err; +DECLARE_HYPERCALL_BOUNCE (extent_start, nr_extents *sizeof (*extent_start),XC_HYPERCALL_BUFFER_BOUNCE_BOTH );struct xen_memory_reservation reservation = { .nr_extents = nr_extents, .extent_order = extent_order,
@@ -595,18 +595,17 @@ int xc_domain_increase_reservation(xc_in };/* may be NULL */ -if ( extent_start &&lock_pages (xch, extent_start, nr_extents *sizeof (xen_pfn_t)) !=0 ) +if (xc_hypercall_bounce_pre (xch, extent_start) ) { -PERROR ("Could not lock memory for XENMEM_increase_reservation hypercall" ); +PERROR ("Could not bounce memory for XENMEM_increase_reservation hypercall" );return -1 ; } -set_xen_guest_handle (reservation.extent_start, extent_start); +xc_set_xen_guest_handle (reservation.extent_start, extent_start); err =do_memory_op (xch, XENMEM_increase_reservation, &reservation,sizeof (reservation)); -if ( extent_start ) -unlock_pages (xch, extent_start, nr_extents *sizeof (xen_pfn_t)); +xc_hypercall_bounce_post (xch, extent_start);return err; }
@@ -645,18 +644,13 @@ int xc_domain_decrease_reservation(xc_in xen_pfn_t *extent_start) {int err; +DECLARE_HYPERCALL_BOUNCE (extent_start, nr_extents *sizeof (*extent_start),XC_HYPERCALL_BUFFER_BOUNCE_BOTH );struct xen_memory_reservation reservation = { .nr_extents = nr_extents, .extent_order = extent_order, .mem_flags =0 , .domid = domid }; - -if (lock_pages (xch, extent_start, nr_extents *sizeof (xen_pfn_t)) !=0 ) - { -PERROR ("Could not lock memory for XENMEM_decrease_reservation hypercall" ); -return -1 ; - }if ( extent_start ==NULL ) {
@@ -665,11 +659,16 @@ int xc_domain_decrease_reservation(xc_inreturn -1 ; } -set_xen_guest_handle (reservation.extent_start, extent_start); +if (xc_hypercall_bounce_pre (xch, extent_start) ) + { +PERROR ("Could not bounce memory for XENMEM_decrease_reservation hypercall" ); +return -1 ; + } +xc_set_xen_guest_handle (reservation.extent_start, extent_start); err =do_memory_op (xch, XENMEM_decrease_reservation, &reservation,sizeof (reservation)); -unlock_pages (xch, extent_start, nr_extents *sizeof (xen_pfn_t)); +xc_hypercall_bounce_post (xch, extent_start);return err; }
@@ -722,6 +721,7 @@ int xc_domain_populate_physmap(xc_interf xen_pfn_t *extent_start) {int err; +DECLARE_HYPERCALL_BOUNCE (extent_start, nr_extents *sizeof (*extent_start),XC_HYPERCALL_BUFFER_BOUNCE_BOTH );struct xen_memory_reservation reservation = { .nr_extents = nr_extents, .extent_order = extent_order,
@@ -729,18 +729,16 @@ int xc_domain_populate_physmap(xc_interf .domid = domid }; -if (lock_pages (xch, extent_start, nr_extents *sizeof (xen_pfn_t)) !=0 ) +if (xc_hypercall_bounce_pre (xch, extent_start) ) { -PERROR ("Could not lock memory for XENMEM_populate_physmap hypercall" ); +PERROR ("Could not bounce memory for XENMEM_populate_physmap hypercall" );return -1 ; } - -set_xen_guest_handle (reservation.extent_start, extent_start); +xc_set_xen_guest_handle (reservation.extent_start, extent_start); err =do_memory_op (xch, XENMEM_populate_physmap, &reservation,sizeof (reservation)); -unlock_pages (xch, extent_start, nr_extents *sizeof (xen_pfn_t)); - +xc_hypercall_bounce_post (xch, extent_start);return err; }
@@ -778,8 +776,9 @@ int xc_domain_memory_exchange_pages(xc_iunsigned int out_order, xen_pfn_t *out_extents) { - int rc; - + int rc = -1; +DECLARE_HYPERCALL_BOUNCE (in_extents, nr_in_extents*sizeof (*in_extents),XC_HYPERCALL_BUFFER_BOUNCE_IN ); +DECLARE_HYPERCALL_BOUNCE (out_extents, nr_out_extents*sizeof (*out_extents),XC_HYPERCALL_BUFFER_BOUNCE_OUT ); struct xen_memory_exchange exchange = { .in = { .nr_extents = nr_in_extents,
@@ -792,10 +791,19 @@ int xc_domain_memory_exchange_pages(xc_i .domid = domid } }; -set_xen_guest_handle (exchange.in.extent_start, in_extents); -set_xen_guest_handle (exchange.out.extent_start, out_extents); + +if (xc_hypercall_bounce_pre (xch, in_extents) || +xc_hypercall_bounce_pre (xch, out_extents)) + goto out; + +xc_set_xen_guest_handle (exchange.in.extent_start, in_extents); +xc_set_xen_guest_handle (exchange.out.extent_start, out_extents); rc =do_memory_op (xch, XENMEM_exchange, &exchange,sizeof (exchange)); + +out: +xc_hypercall_bounce_post (xch, in_extents); +xc_hypercall_bounce_post (xch, out_extents);return rc; }
tools/libxc/xc_private.c +13 -13
@@ -430,23 +430,22 @@ int do_memory_op(xc_interface *xch, intint do_memory_op (xc_interface *xch,int cmd,void *arg,size_t len) {DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BOUNCE (arg, len,XC_HYPERCALL_BUFFER_BOUNCE_BOTH );long ret = -EINVAL ; - hypercall.op = __HYPERVISOR_memory_op; - hypercall.arg[0 ] = (unsigned long )cmd; - hypercall.arg[1 ] = (unsigned long )arg; - -if ( len &&lock_pages (xch, arg, len) !=0 ) +if (xc_hypercall_bounce_pre (xch, arg) ) { -PERROR ("Could not lock memory for XENMEM hypercall" ); +PERROR ("Could not bounce memory for XENMEM hypercall" ); goto out1; } + hypercall.op = __HYPERVISOR_memory_op; + hypercall.arg[0 ] = (unsigned long ) cmd; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + ret =do_xen_hypercall (xch, &hypercall); -if ( len ) -unlock_pages (xch, arg, len); - +xc_hypercall_bounce_post (xch, arg); out1:return ret; }
@@ -476,24 +475,25 @@ int xc_machphys_mfn_list(xc_interface *x xen_pfn_t *extent_start) {int rc; +DECLARE_HYPERCALL_BOUNCE (extent_start, max_extents *sizeof (xen_pfn_t),XC_HYPERCALL_BUFFER_BOUNCE_OUT );struct xen_machphys_mfn_list xmml = { .max_extents = max_extents, }; -if (lock_pages (xch, extent_start, max_extents *sizeof (xen_pfn_t)) !=0 ) +if (xc_hypercall_bounce_pre (xch, extent_start) ) { -PERROR ("Could not lock memory for XENMEM_machphys_mfn_list hypercall" ); +PERROR ("Could not bounce memory for XENMEM_machphys_mfn_list hypercall" );return -1 ; } -set_xen_guest_handle (xmml.extent_start, extent_start); +xc_set_xen_guest_handle (xmml.extent_start, extent_start); rc =do_memory_op (xch, XENMEM_machphys_mfn_list, &xmml,sizeof (xmml));if (rc || xmml.nr_extents != max_extents) rc =-1 ;else rc =0 ; -unlock_pages (xch, extent_start, max_extents *sizeof (xen_pfn_t)); +xc_hypercall_bounce_post (xch, extent_start);return rc; }
PATCH 1/1 libxc: convert mmuext op interface over to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1287650255 -3600
# Node ID 0d9e118f705231b0ac88b9ae98f996e0e62152c7 # Parent 38b752b683f3aec13669c1019e6637e3d3aeb434
libxc: convert mmuext op interface over to hypercall buffers
tools/libxc/xc_private.c +15 -13
@@ -343,23 +343,24 @@ int xc_mmuext_op( domid_t dom) {DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BOUNCE (op, nr_ops*sizeof (*op),XC_HYPERCALL_BUFFER_BOUNCE_BOTH );long ret = -EINVAL ; -if (hcall_buf_prep (xch, (void **)&op, nr_ops*sizeof (*op)) !=0 ) +if (xc_hypercall_bounce_pre (xch, op) ) { -PERROR ("Could not lock memory for Xen hypercall" ); +PERROR ("Could not bounce memory for mmuext op hypercall" ); goto out1; } hypercall.op = __HYPERVISOR_mmuext_op; - hypercall.arg[0 ] = (unsigned long )op; + hypercall.arg[0 ] =HYPERCALL_BUFFER_AS_ARG (op); hypercall.arg[1 ] = (unsigned long )nr_ops; hypercall.arg[2 ] = (unsigned long )0 ; hypercall.arg[3 ] = (unsigned long )dom; ret =do_xen_hypercall (xch, &hypercall); -hcall_buf_release (xch, (void **)&op, nr_ops*sizeof (*op)); +xc_hypercall_bounce_post (xch, op); out1:return ret;
@@ -369,22 +370,23 @@ static int flush_mmu_updates(xc_interfac {int err =0 ;DECLARE_HYPERCALL ; +DECLARE_NAMED_HYPERCALL_BOUNCE (updates, mmu->updates, mmu->idx*sizeof (*mmu->updates),XC_HYPERCALL_BUFFER_BOUNCE_BOTH );if ( mmu->idx ==0 )return 0 ; +if (xc_hypercall_bounce_pre (xch, updates) ) + { +PERROR ("flush_mmu_updates: bounce buffer failed" ); + err =1 ; + goto out; + } + hypercall.op = __HYPERVISOR_mmu_update; - hypercall.arg[0 ] = (unsigned long )mmu->updates; + hypercall.arg[0 ] =HYPERCALL_BUFFER_AS_ARG (updates); hypercall.arg[1 ] = (unsigned long )mmu->idx; hypercall.arg[2 ] =0 ; hypercall.arg[3 ] = mmu->subject; - -if (lock_pages (xch, mmu->updates,sizeof (mmu->updates)) !=0 ) - { -PERROR ("flush_mmu_updates: mmu updates lock_pages failed" ); - err =1 ; - goto out; - }if (do_xen_hypercall (xch, &hypercall) <0 ) {
@@ -394,7 +396,7 @@ static int flush_mmu_updates(xc_interfac mmu->idx =0 ; -unlock_pages (xch, mmu->updates,sizeof (mmu->updates)); +xc_hypercall_bounce_post (xch, updates); out:return err;
PATCH 1/1 libxc: switch page offlining interfaces to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1287650255 -3600
# Node ID 19f7acc52f243f91f3ba539b0475dafbb0546ba0 # Parent 0d9e118f705231b0ac88b9ae98f996e0e62152c7
libxc: switch page offlining interfaces to hypercall buffers
There is no need to lock/bounce minfo->pfn_type in init_mem_info since xc_get_pfn_type_batch() will take care of that for us.
tools/libxc/xc_offline_page.c +1 -9
@@ -294,12 +294,6 @@ 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 (xch, minfo->pfn_type, minfo->p2m_size *sizeof (*minfo->pfn_type)) ) - { -ERROR ("Unable to lock pfn_type array" ); - goto failed; - } -for (i =0 ; i < minfo->p2m_size ; i+=1024 ) {int count = ((dinfo->p2m_size - i ) >1024 ) ?1024 : (dinfo->p2m_size - i);
@@ -307,13 +301,11 @@ static int init_mem_info(xc_interface *x minfo->pfn_type + i)) ) {ERROR ("Failed to get pfn_type %x\n" , rc); - goto unlock; + goto failed; } }return 0 ; -unlock: -unlock_pages (xch, minfo->pfn_type, minfo->p2m_size *sizeof (*minfo->pfn_type)); failed:if (minfo->pfn_type) {
PATCH 1/1 libxc: convert ia64 dom0vp interface to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1287650255 -3600
# Node ID 56cb1fbab19d9e8602244d56976877c13f52f91a # Parent 19f7acc52f243f91f3ba539b0475dafbb0546ba0
libxc: convert ia64 dom0vp interface to hypercall buffers
tools/libxc/ia64/xc_dom_ia64_util.c +9 -7
@@ -36,19 +36,21 @@ xen_ia64_fpswa_revision(struct xc_dom_im {int ret;DECLARE_HYPERCALL ; - hypercall.op = __HYPERVISOR_ia64_dom0vp_op; - hypercall.arg[0 ] = IA64_DOM0VP_fpswa_revision; - hypercall.arg[1 ] = (unsigned long )revision; +DECLARE_HYPERCALL_BOUNCE (revision,sizeof (*revision),XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); -if (lock_pages (revision,sizeof (*revision)) !=0 ) { -xc_interface *xch = dom->xch; +if (xc_hypercall_bounce_pre (dom->xch, revision) ) + {PERROR ("Could not lock memory for xen fpswa hypercall" );return -1 ; } + hypercall.op = __HYPERVISOR_ia64_dom0vp_op; + hypercall.arg[0 ] = IA64_DOM0VP_fpswa_revision; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (revision); + ret =do_xen_hypercall (dom->xch, &hypercall); - -unlock_pages (revision,sizeof (*revision)); + +xc_hypercall_bounce_post (dom->xch, revision);return ret; }
tools/libxc/ia64/xc_ia64_stubs.c +18 -14
@@ -42,19 +42,24 @@ xc_ia64_get_memmap(xc_interface *xch, uint32_t domid, char *buf, unsigned long bufsize) { privcmd_hypercall_t hypercall; +DECLARE_HYPERCALL_BOUNCE (buf, bufsize,XC_HYPERCALL_BUFFER_BOUNCE_OUT );int ret; + +if (xc_hypercall_bounce_pre (xch, pfn_buf) ) + { +PERROR ("xc_get_pfn_list: pfn_buf bounce failed" ); +return -1 ; + } hypercall.op = __HYPERVISOR_ia64_dom0vp_op; hypercall.arg[0 ] = IA64_DOM0VP_get_memmap; hypercall.arg[1 ] = domid; - hypercall.arg[2 ] = (unsigned long )buf; + hypercall.arg[2 ] =HYPERCALL_BUFFER_AS_ARG (buf); hypercall.arg[3 ] = bufsize; hypercall.arg[4 ] =0 ; -if (lock_pages (buf, bufsize) !=0 ) -return -1 ; ret =do_xen_hypercall (xch, &hypercall); -unlock_pages (buf, bufsize); +xc_hypercall_bounce_post (xc, buf);return ret; }
@@ -142,6 +147,7 @@ xc_ia64_map_foreign_p2m(xc_interface *xcstruct xen_ia64_memmap_info *memmap_info, unsigned long flags, unsigned long *p2m_size_p) { + DECLARE_HYPERCALL_BOUNCE(memmap_info, sizeof(*memmap_info) + memmap_info->efi_memmap_size, XC_HYPERCALL_BOUNCE_BUFFER_IN);unsigned long gpfn_max;unsigned long p2m_size;void *addr;
@@ -157,25 +163,23 @@ xc_ia64_map_foreign_p2m(xc_interface *xc addr =mmap (NULL , p2m_size,PROT_READ ,MAP_SHARED , xch->fd,0 );if (addr ==MAP_FAILED )return NULL ; +if (xc_hypercall_bounce_pre (xc, memmap_info)) { + saved_errno = errno; +munmap (addr, p2m_size); + errno = saved_errno; +return NULL ; + } hypercall.op = __HYPERVISOR_ia64_dom0vp_op; hypercall.arg[0 ] = IA64_DOM0VP_expose_foreign_p2m; hypercall.arg[1 ] = (unsigned long )addr; hypercall.arg[2 ] = dom; - hypercall.arg[3 ] = (unsigned long )memmap_info; + hypercall.arg[3 ] =HYPERCALL_BUFFER_AS_ARG (memmap_info); hypercall.arg[4 ] = flags; -if (lock_pages (memmap_info, -sizeof (*memmap_info) + memmap_info->efi_memmap_size) !=0 ) { - saved_errno = errno; -munmap (addr, p2m_size); - errno = saved_errno; -return NULL ; - } ret =do_xen_hypercall (xch, &hypercall); saved_errno = errno; -unlock_pages (memmap_info, -sizeof (*memmap_info) + memmap_info->efi_memmap_size); +xc_hypercall_bounce_post (xch, memmap_info);if (ret <0 ) {munmap (addr, p2m_size); errno = saved_errno;
PATCH 1/1 python acm: use hypercall buffer interface
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1287650255 -3600
# Node ID 98b20dffcac0b3b26907af7eafe8a807a78284b6 # Parent 56cb1fbab19d9e8602244d56976877c13f52f91a python acm: use hypercall buffer interface.
I have a suspicion these routines should be using libxc rather than reimplementing all the hypercalls again, but I don't have the enthusiasm to fix it.
tools/python/xen/lowlevel/acm/acm.c +105 -70
@@ -40,22 +40,20 @@ static PyObject *acm_error_obj;static PyObject *acm_error_obj;/* generic shared function */ -static void *__getssid (int domid,uint32_t *buflen) +static void *__getssid (xc_interface *xc_handle,int domid,uint32_t *buflen,xc_hypercall_buffer_t *buffer) {struct acm_getssid getssid; -xc_interface *xc_handle;#define SSID_BUFFER_SIZE 4096 -void *buf =NULL ; +void *buf; +DECLARE_HYPERCALL_BUFFER_ARGUMENT (buffer); -if ((xc_handle =xc_interface_open (0 ,0 ,0 )) ==0 ) { - goto out1; +if ((buf =xc_hypercall_buffer_alloc (xc_handle, buffer,SSID_BUFFER_SIZE )) ==NULL ) { +PERROR ("acm.policytype: Could not allocate ssid buffer!\n" ); +return NULL ; } -if ((buf =malloc (SSID_BUFFER_SIZE )) ==NULL ) { -PERROR ("acm.policytype: Could not allocate ssid buffer!\n" ); - goto out2; - } +memset (buf,0 ,SSID_BUFFER_SIZE ); -set_xen_guest_handle (getssid.ssidbuf, buf); +xc_set_xen_guest_handle (getssid.ssidbuf, buffer); getssid.ssidbuf_size =SSID_BUFFER_SIZE ; getssid.get_ssid_by = ACM_GETBY_domainid; getssid.id.domainid = domid;
@@ -63,16 +61,10 @@ static void *__getssid(int domid, uint32if (xc_acm_op (xc_handle, ACMOP_getssid, &getssid,sizeof (getssid)) <0 ) {if (errno ==EACCES )PERROR ("ACM operation failed." ); -free (buf); buf =NULL ; - goto out2; }else { *buflen =SSID_BUFFER_SIZE ; - goto out2; } - out2: -xc_interface_close (xc_handle); - out1:return buf; }
@@ -81,52 +73,60 @@ static void *__getssid(int domid, uint32* ssidref for domain 0 (always exists) */ static PyObject *policy (PyObject * self,PyObject * args) { -/* out */ +xc_interface *xc_handle;char *policyreference;PyObject *ret; -void *ssid_buffer;uint32_t buf_len; +DECLARE_HYPERCALL_BUFFER (void, ssid_buffer);if (!PyArg_ParseTuple (args,"" ,NULL )) {return NULL ; } - ssid_buffer =__getssid (0 , &buf_len); -if (ssid_buffer ==NULL || buf_len <sizeof (struct acm_ssid_buffer )) { -free (ssid_buffer); +if ((xc_handle =xc_interface_open (0 ,0 ,0 )) ==0 )return PyErr_SetFromErrno (acm_error_obj); - } + + ssid_buffer =__getssid (xc_handle,0 , &buf_len,HYPERCALL_BUFFER (ssid_buffer)); +if (ssid_buffer ==NULL || buf_len <sizeof (struct acm_ssid_buffer )) + ret =PyErr_SetFromErrno (acm_error_obj);else {struct acm_ssid_buffer *ssid = (struct acm_ssid_buffer *)ssid_buffer; policyreference = (char *)(ssid_buffer + ssid->policy_reference_offset +sizeof (struct acm_policy_reference_buffer )); ret =Py_BuildValue ("s" , policyreference); -free (ssid_buffer); -return ret; } + +xc_hypercall_buffer_free (xc_handle, ssid_buffer); +xc_interface_close (xc_handle); +return ret; }/* retrieve ssid info for a domain domid*/ static PyObject *getssid (PyObject * self,PyObject * args) { +xc_interface *xc_handle; +/* in */ uint32_t domid;/* out */ char *policytype, *policyreference;uint32_t ssidref; +PyObject *ret; -void *ssid_buffer; +DECLARE_HYPERCALL_BUFFER (void, ssid_buffer);uint32_t buf_len;if (!PyArg_ParseTuple (args,"i" , &domid)) {return NULL ; } - ssid_buffer =__getssid (domid, &buf_len); +if ((xc_handle =xc_interface_open (0 ,0 ,0 )) ==0 ) +return PyErr_SetFromErrno (acm_error_obj); + + ssid_buffer =__getssid (xc_handle, domid, &buf_len,HYPERCALL_BUFFER (ssid_buffer));if (ssid_buffer ==NULL ) { -return NULL ; + ret =NULL ; }else if (buf_len <sizeof (struct acm_ssid_buffer )) { -free (ssid_buffer); -return NULL ; + ret =NULL ; }else {struct acm_ssid_buffer *ssid = (struct acm_ssid_buffer *) ssid_buffer; policytype = ACM_POLICY_NAME(ssid->secondary_policy_code << 4 |
@@ -134,12 +134,14 @@ static PyObject *getssid(PyObject * self ssidref = ssid->ssidref; policyreference = (char *)(ssid_buffer + ssid->policy_reference_offset +sizeof (struct acm_policy_reference_buffer )); + ret =Py_BuildValue ("{s:s,s:s,s:i}" , +"policyreference" , policyreference, +"policytype" , policytype, +"ssidref" , ssidref); } -free (ssid_buffer); -return Py_BuildValue ("{s:s,s:s,s:i}" , -"policyreference" , policyreference, -"policytype" , policytype, -"ssidref" , ssidref); +xc_hypercall_buffer_free (xc_handle, ssid_buffer); +xc_interface_close (xc_handle); +return ret; }
@@ -206,7 +208,6 @@ const char ctrlif_op[] = "Could not openconst char ctrlif_op[] ="Could not open control interface." ;const char hv_op_err[] ="Error from hypervisor operation." ; -static PyObject *chgpolicy (PyObject *self,PyObject *args) {struct acm_change_policy chgpolicy;
@@ -215,9 +216,12 @@ static PyObject *chgpolicy(PyObject *selchar *bin_pol =NULL , *del_arr =NULL , *chg_arr =NULL ;int bin_pol_len =0 , del_arr_len =0 , chg_arr_len =0 ;uint errarray_mbrs =20 *2 ; -uint32_t error_array[errarray_mbrs]; -PyObject *result; +PyObject *result =NULL ;uint len; +DECLARE_HYPERCALL_BUFFER (char, bin_pol_buf); +DECLARE_HYPERCALL_BUFFER (char, del_arr_buf); +DECLARE_HYPERCALL_BUFFER (char, chg_arr_buf); +DECLARE_HYPERCALL_BUFFER (uint32_t, error_array);memset (&chgpolicy,0x0 ,sizeof (chgpolicy));
@@ -228,24 +232,34 @@ static PyObject *chgpolicy(PyObject *selreturn NULL ; } - chgpolicy.policy_pushcache_size = bin_pol_len; - chgpolicy.delarray_size = del_arr_len; - chgpolicy.chgarray_size = chg_arr_len; - chgpolicy.errarray_size =sizeof (error_array); - -set_xen_guest_handle (chgpolicy.policy_pushcache, bin_pol); -set_xen_guest_handle (chgpolicy.del_array, del_arr); -set_xen_guest_handle (chgpolicy.chg_array, chg_arr); -set_xen_guest_handle (chgpolicy.err_array, error_array); -if ((xc_handle =xc_interface_open (0 ,0 ,0 )) ==0 ) {PyErr_SetString (PyExc_IOError, ctrlif_op);return NULL ; } +if ( (bin_pol_buf =xc_hypercall_buffer_alloc (xc_handle, bin_pol_buf, bin_pol_len)) ==NULL ) + goto out; +if ( (del_arr_buf =xc_hypercall_buffer_alloc (xc_handle, del_arr_buf, del_arr_len)) ==NULL ) + goto out; +if ( (chg_arr_buf =xc_hypercall_buffer_alloc (xc_handle, chg_arr_buf, chg_arr_len)) ==NULL ) + goto out; +if ( (error_array =xc_hypercall_buffer_alloc (xc_handle, error_array,sizeof (*error_array)*errarray_mbrs)) ==NULL ) + goto out; + +memcpy (bin_pol_buf, bin_pol, bin_pol_len); +memcpy (del_arr_buf, del_arr, del_arr_len); +memcpy (chg_arr_buf, chg_arr, chg_arr_len); + + chgpolicy.policy_pushcache_size = bin_pol_len; + chgpolicy.delarray_size = del_arr_len; + chgpolicy.chgarray_size = chg_arr_len; + chgpolicy.errarray_size =sizeof (*error_array)*errarray_mbrs; +xc_set_xen_guest_handle (chgpolicy.policy_pushcache, bin_pol_buf); +xc_set_xen_guest_handle (chgpolicy.del_array, del_arr_buf); +xc_set_xen_guest_handle (chgpolicy.chg_array, chg_arr_buf); +xc_set_xen_guest_handle (chgpolicy.err_array, error_array); + rc =xc_acm_op (xc_handle, ACMOP_chgpolicy, &chgpolicy,sizeof (chgpolicy)); - -xc_interface_close (xc_handle);/* only pass the filled error codes */ for (len =0 ; (len +1 ) < errarray_mbrs; len +=2 ) {
@@ -256,6 +270,13 @@ static PyObject *chgpolicy(PyObject *sel } result =Py_BuildValue ("is#" , rc, error_array, len); + +out: +xc_hypercall_buffer_free (xc_handle, bin_pol_buf); +xc_hypercall_buffer_free (xc_handle, del_arr_buf); +xc_hypercall_buffer_free (xc_handle, chg_arr_buf); +xc_hypercall_buffer_free (xc_handle, error_array); +xc_interface_close (xc_handle);return result; }
@@ -265,33 +286,37 @@ static PyObject *getpolicy(PyObject *selstruct acm_getpolicy getpolicy;xc_interface *xc_handle;int rc; -uint8_t pull_buffer[8192 ]; -PyObject *result; -uint32_t len =sizeof (pull_buffer); - -memset (&getpolicy,0x0 ,sizeof (getpolicy)); -set_xen_guest_handle (getpolicy.pullcache, pull_buffer); - getpolicy.pullcache_size =sizeof (pull_buffer); +PyObject *result =NULL ; +uint32_t len =8192 ; +DECLARE_HYPERCALL_BUFFER (uint8_t, pull_buffer);if ((xc_handle =xc_interface_open (0 ,0 ,0 )) ==0 ) {PyErr_SetString (PyExc_IOError, ctrlif_op);return NULL ; } +if ((pull_buffer =xc_hypercall_buffer_alloc (xc_handle, pull_buffer, len)) ==NULL ) + goto out; + +memset (&getpolicy,0x0 ,sizeof (getpolicy)); +xc_set_xen_guest_handle (getpolicy.pullcache, pull_buffer); + getpolicy.pullcache_size =sizeof (pull_buffer); + rc =xc_acm_op (xc_handle, ACMOP_getpolicy, &getpolicy,sizeof (getpolicy)); - -xc_interface_close (xc_handle);if (rc ==0 ) {struct acm_policy_buffer *header = (struct acm_policy_buffer *)pull_buffer; -if (ntohl (header->len) <sizeof (pull_buffer)) +if (ntohl (header->len) <8192 ) len =ntohl (header->len); }else { len =0 ; } result =Py_BuildValue ("is#" , rc, pull_buffer, len); +out: +xc_hypercall_buffer_free (xc_handle, pull_buffer); +xc_interface_close (xc_handle);return result; }
@@ -304,8 +329,9 @@ static PyObject *relabel_domains(PyObjecchar *relabel_rules =NULL ;int rel_rules_len =0 ;uint errarray_mbrs =20 *2 ; -uint32_t error_array[errarray_mbrs]; -PyObject *result; +DECLARE_HYPERCALL_BUFFER (uint32_t, error_array); +DECLARE_HYPERCALL_BUFFER (char, relabel_rules_buf); +PyObject *result =NULL ;uint len;memset (&reldoms,0x0 ,sizeof (reldoms));
@@ -315,21 +341,25 @@ static PyObject *relabel_domains(PyObjecreturn NULL ; } - reldoms.relabel_map_size = rel_rules_len; - reldoms.errarray_size =sizeof (error_array); - -set_xen_guest_handle (reldoms.relabel_map, relabel_rules); -set_xen_guest_handle (reldoms.err_array, error_array); -if ((xc_handle =xc_interface_open (0 ,0 ,0 )) ==0 ) {PyErr_SetString (PyExc_IOError, ctrlif_op);return NULL ; } +if ((relabel_rules_buf =xc_hypercall_buffer_alloc (xc_handle, relabel_rules_buf, rel_rules_len)) ==NULL ) + goto out; +if ((error_array =xc_hypercall_buffer_alloc (xc_handle, error_array,sizeof (*error_array)*errarray_mbrs)) ==NULL ) + goto out; + +memcpy (relabel_rules_buf, relabel_rules, rel_rules_len); + + reldoms.relabel_map_size = rel_rules_len; + reldoms.errarray_size =sizeof (error_array); + +xc_set_xen_guest_handle (reldoms.relabel_map, relabel_rules_buf); +xc_set_xen_guest_handle (reldoms.err_array, error_array); + rc =xc_acm_op (xc_handle, ACMOP_relabeldoms, &reldoms,sizeof (reldoms)); - -xc_interface_close (xc_handle); -/* only pass the filled error codes */ for (len =0 ; (len +1 ) < errarray_mbrs; len +=2 ) {
@@ -340,6 +370,11 @@ static PyObject *relabel_domains(PyObjec } result =Py_BuildValue ("is#" , rc, error_array, len); +out: +xc_hypercall_buffer_free (xc_handle, relabel_rules_buf); +xc_hypercall_buffer_free (xc_handle, error_array); +xc_interface_close (xc_handle); +return result; }
PATCH 1/1 python xc: use hypercall buffer interface
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1287650255 -3600
# Node ID 9729034ef96a2247fa913470109299b6b1344e34 # Parent 98b20dffcac0b3b26907af7eafe8a807a78284b6 python xc: use hypercall buffer interface.
tools/python/xen/lowlevel/xc/xc.c +49 -21
@@ -1206,19 +1206,29 @@ static PyObject *pyxc_topologyinfo(XcObj#define MAX_CPU_INDEX 255xc_topologyinfo_t tinfo = {0 };int i, max_cpu_index; -PyObject *ret_obj; +PyObject *ret_obj =NULL ;PyObject *cpu_to_core_obj, *cpu_to_socket_obj, *cpu_to_node_obj; -xc_cpu_to_core_t coremap[MAX_CPU_INDEX +1 ]; -xc_cpu_to_socket_t socketmap[MAX_CPU_INDEX +1 ]; -xc_cpu_to_node_t nodemap[MAX_CPU_INDEX +1 ]; +DECLARE_HYPERCALL_BUFFER (xc_cpu_to_core_t, coremap); +DECLARE_HYPERCALL_BUFFER (xc_cpu_to_socket_t, socketmap); +DECLARE_HYPERCALL_BUFFER (xc_cpu_to_node_t, nodemap); -set_xen_guest_handle (tinfo.cpu_to_core, coremap); -set_xen_guest_handle (tinfo.cpu_to_socket, socketmap); -set_xen_guest_handle (tinfo.cpu_to_node, nodemap); + coremap =xc_hypercall_buffer_alloc (self->xc_handle, coremap,sizeof (*coremap) * (MAX_CPU_INDEX +1 )); +if ( coremap ==NULL ) + goto out; + socketmap =xc_hypercall_buffer_alloc (self->xc_handle, socketmap,sizeof (*socketmap) * (MAX_CPU_INDEX +1 )); +if ( socketmap ==NULL ) + goto out; + nodemap =xc_hypercall_buffer_alloc (self->xc_handle, nodemap,sizeof (*nodemap) * (MAX_CPU_INDEX +1 )); +if ( nodemap ==NULL ) + goto out; + +xc_set_xen_guest_handle (tinfo.cpu_to_core, coremap); +xc_set_xen_guest_handle (tinfo.cpu_to_socket, socketmap); +xc_set_xen_guest_handle (tinfo.cpu_to_node, nodemap); tinfo.max_cpu_index =MAX_CPU_INDEX ;if (xc_topologyinfo (self->xc_handle, &tinfo) !=0 ) -return pyxc_error_to_exception (self->xc_handle); + goto out; max_cpu_index = tinfo.max_cpu_index;if ( max_cpu_index >MAX_CPU_INDEX )
@@ -1271,11 +1281,15 @@ static PyObject *pyxc_topologyinfo(XcObjPyDict_SetItemString (ret_obj,"cpu_to_socket" , cpu_to_socket_obj);Py_DECREF (cpu_to_socket_obj); - +PyDict_SetItemString (ret_obj,"cpu_to_node" , cpu_to_node_obj);Py_DECREF (cpu_to_node_obj); - -return ret_obj; + +out: +xc_hypercall_buffer_free (self->xc_handle, coremap); +xc_hypercall_buffer_free (self->xc_handle, socketmap); +xc_hypercall_buffer_free (self->xc_handle, nodemap); +return ret_obj ? ret_obj :pyxc_error_to_exception (self->xc_handle);#undef MAX_CPU_INDEX }
@@ -1285,20 +1299,30 @@ static PyObject *pyxc_numainfo(XcObjectxc_numainfo_t ninfo = {0 };int i, j, max_node_index;uint64_t free_heap; -PyObject *ret_obj, *node_to_node_dist_list_obj; +PyObject *ret_obj =NULL , *node_to_node_dist_list_obj;PyObject *node_to_memsize_obj, *node_to_memfree_obj;PyObject *node_to_dma32_mem_obj, *node_to_node_dist_obj; -xc_node_to_memsize_t node_memsize[MAX_NODE_INDEX +1 ]; -xc_node_to_memfree_t node_memfree[MAX_NODE_INDEX +1 ]; -xc_node_to_node_dist_t nodes_dist[(MAX_NODE_INDEX +1 ) * (MAX_NODE_INDEX +1 )]; +DECLARE_HYPERCALL_BUFFER (xc_node_to_memsize_t, node_memsize); +DECLARE_HYPERCALL_BUFFER (xc_node_to_memfree_t, node_memfree); +DECLARE_HYPERCALL_BUFFER (xc_node_to_node_dist_t, nodes_dist); -set_xen_guest_handle (ninfo.node_to_memsize, node_memsize); -set_xen_guest_handle (ninfo.node_to_memfree, node_memfree); -set_xen_guest_handle (ninfo.node_to_node_distance, nodes_dist); + node_memsize =xc_hypercall_buffer_alloc (self->xc_handle, node_memsize,sizeof (*node_memsize)*(MAX_NODE_INDEX +1 )); +if ( node_memsize ==NULL ) + goto out; + node_memfree =xc_hypercall_buffer_alloc (self->xc_handle, node_memfree,sizeof (*node_memfree)*(MAX_NODE_INDEX +1 )); +if ( node_memfree ==NULL ) + goto out; + nodes_dist =xc_hypercall_buffer_alloc (self->xc_handle, nodes_dist,sizeof (*nodes_dist)*(MAX_NODE_INDEX +1 )*(MAX_NODE_INDEX +1 )); +if ( nodes_dist ==NULL ) + goto out; + +xc_set_xen_guest_handle (ninfo.node_to_memsize, node_memsize); +xc_set_xen_guest_handle (ninfo.node_to_memfree, node_memfree); +xc_set_xen_guest_handle (ninfo.node_to_node_distance, nodes_dist); ninfo.max_node_index =MAX_NODE_INDEX ;if (xc_numainfo (self->xc_handle, &ninfo) !=0 ) -return pyxc_error_to_exception (self->xc_handle); + goto out; max_node_index = ninfo.max_node_index;if ( max_node_index >MAX_NODE_INDEX )
@@ -1363,8 +1387,12 @@ static PyObject *pyxc_numainfo(XcObjectPyDict_SetItemString (ret_obj,"node_to_node_dist" , node_to_node_dist_list_obj);Py_DECREF (node_to_node_dist_list_obj); - -return ret_obj; + +out: +xc_hypercall_buffer_free (self->xc_handle, node_memsize); +xc_hypercall_buffer_free (self->xc_handle, node_memfree); +xc_hypercall_buffer_free (self->xc_handle, nodes_dist); +return ret_obj ? ret_obj :pyxc_error_to_exception (self->xc_handle);#undef MAX_NODE_INDEX }
PATCH 1/1 xenpm: use hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1287650255 -3600
# Node ID 26a8a8cd558e7a9ed92de6bc3605fef97571735f # Parent 9729034ef96a2247fa913470109299b6b1344e34
xenpm: use hypercall buffers.
tools/misc/xenpm.c +42 -14
@@ -317,15 +317,25 @@ static void signal_int_handler(int signoint i, j, k, ret;struct timeval tv;int cx_cap =0 , px_cap =0 ; -uint32_t cpu_to_core[MAX_NR_CPU ]; -uint32_t cpu_to_socket[MAX_NR_CPU ]; -uint32_t cpu_to_node[MAX_NR_CPU ]; +DECLARE_HYPERCALL_BUFFER (uint32_t, cpu_to_core); +DECLARE_HYPERCALL_BUFFER (uint32_t, cpu_to_socket); +DECLARE_HYPERCALL_BUFFER (uint32_t, cpu_to_node);xc_topologyinfo_t info = {0 }; + + cpu_to_core =xc_hypercall_buffer_alloc (xc_handle, cpu_to_core,sizeof (*cpu_to_core) *MAX_NR_CPU ); + cpu_to_socket =xc_hypercall_buffer_alloc (xc_handle, cpu_to_socket,sizeof (*cpu_to_socket) *MAX_NR_CPU ); + cpu_to_node =xc_hypercall_buffer_alloc (xc_handle, cpu_to_node,sizeof (*cpu_to_node) *MAX_NR_CPU ); + +if ( cpu_to_core ==NULL || cpu_to_socket ==NULL || cpu_to_node ==NULL ) + { +fprintf (stderr,"failed to allocate hypercall buffers\n" ); + goto out; + }if (gettimeofday (&tv,NULL ) ==-1 ) {fprintf (stderr,"failed to get timeofday\n" ); -return ; + goto out ; } usec_end = tv.tv_sec *1000000UL + tv.tv_usec;
@@ -385,9 +395,9 @@ static void signal_int_handler(int signo } } -set_xen_guest_handle (info.cpu_to_core, cpu_to_core); -set_xen_guest_handle (info.cpu_to_socket, cpu_to_socket); -set_xen_guest_handle (info.cpu_to_node, cpu_to_node); +xc_set_xen_guest_handle (info.cpu_to_core, cpu_to_core); +xc_set_xen_guest_handle (info.cpu_to_socket, cpu_to_socket); +xc_set_xen_guest_handle (info.cpu_to_node, cpu_to_node); info.max_cpu_index =MAX_NR_CPU -1 ; ret =xc_topologyinfo (xc_handle, &info);
@@ -485,6 +495,10 @@ static void signal_int_handler(int signofree (pxstat);free (sum);free (avgfreq); +out: +xc_hypercall_buffer_free (xc_handle, cpu_to_core); +xc_hypercall_buffer_free (xc_handle, cpu_to_socket); +xc_hypercall_buffer_free (xc_handle, cpu_to_node);xc_interface_close (xc_handle);exit (0 ); }
@@ -934,21 +948,31 @@ out:void cpu_topology_func (int argc,char *argv[]) { -uint32_t cpu_to_core[MAX_NR_CPU ]; -uint32_t cpu_to_socket[MAX_NR_CPU ]; -uint32_t cpu_to_node[MAX_NR_CPU ]; +DECLARE_HYPERCALL_BUFFER (uint32_t, cpu_to_core); +DECLARE_HYPERCALL_BUFFER (uint32_t, cpu_to_socket); +DECLARE_HYPERCALL_BUFFER (uint32_t, cpu_to_node);xc_topologyinfo_t info = {0 };int i; -set_xen_guest_handle (info.cpu_to_core, cpu_to_core); -set_xen_guest_handle (info.cpu_to_socket, cpu_to_socket); -set_xen_guest_handle (info.cpu_to_node, cpu_to_node); + cpu_to_core =xc_hypercall_buffer_alloc (xc_handle, cpu_to_core,sizeof (*cpu_to_core) *MAX_NR_CPU ); + cpu_to_socket =xc_hypercall_buffer_alloc (xc_handle, cpu_to_socket,sizeof (*cpu_to_socket) *MAX_NR_CPU ); + cpu_to_node =xc_hypercall_buffer_alloc (xc_handle, cpu_to_node,sizeof (*cpu_to_node) *MAX_NR_CPU ); + +if ( cpu_to_core ==NULL || cpu_to_socket ==NULL || cpu_to_node ==NULL ) + { +fprintf (stderr,"failed to allocate hypercall buffers\n" ); + goto out; + } + +xc_set_xen_guest_handle (info.cpu_to_core, cpu_to_core); +xc_set_xen_guest_handle (info.cpu_to_socket, cpu_to_socket); +xc_set_xen_guest_handle (info.cpu_to_node, cpu_to_node); info.max_cpu_index =MAX_NR_CPU -1 ;if (xc_topologyinfo (xc_handle, &info) ) {printf ("Can not get Xen CPU topology: %d\n" , errno); -return ; + goto out; }if ( info.max_cpu_index > (MAX_NR_CPU -1 ) )
@@ -962,6 +986,10 @@ void cpu_topology_func(int argc, char *aprintf ("CPU%d\t %d\t %d\t %d\n" , i, cpu_to_core[i], cpu_to_socket[i], cpu_to_node[i]); } +out: +xc_hypercall_buffer_free (xc_handle, cpu_to_core); +xc_hypercall_buffer_free (xc_handle, cpu_to_socket); +xc_hypercall_buffer_free (xc_handle, cpu_to_node); }void set_sched_smt_func (int argc,char *argv[])
PATCH 1/1 secpol: use hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1287650255 -3600
# Node ID 970a248771788f44fac6e4139972deb3af40a280 # Parent 26a8a8cd558e7a9ed92de6bc3605fef97571735f
secpol: use hypercall buffers
tools/security/secpol_tool.c +56 -27
@@ -242,11 +242,14 @@ int acm_get_ssidref(xc_interface *xc_han uint16_t *ste_ref) {int ret; + DECLARE_HYPERCALL_BUFFER(struct acm_ssid_buffer, ssid); +size_t ssid_buffer_size =4096 ;struct acm_getssid getssid; -char buf[4096 ]; -struct acm_ssid_buffer *ssid = (struct acm_ssid_buffer *)buf; -set_xen_guest_handle (getssid.ssidbuf, buf); - getssid.ssidbuf_size =sizeof (buf); + ssid =xc_hypercall_buffer_alloc (xc_handle, ssid, ssid_buffer_size); +if ( ssid ==NULL ) +return 1 ; +xc_set_xen_guest_handle (getssid.ssidbuf, ssid); + getssid.ssidbuf_size = ssid_buffer_size; getssid.get_ssid_by = ACM_GETBY_domainid; getssid.id.domainid = domid; ret =xc_acm_op (xc_handle, ACMOP_getssid, &getssid,sizeof (getssid));
@@ -254,23 +257,27 @@ int acm_get_ssidref(xc_interface *xc_han *chwall_ref = ssid->ssidref &0xffff ; *ste_ref = ssid->ssidref >>16 ; } +xc_hypercall_buffer_free (xc_handle, ssid);return ret; }/******************************* get policy ******************************/ -#define PULL_CACHE_SIZE 8192 -uint8_t pull_buffer[PULL_CACHE_SIZE ]; -int acm_domain_getpolicy (xc_interface *xc_handle) { +DECLARE_HYPERCALL_BUFFER (uint8_t, pull_buffer); +size_t pull_cache_size =8192 ;struct acm_getpolicy getpolicy;int ret;uint16_t chwall_ref, ste_ref; -memset (pull_buffer,0x00 ,sizeof (pull_buffer)); -set_xen_guest_handle (getpolicy.pullcache, pull_buffer); - getpolicy.pullcache_size =sizeof (pull_buffer); + pull_buffer =xc_hypercall_buffer_alloc (xc_handle, pull_buffer, pull_cache_size); +if ( pull_buffer ==NULL ) +return -1 ; + +memset (pull_buffer,0x00 , pull_cache_size); +xc_set_xen_guest_handle (getpolicy.pullcache, pull_buffer); + getpolicy.pullcache_size = pull_cache_size; ret =xc_acm_op (xc_handle, ACMOP_getpolicy, &getpolicy,sizeof (getpolicy));if (ret >=0 ) { ret =acm_get_ssidref (xc_handle,0 , &chwall_ref, &ste_ref);
@@ -284,8 +291,10 @@ int acm_domain_getpolicy(xc_interface *x }/* dump policy */ -acm_dump_policy_buffer (pull_buffer,sizeof (pull_buffer), +acm_dump_policy_buffer (pull_buffer, pull_cache_size, chwall_ref, ste_ref); + +xc_hypercall_buffer_free (xc_handle, pull_buffer);return ret; }
@@ -293,11 +302,14 @@ int acm_domain_getpolicy(xc_interface *x/************************ dump binary policy ******************************/ static int load_file (const char *filename, -uint8_t **buffer,off_t *len) +uint8_t **buffer,off_t *len, +xc_interface *xc_handle, +xc_hypercall_buffer_t *hcall) {struct stat mystat;int ret =0 ;int fd; +DECLARE_HYPERCALL_BUFFER_ARGUMENT (hcall);if ((ret =stat (filename, &mystat)) !=0 ) {printf ("File %s not found.\n" , filename);
@@ -307,9 +319,16 @@ static int load_file(const char *filenam *len = mystat.st_size; -if ((*buffer =malloc (*len)) ==NULL ) { - ret = -ENOMEM ; - goto out; +if ( hcall ==NULL ) { +if ((*buffer =malloc (*len)) ==NULL ) { + ret = -ENOMEM ; + goto out; + } + }else { +if ((*buffer =xc_hypercall_buffer_alloc (xc_handle, hcall, *len)) ==NULL ) { + ret = -ENOMEM ; + goto out; + } }if ((fd =open (filename,O_RDONLY )) <=0 ) {
@@ -322,7 +341,10 @@ static int load_file(const char *filenamreturn 0 ; free_out: -free (*buffer); +if ( hcall ==NULL ) +free (*buffer); +else +xc_hypercall_buffer_free (xc_handle, hcall); *buffer =NULL ; *len =0 ; out:
@@ -339,7 +361,7 @@ static int acm_domain_dumppolicy(const c chwall_ssidref = (ssidref ) &0xffff ; ste_ssidref = (ssidref >>16 ) &0xffff ; -if ((ret =load_file (filename, &buffer, &len)) ==0 ) { +if ((ret =load_file (filename, &buffer, &len,NULL ,NULL )) ==0 ) {acm_dump_policy_buffer (buffer, len, chwall_ssidref, ste_ssidref);free (buffer); }
@@ -353,11 +375,11 @@ int acm_domain_loadpolicy(xc_interface * {int ret;off_t len; -uint8_t *buffer; +DECLARE_HYPERCALL_BUFFER (uint8_t, buffer);uint16_t chwall_ssidref, ste_ssidref;struct acm_setpolicy setpolicy; - ret =load_file (filename, &buffer, &len); + ret =load_file (filename, &buffer, &len, xc_handle,HYPERCALL_BUFFER (buffer));if (ret !=0 ) goto out;
@@ -367,7 +389,7 @@ int acm_domain_loadpolicy(xc_interface */* dump it and then push it down into xen/acm */ acm_dump_policy_buffer (buffer, len, chwall_ssidref, ste_ssidref); -set_xen_guest_handle (setpolicy.pushcache, buffer); +xc_set_xen_guest_handle (setpolicy.pushcache, buffer); setpolicy.pushcache_size = len; ret =xc_acm_op (xc_handle, ACMOP_setpolicy, &setpolicy,sizeof (setpolicy));
@@ -378,7 +400,7 @@ int acm_domain_loadpolicy(xc_interface * } free_out: -free (buffer); +xc_hypercall_buffer_free (xc_handle, buffer); out:return ret; }
@@ -402,22 +424,27 @@ void dump_ste_stats(struct acm_ste_stats ntohl(ste_stats->gt_cachehit_count)); } -#define PULL_STATS_SIZE 8192int acm_domain_dumpstats (xc_interface *xc_handle) { -uint8_t stats_buffer[PULL_STATS_SIZE ]; +DECLARE_HYPERCALL_BUFFER (uint8_t, stats_buffer); +size_t pull_stats_size =8192 ;struct acm_dumpstats dumpstats;int ret;struct acm_stats_buffer *stats; -memset (stats_buffer,0x00 ,sizeof (stats_buffer)); -set_xen_guest_handle (dumpstats.pullcache, stats_buffer); - dumpstats.pullcache_size =sizeof (stats_buffer); + stats_buffer =xc_hypercall_buffer_alloc (xc_handle, stats_buffer, pull_stats_size); +if ( stats_buffer ==NULL ) +return -1 ; + +memset (stats_buffer,0x00 , pull_stats_size); +xc_set_xen_guest_handle (dumpstats.pullcache, stats_buffer); + dumpstats.pullcache_size = pull_stats_size; ret =xc_acm_op (xc_handle, ACMOP_dumpstats, &dumpstats,sizeof (dumpstats));if (ret <0 ) {printf ("ERROR dumping policy stats. Try 'xm dmesg' to see details.\n" ); +xc_hypercall_buffer_free (xc_handle, stats_buffer);return ret; } stats = (struct acm_stats_buffer *) stats_buffer;
@@ -464,6 +491,7 @@ int acm_domain_dumpstats(xc_interface *xdefault :printf ("UNKNOWN SECONDARY POLICY ERROR!\n" ); } +xc_hypercall_buffer_free (xc_handle, stats_buffer);return ret; }
@@ -472,7 +500,8 @@ int main(int argc, char **argv)int main (int argc,char **argv) { -xc_interface *xc_handle, ret =0 ; +xc_interface *xc_handle; +int ret =0 ;if (argc <2 )usage (argv[0 ]);
PATCH 1/1 libxc: do not align/lock buffers which do not need it
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1287650255 -3600
# Node ID 42caa87197dfe69901d4d20c6432b5914b62ac07 # Parent 970a248771788f44fac6e4139972deb3af40a280
libxc: do not align/lock buffers which do not need it
On restore:
region_mfn is passed to xc_map_foreign_range and xc_map_foreign_bulk. In both cases the buffer is accessed from the ioctl handler in the kernel and not from any hypercall. Therefore normal copy_{to,from}_user handling in the kernel will cope with any faulting access.
p2m_batch is passed to xc_domain_memory_populate_physmap which takes care of bouncing the buffer already.
On save:
pfn_type is passed to xc_map_foreign_bulk which does not need locking as per region_mfn above.
tools/libxc/xc_domain_restore.c +2 -16
@@ -1172,10 +1172,8 @@ int xc_domain_restore(xc_interface *xch, ctx->p2m =calloc (dinfo->p2m_size,sizeof (xen_pfn_t)); pfn_type =calloc (dinfo->p2m_size,sizeof (unsigned long )); - region_mfn =xc_memalign (PAGE_SIZE ,ROUNDUP ( -MAX_BATCH_SIZE *sizeof (xen_pfn_t),PAGE_SHIFT )); - ctx->p2m_batch =xc_memalign ( -PAGE_SIZE ,ROUNDUP (MAX_BATCH_SIZE *sizeof (xen_pfn_t),PAGE_SHIFT )); + region_mfn =malloc (ROUNDUP (MAX_BATCH_SIZE *sizeof (xen_pfn_t),PAGE_SHIFT )); + ctx->p2m_batch =malloc (ROUNDUP (MAX_BATCH_SIZE *sizeof (xen_pfn_t),PAGE_SHIFT ));if ( (ctx->p2m ==NULL ) || (pfn_type ==NULL ) || (region_mfn ==NULL ) || (ctx->p2m_batch ==NULL ) )
@@ -1189,18 +1187,6 @@ int xc_domain_restore(xc_interface *xch, ROUNDUP(MAX_BATCH_SIZE * sizeof(xen_pfn_t), PAGE_SHIFT));memset (ctx->p2m_batch,0 ,ROUNDUP (MAX_BATCH_SIZE *sizeof (xen_pfn_t),PAGE_SHIFT )); - -if (lock_pages (xch, region_mfn,sizeof (xen_pfn_t) *MAX_BATCH_SIZE ) ) - { -PERROR ("Could not lock region_mfn" ); - goto out; - } - -if (lock_pages (xch, ctx->p2m_batch,sizeof (xen_pfn_t) *MAX_BATCH_SIZE ) ) - { -ERROR ("Could not lock p2m_batch" ); - goto out; - }/* Get the domain's shared-info frame. */ domctl.cmd = XEN_DOMCTL_getdomaininfo;
tools/libxc/xc_domain_save.c +1 -8
@@ -1071,8 +1071,7 @@ int xc_domain_save(xc_interface *xch, inanalysis_phase (xch, dom, ctx,HYPERCALL_BUFFER (to_skip),0 ); - pfn_type =xc_memalign (PAGE_SIZE ,ROUNDUP ( -MAX_BATCH_SIZE *sizeof (*pfn_type),PAGE_SHIFT )); + pfn_type =malloc (ROUNDUP (MAX_BATCH_SIZE *sizeof (*pfn_type),PAGE_SHIFT )); pfn_batch =calloc (MAX_BATCH_SIZE ,sizeof (*pfn_batch)); pfn_err =malloc (MAX_BATCH_SIZE *sizeof (*pfn_err));if ( (pfn_type ==NULL ) || (pfn_batch ==NULL ) || (pfn_err ==NULL ) )
@@ -1083,12 +1082,6 @@ int xc_domain_save(xc_interface *xch, in }memset (pfn_type,0 ,ROUNDUP (MAX_BATCH_SIZE *sizeof (*pfn_type),PAGE_SHIFT )); - -if (lock_pages (xch, pfn_type,MAX_BATCH_SIZE *sizeof (*pfn_type)) ) - { -PERROR ("Unable to lock pfn_type array" ); - goto out; - }/* Setup the mfn_to_pfn table mapping */ if ( !(ctx->live_m2p =xc_map_m2p (xch, ctx->max_mfn,PROT_READ , &ctx->m2p_mfn0)) )
PATCH 1/1 libxc: finalise transition to hypercall buffers
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1287650255 -3600
# Node ID a4e1a2dbc215e601acf69b212f82cea767f3330c # Parent 42caa87197dfe69901d4d20c6432b5914b62ac07
libxc: finalise transition to hypercall buffers.
Rename xc_set_xen_guest_handle to set_xen_guest_handle[0] and remove now unused functions:
- xc_memalign
- lock_pages
- unlock_pages
- hcall_buf_prep
- hcall_buf_release
[0] sed -i -e 's/xc_set_xen_guest_handle/set_xen_guest_handle/g' \ tools/libxc/*.[ch] \ tools/python/xen/lowlevel/xc/xc.c \ tools/python/xen/lowlevel/acm/acm.c \ tools/libxc/ia64/xc_ia64_stubs.c \ tools/security/secpol_tool.c \ tools/misc/xenpm.c
tools/libxc/xc_cpupool.c +2 -2
@@ -88,7 +88,7 @@ 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; -xc_set_xen_guest_handle (sysctl.u.cpupool_op.cpumap.bitmap, local); +set_xen_guest_handle (sysctl.u.cpupool_op.cpumap.bitmap, local); sysctl.u.cpupool_op.cpumap.nr_cpus =sizeof (info->cpumap) *8 ; err =do_sysctl_save (xch, &sysctl);
@@ -165,7 +165,7 @@ int xc_cpupool_freeinfo(xc_interface *xc sysctl.cmd = XEN_SYSCTL_cpupool_op; sysctl.u.cpupool_op.op =XEN_SYSCTL_CPUPOOL_OP_FREEINFO ; -xc_set_xen_guest_handle (sysctl.u.cpupool_op.cpumap.bitmap, local); +set_xen_guest_handle (sysctl.u.cpupool_op.cpumap.bitmap, local); sysctl.u.cpupool_op.cpumap.nr_cpus =sizeof (*cpumap) *8 ; err =do_sysctl_save (xch, &sysctl);
tools/libxc/xc_dom_boot.c +1 -1
@@ -72,7 +72,7 @@ static int launch_vm(xc_interface *xch, domctl.cmd = XEN_DOMCTL_setvcpucontext; domctl.domain = domid; domctl.u.vcpucontext.vcpu =0 ; -xc_set_xen_guest_handle (domctl.u.vcpucontext.ctxt, ctxt); +set_xen_guest_handle (domctl.u.vcpucontext.ctxt, ctxt); rc =do_domctl (xch, &domctl);if ( rc !=0 ) xc_dom_panic(xch, XC_INTERNAL_ERROR,
tools/libxc/xc_domain.c +17 -17
@@ -132,7 +132,7 @@ int xc_vcpu_setaffinity(xc_interface *xcbitmap_64_to_byte (local, cpumap, cpusize *8 ); -xc_set_xen_guest_handle (domctl.u.vcpuaffinity.cpumap.bitmap, local); +set_xen_guest_handle (domctl.u.vcpuaffinity.cpumap.bitmap, local); domctl.u.vcpuaffinity.cpumap.nr_cpus = cpusize *8 ;
@@ -165,7 +165,7 @@ int xc_vcpu_getaffinity(xc_interface *xc domctl.domain = (domid_t )domid; domctl.u.vcpuaffinity.vcpu = vcpu; -xc_set_xen_guest_handle (domctl.u.vcpuaffinity.cpumap.bitmap, local); +set_xen_guest_handle (domctl.u.vcpuaffinity.cpumap.bitmap, local); domctl.u.vcpuaffinity.cpumap.nr_cpus = cpusize *8 ; ret =do_domctl (xch, &domctl);
@@ -254,7 +254,7 @@ int xc_domain_getinfolist(xc_interface * sysctl.cmd = XEN_SYSCTL_getdomaininfolist; sysctl.u.getdomaininfolist.first_domain = first_domain; sysctl.u.getdomaininfolist.max_domains = max_domains; -xc_set_xen_guest_handle (sysctl.u.getdomaininfolist.buffer, info); +set_xen_guest_handle (sysctl.u.getdomaininfolist.buffer, info);if (xc_sysctl (xch, &sysctl) <0 ) ret =-1 ;
@@ -282,7 +282,7 @@ int xc_domain_hvm_getcontext(xc_interfac domctl.cmd = XEN_DOMCTL_gethvmcontext; domctl.domain = (domid_t )domid; domctl.u.hvmcontext.size = size; -xc_set_xen_guest_handle (domctl.u.hvmcontext.buffer, ctxt_buf); +set_xen_guest_handle (domctl.u.hvmcontext.buffer, ctxt_buf); ret =do_domctl (xch, &domctl);
@@ -311,7 +311,7 @@ int xc_domain_hvm_getcontext_partial(xc_ domctl.domain = (domid_t ) domid; domctl.u.hvmcontext_partial.type = typecode; domctl.u.hvmcontext_partial.instance = instance; -xc_set_xen_guest_handle (domctl.u.hvmcontext_partial.buffer, ctxt_buf); +set_xen_guest_handle (domctl.u.hvmcontext_partial.buffer, ctxt_buf); ret =do_domctl (xch, &domctl);
@@ -337,7 +337,7 @@ int xc_domain_hvm_setcontext(xc_interfac domctl.cmd = XEN_DOMCTL_sethvmcontext; domctl.domain = domid; domctl.u.hvmcontext.size = size; -xc_set_xen_guest_handle (domctl.u.hvmcontext.buffer, ctxt_buf); +set_xen_guest_handle (domctl.u.hvmcontext.buffer, ctxt_buf); ret =do_domctl (xch, &domctl);
@@ -361,7 +361,7 @@ int xc_vcpu_getcontext(xc_interface *xch domctl.cmd = XEN_DOMCTL_getvcpucontext; domctl.domain = (domid_t )domid; domctl.u.vcpucontext.vcpu = (uint16_t )vcpu; -xc_set_xen_guest_handle (domctl.u.vcpucontext.ctxt, ctxt); +set_xen_guest_handle (domctl.u.vcpucontext.ctxt, ctxt); rc =do_domctl (xch, &domctl);
@@ -420,7 +420,7 @@ int xc_shadow_control(xc_interface *xch, domctl.u.shadow_op.mb = mb ? *mb :0 ; domctl.u.shadow_op.mode = mode;if (dirty_bitmap !=NULL ) -xc_set_xen_guest_handle (domctl.u.shadow_op.dirty_bitmap, +set_xen_guest_handle (domctl.u.shadow_op.dirty_bitmap, dirty_bitmap); rc =do_domctl (xch, &domctl);
@@ -486,7 +486,7 @@ int xc_domain_set_memmap_limit(xc_interf e820->size = (uint64_t )map_limitkb <<10 ; e820->type =E820_RAM ; -xc_set_xen_guest_handle (fmap.map.buffer, e820); +set_xen_guest_handle (fmap.map.buffer, e820); rc =do_memory_op (xch, XENMEM_set_memory_map, &fmap,sizeof (fmap));
@@ -559,7 +559,7 @@ int xc_domain_get_tsc_info(xc_interface domctl.cmd = XEN_DOMCTL_gettscinfo; domctl.domain = (domid_t )domid; -xc_set_xen_guest_handle (domctl.u.tsc_info.out_info, info); +set_xen_guest_handle (domctl.u.tsc_info.out_info, info); rc =do_domctl (xch, &domctl);if ( rc ==0 ) {
@@ -601,7 +601,7 @@ int xc_domain_increase_reservation(xc_inreturn -1 ; } -xc_set_xen_guest_handle (reservation.extent_start, extent_start); +set_xen_guest_handle (reservation.extent_start, extent_start); err =do_memory_op (xch, XENMEM_increase_reservation, &reservation,sizeof (reservation));
@@ -664,7 +664,7 @@ int xc_domain_decrease_reservation(xc_inPERROR ("Could not bounce memory for XENMEM_decrease_reservation hypercall" );return -1 ; } -xc_set_xen_guest_handle (reservation.extent_start, extent_start); +set_xen_guest_handle (reservation.extent_start, extent_start); err =do_memory_op (xch, XENMEM_decrease_reservation, &reservation,sizeof (reservation));
@@ -734,7 +734,7 @@ int xc_domain_populate_physmap(xc_interfPERROR ("Could not bounce memory for XENMEM_populate_physmap hypercall" );return -1 ; } -xc_set_xen_guest_handle (reservation.extent_start, extent_start); +set_xen_guest_handle (reservation.extent_start, extent_start); err =do_memory_op (xch, XENMEM_populate_physmap, &reservation,sizeof (reservation));
@@ -796,8 +796,8 @@ int xc_domain_memory_exchange_pages(xc_i xc_hypercall_bounce_pre(xch, out_extents)) goto out; -xc_set_xen_guest_handle (exchange.in.extent_start, in_extents); -xc_set_xen_guest_handle (exchange.out.extent_start, out_extents); +set_xen_guest_handle (exchange.in.extent_start, in_extents); +set_xen_guest_handle (exchange.out.extent_start, out_extents); rc =do_memory_op (xch, XENMEM_exchange, &exchange,sizeof (exchange));
@@ -976,7 +976,7 @@ int xc_vcpu_setcontext(xc_interface *xch domctl.cmd = XEN_DOMCTL_setvcpucontext; domctl.domain = domid; domctl.u.vcpucontext.vcpu = vcpu; -xc_set_xen_guest_handle (domctl.u.vcpucontext.ctxt, ctxt); +set_xen_guest_handle (domctl.u.vcpucontext.ctxt, ctxt); rc =do_domctl (xch, &domctl);
@@ -1124,7 +1124,7 @@ int xc_get_device_group( domctl.u.get_device_group.machine_bdf = machine_bdf; domctl.u.get_device_group.max_sdevs = max_sdevs; -xc_set_xen_guest_handle (domctl.u.get_device_group.sdev_array, sdev_array); +set_xen_guest_handle (domctl.u.get_device_group.sdev_array, sdev_array); rc =do_domctl (xch, &domctl);
tools/libxc/xc_domain_restore.c +1 -1
@@ -1639,7 +1639,7 @@ int xc_domain_restore(xc_interface *xch, domctl.cmd = XEN_DOMCTL_setvcpucontext; domctl.domain = (domid_t )dom; domctl.u.vcpucontext.vcpu = i; -xc_set_xen_guest_handle (domctl.u.vcpucontext.ctxt, ctxt); +set_xen_guest_handle (domctl.u.vcpucontext.ctxt, ctxt); frc =xc_domctl (xch, &domctl);if ( frc !=0 ) {
tools/libxc/xc_linux.c +1 -1
@@ -686,7 +686,7 @@ static void *_gnttab_map_table(xc_interf setup.dom = domid; setup.nr_frames = query.nr_frames; -xc_set_xen_guest_handle (setup.frame_list, frame_list); +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),
tools/libxc/xc_misc.c +13 -13
@@ -35,7 +35,7 @@ int xc_readconsolering(xc_interface *xchreturn -1 ; sysctl.cmd = XEN_SYSCTL_readconsole; -xc_set_xen_guest_handle (sysctl.u.readconsole.buffer, buffer); +set_xen_guest_handle (sysctl.u.readconsole.buffer, buffer); sysctl.u.readconsole.count = nr_chars; sysctl.u.readconsole.clear = clear; sysctl.u.readconsole.incremental =0 ;
@@ -67,7 +67,7 @@ int xc_send_debug_keys(xc_interface *xchreturn -1 ; sysctl.cmd = XEN_SYSCTL_debug_keys; -xc_set_xen_guest_handle (sysctl.u.debug_keys.keys, keys); +set_xen_guest_handle (sysctl.u.debug_keys.keys, keys); sysctl.u.debug_keys.nr_keys = len; ret =do_sysctl (xch, &sysctl);
@@ -176,8 +176,8 @@ int xc_perfc_reset(xc_interface *xch) sysctl.cmd = XEN_SYSCTL_perfc_op; sysctl.u.perfc_op.cmd = XEN_SYSCTL_PERFCOP_reset; -xc_set_xen_guest_handle (sysctl.u.perfc_op.desc,HYPERCALL_BUFFER_NULL ); -xc_set_xen_guest_handle (sysctl.u.perfc_op.val,HYPERCALL_BUFFER_NULL ); +set_xen_guest_handle (sysctl.u.perfc_op.desc,HYPERCALL_BUFFER_NULL ); +set_xen_guest_handle (sysctl.u.perfc_op.val,HYPERCALL_BUFFER_NULL );return do_sysctl (xch, &sysctl); }
@@ -191,8 +191,8 @@ int xc_perfc_query_number(xc_interface * sysctl.cmd = XEN_SYSCTL_perfc_op; sysctl.u.perfc_op.cmd = XEN_SYSCTL_PERFCOP_query; -xc_set_xen_guest_handle (sysctl.u.perfc_op.desc,HYPERCALL_BUFFER_NULL ); -xc_set_xen_guest_handle (sysctl.u.perfc_op.val,HYPERCALL_BUFFER_NULL ); +set_xen_guest_handle (sysctl.u.perfc_op.desc,HYPERCALL_BUFFER_NULL ); +set_xen_guest_handle (sysctl.u.perfc_op.val,HYPERCALL_BUFFER_NULL ); rc =do_sysctl (xch, &sysctl);
@@ -214,8 +214,8 @@ int xc_perfc_query(xc_interface *xch, sysctl.cmd = XEN_SYSCTL_perfc_op; sysctl.u.perfc_op.cmd = XEN_SYSCTL_PERFCOP_query; -xc_set_xen_guest_handle (sysctl.u.perfc_op.desc, desc); -xc_set_xen_guest_handle (sysctl.u.perfc_op.val, val); +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); }
@@ -226,7 +226,7 @@ int xc_lockprof_reset(xc_interface *xch) sysctl.cmd = XEN_SYSCTL_lockprof_op; sysctl.u.lockprof_op.cmd = XEN_SYSCTL_LOCKPROF_reset; -xc_set_xen_guest_handle (sysctl.u.lockprof_op.data,HYPERCALL_BUFFER_NULL ); +set_xen_guest_handle (sysctl.u.lockprof_op.data,HYPERCALL_BUFFER_NULL );return do_sysctl (xch, &sysctl); }
@@ -239,7 +239,7 @@ int xc_lockprof_query_number(xc_interfac sysctl.cmd = XEN_SYSCTL_lockprof_op; sysctl.u.lockprof_op.cmd = XEN_SYSCTL_LOCKPROF_query; -xc_set_xen_guest_handle (sysctl.u.lockprof_op.data,HYPERCALL_BUFFER_NULL ); +set_xen_guest_handle (sysctl.u.lockprof_op.data,HYPERCALL_BUFFER_NULL ); rc =do_sysctl (xch, &sysctl);
@@ -260,7 +260,7 @@ int xc_lockprof_query(xc_interface *xch, sysctl.cmd = XEN_SYSCTL_lockprof_op; sysctl.u.lockprof_op.cmd = XEN_SYSCTL_LOCKPROF_query; sysctl.u.lockprof_op.max_elem = *n_elems; -xc_set_xen_guest_handle (sysctl.u.lockprof_op.data, data); +set_xen_guest_handle (sysctl.u.lockprof_op.data, data); rc =do_sysctl (xch, &sysctl);
@@ -281,7 +281,7 @@ int xc_getcpuinfo(xc_interface *xch, int sysctl.cmd = XEN_SYSCTL_getcpuinfo; sysctl.u.getcpuinfo.max_cpus = max_cpus; -xc_set_xen_guest_handle (sysctl.u.getcpuinfo.info, info); +set_xen_guest_handle (sysctl.u.getcpuinfo.info, info); rc =do_sysctl (xch, &sysctl);
@@ -413,7 +413,7 @@ int xc_hvm_track_dirty_vram( arg->domid = dom; arg->first_pfn = first_pfn; arg->nr = nr; -xc_set_xen_guest_handle (arg->dirty_bitmap, dirty_bitmap); +set_xen_guest_handle (arg->dirty_bitmap, dirty_bitmap); rc =do_xen_hypercall (xch, &hypercall);
tools/libxc/xc_offline_page.c +3 -3
@@ -82,7 +82,7 @@ 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; -xc_set_xen_guest_handle (sysctl.u.page_offline.status, status); +set_xen_guest_handle (sysctl.u.page_offline.status, status); ret =xc_sysctl (xch, &sysctl);xc_hypercall_bounce_post (xch, status);
@@ -110,7 +110,7 @@ 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; -xc_set_xen_guest_handle (sysctl.u.page_offline.status, status); +set_xen_guest_handle (sysctl.u.page_offline.status, status); ret =xc_sysctl (xch, &sysctl);xc_hypercall_bounce_post (xch, status);
@@ -138,7 +138,7 @@ 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; -xc_set_xen_guest_handle (sysctl.u.page_offline.status, status); +set_xen_guest_handle (sysctl.u.page_offline.status, status); ret =xc_sysctl (xch, &sysctl);xc_hypercall_bounce_post (xch, status);
tools/libxc/xc_pm.c +7 -7
@@ -73,8 +73,8 @@ int xc_pm_get_pxstat(xc_interface *xch, sysctl.u.get_pmstat.type = PMSTAT_get_pxstat; sysctl.u.get_pmstat.cpuid = cpuid; sysctl.u.get_pmstat.u.getpx.total = max_px; -xc_set_xen_guest_handle (sysctl.u.get_pmstat.u.getpx.trans_pt, trans); -xc_set_xen_guest_handle (sysctl.u.get_pmstat.u.getpx.pt, pt); +set_xen_guest_handle (sysctl.u.get_pmstat.u.getpx.trans_pt, trans); +set_xen_guest_handle (sysctl.u.get_pmstat.u.getpx.pt, pt); ret =xc_sysctl (xch, &sysctl);if ( ret )
@@ -146,8 +146,8 @@ int xc_pm_get_cxstat(xc_interface *xch, sysctl.cmd = XEN_SYSCTL_get_pmstat; sysctl.u.get_pmstat.type = PMSTAT_get_cxstat; sysctl.u.get_pmstat.cpuid = cpuid; -xc_set_xen_guest_handle (sysctl.u.get_pmstat.u.getcx.triggers, triggers); -xc_set_xen_guest_handle (sysctl.u.get_pmstat.u.getcx.residencies, residencies); +set_xen_guest_handle (sysctl.u.get_pmstat.u.getcx.triggers, triggers); +set_xen_guest_handle (sysctl.u.get_pmstat.u.getcx.residencies, residencies);if ( (ret =xc_sysctl (xch, &sysctl)) ) goto unlock_2;
@@ -219,9 +219,9 @@ int xc_get_cpufreq_para(xc_interface *xcif (xc_hypercall_bounce_pre (xch, scaling_available_governors) ) goto unlock_3; -xc_set_xen_guest_handle (sys_para->affected_cpus, affected_cpus); -xc_set_xen_guest_handle (sys_para->scaling_available_frequencies, scaling_available_frequencies); -xc_set_xen_guest_handle (sys_para->scaling_available_governors, scaling_available_governors); +set_xen_guest_handle (sys_para->affected_cpus, affected_cpus); +set_xen_guest_handle (sys_para->scaling_available_frequencies, scaling_available_frequencies); +set_xen_guest_handle (sys_para->scaling_available_governors, scaling_available_governors); } sysctl.cmd = XEN_SYSCTL_pm_op;
tools/libxc/xc_private.c +3 -150
195 lines not on this page · raw message
tools/libxc/xc_private.h +0 -8
@@ -97,14 +97,6 @@ void xc_report_progress_step(xc_interfac #define ERROR(_m, _a...) xc_report_error(xch,XC_INTERNAL_ERROR,_m , ## _a ) #define PERROR(_m, _a...) xc_report_error(xch,XC_INTERNAL_ERROR,_m \ " (%d = %s)", ## _a , errno, safe_strerror(errno)) - -void *xc_memalign (size_t alignment,size_t size); - -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 (xc_interface *xch,void **addr,size_t len); -void hcall_buf_release (xc_interface *xch,void **addr,size_t len);/* * HYPERCALL ARGUMENT BUFFERS
tools/libxc/xc_tbuf.c +1 -1
@@ -132,7 +132,7 @@ int xc_tbuf_set_cpu_mask(xc_interface *xbitmap_64_to_byte (bytemap, &mask64,sizeof (mask64) *8 ); -xc_set_xen_guest_handle (sysctl.u.tbuf_op.cpu_mask.bitmap, bytemap); +set_xen_guest_handle (sysctl.u.tbuf_op.cpu_mask.bitmap, bytemap); sysctl.u.tbuf_op.cpu_mask.nr_cpus =sizeof (bytemap) *8 ; ret =do_sysctl (xch, &sysctl);
tools/libxc/xc_tmem.c +2 -2
@@ -86,7 +86,7 @@ int xc_tmem_control(xc_interface *xch, } } -xc_set_xen_guest_handle (op.u.ctrl.buf, buf); +set_xen_guest_handle (op.u.ctrl.buf, buf); rc =do_tmem_op (xch, &op);
@@ -136,7 +136,7 @@ int xc_tmem_control_oid(xc_interface *xc } } -xc_set_xen_guest_handle (op.u.ctrl.buf, buf); +set_xen_guest_handle (op.u.ctrl.buf, buf); rc =do_tmem_op (xch, &op);
tools/libxc/xenctrl.h +3 -2
@@ -252,7 +252,8 @@ typedef struct xc_hypercall_buffer xc_hy* Set a xen_guest_handle in a type safe manner, ensuring that the * data pointer has been correctly allocated. */ -#define xc_set_xen_guest_handle (_hnd, _val) \ +#undef set_xen_guest_handle +#define set_xen_guest_handle (_hnd, _val) \ do { \ xc_hypercall_buffer_t _val1; \ typeof(XC__HYPERCALL_BUFFER_NAME(_val)) *_val2 = HYPERCALL_BUFFER(_val); \
@@ -260,7 +261,7 @@ typedef struct xc_hypercall_buffer xc_hyset_xen_guest_handle_raw (_hnd, (_val2)->hbuf); \ }while (0 ) -/* Use with xc_set_xen_guest_handle in place of NULL */ +/* Use with set_xen_guest_handle in place of NULL */ extern xc_hypercall_buffer_t XC__HYPERCALL_BUFFER_NAME(HYPERCALL_BUFFER_NULL);/*
tools/misc/xenpm.c +6 -6
@@ -395,9 +395,9 @@ static void signal_int_handler(int signo } } -xc_set_xen_guest_handle (info.cpu_to_core, cpu_to_core); -xc_set_xen_guest_handle (info.cpu_to_socket, cpu_to_socket); -xc_set_xen_guest_handle (info.cpu_to_node, cpu_to_node); +set_xen_guest_handle (info.cpu_to_core, cpu_to_core); +set_xen_guest_handle (info.cpu_to_socket, cpu_to_socket); +set_xen_guest_handle (info.cpu_to_node, cpu_to_node); info.max_cpu_index =MAX_NR_CPU -1 ; ret =xc_topologyinfo (xc_handle, &info);
@@ -964,9 +964,9 @@ void cpu_topology_func(int argc, char *a goto out; } -xc_set_xen_guest_handle (info.cpu_to_core, cpu_to_core); -xc_set_xen_guest_handle (info.cpu_to_socket, cpu_to_socket); -xc_set_xen_guest_handle (info.cpu_to_node, cpu_to_node); +set_xen_guest_handle (info.cpu_to_core, cpu_to_core); +set_xen_guest_handle (info.cpu_to_socket, cpu_to_socket); +set_xen_guest_handle (info.cpu_to_node, cpu_to_node); info.max_cpu_index =MAX_NR_CPU -1 ;if (xc_topologyinfo (xc_handle, &info) )
tools/python/xen/lowlevel/acm/acm.c +8 -8
@@ -53,7 +53,7 @@ static void *__getssid(xc_interface *xc_ }memset (buf,0 ,SSID_BUFFER_SIZE ); -xc_set_xen_guest_handle (getssid.ssidbuf, buffer); +set_xen_guest_handle (getssid.ssidbuf, buffer); getssid.ssidbuf_size =SSID_BUFFER_SIZE ; getssid.get_ssid_by = ACM_GETBY_domainid; getssid.id.domainid = domid;
@@ -254,10 +254,10 @@ static PyObject *chgpolicy(PyObject *sel chgpolicy.delarray_size = del_arr_len; chgpolicy.chgarray_size = chg_arr_len; chgpolicy.errarray_size =sizeof (*error_array)*errarray_mbrs; -xc_set_xen_guest_handle (chgpolicy.policy_pushcache, bin_pol_buf); -xc_set_xen_guest_handle (chgpolicy.del_array, del_arr_buf); -xc_set_xen_guest_handle (chgpolicy.chg_array, chg_arr_buf); -xc_set_xen_guest_handle (chgpolicy.err_array, error_array); +set_xen_guest_handle (chgpolicy.policy_pushcache, bin_pol_buf); +set_xen_guest_handle (chgpolicy.del_array, del_arr_buf); +set_xen_guest_handle (chgpolicy.chg_array, chg_arr_buf); +set_xen_guest_handle (chgpolicy.err_array, error_array); rc =xc_acm_op (xc_handle, ACMOP_chgpolicy, &chgpolicy,sizeof (chgpolicy));
@@ -299,7 +299,7 @@ static PyObject *getpolicy(PyObject *sel goto out;memset (&getpolicy,0x0 ,sizeof (getpolicy)); -xc_set_xen_guest_handle (getpolicy.pullcache, pull_buffer); +set_xen_guest_handle (getpolicy.pullcache, pull_buffer); getpolicy.pullcache_size =sizeof (pull_buffer); rc =xc_acm_op (xc_handle, ACMOP_getpolicy, &getpolicy,sizeof (getpolicy));
@@ -356,8 +356,8 @@ static PyObject *relabel_domains(PyObjec reldoms.relabel_map_size = rel_rules_len; reldoms.errarray_size =sizeof (error_array); -xc_set_xen_guest_handle (reldoms.relabel_map, relabel_rules_buf); -xc_set_xen_guest_handle (reldoms.err_array, error_array); +set_xen_guest_handle (reldoms.relabel_map, relabel_rules_buf); +set_xen_guest_handle (reldoms.err_array, error_array); rc =xc_acm_op (xc_handle, ACMOP_relabeldoms, &reldoms,sizeof (reldoms));
tools/python/xen/lowlevel/xc/xc.c +6 -6
@@ -1222,9 +1222,9 @@ static PyObject *pyxc_topologyinfo(XcObjif ( nodemap ==NULL ) goto out; -xc_set_xen_guest_handle (tinfo.cpu_to_core, coremap); -xc_set_xen_guest_handle (tinfo.cpu_to_socket, socketmap); -xc_set_xen_guest_handle (tinfo.cpu_to_node, nodemap); +set_xen_guest_handle (tinfo.cpu_to_core, coremap); +set_xen_guest_handle (tinfo.cpu_to_socket, socketmap); +set_xen_guest_handle (tinfo.cpu_to_node, nodemap); tinfo.max_cpu_index =MAX_CPU_INDEX ;if (xc_topologyinfo (self->xc_handle, &tinfo) !=0 )
@@ -1316,9 +1316,9 @@ static PyObject *pyxc_numainfo(XcObjectif ( nodes_dist ==NULL ) goto out; -xc_set_xen_guest_handle (ninfo.node_to_memsize, node_memsize); -xc_set_xen_guest_handle (ninfo.node_to_memfree, node_memfree); -xc_set_xen_guest_handle (ninfo.node_to_node_distance, nodes_dist); +set_xen_guest_handle (ninfo.node_to_memsize, node_memsize); +set_xen_guest_handle (ninfo.node_to_memfree, node_memfree); +set_xen_guest_handle (ninfo.node_to_node_distance, nodes_dist); ninfo.max_node_index =MAX_NODE_INDEX ;if (xc_numainfo (self->xc_handle, &ninfo) !=0 )
tools/security/secpol_tool.c +4 -4
@@ -248,7 +248,7 @@ int acm_get_ssidref(xc_interface *xc_han ssid =xc_hypercall_buffer_alloc (xc_handle, ssid, ssid_buffer_size);if ( ssid ==NULL )return 1 ; -xc_set_xen_guest_handle (getssid.ssidbuf, ssid); +set_xen_guest_handle (getssid.ssidbuf, ssid); getssid.ssidbuf_size = ssid_buffer_size; getssid.get_ssid_by = ACM_GETBY_domainid; getssid.id.domainid = domid;
@@ -276,7 +276,7 @@ int acm_domain_getpolicy(xc_interface *xreturn -1 ;memset (pull_buffer,0x00 , pull_cache_size); -xc_set_xen_guest_handle (getpolicy.pullcache, pull_buffer); +set_xen_guest_handle (getpolicy.pullcache, pull_buffer); getpolicy.pullcache_size = pull_cache_size; ret =xc_acm_op (xc_handle, ACMOP_getpolicy, &getpolicy,sizeof (getpolicy));if (ret >=0 ) {
@@ -389,7 +389,7 @@ int acm_domain_loadpolicy(xc_interface */* dump it and then push it down into xen/acm */ acm_dump_policy_buffer (buffer, len, chwall_ssidref, ste_ssidref); -xc_set_xen_guest_handle (setpolicy.pushcache, buffer); +set_xen_guest_handle (setpolicy.pushcache, buffer); setpolicy.pushcache_size = len; ret =xc_acm_op (xc_handle, ACMOP_setpolicy, &setpolicy,sizeof (setpolicy));
@@ -437,7 +437,7 @@ int acm_domain_dumpstats(xc_interface *xreturn -1 ;memset (stats_buffer,0x00 , pull_stats_size); -xc_set_xen_guest_handle (dumpstats.pullcache, stats_buffer); +set_xen_guest_handle (dumpstats.pullcache, stats_buffer); dumpstats.pullcache_size = pull_stats_size; ret =xc_acm_op (xc_handle, ACMOP_dumpstats, &dumpstats,sizeof (dumpstats));
Quoted 4 lines · Ian Campbell
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.
WRT solving (3) the approach which I am considering is to implement a new misc device (e.g. /dev/xen/hypercall). The device would support mmap which would provide suitably locked etc memory for use as a hypercall argument as well as supporting the existing IOCTL_PRIVCMD_HYPERCALL on /proc/xen/privcmd (deprecating that ioctl on privcmd).
There are a couple of reasons for the new device instead of extending the existing privcmd, firstly I think it's generally a more upstream friendly/acceptable interface and secondly privcmd already implements mmap as part 1 of the 2 part IOCTL_PRIVCMD_MMAP thing which makes retrofitting the desired new behaviour in a forwards/backwards compatible way a bit difficult.
It might also be nice to migrate IOCTL_PRIVCMD_MMAP* over (or a single generic interface subsuming them) to /dev/xen as well, either as part of this new device or a new /dev/xen/m(achine)mem or similar. This would allow deprecation of /proc/xen/privcmd entirely.
Opinions?
Ian.