libxc: Misc improvements
cover libxc: Misc improvements
Misc improvements for libxc, which are prerequisites for the migration v2 series, but not directly related to it. Some of these patches have been posted to the list singally before; Their submission here superceeds any previous submission.
Andrew Cooper (5):
tools/libxc: Annotate xc_report_error with __attribute__((format)) tools/libxc: Annotate xc_osdep_log with __attribute__((format)) tools/libxc: Use _Static_assert if available tools/libxc: Introduce ARRAY_SIZE() and replace handrolled examples tools/libxc: Add Valgrind client requests as a debugging option
David Vrabel (1):
tools/libxc: add DECLARE_HYPERCALL_BUFFER_SHADOW()
tools/libxc/xc_core.c | 2 +- tools/libxc/xc_dom_arm.c | 2 +- tools/libxc/xc_dom_x86.c | 4 ++-- tools/libxc/xc_domain_restore.c | 6 +++--- tools/libxc/xc_gnttab.c | 2 +- tools/libxc/xc_minios.c | 2 +- tools/libxc/xc_private.h | 16 +++++++++++++++- tools/libxc/xenctrl.h | 18 ++++++++++++++++++ tools/libxc/xenctrl_osdep_ENOSYS.c | 32 ++++++++++++++++---------------- tools/libxc/xenctrlosdep.h | 3 ++- 10 files changed, 60 insertions(+), 27 deletions(-)
Signature · 1 line
1.7.10.4
PATCH 1/6 tools/libxc: Annotate xc_report_error with __attribute__((format))
This helps the compiler spot printf formatting errors.
Fix up all errors discovered.
---
v2: Fix up %zd for ssize_t and %PRIx32 for QEMU Magic
--- tools/libxc/xc_core.c | 2 +- tools/libxc/xc_domain_restore.c | 6 +++--- tools/libxc/xc_gnttab.c | 2 +- tools/libxc/xc_private.h | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-)
tools/libxc/xc_core.c +1 -1
@@ -497,7 +497,7 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, ctxt =calloc (sizeof (*ctxt), info.max_vcpu_id +1 );if ( !ctxt ) { -PERROR ("Could not allocate vcpu context array" , domid); +PERROR ("Could not allocate vcpu context array" ); goto out; }
tools/libxc/xc_domain_restore.c +3 -3
@@ -102,7 +102,7 @@ static ssize_t rdexact(xc_interface *xch, struct restore_ctx *ctx, errno =0 ; }if ( len <=0 ) { -ERROR ("%s failed (read rc: %d, errno: %d)" , __func__, len, errno); +ERROR ("%s failed (read rc: %zd, errno: %d)" , __func__, len, errno);return -1 ; } offset += len;
@@ -443,7 +443,7 @@ static int compat_buffer_qemu(xc_interface *xch, struct restore_ctx *ctx, }if (memcmp (qbuf,"QEVM" ,4 ) ) { -ERROR ("Invalid QEMU magic: 0x%08x" , *(unsigned long *)qbuf); +ERROR ("Invalid QEMU magic: 0x%08" PRIx32, *(uint32_t *)qbuf);free (qbuf);return -1 ; }
@@ -1802,7 +1802,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, }else if (pagebuf.acpi_ioport_location ==0 ) {DBGPRINTF ("Use old firmware ioport from the checkpoint\n" ); }else { -ERROR ("Error, unknow acpi ioport location (%i)" , pagebuf.acpi_ioport_location); +ERROR ("Error, unknow acpi ioport location (%" PRId64")" , pagebuf.acpi_ioport_location); } tdatatmp = tdata;
tools/libxc/xc_gnttab.c +1 -1
@@ -75,7 +75,7 @@ static void *_gnttab_map_table(xc_interface *xch, int domid, int *gnt_num)if ( rc || (query.status != GNTST_okay) ) { -ERROR ("Could not query dom's grant size\n" , domid); +ERROR ("Could not query dom%d's grant size\n" , domid);return NULL ; }
tools/libxc/xc_private.h +2 -1
@@ -93,7 +93,8 @@ struct xc_interface_core {xc_osdep_handle ops_handle;/* opaque data for xc_osdep_ops */ }; -void xc_report_error (xc_interface *xch,int code,const char *fmt, ...); +void xc_report_error (xc_interface *xch,int code,const char *fmt, ...) + __attribute__((format (printf,3 ,4 )));void xc_reportv (xc_interface *xch,xentoollog_logger *lg,xentoollog_level ,int code,const char *fmt,va_list args) __attribute__((format (printf,5 ,0 )));
Signature · 1 line
1.7.10.4
PATCH 2/6 tools/libxc: Annotate xc_osdep_log with __attribute__((format))
In reply to Andrew CooperThis helps the compiler spot printf formatting errors.
Fix up resulting errors in xenctrl_osdep_ENOSYS.c. Substitute %p for the slightly less bad %lx when trying to format an opaque structure.
---
v2: %p -> %lx
--- tools/libxc/xenctrl_osdep_ENOSYS.c | 32 ++++++++++++++++---------------- tools/libxc/xenctrlosdep.h | 3 ++- 2 files changed, 18 insertions(+), 17 deletions(-)
tools/libxc/xenctrl_osdep_ENOSYS.c +16 -16
@@ -15,19 +15,19 @@static xc_osdep_handle ENOSYS_privcmd_open (xc_interface *xch) { -IPRINTF (xch,"ENOSYS_privcmd: opening handle %p\n" , (void *)1 ); +IPRINTF (xch,"ENOSYS_privcmd: opening handle %d\n" ,1 );return (xc_osdep_handle )1 ;/*dummy*/ }static int ENOSYS_privcmd_close (xc_interface *xch,xc_osdep_handle h) { -IPRINTF (xch,"ENOSYS_privcmd: closing handle %p\n" , h); +IPRINTF (xch,"ENOSYS_privcmd: closing handle %lx\n" , h);return 0 ; }static int ENOSYS_privcmd_hypercall (xc_interface *xch,xc_osdep_handle h,privcmd_hypercall_t *hypercall) { -IPRINTF (xch,"ENOSYS_privcmd %p: hypercall: %02lld(%#llx,%#llx,%#llx,%#llx,%#llx)\n" , +IPRINTF (xch,"ENOSYS_privcmd %lx: hypercall: %02lld(%#llx,%#llx,%#llx,%#llx,%#llx)\n" , h, hypercall->op, hypercall->arg[0 ], hypercall->arg[1 ], hypercall->arg[2 ], hypercall->arg[3 ], hypercall->arg[4 ]);
@@ -37,21 +37,21 @@ static int ENOSYS_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmstatic void *ENOSYS_privcmd_map_foreign_batch (xc_interface *xch,xc_osdep_handle h,uint32_t dom,int prot,xen_pfn_t *arr,int num) { -IPRINTF (xch,"ENOSYS_privcmd %p: map_foreign_batch: dom%d prot %#x arr %p num %d\n" , h, dom, prot, arr, num); +IPRINTF (xch,"ENOSYS_privcmd %lx: map_foreign_batch: dom%d prot %#x arr %p num %d\n" , h, dom, prot, arr, num);return MAP_FAILED ; }static void *ENOSYS_privcmd_map_foreign_bulk (xc_interface *xch,xc_osdep_handle h,uint32_t dom,int prot,const xen_pfn_t *arr,int *err,unsigned int num) { -IPRINTF (xch,"ENOSYS_privcmd %p: map_foreign_buld: dom%d prot %#x arr %p err %p num %d\n" , h, dom, prot, arr, err, num); +IPRINTF (xch,"ENOSYS_privcmd %lx map_foreign_buld: dom%d prot %#x arr %p err %p num %d\n" , h, dom, prot, arr, err, num);return MAP_FAILED ; }static void *ENOSYS_privcmd_map_foreign_range (xc_interface *xch,xc_osdep_handle h,uint32_t dom,int size,int prot,unsigned long mfn) { -IPRINTF (xch,"ENOSYS_privcmd %p: map_foreign_range: dom%d size %#x prot %#x mfn %ld\n" , h, dom, size, prot, mfn); +IPRINTF (xch,"ENOSYS_privcmd %lx map_foreign_range: dom%d size %#x prot %#x mfn %ld\n" , h, dom, size, prot, mfn);return MAP_FAILED ; }
@@ -59,7 +59,7 @@ static void *ENOSYS_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handl size_t chunksize, privcmd_mmap_entry_t entries[], int nentries) { - IPRINTF(xch, "ENOSYS_privcmd %p: map_foreign_ranges: dom%d size %zd prot %#x chunksize %zd entries %p num %d\n", h, dom, size, prot, chunksize, entries, nentries); + IPRINTF(xch, "ENOSYS_privcmd %lx map_foreign_ranges: dom%d size %zd prot %#x chunksize %zd entries %p num %d\n", h, dom, size, prot, chunksize, entries, nentries);return MAP_FAILED ; }
@@ -85,59 +85,59 @@ static xc_osdep_handle ENOSYS_evtchn_open(xc_interface *xce)static int ENOSYS_evtchn_close (xc_interface *xce,xc_osdep_handle h) { -IPRINTF (xce,"ENOSYS_evtchn: closing handle %p\n" , h); +IPRINTF (xce,"ENOSYS_evtchn: closing handle %lx\n" , h);return 0 ; }static int ENOSYS_evtchn_fd (xc_interface *xce,xc_osdep_handle h) { -IPRINTF (xce,"ENOSYS_fd %p: fd\n" , h); +IPRINTF (xce,"ENOSYS_fd %lx fd\n" , h);return (int )h; }static int ENOSYS_evtchn_notify (xc_interface *xce,xc_osdep_handle h,evtchn_port_t port) { -IPRINTF (xce,"ENOSYS_evtchn %p: notify: %d\n" , h, port); +IPRINTF (xce,"ENOSYS_evtchn %lx notify: %d\n" , h, port);return -ENOSYS ; }static int ENOSYS_evtchn_bind_unbound_port (xc_interface *xce,xc_osdep_handle h,int domid) { -IPRINTF (xce,"ENOSYS_evtchn %p: bind_unbound_port: dom%d\n" , h, domid); +IPRINTF (xce,"ENOSYS_evtchn %lx bind_unbound_port: dom%d\n" , h, domid);return -ENOSYS ; }static int ENOSYS_evtchn_bind_interdomain (xc_interface *xce,xc_osdep_handle h,int domid,evtchn_port_t remote_port) { -IPRINTF (xce,"ENOSYS_evtchn %p: bind_interdomain: dmo%d %d\n" , h, domid, remote_port); +IPRINTF (xce,"ENOSYS_evtchn %lx bind_interdomain: dmo%d %d\n" , h, domid, remote_port);return -ENOSYS ; }static int ENOSYS_evtchn_bind_virq (xc_interface *xce,xc_osdep_handle h,unsigned int virq) { -IPRINTF (xce,"ENOSYS_evtchn %p: bind_virq: %d\n" , h, virq); +IPRINTF (xce,"ENOSYS_evtchn %lx bind_virq: %d\n" , h, virq);return -ENOSYS ; }static int ENOSYS_evtchn_unbind (xc_interface *xce,xc_osdep_handle h,evtchn_port_t port) { -IPRINTF (xce,"ENOSYS_evtchn %p: unbind: %d\n" , h, port); +IPRINTF (xce,"ENOSYS_evtchn %lx unbind: %d\n" , h, port);return -ENOSYS ; }static evtchn_port_or_error_t ENOSYS_evtchn_pending (xc_interface *xce,xc_osdep_handle h) { -IPRINTF (xce,"ENOSYS_evtchn %p: pending\n" , h); +IPRINTF (xce,"ENOSYS_evtchn %lx pending\n" , h);return -ENOSYS ; }static int ENOSYS_evtchn_unmask (xc_interface *xce,xc_osdep_handle h,evtchn_port_t port) { -IPRINTF (xce,"ENOSYS_evtchn %p: unmask: %d\n" , h, port); +IPRINTF (xce,"ENOSYS_evtchn %lx unmask: %d\n" , h, port);return -ENOSYS ; }
tools/libxc/xenctrlosdep.h +2 -1
@@ -157,7 +157,8 @@ void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h, const xen_pfn_t *arr, int *err, unsigned int num);/* Report errors through xc_interface */ -void xc_osdep_log (xc_interface *xch,xentoollog_level level,int code,const char *fmt, ...); +void xc_osdep_log (xc_interface *xch,xentoollog_level level,int code, +const char *fmt, ...) __attribute__((format (printf,4 ,5 )));#endif
Signature · 1 line
1.7.10.4
PATCH 3/6 tools/libxc: Use _Static_assert if available
In reply to Andrew Cooper--- tools/libxc/xc_private.h | 4 ++++ 1 file changed, 4 insertions(+)
tools/libxc/xc_private.h +4 -0
@@ -48,7 +48,11 @@#define PAGE_MASK XC_PAGE_MASK/* Force a compilation error if condition is true */ +#if __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=6 ) +#define XC_BUILD_BUG_ON (p) ({ _Static_assert(!(p), "!(" #p ")"); }) +#else #define XC_BUILD_BUG_ON (p) ((void)sizeof(struct { int:-!!(p); })) +#endif /* ** Define max dirty page cache to permit during save/restore -- need to balance
Signature · 1 line
1.7.10.4
PATCH 4/6 tools/libxc: Introduce ARRAY_SIZE() and replace handrolled examples
In reply to Andrew Cooper--- tools/libxc/xc_dom_arm.c | 2 +- tools/libxc/xc_dom_x86.c | 4 ++-- tools/libxc/xc_minios.c | 2 +- tools/libxc/xc_private.h | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-)
tools/libxc/xc_dom_arm.c +1 -1
@@ -230,7 +230,7 @@ static int set_mode(xc_interface *xch, domid_t domid, char *guest_type) domctl.domain = domid; domctl.cmd = XEN_DOMCTL_set_address_size; -for ( i =0 ; i <sizeof (types)/sizeof (types[0 ]); i++ ) +for ( i =0 ; i <ARRAY_SIZE (types); i++ )if ( !strcmp (types[i].guest, guest_type) ) domctl.u.address_size.size = types[i].size;if ( domctl.u.address_size.size ==0 )
tools/libxc/xc_dom_x86.c +2 -2
@@ -716,7 +716,7 @@ static int x86_compat(xc_interface *xch, domid_t domid, char *guest_type)memset (&domctl,0 ,sizeof (domctl)); domctl.domain = domid; domctl.cmd = XEN_DOMCTL_set_address_size; -for ( i =0 ; i <sizeof (types)/sizeof (types[0 ]); i++ ) +for ( i =0 ; i <ARRAY_SIZE (types); i++ )if ( !strcmp (types[i].guest, guest_type) ) domctl.u.address_size.size = types[i].size;if ( domctl.u.address_size.size ==0 )
@@ -887,7 +887,7 @@ int arch_setup_bootlate(struct xc_dom_image *dom)xen_pfn_t shinfo;int i, rc; -for ( i =0 ; i <sizeof (types) /sizeof (types[0 ]); i++ ) +for ( i =0 ; i <ARRAY_SIZE (types); i++ )if ( !strcmp (types[i].guest, dom->guest_type) ) pgd_type = types[i].pgd_type;
tools/libxc/xc_minios.c +1 -1
@@ -87,7 +87,7 @@ static int minios_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmint i, ret; call.op = hypercall->op; -for (i =0 ; i <sizeof (hypercall->arg) /sizeof (*hypercall->arg); i++) +for (i =0 ; i <ARRAY_SIZE (hypercall->arg); i++) call.args[i] = hypercall->arg[i]; ret =HYPERVISOR_multicall (&call,1 );
tools/libxc/xc_private.h +2 -0
@@ -54,6 +54,8 @@#define XC_BUILD_BUG_ON (p) ((void)sizeof(struct { int:-!!(p); }))#endif +#define ARRAY_SIZE (a) (sizeof(a) / sizeof(a[0])) +/* ** Define max dirty page cache to permit during save/restore -- need to balance ** keeping cache usage down with CPU impact of invalidating too often.
Signature · 1 line
1.7.10.4
PATCH 5/6 tools/libxc: add DECLARE_HYPERCALL_BUFFER_SHADOW()
In reply to Andrew CooperFrom: David Vrabel <[email protected]>
DECLARE_HYPERCALL_BUFFER_SHADOW() is like DECLARE_HYPERCALL_BUFFER() except it is backed by an already allocated hypercall buffer.
--- tools/libxc/xenctrl.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
tools/libxc/xenctrl.h +18 -0
@@ -266,6 +266,24 @@ typedef struct xc_hypercall_buffer xc_hypercall_buffer_t; }/* +* Like DECLARE_HYPERCALL_BUFFER() but using an already allocated +* hypercall buffer, _hbuf. +* +* Useful when a hypercall buffer is passed to a function and access +* via the user pointer is required. +* +* See DECLARE_HYPERCALL_BUFFER_ARGUMENT() if the user pointer is not +* required. +*/ +#define DECLARE_HYPERCALL_BUFFER_SHADOW (_type, _name, _hbuf) \ + _type *_name = _hbuf->hbuf; \ + xc_hypercall_buffer_t XC__HYPERCALL_BUFFER_NAME(_name) = { \ + .hbuf = (void *)-1, \ + .param_shadow = _hbuf, \ + HYPERCALL_BUFFER_INIT_NO_BOUNCE \ + } + +/* * Declare the necessary data structure to allow a hypercall buffer * passed as an argument to a function to be used in the normal way. */
Signature · 1 line
1.7.10.4
PATCH 6/6 tools/libxc: Add Valgrind client requests as a debugging option
In reply to Andrew Cooperhttp://valgrind.org/docs/manual/mc-manual.html#mc-manual.clientreqs
---
The client requests are safe to compile in even when not running the binary under valgrind. For simplicitly, it might just be easiest to unconditionally enable client requests for debug builds if autoconf determines that <valgrind/memcheck.h> exists.
Thoughts?
--- tools/libxc/xc_private.h | 7 +++++++ 1 file changed, 7 insertions(+)
tools/libxc/xc_private.h +7 -0
@@ -34,6 +34,13 @@#include <xen/sys/privcmd.h> +/* Compile in Valgrind client requests ? */ +#ifdef VALGRIND +#include <valgrind/memcheck.h> +#else +#define VALGRIND_MAKE_MEM_UNDEFINED (addr, len) (void)/* addr, len */ +#endif +#define DECLARE_HYPERCALL privcmd_hypercall_t hypercall#define DECLARE_DOMCTL struct xen_domctl domctl#define DECLARE_SYSCTL struct xen_sysctl sysctl
Signature · 1 line
1.7.10.4