From patchwork Tue Jun 9 20:07:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11596545 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 8A469138C for ; Tue, 9 Jun 2020 20:10: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 5F4DD2072F for ; Tue, 9 Jun 2020 20:10:41 +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="SvN7s+Mj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F4DD2072F 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]:60218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jika0-0000Wf-GN for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jun 2020 16:10:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jikZ1-0007NR-UN for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:39 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:33148) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jikZ0-0005Yy-AX for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:39 -0400 Received: by mail-pl1-x643.google.com with SMTP id t7so25209plr.0 for ; Tue, 09 Jun 2020 13:09: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 :mime-version:content-transfer-encoding; bh=PEbujPtBaJg3B2IT0hPnYXWImSAP6JwyxZ2Cqb86MEY=; b=SvN7s+MjJJ7ADNt5weFq9NU9aiPFWeG9ft6r1PtTQHd+3Gl7ccE4YXSi6/TY6Gxcac D20wS7o7f1naPiFINjoWEKkNr4pVdtSQa0S/aYdAGEVSSl9rpTeE1WFFUnHAVq2WrZBA PFgxacabSIBZ7svHkx90sm50Kia5ly7lZiWHk5d5sXp5ZuP/0FZBdtFlGPqRXLHlwtg9 YP6STyvxaK1o2xW3JeBTkMD+genH0b9J5KssTSRw+TXuJUWuWXYeBiNVKIgUtc9GR0Nh s/0r0LlMZ8y3LVrOLt8Y/0HC7M1TT6DkYv+99MOU9xMp2+ykz47o0OKzLClwjOWwGRje ekNA== 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=PEbujPtBaJg3B2IT0hPnYXWImSAP6JwyxZ2Cqb86MEY=; b=ouAi0af6BUydq+FGArZCkyP2GK1Pv0V9Z8egfKN/jP0nl+gSHBCYHbz4c7C48KcY4D 9PbwFcAgG05trcVm9rgpX+tGffxerAtAepHS6YMFTBWOtoT3LMg/4y7+4vgjZZ7vvPfE YsWlvAJvfB4+TbdT1Sfx+lcqJChCt9CHKLLRF+npOjmc7xBQLArvYHTyK7CjcWNRQF3z Nr5j5ytqiMyCyqbEjMDM65YuhhDQamKMQEEE9vnvCZ5syzuKF0EzIEyx3rHFEfO2Xi/I L+KuQqgvxIrirp8YDzPmxYt5ppnhU4ictRtuphFo2/84e88SoJSZUy+6sJBPyzfM7D3Z pkXQ== X-Gm-Message-State: AOAM532o3oE9D+Uwqxl4ff9Ixf4ReALGfJ2uestRRlnzu2I/Abvc5g7p t++v28RsF3zafOikxRWysS+UfC1h4hv1Wg== X-Google-Smtp-Source: ABdhPJxxJgmIuAK7Dsrr+C1xb6yzvhfArxJ3Rkx7JmEmqecu1FybFjMEzmK8Zqq482a4R9iRL9os5w== X-Received: by 2002:a17:90a:3608:: with SMTP id s8mr6294130pjb.167.1591733376257; Tue, 09 Jun 2020 13:09:36 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:1d09:cef2:3b1f:abce]) by smtp.gmail.com with ESMTPSA id n19sm10523374pfu.194.2020.06.09.13.09.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 13:09:35 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 01/13] configure: add --enable-tsan flag + fiber annotations for coroutine-ucontext Date: Tue, 9 Jun 2020 16:07:26 -0400 Message-Id: <20200609200738.445-2-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609200738.445-1-robert.foley@linaro.org> References: <20200609200738.445-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: Kevin Wolf , robert.foley@linaro.org, alex.bennee@linaro.org, cota@braap.org, Stefan Hajnoczi , Lingfeng Yang , peter.puhov@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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: configure changes, coroutine fix + minor modifications] Reviewed-by: Alex Bennée --- configure | 47 +++++++++++++++++++++++++++- util/coroutine-ucontext.c | 66 +++++++++++++++++++++++++++++++++------ 2 files changed, 103 insertions(+), 10 deletions(-) diff --git a/configure b/configure index 597e909b53..da46f9556e 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" @@ -1754,6 +1759,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 @@ -6196,6 +6202,30 @@ 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. +if test "$tsan" = "yes" && test "$sanitizers" = "yes"; then + error_exit "TSAN is not supported with other sanitiziers." +fi +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 @@ -6297,6 +6327,16 @@ 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 + error_exit "Cannot enable TSAN due to missing fiber annotation interface." + fi +elif test "$tsan" = "yes" ; then + error_exit "Cannot enable TSAN due to missing sanitize thread interface." +fi if test "$have_ubsan" = "yes"; then QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS" QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS" @@ -6332,7 +6372,8 @@ if test "$werror" = "yes"; then QEMU_CFLAGS="-Werror $QEMU_CFLAGS" fi -if test "$solaris" = "no" ; then +# Exclude --warn-common with TSan to suppress warnings from the TSan libraries. +if test "$solaris" = "no" && test "$tsan" = "no"; then if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS" fi @@ -7386,6 +7427,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..613f4c118e 100644 --- a/util/coroutine-ucontext.c +++ b/util/coroutine-ucontext.c @@ -37,12 +37,19 @@ #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 @@ -65,7 +72,18 @@ 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(); +#endif +} + +static inline __attribute__((always_inline)) +void finish_switch_fiber(void *fake_stack_save) { #ifdef CONFIG_ASAN const void *bottom_old; @@ -78,13 +96,30 @@ 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); + __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); + + *fake_stack_save = curr_fiber; + __tsan_switch_to_fiber(new_fiber, 0); /* 0=synchronize */ #endif } @@ -104,8 +139,12 @@ 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); + start_switch_fiber( + COROUTINE_YIELD, + &fake_stack_save, + leader.stack, + leader.stack_size, + self->tsan_caller_fiber); siglongjmp(*(sigjmp_buf *)co->entry_arg, 1); } @@ -154,12 +193,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); } @@ -216,8 +259,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 +274,11 @@ 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(); + } +#endif return current; } From patchwork Tue Jun 9 20:07:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11596551 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 22468912 for ; Tue, 9 Jun 2020 20:12:42 +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 EA2A82072F for ; Tue, 9 Jun 2020 20:12:41 +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="wCQnDTZK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA2A82072F 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]:39014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikbx-0003WF-2i for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jun 2020 16:12:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jikZ3-0007Os-67 for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:41 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:36666) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jikZ2-0005ZH-7E for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:40 -0400 Received: by mail-pj1-x1043.google.com with SMTP id q24so1885049pjd.1 for ; Tue, 09 Jun 2020 13:09: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 :mime-version:content-transfer-encoding; bh=pD3JWxT76a4NROnBN3hpZMTAPaW7sxqBc70GvHSGYPw=; b=wCQnDTZKeoZgWMDzK6ZzWdAIyphAjAWuDsiT1OCXPbI2zLvafiPEIs3hsKVdrm0LQv 4c7ABOz46g0c/CtX9kuWYATO/3bTb9ToHouMW3cjNrgLYRsbubnYCDEETXG5EH6ISEtc 0dPqkXzdw8t2NhpxWntekoroRYJalibvDEKKraXQKwq1PGsY77Ky8dtZ0A5d7iuedN/Z FF2OZu/YKr8jyl6yH2n8TFMrOaRmCh/6p3464DttMRgKevX8w18Kn0HQQrIO1JVwIdrh 4gGBEz4xB5Jv0/A7CNs6NPSD3DhzLb+wLdMSQiLWAMsVlsLCGEY3DzHGDKfJQK8K5P9F mJKg== 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=pD3JWxT76a4NROnBN3hpZMTAPaW7sxqBc70GvHSGYPw=; b=qO8o+YNZqE6DA3pX2s9WB8i885AZTkmAmxuH6LRRL4PhSvPKfpa2x62QXIPBopVxOL JHEvhi5BhULb0elgZiWVq99jPHEdnAtIEEhcXGvJbXbWwvc6SvoLVM2RAOOoktZ79kiS u7LKU2x1RfAtK7hYnq5v/S/8nmUAbv/Yr0C5kULTAOnv8cwzdVA7bRDZP6DjeoiiPWFZ pRVaBm3cCoCsJLBl4gIBiwHMfUjBSlRNqdhECngK3oPpF7cyX25WgOJj4E7Xhmj0U6k+ BM+MSy53MWuYCTVyAI81zLdpbFGqcq728NaUTeIZkFjmfiDwbbdEIEf6haRwcOtCP3Eo JxiA== X-Gm-Message-State: AOAM532QSaRyNMTuara+MUnPn2yNtPq8p4UaW84QVOBEydm9WCgaaE6s MJNwIj12p9Cp4uEX/Vj9ZZKAqEFHKVrUMA== X-Google-Smtp-Source: ABdhPJwSE+qwkssRPlMyXQ7j15XVFeebiljc43KOVqesCJuEldCz7vB+6h9yrLpbT6bUj29O5qFldA== X-Received: by 2002:a17:90a:240c:: with SMTP id h12mr6670763pje.42.1591733378558; Tue, 09 Jun 2020 13:09:38 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:1d09:cef2:3b1f:abce]) by smtp.gmail.com with ESMTPSA id n19sm10523374pfu.194.2020.06.09.13.09.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 13:09:37 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 02/13] cpu: convert queued work to a QSIMPLEQ Date: Tue, 9 Jun 2020 16:07:27 -0400 Message-Id: <20200609200738.445-3-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609200738.445-1-robert.foley@linaro.org> References: <20200609200738.445-1-robert.foley@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=robert.foley@linaro.org; helo=mail-pj1-x1043.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, Eduardo Habkost , cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" We convert queued work to a QSIMPLEQ, 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 Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley --- cpus-common.c | 25 ++++++++----------------- cpus.c | 14 ++++++++++++-- hw/core/cpu.c | 1 + include/hw/core/cpu.h | 6 +++--- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/cpus-common.c b/cpus-common.c index 70a9d12981..8f5512b3d7 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 f31ec48ee6..80d51c24dd 100644 --- a/hw/core/cpu.c +++ b/hw/core/cpu.c @@ -370,6 +370,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 497600c49e..b3f4b79318 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 Tue Jun 9 20:07:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11596547 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 75781912 for ; Tue, 9 Jun 2020 20:10:48 +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 4A7652072F for ; Tue, 9 Jun 2020 20:10:48 +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="U03bWEWI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A7652072F 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]:60718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jika7-0000lF-HP for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jun 2020 16:10:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jikZ4-0007RC-K7 for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:42 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:41994) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jikZ3-0005Zd-Rb for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:42 -0400 Received: by mail-pl1-x643.google.com with SMTP id x11so7667plv.9 for ; Tue, 09 Jun 2020 13:09:41 -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=hi7LUnC/2Vxc6CG4AyW71h/9KhgELUl20yMZDhooBMo=; b=U03bWEWIv5lmCxfVjI5TYxG7RiozcKxCQ+evlMNwHzvIXrXt1/I7T6fSDdvPQR7pVP hw9kBk29qkHugmcZCb2wefK1ecjO6DaQCyVwoeu/nH+237tldj2WIkjAtT6R7QVSAdzU R1bCWRRXbzX9F+7uiweQMhNFjs2dNLwzyurj5xF7FErQdZhqezs1wc+sY8mfoTFf/keG 9jCu7LrOBjx9mMkcH4P5Qh5GWfwOWzoETs6kIpqrhsk8arLLQZvQw00cPG/u20End6NM qJHridjevr2gCVkVh+5g1LOEeJorocZlLR2LdzMDsIUOSkBeY9jQ7iDifyJh6y/+ZAy8 Qojw== 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=hi7LUnC/2Vxc6CG4AyW71h/9KhgELUl20yMZDhooBMo=; b=S2QTGC5y5YXNmKjFKj+tQHO6iyn05azFckMbvAFhkQjVmCWCmjJ25CKGXUhCUo9vlR F1h9fVPhb7AnTo3rKFlt65NKBLqgqhii4GGHTS9A8oJavQ6pCl6qANxqF8+UOFIKxN2O Jyj+m+7u797CJRVSyk0cnUpofd5rGlL/XkRIWJnCxGyHhpfBM/5EOKDgaJLgM5lqk0Zu ujDQ3yc9DfmwnzsVPxQDn0zG0zD7iNiVWxIdFkPZgn6ox0+zBuhWqeIelrS1l6HFuht0 3MT8tn9SyqLFOoxadBdVTTwHJh+3sH/Q617GA0HYKiARbRRwnvzrayCiAtsWD2/5aY6t ULwA== X-Gm-Message-State: AOAM530oq8ikNu477zwlnfBmyaqLe08eb1W0OGYyIpbo9Xfv/r/jWC2I 4bv8TaHDQZT1yT+/hqypXnXTjVkcWONxMA== X-Google-Smtp-Source: ABdhPJwypIq3skTHG6eKDpGKZhbgZ+3obRqjtUqU0TqiC9pvYMIKw0xGDMscL+kqSdh6xKIqrJaW4Q== X-Received: by 2002:a17:902:7247:: with SMTP id c7mr63673pll.103.1591733380337; Tue, 09 Jun 2020 13:09:40 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:1d09:cef2:3b1f:abce]) by smtp.gmail.com with ESMTPSA id n19sm10523374pfu.194.2020.06.09.13.09.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 13:09:39 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 03/13] thread: add qemu_spin_destroy Date: Tue, 9 Jun 2020 16:07:28 -0400 Message-Id: <20200609200738.445-4-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609200738.445-1-robert.foley@linaro.org> References: <20200609200738.445-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: 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 Reviewed-by: Alex Bennée --- 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 Tue Jun 9 20:07:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11596557 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 A3F31138C for ; Tue, 9 Jun 2020 20:14:24 +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 78EF82072F for ; Tue, 9 Jun 2020 20:14: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="FOMrvHJr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 78EF82072F 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]:44458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikda-0005kf-Oq for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jun 2020 16:14:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jikZ7-0007Vb-5J for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:45 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:37886) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jikZ6-0005aI-4t for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:44 -0400 Received: by mail-pl1-x641.google.com with SMTP id y18so17417plr.4 for ; Tue, 09 Jun 2020 13:09:43 -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=mMbQhssouUvEnYpKM8BJ1rWl4q0BOBlTa248+fa3MEA=; b=FOMrvHJrOFSJ+/V6jlfepp24K34u2dT1Y3Ao4CiNA7GTTNvDUWqQ9tsJ3FG+TV5De8 Z/Xlqaa6+3XV237J5yLXl5w7NpAMBzlL5bMrvqWeHeuZoQvjDukKmFQGoUFWF6z2a/ao VHMKOhypwPlZSOJKd3oMKdMBxJApD+Jk2eZj0J+e8V22RG4zbzZSmtadWcZqAhGe/wCv M9tL1NQ810u6sH5bW0uPrAmd2tJrMdyGCFfUSAsKG9Y9hq6jUM3Aa90dvewsLNTFS5EJ tYVquQRJoxJu8cVpHV2J0oUv5/yD3yRUiMTSmtUm4UvxX9LTzsoX3wAhGSiS1tYG+d7q OhmQ== 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=mMbQhssouUvEnYpKM8BJ1rWl4q0BOBlTa248+fa3MEA=; b=J1QniRRkAApzrfaxutYEw9Tjk8pViZ44J0dntoWgmgxJueM9q+qYsfjpkIhJXe3QJN J560cie5N2QAVsgSSMGno7Urm+TNalYe7sTiWkHXw9w6iKwDFFS6F5PiXwfVD77MHSaz st0HntH8htlQ/49P2du3ghWNyauv+lpfGkYprkQHhYjOGTOAnLCW2jQVTCN/VpZqfLt6 4karAjYNkO3X3c07iubhEd298JZ5sq6zF4npLReBRnZAcRtlqvr4uObk9/vL/+LqLSJq SpV8noojaIUpOZxpAUobAaOVa/WdHxDlg0u/hXhLL3HEmr5uEJE9Ca5rY63pMxiwGiMq oEAw== X-Gm-Message-State: AOAM532IPkFuoak0YW4SQaGJEH06uSIEtoSw/AXUt8mRhHoVdAEwWNMK lF0xwnWv7iDkARPSt3Nuz3N+6A41YYIWmw== X-Google-Smtp-Source: ABdhPJzxlvdrBCnUEM7RPIO3vWT52v7eeiJzh6mCaIf7QVxvfIcuwLWBeWH2CVUQ9Bp1f1X4uyV3zg== X-Received: by 2002:a17:90a:df82:: with SMTP id p2mr6707823pjv.217.1591733382355; Tue, 09 Jun 2020 13:09:42 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:1d09:cef2:3b1f:abce]) by smtp.gmail.com with ESMTPSA id n19sm10523374pfu.194.2020.06.09.13.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 13:09:41 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 04/13] cputlb: destroy CPUTLB with tlb_destroy Date: Tue, 9 Jun 2020 16:07:29 -0400 Message-Id: <20200609200738.445-5-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609200738.445-1-robert.foley@linaro.org> References: <20200609200738.445-1-robert.foley@linaro.org> MIME-Version: 1.0 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: robert.foley@linaro.org, cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson 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 Reviewed-by: Alex Bennée --- 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 be4be2df3a..79211fb23d 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 Tue Jun 9 20:07:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11596561 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 89CEB912 for ; Tue, 9 Jun 2020 20:16:04 +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 5D98F20734 for ; Tue, 9 Jun 2020 20:16:04 +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="taIbyG7t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D98F20734 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]:48880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikfD-0007f8-Kk for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jun 2020 16:16:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jikZ8-0007Yx-O7 for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:46 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:42761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jikZ7-0005aj-Vu for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:46 -0400 Received: by mail-pf1-x441.google.com with SMTP id b5so40861pfp.9 for ; Tue, 09 Jun 2020 13:09:45 -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=hMythbUcqIycDnX7vBXLsyLkA4NDGTmBWD2zTKmRWuE=; b=taIbyG7tjBJJgV8zx4GDb38LGhzVx0dwki4yaynSdDoTWhApgA4g6cMYNXYJg1ykTe 775xIXWqipvEbxa9kEevlG8kxg2oc8h7CLIfTYjHDLiSUcQYGLRDGpnJeh4E0CxbPioI RDNk0nnPvW43ZpaG3QBv6iiwe+5xExrdaMdgtbcGlP5kCATRH5jZKAf0RbsSVipcVeN4 jVJ47wDwIKrlZyxgtbO1fVjXonv57RYro15U/XrbP0BqLyEz+wtmB6UJve2+/42Z9vxr 8AT2MtQcmAQkPdMjdZr7gWNQILjSp8R73QtlCdl5U4+44nWckcE/9Gt9DdX7Eq9s9hzR Y1SA== 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=hMythbUcqIycDnX7vBXLsyLkA4NDGTmBWD2zTKmRWuE=; b=qCtGABhCil0Bcqz4JD5YQqoKwb0Qz4WzGe9Uo87+gtlowqzhEM5yfdlsiOVdX0uFgi ooJsJl6msHUhZsoLdwPjKjkdUTSe9nVtJAR39E6v1cBVaoDQPe6wg6BxzuGlS8nC3aep 8wF5MXpdkRnDtZXNA+tsbs4GsX3Mh24nEnfy8+qdY/CyB5hhC6gmgi2+rOJlRbdSEXHE pognDWNgv7DhwDy9wtIuuxKHCmC7jADOvUH6oR/zhPKuUzAYAytOZrQHZg9RetXcbqTO j+QTAVHcMsm+m8sh4j+K9xcjj603doJvK20FBSKqIMpHdYt7vnRKc2CNeJTSQrFTRw2+ bDsQ== X-Gm-Message-State: AOAM5326Kv+DFODHnhXXza/MuwRiRZzQO+Eo8DBp2WCLErRoOn6g8MSM 3J5athmohbMe8BECJGhYRcSrbQVE1Ynq4w== X-Google-Smtp-Source: ABdhPJxLp+5rb3an/abxTUz6Y+/u7tiKfB67V7VSwEzXcAPVzOdBmHfWFy4dmS8fmVYFovTWpRBEgw== X-Received: by 2002:a63:2f43:: with SMTP id v64mr25800165pgv.232.1591733384164; Tue, 09 Jun 2020 13:09:44 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:1d09:cef2:3b1f:abce]) by smtp.gmail.com with ESMTPSA id n19sm10523374pfu.194.2020.06.09.13.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 13:09:43 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 05/13] qht: call qemu_spin_destroy for head buckets Date: Tue, 9 Jun 2020 16:07:30 -0400 Message-Id: <20200609200738.445-6-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609200738.445-1-robert.foley@linaro.org> References: <20200609200738.445-1-robert.foley@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::441; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x441.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 Reviewed-by: Alex Bennée --- 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 Tue Jun 9 20:07:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11596563 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 32A58912 for ; Tue, 9 Jun 2020 20:17: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 07BB220734 for ; Tue, 9 Jun 2020 20:17: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="qe6nEER4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 07BB220734 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]:53046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikgg-0000zg-Ar for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jun 2020 16:17:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jikZC-0007dg-5B for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:50 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:36904) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jikZB-0005at-6y for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:49 -0400 Received: by mail-pf1-x443.google.com with SMTP id j1so52125pfe.4 for ; Tue, 09 Jun 2020 13:09:47 -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=qwuZW03UALyLreC41dDKLL3VuvvJz8e2voNJjWwlkPc=; b=qe6nEER44UMHZJMd1lWxtNsxrVCLglEqB+UsmAhsfFJgiznbPIbfk6cDYk1MugwxM7 OwhZ60uoKRWB2mTzbFmNOpm0mi3PrRs0gj3B8JGmOKiU9BCs3QTXy9s9JG+AR7E5ZydF 03jsXgTAYHxE7fYLCBsJweUdFmjFOk7icdd9oEAzM3W+wqJPEkBCZyb18fgiiswJsnmJ i76oWZIdNg+IMDJJwLXEldE7+plVvwHx7PSSpkJ5U/nWtqdw1BLMCoFocYlPTTD52NA7 aYAIPpwcxUAPeEKxjYXlIyZq4Wv/BBRkuvL1dWtdDKJKsKzqtuxvzOqTDpnFOcSlGOXC QYbg== 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=qwuZW03UALyLreC41dDKLL3VuvvJz8e2voNJjWwlkPc=; b=gCVgeE5enpSy10Xn9p0CgN2PeMeMpoES/dzwSeCRnX4P8f2QFvd+A3KqLA1YaKzF6M iPMWQ/ab6kOcmMOOQMHnHt71yS5OClddK3fcvgXEY6Cl9OFV5KNLOILq2fdsXhBfT24s YTCa5tyCN9h2snh5AHwNXvqIIwIDKmNK7sAjzI2k3pJS4rsMUeDri1pKLmgwGaCzmI94 NGjEq6FyJLtmsFEIZrcxyqniL0UlF06bd5JedySrsV+yrBgs2l6DuW86wS+aOFzMSxRJ dhH5sc7yCSC2TeQisBi9YTwo246SkhhvKtprFT3BhBvIAixVkUdG6xU1kE1WWVpwnLZc bWxg== X-Gm-Message-State: AOAM5324bcr56DKqVeqD5mVtKw6i2ZGpWlLTA9g8ZrRFssXPIzy9/asi 1tQIQ8b+bx1hEghE9mmbtu4s/5RY8I6Qig== X-Google-Smtp-Source: ABdhPJxKnlvrEpi/+d3CZifxs278bJiZkebAHmX7xunAY1mYrXD5p54CsfBffh+BbiqWj5HhykG/0g== X-Received: by 2002:a63:1a11:: with SMTP id a17mr25991301pga.227.1591733386297; Tue, 09 Jun 2020 13:09:46 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:1d09:cef2:3b1f:abce]) by smtp.gmail.com with ESMTPSA id n19sm10523374pfu.194.2020.06.09.13.09.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 13:09:45 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 06/13] tcg: call qemu_spin_destroy for tb->jmp_lock Date: Tue, 9 Jun 2020 16:07:31 -0400 Message-Id: <20200609200738.445-7-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609200738.445-1-robert.foley@linaro.org> References: <20200609200738.445-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x443.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, cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson 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 + remove tb_destroy_func] --- accel/tcg/translate-all.c | 8 ++++++++ include/tcg/tcg.h | 1 + tcg/tcg.c | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 42ce1dfcff..c937210e21 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; } +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; } @@ -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 380014ed80..e63450a893 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -819,6 +819,7 @@ void tcg_pool_reset(TCGContext *s); TranslationBlock *tcg_tb_alloc(TCGContext *s); void tcg_region_init(void); +void tb_destroy(TranslationBlock *tb); void tcg_region_reset_all(void); size_t tcg_code_size(void); diff --git a/tcg/tcg.c b/tcg/tcg.c index 1aa6cb47f2..1362bc6101 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -502,6 +502,14 @@ size_t tcg_nb_tbs(void) return nb_tbs; } +static gboolean tcg_region_tree_traverse(gpointer k, gpointer v, gpointer data) +{ + TranslationBlock *tb = v; + + tb_destroy(tb); + return FALSE; +} + static void tcg_region_tree_reset_all(void) { size_t i; @@ -510,6 +518,7 @@ 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; + g_tree_foreach(rt->tree, tcg_region_tree_traverse, NULL); /* Increment the refcount first so that destroy acts as a reset */ g_tree_ref(rt->tree); g_tree_destroy(rt->tree); From patchwork Tue Jun 9 20:07:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11596553 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 0817D912 for ; Tue, 9 Jun 2020 20:12:43 +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 D069A2072F for ; Tue, 9 Jun 2020 20:12:42 +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="qNr97HSB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D069A2072F 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]:39116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikby-0003Ym-2Y for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jun 2020 16:12:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jikZD-0007fU-5Z for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:51 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:35061) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jikZC-0005b3-2s for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:50 -0400 Received: by mail-pf1-x443.google.com with SMTP id h185so56290pfg.2 for ; Tue, 09 Jun 2020 13:09:49 -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=1NsThI0eMK49RH+R+oR0Ud3TTjxqLqaksL0ZDGz/oqg=; b=qNr97HSBUrOLimU07hmS+GwNc/esKVcAbmxKLUEx1422R0EYpQRn2sv06RpdmFuYYT m5six1s/d8vspHwVB5DnLLNS5GQv1bSwYsazcdAivIzg2cI702ZxcjrpjbSBGfFAe+yb 3yQq62A7Bm5wEHI3oeeTjKMO1hyVjm/8bub7qon4xNBMIf2/MUhfWtlsT/6Pmfdte6/n 0ZdMEySxVb2hgOfB++yb78dY7zW36TNeaKylC9nKcplLg5D2n9ym7VBG29ttRm0P+MRA gyJ6sMVhn441+TLYzTGraOGwwKFG36Ikaf9EKGHI1DCQNVKZ0giAGKmAsPU6zFDlwYg7 QrPQ== 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=1NsThI0eMK49RH+R+oR0Ud3TTjxqLqaksL0ZDGz/oqg=; b=t7byID3GFmtKfoJ1K8gHiAz+wodBrt4I33PZCAbZpLpV5lghafi9RL/wDkEllL+HdV SlVB6LTuTJVDEaDMnFcrnvF7JUKvCzwhhPi7ZblijRb7Jhs1JMxeiRFseUD870c2mbPF 1rAP2XZ3N4y5Xfk4aD7Xj73ekzjs+XOM9I1Elk57wfdcnYhG0zK+k3ssbtjx3+9J9qKt Wcubq5ME5qPiTt7ng4iTgVM28zlFyFgj1Y1KVid1QnyYcGBkn9c7JjBLfruOe4HJz58e X/lRgS/luPR/lhIGxQwyKl+8366yNlESm8vOHM1EqaaSM7zWd7WyQsZ4sizS019CWZti bcPg== X-Gm-Message-State: AOAM533RoOTwbRfa+oiZ171+NDOmw5EP7EzrJhprz8bHwCYRZTM8Ou1z 9JSYDEGlH11d6iHQNQNkWupXEgISUPwQiw== X-Google-Smtp-Source: ABdhPJxHHzSfYmC1pKiR0IWFZdofK9e9baudvG4kTQOonBCRqOHqxy0qDY2GY164Tvt13uY9qSumKg== X-Received: by 2002:a65:46cc:: with SMTP id n12mr26290909pgr.80.1591733388359; Tue, 09 Jun 2020 13:09:48 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:1d09:cef2:3b1f:abce]) by smtp.gmail.com with ESMTPSA id n19sm10523374pfu.194.2020.06.09.13.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 13:09:47 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 07/13] translate-all: call qemu_spin_destroy for PageDesc Date: Tue, 9 Jun 2020 16:07:32 -0400 Message-Id: <20200609200738.445-8-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609200738.445-1-robert.foley@linaro.org> References: <20200609200738.445-1-robert.foley@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x443.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, cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson 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 Reviewed-by: Alex Bennée --- 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 c937210e21..c3d37058a1 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 Tue Jun 9 20:07:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11596549 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 B03C9912 for ; Tue, 9 Jun 2020 20:10:58 +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 8522B20734 for ; Tue, 9 Jun 2020 20:10:58 +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="DcTY0w/8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8522B20734 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]:33350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikaH-00016V-Lj for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jun 2020 16:10:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jikZF-0007i6-IR for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:53 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:42048) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jikZE-0005bK-0h for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:53 -0400 Received: by mail-pg1-x544.google.com with SMTP id e9so10754541pgo.9 for ; Tue, 09 Jun 2020 13:09:51 -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=AYdOaJYxtk+d/I+Jwq+9vEcr8Iz8aXatF1CrO9YlEDI=; b=DcTY0w/8OD14Sm++yyBa4igV00n4r6Ty47GW1i8jTGsc6pxoB73b5ogmJIqP62WPlX jOswX7x96FJQ3RT9v4Uotev16p7W7o7x5ChM8w3NRx6bsb/clhNq14gu6gvPfynVfrk7 c8fExNHJ7jG2UCOo1N8nnd4DdXvGUSxjd2BdJwO/bCxCtE/aLNnOvFJR+YIfSOWHNpRZ EqLfiV484sWiFhGk255xasHZfsRdnY9WLuIsDhjClZOUaTZR6OVPbHxzHYx/8LAMmm4o 9rOCnpwx0fIW7ShgaG7tJHgj5QGszvtrSHynx2w9gypcDdlrG9ogVc5YJNFVpKaGCqOV HYVg== 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=AYdOaJYxtk+d/I+Jwq+9vEcr8Iz8aXatF1CrO9YlEDI=; b=N2o4byZrb+2L7IStiUnBFNGc/Tpk13BNSrM5lpG5etdXCfgltksCvLBtn9zERm+o9I IVI9nUoIrMBzakmgGeF2amcTjNZMj/8hZeIj2lfUcdYxuR6oMNcX/HvxNHFj3IY+Gdva dhlxM6D3A/mIA9YAciljw6Dhhurl2NAEa0dYctsVpyi/AMAfic2OZgNYTQ4ZulCaqQjl h4ZbXdR9zI3ExkBcVy2UoATCzmNWgwzSkhvHL5SBSHwxqxJpcdcBAlLeHtmDYlDjhC9I GfqXdWoIJGTLruD3lAXdoII7GCFwVhH6qGY4EJVAtajCtPNbPok7e3IB3LHhr32R7W/9 pmug== X-Gm-Message-State: AOAM531Y37Nt9KGvteanA9FdPOhpsR4Bb5hj5jBpXLpajMlYjC6zTYiw aTWntLHPGRUq342c2hxkmRsfDfpFN5rZwQ== X-Google-Smtp-Source: ABdhPJxYN8fCgGZTuZeG9zOJd6vnrZel5fYLloFdSflWGVX8GEPe3bFjl5mYHqz3lPgq8W7cU/sQxQ== X-Received: by 2002:a63:9258:: with SMTP id s24mr25931521pgn.362.1591733390238; Tue, 09 Jun 2020 13:09:50 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:1d09:cef2:3b1f:abce]) by smtp.gmail.com with ESMTPSA id n19sm10523374pfu.194.2020.06.09.13.09.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 13:09:49 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 08/13] thread: add tsan annotations to QemuSpin Date: Tue, 9 Jun 2020 16:07:33 -0400 Message-Id: <20200609200738.445-9-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609200738.445-1-robert.foley@linaro.org> References: <20200609200738.445-1-robert.foley@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::544; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x544.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 Reviewed-by: Alex Bennée --- 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 Tue Jun 9 20:07:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11596555 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 AF441138C for ; Tue, 9 Jun 2020 20:12:59 +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 83DB520734 for ; Tue, 9 Jun 2020 20:12:59 +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="Pnb8W6ET" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 83DB520734 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]:40052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikcE-0003vx-QI for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jun 2020 16:12:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jikZI-0007lW-0b for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:56 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:33917) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jikZG-0005bk-Ee for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:55 -0400 Received: by mail-pl1-x643.google.com with SMTP id n9so23553plk.1 for ; Tue, 09 Jun 2020 13:09:53 -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=a1IujnwDzWygiMOVADIbNYVV1mCmC+OLrxpPE5Le/ts=; b=Pnb8W6ET7Y3BwO5XBHAzWyRRHzYavh+NAtfMQRw64L9OaL3xjyydIsylR1UlNvsIuI g9InhaZDEXgebaH6nQD/3pDSnuBRoLnz+O9I8BlqsOuiLQVSy14Rk9fk68mEyNR9JNO/ 16t9e7RGjPb7x2RONhQ6t16ihONAqQgT3WHUw4tW0oH/t8M+s8hg7SyQcXq2CCnD9r2U 1U7JLYcVFDRls8drGFJHi55XDqINelL7djsdpkZNa+8Y+43U9L7hS+LUe2mEhpsXX9WK 5AZ2HYAxfzmRz9rI+uoVAhJSVb376AnavagnEfOuWq6pRjIHaUleO7xA8exz0ZafG/lr DsSQ== 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=a1IujnwDzWygiMOVADIbNYVV1mCmC+OLrxpPE5Le/ts=; b=pqH8HGxKgTINyfCYpHLGqk1jSCB7zlW7Ay0zYlHhF/4p82cIfNCqdczg+XoC2eVmO6 4sf7wM2nCc8yqBLsHpwZcNfk2RXL59xI9y2kW1PXEHufKVMemDHkUqZn7w61tBqFIJAK mN3wvzQLGjkYYUy+1vaN97xDHSdzGk9tG2JJoH15C40/vCBNpbkteqfnDHiWBt6JjDv8 lUYkskr7w8VXllLbxGU4ceO90eXhFzuM1yx/JtZBhd5c1lubNiAFHdQFlB2+J7/Z9usA ZrmgpafQSq3oIgQHLp3mvaefrtF6SJftCpDVmXrnTViYAD+M8VMhDFl7To+6PWCO4RX/ pLAA== X-Gm-Message-State: AOAM532PE35QAmn7JQLzAjKF5qGvuDZo3QeGNd/62BjBUoibw4Z35fHr wQb+pjIHxKGttVOp/U74+55HYXGg128Cew== X-Google-Smtp-Source: ABdhPJwvGhELKNceLGvowMWIg8AUoPQed9Q710b9V6ZLgHDB6pLf4y2C/8O+0CPheyuktgDbsdWq5g== X-Received: by 2002:a17:902:7204:: with SMTP id ba4mr60645plb.137.1591733392290; Tue, 09 Jun 2020 13:09:52 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:1d09:cef2:3b1f:abce]) by smtp.gmail.com with ESMTPSA id n19sm10523374pfu.194.2020.06.09.13.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 13:09:51 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 09/13] tests/docker: Added docker build support for TSan. Date: Tue, 9 Jun 2020 16:07:34 -0400 Message-Id: <20200609200738.445-10-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609200738.445-1-robert.foley@linaro.org> References: <20200609200738.445-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-tsan-ubuntu2004 V=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 Reviewed-by: Alex Bennée --- tests/docker/dockerfiles/ubuntu2004.docker | 65 ++++++++++++++++++++++ tests/docker/test-tsan | 44 +++++++++++++++ tests/tsan/blacklist.tsan | 10 ++++ tests/tsan/suppressions.tsan | 14 +++++ 4 files changed, 133 insertions(+) create mode 100644 tests/docker/dockerfiles/ubuntu2004.docker create mode 100755 tests/docker/test-tsan create mode 100644 tests/tsan/blacklist.tsan create mode 100644 tests/tsan/suppressions.tsan 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/docker/test-tsan b/tests/docker/test-tsan new file mode 100755 index 0000000000..eb40ac45b7 --- /dev/null +++ b/tests/docker/test-tsan @@ -0,0 +1,44 @@ +#!/bin/bash -e +# +# This test will use TSan as part of a build and a make check. +# +# Copyright (c) 2020 Linaro +# Copyright (c) 2016 Red Hat Inc. +# +# Authors: +# Robert Foley +# Originally based on test-quick from Fam Zheng +# +# This work is licensed under the terms of the GNU GPL, version 2 +# or (at your option) any later version. See the COPYING file in +# the top-level directory. + +. common.rc + +setup_tsan() +{ + requires clang tsan + 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 detector 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_warning" + export TSAN_OPTIONS="$tsan_opts" +} + +cd "$BUILD_DIR" + +TARGET_LIST=${TARGET_LIST:-$DEF_TARGET_LIST} \ +setup_tsan +build_qemu +check_qemu +install_qemu diff --git a/tests/tsan/blacklist.tsan b/tests/tsan/blacklist.tsan new file mode 100644 index 0000000000..75e444f5dc --- /dev/null +++ b/tests/tsan/blacklist.tsan @@ -0,0 +1,10 @@ +# This is an example blacklist. +# To enable use of the blacklist add this to configure: +# "--extra-cflags=-fsanitize-blacklist=/tests/tsan/blacklist.tsan" +# The eventual goal would be to fix these warnings. + +# 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 diff --git a/tests/tsan/suppressions.tsan b/tests/tsan/suppressions.tsan new file mode 100644 index 0000000000..73414b9ebd --- /dev/null +++ b/tests/tsan/suppressions.tsan @@ -0,0 +1,14 @@ +# This is the set of runtime suppressions of TSan warnings. +# The goal would be to have here only items we do not +# plan to fix, and to explain why for each item. + +# TSan reports a double lock on RECURSIVE mutexes. +# Since the recursive lock is intentional, we choose to ignore it. +mutex:aio_context_acquire +mutex:pthread_mutex_lock + +# TSan reports a race betwen pthread_mutex_init() and +# pthread_mutex_lock(). Since this is outside of QEMU, +# we choose to ignore it. +race:pthread_mutex_init +race:pthread_mutex_lock From patchwork Tue Jun 9 20:07:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11596565 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 405A4739 for ; Tue, 9 Jun 2020 20:18:57 +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 1552920734 for ; Tue, 9 Jun 2020 20:18:57 +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="Lnj7Pdp+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1552920734 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]:56198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jiki0-0002Fn-DS for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jun 2020 16:18:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jikZI-0007nK-SJ for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:56 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:52595) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jikZH-0005by-Qu for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:56 -0400 Received: by mail-pj1-x1042.google.com with SMTP id k2so1863108pjs.2 for ; Tue, 09 Jun 2020 13:09:55 -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=Z+OFj29yCFbAWNlzpwiIPBHhzK7hPpPDuoaMSZsMcbg=; b=Lnj7Pdp+K51xUfHhblxF7XbUs3dLR9opXx9M+AWdHgBl9VVh+aeAPAmBRamIwP6iyU /uqt2K1+opgxJQemvVrnMER/Hv368Znh7CSMuNMAE6S7ekPpzwpxew1+SiCf/pX/m/rg K3Qmd+PziI0Eg82RxvuAZYJM92nTH5WDm206RXdpeWHte/y4kMPpQak+scI7j1H04Fmj E017CRiRslEP6kbefibu2oSx+4tAuvqnAQYQO/YzTuP97SH6wAC7N5nI44X3J5aVrrGl I06mTsqDypbS6gIqUI+KTHRYpnbzbveET5Y84cLl1vDZ0pk+jHeo2LburtNAy2bVQW7J CCeg== 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=Z+OFj29yCFbAWNlzpwiIPBHhzK7hPpPDuoaMSZsMcbg=; b=WA0I6Ci9R78GrFvTAk2p1xQvOHUtFTGZDousAxIGoe0dgqKKxnCZ6XLZRWCHs0PRJM BU6SXhaXM6BHWK4KO+j/soIBwDj2RIUHUVESvpipbn1HJhNwEKAp0zRVYW3vOrskJHEk RiCbKXc07ELRJc+FIyjxWlaAFBxgJH5BpboXXXiHBnYfrjKtuK33lBniZdanDelHAle9 IE4UATUFqz9VjlLZc9VSTxuTeGKEckfjdf0QkkPcY5tDUz90E0mV7AgOzzzs4QZGyfZL ECKQ7jxILrooZ47iJhsENoWuE/Lr+APZSm1YEObg8IxOENL7f4b6muuAK8WWNyVjJkoV 12Xw== X-Gm-Message-State: AOAM531psS6XHtPIpe8wDoa5wuQFB6pJ+dZJhpk97mstUVhjy9m9ggcX 7OyiXlhvz957AdInmgXY3EgbaFV2K+iJug== X-Google-Smtp-Source: ABdhPJyU20Hk8Mos/BIxOTs1ANFg7ICxXFNhwqU8eMRkywfayDgvzFrSrQL5E0SB425Bm4+IskwLOw== X-Received: by 2002:a17:902:bc84:: with SMTP id bb4mr71130plb.55.1591733394129; Tue, 09 Jun 2020 13:09:54 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:1d09:cef2:3b1f:abce]) by smtp.gmail.com with ESMTPSA id n19sm10523374pfu.194.2020.06.09.13.09.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 13:09:53 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 10/13] include/qemu: Added tsan.h for annotations. Date: Tue, 9 Jun 2020 16:07:35 -0400 Message-Id: <20200609200738.445-11-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609200738.445-1-robert.foley@linaro.org> References: <20200609200738.445-1-robert.foley@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1042; envelope-from=robert.foley@linaro.org; helo=mail-pj1-x1042.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 Reviewed-by: Alex Bennée --- include/qemu/tsan.h | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 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..09cc665f91 --- /dev/null +++ b/include/qemu/tsan.h @@ -0,0 +1,71 @@ +#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. + * + * Annotation examples can be found here: + * https://github.com/llvm/llvm-project/tree/master/compiler-rt/test/tsan + * annotate_happens_before.cpp or ignore_race.cpp are good places to start. + * + * The full set of annotations can be found here in tsan_interface_ann.cpp. + * https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/tsan/rtl/ + * + * 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 +/* + * Informs TSan of a happens before/after relationship. + */ +#define QEMU_TSAN_ANNOTATE_HAPPENS_BEFORE(addr) \ + AnnotateHappensBefore(__FILE__, __LINE__, (void *)(addr)) +#define QEMU_TSAN_ANNOTATE_HAPPENS_AFTER(addr) \ + AnnotateHappensAfter(__FILE__, __LINE__, (void *)(addr)) +/* + * Gives TSan more information about thread names it can report the + * name of the thread in the warning report. + */ +#define QEMU_TSAN_ANNOTATE_THREAD_NAME(name) \ + AnnotateThreadName(__FILE__, __LINE__, (void *)(name)) +/* + * Allows defining a region of code on which TSan will not record memory READS. + * This has the effect of disabling race detection for this section of code. + */ +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_BEGIN() \ + AnnotateIgnoreReadsBegin(__FILE__, __LINE__) +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_END() \ + AnnotateIgnoreReadsEnd(__FILE__, __LINE__) +/* + * Allows defining a region of code on which TSan will not record memory + * WRITES. This has the effect of disabling race detection for this + * section of code. + */ +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN() \ + AnnotateIgnoreWritesBegin(__FILE__, __LINE__) +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_END() \ + AnnotateIgnoreWritesEnd(__FILE__, __LINE__) +#else +#define QEMU_TSAN_ANNOTATE_HAPPENS_BEFORE(addr) +#define QEMU_TSAN_ANNOTATE_HAPPENS_AFTER(addr) +#define QEMU_TSAN_ANNOTATE_THREAD_NAME(name) +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_BEGIN() +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_END() +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN() +#define QEMU_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 Tue Jun 9 20:07:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11596567 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 8EBF7618 for ; Tue, 9 Jun 2020 20:20: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 206FE206C3 for ; Tue, 9 Jun 2020 20:20: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="Jbd4VB5t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 206FE206C3 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]:58370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikjG-0003AZ-4W for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jun 2020 16:20:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59344) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jikZK-0007rz-OF for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:58 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:41996) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jikZJ-0005cO-TH for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:09:58 -0400 Received: by mail-pl1-x644.google.com with SMTP id x11so7922plv.9 for ; Tue, 09 Jun 2020 13:09:57 -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=bZmmE8g6bACENWl1LtFwmXs+x0B5ALCEi1t1qd6zEd8=; b=Jbd4VB5tNNHl83ZC/85lNtZEpg1zmVsflfBRMACSeRar/5YVqcwprrkY43v9BuhXT/ OAcnBHCKQ/V3oiS+8BNsYGOZVz1RSHA6YcDdlltJ7Lk0WXuTGQUslJgOsNj72l8UzFX5 J4dvMoSDFDR4q5wpvDs4MhAqJa5Nc4IONPNAm7aaWLNBvcIncCeMwfQZouAnAvZEfUto f4SSeeTOnYAWtj2OaQ7bu6XGtA1UHI5d948/WpOHLcqHRtrkYajKthNooCkgszVwIdnf F4R9E3MP3TYBpGq4h2JBwxwosGjT+3hQv10CKClLtcSXKg8bJzJXIYNEZ6meIGbEnC6w YNJA== 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=bZmmE8g6bACENWl1LtFwmXs+x0B5ALCEi1t1qd6zEd8=; b=Aey97XeAcf22dks8Eh8OFnBpKUdGVPv137ek2tijUAG09JjPcyhPvJ2h9EyxSEP7OU Z9lqChDPSIA2urm1HbC0C1N0WE+tl5c5m/31a3lR7yq6B7x3UEQTZ+x8zLjMq6+V6YU0 W+jIdN+gc61JVX51RCBslarPGs6/yjGSmhTuWy6TE5XWqCy1nnDj/vPHyDTS/WRpQ1Vk fw0EZJbU9F9Ldihx1MzlyRaTHcMW1XsWhs+9nXL4l2Ao/GJ6vB+E25zEd9tcJvkLS9lW Buh6u2ZNAJAMDV1kf1BH6eE0rIxyk8SuKX5ASxVg9OdXfX8xLW5mGLJG1BrMUUU393eH cCLw== X-Gm-Message-State: AOAM533VSuOKSQy6wtdGL+tGuQr/QJAVayaQ8FKRkMZzVGfkXVFBvxf/ QSRhUzW6q9E9R6OdeLOwzVsK06f2eE5uqA== X-Google-Smtp-Source: ABdhPJyu6EbSyaHoN1bHSnEOFkYtD4Fq5yIq6dhsgHdEWceX9rtvpP9BrJ0KGNyNC6IgMEwtPLftvA== X-Received: by 2002:a17:90a:328d:: with SMTP id l13mr6262891pjb.236.1591733396272; Tue, 09 Jun 2020 13:09:56 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:1d09:cef2:3b1f:abce]) by smtp.gmail.com with ESMTPSA id n19sm10523374pfu.194.2020.06.09.13.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 13:09:55 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 11/13] util: Added tsan annotate for thread name. Date: Tue, 9 Jun 2020 16:07:36 -0400 Message-Id: <20200609200738.445-12-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609200738.445-1-robert.foley@linaro.org> References: <20200609200738.445-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, Paolo Bonzini 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..b4c2359272 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 + QEMU_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 Tue Jun 9 20:07:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11596569 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 5B2FF618 for ; Tue, 9 Jun 2020 20:21: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 2CC2D206C3 for ; Tue, 9 Jun 2020 20:21: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="RY9HSuxK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2CC2D206C3 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]:60550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikkO-0004Dr-Gl for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jun 2020 16:21:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jikZM-0007wu-Tu for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:10:00 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:43454) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jikZL-0005cX-T9 for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:10:00 -0400 Received: by mail-pf1-x441.google.com with SMTP id 23so38713pfw.10 for ; Tue, 09 Jun 2020 13:09:59 -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=zkAx8xWtCWhcEMmU8jAnkCrKBrfEu7h9Ojxrn77WllE=; b=RY9HSuxKrh+3sCVZGVO29aHtQcqu05Ks7BVdJWz6BGcbmrXjcthKCUNBmjXQFQZ1rw gvUaLSY54aJA4LA+m72NIXhgBfOyN8KufeDoEdYyw88z99Ua6y3Cdrz3ipWw5h8ThVe/ tXj43gVefliTzfn95WLeogFT3JB512U8ohSHZK9UNjiyj3eH3b3jKIJnHXc4kTAeJ/SZ VUohOqcs/EA7SMw6LFgYr3tnk4TJ2rCbL8D285xMaAFpx0+bS8aEWpft9kwVc2EnYsom 2cybvXWxHFCmAq4zwZoyOGDKqirVDKeYOguiDcnh11zalctU9OGEFufq2vNwG/ms7Tv7 M6QQ== 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=zkAx8xWtCWhcEMmU8jAnkCrKBrfEu7h9Ojxrn77WllE=; b=pbMZV5u4xKf/mPqrtKje2yVRFnUxfPLuxNgmGiYTTH+WRL1W9juHGMT7jo/NYbBBMI WfWN6TyfQAbdfTuscCDoK0eSuslvphYZBGzzgvbGLvzgjx2hqThszz++Y7Sb+cz1X8gO aKzIBlLqzY48GARPRdHgTM54u450DI7XLfNT7n48OT01n3Rgih37gUM5E0AMTs0JMr8l zH71HIB6A0qjEptHyXgZJw6tzZVNUcDobeDuq0XxOGcObQgUjv9YgQB4i+cZ3inM/iL0 GXKTIMLHbOvBeMevAuO3qCf820g1w4NkSRmKo9VYEpWUCL0hf4AZWXR3n20xOUocysr/ aDiQ== X-Gm-Message-State: AOAM530M13ANuNHdV5mT6SreTXazTzoUICJPMZaQoE+QJLT2FXFd7Rh2 Zzqw0PohZ8Coa4Wy5H1U7s7PEE8XzNJvog== X-Google-Smtp-Source: ABdhPJzbFDhQ1//obqhcgw4mrxhYcS7LcsCDuySrwkybLPcs8s46Y0PK3LkFeG5gHlYlpr3XzDeH5Q== X-Received: by 2002:a62:55c1:: with SMTP id j184mr25464470pfb.240.1591733398111; Tue, 09 Jun 2020 13:09:58 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:1d09:cef2:3b1f:abce]) by smtp.gmail.com with ESMTPSA id n19sm10523374pfu.194.2020.06.09.13.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 13:09:57 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 12/13] docs: Added details on TSan to testing.rst Date: Tue, 9 Jun 2020 16:07:37 -0400 Message-Id: <20200609200738.445-13-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609200738.445-1-robert.foley@linaro.org> References: <20200609200738.445-1-robert.foley@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::441; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x441.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" Adds TSan details to testing.rst. This includes background and reference details on TSan, and details on how to build and test with TSan both with and without docker. Signed-off-by: Robert Foley Reviewed-by: Emilio G. Cota Reviewed-by: Alex Bennée --- docs/devel/testing.rst | 107 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst index 770a987ea4..c1ff24370b 100644 --- a/docs/devel/testing.rst +++ b/docs/devel/testing.rst @@ -397,6 +397,113 @@ 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 +================ + +Thread Sanitizer (TSan) is a tool which can detect data races. QEMU supports +building and testing with this tool. + +For more information on TSan: + +https://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual + +Thread Sanitizer in Docker +--------------------------- +TSan is currently supported in the ubuntu2004 docker. + +The test-tsan test will build using TSan and then run make check. + +.. code:: + + make docker-test-tsan@ubuntu2004 + +TSan warnings under docker 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. + +Building and Testing with TSan +------------------------------ + +It is possible to build and test with TSan, with a few additional steps. +These steps are normally done automatically in the docker. + +There is a one time patch needed in clang-9 or clang-10 at this time: + +.. code:: + + sed -i 's/^const/static const/g' \ + /usr/lib/llvm-10/lib/clang/10.0.0/include/sanitizer/tsan_interface.h + +To configure the build for TSan: + +.. code:: + + ../configure --enable-tsan --cc=clang-10 --cxx=clang++-10 \ + --disable-werror --extra-cflags="-O0" + +The runtime behavior of TSAN is controlled by the TSAN_OPTIONS environment +variable. + +More information on the TSAN_OPTIONS can be found here: + +https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags + +For example: + +.. code:: + + export TSAN_OPTIONS=suppressions=/tests/tsan/suppressions.tsan \ + detect_deadlocks=false history_size=7 exitcode=0 \ + log_path=/tsan/tsan_warning + +The above exitcode=0 has 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. + +TSan Suppressions +----------------- +Keep in mind that for any data race warning, although there might be a data race +detected by TSan, there might be no actual bug here. TSan provides several +different mechanisms for suppressing warnings. In general it is recommended +to fix the code if possible to eliminate the data race rather than suppress +the warning. + +A few important files for suppressing warnings are: + +tests/tsan/suppressions.tsan - Has TSan warnings we wish to suppress at runtime. +The comment on each supression will typically indicate why we are +suppressing it. More information on the file format can be found here: + +https://github.com/google/sanitizers/wiki/ThreadSanitizerSuppressions + +tests/tsan/blacklist.tsan - Has TSan warnings we wish to disable +at compile time for test or debug. +Add flags to configure to enable: + +"--extra-cflags=-fsanitize-blacklist=/tests/tsan/blacklist.tsan" + +More information on the file format can be found here under "Blacklist Format": + +https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags + +TSan Annotations +---------------- +include/qemu/tsan.h defines annotations. See this file for more descriptions +of the annotations themselves. Annotations can be used to suppress +TSan warnings or give TSan more information so that it can detect proper +relationships between accesses of data. + +Annotation examples can be found here: + +https://github.com/llvm/llvm-project/tree/master/compiler-rt/test/tsan/ + +Good files to start with are: annotate_happens_before.cpp and ignore_race.cpp + +The full set of annotations can be found here: + +https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cpp + VM testing ========== From patchwork Tue Jun 9 20:07:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11596559 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 48B1B912 for ; Tue, 9 Jun 2020 20:14:36 +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 1D87D2065C for ; Tue, 9 Jun 2020 20:14:36 +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="meFFanmv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D87D2065C 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]:45280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikdn-00064s-By for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jun 2020 16:14:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jikZP-000815-Mz for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:10:03 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:39678) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jikZO-0005cr-ED for qemu-devel@nongnu.org; Tue, 09 Jun 2020 16:10:03 -0400 Received: by mail-pg1-x52c.google.com with SMTP id w20so10766230pga.6 for ; Tue, 09 Jun 2020 13:10: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=cHjY5HzznfKw8VbLxbBOVqurhqy9xCUukR85p1gtXTQ=; b=meFFanmvYve6P4U84sZWJmvNJtxvl5Odzkfx3EOOaEY5IqWwcu1Km1m14phH79lK+E siDDwMZyUYpSACzfFDVm51PWeqkaCCEzWEPOtCFWKm3bivPuBYP+zmprenJG6WtDXzaC eVNGbpf1vr2zkfRk8OItepu9IEUQcFqVV7O+cLN4ZeXomi5N3P8asrGpUJpZ1jGOFyQb 8GjgAlYecgyA5wyUlQ3r4OUDaaXZuxyvmPHIvHv2x/98AivNrO6aHm1h1vw36xKxJ7bT MchefeoniBvHVRetRX7wQxSKGs8BnpJ/x45nHcJdXojORQOXuN7bM4s4Gone8VxuV0LH 6Obw== 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=cHjY5HzznfKw8VbLxbBOVqurhqy9xCUukR85p1gtXTQ=; b=Fe5aprxNo2W2erFC9UsLro6G/IGjM388VQV0pfqiLxMr0pMKI6OccXR7mPNzVJ92ft i/osxIK22ZAC5W6AbyyfBcc18ezJo+t7pdIzwxjFiijCeknCrU2im64X+lExyyQTwP8u 8g3X9WW4KG9U3VDseBBie6ceIKiTSAFas/Xs+QrInhLWipoC7Nu79f8I8uWm21UFl0Ku 5FSdMeq2yc1kEBCdK//MfEnxgaHdSfG2uRNEsW/nuZVsrbuO27ZIPtunmKlHLOAV+tSw Hav7JxRJoPvV348SjRvq2zbFG8WH1EL5sdsIz89XULgD0Vu9C8vICaVs9jQ3ORct2uXl ZCWA== X-Gm-Message-State: AOAM530xr2PqBahfSbj9xyHFacb45J9WpF0OmGYYNevp5EOyPHYlMFdN m0ofy99W46QEs1mm7fLjxaAebDA0SEhjUQ== X-Google-Smtp-Source: ABdhPJyTysgoZ3Lbeg8LtOxKKhDI98mw0xurs+9pgRIytjwTseN0pyz7We8x3Kd2vlZamEf6L7oeRQ== X-Received: by 2002:aa7:8b56:: with SMTP id i22mr26717403pfd.63.1591733400654; Tue, 09 Jun 2020 13:10:00 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:1d09:cef2:3b1f:abce]) by smtp.gmail.com with ESMTPSA id n19sm10523374pfu.194.2020.06.09.13.09.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 13:09:59 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 13/13] tests: Disable select tests under TSan, which hit TSan issue. Date: Tue, 9 Jun 2020 16:07:38 -0400 Message-Id: <20200609200738.445-14-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609200738.445-1-robert.foley@linaro.org> References: <20200609200738.445-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x52c.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: Laurent Vivier , Thomas Huth , robert.foley@linaro.org, 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" Disable a few tests under CONFIG_TSAN, which run into a known TSan issue that results in a hang. https://github.com/google/sanitizers/issues/1116 The disabled tests under TSan include all the qtests as well as the test-char, test-qga, and test-qdev-global-props. Signed-off-by: Robert Foley Reviewed-by: Emilio G. Cota --- tests/Makefile.include | 9 +++++++-- tests/qtest/Makefile.include | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index c2397de8ed..8d82c24d83 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -55,7 +55,6 @@ SYSEMU_TARGET_LIST := $(subst -softmmu.mak,,$(notdir \ check-unit-y += tests/check-qdict$(EXESUF) check-unit-y += tests/check-block-qdict$(EXESUF) -check-unit-$(CONFIG_SOFTMMU) += tests/test-char$(EXESUF) check-unit-y += tests/check-qnum$(EXESUF) check-unit-y += tests/check-qstring$(EXESUF) check-unit-y += tests/check-qlist$(EXESUF) @@ -108,7 +107,6 @@ check-unit-y += tests/test-qht$(EXESUF) check-unit-y += tests/test-qht-par$(EXESUF) check-unit-y += tests/test-bitops$(EXESUF) check-unit-y += tests/test-bitcnt$(EXESUF) -check-unit-$(CONFIG_SOFTMMU) += tests/test-qdev-global-props$(EXESUF) check-unit-y += tests/check-qom-interface$(EXESUF) check-unit-y += tests/check-qom-proplist$(EXESUF) check-unit-y += tests/test-qemu-opts$(EXESUF) @@ -123,9 +121,16 @@ check-speed-$(CONFIG_BLOCK) += tests/benchmark-crypto-cipher$(EXESUF) check-unit-$(CONFIG_BLOCK) += tests/test-crypto-secret$(EXESUF) check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_GNUTLS)) += tests/test-crypto-tlscredsx509$(EXESUF) check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_GNUTLS)) += tests/test-crypto-tlssession$(EXESUF) +ifndef CONFIG_TSAN +# Some tests: test-char, test-qdev-global-props, and test-qga, +# are not runnable under TSan due to a known issue. +# https://github.com/google/sanitizers/issues/1116 +check-unit-$(CONFIG_SOFTMMU) += tests/test-char$(EXESUF) +check-unit-$(CONFIG_SOFTMMU) += tests/test-qdev-global-props$(EXESUF) ifneq (,$(findstring qemu-ga,$(TOOLS))) check-unit-$(call land,$(CONFIG_LINUX),$(CONFIG_VIRTIO_SERIAL)) += tests/test-qga$(EXESUF) endif +endif check-unit-$(CONFIG_SOFTMMU) += tests/test-timed-average$(EXESUF) check-unit-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_INOTIFY1)) += tests/test-util-filemonitor$(EXESUF) check-unit-$(CONFIG_SOFTMMU) += tests/test-util-sockets$(EXESUF) diff --git a/tests/qtest/Makefile.include b/tests/qtest/Makefile.include index 9e5a51d033..71fd714a2a 100644 --- a/tests/qtest/Makefile.include +++ b/tests/qtest/Makefile.include @@ -313,12 +313,15 @@ tests/qtest/tpm-tis-device-test$(EXESUF): tests/qtest/tpm-tis-device-test.o test # QTest rules TARGETS=$(patsubst %-softmmu,%, $(filter %-softmmu,$(TARGET_DIRS))) +QTEST_TARGETS = +# The qtests are not runnable (yet) under TSan due to a known issue. +# https://github.com/google/sanitizers/issues/1116 +ifndef CONFIG_TSAN ifeq ($(CONFIG_POSIX),y) QTEST_TARGETS = $(TARGETS) check-qtest-y=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)-y:%=tests/qtest/%$(EXESUF))) check-qtest-y += $(check-qtest-generic-y:%=tests/qtest/%$(EXESUF)) -else -QTEST_TARGETS = +endif endif qtest-obj-y = tests/qtest/libqtest.o $(test-util-obj-y)