From patchwork Fri May 22 16:07:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187168 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2643796ilb; Fri, 22 May 2020 09:15:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOpPbXceOtPeUoLeNGBPXaivnCJOfdcR8+fyFh2keKQ4xoXeffNC3+pGsgX4kyWjuCvUjo X-Received: by 2002:a5b:5c6:: with SMTP id w6mr25638007ybp.261.1590164119997; Fri, 22 May 2020 09:15:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164119; cv=none; d=google.com; s=arc-20160816; b=TgLaJO3ecINya6de3LAM4ig4o1KaspKqH1oSelStSOl4grxxbA4iW3up7E4dP2oS41 XfOfX95hllvITKnTK2mhM/QdhfesXS2pNmhML9Unx1/CcFwi3rZHFBlhXWEoivFHkRIg /BvGn+CJSfMPoZHGwpbCtt5PRMINe2UsRXX4iEQBnwASixBkSNZxT9+u9dSiqgAVcjSe mYh++EGwtpRFIJDfFU5VbbEBL7Yc6NIMWPzW3f54eoNteNO2niRyPs6BbK6N/BncXpqE xMpcDBrWHOe2Er0idQbui3s0jRBbgw9ikKIHgRloMSN5Ii+p6Sj+3bBO3usjsZ1Qoz9X Na4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=vLmwpV4CahL0pJZ+ld8j2cVRuvN4pfMS6sb1kFhB4zs=; b=jRhyw5Yfl60k6zzGoFpK2yECvrg70hnUNUXZ6zsggA/6eQH9h+Yda9yCcWDGuCaZ02 6Px6nw09BXegw9NqGmJZD3TNoCWG7KxnxUa7LmJINyTXzbSY8wqrjud/z8Ie44WqGYV+ Y7/OxEyQiSHse2l9KqcASJQhqzz5kiDMswZyIFJIqfdboIKsuy6DN6uoJaVzguFhn8J/ XU8gyol+K64UVFcVP5EvqLcs3o++w6xzLzc1Tj/kZyHz63Y4qRtlskDi69pN16L22M9c Qh5UJ5yRnnJsNorg9chHLU9em6els2iZJ5bV4KeYbB0aOSgANaQkmCtXMpFIvEdPbnBa 1klQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=s0Qa8JM5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q77si1486299ybg.70.2020.05.22.09.15.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:15:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=s0Qa8JM5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAKL-0002V4-OJ for patch@linaro.org; Fri, 22 May 2020 12:15:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAK7-0002T7-P2 for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:03 -0400 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:34232) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAK6-000662-8w for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:03 -0400 Received: by mail-pj1-x1041.google.com with SMTP id l73so2349970pjb.1 for ; Fri, 22 May 2020 09:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vLmwpV4CahL0pJZ+ld8j2cVRuvN4pfMS6sb1kFhB4zs=; b=s0Qa8JM5KVLZCBbZzIiGJU8iOkPsgRkpZoVYn1R6VuYtkxh4VueGuaTYapE9zoNLpF c8SPbIvVICU0FwYPFi9+KJJizgMHbOynsGPFFSdW5bIRt+l+vdsMNL/5KgkvN1RaoZHH 755W2UUf/zyon3kX8vBU5o4ZiBuRPdAChYK5BS1B+p/z0G2DdWyXX4TTBJvO51HMTglw c0DxW8Jy59itXNLCE8XWE1SonG7W9zxLrsdqd9acNWA4PsnDf9NoFGP6lwoBPgkYceGX owbXhUva+9VsrwrpxTcQdcX4zNQUjtHoKrlnqeOvRBK/YKlaL/XE0fOKjZSkLSaY2J4A RxNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vLmwpV4CahL0pJZ+ld8j2cVRuvN4pfMS6sb1kFhB4zs=; b=gQJf+ARuasCDqC/XkOa3LPEVv5hPwxDm0cqcxT7L5w+MCf9O7KIQFHQzHOQqJDXdxY BUqu+VmQO5C3kStoIHcy6jIaFVv2NoRSk5dvEehjCVP6JgWerYUkYNGsHuelKs2E5R1e W7ygeLqZy6E2MGZopcVYNrnWkXxiELJxSZYEotnfrhRg6hZh+oG/k+c5UWTebjPKb6vY SN0aJPup4eG3eptXXP4ELLYYi8Zcjcl1oXbvmOyT8SVDicl3LMcXZVYTSqtHf5OlP7u3 /Ms1i28sMvZ1DEFPeVM24nCsxGglxuY3Bzj1vHj6RmziI6fueAaF6pABZnsMibuAOmPI pqYA== X-Gm-Message-State: AOAM531prDn9grBEagzY8gHWPnwK5nGtDxw99dEkwH4RjkEYdH2yBfiJ F4DdfMmUU2ymWMQk1DHhff/cezywsMq6hA== X-Received: by 2002:a17:90b:ed2:: with SMTP id gz18mr5434570pjb.22.1590164100020; Fri, 22 May 2020 09:15:00 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:14:59 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 01/19] configure: add --enable-tsan flag + fiber annotations for coroutine-ucontext Date: Fri, 22 May 2020 12:07:37 -0400 Message-Id: <20200522160755.886-2-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::1041; envelope-from=robert.foley@linaro.org; helo=mail-pj1-x1041.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org, Lingfeng Yang Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Lingfeng Yang We tried running QEMU under tsan in 2016, but tsan's lack of support for longjmp-based fibers was a blocker: https://groups.google.com/forum/#!topic/thread-sanitizer/se0YuzfWazw Fortunately, thread sanitizer gained fiber support in early 2019: https://reviews.llvm.org/D54889 This patch brings tsan support upstream by importing the patch that annotated QEMU's coroutines as tsan fibers in Android's QEMU fork: https://android-review.googlesource.com/c/platform/external/qemu/+/844675 Tested with '--enable-tsan --cc=clang-9 --cxx=clang++-9 --disable-werror' configure flags. Signed-off-by: Lingfeng Yang Signed-off-by: Emilio G. Cota [cota: minor modifications + configure changes] Signed-off-by: Robert Foley [RF: minor changes to clean up checkpatch warnings/errors] --- configure | 39 ++++++++++++++++ util/coroutine-ucontext.c | 97 +++++++++++++++++++++++++++++++++++---- 2 files changed, 127 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/configure b/configure index 26084fc53a..c95c54fb48 100755 --- a/configure +++ b/configure @@ -395,6 +395,7 @@ gprof="no" debug_tcg="no" debug="no" sanitizers="no" +tsan="no" fortify_source="" strip_opt="yes" tcg_interpreter="no" @@ -1150,6 +1151,10 @@ for opt do ;; --disable-sanitizers) sanitizers="no" ;; + --enable-tsan) tsan="yes" + ;; + --disable-tsan) tsan="no" + ;; --enable-sparse) sparse="yes" ;; --disable-sparse) sparse="no" @@ -1750,6 +1755,7 @@ Advanced options (experts only): --with-pkgversion=VERS use specified string as sub-version of the package --enable-debug enable common debug build options --enable-sanitizers enable default sanitizers + --enable-tsan enable thread sanitizer --disable-strip disable stripping binaries --disable-werror disable compilation abort on warning --disable-stack-protector disable compiler-provided stack protection @@ -6176,6 +6182,27 @@ if test "$fuzzing" = "yes" ; then fi fi +# Thread sanitizer is, for now, much noisier than the other sanitizers; +# keep it separate until that is not the case. +have_tsan=no +have_tsan_iface_fiber=no +if test "$tsan" = "yes" ; then + write_c_skeleton + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then + have_tsan=yes + fi + cat > $TMPC << EOF +#include +int main(void) { + __tsan_create_fiber(0); + return 0; +} +EOF + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then + have_tsan_iface_fiber=yes + fi +fi + ########################################## # check for libpmem @@ -6277,6 +6304,14 @@ if test "$have_asan" = "yes"; then "Without code annotation, the report may be inferior." fi fi +if test "$have_tsan" = "yes" ; then + if test "$have_tsan_iface_fiber" = "yes" ; then + QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS" + QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS" + else + echo "Cannot enable TSAN due to missing fiber annotation interface." + fi +fi if test "$have_ubsan" = "yes"; then QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS" QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS" @@ -7365,6 +7400,10 @@ if test "$have_asan_iface_fiber" = "yes" ; then echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak fi +if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then + echo "CONFIG_TSAN=y" >> $config_host_mak +fi + if test "$has_environ" = "yes" ; then echo "CONFIG_HAS_ENVIRON=y" >> $config_host_mak fi diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c index bd593e61bc..a3dc78e67a 100644 --- a/util/coroutine-ucontext.c +++ b/util/coroutine-ucontext.c @@ -37,18 +37,33 @@ #endif #endif +#ifdef CONFIG_TSAN +#include +#endif + typedef struct { Coroutine base; void *stack; size_t stack_size; sigjmp_buf env; + void *tsan_co_fiber; + void *tsan_caller_fiber; + #ifdef CONFIG_VALGRIND_H unsigned int valgrind_stack_id; #endif } CoroutineUContext; +#define UC_DEBUG 0 +#if UC_DEBUG && defined(CONFIG_TSAN) +#define UC_TRACE(fmt, ...) fprintf(stderr, "%s:%d:%p " fmt "\n", \ + __func__, __LINE__, __tsan_get_current_fiber(), ##__VA_ARGS__); +#else +#define UC_TRACE(fmt, ...) +#endif + /** * Per-thread coroutine bookkeeping */ @@ -65,7 +80,20 @@ union cc_arg { int i[2]; }; -static void finish_switch_fiber(void *fake_stack_save) +/* QEMU_ALWAYS_INLINE only does so if __OPTIMIZE__, so we cannot use it. */ +static inline __attribute__((always_inline)) +void on_new_fiber(CoroutineUContext *co) +{ +#ifdef CONFIG_TSAN + co->tsan_co_fiber = __tsan_create_fiber(0); /* flags: sync on switch */ + co->tsan_caller_fiber = __tsan_get_current_fiber(); + UC_TRACE("Create new TSAN co fiber. co: %p co fiber: %p caller fiber: %p ", + co, co->tsan_co_fiber, co->tsan_caller_fiber); +#endif +} + +static inline __attribute__((always_inline)) +void finish_switch_fiber(void *fake_stack_save) { #ifdef CONFIG_ASAN const void *bottom_old; @@ -78,18 +106,40 @@ static void finish_switch_fiber(void *fake_stack_save) leader.stack_size = size_old; } #endif +#ifdef CONFIG_TSAN + if (fake_stack_save) { + __tsan_release(fake_stack_save); + __tsan_switch_to_fiber(fake_stack_save, 0); /* 0=synchronize */ + } +#endif } -static void start_switch_fiber(void **fake_stack_save, - const void *bottom, size_t size) +static inline __attribute__((always_inline)) void start_switch_fiber( + CoroutineAction action, void **fake_stack_save, + const void *bottom, size_t size, void *new_fiber) { #ifdef CONFIG_ASAN - __sanitizer_start_switch_fiber(fake_stack_save, bottom, size); + if (action == COROUTINE_TERMINATE) { + __sanitizer_start_switch_fiber( + action == COROUTINE_TERMINATE ? NULL : fake_stack_save, + bottom, size); + } +#endif +#ifdef CONFIG_TSAN + void *curr_fiber = + __tsan_get_current_fiber(); + __tsan_acquire(curr_fiber); + + UC_TRACE("Current fiber: %p.", curr_fiber); + *fake_stack_save = curr_fiber; + UC_TRACE("Switch to fiber %p", new_fiber); + __tsan_switch_to_fiber(new_fiber, 0); /* 0=synchronize */ #endif } static void coroutine_trampoline(int i0, int i1) { + UC_TRACE("Start trampoline"); union cc_arg arg; CoroutineUContext *self; Coroutine *co; @@ -104,21 +154,34 @@ static void coroutine_trampoline(int i0, int i1) /* Initialize longjmp environment and switch back the caller */ if (!sigsetjmp(self->env, 0)) { - start_switch_fiber(&fake_stack_save, - leader.stack, leader.stack_size); + UC_TRACE("Current fiber: %p. Set co %p to env 0x%lx", + __tsan_get_current_fiber(), self, (unsigned long)self->env); + start_switch_fiber( + COROUTINE_YIELD, + &fake_stack_save, + leader.stack, + leader.stack_size, + self->tsan_caller_fiber); + UC_TRACE("Jump to co %p caller fiber %p env 0x%lx", + co, self->tsan_caller_fiber, *(unsigned long *)co->entry_arg); siglongjmp(*(sigjmp_buf *)co->entry_arg, 1); } + UC_TRACE("After first siglongjmp"); + finish_switch_fiber(fake_stack_save); while (true) { co->entry(co->entry_arg); + UC_TRACE("switch from co %p to caller co %p fiber %p\n", + co, co->caller, self->tsan_caller_fiber); qemu_coroutine_switch(co, co->caller, COROUTINE_TERMINATE); } } Coroutine *qemu_coroutine_new(void) { + UC_TRACE("Start new coroutine"); CoroutineUContext *co; ucontext_t old_uc, uc; sigjmp_buf old_env; @@ -154,12 +217,16 @@ Coroutine *qemu_coroutine_new(void) arg.p = co; + on_new_fiber(co); makecontext(&uc, (void (*)(void))coroutine_trampoline, 2, arg.i[0], arg.i[1]); /* swapcontext() in, siglongjmp() back out */ if (!sigsetjmp(old_env, 0)) { - start_switch_fiber(&fake_stack_save, co->stack, co->stack_size); + start_switch_fiber( + COROUTINE_YIELD, + &fake_stack_save, + co->stack, co->stack_size, co->tsan_co_fiber); swapcontext(&old_uc, &uc); } @@ -185,6 +252,7 @@ static inline void valgrind_stack_deregister(CoroutineUContext *co) void qemu_coroutine_delete(Coroutine *co_) { + UC_TRACE("Nuking co %p from orbit", co_); CoroutineUContext *co = DO_UPCAST(CoroutineUContext, base, co_); #ifdef CONFIG_VALGRIND_H @@ -209,6 +277,10 @@ qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, { CoroutineUContext *from = DO_UPCAST(CoroutineUContext, base, from_); CoroutineUContext *to = DO_UPCAST(CoroutineUContext, base, to_); + UC_TRACE("from to: %p %p uc: %p %p. fibers: %p %p caller fibers: %p %p\n", + from_, to_, from, to, + from->tsan_co_fiber, to->tsan_co_fiber, + from->tsan_caller_fiber, to->tsan_caller_fiber); int ret; void *fake_stack_save = NULL; @@ -216,8 +288,8 @@ qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, ret = sigsetjmp(from->env, 0); if (ret == 0) { - start_switch_fiber(action == COROUTINE_TERMINATE ? - NULL : &fake_stack_save, to->stack, to->stack_size); + start_switch_fiber(action, &fake_stack_save, + to->stack, to->stack_size, to->tsan_co_fiber); siglongjmp(to->env, action); } @@ -231,6 +303,13 @@ Coroutine *qemu_coroutine_self(void) if (!current) { current = &leader.base; } +#ifdef CONFIG_TSAN + if (!leader.tsan_co_fiber) { + leader.tsan_co_fiber = __tsan_get_current_fiber(); + UC_TRACE("For co %p set leader co fiber to %p", + current, leader.tsan_co_fiber); + } +#endif return current; } From patchwork Fri May 22 16:07:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187172 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2645885ilb; Fri, 22 May 2020 09:17:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5tHt1hQ18cG9nGwit19dQkFNmTc/lbnXmqyTz7bPfP8Cg3vvc9P+wPTjqdehEi6aB4hLP X-Received: by 2002:ac8:4e06:: with SMTP id c6mr16800851qtw.360.1590164265981; Fri, 22 May 2020 09:17:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164265; cv=none; d=google.com; s=arc-20160816; b=smMO5pNFnatUQyFmXS2p3ZytnSfZ/L33ahuWhF2EaTJPOvk8K8xVjBtX3AeC8NDDDQ 0xAhc+SdSZbUL1xyF7H5gR+VJuLODfPK8eRNowtRLviQkCi2BFhEBBqs0/nKyBsKHhaW vq5S/RTQWOdi1kXGriKg31QUMEcqQ8q9nRv5cyMLkG7AgX6XSjexBo5ghBfXPy/C9BRD lWp4xePkoboKacwXJu+ap5fKa8Cnwsu7v/48di2sZL0wAMtupYIGYECkVNBcsIRnHSSd YDODEUnvExnTvN4BBpdjDYhJ2MQ09BGX7NRX9DsyDGXjn5+O9OH5K8U6wRsyCpiIy9uu JPjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=gyX/K3LZb5/HWyZyTqUsQNfRcZPtWqUo2ougwCy84HA=; b=LYbA9FUoZvjLcrSOKzE7hVOwKdIxg0kIJGBlwrpKkWKoh3WfNMYTJOoFtt28g/hbVj OLUWTyexQK5mu263G2JK6oqXF7HF2u2OrzoIivV3LghUd70J3SiFm03SSPnWvF20USBQ UlKX0K0CNyLOfItttt2B9Y18S+fcFxAAaDgS8444hKlWo6amVTWUqnVI9rkXPMEKsM8/ +Ad6JXG/kJyCPR0xkBdQarykJCrgZC68k7gSqAe7DBM8wdr7lrEcXGYNn4gtsegYt8bR StAjhxqEkPYNerKW6IoupcczyDdqJi9A1CLqSAzSarDPAGCtNs7HOBUSPKpdj1e6wuku AH8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ONf2Ckbo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o27si5633848qtt.159.2020.05.22.09.17.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:17:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ONf2Ckbo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAMj-0006OZ-GS for patch@linaro.org; Fri, 22 May 2020 12:17:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAK8-0002UY-VR for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:04 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:44593) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAK7-00067J-U0 for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:04 -0400 Received: by mail-pl1-x642.google.com with SMTP id w19so4558802ply.11 for ; Fri, 22 May 2020 09:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gyX/K3LZb5/HWyZyTqUsQNfRcZPtWqUo2ougwCy84HA=; b=ONf2Ckbo+/goDD1b0DdcsqN+YxZclLMARgdHRqRTtf0UIaoHcIAJARRqsps+asbCE6 TJTHBFvRfmNJSdwfxmxYRXUfhdZ+OkD3/whX5pI0MzUtrI8YmeB6tuNUcsES5FG0v89+ pGMGC/iMx6yzcfn0RB5sAp3V5LNEe5dobsoZ5HZVQEaPOogPN4XdiPj3B7yy6k4rSvIz GWjsOdr1l2C/m/vpkIKEOSOcy2ooFk3hcVwKNh9xXkLP3/seU7074n/+bzdsDND8Akx4 7ScG9GNhA1wIzXbpzsqK+kX1YeWjb0XnTP5ONO57Vh5+WXxkC8CZqZTDzUhhsK+jYELk Hznw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gyX/K3LZb5/HWyZyTqUsQNfRcZPtWqUo2ougwCy84HA=; b=dj4l0yttWdE5QC4ftrvbO6p14i4GblDkQ59kk58/cS7938+AGcNggyupY/UFAlMRBe VeoM+xBXDTqUf5xIReXikP05xpSnxu6Ho7BTDnEwvQOViStf3W7kzRNn3O8rqSoNZ58r ApEsBzrddV5/AfR3dK/zxX7E6pgGd8LWi0CRkVDWj6sKuBlOcl1oYcuhgkzwfszS+sMC o5L+s0opxjzyF1VYKDlpFaZ/RJuPy43ecOwayvBECSt992T9an6tBHDwe+mnRRbDUE2k QbBjavwbMimIAhORzyCWPJuJRzd6s0PXlmV8gk4V2CS378JYhfVW+asYhB21XDDiCWX8 xAfw== X-Gm-Message-State: AOAM532XZ8qufK4zZ2Y3rL1T+Ak0/AscPrma9oAemsFKm9unO9t+cr6B 74tFeWRrV3YNa9ClYLiumnZ3Dzih0K0KcQ== X-Received: by 2002:a17:90a:268f:: with SMTP id m15mr5747086pje.190.1590164102172; Fri, 22 May 2020 09:15:02 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:01 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 02/19] cpu: convert queued work to a QSIMPLEQ Date: Fri, 22 May 2020 12:07:38 -0400 Message-Id: <20200522160755.886-3-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::642; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x642.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Instead of open-coding it. While at it, make sure that all accesses to the list are performed while holding the list's lock. Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley --- cpus-common.c | 25 ++++++++----------------- cpus.c | 14 ++++++++++++-- hw/core/cpu.c | 1 + include/hw/core/cpu.h | 6 +++--- 4 files changed, 24 insertions(+), 22 deletions(-) -- 2.17.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/cpus-common.c b/cpus-common.c index 55d5df8923..210fc7fc39 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -97,7 +97,7 @@ void cpu_list_remove(CPUState *cpu) } struct qemu_work_item { - struct qemu_work_item *next; + QSIMPLEQ_ENTRY(qemu_work_item) node; run_on_cpu_func func; run_on_cpu_data data; bool free, exclusive, done; @@ -106,13 +106,7 @@ struct qemu_work_item { static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi) { qemu_mutex_lock(&cpu->work_mutex); - if (cpu->queued_work_first == NULL) { - cpu->queued_work_first = wi; - } else { - cpu->queued_work_last->next = wi; - } - cpu->queued_work_last = wi; - wi->next = NULL; + QSIMPLEQ_INSERT_TAIL(&cpu->work_list, wi, node); wi->done = false; qemu_mutex_unlock(&cpu->work_mutex); @@ -306,17 +300,14 @@ void process_queued_cpu_work(CPUState *cpu) { struct qemu_work_item *wi; - if (cpu->queued_work_first == NULL) { + qemu_mutex_lock(&cpu->work_mutex); + if (QSIMPLEQ_EMPTY(&cpu->work_list)) { + qemu_mutex_unlock(&cpu->work_mutex); return; } - - qemu_mutex_lock(&cpu->work_mutex); - while (cpu->queued_work_first != NULL) { - wi = cpu->queued_work_first; - cpu->queued_work_first = wi->next; - if (!cpu->queued_work_first) { - cpu->queued_work_last = NULL; - } + while (!QSIMPLEQ_EMPTY(&cpu->work_list)) { + wi = QSIMPLEQ_FIRST(&cpu->work_list); + QSIMPLEQ_REMOVE_HEAD(&cpu->work_list, node); qemu_mutex_unlock(&cpu->work_mutex); if (wi->exclusive) { /* Running work items outside the BQL avoids the following deadlock: diff --git a/cpus.c b/cpus.c index 5670c96bcf..af44027549 100644 --- a/cpus.c +++ b/cpus.c @@ -97,9 +97,19 @@ bool cpu_is_stopped(CPUState *cpu) return cpu->stopped || !runstate_is_running(); } +static inline bool cpu_work_list_empty(CPUState *cpu) +{ + bool ret; + + qemu_mutex_lock(&cpu->work_mutex); + ret = QSIMPLEQ_EMPTY(&cpu->work_list); + qemu_mutex_unlock(&cpu->work_mutex); + return ret; +} + static bool cpu_thread_is_idle(CPUState *cpu) { - if (cpu->stop || cpu->queued_work_first) { + if (cpu->stop || !cpu_work_list_empty(cpu)) { return false; } if (cpu_is_stopped(cpu)) { @@ -1498,7 +1508,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) cpu = first_cpu; } - while (cpu && !cpu->queued_work_first && !cpu->exit_request) { + while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) { atomic_mb_set(&tcg_current_rr_cpu, cpu); current_cpu = cpu; diff --git a/hw/core/cpu.c b/hw/core/cpu.c index 5284d384fb..77703d62b7 100644 --- a/hw/core/cpu.c +++ b/hw/core/cpu.c @@ -368,6 +368,7 @@ static void cpu_common_initfn(Object *obj) cpu->nr_threads = 1; qemu_mutex_init(&cpu->work_mutex); + QSIMPLEQ_INIT(&cpu->work_list); QTAILQ_INIT(&cpu->breakpoints); QTAILQ_INIT(&cpu->watchpoints); diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 07f7698155..d78ff1d165 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -331,8 +331,8 @@ struct qemu_work_item; * @opaque: User data. * @mem_io_pc: Host Program Counter at which the memory was accessed. * @kvm_fd: vCPU file descriptor for KVM. - * @work_mutex: Lock to prevent multiple access to queued_work_*. - * @queued_work_first: First asynchronous work pending. + * @work_mutex: Lock to prevent multiple access to @work_list. + * @work_list: List of pending asynchronous work. * @trace_dstate_delayed: Delayed changes to trace_dstate (includes all changes * to @trace_dstate). * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask). @@ -376,7 +376,7 @@ struct CPUState { sigjmp_buf jmp_env; QemuMutex work_mutex; - struct qemu_work_item *queued_work_first, *queued_work_last; + QSIMPLEQ_HEAD(, qemu_work_item) work_list; CPUAddressSpace *cpu_ases; int num_ases; From patchwork Fri May 22 16:07:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187169 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2643977ilb; Fri, 22 May 2020 09:15:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9xMYBv/KFub41zbpp/fRRJDz/QfHgoHVR+0YGQhAhIMBvDSL8Bgs3tZ3T8KXbbNy4bb8n X-Received: by 2002:a25:83c7:: with SMTP id v7mr16959649ybm.252.1590164131551; Fri, 22 May 2020 09:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164131; cv=none; d=google.com; s=arc-20160816; b=O5Uq946RbA1rSwXmaUn1owDQr2IA7pWxaTVl7qOj3zqn0q6lwz4c7HHO7CEYUJhhNZ xZcSUhw8zNxNk3IWg6uwIITfp4cz5K3l4rLphynNE3cK/f+0HFid+/kStTTjWvtJy6S1 crWKPMJjEQbNFjOgB1ZEWob1o2d2yqAdztnhGDAJaonh6x2pXrkQBnRgAa1UL4QdZONS BLn5GIXs33NFVaqygi9WiXGaE7aPoyLOBKYZWqQkeFbVsOdLHYHh8jXF1lxE2tG5a7eK 6zVEUwhe/XdcGbm6myP4EsM5v9K9rYaCbhlEtyDKWE4TTkDK/zxvpeSvWHzjg4hQrYNd asVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=wgvUXG0Vlnhy8HNXWH/V4PveTdhkLExBdueTuZ9bPNI=; b=SKkc9EVOB6y4e4KyDwpqrj5mokPgKNW8inGOO71AZpDkIp2Z+XttMHd8ydYjpCwDj5 M+0iSwVTN8adqmXXIZlos+t2lE1Y+6cZNDngRteLJ8LJDMrzGZFS+3zENqHYuHV3z5f+ EcMEU8PizjFuPHHFlCGp7tXs1EcfFZN+KRGZyvgnbUnfn8Y1zEKt70XDG6WbjVu43hRM fGY+Zpay5s/a/mRPZrXYgLNaz+IY0svmdMaJuZyDzPiUw/qeL4qwn7bz3wZugtFrm+nb nuoJa22DQDiMwJ0HEYRTERj/lZPCuAq6152fnt0DVhnrI6tv4wHiR1MapMpBrtfT3lwp GOGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ccGLHO1w; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m191si8909859ybm.283.2020.05.22.09.15.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:15:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ccGLHO1w; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAKZ-0002ZY-2V for patch@linaro.org; Fri, 22 May 2020 12:15:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKA-0002Xc-Mv for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:06 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:40396) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAK9-00067X-S5 for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:06 -0400 Received: by mail-pl1-x633.google.com with SMTP id t16so4573432plo.7 for ; Fri, 22 May 2020 09:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wgvUXG0Vlnhy8HNXWH/V4PveTdhkLExBdueTuZ9bPNI=; b=ccGLHO1w5NQPtQ7Rw2MtZFfVYhJ3tP7AAvuRI3xxgode+dWuOLf/ZlQHaYOhMsAEV+ 6OuC/NlscC8vvm/Hntt1b/xO0ulUmOmf8IXNR/elhsvI+Squf/LRqtA9LcpxnNqKyQo1 dzn3qHuonfPCP+BCcmR1h60l6BKBHTmoNr81QtxxmMr5FopnsbOH7SAgAlmYfaOavJ/a lXv4HuWeqvJo8WuBR2B9WcVTRD4KFVfOa8nmS7OagkCM/wO3D0CO+gSZv58KjXK8IX2b QBylJNVX295sMt9wW8jHI3jvTSbMg3q1eXkLvLAzwJE/507XtVYaGCKFBUrx+5E6xl2q 20Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wgvUXG0Vlnhy8HNXWH/V4PveTdhkLExBdueTuZ9bPNI=; b=ZFMkpmaMSwWMWObS2a5s2rllt1Xu5HBlnh1RoMBdalAcOlCUf6g8cvRMddVutnrX0S lNzTKLFTGkrZJ8Dj0dk04UiHV8tpH/wGZGHNjsG5cu+wT7fpQ6MLNC+aB0HH29EfMhdh NkciVFUx4JN/pFURkfPDCu6rctR8DORgaRyv9DleqGoJAhNd4CVPSkHtTUh2lRgxJRTn DmlZaYu6gGnQRtN6ONaYdLcTvJqu+hFEWut7P1teWf/rGuThpbofCMOejugbadF8/wwl afgPRxOrrkNN9O6odE31WoMN1YXcOPxevMjDyARPn7OqtBH3PZ88wQqQq3lFSZiA3r1a lxKQ== X-Gm-Message-State: AOAM532QksKuXDZwA9rdv2MGiGhzMmMEmuXOQa8BMboFaFhtZlXN9xfZ tVcZJKhDDREWm7JgvZM96H587nY0WS80zA== X-Received: by 2002:a17:90a:c201:: with SMTP id e1mr5603313pjt.162.1590164104261; Fri, 22 May 2020 09:15:04 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:03 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 03/19] thread: add qemu_spin_destroy Date: Fri, 22 May 2020 12:07:39 -0400 Message-Id: <20200522160755.886-4-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x633.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" It will be used for TSAN annotations. Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley --- include/qemu/thread.h | 3 +++ 1 file changed, 3 insertions(+) -- 2.17.1 diff --git a/include/qemu/thread.h b/include/qemu/thread.h index d22848138e..e50a073889 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -215,6 +215,9 @@ static inline void qemu_spin_init(QemuSpin *spin) __sync_lock_release(&spin->value); } +static inline void qemu_spin_destroy(QemuSpin *spin) +{ } + static inline void qemu_spin_lock(QemuSpin *spin) { while (unlikely(__sync_lock_test_and_set(&spin->value, true))) { From patchwork Fri May 22 16:07:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187170 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2644062ilb; Fri, 22 May 2020 09:15:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkF9lGtOSpLCeym5ODBgFuRUiBTqPDGIiKa4Ll3TZ9U3s4C92Jq9tJIY/Ugari5zx6GHsE X-Received: by 2002:a25:818a:: with SMTP id p10mr8364975ybk.160.1590164136685; Fri, 22 May 2020 09:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164136; cv=none; d=google.com; s=arc-20160816; b=J8ugI0OQhdPgOpK9+P5xkC74bz0nAeeATm6c8EgvTnWeCFcE+TebzFRpE4NxV1geCt Tyfd4ERaatavnZkEZ3xgRWvjJGmlzjjFlZ4623mdBPocGDZGgZ8uktrj+zFzr9/NrSnz bz80XbaqAsfreuoTdvbwBu3GwF7V3y5kcdpCWVnZ6J4WTisvA+DgAjMnoEKo0lF4c6G4 aOEV+OheTx3QR7RVwavzY28kBZaaCnyIgynnACNt+TPIBTHdGNCiTGABvoQ39umaPlc1 JpHIDRewTkFv+u+SefM79uWHhZCJawqWpaiTzchQGmmLvAcoGR+FV23dbhB1ftM8X7oN OHMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=aGYJ5nJt/JAH6FWXmjwSAlg0Omv/+y0t2oEMaylOlqc=; b=XOVe+eZkRICRNdO/k1JrPGwpBW3pKo+fIqSGRV80RsZeClQmQL9Cw0SFKGce8+D8dI tzzQFfGca1rnAHIfR8y+M8o8N9yFL+Ywx51I63MFWSnn2o6DEPC5KNl72EZk/HQGnw6U k7TQx3S7Dz+7h81p3YK+PXr2wf7egZyePKfbSFoQiqRUvvIBVn5FXRydj0XrIukVsDOh Z/mcYDKbz/b+KTrGNOI3giKO6IOYNWsXrz6yV2sos1K7ry3ZGsnHo4KGzAQpeSDoNC/B pnN6ytA5tf3+KxVRy1ULiZtmwaSQbpuG7NNRzyh7ugEsYcLBezVU7FJCdeKFfZdG7KHd fG/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=sJInSJ3s; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e205si8917797yba.419.2020.05.22.09.15.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:15:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=sJInSJ3s; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAKe-0002iF-1b for patch@linaro.org; Fri, 22 May 2020 12:15:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40344) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKD-0002cU-2Q for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:09 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:42814) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKC-00067n-0V for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:08 -0400 Received: by mail-pg1-x543.google.com with SMTP id n11so5188528pgl.9 for ; Fri, 22 May 2020 09:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aGYJ5nJt/JAH6FWXmjwSAlg0Omv/+y0t2oEMaylOlqc=; b=sJInSJ3sEElKT1TpnsSXQm2I4F8ZElU4nNyi6Zssq0Nup1GjSWFVvQtzJBaPe4Owf3 6QeHbv55Djq1I7FTChBU5zJ7dzhwzTkhpm7yNDueRr7jAKm1vEwbUVJkzlIBY3m3HFQt zr9y5Jr66h4ZXg0dWtt5GB6CfB+WeMwk6zCgrUI6Ngj7rKN4/zinW+jsB8NU4Z/n1kVO xr/LTa8lOPhlnSn6Hxt1lHSoPEZHni/AsvzTFLWnaZ5yv2HOsYNlh/RKiNGk19yhHMXR D10vS9C6fBqLSysHU9HlceOGmCKV7NhnCh+EJeCNVSvzUo6+NJFlXTQWaSxnoKShdj5D U2nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aGYJ5nJt/JAH6FWXmjwSAlg0Omv/+y0t2oEMaylOlqc=; b=b84yuMDqU7PhpFQ1uJPhqtdkLwHlYnvs4tBhigRWMYB2xA4/BC5xz5vrn2HfMABKqo QkYRvohf7kD8mI6MAO/+j0lrglAGGEYnsBi2I7XHWvAyAFtqAGekEVQmHzbG0MMQatHe GL4RFxpcsv9BzLxt1CYLMDWPZnlJ+FgGqU6pTQLJ43sxSY9gGK1HA3XsHNs7msTdTuLS zKEnJewIwngmRyi9LGcKpiq97nDHhIHhjLIU/Q6MtWj5nRdP42txrltAa2lROM9HP3xg 3GJlLzsfyxGbFWs8eRcrH43QCP+MtUA3vYxosFM5AeZphKCgyglvdD8Oi5KeXEpeYA4f dyrw== X-Gm-Message-State: AOAM531g2ZOJEnYavSQQGxF/tbMWxZY0cq5cyut6BjtXkBFuv+ZgrwLa y+jvmdyRd0Tj46IpPirbxwtEbsiU0LTqaA== X-Received: by 2002:a65:400d:: with SMTP id f13mr14084387pgp.336.1590164106295; Fri, 22 May 2020 09:15:06 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:05 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 04/19] cputlb: destroy CPUTLB with tlb_destroy Date: Fri, 22 May 2020 12:07:40 -0400 Message-Id: <20200522160755.886-5-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::543; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x543.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" I was after adding qemu_spin_destroy calls, but while at it I noticed that we are leaking some memory. Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley --- accel/tcg/cputlb.c | 15 +++++++++++++++ exec.c | 1 + include/exec/exec-all.h | 8 ++++++++ 3 files changed, 24 insertions(+) -- 2.17.1 diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index eb2cf9de5e..1e815357c7 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -270,6 +270,21 @@ void tlb_init(CPUState *cpu) } } +void tlb_destroy(CPUState *cpu) +{ + CPUArchState *env = cpu->env_ptr; + int i; + + qemu_spin_destroy(&env_tlb(env)->c.lock); + for (i = 0; i < NB_MMU_MODES; i++) { + CPUTLBDesc *desc = &env_tlb(env)->d[i]; + CPUTLBDescFast *fast = &env_tlb(env)->f[i]; + + g_free(fast->table); + g_free(desc->iotlb); + } +} + /* flush_all_helper: run fn across all cpus * * If the wait flag is set then the src cpu's helper will be queued as diff --git a/exec.c b/exec.c index 5162f0d12f..da3d60b034 100644 --- a/exec.c +++ b/exec.c @@ -892,6 +892,7 @@ void cpu_exec_unrealizefn(CPUState *cpu) { CPUClass *cc = CPU_GET_CLASS(cpu); + tlb_destroy(cpu); cpu_list_remove(cpu); if (cc->vmsd != NULL) { diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 8792bea07a..3cf88272df 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -124,6 +124,11 @@ void cpu_address_space_init(CPUState *cpu, int asidx, * @cpu: CPU whose TLB should be initialized */ void tlb_init(CPUState *cpu); +/** + * tlb_destroy - destroy a CPU's TLB + * @cpu: CPU whose TLB should be destroyed + */ +void tlb_destroy(CPUState *cpu); /** * tlb_flush_page: * @cpu: CPU whose TLB should be flushed @@ -284,6 +289,9 @@ void tlb_set_page(CPUState *cpu, target_ulong vaddr, static inline void tlb_init(CPUState *cpu) { } +static inline void tlb_destroy(CPUState *cpu) +{ +} static inline void tlb_flush_page(CPUState *cpu, target_ulong addr) { } From patchwork Fri May 22 16:07:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187182 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2650261ilb; Fri, 22 May 2020 09:23:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjz/q5iIZcUHCQMEA7vSrqmTNGjt5olfuUTIcXuPMf3bdlfKqGIuVux1yGpVNwq6Hd6tw/ X-Received: by 2002:a37:7143:: with SMTP id m64mr16990681qkc.215.1590164586505; Fri, 22 May 2020 09:23:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164586; cv=none; d=google.com; s=arc-20160816; b=zAsrFiTfhGUM2qJdx41dOGZqdESSF1wSv5xbS9acL/K6K62tp964rf7PMvhyJ/iFkr 0/8HVHJ1SWM4uEzRa/sChzUxEu3Z3OoX4QWzKixEIX4/guBfN/1MtTpzwOrxm807VzKZ OhfDO0hx/LVhMKXGPx2xNQK0R5JVaPElOZOvAOm8hjTRcqevADIOjH46k+T3knoL/orE a/ZUmIT4ve2RaCXRxsA1rAhQ8Yeq9G8iAnjuoQ8fsiP/yejZj1Bh8t1SKni909IXSkGM 5qRxiMlLEiZDqVktRwwR0OyKX8IHKqI0XONGc0G4Jf/e0Co/+b+AyciuU8qo8W4thFxC zlzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=kxh2o1V8iXkuJj8JRvzQtcAUGmlKoLZ53V+la2Fi9CI=; b=XfhLZyd+46u68bbuAV6OV7iy4EkL3QSHZVPzyeb6abekJ2xQUAepfegv88E85WLyvJ bXW9zRk6bpNenU4+HRDiNo5goFS/wD5dl6OVl3nOVueUIryAkEFdF9uIERrHnYLqs/IM I0v4+ZT8OGcN6zLAs5yLdk+DXFkNz6PGZ75O9vP5ijpSDfVY6Ufmi3x3e8HgkaSt467l E98jWFrlCjH2xL3I4rUkw1xsuDCx1QwmBHuKQpgij9Mq6l7/VcMXRHfwrrvfwSI+J5UD QYxFlxMBMZ8hRe+SqmibCvds24JRT5gt044udBvr0MQsmNuI0f4QBSTqX+ho19xF/5Cz 1qqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=EflvFJMn; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v144si5726269qka.178.2020.05.22.09.23.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:23:06 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=EflvFJMn; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcARt-0000hE-VE for patch@linaro.org; Fri, 22 May 2020 12:23:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKZ-0003E9-39 for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:31 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:43261) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKX-0006G8-5y for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:30 -0400 Received: by mail-pf1-x444.google.com with SMTP id v63so5393931pfb.10 for ; Fri, 22 May 2020 09:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kxh2o1V8iXkuJj8JRvzQtcAUGmlKoLZ53V+la2Fi9CI=; b=EflvFJMnpr9hfGwGwkLoT90GuXYL0WnbaWiKcadAupSoAPkuxPxNW9QyM/BF1Hml0U mX/OL0mCTzcp++Mr1/S3Yo6ElM8P8rpYBqLSgppjH/THbc2dw4+sEb0wW+Nx1ZIoSdcp cBU6oenpIQXKQqlGaLRWYbYyJ1UbjdqDfmI5gxRGLioPF/Hb9gXE22gEwpHhr5uRQDrH MouxUnm/XmfAP1nacc5/PPeOGQ1JYk3wGI6Lk3pylQ3HwkpkdQ1btimriCpspSrHtZBi owrRhdrVLrIg0HpIORotacOj10tEfxmV03k6/EWyk/RnPw+3xxJsbJha7V7J98ZTGrvl PuGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kxh2o1V8iXkuJj8JRvzQtcAUGmlKoLZ53V+la2Fi9CI=; b=S/Oi52KFV14Dk60klUCaS7yf4vM6ynHIA8mOk3jErhMPzBYkHM3tKgYCwvqmrAHYdv t8/SQmBxdYQIEw2GVCBLBxmfGpqG+vfs8KjYUOUiFpSQECWsd3Il8qx4cOV+0cXUeIA5 vptQ4LY/OCTx2xCTuTtD7VIzq5bvQZHAjPgREFK1lmmb4Q0bDtAu3N7DWQtLALmYg8L3 gO4QV4cPDzKvtFfWRmG/o98JW0iu5jf4T9Nef4T62vAzhZQSn4sswkIvQgabZmKyY803 GdyS603tv/yVUPGErYkMXT6xDYQbTQv6wRjkoZ65xG5N6imihv2kKRANKuQ36k/50NQh BBjQ== X-Gm-Message-State: AOAM5317FGdp5I9gU58XB0gHw+FCNe3UNj8F+Fiwyn/vCUb4dLobDqiK 0bLGERCf5fAy4pGGPA/sGs4ZqK+gLZtlkg== X-Received: by 2002:a62:7f03:: with SMTP id a3mr4594490pfd.113.1590164108266; Fri, 22 May 2020 09:15:08 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:07 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 05/19] qht: call qemu_spin_destroy for head buckets Date: Fri, 22 May 2020 12:07:41 -0400 Message-Id: <20200522160755.886-6-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Signed-off-by: Robert Foley --- util/qht.c | 1 + 1 file changed, 1 insertion(+) -- 2.17.1 diff --git a/util/qht.c b/util/qht.c index aa51be3c52..67e5d5b916 100644 --- a/util/qht.c +++ b/util/qht.c @@ -348,6 +348,7 @@ static inline void qht_chain_destroy(const struct qht_bucket *head) struct qht_bucket *curr = head->next; struct qht_bucket *prev; + qemu_spin_destroy(&head->lock); while (curr) { prev = curr; curr = curr->next; From patchwork Fri May 22 16:07:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187174 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2645953ilb; Fri, 22 May 2020 09:17:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgOTSdwRzVfi8pZRs0+Zn5uzLPZJ69dntlpeeZO7XGM5E9ybqHokPPQE3YurkHFKbYw5lr X-Received: by 2002:ac8:4f4e:: with SMTP id i14mr17050524qtw.167.1590164270653; Fri, 22 May 2020 09:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164270; cv=none; d=google.com; s=arc-20160816; b=fdwsxv8S4ByNA6yu2Rzcd44fq2Lq3S+zjAzaNItlUUW9RxZfUXzKGprQdYvAoMmRN0 5ZoQNvBOtmnXYzGT4WeqcPQNP02UjjkJNTjothK6EODhPso4hFGwtRUcw+3QHZmg+isb x6fCFK8w5lv/JorVaQfw7GuhsM1R+oZubLunJx5QCB9tCrxaldOMeI49tLD/0TQxpI77 URKK80bvWIKbe0TxjQGszSGPIbUHtgW0p7/CkcytkNygy3daZyq+pfV8Z/dvVQuL0BC6 h5Qz4r+6V+vhhkbfhF9f3orS42D5qGj3iVHzvk5Vi2rltRjCVZAKf5+dFLYuARY128va 7Biw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=JYiXtqj6gRVqxuRODQQz1eMSRJbQ7+uu1VT7LzsetPI=; b=Vw1AhmofM2aD+LyjavTdQk7VMPcoOqmVkqXrA16ue4dZW/0AcBcpQcwJs5PtbmO88t yKsvLnfVOtbwQEQJEqz8mardIifQ3GKCIgy5Nv78EAdjZWKxa9Mb3ytw7RolxCLbOXKb Aw0EU/ejKSa24uu1OVhR7TFq//xTXpR/RBFlcjhsQVm916hTH7OsG0eqPQs/Sc7oyXZw IQTo0O47Bw9ArP0El7MjXB87H27Y8HhuDRHq8XnLtJgTS55Z4WDuR2chfBeZF/3DZWAj ykj/76BAAfTR9OnweuvIf0MK8bn6Ddc7IFPCerHqZfQwrlZg3CRd01oNzLpWyjXsKwdV M+NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oYEvkOCJ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v19si5543852qvl.57.2020.05.22.09.17.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:17:50 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oYEvkOCJ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAMo-0006cV-5d for patch@linaro.org; Fri, 22 May 2020 12:17:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40354) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKI-0002rP-AA for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:14 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:34113) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKH-00068Z-2l for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:13 -0400 Received: by mail-pf1-x442.google.com with SMTP id z64so881534pfb.1 for ; Fri, 22 May 2020 09:15:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JYiXtqj6gRVqxuRODQQz1eMSRJbQ7+uu1VT7LzsetPI=; b=oYEvkOCJGliRXZ0zkgt/2z4gEHerit/8rwZVg00ncJ2XoANaDewSsNkRNlIUq89HZP Kn6Jco/Le7N32URl4/LaGQqY6TNDu0UhwNV/N2yJtcjk/WrXRIOCch/LFMOPn+jl+fJ7 Cvq/XWmpvVOOyENH2NzgJNBF5GIG9uDwHbWaebC0r/IcQLWspcVUej6ctspFANilNjpS glRjG0ekFTBYu82W166JXjBwdctBmG/giTENNIkbA7MTSfLr73YT4oqAScXUopnTSe8x xsn8avxqns6JOEh39xBG68GaBO5eO6XspgTG+u/q+zIl6EcPmBdYnubXlxpSMcgImvKy F8lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JYiXtqj6gRVqxuRODQQz1eMSRJbQ7+uu1VT7LzsetPI=; b=A38tQb+f34GyH6p1DxsM4huFi3GEKEZ0dyNWBNDYXC9KCec3kRyNjYUDeE535z38li lhPEHy5dlBt5fUxczyXEEZSS8lrSNRFvhUVqPIsUGPGwFp7IXZU7fV1U1xJOwaFOoFo7 MuKO/ukn41HYILOe7WX4tsitZAC2Q3AmR8AT2dS1vxh99Mv3tntqgD2N3ToctwKmaIW0 CcmqQyjMEXnuw6fFj/MF7gvhjqkYq21kjsIuaB/7zYG36vm2L79ECYcKO40YtGmZfkfC QN4NNWmPHQI9rI02lEvo+4xPW8QjBQbMva4cDRxVD8gQYOvg96WNjPTCN9oluk9yVDJf 53Rw== X-Gm-Message-State: AOAM531PMGY3Ywd32iyOJJHAChOIPZlbtkJx3DCA8cXtR7RUxzn7HjfW rOdqkoMp7rjSRdIM5rNYrbV5fx9JeYYryg== X-Received: by 2002:a62:1957:: with SMTP id 84mr4544208pfz.54.1590164110282; Fri, 22 May 2020 09:15:10 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:09 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 06/19] tcg: call qemu_spin_destroy for tb->jmp_lock Date: Fri, 22 May 2020 12:07:42 -0400 Message-Id: <20200522160755.886-7-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley [RF: Minor changes to fix some checkpatch errors] --- accel/tcg/translate-all.c | 10 +++++++++- include/tcg/tcg.h | 3 ++- tcg/tcg.c | 19 ++++++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 42ce1dfcff..3708aab36b 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -384,6 +384,11 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, return 0; } +static void tb_destroy(TranslationBlock *tb) +{ + qemu_spin_destroy(&tb->jmp_lock); +} + bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit) { TranslationBlock *tb; @@ -413,6 +418,7 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit) /* one-shot translation, invalidate it immediately */ tb_phys_invalidate(tb, -1); tcg_tb_remove(tb); + tb_destroy(tb); } r = true; } @@ -1230,7 +1236,7 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) qht_reset_size(&tb_ctx.htable, CODE_GEN_HTABLE_SIZE); page_flush_tb(); - tcg_region_reset_all(); + tcg_region_reset_all(tb_destroy); /* XXX: flush processor icache at this point if cache flush is expensive */ atomic_mb_set(&tb_ctx.tb_flush_count, tb_ctx.tb_flush_count + 1); @@ -1886,6 +1892,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, orig_aligned -= ROUND_UP(sizeof(*tb), qemu_icache_linesize); atomic_set(&tcg_ctx->code_gen_ptr, (void *)orig_aligned); + tb_destroy(tb); return existing_tb; } tcg_tb_insert(tb); @@ -2235,6 +2242,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) tb_phys_invalidate(tb->orig_tb, -1); } tcg_tb_remove(tb); + tb_destroy(tb); } /* TODO: If env->pc != tb->pc (i.e. the faulting instruction was not diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index c48bd76b0a..2c5997e14e 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -815,8 +815,9 @@ void *tcg_malloc_internal(TCGContext *s, int size); void tcg_pool_reset(TCGContext *s); TranslationBlock *tcg_tb_alloc(TCGContext *s); +typedef void (*tb_destroy_func)(TranslationBlock *tb); void tcg_region_init(void); -void tcg_region_reset_all(void); +void tcg_region_reset_all(tb_destroy_func tb_destroy); size_t tcg_code_size(void); size_t tcg_code_capacity(void); diff --git a/tcg/tcg.c b/tcg/tcg.c index a2268d9db0..2680968683 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -502,7 +502,16 @@ size_t tcg_nb_tbs(void) return nb_tbs; } -static void tcg_region_tree_reset_all(void) +static gboolean tcg_region_tree_traverse(gpointer k, gpointer v, gpointer data) +{ + TranslationBlock *tb = v; + tb_destroy_func tb_destroy = data; + + tb_destroy(tb); + return FALSE; +} + +static void tcg_region_tree_reset_all(tb_destroy_func tb_destroy) { size_t i; @@ -510,6 +519,10 @@ static void tcg_region_tree_reset_all(void) for (i = 0; i < region.n; i++) { struct tcg_region_tree *rt = region_trees + i * tree_size; + if (tb_destroy != NULL) { + g_tree_foreach(rt->tree, tcg_region_tree_traverse, tb_destroy); + } + /* Increment the refcount first so that destroy acts as a reset */ g_tree_ref(rt->tree); g_tree_destroy(rt->tree); @@ -586,7 +599,7 @@ static inline bool tcg_region_initial_alloc__locked(TCGContext *s) } /* Call from a safe-work context */ -void tcg_region_reset_all(void) +void tcg_region_reset_all(tb_destroy_func tb_destroy) { unsigned int n_ctxs = atomic_read(&n_tcg_ctxs); unsigned int i; @@ -603,7 +616,7 @@ void tcg_region_reset_all(void) } qemu_mutex_unlock(®ion.lock); - tcg_region_tree_reset_all(); + tcg_region_tree_reset_all(tb_destroy); } #ifdef CONFIG_USER_ONLY From patchwork Fri May 22 16:07:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187178 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2647235ilb; Fri, 22 May 2020 09:19:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5GjqFr1LiBiZqjQGTixIsydYRUWyoD5VvEK+GqT6qmSGjdrKClATi70RTO/S8JY8p29vQ X-Received: by 2002:a05:6902:4a2:: with SMTP id r2mr6760344ybs.512.1590164367844; Fri, 22 May 2020 09:19:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164367; cv=none; d=google.com; s=arc-20160816; b=Lm0BMS/q6btm/Os01LcPSfmPjOoAlKmGCSt2hcx7Dw+mBrqXGUTq0r6JFVIClTvjaD +5Xe0gYsX5nFPUmmEtEiuP0p0bPd7U0PbvSEEV3tPqKod2GVBOFcg1FRJWFyXsu4eQCn witbf3h4AvjYKXNWk5OKFCXVR51gV5cgVRFqi7d92VjXEZK9hYvXKxcoGfy4Q36YoEXd mpkyh9+Kd5RtxLUDjZoBCA8+CsHMpr6xtb3I4iW8kgUOCRfILmyMxV+WWgXEhVxKyOF5 pyjY3XlyGcAph30Igl0SsQxu86VpPAh6pE4kZO3hsKxmgjPh++Q9+YWBVaPAuqzQyl6S B8eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=v6Twul2TWinr3wq/OK/PDzXQA1fcuJlgD8ranJI4BbA=; b=aK53WaTlgstlpTQWLjkGzo5EWoKswYLfemjuAe/aBlA5C/4Yw0cNQ6qQ02GScgGNZ+ kialc1QwAZbJQC9ewx6oIs0cjwrlXcdlenCjL8kYjwX0X+kWr8bECoBG3r9q9pEEkC99 o4zVz2e33mpz9189er1vgmV1xDDAHzOhhYeN55w5zQG6w+YP8iedlF+QVeXTGubUH5En W1j5BscPThYxmnd1gg9D0BYs2ZhraXfnTPofCo4c2gbayIlmNdrUa0iWW7PMMjOjh/u/ nBe5r8IYKLM+3jTOpe6Ri9UVnpKNkvaKvVE23BUWUXJ2kIXTJ7TjLxATWXClMkZfWCXa 5KDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=hDFxAIro; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r206si8011944ybc.378.2020.05.22.09.19.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:19:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=hDFxAIro; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAON-0001bl-7f for patch@linaro.org; Fri, 22 May 2020 12:19:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40358) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKJ-0002uJ-7x for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:15 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:40693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKI-00068v-5D for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:14 -0400 Received: by mail-pf1-x444.google.com with SMTP id v2so317048pfv.7 for ; Fri, 22 May 2020 09:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=v6Twul2TWinr3wq/OK/PDzXQA1fcuJlgD8ranJI4BbA=; b=hDFxAIroI0ANOVWUCCGJeF68Vy9zZCrDKE0UnTkapT+zSSGzHRoBZzk6RBzsRYlnr3 KIQF+IzAqeNeY0Dns4JNH5e1qztDV4rKfeafnjPCIBRi3NVVPoWBNTndJzL3fuekbTLj lZAnriIraJ1RRMdr+tMqAEijsvxw98sYdxDc+N6nCffhazzwnoTZFcXYoZWLavn/0Gqk AJe9MgLlNCDLs6diOr0qf8/vn6FIv5zULDbLg1ifTx3Mz+qcKX5Psfy7ueF1kH4vrk0Q zn5YWqre7rhbapq5+U53fpZhuc3k1bTsUAK6+iog6lS363WllMLD+zLF4frfURQtYDER cOFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v6Twul2TWinr3wq/OK/PDzXQA1fcuJlgD8ranJI4BbA=; b=UWjbxSRERWThzq54hnbWAXJfCLTw04SdU0dk68zgf9UcgsF1g9pTFYvYZv/012q0J+ D38OssZ5i2wRmxOTsZ8T4Jh1nUcHfptEvGvjz+GVbPxkxujagEBQqBZ01TGhZVgFeir7 2nZfipwYoESnrEqy5pn4ZRr8bfqY92ItnbNDD3s4dZQA5KM7FSaqBeL1qMZwMYkokmC2 EJySmb97zaYr/NPa5MSOs8riHvA+Z1LIGutC2thzhGMFTO6hjHh3AHP76rvf36KcLYYu Hd34Iz2wxbB7tOJtVHp+naLyYHUsE7hsTC11QHh1xYmndcVuxG20QDeUR5nQk1v20GqS 0piA== X-Gm-Message-State: AOAM532p0OjtqYf6Vt86Z/6+JFGMrWHyuCsS/Angco7z1QQeIMmQCJbn bMu4UVumphIWZcbSHY1Cgg5RUdOP0OWUuQ== X-Received: by 2002:aa7:8a48:: with SMTP id n8mr4571386pfa.257.1590164112406; Fri, 22 May 2020 09:15:12 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:11 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 07/19] translate-all: call qemu_spin_destroy for PageDesc Date: Fri, 22 May 2020 12:07:43 -0400 Message-Id: <20200522160755.886-8-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" The radix tree is append-only, but we can fail to insert a PageDesc if the insertion races with another thread. Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley --- accel/tcg/translate-all.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.17.1 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 3708aab36b..3fb71a1503 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -547,6 +547,15 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc) #endif existing = atomic_cmpxchg(lp, NULL, pd); if (unlikely(existing)) { +#ifndef CONFIG_USER_ONLY + { + int i; + + for (i = 0; i < V_L2_SIZE; i++) { + qemu_spin_destroy(&pd[i].lock); + } + } +#endif g_free(pd); pd = existing; } From patchwork Fri May 22 16:07:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187171 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2645888ilb; Fri, 22 May 2020 09:17:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyl5sEolpglyN0BvvQvBEVAmjN4IUsPNSmrmvBb3IvwX4tuEFmud0e4ue0JGw9swDABKwM5 X-Received: by 2002:a37:27d6:: with SMTP id n205mr16119567qkn.149.1590164266191; Fri, 22 May 2020 09:17:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164266; cv=none; d=google.com; s=arc-20160816; b=ZwOlVRPVuaGhOcp3Ig7BK2xu8Uvr5Kygz0QzM61f1pUzYc5At0MxQKNaL2YyMvlDDa /9XqxkNw+r5rqyuvm/doj1kH3IXhSy525BweNuGfRf9Kgji52QSykOJmX+TiXCgLoFdf GXKlEUpmoYaRoIylmuZn9wF92ly6d+EQHeKihKipOyU4SNy5JJhJrbhfc+zkP5dINagn 2l7hn82kvdFm/+YRAhjGKM0w7R2fmNoCfsRqQe366JNnnceELMUC6r2un4CwTYXI/Vi7 XiW/Qpb50fqd0z24XzY40EHOX/lalZJDJLhzN0wACJRliIUyrWVwsFT+j9b51V1N+AK8 V9uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=mGW6wnv9FlzkC02Bo8Bk1So4QHTwo22NecRxOgB5aoI=; b=kzgCTjnY/9162TfjB5XpY+TJ7I4K0Qir/aJ24sX2I66lgh4NIWtkkqDNx/xHtfD5ew MwhRLx5TvFeoMR6ejdjUersJje+8v7IygZ0HrFPvP+GufMd1E84EHXUigGr2n3upkp4m 4Qa1EoQ5tc1pt8bAu0Gt5ORCVmpFvGJBeIMyt2s3gIpROXrdSof9qDGpO1BdQeuM9gAi 2ZjcsKIUQiV1E0YGvtR32IlGyz1MDCfZta+vPlHu7Pc08Adfi93qWjVeMpxgSQ0n5q0N q6eF0icaUTmbJcRTVwlBcD4u9wFiKWfHCy64988ksQYnyHiqA3JCFJiTDHwlcfMw0Cjt qEQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dF1P08+W; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j24si5533711qtk.305.2020.05.22.09.17.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:17:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dF1P08+W; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAMj-0006Pj-Nd for patch@linaro.org; Fri, 22 May 2020 12:17:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKL-00031t-WD for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:19 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:40692) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKK-00069X-1W for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:17 -0400 Received: by mail-pf1-x442.google.com with SMTP id v2so317078pfv.7 for ; Fri, 22 May 2020 09:15:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mGW6wnv9FlzkC02Bo8Bk1So4QHTwo22NecRxOgB5aoI=; b=dF1P08+W1ySZKkdJtEBOMsR7tfuqSb7PFhn5sie4eh3zucjXn7ftbpYsWjrUwNiQdW SQHW0NXOvu7erCgRnAVl2kTymTE/vic71Q+fIdCIkA1+rwGRuvP83xMuxy0LF62m3wwg PFLQMkUGOdN9KZQWBIXZ8AEUjvlYKeyXED+l2M1lnflct+fn50dUOyCvxrnVBMZ/GsGU ases1B3fuvzf0oefio9BzK1KzeU+wtACKkgkP3zBCO94703CQPvtvisDAjFnyi8RFjXy cf/qjX4n8SsCxRQhAfC1UQJEg2L3Y/V3eie+HohwJYLmxQsBknTomF+vlO9eMPIQ9a+s iLxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mGW6wnv9FlzkC02Bo8Bk1So4QHTwo22NecRxOgB5aoI=; b=IPueW35ASYAOydobpu/r7pkZfYUG1v0oNDJ5fZDuBnQChlPjMreqESpac0Vwcn3VlU KN1RUR8JfSrQ0RJt1+mUR7ceojGAHasc0mFfiCn8yzrBsYCQahMAvlsBxv04YJakCd86 AKSuVM1/9acBrd3FXY6P9EDpRAHC+bsRB4IVj8AnMQLoZvc6i4gMOcXnJnpucsZgbY69 wEL4fjFTQEBTGgRm3tdfjftiXC7gS0DImFhuu9M34jaiLgh3bwiwJ3snn61QvM+r/HkX QZ+zLdaW4ctuUkz2AmAxJAT3ePHqzCCxy31lQFgxpqoI7HaJfDZ8CL9QTd3OGz/5RT70 1aQA== X-Gm-Message-State: AOAM5327XnCNpzFXSi+9gXUKaNkrmKkHWyE9lMEzqbGOHgT+esujTVtR uoYztVtpunh6qDOiwILlPqzrjFTLMl143w== X-Received: by 2002:a63:4d4e:: with SMTP id n14mr12683505pgl.93.1590164114424; Fri, 22 May 2020 09:15:14 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:13 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 08/19] thread: add tsan annotations to QemuSpin Date: Fri, 22 May 2020 12:07:44 -0400 Message-Id: <20200522160755.886-9-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley --- include/qemu/thread.h | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/include/qemu/thread.h b/include/qemu/thread.h index e50a073889..43fc094b96 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -206,6 +206,10 @@ void qemu_thread_atexit_add(struct Notifier *notifier); */ void qemu_thread_atexit_remove(struct Notifier *notifier); +#ifdef CONFIG_TSAN +#include +#endif + struct QemuSpin { int value; }; @@ -213,23 +217,46 @@ struct QemuSpin { static inline void qemu_spin_init(QemuSpin *spin) { __sync_lock_release(&spin->value); +#ifdef CONFIG_TSAN + __tsan_mutex_create(spin, __tsan_mutex_not_static); +#endif } -static inline void qemu_spin_destroy(QemuSpin *spin) -{ } +/* const parameter because the only purpose here is the TSAN annotation */ +static inline void qemu_spin_destroy(const QemuSpin *spin) +{ +#ifdef CONFIG_TSAN + __tsan_mutex_destroy((void *)spin, __tsan_mutex_not_static); +#endif +} static inline void qemu_spin_lock(QemuSpin *spin) { +#ifdef CONFIG_TSAN + __tsan_mutex_pre_lock(spin, 0); +#endif while (unlikely(__sync_lock_test_and_set(&spin->value, true))) { while (atomic_read(&spin->value)) { cpu_relax(); } } +#ifdef CONFIG_TSAN + __tsan_mutex_post_lock(spin, 0, 0); +#endif } static inline bool qemu_spin_trylock(QemuSpin *spin) { - return __sync_lock_test_and_set(&spin->value, true); +#ifdef CONFIG_TSAN + __tsan_mutex_pre_lock(spin, __tsan_mutex_try_lock); +#endif + bool busy = __sync_lock_test_and_set(&spin->value, true); +#ifdef CONFIG_TSAN + unsigned flags = __tsan_mutex_try_lock; + flags |= busy ? __tsan_mutex_try_lock_failed : 0; + __tsan_mutex_post_lock(spin, flags, 0); +#endif + return busy; } static inline bool qemu_spin_locked(QemuSpin *spin) @@ -239,7 +266,13 @@ static inline bool qemu_spin_locked(QemuSpin *spin) static inline void qemu_spin_unlock(QemuSpin *spin) { +#ifdef CONFIG_TSAN + __tsan_mutex_pre_unlock(spin, 0); +#endif __sync_lock_release(&spin->value); +#ifdef CONFIG_TSAN + __tsan_mutex_post_unlock(spin, 0); +#endif } struct QemuLockCnt { From patchwork Fri May 22 16:07:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187177 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2647187ilb; Fri, 22 May 2020 09:19:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZs+BY5uTjX2vjOv7c1nYKE7ZuAc7cfW+VEq26QR+r4AhWbJ2L52K3I1RpSabZrxDR/Fom X-Received: by 2002:a25:9d86:: with SMTP id v6mr24215253ybp.322.1590164364452; Fri, 22 May 2020 09:19:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164364; cv=none; d=google.com; s=arc-20160816; b=Y91Wua3QvUKcbpgT3q/LUOpU3VqKUagm6F+rAAViX0ZN0GKcofCO/ZqCL4OdRGs5R8 YovFHt7eduYD0Xed0Iyegh4lHgI1yjq7Laf0CTOj+acbtNQvfdSGim8q5omZy9qu/Hz0 tYvDcOfq3mv6q44a1VnSRyijfof5j4Q5aupi7a3JVcVnVWcNmudt0LeqkfqY4bGEUH+V 9jQ8ifZ2WJ6IhBvZ1DTwUlB+HnJezVQZ0AHaK9Zsrh+Hlm9610h8HHk5HHK4HIFRrWF7 JQgDRd7ztpTywBs8GXAA2X84ynLrNTC95yfU+rSxf+KodM9ira/Od1I7iqBz1u+E0M6Y p5kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=NlGChhLZQ6hBueDHSr0fX6nm53bsIvTSR/1CZBu8arw=; b=z+oRst08gSmzgtO5SDIqlg2fTRTMO7Cx7IKrKpWemHqIkq/K5Y9jgOejIMQL/hMSeF jnMNpsD2xxYnDdlQd55PzKbNuDZfbNHptoBccay8wZ0tppxj+/v1Uynjg+bm6rtRsB/D m70LOUhN9xBNsgBLHmJqcRKV5TUs/d7LeVFRd1YR5PeD+LNe5QM/6n7KGLkvqX5jNYEu Tj2qjFBmjPtnubn1sw4H7DtkBLJ7Q8922H+R6zWR6B4yZ8PfmiiVfomLbDWAvadwkJi5 yY6Zn5yVqy0GWWCmJuqqSBliUpsxoG0NxxWMKR6lsRD5+SN6/wekw8xuDMcbkKhFAeYA 9T0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SNnTHiJr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b142si2394972ybg.210.2020.05.22.09.19.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:19:24 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SNnTHiJr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAOJ-0001Rq-UX for patch@linaro.org; Fri, 22 May 2020 12:19:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKR-00034W-Ey for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:23 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:40166) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKN-0006C8-I1 for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:23 -0400 Received: by mail-pl1-x643.google.com with SMTP id t16so4573652plo.7 for ; Fri, 22 May 2020 09:15:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NlGChhLZQ6hBueDHSr0fX6nm53bsIvTSR/1CZBu8arw=; b=SNnTHiJrh7h6kmmRMdC+zZ3FcVmcCHvealLhuc03ZGBoWQ9hXLe61Yllg7bGP1rDtH Y5lfhnk0j69r894CtvLaSfilMLKANdKtZGov5zouD69y3wlZmwngzkMwvjrvXnuL71dO UlFM9aE16W1TA3gjp/xITOE1bHO+bFB08FAMNHMJVw5Oh9NliiOKmiYelN6lfMmWXc0t iKqbnBrvoKxIOT2qsvc3vBOcuT2Ja5X6EsGssFiJxlyv2P4d024j4b0P8tUA8UEMvz91 3AntaeBny7NUh8p8EBg/7E+HtJgHG3xe3jJcaF7kHWZoF5SGvMTTh63pFHZjJy8neblA 3zUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NlGChhLZQ6hBueDHSr0fX6nm53bsIvTSR/1CZBu8arw=; b=QKZ6WNYUkJi3BfMieoLhNlv1dOktGwCqqvcA4CQAvaRjn6374TAd0tk6BBGA8G1Ubc MC9zEsF7FccnTng/BSC7cMYd3jxFVeii+4qv8icyCnn1l6bW/6mGSQzPl4UNaTYqS59U Qi3q/aQ7z/iHOCWWnpowNbBDwUrMbyhZW7GLkla///X72yRn9OZGbdXf3DiK06mD5SL7 2ySBWp7y6oEnBTsDlz6zdCmT+27vFTEHSKemzH2hHyzi88/lEQ7Zj/gULlki0QeAOxQh y5b6qGNQ5Dn9oH7kfWFdC3IMDMF8/a8zjdS8bKBJxGUYDKCOga4hldyIrg4wA0dlmwdo /SPw== X-Gm-Message-State: AOAM5314jBnpDPCMqmpL5CCiFK5+h3na14cAFe6ruPkLvM+VwQZQsR4e lClrA8YBZiVYs1MNr6Xx6YrZFGyXm1p05w== X-Received: by 2002:a17:902:6ac3:: with SMTP id i3mr16038139plt.261.1590164116683; Fri, 22 May 2020 09:15:16 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:16 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 09/19] tests/docker: Added docker build support for TSan. Date: Fri, 22 May 2020 12:07:45 -0400 Message-Id: <20200522160755.886-10-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::643; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x643.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , robert.foley@linaro.org, =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , cota@braap.org, peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Added a new docker for ubuntu 20.04. This docker has support for Thread Sanitizer including one patch we need in one of the header files. https://github.com/llvm/llvm-project/commit/a72dc86cd This command will build with tsan enabled: make docker-test-build-ubuntu2004 V=1 TSAN=1 Also added the TSAN suppresion file to disable certain cases of TSAN warnings. Cc: Fam Zheng Cc: Philippe Mathieu-Daudé Signed-off-by: Robert Foley --- tests/docker/Makefile.include | 2 + tests/docker/common.rc | 19 +++++++ tests/docker/dockerfiles/ubuntu2004.docker | 65 ++++++++++++++++++++++ tests/tsan/suppressions.tsan | 14 +++++ 4 files changed, 100 insertions(+) create mode 100644 tests/docker/dockerfiles/ubuntu2004.docker create mode 100644 tests/tsan/suppressions.tsan -- 2.17.1 diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include index 43a8678688..e029e54b42 100644 --- a/tests/docker/Makefile.include +++ b/tests/docker/Makefile.include @@ -202,6 +202,7 @@ endif @echo ' (default is 1)' @echo ' DEBUG=1 Stop and drop to shell in the created container' @echo ' before running the command.' + @echo ' TSAN=1 Enable use of tsan during the build/test.' @echo ' NETWORK=1 Enable virtual network interface with default backend.' @echo ' NETWORK=$$BACKEND Enable virtual network interface with $$BACKEND.' @echo ' NOUSER Define to disable adding current user to containers passwd.' @@ -239,6 +240,7 @@ docker-run: docker-qemu-src -e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \ -e V=$V -e J=$J -e DEBUG=$(DEBUG) \ -e SHOW_ENV=$(SHOW_ENV) \ + $(if $(TSAN),,-e TSAN=$(TSAN)) \ $(if $(NOUSER),, \ -e CCACHE_DIR=/var/tmp/ccache \ -v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \ diff --git a/tests/docker/common.rc b/tests/docker/common.rc index 02cd67a8c5..5df93c6326 100755 --- a/tests/docker/common.rc +++ b/tests/docker/common.rc @@ -27,6 +27,25 @@ requires() configure_qemu() { + if test -z "$TSAN"; then + requires clang tsan + echo "Including TSan Support" + tsan_log_dir="/tmp/qemu-test/build/tsan" + mkdir -p $tsan_log_dir > /dev/null || true + EXTRA_CONFIGURE_OPTS="${EXTRA_CONFIGURE_OPTS} --enable-tsan \ + --cc=clang-10 --cxx=clang++-10 \ + --disable-werror --extra-cflags=-O0" + # detect deadlocks is false currently simply because + # TSan crashes immediately with deadlock detecter enabled. + # We have maxed out the history size to get the best chance of finding + # warnings during testing. + # Note, to get tsan to fail on warning, use exitcode=66 below. + tsan_opts="suppressions=/tmp/qemu-test/src/tests/tsan/suppressions.tsan\ + detect_deadlocks=false history_size=7\ + halt_on_error=0 exitcode=0 verbose=5\ + log_path=$tsan_log_dir/tsan_warnings.txt" + export TSAN_OPTIONS="$tsan_opts" + fi config_opts="--enable-werror \ ${TARGET_LIST:+--target-list=${TARGET_LIST}} \ --prefix=$INSTALL_DIR \ diff --git a/tests/docker/dockerfiles/ubuntu2004.docker b/tests/docker/dockerfiles/ubuntu2004.docker new file mode 100644 index 0000000000..6050ce7e8a --- /dev/null +++ b/tests/docker/dockerfiles/ubuntu2004.docker @@ -0,0 +1,65 @@ +FROM ubuntu:20.04 +ENV PACKAGES flex bison \ + ccache \ + clang-10\ + gcc \ + gettext \ + git \ + glusterfs-common \ + libaio-dev \ + libattr1-dev \ + libbrlapi-dev \ + libbz2-dev \ + libcacard-dev \ + libcap-ng-dev \ + libcurl4-gnutls-dev \ + libdrm-dev \ + libepoxy-dev \ + libfdt-dev \ + libgbm-dev \ + libgtk-3-dev \ + libibverbs-dev \ + libiscsi-dev \ + libjemalloc-dev \ + libjpeg-turbo8-dev \ + liblzo2-dev \ + libncurses5-dev \ + libncursesw5-dev \ + libnfs-dev \ + libnss3-dev \ + libnuma-dev \ + libpixman-1-dev \ + librados-dev \ + librbd-dev \ + librdmacm-dev \ + libsasl2-dev \ + libsdl2-dev \ + libseccomp-dev \ + libsnappy-dev \ + libspice-protocol-dev \ + libspice-server-dev \ + libssh-dev \ + libusb-1.0-0-dev \ + libusbredirhost-dev \ + libvdeplug-dev \ + libvte-2.91-dev \ + libxen-dev \ + libzstd-dev \ + make \ + python3-yaml \ + python3-sphinx \ + sparse \ + texinfo \ + xfslibs-dev\ + vim +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get -y install $PACKAGES +RUN dpkg -l $PACKAGES | sort > /packages.txt +ENV FEATURES clang tsan pyyaml sdl2 + +# https://bugs.launchpad.net/qemu/+bug/1838763 +ENV QEMU_CONFIGURE_OPTS --disable-libssh + +# Apply patch https://reviews.llvm.org/D75820 +# This is required for TSan in clang-10 to compile with QEMU. +RUN sed -i 's/^const/static const/g' /usr/lib/llvm-10/lib/clang/10.0.0/include/sanitizer/tsan_interface.h diff --git a/tests/tsan/suppressions.tsan b/tests/tsan/suppressions.tsan new file mode 100644 index 0000000000..975b0c2934 --- /dev/null +++ b/tests/tsan/suppressions.tsan @@ -0,0 +1,14 @@ +# TSan reports a double lock on RECURSIVE mutexes. +mutex:aio_context_acquire +mutex:pthread_mutex_lock + +# TSan reports a race betwen pthread_mutex_init() and +# pthread_mutex_lock() +race:pthread_mutex_init +race:pthread_mutex_lock + +# TSan is unhappy about these load and store operations. +race:bswap.h +race:store_helper +race:load_helper +race:tb_set_jmp_target From patchwork Fri May 22 16:07:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187176 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2647170ilb; Fri, 22 May 2020 09:19:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxggThq/P2seu9DW/fS03fAjB4J1OvNy/OnS59xdk4jRSPXo3rDGaCSILHu/lX0Y0KVRs7j X-Received: by 2002:a25:c5c7:: with SMTP id v190mr23323794ybe.421.1590164363475; Fri, 22 May 2020 09:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164363; cv=none; d=google.com; s=arc-20160816; b=znp7MqctsUM9KkYFg2GR/yIQ491Wwti5/12jPYaiUWlMSRmZNJaZKGWmmG1Mp4JDn3 IqxN81d19yH/UfVrVcIts9bvz+5IUF3pVuS3cLRMnPBxhk3cGdg4XcpQrGmMDs3CgsL7 7L6553SjQftX2R9Nr1BEILbaUEYytko99XJMKz0FCnNWbqyRLnRDtGjqzJh+9yW+Gz8J o4pJL4qg02GuExoTLQ+6B3RyWsuHoojMrjTDFJaZ/AnuSRXej9TUGySu2AF5vh2z5MpH AX+1U5T977YbWftBHABnfcJq3iYV1iPHZKdOfAIoEJT3dVzZsT5mtHd398CIgHGRoTLC ONwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=tLifGO+pAQPZlQcKX63d2L4JgerTfPuetScyiOswaLc=; b=0BVIGYF1tazEGvTQN2eIPimur/WHThVNKJfnfJepqXHzUx2YNUly5OFo8zckZBcEjH 2oYxWmADhxKnA6bxbGuHFbfj76+8vDyjBfEwiTJGnV0LJeh9zsNDUZ1XN8uOv13aD7KN UjAoauGCNE9ihu69QYWULiB3TEkWADrKaUXbnKCcGBawVI0s5dltTqEq162qf2Zh4SjF PhxQiUs0a6hX3RhuUQlqQbctUHqO4nh/ehpsAHrs8LRVGserkmy/VajoVLWe300UBg80 LMQ+to4AgeB/Wi4ZwXNWLPEQrIPo72PbmynJETbN19teE4Lm3evaFT+v/TXktig/SgcP iDKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=G9CmtFg1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x9si8122921ybp.92.2020.05.22.09.19.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:19:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=G9CmtFg1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAOI-0001PZ-UH for patch@linaro.org; Fri, 22 May 2020 12:19:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKU-00038u-Bc for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:26 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:42643) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKP-0006Db-FR for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:26 -0400 Received: by mail-pl1-x643.google.com with SMTP id x11so3579198plv.9 for ; Fri, 22 May 2020 09:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tLifGO+pAQPZlQcKX63d2L4JgerTfPuetScyiOswaLc=; b=G9CmtFg1o2wGg+WHrpNPN1h6vLku/VJXlgQXhVPVPeIZzFRRdCpt32OyljhRliJ13t Yvjz29IFUXrEqyV+WhUGjCSjtawU9ME7WYcmX04OAk4WZjVbcPcSOzo8z41kMqViYmMP OCpi3RWP9L1UJ27YY+1cK0qoUA4xOxafLlq3WPpn7DeLqafqRrb8BCVSKsm1OAndeUhW SzvZJw6Bx6cSzhyDQ24Li1xD4Zr/evm/jdZ+uQeqlHgNfznPV3r5A9utR8eJLZlHEsd8 Uu7/qfW/AuxNU8TGWOpSxae29uHFQrt5SDCSkjwEPnDfAwkbpXYj65ZaQndDGLANp2D3 urLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tLifGO+pAQPZlQcKX63d2L4JgerTfPuetScyiOswaLc=; b=MIgB2R1Rb4dIWhe4R4a/9jwaEw2yjq+AKhTkj5zUQEQExHxSNbiX6GWixZzLKPxG5A U9SIxW5o+IQtZweSTxuPxw4lhb67fdd8Kl2ww3FGNG6IiRnAFbaiB5ved/cDwdb8magh PTI651AEAMl32cgBY2q4YXEfJ7bdb9uWoJy3/siFBRfBAH7M1wCHhBavYJyJ6BoXDnse ZfRY3ovPc6ZD9zr3bQ66jDM+Gdl4JKs6lWfHaLQzzvF0MCCKKUxtE4jOmTmRBO6d2NmA pTUYD23XFLHmODLkgLFVZdFgNXpayH6yTSYsQNA0SFYygQH5xmrxXr0dd1GLBWXUuf2k +vgA== X-Gm-Message-State: AOAM5336LRCuliQX+Up/AIkagtGuMTfwNkwMjQxFDzKasTkWGStsR3tl IAX2AU3aUM7qs8/D7+IRA9l+TXTjsguHZw== X-Received: by 2002:a17:90a:8a0f:: with SMTP id w15mr4908406pjn.27.1590164118719; Fri, 22 May 2020 09:15:18 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:18 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 10/19] include/qemu: Added tsan.h for annotations. Date: Fri, 22 May 2020 12:07:46 -0400 Message-Id: <20200522160755.886-11-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::643; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x643.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" These annotations will allow us to give tsan additional hints. For example, we can inform tsan about reads/writes to ignore to silence certain classes of warnings. We can also annotate threads so that the proper thread naming shows up in tsan warning results. Signed-off-by: Robert Foley --- include/qemu/tsan.h | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 include/qemu/tsan.h -- 2.17.1 Reviewed-by: Emilio G. Cota diff --git a/include/qemu/tsan.h b/include/qemu/tsan.h new file mode 100644 index 0000000000..8b7d0acf3e --- /dev/null +++ b/include/qemu/tsan.h @@ -0,0 +1,48 @@ +#ifndef QEMU_TSAN_H +#define QEMU_TSAN_H +/* + * tsan.h + * + * This file defines macros used to give ThreadSanitizer + * additional information to help suppress warnings. + * This is necessary since TSan does not provide a header file + * for these annotations. The standard way to include these + * is via the below macros. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifdef CONFIG_TSAN +#define TSAN_ANNOTATE_HAPPENS_BEFORE(addr) \ + AnnotateHappensBefore(__FILE__, __LINE__, (void *)(addr)) +#define TSAN_ANNOTATE_HAPPENS_AFTER(addr) \ + AnnotateHappensAfter(__FILE__, __LINE__, (void *)(addr)) +#define TSAN_ANNOTATE_THREAD_NAME(name) \ + AnnotateThreadName(__FILE__, __LINE__, (void *)(name)) +#define TSAN_ANNOTATE_IGNORE_READS_BEGIN() \ + AnnotateIgnoreReadsBegin(__FILE__, __LINE__) +#define TSAN_ANNOTATE_IGNORE_READS_END() \ + AnnotateIgnoreReadsEnd(__FILE__, __LINE__) +#define TSAN_ANNOTATE_IGNORE_WRITES_BEGIN() \ + AnnotateIgnoreWritesBegin(__FILE__, __LINE__) +#define TSAN_ANNOTATE_IGNORE_WRITES_END() \ + AnnotateIgnoreWritesEnd(__FILE__, __LINE__) +#else +#define TSAN_ANNOTATE_HAPPENS_BEFORE(addr) +#define TSAN_ANNOTATE_HAPPENS_AFTER(addr) +#define TSAN_ANNOTATE_THREAD_NAME(name) +#define TSAN_ANNOTATE_IGNORE_READS_BEGIN() +#define TSAN_ANNOTATE_IGNORE_READS_END() +#define TSAN_ANNOTATE_IGNORE_WRITES_BEGIN() +#define TSAN_ANNOTATE_IGNORE_WRITES_END() +#endif + +void AnnotateHappensBefore(const char *f, int l, void *addr); +void AnnotateHappensAfter(const char *f, int l, void *addr); +void AnnotateThreadName(const char *f, int l, char *name); +void AnnotateIgnoreReadsBegin(const char *f, int l); +void AnnotateIgnoreReadsEnd(const char *f, int l); +void AnnotateIgnoreWritesBegin(const char *f, int l); +void AnnotateIgnoreWritesEnd(const char *f, int l); +#endif From patchwork Fri May 22 16:07:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187173 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2645902ilb; Fri, 22 May 2020 09:17:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvLDzmeVtB5ig+jG0+ureKCJBCrimsqyznCdBthQdvb7isNvItOnEsxF7fPqRl+wDtvema X-Received: by 2002:a05:6214:7cd:: with SMTP id bb13mr4564436qvb.17.1590164267256; Fri, 22 May 2020 09:17:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164267; cv=none; d=google.com; s=arc-20160816; b=MxasZdDJvu7LYSyXtY0NnGzJ7Bfd8rlmzq3apsCm/5r9/yCuWWon8UOw9jc9/5u+tM a5IdQgZKWiaMne0uU8Wgtv0Knxv4XUvKlm0bgPov6Mm5/JIyzfFePcRfLP+PBtrNTIXs ghdoCJ0mCsugXQAHkwIrl+krMmVWxmGyOZHRsOd8cVDz+LBOc+/Wwl/mjMDcZDp3BmrP qC3oGlwBOHwK73c8tbXpi8dFoSMayrGHdIRe1r1anIr7P1xgjTL08gmLKOZaQPQrIHHb qnfIfB6n+wqOKQzCxbN34ps7swrzVoN1WoqTQfKofXu2g5dJQNITPnommwEpYmKiXIbW sIoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=sWktVAUx9ulLHoMCqPkS2j+iHzQ8DGPuikmGe+LrZUk=; b=FQwxDmkkJUmHey5bpy6Da/0EfGR/hKApnHBg5jpJd4LVJGxFURsubsbRBR0Uwr2qcG xkPIqfGs37fLyU9l0Vy4tqc3MWcwaGW56YXL4vVA4TD+gYuy85A6p0s0ccXMaFUJzZcq l3qEAOs7o20IEJSfrOvzbCvIvQAaiRxCmY21Wz12oNYKA/S31U2Eodd6yecvjj/VzEA5 4UoDF20Uvn+PT+36Pfdh19GahzTK42JAoV5lKxEV+VOj6BdFdqYlYVtLX3/a1vwdUvaN FJXhtzs3DLDIf6xpdjhsQXiFcH32krZ8Z7C1z5PcK+FefCm3L0ThcacK0QcvjADeFFoL s6zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Cm0akHXB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t7si5253511qtn.208.2020.05.22.09.17.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:17:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Cm0akHXB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAMk-0005FL-Nt for patch@linaro.org; Fri, 22 May 2020 12:17:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKT-00038Q-Gk for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:26 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:41122) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKR-0006Eq-2Q for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:25 -0400 Received: by mail-pg1-x541.google.com with SMTP id r10so5193161pgv.8 for ; Fri, 22 May 2020 09:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sWktVAUx9ulLHoMCqPkS2j+iHzQ8DGPuikmGe+LrZUk=; b=Cm0akHXBJ44Xf4i0soK9E5rV+vLa3l1KWkBctdFf7kBUJ//m1QQ4AXHqDQO1h6uu9j UlRhlrcnfnjlxwkXv9EaKsjDFcLddrVZNOs2e5iXYdJHACrZGOYnWDu7IO9ObTGRlUHx 3f/UCqRYdjKg/DeM8Cz1/rRQvH+aDd/7lrAHb7TrgoeJRUDb4IAAsQfW8pETdZuFmJFc 7B4FiZ/pyLBvCmcclK2NhdtKkEtTAHbje2+3aCCcpHG3DQtfK047Wx4ngfPZS1CR7f+m qPN4D/TfeKGbs7/b1YQPZTNDOm6YgZBz7L+hK+qkxVLy9khFV1hXhwJ/ZF01xk/oRgdp VKTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sWktVAUx9ulLHoMCqPkS2j+iHzQ8DGPuikmGe+LrZUk=; b=Ko536QNTtXf3xHaYYO4OT4ABAODEauKRk8P8QQH7NbKWhRV1vWBbJ6aOOxIeHSzNQC tjzagO82+g4C1oQ5zzq9Y1nBykQMFyD8PjNofeF+JDFkWig2xPpIvpqOGL73g8RiD+02 4RS7/EdOtZuNPVYmkTJ7+JZhemd7f5fjToy4ZD3nZJA0QzVxpsTmqhtofmghPTQECoEI rTFa7lhAir/lJd6uaIXZixsR4dKAgtV/Ec4GK84qn7833Ccckzd5/FAqwZiktve6/vQM fW4Gc2vzL0scAnOJAEW2zskv9JYUHFuhgJPmwa7x70EzO/ZGpvjZmuvIwnCI0YvsBc+y 5HHA== X-Gm-Message-State: AOAM530dQ/1eamBKcQveCuV9sPZkH6UbRziNyslu+VcHOfLNAzRYn4O7 cJq9Fu7P66kTaobWEhBdRg+pdjryIiVhWg== X-Received: by 2002:a62:7a0b:: with SMTP id v11mr4662621pfc.111.1590164121017; Fri, 22 May 2020 09:15:21 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:20 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 11/19] accel/tcg: Fixed tsan warnings related to parallel_cpus Date: Fri, 22 May 2020 12:07:47 -0400 Message-Id: <20200522160755.886-12-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, Richard Henderson , cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Fixed several tsan warnings. e.g. WARNING: ThreadSanitizer: data race (pid=35425) Read of size 1 at 0x557cd83aee28 by thread T7: #0 curr_cflags include/exec/exec-all.h:460:13 (qemu-system-aarch64+0x4b7f27) #1 cpu_exec accel/tcg/cpu-exec.c:730:26 (qemu-system-aarch64+0x4b7f27) #2 tcg_cpu_exec cpus.c:1415:11 (qemu-system-aarch64+0x45b9b6) #3 qemu_tcg_cpu_thread_fn cpus.c:1723:17 (qemu-system-aarch64+0x45b9b6) #4 qemu_thread_start util/qemu-thread-posix.c:519:9 (qemu-system-aarch64+0xd431e0) Previous write of size 1 at 0x557cd83aee28 by thread T6: #0 cpu_exec_step_atomic accel/tcg/cpu-exec.c:254:23 (qemu-system-aarch64+0x4b6caa) #1 qemu_tcg_cpu_thread_fn cpus.c:1741:17 (qemu-system-aarch64+0x45baca) #2 qemu_thread_start util/qemu-thread-posix.c:519:9 (qemu-system-aarch64+0xd431e0) Location is global 'parallel_cpus' of size 1 at 0x557cd83aee28 (qemu-system-aarch64+0x000001fb3e28) Cc: Richard Henderson Cc: Paolo Bonzini Signed-off-by: Robert Foley --- accel/tcg/cpu-exec.c | 4 ++-- cpus.c | 2 +- include/exec/exec-all.h | 2 +- linux-user/syscall.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) -- 2.17.1 Reviewed-by: Emilio G. Cota diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index d95c4848a4..4cbdef1373 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -250,7 +250,7 @@ void cpu_exec_step_atomic(CPUState *cpu) } /* Since we got here, we know that parallel_cpus must be true. */ - parallel_cpus = false; + atomic_set(¶llel_cpus, false); cc->cpu_exec_enter(cpu); /* execute the generated code */ trace_exec_tb(tb, pc); @@ -278,7 +278,7 @@ void cpu_exec_step_atomic(CPUState *cpu) * the execution. */ g_assert(cpu_in_exclusive_context(cpu)); - parallel_cpus = true; + atomic_set(¶llel_cpus, true); end_exclusive(); } diff --git a/cpus.c b/cpus.c index af44027549..c5d04486a8 100644 --- a/cpus.c +++ b/cpus.c @@ -1966,7 +1966,7 @@ static void qemu_tcg_init_vcpu(CPUState *cpu) if (qemu_tcg_mttcg_enabled()) { /* create a thread per vCPU with TCG (MTTCG) */ - parallel_cpus = true; + atomic_set(¶llel_cpus, true); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", cpu->cpu_index); diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 3cf88272df..3f2c0290e1 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -496,7 +496,7 @@ static inline uint32_t tb_cflags(const TranslationBlock *tb) /* current cflags for hashing/comparison */ static inline uint32_t curr_cflags(void) { - return (parallel_cpus ? CF_PARALLEL : 0) + return (atomic_read(¶llel_cpus) ? CF_PARALLEL : 0) | (use_icount ? CF_USE_ICOUNT : 0); } diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 05f03919ff..8e39c09c5d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6022,8 +6022,8 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, /* If this is our first additional thread, we need to ensure we * generate code for parallel execution and flush old translations. */ - if (!parallel_cpus) { - parallel_cpus = true; + if (!atomic_read(¶llel_cpus)) { + atomic_set(¶llel_cpus, true); tb_flush(cpu); } From patchwork Fri May 22 16:07:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187181 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2649110ilb; Fri, 22 May 2020 09:21:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzdEXWdfvHm7BhRLxnW8XgRQZI4ulFZtcSMtDCvJGGWuQbvOv7tk13+BxX5IkGVb7fUW+1 X-Received: by 2002:a25:4c04:: with SMTP id z4mr24820948yba.466.1590164502689; Fri, 22 May 2020 09:21:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164502; cv=none; d=google.com; s=arc-20160816; b=u5Eu6lFV5U6LFC4nVyFRImGiPDZQz/Os8TmDvNS99c6sH7NheJnBtojbNKMN+66g4e UrGAO7xk17bU3QSq7Rm4+koCP9kaQ/8Y4ZCDB0+QMxlYHeU2ur9SvxGHqxRdKciRXtz1 o5DVKCzljB8El2GE4D2qIhw3BQEfGl/0arBq1SQbtZ0hcsUP+p9427y4mB656KozFgzV jeKQsAJEINbmahrZ6ZSlmyVlh6daWIIAQDqltlTtsmJoQirteNr0UTNOUr35oDjFcedD y73h5Q5EiUHST/W0unl2l44DbYoyOdMSTeKdNpJjF+xpRXuksFQdcN5CI3VSvMhViqqo aP0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=E2NUbUllh+KAafmECCEQXin5XBjgzmIjrK1tK+Jhx74=; b=thLri8Vewjbb3Coa6mEMMLrDMSCsJ4vHTxfK3KMvvc8ir8DOMpF8V3uDM9UUIc6F0v 6NVV286OhOtkHvWs1CuRq7ntsVMpyKZVZa7wtCnYHVtFu7ziHIKcSD9oicwvLOmECIQI 6DD6fwU8CQd+ut6qgil8VSLJ7j0aSJxYaLMxGEq+6AHrVEzAAyp0pNwALuoJNErS/Omk gjfKH3lOArOYrky+wN3EYZfaaf+sMcVjRn3Zfuy0hwMe9Fl+wX68V04P6A/cYaRfkGuR JYbdy2yZvMfeISUbT3YyRos4XKNXTXmjBhXGYlkHswjs8CD59l3t525sgDgSTYo/kLWf uzFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KkIZOsoP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r206si8016955ybc.378.2020.05.22.09.21.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:21:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KkIZOsoP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAQY-00057M-6X for patch@linaro.org; Fri, 22 May 2020 12:21:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKV-0003AI-CQ for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:28 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:44546) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKT-0006FO-63 for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:27 -0400 Received: by mail-pg1-x541.google.com with SMTP id p30so5183675pgl.11 for ; Fri, 22 May 2020 09:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=E2NUbUllh+KAafmECCEQXin5XBjgzmIjrK1tK+Jhx74=; b=KkIZOsoPSxtyYHa4qo7TTlEhyFRe1hQt3UNu58y4mklHRa2rWYiB0J2aYP1+yUiHsC HYWG+SlaK+uRBEYSzikdTAtW+3ZSjLJxFtIoX/OaOAfv9YSj5SwgIgWsfT6aUhbUW8as 3sAnUnH8lTFSl9iwfwkzoELmBKAxB3Encr5RibxG0N1n9jMqe+J4lOawUj88oTwjK1HK 7frTSAi1KOLYRC6rjAsmBC4RdxiHymYBd23EwjVqHm41VU2CNCFCWjfWQyMwzwssWHu5 dqDsOxgYFoiLkPviX8TNuKch6IkA+l6gKG7hjlKyQj8tRKVLwW0RAR4m510PcShLSukh 9Bfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=E2NUbUllh+KAafmECCEQXin5XBjgzmIjrK1tK+Jhx74=; b=DtvAJvbNDcnOAryLMXracxiqNq3W9GSyIUQeoKJRZ1vEi4bTtV9W+KFUqzQTCD7P6i aPSFOZ88xU3V4JVteg/LYyEcPPQmy1XqRS+2dTgGNQtcB4VAJoeCvI1ZCNH2TB1v/Z1e rlGFDHLWK4ANwM0yqB8QeuV1Vd19awmKoykDKOhmAQNrWYJjd0x0Rk12l8o20IxYf+VU 8DI76CAp97Y2B13dc39qfla1PO2qzUAWOw3X1L5V4HNCR4ptJVnn/FBB0yLAnpnKcS1K bFGpRVn8by94oNwORd23xjo3HxR4uk/jDV2S3dlZjrX0UJmF1ABVZ8HvoIpZSTP1Eiz+ CxfQ== X-Gm-Message-State: AOAM530boVvJHCXBNqxZQDctaR9umQbUT20kfZ3FHtru1nx2kAcG01lZ MGIgPM11AURdTZpuSJrdT6T96yGgUNrSpQ== X-Received: by 2002:a63:f59:: with SMTP id 25mr14173119pgp.420.1590164123073; Fri, 22 May 2020 09:15:23 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:22 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 12/19] configure: added tsan support for blacklist. Date: Fri, 22 May 2020 12:07:48 -0400 Message-Id: <20200522160755.886-13-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Initially put several files into blacklist that were causing the most problems, namely bitops.c and bitmap.c. Signed-off-by: Robert Foley --- configure | 3 ++- tests/tsan/blacklist.tsan | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/tsan/blacklist.tsan -- 2.17.1 diff --git a/configure b/configure index c95c54fb48..8a86a0638d 100755 --- a/configure +++ b/configure @@ -6306,7 +6306,8 @@ if test "$have_asan" = "yes"; then fi if test "$have_tsan" = "yes" ; then if test "$have_tsan_iface_fiber" = "yes" ; then - QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS" + QEMU_CFLAGS="-fsanitize=thread -fsanitize-blacklist="\ + "\$(SRC_PATH)/tests/tsan/blacklist.tsan $QEMU_CFLAGS" QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS" else echo "Cannot enable TSAN due to missing fiber annotation interface." diff --git a/tests/tsan/blacklist.tsan b/tests/tsan/blacklist.tsan new file mode 100644 index 0000000000..67dd809e96 --- /dev/null +++ b/tests/tsan/blacklist.tsan @@ -0,0 +1,5 @@ +# TSan is not happy about setting/getting of dirty bits, +# for example, cpu_physical_memory_set_dirty_range, +# and cpu_physical_memory_get_dirty. +src:bitops.c +src:bitmap.c From patchwork Fri May 22 16:07:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187179 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2648582ilb; Fri, 22 May 2020 09:21:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaY0AjJ3BVzFT1nyTgLq8Z86jgnF51qPQq1iOhlcOBG/PNOzCEFC3TntQZ+tq6Xl24422t X-Received: by 2002:a37:b743:: with SMTP id h64mr15228655qkf.460.1590164460603; Fri, 22 May 2020 09:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164460; cv=none; d=google.com; s=arc-20160816; b=aCfbOdgnbJwZkx3do++9StnmJ/qeVhqZ2kKodHwBFfcpgs820LqGIieLwLY8KhlfDr cRcfQKZEaUJNyxSihjUKHOC8yjTDwcFNAm+3jM7LN5VNHSeGjV2BFTx6OSNb4Vjd/c2h 5QgV4UoSy0qai52/clNBdlsUhk/z6HvczUzocabVE1R+rYRBxsdp+gj0czBOdTFb62XY 26eAwkRDX9a9P9b1I7l+Vid31Lm7XzglzU4KODTuxGMpPn38dAL6wgB3HvoxdKTT3VuV c5SgpGoRp4C1dnPhWb+bgBc60KPNH3CkIBRWWYpS6ieQsQars1gRGRQ8UPJH4eqLcLZS 9B3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=RmwrC3sLLuRkvLN26zkcFirbGoGQYa0KIlDIjcwq1Ao=; b=HiV2rsFGC0k+UysBTKS+8DWEUB1//aly76ufRf3YtS18QTrbRMX2D8jZFYTLNgf7J/ rrsx5FHA3DUtR/tBtEtvGR80UNbazKOiGg25YFWeTDE2sy8VndsqRmJsu7/W104iESJL uu4HzFNbts3wEAN7e3Xa4kmodGh4GpmxK4uWEk1xrDgthXcEmrPojFlP37UZ75JKTMaF eG9NxSeTkfNubcLZA7AjtiM1RharAPOby0t8m7liCYpXSQD9c+V8pscrOA2boKa79WRA FlHGPBjEscKGe8xUgNUm6pw4YEd6mo7J0mr1aa47ObIgx2Atf40JYTf7aW156TOgCA/g 84Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=N2W5klQA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f7si5283757qte.299.2020.05.22.09.21.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:21:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=N2W5klQA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAPs-00052B-3O for patch@linaro.org; Fri, 22 May 2020 12:21:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKW-0003Bo-PT for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:28 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:42794) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKV-0006Fb-0y for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:28 -0400 Received: by mail-pf1-x444.google.com with SMTP id y18so5388902pfl.9 for ; Fri, 22 May 2020 09:15:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RmwrC3sLLuRkvLN26zkcFirbGoGQYa0KIlDIjcwq1Ao=; b=N2W5klQADY+U2KyTIyrtrH2WNaG8WKXsoBq6Xhowpd6L48eQLDgZbu/RrQIRIgCGMK Rmn2ToDaewJL48Ir4W+XUFIQ9EUZC0PqpzUVJcofdAgLO0nrDUXuvvyqw3E/vJy2WBsx aI40QT1MZ91Zllwygdiaoh5+GUceOxLfUm659Y/AJdqQnz/DW/fdSTIemmkkweICIe1L CLyMKd0DrrLvyHsHqPQ7WTxptNFS+WrmLAuXyLTd1j1oc1HkD/EYqkAJSEr6wB4mo2Ze WO1Hch9QYkYvsAioGXtG8YjVBc/XLNJgojSRHX7P2HYR4bgURjYVpxoEM7EStKwCjApZ MSHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RmwrC3sLLuRkvLN26zkcFirbGoGQYa0KIlDIjcwq1Ao=; b=ApVzKxoKq59ddE7u1R1/QUM6iENgmBBf1Wl4I5eFGIeojmeWI6qE5kn4qESL0ard7v S7FGVr/PMIU94ZdiUpjmQvONcxWKn0t7ekt6Yw9kXB1GWaLpociXjnQV1OSXEf2LuXhp 9Uh5DUPyK2ZpQ0zzjVIn/MFlOR/T/LISGMRbYTOdDVaRjmROcZ07tJOI6RlHM0LXCwMU f5x0J8Gs/SXpQsOwuACkZFfOGPc6UKazRUlfmog8gwT9vKy5moaigJc0k5ya4dLGA52f jXIICbHeDQ4NVHyZW2IjJ4uUj2TAXslsljziKBT9NnfIynbZeE8sMSFtdqmECcRqW45Q Yb6Q== X-Gm-Message-State: AOAM532vUE0BdGja9mhPAL6ylhll9NU/rkCszTGJWMGsIIJpifurLc6X oVXrdLHxwJ/WQWz4pPjHiNJJxvisNxnqWg== X-Received: by 2002:a62:1512:: with SMTP id 18mr4611082pfv.326.1590164125233; Fri, 22 May 2020 09:15:25 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:24 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 13/19] accel/tcg: Fixed tsan warnings. Date: Fri, 22 May 2020 12:07:49 -0400 Message-Id: <20200522160755.886-14-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, Richard Henderson , cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For example: WARNING: ThreadSanitizer: data race (pid=35425) Write of size 4 at 0x7bbc000000ac by main thread (mutexes: write M875): #0 cpu_reset_interrupt hw/core/cpu.c:107:28 (qemu-system-aarch64+0x843790) #1 arm_cpu_set_irq target/arm/cpu.c (qemu-system-aarch64+0x616265) #2 qemu_set_irq hw/core/irq.c:44:5 (qemu-system-aarch64+0x8462ca) Previous atomic read of size 4 at 0x7bbc000000ac by thread T6: #0 __tsan_atomic32_load (qemu-system-aarch64+0x394c1c) #1 cpu_handle_interrupt accel/tcg/cpu-exec.c:534:9 (qemu-system-aarch64+0x4b7e79) #2 cpu_exec accel/tcg/cpu-exec.c:720:17 (qemu-system-aarch64+0x4b7e79) or WARNING: ThreadSanitizer: data race (pid=25425) Read of size 8 at 0x7f8ad8e138d0 by thread T10: #0 tb_lookup_cmp accel/tcg/cpu-exec.c:307:13 (qemu-system-aarch64+0x4ac4d2) #1 qht_do_lookup util/qht.c:502:34 (qemu-system-aarch64+0xd05264) Previous write of size 8 at 0x7f8ad8e138d0 by thread T15 (mutexes: write M728311726235541804): #0 tb_link_page accel/tcg/translate-all.c:1625:26 (qemu-system-aarch64+0x4b0bf2) #1 tb_gen_code accel/tcg/translate-all.c:1865:19 (qemu-system-aarch64+0x4b0bf2) #2 tb_find accel/tcg/cpu-exec.c:407:14 (qemu-system-aarch64+0x4ad77c) Cc: Richard Henderson Cc: Paolo Bonzini Signed-off-by: Robert Foley --- accel/tcg/tcg-all.c | 4 ++-- accel/tcg/tcg-runtime.c | 7 ++++++- accel/tcg/translate-all.c | 6 +++++- hw/core/cpu.c | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index 3b4fda5640..f94ea4c4b3 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -54,8 +54,8 @@ static void tcg_handle_interrupt(CPUState *cpu, int mask) int old_mask; g_assert(qemu_mutex_iothread_locked()); - old_mask = cpu->interrupt_request; - cpu->interrupt_request |= mask; + old_mask = atomic_read(&cpu->interrupt_request); + atomic_or(&cpu->interrupt_request, mask); /* * If called from iothread context, wake the target cpu in diff --git a/accel/tcg/tcg-runtime.c b/accel/tcg/tcg-runtime.c index 446465a09a..bd0cd77450 100644 --- a/accel/tcg/tcg-runtime.c +++ b/accel/tcg/tcg-runtime.c @@ -31,6 +31,7 @@ #include "disas/disas.h" #include "exec/log.h" #include "tcg/tcg.h" +#include "qemu/tsan.h" /* 32-bit helpers */ @@ -151,6 +152,7 @@ void *HELPER(lookup_tb_ptr)(CPUArchState *env) TranslationBlock *tb; target_ulong cs_base, pc; uint32_t flags; + void *tc_ptr; tb = tb_lookup__cpu_state(cpu, &pc, &cs_base, &flags, curr_cflags()); if (tb == NULL) { @@ -161,7 +163,10 @@ void *HELPER(lookup_tb_ptr)(CPUArchState *env) TARGET_FMT_lx "/" TARGET_FMT_lx "/%#x] %s\n", cpu->cpu_index, tb->tc.ptr, cs_base, pc, flags, lookup_symbol(pc)); - return tb->tc.ptr; + TSAN_ANNOTATE_IGNORE_READS_BEGIN(); + tc_ptr = tb->tc.ptr; + TSAN_ANNOTATE_IGNORE_READS_END(); + return tc_ptr; } void HELPER(exit_atomic)(CPUArchState *env) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 3fb71a1503..6c0e61994c 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -58,6 +58,7 @@ #include "exec/log.h" #include "sysemu/cpus.h" #include "sysemu/tcg.h" +#include "qemu/tsan.h" /* #define DEBUG_TB_INVALIDATE */ /* #define DEBUG_TB_FLUSH */ @@ -1704,6 +1705,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, max_insns = 1; } + TSAN_ANNOTATE_IGNORE_WRITES_BEGIN(); buffer_overflow: tb = tcg_tb_alloc(tcg_ctx); if (unlikely(!tb)) { @@ -1902,9 +1904,11 @@ TranslationBlock *tb_gen_code(CPUState *cpu, orig_aligned -= ROUND_UP(sizeof(*tb), qemu_icache_linesize); atomic_set(&tcg_ctx->code_gen_ptr, (void *)orig_aligned); tb_destroy(tb); + TSAN_ANNOTATE_IGNORE_WRITES_END(); return existing_tb; } tcg_tb_insert(tb); + TSAN_ANNOTATE_IGNORE_WRITES_END(); return tb; } @@ -2409,7 +2413,7 @@ void dump_opcount_info(void) void cpu_interrupt(CPUState *cpu, int mask) { g_assert(qemu_mutex_iothread_locked()); - cpu->interrupt_request |= mask; + atomic_or(&cpu->interrupt_request, mask); atomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1); } diff --git a/hw/core/cpu.c b/hw/core/cpu.c index 77703d62b7..6c16ccc426 100644 --- a/hw/core/cpu.c +++ b/hw/core/cpu.c @@ -104,7 +104,7 @@ void cpu_reset_interrupt(CPUState *cpu, int mask) if (need_lock) { qemu_mutex_lock_iothread(); } - cpu->interrupt_request &= ~mask; + atomic_and(&cpu->interrupt_request, ~mask); if (need_lock) { qemu_mutex_unlock_iothread(); } From patchwork Fri May 22 16:07:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187175 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2646873ilb; Fri, 22 May 2020 09:19:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdCAlswhfJdZa+t9Qe7vAZ/Zspg34wnNMZm2GnZDpAFvzWuq+ZRYzk01uUZoaeN161xy7h X-Received: by 2002:a25:cc87:: with SMTP id l129mr7207848ybf.18.1590164340644; Fri, 22 May 2020 09:19:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164340; cv=none; d=google.com; s=arc-20160816; b=PfkaAvSqlQmjgYvPpwp2WWv7BRZzvGH1qPdQ42UlWG/qBFkbJ32sBiQElyhDqMZUXK CcF47vQiBAkgt9DpbwktaEWh5uyxQi0WNZEyr2SeVZ5Bfm93kPlvrw6Vy7hn7n1DqxQS AtGySBFWfialVC/rDtdYp77thcLCrqv+QRvMw2sZOGuqrvrIBepN/bbg7397R2zUareF pnfOJijSUxTQOQdIoL3g8OBcgVWyNgVdAu/Ju0YZYrJL7gNtbYuSZbYquV1t1gx1NP+U vD33YaVrPVXiurYoLMwyBvJailBTwGBym4jFQxY05wTI46dCI2qKyJQ2xcijuDY89a/D gXVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=hhjHkZsuPQqpn5j1/wPu9TPYOQurYS1uCjZTE9jPves=; b=PnJSekGIuyO2y1pHXshYvn6Ne/q2jXi9pMSaF/95bpt9jTjLCpT48tSDVbCz50g6dE yRwmMvBw81vNSL0D8NeGn5CXcBVXsbMkuPgT2Q/nj5TDxOuuF3NMoZDH6sGSeir5HefU KhwyPn9G/4B8ErgGaKyVy4c2gnTAXlpQrK97HAFQzxbnoOBVZ6XoPs7840QRdmXYyZ75 IwldvU3hSyImyaUYytMTpgL8dYHszKV4qI0YJBtSrCsv9b0cr7rZOAOTQBz6ZEevOdp9 /E8nvw0nQCFxMonSzcWI2yFfWloQyVvQW2c9MSTd6wow4wZGOL1FyVTX6n07mKmtIoGe N1fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WHSPHQjy; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l127si4052537ybf.20.2020.05.22.09.19.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:19:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WHSPHQjy; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcANw-0000Tw-4Q for patch@linaro.org; Fri, 22 May 2020 12:19:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKZ-0003GA-V0 for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:32 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:40166) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKY-0006GA-NT for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:31 -0400 Received: by mail-pl1-x641.google.com with SMTP id t16so4573855plo.7 for ; Fri, 22 May 2020 09:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hhjHkZsuPQqpn5j1/wPu9TPYOQurYS1uCjZTE9jPves=; b=WHSPHQjyqPfkzx7W+A894tHes/HkqL5TUFS5Hj6vTkvKkXpW9L4MW55REOjg5JhSWk SdOcmNelEvU5zmmI0Y1wmOsFg3HijE7su3DitGIbdPwBdfyfUWc1n4Qfkco4B9WOHOkM /oZjjHwdzYqWBU3+SRAGvK9cgZlRLQjBuvQfs0bbAPKeclO5CutnSS89wJcQy76miFxb mnvlzxOnJ8HZylKa9IKqRbMj4R53lVBWz/0aBENrJeGdfGSJeY2S8M4H0vl1NB+Z1v/j CvrUsoqfLMuutzahVqHsyjKggQnPqI84rX0FeMHeCbLWgRnqU4DT26BimQ18ol9qPAV1 tM2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hhjHkZsuPQqpn5j1/wPu9TPYOQurYS1uCjZTE9jPves=; b=hBxtymA0m1tZcVScZylq9HviVBjiGjRXPI6Vw3L98hcYJlJbVmJRhXfugf+ZnzxOzO hNOQTBjKNBUK6BXw8qLqCcJ7yZ4GXicBIPif6kqg71Vs0tCGct8FvN3QNF+CSE4slR1p wUqyy+VBONY7ugW2f2d08kUQN8fkA3xNWr8hhR2HE66P0U3IdZOSfz/Ezp3xvrLkQ75M x1g6tNZIdieyONuaS9R5GtezAfFrW7TQJAchYc2/k+7M7eQ/lkjB9QLnDCxWKsXWzrqi beoYSoN/5+2WNoTtKA301WtqLxiHarDPa96T+A+XjZtPXnkvPexoEl2KFPNvKqYDW8yG pUiw== X-Gm-Message-State: AOAM532bcjs+5znm3j9GlfwDScKiSfdzV4HzfxcKqnNgBGYPyrfLgc8k 0NpiE6W9qWCIlZ0tPyIu/6HbhdEO4bF75Q== X-Received: by 2002:a17:90a:1217:: with SMTP id f23mr5114019pja.150.1590164127476; Fri, 22 May 2020 09:15:27 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:26 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 14/19] util/async: Fixed tsan warnings Date: Fri, 22 May 2020 12:07:50 -0400 Message-Id: <20200522160755.886-15-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::641; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x641.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , robert.foley@linaro.org, cota@braap.org, Stefan Hajnoczi , peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For example: Atomic write of size 8 at 0x7b4800113c28 by main thread (mutexes: write M30): #0 __tsan_atomic64_exchange (qemu-system-aarch64+0x386f85) #1 aio_bh_poll util/async.c:146:5 (qemu-system-aarch64+0xcd1f61) #2 aio_dispatch util/aio-posix.c:380:5 (qemu-system-aarch64+0xcd8abb) #3 aio_ctx_dispatch util/async.c:298:5 (qemu-system-aarch64+0xcd31b0) #4 g_main_context_dispatch (libglib-2.0.so.0+0x4c416) #5 qemu_main_loop softmmu/vl.c:1664:9 (qemu-system-aarch64+0x5cc6d6) #6 main softmmu/main.c:49:5 (qemu-system-aarch64+0xc62857) Previous read of size 8 at 0x7b4800113c28 by thread T3 (mutexes: write M81): #0 aio_bh_enqueue util/async.c:81:9 (qemu-system-aarch64+0xcd2267) #1 qemu_bh_schedule util/async.c:181:5 (qemu-system-aarch64+0xcd2267) #2 worker_thread util/thread-pool.c:113:9 (qemu-system-aarch64+0xcd473c) #3 qemu_thread_start util/qemu-thread-posix.c:519:9 (qemu-system-aarch64+0xcde280) Cc: Stefan Hajnoczi Cc: Fam Zheng Signed-off-by: Robert Foley --- util/async.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/util/async.c b/util/async.c index 1319eee3bc..51e306bf0c 100644 --- a/util/async.c +++ b/util/async.c @@ -33,6 +33,7 @@ #include "block/raw-aio.h" #include "qemu/coroutine_int.h" #include "trace.h" +#include "qemu/tsan.h" /***********************************************************/ /* bottom halves (can be seen as timers which expire ASAP) */ @@ -76,10 +77,12 @@ static void aio_bh_enqueue(QEMUBH *bh, unsigned new_flags) * 2. ctx is loaded before the callback has a chance to execute and bh * could be freed. */ + TSAN_ANNOTATE_IGNORE_WRITES_BEGIN(); old_flags = atomic_fetch_or(&bh->flags, BH_PENDING | new_flags); if (!(old_flags & BH_PENDING)) { QSLIST_INSERT_HEAD_ATOMIC(&ctx->bh_list, bh, next); } + TSAN_ANNOTATE_IGNORE_WRITES_END(); aio_notify(ctx); } @@ -143,7 +146,9 @@ int aio_bh_poll(AioContext *ctx) BHListSlice *s; int ret = 0; + TSAN_ANNOTATE_IGNORE_WRITES_BEGIN(); QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list); + TSAN_ANNOTATE_IGNORE_WRITES_END(); QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next); while ((s = QSIMPLEQ_FIRST(&ctx->bh_slice_list))) { @@ -280,14 +285,16 @@ aio_ctx_check(GSource *source) aio_notify_accept(ctx); QSLIST_FOREACH_RCU(bh, &ctx->bh_list, next) { - if ((bh->flags & (BH_SCHEDULED | BH_DELETED)) == BH_SCHEDULED) { + if ((atomic_read(&bh->flags) & (BH_SCHEDULED | BH_DELETED)) + == BH_SCHEDULED) { return true; } } QSIMPLEQ_FOREACH(s, &ctx->bh_slice_list, next) { QSLIST_FOREACH_RCU(bh, &s->bh_list, next) { - if ((bh->flags & (BH_SCHEDULED | BH_DELETED)) == BH_SCHEDULED) { + if ((atomic_read(&bh->flags) & (BH_SCHEDULED | BH_DELETED)) + == BH_SCHEDULED) { return true; } } From patchwork Fri May 22 16:07:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187183 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2650592ilb; Fri, 22 May 2020 09:23:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWzevONuHU8f8+h5ruxeqt7FrVCw3fx+vG9omSRXoW6fYjvy42SEOAdTjJ+qeEX656/7SM X-Received: by 2002:aed:257c:: with SMTP id w57mr16456255qtc.208.1590164610229; Fri, 22 May 2020 09:23:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164610; cv=none; d=google.com; s=arc-20160816; b=HgwwJYw8wm+1C+ft692MtC2QBLLXHtYbpcq60OhBHt/qyL8LI7RMRkCKAGRtjxM+wL D2LNtAjYsHozIVpjyZNZW8T8S3iF9IJOFot2DjIJ1ELh/g2jFRKEXQ4doJGhbbh+eeDj qIktBxy3Uhfb64fh7xrAMeL+rs8XFgb4ATd8UdSxDNEMsR6x4nbHYhrT0g15CY6v+ohS BT+9//RjCFQ592vdj9/fm+8CqdaxC+gxchwo/EBR92gfSS2YrafYLQLse5Q90nEb5hcc mD0OErTGNZ+AZLQwXq/8IIVvWGPbjyIoutFqKSQ8G1FJ2Ak2hiBWVRoq1surjI5Xm/us d4rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=sRbh5iLhIJgul14kcDJeTEj/XcHGk+PMKpVRoyVth+g=; b=bX5PSkd2hVbfPNHYT2gemi8P6TrIAVtD3Nb0phkEj+ox34eiFmAfvVdLuHNFtIGrjm jrBhOGpXGu8WZZnnmkVeQLP2NwIXdzKtQmHnMTnnArv6Pz6vJitiMvHaOhFGCeJuv/Kh hXBf3UgcgE4X51zXiR9Wf+dD439AmFo8Hh7mHuum+wMkIqZKlOO+4OqC/cfrWHASN3sm pVwEoGSE7kUuK2sJ3esWSpMNV/gWmSMe5yzUB0JMWOsHSuzl1inDMvXgE1iUY+/0lqKQ NqECM3ov85pyx/A4cdbrF7KOzgODp5/zWvDq/bGrp5kmyHotbofS+JNyTC2acwFFFagl XSew== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PIBtX2Kg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a123si1472624qkg.111.2020.05.22.09.23.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:23:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PIBtX2Kg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcASH-0000ls-NS for patch@linaro.org; Fri, 22 May 2020 12:23:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKb-0003Jr-Bb for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:33 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:39705) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKZ-0006GR-8s for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:32 -0400 Received: by mail-pg1-x543.google.com with SMTP id w20so179973pga.6 for ; Fri, 22 May 2020 09:15:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sRbh5iLhIJgul14kcDJeTEj/XcHGk+PMKpVRoyVth+g=; b=PIBtX2KghCulSwqtE4E+2lMTUvnCtv2kFXVft1HT72ud2AiuiPjQeh+WoHEYj3wduP JUyXBazeEzx3DN9vJqFwIWgjNYXGoMKSd0q7AEbJ4zzklyLFgpoIApc538pW3WwSiwKG V1ED0lM1E6tpCe6h3h7gbgq2JQsibfTItSglZ9xxd0w9PKrQzNZNSlSwr4O5wPm307Bq G9Ca5NAx4+fWYon/N772t4WKnG2POFkg1krJ5gqcfW8zUBdN0wQ7Olq669k0GUGxugCa /W0dEkFBM9FJ979mgOVEvZ+x4k69qR6E4YitFAK5YQIUoJiR1OQrwYWHWl3gr2HGh1b0 /Wjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sRbh5iLhIJgul14kcDJeTEj/XcHGk+PMKpVRoyVth+g=; b=HQe6mmFIXto2DqBirHzB/PDbBTYSuvMOEPExOaysh2JqvqAPqsIPYPtleqwWcdKmDw FxbZmmcEdDcesNRrx5t366DoCBzCCjaRB0l0RqTz40703auoxJnaCWidbhQEiK3aJAas llg59O7swA52XgT9gSBHQ/LbcfVueVrM/S9nLRJmAyBEqfwZXUF8bS05TV4z81OzsqrN vnNxYg2JyEzf2HXqhFbvcBHfhfp4Z7TCd5d2EG+5Jo/2KkFr8BsIUi9R7FdX3+dFZrBD vmNgUOGnAUFf5KxdEiOKrhSqh6RqgogBoDawxTuRGxY9HlZMYLTIqt7q0GBtSPS8a5pn jWeQ== X-Gm-Message-State: AOAM533SUf4xBtd2XlRkWUzL6lFakoNJ0UlsF1Ufxthik+1tb/4qEIs4 ryMWHQGb4fnhYgCS5RWc3z68RkvSZtmYBw== X-Received: by 2002:a05:6a00:46:: with SMTP id i6mr4755152pfk.146.1590164129705; Fri, 22 May 2020 09:15:29 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:29 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 15/19] qht: Fix tsan warnings. Date: Fri, 22 May 2020 12:07:51 -0400 Message-Id: <20200522160755.886-16-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::543; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x543.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For example: WARNING: ThreadSanitizer: data race (pid=23406) Atomic read of size 4 at 0x7b100003e3c8 by thread T7: #0 __tsan_atomic32_load (qemu-system-aarch64+0x39a36c) #1 qht_do_lookup util/qht.c:495:17 (qemu-system-aarch64+0xd82f7a) #2 qht_lookup_custom util/qht.c:539:11 (qemu-system-aarch64+0xd82f7a) Previous write of size 8 at 0x7b100003e3c8 by thread T6 (mutexes: write M166769147697783108, write M995435858420506688): #0 posix_memalign (qemu-system-aarch64+0x350dd1) #1 qemu_try_memalign util/oslib-posix.c:189:11 (qemu-system-aarch64+0xd59317) #2 qemu_memalign util/oslib-posix.c:205:27 (qemu-system-aarch64+0xd5943e) #3 qht_insert__locked util/qht.c:583:9 (qemu-system-aarch64+0xd837c5) Signed-off-by: Robert Foley --- util/qht.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.17.1 diff --git a/util/qht.c b/util/qht.c index 67e5d5b916..739a53ced0 100644 --- a/util/qht.c +++ b/util/qht.c @@ -69,6 +69,7 @@ #include "qemu/qht.h" #include "qemu/atomic.h" #include "qemu/rcu.h" +#include "qemu/tsan.h" //#define QHT_DEBUG @@ -580,10 +581,12 @@ static void *qht_insert__locked(const struct qht *ht, struct qht_map *map, b = b->next; } while (b); + TSAN_ANNOTATE_IGNORE_WRITES_BEGIN(); b = qemu_memalign(QHT_BUCKET_ALIGN, sizeof(*b)); memset(b, 0, sizeof(*b)); new = b; i = 0; + TSAN_ANNOTATE_IGNORE_WRITES_END(); atomic_inc(&map->n_added_buckets); if (unlikely(qht_map_needs_resize(map)) && needs_resize) { *needs_resize = true; From patchwork Fri May 22 16:07:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187180 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2649115ilb; Fri, 22 May 2020 09:21:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoCppKxM68FhinQlUW8Vg5DxBp1Z0g1lFstin1+vz94c/EXS0RkoM/5dCFUtqYgK+Cj5LF X-Received: by 2002:a25:c010:: with SMTP id c16mr9567297ybf.506.1590164503103; Fri, 22 May 2020 09:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164503; cv=none; d=google.com; s=arc-20160816; b=svsJ5WUpkW1Z4vDAnsq5gvRe30MhZD5gA7XfAXjC0YdXkJVAOiwHnu38dzCelu4vg4 S8UR2OKAfvv+D9LXI6gx5oqmWFaJrnKqcYXl0ed9moz8NiTllkgks/uPhddhc1vma5ac mq/mSDiDRtpGMFPBTMcgDnxTaLNl4UKcuPOtWssblqRQT+SroFzzFL76DYb1i/ECvDiS eXfzF38Vi42suzUqVHDrUKtLlsygEZwmUKVaSP4b6r2uMayuvLog5/LAt1mB1TUy4jcH g8pwFY6W+Fyy/bQ+TFFgWzEUQiSiEB5BLVSkCcO8ufZ/lmF2ll0catui5eC796KFvbvW Kscg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=diIOPIiuRLIcEaQmwzzlKokyZy0yKGmGdNzT1yctxLA=; b=B4vejI4UtfVj74ZOaYgHzmZkM6rD1KZJZOeUaHDdXCrx3Q77c+zlfMIeSzMRVDc17O HL/92ItxnTOoNEke/P0pRAIr+lyUJ0pmZdXbeJiQ2RmQydGTgiEXAySp3steEQVVy2lt 931h5YBdcTtzqNRGGrIeynzSQw5Ww5TSNnj77aO99gyetV+ZtSWix4J0CdjerjW+hrhe zYsm3PtIz4KE3VJXhnaH2OgZkq85PAL5dmS3q8XiX0/rYHvKK3IgPAEgXxCq1W7JD3NI JCD4pwhVkYSUZMmZ3naUjVMxvw8riFaC19Zxtu5bHZ3pCCTxqAzUDqGeU2cEzhV8MaQh wfag== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=y4htgXC0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n129si8683105ybg.54.2020.05.22.09.21.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:21:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=y4htgXC0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAQY-0006K7-HU for patch@linaro.org; Fri, 22 May 2020 12:21:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKd-0003Q8-KO for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:35 -0400 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]:52588) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKb-0006Hv-9G for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:35 -0400 Received: by mail-pj1-x1044.google.com with SMTP id a5so5132886pjh.2 for ; Fri, 22 May 2020 09:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=diIOPIiuRLIcEaQmwzzlKokyZy0yKGmGdNzT1yctxLA=; b=y4htgXC0XqAXfehtDZQyLI9kx5BTzgc4CTGWxcPXdh5B0UA+GPS1ORWRLQyFPk/lO+ TnKu76KLNbHbLTK0McGA3WrmyD/dilSsefEJjCSzk4SJUxPf5803dOQx1bIbgn8TS1PI MRz5pZv8tZev+gcRlNm3vX7/zntQmNBvTFhr6RsDswnQ/JW/AWORUhVEYFT3O6Lz3uwQ JA/WM+99857+4onUrQD16AxqoEClH/W8l/KpZf34uoLXKhe8x5yCaCKhBxAhjzovsL9f djQJSYRJKmikgS6u765pkXlJusu1Q3sA3gB2KM5iPrQvy41MMtkb3OAGm3W9q9FaZfoz s0PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=diIOPIiuRLIcEaQmwzzlKokyZy0yKGmGdNzT1yctxLA=; b=rsUr/23n8bmhOb3ESYKV0FJ1php01nrIF+30PdbxXNqVD7HTev5pZZordgkg4FUFEH JKc5dMdFX8fXNoZstW0SCy4EAzQQMTu2AN6Adg7FiCepIPw5WAZmfZ+X1N62VbD04Ngn raZRVKB4QmguR08Ivy4vvid8F465uldVJ0uPNIfvkK87bGwjqpTJj8afcGfVOGBmg69L p0kL0ZpcFtzR9nBcoxQmvUFFQqVnH9wW+W+iqikgMOsDMGygfDRCcVqME0i2qLTs77gi CgyebGvhBwuk5EEvRyUjEZBVue7q3YBjpVh1v9z+esSRxs0n2c7yV133x6Dmd29QVJfB ip6g== X-Gm-Message-State: AOAM5300UhWdhz9gmXklsz1NilzG2y6QjP3dPfB4RVU4obXDHLtY/K6F rqKlmETUSh2I4YqwdVDlXhGN8rbgrxZB1Q== X-Received: by 2002:a17:90b:1082:: with SMTP id gj2mr5610647pjb.225.1590164131706; Fri, 22 May 2020 09:15:31 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:31 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 16/19] util: fixed tsan warnings in thread_pool.c Date: Fri, 22 May 2020 12:07:52 -0400 Message-Id: <20200522160755.886-17-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::1044; envelope-from=robert.foley@linaro.org; helo=mail-pj1-x1044.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For example: WARNING: ThreadSanitizer: data race (pid=14665) Write of size 4 at 0x7b1c00007890 by thread T99: #0 worker_thread util/thread-pool.c:112:20 (qemu-system-aarch64+0xd52108) #1 qemu_thread_start util/qemu-thread-posix.c:519:9 (qemu-system-aarch64+0xd5be30) Previous read of size 4 at 0x7b1c00007890 by main thread (mutexes: write M875, write M897): #0 thread_pool_completion_bh util/thread-pool.c:177:19 (qemu-system-aarch64+0xd51a73) #1 aio_bh_call util/async.c:136:5 (qemu-system-aarch64+0xd4f98e) #2 aio_bh_poll util/async.c:164:13 (qemu-system-aarch64+0xd4f98e) Signed-off-by: Robert Foley --- util/thread-pool.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/util/thread-pool.c b/util/thread-pool.c index d763cea505..2403669827 100644 --- a/util/thread-pool.c +++ b/util/thread-pool.c @@ -21,6 +21,7 @@ #include "trace.h" #include "block/thread-pool.h" #include "qemu/main-loop.h" +#include "qemu/tsan.h" static void do_spawn_thread(ThreadPool *pool); @@ -97,7 +98,9 @@ static void *worker_thread(void *opaque) } req = QTAILQ_FIRST(&pool->request_list); + TSAN_ANNOTATE_IGNORE_WRITES_BEGIN(); QTAILQ_REMOVE(&pool->request_list, req, reqs); + req->state = THREAD_ACTIVE; qemu_mutex_unlock(&pool->lock); @@ -107,7 +110,7 @@ static void *worker_thread(void *opaque) /* Write ret before state. */ smp_wmb(); req->state = THREAD_DONE; - + TSAN_ANNOTATE_IGNORE_WRITES_END(); qemu_mutex_lock(&pool->lock); qemu_bh_schedule(pool->completion_bh); From patchwork Fri May 22 16:07:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187184 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2651431ilb; Fri, 22 May 2020 09:24:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyr1ivZHoFlr5NwY0znDMmVoGISP8wPNpWA++kyokPJPZhw3Fn+MWuq/CgpguM2Ev9ReVMQ X-Received: by 2002:a37:61d8:: with SMTP id v207mr16412148qkb.146.1590164682093; Fri, 22 May 2020 09:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164682; cv=none; d=google.com; s=arc-20160816; b=WhwLcp4HlUGVkbYLBcgDcl9Yn0KOjfnQN1ztXOGLTWcZmKEX8fjqQHGIRYxAAIjw4f MZikUyHwbc1BozcOg11PFooZ6pKZdPegOshfW0AMhdTr5c5MVlv8Yts5uWqBK5KYRC3f 3WAfgnaOQVvBaGd/j2h+tvI7C2HkeT29ThffRa0vcJOsMFjUW8SxqaCOAaraHPsrZlRa 0yqY96ZWXm9tgiGM4Lytq/BFnPesaieAC3g1ED2aX4GHQnqtvt19BSPBBn6ji278zXee ZH84vWRFcZi1uWTdXVD2b7aJl8uyu1WClozUwVsfR2WWdcPcLV0xTrsYLYO7ekGewQUP yj2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=A/nKw6Isa4Oy51HOhG9UE8FR/bJbLBceggcTqOyEfB0=; b=i2AZg0pf5qfk0BmFszBtsW4Mid9SIQJvBM7TExaOKLs4+lWXm7+diEzmda8EM/AI4E 35ukJ2quBSrGcSex+Ztdf/uLQMd7cCTDbi+jXZ6bnZ+N8nxzTVNBZSSVIxTrqEvBZXA/ /Jhj47eAsKO/13jQoSBt0WnlpcsE8DY4GcqyU/8kV6d1/+V3uYvDEXlOoSuIoZSvboab OlMDy0reWCp/QDemHYQdB813f7cCzW/mA2rHEEFRm/ogdlwQXbwAQAsbWxMMvM434Ztc maf19IrvEfeeFQcIF/GKgxhKRvs8ajiFSSvfepVSNAdPmQ1zd8m+bJafiipNRXKYkCct pIAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GNUp0U1n; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id az9si992290qvb.167.2020.05.22.09.24.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:24:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GNUp0U1n; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcATR-0004nI-KD for patch@linaro.org; Fri, 22 May 2020 12:24:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40490) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKe-0003Rm-6P for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:36 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:43099) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKd-0006I8-86 for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:35 -0400 Received: by mail-pl1-x643.google.com with SMTP id k22so4567170pls.10 for ; Fri, 22 May 2020 09:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=A/nKw6Isa4Oy51HOhG9UE8FR/bJbLBceggcTqOyEfB0=; b=GNUp0U1nhxuxngkyDMTNsnpGA/d53w6KxMd8KlP/3m7zeATcCIG7xrrSyIBqYMFBuM aghOEnTh/k82NwcDMLQXbC+5HkJXN45Q3QxXbOVGGrC6jJFIx7Y2dUXaS/ookwmGRP/X qMGatvSQU975cg4iXHgLIS+nzHufl63e2b2u/xkMSBR+GZ1kx0Niewnir32DD0vyzwTv AaqKHdmAfU/7BHHpTPtfOAJUO0TXonPl+mkGHAPJkmGDhgUcEPFjjqOD0aRrtwFiaJho mriiQYnJbmC88D0wQzawIRCulCUwxhNNCU6YmIHEF4A1bLrJz/315PYXyojL5xrrwQjl ac6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=A/nKw6Isa4Oy51HOhG9UE8FR/bJbLBceggcTqOyEfB0=; b=A+F/KXf5RhaOSBV5e5OejE7EPgVgf3BFwiIIfEAIV+FSUVpnCMB/Z7J4iSiZ3oYNa4 ks1HtUxCYDWb4lGt2ReymI2oRam9AbRCgELLJ5m7YgZ0wZpa/COVd01MTIb//f39NB4V OQPi8Y12ZW2H7NPHed3GT0cN9uw4hXnO/LlxUDACe70G34fLbl6hb9Q2JQyW8/FkDv4m EZXnxfWm7LCOqrRZnNJ16B4AQwe7gKZvYnMsDk8m7iJ0vUn+9VBcniRY9aNjxkLDyLdA dtkzciaajO+95LyxL0TiNOpgFKcTg++Ke+Hac0cpV/hPPqxkumErgcKp553m2Qxl4Ag0 rgfg== X-Gm-Message-State: AOAM531E/J8zeewGkPBolYzrrQaLnjtEarh8qc5nvgLBumhHKp63WUlV Db7UnwdBdvMtvxq5HnKNzyyEXlkl6OTbrA== X-Received: by 2002:a17:902:8d8d:: with SMTP id v13mr15554071plo.67.1590164133603; Fri, 22 May 2020 09:15:33 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:33 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 17/19] util: Added tsan annotate for thread name. Date: Fri, 22 May 2020 12:07:53 -0400 Message-Id: <20200522160755.886-18-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::643; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x643.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This allows us to see the name of the thread in tsan warning reports such as this: Thread T7 'CPU 1/TCG' (tid=24317, running) created by main thread at: Signed-off-by: Robert Foley --- util/qemu-thread-posix.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.17.1 Reviewed-by: Emilio G. Cota diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 838980aaa5..dcbc82d80f 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -15,6 +15,7 @@ #include "qemu/atomic.h" #include "qemu/notify.h" #include "qemu-thread-common.h" +#include "qemu/tsan.h" static bool name_threads; @@ -513,6 +514,7 @@ static void *qemu_thread_start(void *args) # endif } #endif + TSAN_ANNOTATE_THREAD_NAME(qemu_thread_args->name); g_free(qemu_thread_args->name); g_free(qemu_thread_args); pthread_cleanup_push(qemu_thread_atexit_notify, NULL); From patchwork Fri May 22 16:07:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187186 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2652735ilb; Fri, 22 May 2020 09:26:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkNNN2+sXGfM75MkJxdLxXa805LYlHO1yTfAiJE3rN/Oq6pCpxTGY/CFIwJ+Cgv381rjCJ X-Received: by 2002:a5b:185:: with SMTP id r5mr20639464ybl.39.1590164778934; Fri, 22 May 2020 09:26:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164778; cv=none; d=google.com; s=arc-20160816; b=itbfCBec5EQk1Tw47FuEuXMQ5PZvC7df3OwDL0yDaBrCrE00cCvAY6pb6j6pZdWPfe gSGIMVTO972wWQjXiFC58r68B9hsoSK7jxuakwd1Fw0TlqUl88glnq+p5gSzRcnVpjRl co/zovlyhp0UPk3Vox7+/sgw1CuLsgWlm6HmjYbkpiY716GNSFlYH/nr9bSDQWzbGnzx VmHzzA8hr/jZDtPIfBJXJLKORnQkrhx9K6GQ+hdSZMPNJyHrTrxfKCPdgsRJuR/ciSU+ 53poOMk43CsAeDpXYDiK4NTSPe0pJffyZI9jtRa6Q/XVKV2SgTree5xVAxnRRzSrnnkQ ZrFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=HfLXLJX8xYWjaZkhWytSgY03XSw6juhoh6RiJzn7u1c=; b=Et4/Qq0QOgWUnY8089kPguj0sQe3VU2oEXOyXghx3twc3GITQChHQGWLSyXY1Xyr7C GIFtj5uN2SEyWg3AXBCHpvqwzHyxz9s7oxfR6kqKk6LbgHtQvDlmF9gjWTUGqCTuPsU0 +UAbGHB0Po7HjCCGsJiueMR1hryZCiCZRpX78kzTWxiqKFa2uu0ZMGr1ZKWett4BaO4I RDNSfKcHenm5hVhvbVi9JWpjf52EJ9ovte4Icdeh4u4zLwX9JZx9gI3246WegXeZGyIQ slm2eWXSHdXSswPRGeL6rEXRYRtAm7tY1mJNNl2f6b0u1O1NIZLIBBZZaW6nHezjrcYm sSRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CT+0Y3Lb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q2si8464485ybf.167.2020.05.22.09.26.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:26:18 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CT+0Y3Lb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAV0-0000H2-ET for patch@linaro.org; Fri, 22 May 2020 12:26:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKg-0003Xh-K3 for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:38 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:38071) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKf-0006IS-KC for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:38 -0400 Received: by mail-pl1-x641.google.com with SMTP id m7so4577354plt.5 for ; Fri, 22 May 2020 09:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HfLXLJX8xYWjaZkhWytSgY03XSw6juhoh6RiJzn7u1c=; b=CT+0Y3LbfxdDeDDkrK9LzvOCb5kJTQVIScmmf8UAVpnilrJkIAI/qy+DWy03GLp1BR kV4cwcmj1hF3BPf9DB3nl1r0zEjT0hTDm8HiBQWtPptLJOfR4C9g5Koc+OtWxF5soFTH Qpz1chJuI7ONIltDBzLBqEp8+0gIz0EiZcqMAzixEP4Ay2N/gYsByQiDqmNKhke3bPiF niGvg/+q0aWcVX5knDifbiatYaXYa2BIVv8TTvSu6MU6osYMNT6bF4nFWPlmumOCw5nQ xqMXTAaklCAgQKCVkX6EGSb2FDHeVmt/7D7XKi+DyeLf4wPBvaOBvY/1wK2JXWLUzcop xerQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HfLXLJX8xYWjaZkhWytSgY03XSw6juhoh6RiJzn7u1c=; b=uWhvzgA94I2KsWZIid6n+dAME073+bAGb5vO5kdJXzaC5o2ozLtvOpIDdVvIrP+FiF mwIpLelJzen43CTiDHJoXMGIz+IOAZa4UmZXuT8pQUzkdNLivDJtQ1+dkd8xtEEpn+Ca 6nMB1ts7JqZHGimLBxqF2i3GDxd5dtFOMgXPt5qJlzzUUyw1uo5/S7/dh0QjZFFagQBR c6I2U1rOE9eP6JyVv7LeFzkfRaUYNJ3M4bzgHqAV+DVGfTsnpyZYes9R7ZzLJq+uk2Rz 0uGROOb/ItgaRTw6VQdx5SRznb26mIK9BUSIcg0TR+M28qNcuo+9NEazItaAb5WRfthX op9w== X-Gm-Message-State: AOAM530FrPNhB9fP3bzngQ165GgS8FDC4zYm00bCKiUhcWy59sS7A2pr IsY03v8er9tPaKzTaGrDW7aTPunHktp9BA== X-Received: by 2002:a17:902:694b:: with SMTP id k11mr14190443plt.77.1590164135801; Fri, 22 May 2020 09:15:35 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:35 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 18/19] target/arm: Fix tsan warning in cpu.c Date: Fri, 22 May 2020 12:07:54 -0400 Message-Id: <20200522160755.886-19-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::641; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x641.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , robert.foley@linaro.org, Richard Henderson , cota@braap.org, peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For example: WARNING: ThreadSanitizer: data race (pid=11134) Atomic write of size 4 at 0x7bbc0000e0ac by main thread (mutexes: write M875): #0 __tsan_atomic32_store (qemu-system-aarch64+0x394d84) #1 cpu_reset_interrupt hw/core/cpu.c:107:5 (qemu-system-aarch64+0x842f90) #2 arm_cpu_set_irq target/arm/cpu.c (qemu-system-aarch64+0x615a55) Previous read of size 4 at 0x7bbc0000e0ac by thread T7: #0 arm_cpu_has_work target/arm/cpu.c:78:16 (qemu-system-aarch64+0x6178ba) #1 cpu_has_work include/hw/core/cpu.h:700:12 (qemu-system-aarch64+0x68be2e) Cc: Peter Maydell Cc: Richard Henderson Signed-off-by: Robert Foley --- target/arm/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 32bec156f2..cdb90582ee 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -75,7 +75,7 @@ static bool arm_cpu_has_work(CPUState *cs) ARMCPU *cpu = ARM_CPU(cs); return (cpu->power_state != PSCI_OFF) - && cs->interrupt_request & + && atomic_read(&cs->interrupt_request) & (CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD | CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ | CPU_INTERRUPT_EXITTB); From patchwork Fri May 22 16:07:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187185 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2651472ilb; Fri, 22 May 2020 09:24:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcPxi3pfFtE0K66wq/bhe1ovKs2jpJ5YAHHyNYJWxy+Indgi7GCbg0rKjJv7ApQ2VW+HcU X-Received: by 2002:a37:e309:: with SMTP id y9mr6646034qki.206.1590164684527; Fri, 22 May 2020 09:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590164684; cv=none; d=google.com; s=arc-20160816; b=zf1l1dDZA8e1PY7H+7fVyU5UCA6lRP6AucEJl1UtxCFI+RLrjWXN9GUApQHyIN0k+Y RBvpjDNdQzftsIPr6RzkCE3I8gqV8eoQWvGR4hHe0852vDQmwjQTdGB76A5UTkVyi3Fj R9SNd1vDfyZ5DoMMg4q7HV2uvapudBW9GesN5Wn4gEny9wlQzDdwVBxlJ6lG8tszT6aT e8VrJ1U79MFbqPq1VKWPTKrORxqmfDaIzwasd74Vf67DqqemmIlDAlkgSIfSxjcn2mv9 fZ709ifEC2cbdf2djRfVsI6x8r/v8ap/7GxiytRLCrUjFsl+XVf1APtKPdfFO9F9rN+e CJfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=NheIrwAPnCYgtMEumEcCojybpzE1xkpB6QxsKMCy5vo=; b=VSrIcQ1M4UYOKEJ1+nnCh/i1CC+v+EgGOHWf1ZUWbk7ZZnB7cqnKMrF6phnzGymaXs lg4z9NOEdH+hY1kYwgsQ8V5ilbamDFfDB9I1Fje7FU8YtqDRS9o5G4O+VcLDOv8fK3Wn AV6k7fR8+Kmeqt8ce6Sy6TYMkKU0D0fSw8z4B2sVpSz1+OQg3y2AyT7RAHX1xdJs+Fm5 fLXGqOY4+rydCGAu3GsM2XxUbvDllVfBHEqX6GEclTdNyneiaBSSHJiPDjG3ig5q4SXD Z/WMqNq35qx0QMNDlCS81OMf/9XGyunYrd9MnIWG5qUkFhvvKVSr1E3S6nwv9MudANN3 Bzzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GaOU4WrC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d12si5328334qvv.24.2020.05.22.09.24.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 May 2020 09:24:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GaOU4WrC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcATT-0004op-UF for patch@linaro.org; Fri, 22 May 2020 12:24:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKj-0003dT-0h for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:41 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:35635) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKh-0006JT-Qp for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:40 -0400 Received: by mail-pl1-x644.google.com with SMTP id q16so4580738plr.2 for ; Fri, 22 May 2020 09:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NheIrwAPnCYgtMEumEcCojybpzE1xkpB6QxsKMCy5vo=; b=GaOU4WrCYODdrY8UKoFMtLv93SAadUOT5ArmGLTkLq+AHpZuoiQFKQa+IMWvS0lqss eU1I/J1b/i1fjNWgHGMWmfCs0DqwAFCfyHOLqIWAcc1nLx2rXo+mN6xj6nMon+vf0s7J luKu8y9Cnp1/85Pg2i6b5x6mGOyj9vwfRkJ32xqFkDZYjUozjAF1K+FqaghHX3Upkv3z mfCKIalBSdooEGfy2aFGy8wMxxUjW9pVG7JhdMTJCvQO+8pf6DOiCbAhTuZSRs1Et0t8 7awqt4hUHVwdahTXHmTy61xcSotRSKqnm87yraG6gd9KkearXHhKabyht+ACBtReFNuQ 2HOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NheIrwAPnCYgtMEumEcCojybpzE1xkpB6QxsKMCy5vo=; b=jNoeHJwVq3BEI1ZHDbQm67Jt1mL5JFKQEDToNRsneunZ9a/sLecq8G8wGdnFm5shWJ 21sHBv4+9mioUjrxbfutpEi1fkEsSXbqcuPHkdn/o/EfEiwV4aQZNP8nAIyAE/RQ+zL/ 2hWuh3MfOEYbBZM/ijcd75GslD4zVYyOAXWw9DGR8LmTIAv6sG/pHq9GoCgbFtbrqAee XvETVZCBT0muB4xHHK059dj3DLRDses7Uh5gM3x3MV+MnwAQajM5Wjwpsg6KTyaj6pbx FxCMnOZWIvQsP029HUSGq2XHZ8Vf7Al/Vn1/ao9EQtDsQfTtgm5H63Y6Tavtwh/UjUVa o9Dw== X-Gm-Message-State: AOAM531+lzV2w6/x+cehvVBQ3ic5gdPfg2S4dApal6wHPjG7EXJCZr+Y nULmQ/NEShmW+8hDzgIdhmqlycj8MaSDFA== X-Received: by 2002:a17:902:44e:: with SMTP id 72mr15445673ple.301.1590164137952; Fri, 22 May 2020 09:15:37 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:37 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 19/19] docs: Added details on TSan to testing.rst Date: Fri, 22 May 2020 12:07:55 -0400 Message-Id: <20200522160755.886-20-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::644; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x644.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This includes details on how to build and test with TSan both inside a docker and outside. Signed-off-by: Robert Foley --- docs/devel/testing.rst | 72 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) -- 2.17.1 Reviewed-by: Emilio G. Cota diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst index 770a987ea4..5b0a828068 100644 --- a/docs/devel/testing.rst +++ b/docs/devel/testing.rst @@ -397,6 +397,78 @@ list is in the ``make docker`` help text. The frequently used ones are: * ``DEBUG=1``: enables debug. See the previous "Debugging a Docker test failure" section. +Thread Sanitizer +================ +TSan is currently supported in the ubuntu2004 docker. + +Just add the TSAN=1 argument to use TSan + +.. code:: + + make docker-test-build@ubuntu2004 TSAN=1 + +or + +.. code:: + + make docker-test-quick@ubuntu2004 TSAN=1 + +The runtime behavior or TSAN is controlled by the TSAN_OPTIONS environment +variable. We set this variable automatically to for example, maximize +the number of warnings TSan can find and also to specify the location of +the files with TSan warnings. + +TSan warnings are placed in files located at build/tsan/. + +We recommend using DEBUG=1 to allow launching the test from inside the docker, +and to allow review of the warnings generated by TSan. +A few important files to note are: + +tests/tsan/suppressions.tsan - Has TSan warnings we wish to suppress at runtime. +In some cases we choose to put suppressions here since the resolution is +slightly finer than the blacklist, since we can disable by warning type. + +tests/tsan/blacklist.tsan - Has TSan warnings we wish to disable +at compile time. + +include/qemu/tsan.h - Defines various annotations which can also be used +to give TSan more information some example uses are to allow suppressing +TSan warnings, or annotating thread names so they show up properly in +the TSan warnings. + +TSan without docker +------------------- + +It is possible to build and test with TSan outside of a docker, but with a +few additional steps required. +These steps are normally done automatically in the docker. + +First, to configure the build for TSan: + +.. code:: + + ../configure --enable-tsan --cc=clang-10 --cxx=clang++-10 \ + --disable-werror --extra-cflags="-O0" + +There is also a one time patch needed in clang-9 or clang-10: + +.. code:: + + sed -i 's/^const/static const/g' \ + /usr/lib/llvm-10/lib/clang/10.0.0/include/sanitizer/tsan_interface.h + +When running tests, the TSAN_OPTIONS environment variable needs to be set. + +.. code:: + + export TSAN_OPTIONS=suppressions=/tests/tsan/suppressions.tsan \ + detect_deadlocks=false history_size=7 exitcode=0 \ + log_path=/tsan/tsan_warnings.txt + +The above exitcode makes TSan continue without error if any warnings are found. +This allows for running the test and then checking the warnings afterwards. +If you want TSan to stop and exit with error on warnings, use exitcode=66. + VM testing ==========