All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: Stefan Weil <sw@weilnetz.de>
Cc: qemu-devel@nongnu.org, Avi Kivity <avi@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2] Support running QEMU on Valgrind
Date: Tue, 01 Nov 2011 11:21:17 -0500	[thread overview]
Message-ID: <4EB01C7D.5070506@us.ibm.com> (raw)
In-Reply-To: <1320092986-2490-1-git-send-email-sw@weilnetz.de>

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<sw@weilnetz.de>

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);

      reply	other threads:[~2011-11-01 16:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-31 20:29 [Qemu-devel] [PATCH v2] Support running QEMU on Valgrind Stefan Weil
2011-11-01 16:21 ` Anthony Liguori [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EB01C7D.5070506@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.