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-devel

[Xen-devel] Re: [PATCH 0 of 3] xl: free allocations made at top level

To: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] Re: [PATCH 0 of 3] xl: free allocations made at top level
From: Ian Campbell <Ian.Campbell@xxxxxxxxxxxxx>
Date: Fri, 30 Jul 2010 15:02:22 +0100
Delivery-date: Fri, 30 Jul 2010 07:03:21 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1280480568@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Organization: Citrix Systems, Inc.
References: <patchbomb.1280480568@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
On Fri, 2010-07-30 at 10:02 +0100, Ian Campbell wrote:
> 
> I used a version of valgrind which I have patched to understand the
> PRIVCMD_HYPERCALL ioctl on /proc/xen/privcmd. It currently understands
> exactly one sysctl (XEN_SYSCTL_getdomaininfolist). I will post the
> patch shortly and imagine I will be expanding it as I test other xl
> commands etc. 

Here is the patch I used. It's obviously very basic and terribly
incomplete, only understands a single sysctl, only for the version of
Xen it is built against, is my first attempt at hacking valgrind, etc
etc.

I also bailed on the normal valgrind policy of duplicating the interface
headers so usage is:

        ./configure --with-xen=/path/to/headers

The path needs to be to an installed set of xen headers, such that
"#include <xen/xen.h>" is valid e.g. dist/install/usr/include in your
built Xen tree or /usr/include or something equivalent (e.g. libxen-dev
installed under Debian etc.)

Ian.

diff --git a/configure.in b/configure.in
index 62e1837..e71ecd6 100644
--- a/configure.in
+++ b/configure.in
@@ -1558,6 +1558,11 @@ elif test x$VGCONF_PLATFORM_SEC_CAPS = xPPC32_AIX5 ; then
   mflag_secondary=-q32
 fi
 
