WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Make it possible to run valgrind on code linked with the

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Make it possible to run valgrind on code linked with the libxc libraries.
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 22 Nov 2005 18:20:06 +0000
Delivery-date: Tue, 22 Nov 2005 18:20:14 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID 602aefe7bd48f801b703bc423f148b7a14645fa4
# Parent  c1c8da6f2afece83a6f8f6aaa02c95d80bba2761
Make it possible to run valgrind on code linked with the libxc libraries.
Valgrind cannot see when a hypercall has initialised entries in a data
structure, so appropriate memsets have been placed before using dom0_op_t,
privcmd_hypercall_t, and a couple of miscellaneous blocks passed into this
layer.  This initialises the block so that valgrind considers it to be valid,
but the data therein will be immediately overwritten by the hypercall, all
being well.

These changes are semantically neutral if -DVALGRIND is not set.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/Makefile
--- a/tools/libxc/Makefile      Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/Makefile      Tue Nov 22 15:31:16 2005
@@ -49,6 +49,11 @@
 CFLAGS   += -O3
 CFLAGS   += -fno-strict-aliasing
 CFLAGS   += $(INCLUDES) -I.
+
+# Define this to make it possible to run valgrind on code linked with these
+# libraries.
+#CFLAGS   += -DVALGRIND -O0 -ggdb3
+
 # Get gcc to generate the dependencies for us.
 CFLAGS   += -Wp,-MD,.$(@F).d
 LDFLAGS  += -L.
diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xc_bvtsched.c
--- a/tools/libxc/xc_bvtsched.c Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/xc_bvtsched.c Tue Nov 22 15:31:16 2005
@@ -11,7 +11,7 @@
 int xc_bvtsched_global_set(int xc_handle,
                            unsigned long ctx_allow)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
 
     op.cmd = DOM0_SCHEDCTL;
     op.u.schedctl.sched_id = SCHED_BVT;
@@ -24,7 +24,7 @@
 int xc_bvtsched_global_get(int xc_handle,
                            unsigned long *ctx_allow)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     int ret;
     
     op.cmd = DOM0_SCHEDCTL;
@@ -46,7 +46,7 @@
                            long long warpl,
                            long long warpu)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     struct bvt_adjdom *bvtadj = &op.u.adjustdom.u.bvt;
 
     op.cmd = DOM0_ADJUSTDOM;
@@ -72,7 +72,7 @@
                            long long *warpu)
 {
     
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     int ret;
     struct bvt_adjdom *adjptr = &op.u.adjustdom.u.bvt;
 
diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xc_domain.c
--- a/tools/libxc/xc_domain.c   Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/xc_domain.c   Tue Nov 22 15:31:16 2005
@@ -15,7 +15,7 @@
                      uint32_t *pdomid)
 {
     int err;
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
 
     op.cmd = DOM0_CREATEDOMAIN;
     op.u.createdomain.domain = (domid_t)*pdomid;
@@ -32,7 +32,7 @@
 int xc_domain_pause(int xc_handle, 
                     uint32_t domid)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     op.cmd = DOM0_PAUSEDOMAIN;
     op.u.pausedomain.domain = (domid_t)domid;
     return do_dom0_op(xc_handle, &op);
@@ -42,7 +42,7 @@
 int xc_domain_unpause(int xc_handle,
                       uint32_t domid)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     op.cmd = DOM0_UNPAUSEDOMAIN;
     op.u.unpausedomain.domain = (domid_t)domid;
     return do_dom0_op(xc_handle, &op);
@@ -52,7 +52,7 @@
 int xc_domain_destroy(int xc_handle,
                       uint32_t domid)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     op.cmd = DOM0_DESTROYDOMAIN;
     op.u.destroydomain.domain = (domid_t)domid;
     return do_dom0_op(xc_handle, &op);
@@ -63,7 +63,7 @@
                      int vcpu,
                      cpumap_t cpumap)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     op.cmd = DOM0_PINCPUDOMAIN;
     op.u.pincpudomain.domain  = (domid_t)domid;
     op.u.pincpudomain.vcpu    = vcpu;
