From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:45699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLHDf-0003da-HE for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:29:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLHDe-0003SJ-Be for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:29:47 -0400 Received: from e7.ny.us.ibm.com ([32.97.182.137]:45022) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLHDe-0003SB-3Q for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:29:46 -0400 Received: from /spool/local by e7.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 1 Nov 2011 12:22:58 -0400 Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pA1GLNuL230738 for ; Tue, 1 Nov 2011 12:21:23 -0400 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pA1GLLlo002325 for ; Tue, 1 Nov 2011 12:21:21 -0400 Message-ID: <4EB01C7D.5070506@us.ibm.com> Date: Tue, 01 Nov 2011 11:21:17 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1320092986-2490-1-git-send-email-sw@weilnetz.de> In-Reply-To: <1320092986-2490-1-git-send-email-sw@weilnetz.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2] Support running QEMU on Valgrind List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Weil Cc: qemu-devel@nongnu.org, Avi Kivity On 10/31/2011 03:29 PM, Stefan Weil wrote: > Valgrind is a tool which can automatically detect many kinds of bugs. > > Running QEMU on Valgrind with x86_64 hosts was not possible because > Valgrind aborts when memalign is called with an alignment larger than > 1 MiB. QEMU normally uses 2 MiB on Linux x86_64. > > Now the alignment is reduced to the page size when QEMU is running on > Valgrind. > > v2: > Instead of using the macro RUNNING_ON_VALGRIND from valgrind.h, > the patch now uses a hack from libvirt which tests for the pre-loaded > vgpreload_*.so shared libraries. This avoids the need for valgrind.h. > > Signed-off-by: Stefan Weil Applied. Thanks. Regards, Anthony Liguori > --- > oslib-posix.c | 22 +++++++++++++++++++--- > 1 files changed, 19 insertions(+), 3 deletions(-) > > diff --git a/oslib-posix.c b/oslib-posix.c > index dbc8ee8..6f29762 100644 > --- a/oslib-posix.c > +++ b/oslib-posix.c > @@ -36,8 +36,11 @@ extern int daemon(int, int); > #endif > > #if defined(__linux__)&& defined(__x86_64__) > - /* Use 2MB alignment so transparent hugepages can be used by KVM */ > + /* Use 2 MiB alignment so transparent hugepages can be used by KVM. > + Valgrind does not support alignments larger than 1 MiB, > + therefore we need special code which handles running on Valgrind. */ > # define QEMU_VMALLOC_ALIGN (512 * 4096) > +# define CONFIG_VALGRIND > #else > # define QEMU_VMALLOC_ALIGN getpagesize() > #endif > @@ -47,7 +50,11 @@ extern int daemon(int, int); > #include "trace.h" > #include "qemu_socket.h" > > - > +#if defined(CONFIG_VALGRIND) > +static int running_on_valgrind = -1; > +#else > +# define running_on_valgrind 0 > +#endif > > int qemu_daemon(int nochdir, int noclose) > { > @@ -89,7 +96,16 @@ void *qemu_vmalloc(size_t size) > void *ptr; > size_t align = QEMU_VMALLOC_ALIGN; > > - if (size< align) { > +#if defined(CONFIG_VALGRIND) > + if (running_on_valgrind< 0) { > + /* First call, test whether we are running on Valgrind. > + This is a substitute for RUNNING_ON_VALGRIND from valgrind.h. */ > + const char *ld = getenv("LD_PRELOAD"); > + running_on_valgrind = (ld != NULL&& strstr(ld, "vgpreload")); > + } > +#endif > + > + if (size< align || running_on_valgrind) { > align = getpagesize(); > } > ptr = qemu_memalign(align, size);