From patchwork Fri Jul 13 15:31:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 170911 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4E1AF2C03CD for ; Sat, 14 Jul 2012 01:31:58 +1000 (EST) Received: from localhost ([::1]:33457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SphqW-0004Wd-FS for incoming@patchwork.ozlabs.org; Fri, 13 Jul 2012 11:31:56 -0400 Received: from eggs.gnu.org ([208.118.235.92]:55618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SphqM-0004VO-Al for qemu-devel@nongnu.org; Fri, 13 Jul 2012 11:31:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SphqL-0000ep-7Q for qemu-devel@nongnu.org; Fri, 13 Jul 2012 11:31:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3441) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SphqK-0000ec-V3 for qemu-devel@nongnu.org; Fri, 13 Jul 2012 11:31:45 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6DFVhdr029867 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 13 Jul 2012 11:31:43 -0400 Received: from dhcp-5-188.str.redhat.com (vpn1-5-211.ams2.redhat.com [10.36.5.211]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q6DFVfXL013604; Fri, 13 Jul 2012 11:31:42 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 13 Jul 2012 17:31:40 +0200 Message-Id: <1342193500-5708-1-git-send-email-kwolf@redhat.com> In-Reply-To: <1342103249-20888-2-git-send-email-kwolf@redhat.com> References: <1342103249-20888-2-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH v2 1/2] coroutine-ucontext: Help valgrind understand coroutines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org valgrind tends to get confused and report false positives when you switch stacks and don't tell it about it. Signed-off-by: Kevin Wolf Reviewed-by: Paolo Bonzini --- v2: - Use unsigned for the stack ID - Older gccs don't know #pragma diagnostic push/pop, so replace them by explicitly switching back to error afterwards - They also don't like it inside a function... - Check in configure that the macro and the #pragma work configure | 20 ++++++++++++++++++++ coroutine-ucontext.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 0 deletions(-) diff --git a/configure b/configure index 500fe24..aae73f4 100755 --- a/configure +++ b/configure @@ -2855,6 +2855,22 @@ if compile_prog "" "" ; then fi ######################################## +# check if we have valgrind/valgrind.h + +valgrind_h=no +cat > $TMPC << EOF +#include +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +int main(void) { + VALGRIND_STACK_DEREGISTER(0); + return 0; +} +EOF +if compile_prog "" "" ; then + valgrind_h=yes +fi + +######################################## # check if environ is declared has_environ=no @@ -3380,6 +3396,10 @@ if test "$linux_magic_h" = "yes" ; then echo "CONFIG_LINUX_MAGIC_H=y" >> $config_host_mak fi +if test "$valgrind_h" = "yes" ; then + echo "CONFIG_VALGRIND_H=y" >> $config_host_mak +fi + if test "$has_environ" = "yes" ; then echo "CONFIG_HAS_ENVIRON=y" >> $config_host_mak fi diff --git a/coroutine-ucontext.c b/coroutine-ucontext.c index 5f43083..e3c450b 100644 --- a/coroutine-ucontext.c +++ b/coroutine-ucontext.c @@ -30,6 +30,10 @@ #include "qemu-common.h" #include "qemu-coroutine-int.h" +#ifdef CONFIG_VALGRIND_H +#include +#endif + enum { /* Maximum free pool size prevents holding too many freed coroutines */ POOL_MAX_SIZE = 64, @@ -43,6 +47,11 @@ typedef struct { Coroutine base; void *stack; jmp_buf env; + +#ifdef CONFIG_VALGRIND_H + unsigned int valgrind_stack_id; +#endif + } CoroutineUContext; /** @@ -159,6 +168,11 @@ static Coroutine *coroutine_new(void) uc.uc_stack.ss_size = stack_size; uc.uc_stack.ss_flags = 0; +#ifdef CONFIG_VALGRIND_H + co->valgrind_stack_id = + VALGRIND_STACK_REGISTER(co->stack, co->stack + stack_size); +#endif + arg.p = co; makecontext(&uc, (void (*)(void))coroutine_trampoline, @@ -185,6 +199,16 @@ Coroutine *qemu_coroutine_new(void) return co; } +#ifdef CONFIG_VALGRIND_H +/* Work around an unused variable in the valgrind.h macro... */ +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +static inline void valgrind_stack_deregister(CoroutineUContext *co) +{ + VALGRIND_STACK_DEREGISTER(co->valgrind_stack_id); +} +#pragma GCC diagnostic error "-Wunused-but-set-variable" +#endif + void qemu_coroutine_delete(Coroutine *co_) { CoroutineUContext *co = DO_UPCAST(CoroutineUContext, base, co_); @@ -196,6 +220,10 @@ void qemu_coroutine_delete(Coroutine *co_) return; } +#ifdef CONFIG_VALGRIND_H + valgrind_stack_deregister(co); +#endif + g_free(co->stack); g_free(co); }