@@ -79,7 +79,7 @@
 {
     unsigned int nr_doms;
     uint32_t next_domid = first_domid;
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     int rc = 0; 
 
     memset(info, 0, max_doms*sizeof(xc_dominfo_t));
@@ -134,7 +134,7 @@
                           xc_domaininfo_t *info)
 {
     int ret = 0;
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
 
     if ( mlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
         return -1;
@@ -161,7 +161,7 @@
                                vcpu_guest_context_t *ctxt)
 {
     int rc;
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
 
     op.cmd = DOM0_GETVCPUCONTEXT;
     op.u.getvcpucontext.domain = (domid_t)domid;
@@ -187,7 +187,7 @@
                       xc_shadow_control_stats_t *stats )
 {
     int rc;
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     op.cmd = DOM0_SHADOW_CONTROL;
     op.u.shadow_control.domain = (domid_t)domid;
     op.u.shadow_control.op     = sop;
@@ -250,7 +250,7 @@
                         uint32_t domid, 
                         unsigned int max_memkb)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     op.cmd = DOM0_SETDOMAINMAXMEM;
     op.u.setdomainmaxmem.domain = (domid_t)domid;
     op.u.setdomainmaxmem.max_memkb = max_memkb;
@@ -328,7 +328,7 @@
 
 int xc_domain_max_vcpus(int xc_handle, uint32_t domid, unsigned int max)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     op.cmd = DOM0_MAX_VCPUS;
     op.u.max_vcpus.domain = (domid_t)domid;
     op.u.max_vcpus.max    = max;
@@ -338,7 +338,7 @@
 int xc_domain_sethandle(int xc_handle, uint32_t domid, 
                         xen_domain_handle_t handle)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     op.cmd = DOM0_SETDOMAINHANDLE;
     op.u.setdomainhandle.domain = (domid_t)domid;
     memcpy(op.u.setdomainhandle.handle, handle, sizeof(xen_domain_handle_t));
@@ -351,8 +351,7 @@
                             xc_vcpuinfo_t *info)
 {
     int rc;
-    dom0_op_t op;
-
+    DECLARE_DOM0_OP;
     op.cmd = DOM0_GETVCPUINFO;
     op.u.getvcpuinfo.domain = (domid_t)domid;
     op.u.getvcpuinfo.vcpu   = (uint16_t)vcpu;
@@ -370,7 +369,7 @@
                                 uint16_t nr_ports,
                                 uint16_t allow_access)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
 
     op.cmd = DOM0_IOPORT_PERMISSION;
     op.u.ioport_permission.domain = (domid_t)domid;
diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xc_evtchn.c
--- a/tools/libxc/xc_evtchn.c   Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/xc_evtchn.c   Tue Nov 22 15:31:16 2005
@@ -12,7 +12,7 @@
 static int do_evtchn_op(int xc_handle, evtchn_op_t *op)
 {
     int ret = -1;
-    privcmd_hypercall_t hypercall;
+    DECLARE_HYPERCALL;
 
     hypercall.op     = __HYPERVISOR_event_channel_op;
     hypercall.arg[0] = (unsigned long)op;
diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xc_gnttab.c
--- a/tools/libxc/xc_gnttab.c   Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/xc_gnttab.c   Tue Nov 22 15:31:16 2005
@@ -17,7 +17,7 @@
              unsigned long count)
 {
     int ret = -1;
-    privcmd_hypercall_t hypercall;
+    DECLARE_HYPERCALL;
 
     hypercall.op     = __HYPERVISOR_grant_table_op;
     hypercall.arg[0] = cmd;
diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xc_linux_build.c
--- a/tools/libxc/xc_linux_build.c      Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/xc_linux_build.c      Tue Nov 22 15:31:16 2005
@@ -692,7 +692,8 @@
                    unsigned int console_evtchn,
                    unsigned long *console_mfn)
 {
-    dom0_op_t launch_op, op;
+    dom0_op_t launch_op;
+    DECLARE_DOM0_OP;
     int initrd_fd = -1;
     gzFile initrd_gfd = NULL;
     int rc, i;
@@ -727,6 +728,10 @@
             goto error_out;
         }
     }
+
+#ifdef VALGRIND
+    memset(&st_ctxt, 0, sizeof(st_ctxt));
+#endif
 
     if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
     {   
diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xc_linux_restore.c
--- a/tools/libxc/xc_linux_restore.c    Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/xc_linux_restore.c    Tue Nov 22 15:31:16 2005
@@ -106,7 +106,7 @@
                      unsigned int store_evtchn, unsigned long *store_mfn,
                      unsigned int console_evtchn, unsigned long *console_mfn)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     int rc = 1, i, n;
     unsigned long mfn, pfn; 
     unsigned int prev_pc, this_pc;
diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xc_misc.c
--- a/tools/libxc/xc_misc.c     Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/xc_misc.c     Tue Nov 22 15:31:16 2005
@@ -25,7 +25,7 @@
                        int clear)
 {
     int ret;
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     char *buffer = *pbuffer;
     unsigned int nr_chars = *pnr_chars;
 
@@ -52,7 +52,7 @@
                 xc_physinfo_t *put_info)
 {
     int ret;
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     
     op.cmd = DOM0_PHYSINFO;
     op.interface_version = DOM0_INTERFACE_VERSION;
@@ -69,7 +69,7 @@
                 int *sched_id)
 {
     int ret;
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     
     op.cmd = DOM0_SCHED_ID;
     op.interface_version = DOM0_INTERFACE_VERSION;
@@ -83,25 +83,25 @@
 }
 
 int xc_perfc_control(int xc_handle,
-                     uint32_t op,
+                     uint32_t opcode,
                      xc_perfc_desc_t *desc)
 {
     int rc;
-    dom0_op_t dop;
+    DECLARE_DOM0_OP;
 
-    dop.cmd = DOM0_PERFCCONTROL;
-    dop.u.perfccontrol.op   = op;
-    dop.u.perfccontrol.desc = desc;
+    op.cmd = DOM0_PERFCCONTROL;
+    op.u.perfccontrol.op   = opcode;
+    op.u.perfccontrol.desc = desc;
 
-    rc = do_dom0_op(xc_handle, &dop);
+    rc = do_dom0_op(xc_handle, &op);
 
-    return (rc == 0) ? dop.u.perfccontrol.nr_counters : rc;
+    return (rc == 0) ? op.u.perfccontrol.nr_counters : rc;
 }
 
 long long xc_msr_read(int xc_handle, int cpu_mask, int msr)
 {
     int rc;    
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     
     op.cmd = DOM0_MSR;
     op.u.msr.write = 0;
@@ -117,7 +117,7 @@
                   unsigned int high)
 {
     int rc;    
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     
     op.cmd = DOM0_MSR;
     op.u.msr.write = 1;
diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c  Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/xc_private.c  Tue Nov 22 15:31:16 2005
@@ -68,7 +68,7 @@
 int xc_get_pfn_type_batch(int xc_handle, 
                           uint32_t dom, int num, unsigned long *arr)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     op.cmd = DOM0_GETPAGEFRAMEINFO2;
     op.u.getpageframeinfo2.domain = (domid_t)dom;
     op.u.getpageframeinfo2.num    = num;
@@ -81,7 +81,7 @@
                           unsigned long mfn, 
                           uint32_t dom)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     op.cmd = DOM0_GETPAGEFRAMEINFO;
     op.u.getpageframeinfo.pfn    = mfn;
     op.u.getpageframeinfo.domain = (domid_t)dom;
@@ -99,7 +99,7 @@
     unsigned int nr_ops,
     domid_t dom)
 {
-    privcmd_hypercall_t hypercall;
+    DECLARE_HYPERCALL;
     long ret = -EINVAL;
 
     hypercall.op     = __HYPERVISOR_mmuext_op;
@@ -125,7 +125,7 @@
 static int flush_mmu_updates(int xc_handle, xc_mmu_t *mmu)
 {
     int err = 0;
-    privcmd_hypercall_t hypercall;
+    DECLARE_HYPERCALL;
 
     if ( mmu->idx == 0 )
         return 0;
@@ -188,7 +188,7 @@
                  int cmd,
                  void *arg)
 {
-    privcmd_hypercall_t hypercall;
+    DECLARE_HYPERCALL;
     struct xen_memory_reservation *reservation = arg;
     long ret = -EINVAL;
 
@@ -236,7 +236,7 @@
 
 long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid, int vcpu )
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
 
     op.cmd = DOM0_GETVCPUINFO;
     op.u.getvcpuinfo.domain = (domid_t)domid;
@@ -255,13 +255,16 @@
                     unsigned long *pfn_buf, 
                     unsigned long max_pfns)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     int ret;
     op.cmd = DOM0_GETMEMLIST;
     op.u.getmemlist.domain   = (domid_t)domid;
     op.u.getmemlist.max_pfns = max_pfns;
     op.u.getmemlist.buffer   = pfn_buf;
 
+#ifdef VALGRIND
+    memset(pfn_buf, 0, max_pfns * sizeof(unsigned long));
+#endif
 
     if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 )
     {
@@ -293,7 +296,7 @@
 
 long xc_get_tot_pages(int xc_handle, uint32_t domid)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     op.cmd = DOM0_GETDOMAININFO;
     op.u.getdomaininfo.domain = (domid_t)domid;
     return (do_dom0_op(xc_handle, &op) < 0) ? 
@@ -402,6 +405,11 @@
         PERROR("Could not lock memory for version hypercall");
         return -ENOMEM;
     }
+
+#ifdef VALGRIND
+    if (argsize != 0)
+        memset(arg, 0, argsize);
+#endif
 
     rc = do_xen_version(xc_handle, cmd, arg);
 
diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h  Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/xc_private.h  Tue Nov 22 15:31:16 2005
@@ -16,6 +16,19 @@
 #include "xenctrl.h"
 
 #include <xen/linux/privcmd.h>
