Skip to contentSkip to conversation

valgrind: Support for ioctls used by Xen toolstack processes.

PATCH In review Ian Campbell 1 participant 2 messages Sep 4, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 valgrind: Support for ioctls used by Xen toolstack processes.

Please CC as I'm not subscribed to valgrind-developers.

Under Xen the toolstack is responsible for managing the domains in the system, e.g. creating, destroying, and otherwise manipulating them.

To do this it uses a number of ioctls on the /proc/xen/privcmd device. Most of these (the MMAPBATCH ones) simply set things up such that a subsequenct mmap call will map the desired guest memory. Since valgrind has no way of knowing what the memory contains we assume that it is all initialised (to do otherwise would require valgrind to be observing the complete state of the system and not just the given process).

The most interesting ioctl is XEN_IOCTL_PRIVCMD_HYPERCALL which allows the toolstack to make arbitrary hypercalls. Although the mechanism here is specific to the OS of the guest running the toolstack the hypercalls themselves are defined solely by the hypervisor. Therefore I have split support for this ioctl into a part in syswrap-linux.c which handles the ioctl itself and passes things onto a new syswrap-xen.c which handles the specifics of the hypercalls themselves. Porting this to another OS should just be a matter of wiring up syswrap-$OS.c to decode the ioctl and call into syswrap-xen.c. In the future we may want to split this into syswrap-$ARCH-xen.c but for now this is x86 only.

The hypercall coverage here is pretty small but is enough to get reasonable(-ish) results out of the xl toolstack when listing, creating and destroying domains.

One issue is that the hypercalls which are exlusively used by the toolstacks (as opposed to those used by guest operating systems) are not considered a stable ABI, since the hypervisor and the lowlevel tools are considered a matched pair. This covers the sysctl and domctl hypercalls which are a fairly large chunk of the support here. I'm not sure how to solve this without invoking a massive amount of duplication. Right now this targets the Xen unstable interface (which will shortly be released as Xen 4.2), perhaps I can get away with deferring this problem until the first change ;-).

On the plus side the vast majority of hypercalls are not of interest to the toolstack (they are used by guests) so we can get away without implementing them.

There are some other wrinkles here I've not been sure how to solve:

Firstly, di_notify_mmap tries to read from the magic proc device:
--20208-- WARNING: Serious error when reading debug info --20208-- When reading debug info from /proc/xen/privcmd:
--20208-- can't read file to inspect ELF header

I've hacked around this with an explicit check for /proc/xen. Hopefully someone can point to the right solution.

Secondly, a hypercall only reads as many words from the ioctl arg struct as there are actual arguments to that hypercall and the toolstack only initialises the arguments which are used. However there is no space in the DEFN_PRE_TEMPLATE prototype to allow this to be communicated from syswrap-xen.c back to syswrap-linux.c. Since a hypercall can have at most 5 arguments I have hackily stolen ARG8 for this purpose.

---
 configure.in                           |   19 +
 coregrind/Makefile.am                  |    8 +-
 coregrind/m_debuginfo/debuginfo.c      |    9 +
 coregrind/m_syswrap/priv_syswrap-xen.h |   10 +
 coregrind/m_syswrap/syswrap-linux.c    |  107 ++++-
 coregrind/m_syswrap/syswrap-xen.c      | 1023 ++++++++++++++++++++++++++++++++
 include/Makefile.am                    |    3 +-
 include/pub_tool_vki.h                 |    1 +
 include/vki/vki-linux.h                |   44 ++
 include/vki/vki-xen.h                  |    8 +
 10 files changed, 1229 insertions(+), 3 deletions(-)
 create mode 100644 coregrind/m_syswrap/priv_syswrap-xen.h
 create mode 100644 coregrind/m_syswrap/syswrap-xen.c
 create mode 100644 include/vki/vki-xen.h
configure.in +19 -0
index b385aed..d94644c 100644
@@ -2012,6 +2012,25 @@ AC_ARG_WITH(mpicc,
 )
 AC_SUBST(MPI_CC)
 
