valgrind: Support Xen toolstack process ioctls
authorbart <bart@a5019735-40e9-0310-863c-91ae7b9d1cf9>
Sun, 9 Sep 2012 18:30:17 +0000 (18:30 +0000)
committerbart <bart@a5019735-40e9-0310-863c-91ae7b9d1cf9>
Sun, 9 Sep 2012 18:30:17 +0000 (18:30 +0000)
commit7283a15eb133c581f1d9e928b8971f521f0fa26a
tree4522cdccf703341d4e141fca461b6b45d5f4c4c1
parentb7464782f612246040cb73dfdf81194dff529442
valgrind: Support Xen toolstack process ioctls

From: Ian Campbell <Ian.Campbell@citrix.com>

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.

Note: 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.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12963 a5019735-40e9-0310-863c-91ae7b9d1cf9
configure.in
coregrind/Makefile.am
coregrind/m_debuginfo/debuginfo.c
coregrind/m_syswrap/priv_syswrap-xen.h [new file with mode: 0644]
coregrind/m_syswrap/syswrap-linux.c
coregrind/m_syswrap/syswrap-xen.c [new file with mode: 0644]
include/Makefile.am
include/pub_tool_vki.h
include/vki/vki-linux.h
include/vki/vki-xen.h [new file with mode: 0644]