+
+/* valgrind cannot see when a hypercall has filled in some values.  For this
+   reason, we must zero the privcmd_hypercall_t or dom0_op_t instance before a
+   call, if using valgrind.  */
+#ifdef VALGRIND
+#define DECLARE_HYPERCALL privcmd_hypercall_t hypercall; \
+  memset(&hypercall, 0, sizeof(hypercall))
+#define DECLARE_DOM0_OP dom0_op_t op; memset(&op, 0, sizeof(op))
+#else
+#define DECLARE_HYPERCALL privcmd_hypercall_t hypercall
+#define DECLARE_DOM0_OP dom0_op_t op
+#endif
+
 
 #define PAGE_SHIFT              XC_PAGE_SHIFT
 #define PAGE_SIZE               (1UL << PAGE_SHIFT)
@@ -61,7 +74,7 @@
 
 static inline int do_xen_version(int xc_handle, int cmd, void *dest)
 {
-    privcmd_hypercall_t hypercall;
+    DECLARE_HYPERCALL;
 
     hypercall.op     = __HYPERVISOR_xen_version;
     hypercall.arg[0] = (unsigned long) cmd;
@@ -73,7 +86,7 @@
 static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
 {
     int ret = -1;
-    privcmd_hypercall_t hypercall;
+    DECLARE_HYPERCALL;
 
     op->interface_version = DOM0_INTERFACE_VERSION;
 
diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xc_ptrace.c
--- a/tools/libxc/xc_ptrace.c   Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/xc_ptrace.c   Tue Nov 22 15:31:16 2005
@@ -283,7 +283,7 @@
     int *status,
     int options)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     int retval;
     struct timespec ts;
     ts.tv_sec = 0;
@@ -323,7 +323,7 @@
     long eaddr,
     long edata)
 {
-    dom0_op_t       op;
+    DECLARE_DOM0_OP;
     int             status = 0;
     struct gdb_regs pt;
     long            retval = 0;
diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xc_sedf.c
--- a/tools/libxc/xc_sedf.c     Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/xc_sedf.c     Tue Nov 22 15:31:16 2005
@@ -13,7 +13,7 @@
 int xc_sedf_domain_set(int xc_handle,
                           uint32_t domid, uint64_t period, uint64_t 
slice,uint64_t latency, uint16_t extratime,uint16_t weight)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     struct sedf_adjdom *p = &op.u.adjustdom.u.sedf;
 
     op.cmd = DOM0_ADJUSTDOM;
@@ -31,7 +31,7 @@
 
 int xc_sedf_domain_get(int xc_handle, uint32_t domid, uint64_t *period, 
uint64_t *slice, uint64_t* latency, uint16_t* extratime, uint16_t* weight)
 {
-    dom0_op_t op;
+    DECLARE_DOM0_OP;
     int ret;
     struct sedf_adjdom *p = &op.u.adjustdom.u.sedf;
 
diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xc_tbuf.c
--- a/tools/libxc/xc_tbuf.c     Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/xc_tbuf.c     Tue Nov 22 15:31:16 2005
@@ -10,7 +10,7 @@
 
 int xc_tbuf_enable(int xc_handle, int enable)
 {
-  dom0_op_t op;
+  DECLARE_DOM0_OP;
 
   op.cmd = DOM0_TBUFCONTROL;
   op.interface_version = DOM0_INTERFACE_VERSION;
@@ -24,7 +24,7 @@
 
 int xc_tbuf_set_size(int xc_handle, uint32_t size)
 {
-  dom0_op_t op;
+  DECLARE_DOM0_OP;
 
   op.cmd = DOM0_TBUFCONTROL;
   op.interface_version = DOM0_INTERFACE_VERSION;
@@ -37,7 +37,7 @@
 int xc_tbuf_get_size(int xc_handle, uint32_t *size)
 {
   int rc;
-  dom0_op_t op;
+  DECLARE_DOM0_OP;
 
   op.cmd = DOM0_TBUFCONTROL;
   op.interface_version = DOM0_INTERFACE_VERSION;
diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xg_private.h
--- a/tools/libxc/xg_private.h  Mon Nov 21 18:08:44 2005
+++ b/tools/libxc/xg_private.h  Tue Nov 22 15:31:16 2005
@@ -15,6 +15,16 @@
 
 #include <xen/linux/privcmd.h>
 #include <xen/memory.h>
+
+/* valgrind cannot see when a hypercall has filled in some values.  For this
+   reason, we must zero the dom0_op_t instance before a call, if using
+   valgrind.  */
+#ifdef VALGRIND
+#define DECLARE_DOM0_OP dom0_op_t op; memset(&op, 0, sizeof(op))
+#else
+#define DECLARE_DOM0_OP dom0_op_t op
+#endif
+
 
 char *xc_read_kernel_image(const char *filename, unsigned long *size);
 unsigned long csum_page (void * page);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Make it possible to run valgrind on code linked with the libxc libraries., Xen patchbot -unstable <=