+AC_ARG_WITH(xen,
+   [  --with-xen=             Specify location of Xen headers],
+   XEN_CFLAGS=-I$withval
+)
+AC_SUBST(XEN_CFLAGS)
 
 AC_ARG_WITH(mpicc,
    [  --with-mpicc=           Specify name of MPI2-ised C compiler],
diff --git a/coregrind/Makefile.am b/coregrind/Makefile.am
index d9d1bca..d7216f9 100644
--- a/coregrind/Makefile.am
+++ b/coregrind/Makefile.am
@@ -211,6 +211,7 @@ noinst_HEADERS = \
        m_syswrap/priv_syswrap-aix5.h \
        m_syswrap/priv_syswrap-darwin.h \
        m_syswrap/priv_syswrap-main.h \
+       m_syswrap/priv_syswrap-xen.h \
        m_ume/priv_ume.h
 
 #----------------------------------------------------------------------------
@@ -338,6 +339,7 @@ COREGRIND_SOURCES_COMMON = \
        m_syswrap/syswrap-ppc64-aix5.c \
        m_syswrap/syswrap-x86-darwin.c \
        m_syswrap/syswrap-amd64-darwin.c \
+       m_syswrap/syswrap-xen.c \
        m_ume/elf.c \
        m_ume/macho.c \
        m_ume/main.c \
@@ -350,7 +352,7 @@ nodist_libcoregrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_a_SOURCES 
= \
 libcoregrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_a_CPPFLAGS = \
     $(AM_CPPFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
 libcoregrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_a_CFLAGS = \
-    $(AM_CFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
+    $(AM_CFLAGS_@VGCONF_PLATFORM_PRI_CAPS@) @XEN_CFLAGS@
 libcoregrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_a_CCASFLAGS = \
     $(AM_CCASFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
 if VGCONF_HAVE_PLATFORM_SEC
diff --git a/coregrind/m_syswrap/priv_syswrap-xen.h 
b/coregrind/m_syswrap/priv_syswrap-xen.h
new file mode 100644
index 0000000..c65edca
--- /dev/null
+++ b/coregrind/m_syswrap/priv_syswrap-xen.h
@@ -0,0 +1,10 @@
+#ifndef __PRIV_SYSWRAP_XEN_H
+#define __PRIV_SYSWRAP_XEN_H
+
+DECL_TEMPLATE(xen, ioctl_privcmd_hypercall);
+
+#endif   // __PRIV_SYSWRAP_XEN_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
diff --git a/coregrind/m_syswrap/syswrap-linux.c 
b/coregrind/m_syswrap/syswrap-linux.c
index 247402d..42dc4d9 100644
--- a/coregrind/m_syswrap/syswrap-linux.c
+++ b/coregrind/m_syswrap/syswrap-linux.c
@@ -57,7 +57,7 @@
 #include "priv_types_n_macros.h"
 #include "priv_syswrap-generic.h"
 #include "priv_syswrap-linux.h"
-
+#include "priv_syswrap-xen.h"
 
 // Run a thread from beginning to end and return the thread's
 // scheduler-return-code.
@@ -4821,6 +4821,11 @@ PRE(sys_ioctl)
       }
       break;
 
+
+   case VKI_XEN_IOCTL_PRIVCMD_HYPERCALL:
+      WRAPPER_PRE_NAME(xen, ioctl_privcmd_hypercall)(tid, layout, arrghs, 
status, flags);
+      break;
+
    default:
       /* EVIOC* are variable length and return size written on success */
       switch (ARG2 & ~(_VKI_IOC_SIZEMASK << _VKI_IOC_SIZESHIFT)) {
@@ -5633,6 +5638,10 @@ POST(sys_ioctl)
       }
       break;
 
+   case VKI_XEN_IOCTL_PRIVCMD_HYPERCALL:
+      WRAPPER_POST_NAME(xen, ioctl_privcmd_hypercall)(tid, arrghs, status);
+      break;
+
    default:
       /* EVIOC* are variable length and return size written on success */
       switch (ARG2 & ~(_VKI_IOC_SIZEMASK << _VKI_IOC_SIZESHIFT)) {
diff --git a/coregrind/m_syswrap/syswrap-xen.c 
b/coregrind/m_syswrap/syswrap-xen.c
new file mode 100644
index 0000000..53e6078
--- /dev/null
+++ b/coregrind/m_syswrap/syswrap-xen.c
@@ -0,0 +1,117 @@
+#include "pub_core_basics.h"
+#include "pub_core_vki.h"
+#include "pub_core_vkiscnums.h"
+#include "pub_core_threadstate.h"
+#include "pub_core_aspacemgr.h"
+#include "pub_core_debuginfo.h"    // VG_(di_notify_*)
+#include "pub_core_transtab.h"     // VG_(discard_translations)
+#include "pub_core_xarray.h"
+#include "pub_core_clientstate.h"
+#include "pub_core_debuglog.h"
+#include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
+#include "pub_core_libcfile.h"
+#include "pub_core_libcprint.h"
+#include "pub_core_libcproc.h"
+#include "pub_core_libcsignal.h"
+#include "pub_core_mallocfree.h"
+#include "pub_core_tooliface.h"
+#include "pub_core_options.h"
+#include "pub_core_scheduler.h"
+#include "pub_core_signals.h"
+#include "pub_core_syscall.h"
+#include "pub_core_syswrap.h"
+
+#include "priv_types_n_macros.h"
+#include "priv_syswrap-generic.h"
+#include "priv_syswrap-xen.h"
+
+#include <stdint.h>
+
+#define __XEN_TOOLS__
+
+#include <xen/xen.h>
+#include <xen/sysctl.h>
+
+
+#define PRE(name)       DEFN_PRE_TEMPLATE(xen, name)
+#define POST(name)      DEFN_POST_TEMPLATE(xen, name)
+
+PRE(ioctl_privcmd_hypercall)
+{
+   struct vki_xen_privcmd_hypercall *args = (struct vki_xen_privcmd_hypercall 
*)(ARG3);
+
+   if (!args)
+      return;
+
+
+   switch (args->op) {
+   case __HYPERVISOR_sysctl: {
+      struct xen_sysctl *sysctl = (struct xen_sysctl *)(unsigned 
int)args->arg[0];
+
+      PRINT("__HYPERVISOR_sysctl ( %d )", sysctl->cmd);
+
+      /* Single argument hypercall */
+      PRE_MEM_READ("hypercall", ARG3, 8 + ( 8 * 1 ) );
+
+      /* Common part of xen_sysctl */
+      PRE_MEM_READ("__HYPERVISOR_sysctl", args->arg[0], ( 4 + 4 ));
+
+      if (!sysctl || sysctl->interface_version != XEN_SYSCTL_INTERFACE_VERSION)
+        /* BUG ? */
+        return;
+
+      //PRE_REG_READ1(long, "__HYPERVISOR_sysctl",);
+      switch (sysctl->cmd) {
+      case XEN_SYSCTL_getdomaininfolist:
+        PRE_MEM_READ("__HYPERVISOR_sysctl", 
&sysctl->u.getdomaininfolist.first_domain, sizeof(domid_t));
+        PRE_MEM_READ("__HYPERVISOR_sysctl", 
&sysctl->u.getdomaininfolist.max_domains, sizeof(uint32_t));
+        PRE_MEM_READ("__HYPERVISOR_sysctl", 
&sysctl->u.getdomaininfolist.buffer, 
sizeof(&sysctl->u.getdomaininfolist.buffer));
+        break;
+
+      default:
+        VG_(printf)("pre sysctl version %x unknown cmd %d\n",
+                    sysctl->interface_version, sysctl->cmd);
+        break;
+      }
+   }
+      break;
+
+   default:
+      VG_(printf)("pre unknown hypercall %lld ( 0x%#llx, 0x%#llx, 0x%#llx, 
0x%#llx, 0x%#llx )\n",
+                 args->op, args->arg[0], args->arg[1], args->arg[2], 
args->arg[3], args->arg[4]);
+   }
+}
+
+POST(ioctl_privcmd_hypercall)
+{
+   struct vki_xen_privcmd_hypercall *args = (struct vki_xen_privcmd_hypercall 
*)(ARG3);
+
+   if (!args)
+      return;
+
+   switch (args->op) {
+   case __HYPERVISOR_sysctl: {
+      struct xen_sysctl *sysctl = (struct xen_sysctl *)(unsigned 
int)args->arg[0];
+
+      if (!sysctl || sysctl->interface_version != XEN_SYSCTL_INTERFACE_VERSION)
+        return;
+
+      switch (sysctl->cmd) {
+      case XEN_SYSCTL_getdomaininfolist:
+        POST_MEM_WRITE(&sysctl->u.getdomaininfolist.num_domains, 
sizeof(sysctl->u.getdomaininfolist.num_domains));
+        POST_MEM_WRITE(sysctl->u.getdomaininfolist.buffer.p, 
sizeof(xen_domctl_getdomaininfo_t) * sysctl->u.getdomaininfolist.num_domains);
+        break;
+      default:
+        VG_(printf)("post sysctl version %x cmd %d\n",
+                    sysctl->interface_version, sysctl->cmd);
+        break;
+      }
+      break;
+   }
+   default:
+      VG_(printf)("post unknown hypercall %lld ( 0x%#llx, 0x%#llx, 0x%#llx, 
0x%#llx, 0x%#llx )\n",
+                 args->op, args->arg[0], args->arg[1], args->arg[2], 
args->arg[3], args->arg[4]);
+      break;
+   }
+}
diff --git a/include/Makefile.am b/include/Makefile.am
index 33d0857..22bffa7 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -54,7 +54,8 @@ nobase_pkginclude_HEADERS = \
        vki/vki-scnums-ppc64-linux.h    \
        vki/vki-scnums-x86-linux.h      \
        vki/vki-scnums-arm-linux.h      \
-       vki/vki-scnums-darwin.h
+       vki/vki-scnums-darwin.h         
+       vki/vki-xen.h
 
 noinst_HEADERS = \
        vki/vki-ppc32-aix5.h            \
diff --git a/include/pub_tool_vki.h b/include/pub_tool_vki.h
index 73a4174..c4c117f 100644
--- a/include/pub_tool_vki.h
+++ b/include/pub_tool_vki.h
@@ -47,6 +47,7 @@
 
 #if defined(VGO_linux)
 #  include "vki/vki-linux.h"
+#  include "vki/vki-xen.h"
 #elif defined(VGP_ppc32_aix5)
 #  include "vki/vki-ppc32-aix5.h"
 #elif defined(VGP_ppc64_aix5)
diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h
index beff378..86126ea 100644
--- a/include/vki/vki-linux.h
+++ b/include/vki/vki-linux.h
@@ -2709,6 +2709,17 @@ struct vki_getcpu_cache {
 #define VKI_EV_MAX             0x1f
 #define VKI_EV_CNT             (VKI_EV_MAX+1)
 
+//----------------------------------------------------------------------
+// Xen privcmd IOCTL
+//----------------------------------------------------------------------
+
+struct vki_xen_privcmd_hypercall {
+       __vki_u64 op;
+       __vki_u64 arg[5];
+};
+
+#define VKI_XEN_IOCTL_PRIVCMD_HYPERCALL _VKI_IOC(_VKI_IOC_NONE, 'P', 0, 
sizeof(struct vki_xen_privcmd_hypercall))
+
 #endif // __VKI_LINUX_H
 
 /*--------------------------------------------------------------------*/
diff --git a/include/vki/vki-xen.h b/include/vki/vki-xen.h
new file mode 100644
index 0000000..7842cc9
--- /dev/null
+++ b/include/vki/vki-xen.h
@@ -0,0 +1,8 @@
+#ifndef __VKI_XEN_H
+#define __VKI_XEN_H
+
+#endif // __VKI_XEN_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/



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