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.
Changes since last time:
- rebased on top of recent cpupool changes, conflicts in xc_cpupool_getinfo and xc_cpupool_freeinfo.
PATCH 1/1 libxc: infrastructure for hypercall safe data buffers
# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1287742257 -3600
# Node ID 38e25ffde90ec62f659f08996a828ef24f0ee8fb # Parent 1f5676c9f1266d49a5fd1d8fdd84e60d7fe357a6
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
Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers
The following patch is needed before this one to fix build error in xc_hcall_buf.c when building with stub domains.
# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1288022053 -3600
# Node ID 53b519f53bc1471610ab1423e3c70288a6c867b5 # Parent 3b5c6d7181fecdf6c1043a35047632ddf9950343
minios: add parentheses to mlock/mulock arguments.
Fixes warning/build error with non-trivial arguments.
extras/mini-os/include/posix/sys/mman.h +2 -2
@@ -16,7 +16,7 @@void *mmap (void *start,size_t length,int prot,int flags,int fd,off_t offset) asm("mmap64" );int munmap (void *start,size_t length); -#define munlock (addr, len) ((void)addr, (void)len, 0) -#define mlock (addr, len) ((void)addr, (void)len, 0) +#define munlock (addr, len) ((void)(addr), (void)(len), 0) +#define mlock (addr, len) ((void)(addr), (void)(len), 0)#endif /* _POSIX_SYS_MMAN_H */
Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers
Ian Campbell writes ("[Xen-devel] Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers"):
Quoted 2 lines
The following patch is needed before this one to fix build error in
xc_hcall_buf.cwhen building with stub domains.
I've committed, this, and the following 25-patch series (with the revised version of 01/25).
Thanks,
Ian.
Re: Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers
Quoted 6 lines · Ian Jackson
Ian Campbell writes ("[Xen-devel] Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers"):
Quoted 2 lines
The following patch is needed before this one to fix build error in
xc_hcall_buf.cwhen building with stub domains.I've committed, this, and the following 25-patch series (with the revised version of 01/25).
Does that actually for anyone?
Rev 22285 worked, rev 22313 broke.
...
[2010-10-26 17:09:11 4743] INFO (SrvDaemon:332) Xend Daemon started
[2010-10-26 17:09:11 4743] ERROR (SrvDaemon:349) Exception starting xend ((14, 'Bad address')) Traceback (most recent call last):
File "/usr/lib64/python2.6/site-packages/xen/xend/server/SrvDaemon.py", line 335, in run
xinfo = xc.xeninfo()
Error: (14, 'Bad address')
[2010-10-26 17:09:11 4742] INFO (SrvDaemon:220) Xend exited with status 1.
...
Does this series require dom0 kernel changes by any chance?
Olaf
Re: Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers
Quoted 12 lines · Olaf Hering
Quoted 6 lines · Ian Jackson
Ian Campbell writes ("[Xen-devel] Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers"):
Quoted 2 lines
The following patch is needed before this one to fix build error in
xc_hcall_buf.cwhen building with stub domains.I've committed, this, and the following 25-patch series (with the revised version of 01/25).
Does that actually for anyone?
Rev 22285 worked, rev 22313 broke.
Quoted 9 lines
...
[2010-10-26 17:09:11 4743] INFO (SrvDaemon:332) Xend Daemon started
[2010-10-26 17:09:11 4743] ERROR (SrvDaemon:349) Exception starting xend ((14, 'Bad address')) Traceback (most recent call last):
File "/usr/lib64/python2.6/site-packages/xen/xend/server/SrvDaemon.py", line 335, in run
xinfo =xc.xeninfo()
Error: (14, 'Bad address')
[2010-10-26 17:09:11 4742] INFO (SrvDaemon:220) Xend exited with status 1.
...
hmm, I tested xend but trying it now myself I see that it is broken. I'll sort it out ASAP.
Quoted 1 line
Does this series require dom0 kernel changes by any chance?
it shouldn't.
Ian.
Re: Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers
Quoted 23 lines · Ian Campbell
Quoted 12 lines · Olaf Hering
Quoted 6 lines · Ian Jackson
Ian Campbell writes ("[Xen-devel] Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers"):
Quoted 2 lines
The following patch is needed before this one to fix build error in
xc_hcall_buf.cwhen building with stub domains.I've committed, this, and the following 25-patch series (with the revised version of 01/25).
Does that actually for anyone?
Rev 22285 worked, rev 22313 broke.Quoted 9 lines
...
[2010-10-26 17:09:11 4743] INFO (SrvDaemon:332) Xend Daemon started
[2010-10-26 17:09:11 4743] ERROR (SrvDaemon:349) Exception starting xend ((14, 'Bad address')) Traceback (most recent call last):
File "/usr/lib64/python2.6/site-packages/xen/xend/server/SrvDaemon.py", line 335, in run
xinfo =xc.xeninfo()
Error: (14, 'Bad address')
[2010-10-26 17:09:11 4742] INFO (SrvDaemon:220) Xend exited with status 1.
...
Quoted 2 lines
hmm, I tested xend but trying it now myself I see that it is broken. I'll sort it out ASAP.
ASAP won't be today now unfortunately.
Reverting 9fad5e5e2fc1 followed by ca4a781c8ae8 fixes the issue for me, with ca4a781c8ae8 more than likely being the actual culprit.
I'm sure I fixed something like this once before, must have rebroken it in a rebase or something.
Ian.
Quoted 12 lines
Quoted 2 lines
Does this series require dom0 kernel changes by any chance?
it shouldn't.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers
Quoted 1 line · Ian Campbell
ASAP won't be today now unfortunately.
Actually, maybe it will:
# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1288118755 -3600
# Node ID 630441a717dacd0764836386b63a5db8cd5d11dd # Parent cd193fa265b88bf4ff891f03c9be0e12415e6778
libxc: fix xc_version by handling all known command types.
xend was crashing since 22289:ca4a781c8ae8 due to missing handling of XENVER_commandline.
tools/libxc/xc_private.c +19 -1
@@ -447,11 +447,14 @@ int xc_version(xc_interface *xch, int cmint xc_version (xc_interface *xch,int cmd,void *arg) {DECLARE_HYPERCALL_BOUNCE (arg,0 ,XC_HYPERCALL_BUFFER_BOUNCE_OUT );/* Size unknown until cmd decoded */ -size_t sz =0 ; +size_t sz;int rc;switch ( cmd ) { +case XENVER_version: + sz =0 ; +break ;case XENVER_extraversion: sz =sizeof (xen_extraversion_t);break ;
@@ -467,6 +470,21 @@ int xc_version(xc_interface *xch, int cmcase XENVER_platform_parameters: sz =sizeof (xen_platform_parameters_t);break ; +case XENVER_get_features: + sz =sizeof (xen_feature_info_t); +break ; +case XENVER_pagesize: + sz =0 ; +break ; +case XENVER_guest_handle: + sz =sizeof (xen_domain_handle_t); +break ; +case XENVER_commandline: + sz =sizeof (xen_commandline_t); +break ; +default : +ERROR ("xc_version: unknown command %d\n" , cmd); +return -EINVAL ; }HYPERCALL_BOUNCE_SET_SIZE (arg, sz);
Olaf Hering
Tested-byRe: Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers
Quoted 12 lines · Ian Campbell
Quoted 1 line · Ian Campbell
ASAP won't be today now unfortunately.
Actually, maybe it will:
# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1288118755 -3600
# Node ID630441a717dacd0764836386b63a5db8cd5d11dd# Parentcd193fa265b88bf4ff891f03c9be0e12415e6778
libxc: fixxc_versionby handling all known command types.
Quoted 4 lines
xend was crashing since 22289:ca4a781c8ae8 due to missing handling of
XENVER_commandline.Signed-off-by Ian Campbell <[email protected]>
Thanks, that change helps.
Olaf
Ian Jackson
AppliedRe: Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers
In reply to Ian CampbellIan Campbell writes ("Re: [Xen-devel] Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers"):
Quoted 4 lines
libxc: fix
xc_versionby handling all known command types.xend was crashing since 22289:ca4a781c8ae8 due to missing handling of
XENVER_commandline.
Applied, thanks.
Ian.
Re: [PATCH 01 of 25] libxc: infrastructure for hypercall safe data buffers
In reply to Ian CampbellResending with updates #includes in xc_hcall_buf.c to fix stubdomain build.
# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1288022054 -3600
# Node ID 56ea205819916669ff0f78414a461d12c35606bc # Parent 53b519f53bc1471610ab1423e3c70288a6c867b5
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 +162 -0
162 lines not on this page · raw message
tools/libxc/xc_private.c +0 -2
@@ -18,13 +18,11 @@* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <inttypes.h> #include "xc_private.h" #include "xg_private.h" #include "xc_dom.h" #include <stdarg.h> #include <stdlib.h> -#include <malloc.h> #include <unistd.h> #include <pthread.h> #include <assert.h>
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 1287756891 -3600
# Node ID 5ebd5f2c9cea0c0b43fabe61545beeb8f3ddc908 # Parent 38e25ffde90ec62f659f08996a828ef24f0ee8fb
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 1287756891 -3600
# Node ID 76289f9bffff7f966e99ba6597321e2d655cc643 # Parent 5ebd5f2c9cea0c0b43fabe61545beeb8f3ddc908
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 1287756891 -3600
# Node ID 889ad17d10f98e3e2aed45bb04d2903328e97479
# Parent 76289f9bffff7f966e99ba6597321e2d655cc643
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
@@ -601,7 +601,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 1287756891 -3600
# Node ID a535e89658c09f6a491213e0f2373de775fbabb1 # Parent 889ad17d10f98e3e2aed45bb04d2903328e97479
libxc: convert sysctl interfaces over to hypercall buffers
tools/libxc/xc_cpupool.c +45 -45
@@ -73,12 +73,12 @@ xc_cpupoolinfo_t *xc_cpupool_getinfo(xc_ uint32_t poolid) {int err =0 ; -xc_cpupoolinfo_t *info; -uint8_t *local; +xc_cpupoolinfo_t *info =NULL ;int local_size;int cpumap_size;int size;DECLARE_SYSCTL ; +DECLARE_HYPERCALL_BUFFER (uint8_t, local); local_size =get_cpumap_size (xch);if (!local_size)
@@ -86,42 +86,42 @@ xc_cpupoolinfo_t *xc_cpupool_getinfo(xc_PERROR ("Could not get number of cpus" );return NULL ; } - local =alloca (local_size); + + local =xc_hypercall_buffer_alloc (xch, local, local_size); +if ( local ==NULL ) { +PERROR ("Could not allocate locked memory for xc_cpupool_getinfo" ); +return NULL ; + } + cpumap_size = (local_size +sizeof (*info->cpumap) -1 ) /sizeof (*info->cpumap); size =sizeof (xc_cpupoolinfo_t) + cpumap_size *sizeof (*info->cpumap); + + 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); + sysctl.u.cpupool_op.cpumap.nr_cpus = local_size *8 ; + + err =do_sysctl_save (xch, &sysctl); + +if ( err <0 ) + goto out; + info =malloc (size);if ( !info ) -return NULL ; + goto out;memset (info,0 , size); info->cpumap_size = local_size *8 ; info->cpumap = (uint64_t *)(info +1 ); - 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); - sysctl.u.cpupool_op.cpumap.nr_cpus = local_size *8 ; - -if ( (err =lock_pages (xch, local, local_size)) !=0 ) - { -PERROR ("Could not lock memory for Xen hypercall" ); -free (info); -return NULL ; - } - err =do_sysctl_save (xch, &sysctl); -unlock_pages (xch, local, local_size); - -if ( err <0 ) - { -free (info); -return NULL ; - } - info->cpupool_id = sysctl.u.cpupool_op.cpupool_id; info->sched_id = sysctl.u.cpupool_op.sched_id; info->n_dom = sysctl.u.cpupool_op.n_dom;bitmap_byte_to_64 (info->cpumap, local, local_size *8 ); + +out: +xc_hypercall_buffer_free (xch, local);return info; }
@@ -168,38 +168,38 @@ uint64_t * xc_cpupool_freeinfo(xc_interfuint64_t *xc_cpupool_freeinfo (xc_interface *xch,int *cpusize) { -int err; -uint8_t *local; -uint64_t *cpumap; +int err =-1 ; +uint64_t *cpumap =NULL ;DECLARE_SYSCTL ; +DECLARE_HYPERCALL_BUFFER (uint8_t, local); *cpusize =get_cpumap_size (xch);if (*cpusize ==0 )return NULL ; - local =alloca (*cpusize); - cpumap =calloc ((*cpusize +sizeof (*cpumap) -1 ) /sizeof (*cpumap),sizeof (*cpumap)); -if (cpumap ==NULL ) + + local =xc_hypercall_buffer_alloc (xch, local, *cpusize); +if ( local ==NULL ) { +PERROR ("Could not allocate locked memory for xc_cpupool_freeinfo" );return NULL ; + } 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 = *cpusize *8 ; -if ( (err =lock_pages (xch, local, *cpusize)) !=0 ) - { -PERROR ("Could not lock memory for Xen hypercall" ); -free (cpumap); -return NULL ; - } + err =do_sysctl_save (xch, &sysctl); - err =do_sysctl_save (xch, &sysctl); -unlock_pages (xch, local, *cpusize); +if ( err <0 ) + goto out; + + cpumap =calloc ((*cpusize +sizeof (*cpumap) -1 ) /sizeof (*cpumap),sizeof (*cpumap)); +if (cpumap ==NULL ) + goto out; +bitmap_byte_to_64 (cpumap, local, *cpusize *8 ); -if (err >=0 ) -return cpumap; - -free (cpumap); -return NULL ; +out: +xc_hypercall_buffer_free (xch, local); +return cpumap; }
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 1287756891 -3600
# Node ID ae3069299aaee8067deb74fe678029c29eb15717 # Parent a535e89658c09f6a491213e0f2373de775fbabb1
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 1287756891 -3600
# Node ID 64abd5a41eed626a677ec79ff9728ddd68b824d9 # Parent ae3069299aaee8067deb74fe678029c29eb15717
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 1287756891 -3600
# Node ID 0ddcbfd4824fe9c44c4f98f9a4e9cf02e869c290 # Parent 64abd5a41eed626a677ec79ff9728ddd68b824d9
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 1287756891 -3600
# Node ID 13eb390743e77d302151bb2c53a333626997194c # Parent 0ddcbfd4824fe9c44c4f98f9a4e9cf02e869c290
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 1287756891 -3600
# Node ID d6d85046e71462902f8ac32a9a5bf90cd2d1e14a # Parent 13eb390743e77d302151bb2c53a333626997194c
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 1287756891 -3600
# Node ID f30814a875717258b94df571cfacce949ca37a50 # Parent d6d85046e71462902f8ac32a9a5bf90cd2d1e14a
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 1287756891 -3600
# Node ID 36df3e4c37de798250bd45b24f4d13197b627aac # Parent f30814a875717258b94df571cfacce949ca37a50
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 1287756891 -3600
# Node ID 441891ba02392f7ac7ca215569eab45023b8c9cc # Parent 36df3e4c37de798250bd45b24f4d13197b627aac
libxc: convert mca interface over to hypercall buffers
tools/libxc/xc_misc.c +8 -7
@@ -167,18 +167,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 1287756891 -3600
# Node ID f9d7420fae6d3f4a324cd783ab56ea5a158cf664 # Parent 441891ba02392f7ac7ca215569eab45023b8c9cc
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 1287756891 -3600
# Node ID ba4bc1c93fee7072c32d8a0a1aef61d6fb50e757 # Parent f9d7420fae6d3f4a324cd783ab56ea5a158cf664
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 1287756891 -3600
# Node ID 63c5a929ae7ca0c82406e0cd33f95c82f219d59f # Parent ba4bc1c93fee7072c32d8a0a1aef61d6fb50e757
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 1287756891 -3600
# Node ID 571e4fd050f7ae7cad9a94c94f9be79acf55710d # Parent 63c5a929ae7ca0c82406e0cd33f95c82f219d59f
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 1287756891 -3600
# Node ID 6624f76887ab0672598d99d4ab5a37815d5b4aa3 # Parent 571e4fd050f7ae7cad9a94c94f9be79acf55710d
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 1287756891 -3600
# Node ID cfab497ee5a0c8ea0ed6b136c4d10f21c921eac0 # Parent 6624f76887ab0672598d99d4ab5a37815d5b4aa3
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 1287756891 -3600
# Node ID 84dc04924708cd8e7fff48312a436fbbd0c79456 # Parent cfab497ee5a0c8ea0ed6b136c4d10f21c921eac0 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 1287756891 -3600
# Node ID 5daeac9c13b0d728d93e9e30b53bb70bd5e81ee2 # Parent 84dc04924708cd8e7fff48312a436fbbd0c79456 python xc: use hypercall buffer interface.
tools/python/xen/lowlevel/xc/xc.c +49 -21
@@ -1203,19 +1203,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 )
@@ -1268,11 +1278,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 }
@@ -1282,20 +1296,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 )
@@ -1360,8 +1384,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 1287756891 -3600
# Node ID de7310bdfe91d9356d5c6fca92daa93f07ab4fb5 # Parent 5daeac9c13b0d728d93e9e30b53bb70bd5e81ee2
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 1287756891 -3600
# Node ID 02dca31076126f4a0334881eb9a9980fd188cf25 # Parent de7310bdfe91d9356d5c6fca92daa93f07ab4fb5
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 1287756891 -3600
# Node ID 5d4e169f1ef0cc1ec40855f42443752b2c29093c # Parent 02dca31076126f4a0334881eb9a9980fd188cf25
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 1287756891 -3600
# Node ID d3f52cd04d85a3d3e1a69b658e736722b14e243c # Parent 5d4e169f1ef0cc1ec40855f42443752b2c29093c
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
@@ -99,7 +99,7 @@ xc_cpupoolinfo_t *xc_cpupool_getinfo(xc_ 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 = local_size *8 ; err =do_sysctl_save (xch, &sysctl);
@@ -185,7 +185,7 @@ uint64_t * xc_cpupool_freeinfo(xc_interf 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 = *cpusize *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
@@ -49,7 +49,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 ;
@@ -81,7 +81,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);
@@ -190,8 +190,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); }
@@ -205,8 +205,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);
@@ -228,8 +228,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); }
@@ -240,7 +240,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); }
@@ -253,7 +253,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);
@@ -274,7 +274,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);
@@ -295,7 +295,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);
@@ -427,7 +427,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
@@ -1219,9 +1219,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 )
@@ -1313,9 +1313,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));
Ian,
is the usage like shown below ok, adding an offset +start to the initial buffer?
Olaf
tools/libxc/xc_domain.c +60 -30
@@ -572,6 +572,55 @@ int xc_domain_get_tsc_info(xc_interfacereturn rc; } +static int do_xenmem_op_retry (xc_interface *xch,int cmd,struct xen_memory_reservation *reservation,size_t len,unsigned long nr_extents,xen_pfn_t *extent_start) +{ +xen_pfn_t *es = extent_start; +DECLARE_HYPERCALL_BOUNCE (es, nr_extents *sizeof (*es),XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); +int err =0 ; +unsigned long count = nr_extents; +unsigned long delay =0 ; +unsigned long start =0 ; + +fprintf (stderr,"%s: %d count %lx\n" ,__func__,cmd,count); + +if (xc_hypercall_bounce_pre (xch, es) ) + { +PERROR ("Could not bounce memory for XENMEM_* hypercall" ); +return -1 ; + } + +while ( start < nr_extents ) + { + es = extent_start + start; +set_xen_guest_handle (reservation->extent_start, es); + reservation->nr_extents = count; + + err =do_memory_op (xch, cmd, reservation, len); +if ( err == count ) +break ; + +if ( err > count || err <0 ) +break ; + +if ( delay >1000 *1000 ) + { + err = start; +break ; + } + +if ( err ) + delay =0 ; + + start += err; + count -= err; +usleep (delay); + delay +=666 ;/* 1500 iterations, 12 seconds */ + } +fprintf (stderr,"%s: %d err %x count %lx start %lx delay %lu/%lu\n" ,__func__,cmd,err,count,start,delay,delay/666 ); + +xc_hypercall_bounce_post (xch, es); +return err; +}int xc_domain_maximum_gpfn (xc_interface *xch,domid_t domid) {
@@ -643,10 +692,7 @@ int xc_domain_decrease_reservation(xc_in unsigned int extent_order, 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
@@ -659,18 +705,7 @@ int xc_domain_decrease_reservation(xc_inreturn -1 ; } -if (xc_hypercall_bounce_pre (xch, extent_start) ) - { -PERROR ("Could not bounce memory for XENMEM_decrease_reservation hypercall" ); -return -1 ; - } -set_xen_guest_handle (reservation.extent_start, extent_start); - - err =do_memory_op (xch, XENMEM_decrease_reservation, &reservation,sizeof (reservation)); - -xc_hypercall_bounce_post (xch, extent_start); - -return err; +return do_xenmem_op_retry (xch, XENMEM_decrease_reservation, &reservation,sizeof (reservation), nr_extents, extent_start); } int xc_domain_decrease_reservation_exact(xc_interface *xch,
@@ -704,13 +739,20 @@ int xc_domain_add_to_physmap(xc_interfacunsigned long idx, xen_pfn_t gpfn) { + uint8_t delay = 0; +int rc;struct xen_add_to_physmap xatp = { .domid = domid, .space = space, .idx = idx, .gpfn = gpfn, }; -return do_memory_op (xch, XENMEM_add_to_physmap, &xatp,sizeof (xatp)); +do { + rc =do_memory_op (xch, XENMEM_add_to_physmap, &xatp,sizeof (xatp)); +if ( rc <0 && errno ==ENOENT ) +usleep (1000 ); + }while ( rc <0 && errno ==ENOENT && ++delay ); +return rc; } int xc_domain_populate_physmap(xc_interface *xch,
@@ -720,26 +762,13 @@ int xc_domain_populate_physmap(xc_interfunsigned int mem_flags, 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 = mem_flags, .domid = domid }; -if (xc_hypercall_bounce_pre (xch, extent_start) ) - { -PERROR ("Could not bounce memory for XENMEM_populate_physmap hypercall" ); -return -1 ; - } -set_xen_guest_handle (reservation.extent_start, extent_start); - - err =do_memory_op (xch, XENMEM_populate_physmap, &reservation,sizeof (reservation)); - -xc_hypercall_bounce_post (xch, extent_start); -return err; +return do_xenmem_op_retry (xch, XENMEM_populate_physmap, &reservation,sizeof (reservation), nr_extents, extent_start); } int xc_domain_populate_physmap_exact(xc_interface *xch,
@@ -799,6 +828,7 @@ int xc_domain_memory_exchange_pages(xc_iset_xen_guest_handle (exchange.in.extent_start, in_extents);set_xen_guest_handle (exchange.out.extent_start, out_extents); +/* FIXME use do_xenmem_op_retry or some retry loop??? */ rc =do_memory_op (xch, XENMEM_exchange, &exchange,sizeof (exchange)); out:
Quoted 4 lines · Olaf Hering
Ian,
is the usage like shown below ok, adding an offset +start to the initial buffer?
Unfortunately I think you need to extend the infrastructure to make it work.
es is a pointer to the unbounced buffer so you can't just take offsets from it etc.
I think you need to add a set_xen_guest_handle_offset used as
set_xen_guest_handle_offset(reservation->extent_start, es, start)
or whatever. (I think this actually makes es useless so you can bounce extent_start directly and use extent_start directly).
Ian.
Quoted 149 lines
Olaf
tools/libxc/xc_domain.c +60
-30@@ -572,6 +572,55 @@ int xc_domain_get_tsc_info(xc_interfacereturn rc; } +static int do_xenmem_op_retry (xc_interface *xch,int cmd,struct xen_memory_reservation *reservation,size_t len,unsigned long nr_extents,xen_pfn_t *extent_start) +{ +xen_pfn_t *es = extent_start; +DECLARE_HYPERCALL_BOUNCE (es, nr_extents *sizeof (*es),XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); +int err =0 ; +unsigned long count = nr_extents; +unsigned long delay =0 ; +unsigned long start =0 ; + +fprintf (stderr,"%s: %d count %lx\n" ,__func__,cmd,count); + +if (xc_hypercall_bounce_pre (xch, es) ) + { +PERROR ("Could not bounce memory for XENMEM_* hypercall" ); +return -1 ; + } + +while ( start < nr_extents ) + { + es = extent_start + start; +set_xen_guest_handle (reservation->extent_start, es); + reservation->nr_extents = count; + + err =do_memory_op (xch, cmd, reservation, len); +if ( err == count ) +break ; + +if ( err > count || err <0 ) +break ; + +if ( delay >1000 *1000 ) + { + err = start; +break ; + } + +if ( err ) + delay =0 ; + + start += err; + count -= err; +usleep (delay); + delay +=666 ;/* 1500 iterations, 12 seconds */ + } +fprintf (stderr,"%s: %d err %x count %lx start %lx delay %lu/%lu\n" ,__func__,cmd,err,count,start,delay,delay/666 ); + +xc_hypercall_bounce_post (xch, es); +return err; +}int xc_domain_maximum_gpfn (xc_interface *xch,domid_t domid) {@@ -643,10 +692,7 @@ int xc_domain_decrease_reservation(xc_in unsigned int extent_order, 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@@ -659,18 +705,7 @@ int xc_domain_decrease_reservation(xc_inreturn -1 ; } -if (xc_hypercall_bounce_pre (xch, extent_start) ) - { -PERROR ("Could not bounce memory for XENMEM_decrease_reservation hypercall" ); -return -1 ; - } -set_xen_guest_handle (reservation.extent_start, extent_start); - - err =do_memory_op (xch, XENMEM_decrease_reservation, &reservation,sizeof (reservation)); - -xc_hypercall_bounce_post (xch, extent_start); - -return err; +return do_xenmem_op_retry (xch, XENMEM_decrease_reservation, &reservation,sizeof (reservation), nr_extents, extent_start); } int xc_domain_decrease_reservation_exact(xc_interface *xch,@@ -704,13 +739,20 @@ int xc_domain_add_to_physmap(xc_interfacunsigned long idx, xen_pfn_t gpfn) { + uint8_t delay = 0; +int rc;struct xen_add_to_physmap xatp = { .domid = domid, .space = space, .idx = idx, .gpfn = gpfn, }; -return do_memory_op (xch, XENMEM_add_to_physmap, &xatp,sizeof (xatp)); +do { + rc =do_memory_op (xch, XENMEM_add_to_physmap, &xatp,sizeof (xatp)); +if ( rc <0 && errno ==ENOENT ) +usleep (1000 ); + }while ( rc <0 && errno ==ENOENT && ++delay ); +return rc; } int xc_domain_populate_physmap(xc_interface *xch,@@ -720,26 +762,13 @@ int xc_domain_populate_physmap(xc_interfunsigned int mem_flags, 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 = mem_flags, .domid = domid }; -if (xc_hypercall_bounce_pre (xch, extent_start) ) - { -PERROR ("Could not bounce memory for XENMEM_populate_physmap hypercall" ); -return -1 ; - } -set_xen_guest_handle (reservation.extent_start, extent_start); - - err =do_memory_op (xch, XENMEM_populate_physmap, &reservation,sizeof (reservation)); - -xc_hypercall_bounce_post (xch, extent_start); -return err; +return do_xenmem_op_retry (xch, XENMEM_populate_physmap, &reservation,sizeof (reservation), nr_extents, extent_start); } int xc_domain_populate_physmap_exact(xc_interface *xch,@@ -799,6 +828,7 @@ int xc_domain_memory_exchange_pages(xc_iset_xen_guest_handle (exchange.in.extent_start, in_extents);set_xen_guest_handle (exchange.out.extent_start, out_extents); +/* FIXME use do_xenmem_op_retry or some retry loop??? */ rc =do_memory_op (xch, XENMEM_exchange, &exchange,sizeof (exchange)); out:
Quoted 8 lines · Ian Campbell
Quoted 4 lines · Olaf Hering
Ian,
is the usage like shown below ok, adding an offset +start to the initial buffer?
Unfortunately I think you need to extend the infrastructure to make it work.
This should work as well, using existing code:
err = do_memory_op(xch, cmd | (start << MEMOP_EXTENT_SHIFT), reservation, len);
Olaf
Quoted 8 lines · Olaf Hering
Quoted 6 lines · Ian Campbell
Quoted 4 lines · Olaf Hering
Ian,
is the usage like shown below ok, adding an offset +start to the initial buffer?
Quoted 6 lines
Quoted 2 lines
Unfortunately I think you need to extend the infrastructure to make it work.
This should work as well, using existing code:
err =
do_memory_op(xch, cmd | (start << MEMOP_EXTENT_SHIFT), reservation, len);
That would be preferable then, I think (without having seen the entire patch).
Ian.