From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:57879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKwxu-0000cr-GI for qemu-devel@nongnu.org; Mon, 31 Oct 2011 14:52:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RKwxt-0006mC-38 for qemu-devel@nongnu.org; Mon, 31 Oct 2011 14:52:10 -0400 Received: from v220110690675601.yourvserver.net ([78.47.199.172]:48178) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKwxs-0006m4-TY for qemu-devel@nongnu.org; Mon, 31 Oct 2011 14:52:09 -0400 Message-ID: <4EAEEE2D.7010905@weilnetz.de> Date: Mon, 31 Oct 2011 19:51:25 +0100 From: Stefan Weil MIME-Version: 1.0 References: <1319976446-12602-1-git-send-email-sw@weilnetz.de> <20111031182248.GJ27570@redhat.com> In-Reply-To: <20111031182248.GJ27570@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] Support running QEMU on Valgrind List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: Avi Kivity , Markus Armbruster , qemu-devel@nongnu.org Am 31.10.2011 19:22, schrieb Daniel P. Berrange: > On Sun, Oct 30, 2011 at 01:07:26PM +0100, 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. >> >> valgrind.h is a copy from Valgrind svn trunk r12226 with trailing >> whitespace stripped but otherwise unmodified, so it still raises lots >> of errors when checked with scripts/checkpatch.pl. >> >> It is included here to avoid a dependency on Valgrind. > > In libvirt we do the following fun hack to avoid a build dep on valgrind: > > const char *ld = getenv("LD_PRELOAD"); > if (ld && strstr(ld, "vgpreload")) { > fprintf(stderr, "Running under valgrind, disabling driver\n"); > return 0; > } > > Regards, > Daniel Thanks, Daniel. That works, although it is not the official way and it would fail if vgpreload were renamed. It is much slower than the offical macro, so the test would have to be done once and save the result in a static variable. As it solves the current problem with QEMU on Valgrind, this solution would be better than no solution, so if more people agree, it could be done like this. From other mails, I expect that the 2 MiB alignment will be used in more scenarios (any host and operating system which supports KVM). As far as I know, Valgrind runs on ARM, PPC, S390, BSD, ..., too, and latest valgrind.h is designed to support all those scenarios. I have no idea whether the vgpreload hack also works everywhere. Regards, Stefan