+#----------------------------------------------------------------------------
+# Xen checks
+#----------------------------------------------------------------------------
+AC_ARG_ENABLE(xen, 
+      [  --enable-xen            Enable support for Xen hypervisor],
+      [vg_cv_xen=$enableval],
+      [vg_cv_xen=no])
+
+AC_ARG_WITH(xen,
+   [  --with-xen=             Specify location of Xen headers],
+   XEN_CFLAGS=-I$withval
+)
+AC_SUBST(XEN_CFLAGS)
+
+AM_CONDITIONAL([ENABLE_XEN], [test x$vg_cv_xen = xyes])
+if test x"$vg_cv_xen" = xyes; then
+    AC_DEFINE([ENABLE_XEN], 1, [configured to support Xen])
+fi
+
 ## We AM_COND_IF here instead of automake "if" in mpi/Makefile.am so that we can
 ## use these values in the check for a functioning mpicc.
 ##
coregrind/Makefile.am +7 -1
index 01015a7..58a7dce 100644
@@ -224,6 +224,7 @@ noinst_HEADERS = \
 	m_syswrap/priv_syswrap-linux-variants.h \
 	m_syswrap/priv_syswrap-darwin.h \
 	m_syswrap/priv_syswrap-main.h \
+	m_syswrap/priv_syswrap-xen.h \
 	m_ume/priv_ume.h
 
 #----------------------------------------------------------------------------
@@ -371,6 +372,11 @@ COREGRIND_SOURCES_COMMON = \
 	m_ume/main.c \
 	m_ume/script.c
 
+if ENABLE_XEN
+COREGRIND_SOURCES_COMMON += m_syswrap/syswrap-xen.c
+CFLAGS += @XEN_CFLAGS@
+endif
+
 libcoregrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_a_SOURCES = \
     $(COREGRIND_SOURCES_COMMON)
 nodist_libcoregrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_a_SOURCES = \
@@ -378,7 +384,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 ENABLE_LINUX_TICKET_LOCK_PRIMARY
coregrind/m_debuginfo/debuginfo.c +9 -0
index 218547b..b634ce0 100644
@@ -729,6 +729,15 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd )
    if (!filename)
       return 0;
 
+   /*
+    * Cannot read from these magic files:
+    * --20208-- WARNING: Serious error when reading debug info
+    * --20208-- When reading debug info from /proc/xen/privcmd:
+    * --20208-- can't read file to inspect ELF header
+    */
+   if (VG_(strncmp)(filename, "/proc/xen/", 10) == 0)
+      return 0;
+
    if (debug)
       VG_(printf)("di_notify_mmap-2: %s\n", filename);
 
coregrind/m_syswrap/priv_syswrap-xen.h new file +10 -0
new file mode 100644
index 0000000..4dc4748
@@ -0,0 +1,10 @@
+#ifndef __PRIV_SYSWRAP_XEN_H
+#define __PRIV_SYSWRAP_XEN_H
+
+DECL_TEMPLATE(xen, hypercall);
+
+#endif   // __PRIV_SYSWRAP_XEN_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
coregrind/m_syswrap/syswrap-linux.c +106 -1

125 lines not on this page · raw message

coregrind/m_syswrap/syswrap-xen.c new file +1023 -0

1,023 lines not on this page · raw message

include/Makefile.am +2 -1
index ade27c2..f1a3443 100644
@@ -64,4 +64,5 @@ nobase_pkginclude_HEADERS = \
 	vki/vki-scnums-arm-linux.h	\
 	vki/vki-scnums-s390x-linux.h	\
 	vki/vki-scnums-mips32-linux.h	\
-	vki/vki-scnums-darwin.h
+	vki/vki-scnums-darwin.h		\
+	vki/vki-xen.h
include/pub_tool_vki.h +1 -0
index a0996f9..6598106 100644
@@ -47,6 +47,7 @@
 
 #if defined(VGO_linux)
 #  include "vki/vki-linux.h"
+#  include "vki/vki-xen.h"
 #elif defined(VGO_darwin)
 #  include "vki/vki-darwin.h"
 #else
include/vki/vki-linux.h +44 -0

50 lines not on this page · raw message

include/vki/vki-xen.h new file +8 -0
new file mode 100644
index 0000000..7842cc9
@@ -0,0 +1,8 @@
+#ifndef __VKI_XEN_H
+#define __VKI_XEN_H
+
+#endif // __VKI_XEN_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 1 line · Ian Campbell

Please CC as I'm not subscribed to valgrind-developers.

Which turns out to be a subscriber only list...

Sorry xen-devel for the repost you are about to receive ...

Ian.