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: 11565907 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CFCF6739 for ; Fri, 22 May 2020 16:16:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9704020663 for ; Fri, 22 May 2020 16:16:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="s0Qa8JM5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9704020663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcALG-0004N9-Of for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:16:14 -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-Google-Smtp-Source: ABdhPJzxSmD7KEq2QPryYQMHBtj+5onh5agc3+Yz2is4fS0MDWtw+Cs+5HX/qpkXNG/lQa97hbuSlw== 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+patchwork-qemu-devel=patchwork.kernel.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(-) 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: 11565915 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D8B8739 for ; Fri, 22 May 2020 16:18:25 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D825320663 for ; Fri, 22 May 2020 16:18:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ONf2Ckbo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D825320663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:55706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcANL-00081m-Qi for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:18:23 -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-Google-Smtp-Source: ABdhPJw9suB9vdA8ZJLsS+tfBe02QbhLf2PtDNmG5JFqWlBe4c9HvJGkTUdNefGrLHuynm4yPDDuXg== 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+patchwork-qemu-devel=patchwork.kernel.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 Reviewed-by: Philippe Mathieu-Daudé --- 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(-) 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: 11565909 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C04FF1392 for ; Fri, 22 May 2020 16:16:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9792620663 for ; Fri, 22 May 2020 16:16:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ccGLHO1w" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9792620663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcALI-0004S5-Po for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:16:16 -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-Google-Smtp-Source: ABdhPJyCWEBAqgBlzzZJeZGp6mNgNwpgUuW84wee+Ybay5X/X0tfJmay/ZSt9yK/jPfOXAS580My9w== 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+patchwork-qemu-devel=patchwork.kernel.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(+) 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: 11565911 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65B2F1392 for ; Fri, 22 May 2020 16:16:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3CF9E20663 for ; Fri, 22 May 2020 16:16:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="sJInSJ3s" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3CF9E20663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcALN-0004dz-Cl for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:16:21 -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-Google-Smtp-Source: ABdhPJzo48VSi3ztMal9raejfrpDrWqSAzJMJfDolCRnzB922MRga9wqozGuaZAU1Iu2qgxZbtQiRw== 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+patchwork-qemu-devel=patchwork.kernel.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(+) 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: 11565947 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9ABAA1391 for ; Fri, 22 May 2020 16:23:34 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 720C32070A for ; Fri, 22 May 2020 16:23:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="EflvFJMn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 720C32070A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:53300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcASL-0002fX-IP for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:23:33 -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-Google-Smtp-Source: ABdhPJxxa8q1BvPVAb0Dfq2B3L4+SFf1kgZLZLM0P814nYfjSooeOlG+SsPMvcp4cCmCvioaenJwbw== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Signed-off-by: Robert Foley --- util/qht.c | 1 + 1 file changed, 1 insertion(+) 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: 11565919 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8FF1739 for ; Fri, 22 May 2020 16:18:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7F95520663 for ; Fri, 22 May 2020 16:18:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="oYEvkOCJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F95520663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:56234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcANZ-0008Et-Na for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:18:37 -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-Google-Smtp-Source: ABdhPJzPg+7Mb52mPLK33MwR4NS+FW4JwBoR7aokwnTMGbFqzPdJWjrMYnFZxOqf8QE8Wk4JH7DjHg== 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+patchwork-qemu-devel=patchwork.kernel.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(-) 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: 11565927 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D36BA739 for ; Fri, 22 May 2020 16:19:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AAD2220663 for ; Fri, 22 May 2020 16:19:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hDFxAIro" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AAD2220663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAOn-0003Ci-Sx for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:19:53 -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-Google-Smtp-Source: ABdhPJykOQgaC2KLYX1YDI/KN2+rrp9UKAfxluW7PefbeLWNJjsIEOOcwORr9g/x9gWSGvfSfS/KoA== 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+patchwork-qemu-devel=patchwork.kernel.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(+) 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: 11565917 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 72F591392 for ; Fri, 22 May 2020 16:18:25 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4A3F120663 for ; Fri, 22 May 2020 16:18:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dF1P08+W" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A3F120663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:55748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcANM-00082c-HC for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:18:24 -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-Google-Smtp-Source: ABdhPJyuDaqzES88dCe0KcGqW6YrYPhqTjIrG/1drcJkt+KZ9APKc0/DeN7o4bHyMG0FJCK3V+5aSg== 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+patchwork-qemu-devel=patchwork.kernel.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(-) 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: 11565925 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC8CE1392 for ; Fri, 22 May 2020 16:19:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9381B20663 for ; Fri, 22 May 2020 16:19:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SNnTHiJr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9381B20663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAOk-00034J-Pg for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:19:50 -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-Google-Smtp-Source: ABdhPJz4JdkAA7HN8RgeAICBf9nxoyHtWS7Qh00d5hv4GKS6NVTN9upFWXH6Me3LpchM4st2HUnY0Q== 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?Philippe_?= =?utf-8?q?Mathieu-Daud=C3=A9?= , cota@braap.org, peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.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 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: 11565923 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C1B351392 for ; Fri, 22 May 2020 16:19:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 989FC20663 for ; Fri, 22 May 2020 16:19:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="G9CmtFg1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 989FC20663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:35936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAOj-00030k-NT for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:19:49 -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-Google-Smtp-Source: ABdhPJyINZ8xwkbbrhL0MVgp6irRJJYrglItnVBoOEKIQpou1F76x3dXbN7h8F7Ij9yj/V4DMESaCw== 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+patchwork-qemu-devel=patchwork.kernel.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 Reviewed-by: Emilio G. Cota --- include/qemu/tsan.h | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 include/qemu/tsan.h 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: 11565913 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4C3C1392 for ; Fri, 22 May 2020 16:17:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7B42A20663 for ; Fri, 22 May 2020 16:17:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Cm0akHXB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B42A20663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:53304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAMp-00073H-Lo for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:17:51 -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-Google-Smtp-Source: ABdhPJw6NNyAAxg8yXcqELcQCSJELqsEUQ6IY7mcABXzUhCqBZwx3eHJ+AI+M6NK9u1nOnOvR7LWbg== 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+patchwork-qemu-devel=patchwork.kernel.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 Reviewed-by: Emilio G. Cota --- 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(-) 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: 11565937 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 363D5739 for ; Fri, 22 May 2020 16:21:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D91C2070A for ; Fri, 22 May 2020 16:21:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="KkIZOsoP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D91C2070A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAQf-00071n-6e for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:21:49 -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-Google-Smtp-Source: ABdhPJxSWGGajirmm6Ds/VeFTnZ+AJ33Vhht1mdP5l9A1jIZ7juEikAtmhzxfAm1ZzAeeVMO+4cxcg== 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+patchwork-qemu-devel=patchwork.kernel.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 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: 11565931 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 91792159A for ; Fri, 22 May 2020 16:21:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 68D3F2072C for ; Fri, 22 May 2020 16:21:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="N2W5klQA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68D3F2072C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAQZ-0006pX-Jr for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:21:43 -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-Google-Smtp-Source: ABdhPJxejFJfyZ68h+SYgdNQ8DHz0GvmK3i8D7h/UlhfwZlpEI8w8jNZBT6iAiBfAcXrjPH8h3NEbg== 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+patchwork-qemu-devel=patchwork.kernel.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(-) 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: 11565921 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 66B70739 for ; Fri, 22 May 2020 16:19:30 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3D9D620663 for ; Fri, 22 May 2020 16:19:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="WHSPHQjy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D9D620663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAOP-00026e-CD for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:19:29 -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-Google-Smtp-Source: ABdhPJxS6O5pF1E7y2oFN4vEouVrNICucVS+qcpof41rMFRCukUh1HQqPbDyCANC34mHd/M2XSUBlg== 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+patchwork-qemu-devel=patchwork.kernel.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(-) 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: 11565949 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61CB2739 for ; Fri, 22 May 2020 16:23:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 392312070A for ; Fri, 22 May 2020 16:23:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="PIBtX2Kg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 392312070A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:53330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcASM-0002gS-9Q for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:23:34 -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-Google-Smtp-Source: ABdhPJzB2duxHEauhLrjN8q6cAKEcesq2o6omT60tyUUDs27i+8CJApt/nk2nhaJ0jdlVmIcpd1AqQ== 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+patchwork-qemu-devel=patchwork.kernel.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(+) 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: 11565943 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ADE39739 for ; Fri, 22 May 2020 16:22:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 83DCE2070A for ; Fri, 22 May 2020 16:22:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="y4htgXC0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 83DCE2070A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcARL-0008OW-KH for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:22:31 -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-Google-Smtp-Source: ABdhPJzJNjSu3apx5VFMvsRSRbtiGOv0+yhJ38PtdCJlBmLFO9eYQhVMNPtyCBnn8NIKHqg6ZPYwFg== 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+patchwork-qemu-devel=patchwork.kernel.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(-) 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: 11565955 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A9636739 for ; Fri, 22 May 2020 16:25:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 804A120723 for ; Fri, 22 May 2020 16:25:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="GNUp0U1n" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 804A120723 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAU1-0006it-M9 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:25:17 -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-Google-Smtp-Source: ABdhPJys21ul8aDdEdjRji90tJOwobuTXZmcDYOj8bqY+tDMDzG35LNfgEPTjyTieiqNDSUhOZ27OQ== 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+patchwork-qemu-devel=patchwork.kernel.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 Reviewed-by: Emilio G. Cota --- util/qemu-thread-posix.c | 2 ++ 1 file changed, 2 insertions(+) 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: 11565959 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06912739 for ; Fri, 22 May 2020 16:26:41 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 90BB620727 for ; Fri, 22 May 2020 16:26:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="CT+0Y3Lb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 90BB620727 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:39162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAVL-000156-IS for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:26:39 -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-Google-Smtp-Source: ABdhPJyVSSNMgunpT7lv7Ih6PqROoXJwH72krGad2+09dtgPx+0B1zE5GpW7yZXm/kemZ7Uen5utWA== 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+patchwork-qemu-devel=patchwork.kernel.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(-) 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: 11565957 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24602739 for ; Fri, 22 May 2020 16:25:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F03B920723 for ; Fri, 22 May 2020 16:25:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="GaOU4WrC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F03B920723 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAU4-0006pt-3i for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 May 2020 12:25:20 -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-Google-Smtp-Source: ABdhPJziwesNSRdfYiiN1b2ilegPb02rnpiQXZ9O8pkX7n+TdcHFEYvQlneSlVPW4GNQzsYw8EoG3Q== 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+patchwork-qemu-devel=patchwork.kernel.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 Reviewed-by: Emilio G. Cota --- docs/devel/testing.rst | 72 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) 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 ==========