From nobody Thu May 9 14:30:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591733461; cv=none; d=zohomail.com; s=zohoarc; b=RJYS6uAaVjiM4DVGwreZEEUAvLcCvQCSXp/PpMzSYS0wfAWWYVBWW0LEVZy7XkPGPXOCJl/7eJeG1KbQYfjWj5qvOkTL0IbaecjnFULVM0RkM2Tdyjk6JgYHVZ/Dsd1Fy+60b8o2YUIRLlXHVLagFG9w/3z1QLFAPtR9cw/1Spg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591733461; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PEbujPtBaJg3B2IT0hPnYXWImSAP6JwyxZ2Cqb86MEY=; b=MohNNgm7cf6AIf08Fan+2C7G04REQSB2+hII+5dSdqY1dpNGarNFKTnZQ6lZ0TuUMNtYj88U9avvhDDkpEtRRsKF2o5v/Yd0A+GaQNfopm2/TXfuaRjwG5DAA32gHx34Q8elb9x1AO+V4MIYVw4/P+Otkd+Ig1rsCigZt53VgAE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591733461621897.5262068736521; Tue, 9 Jun 2020 13:11:01 -0700 (PDT) Received: from localhost ([::1]:60218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikaK-0000Wf-5D for importer@patchew.org; Tue, 09 Jun 2020 16:11:00 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::643; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x643.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 annotat= ed 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=3Dclang-9 --cxx=3Dclang++-9 --disable-werro= r' 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=C3=A9e --- 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=3D"no" debug_tcg=3D"no" debug=3D"no" sanitizers=3D"no" +tsan=3D"no" fortify_source=3D"" strip_opt=3D"yes" tcg_interpreter=3D"no" @@ -1150,6 +1151,10 @@ for opt do ;; --disable-sanitizers) sanitizers=3D"no" ;; + --enable-tsan) tsan=3D"yes" + ;; + --disable-tsan) tsan=3D"no" + ;; --enable-sparse) sparse=3D"yes" ;; --disable-sparse) sparse=3D"no" @@ -1754,6 +1759,7 @@ Advanced options (experts only): --with-pkgversion=3DVERS use specified string as sub-version of the pa= ckage --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" =3D "yes" ; then fi fi =20 +# Thread sanitizer is, for now, much noisier than the other sanitizers; +# keep it separate until that is not the case. +if test "$tsan" =3D "yes" && test "$sanitizers" =3D "yes"; then + error_exit "TSAN is not supported with other sanitiziers." +fi +have_tsan=3Dno +have_tsan_iface_fiber=3Dno +if test "$tsan" =3D "yes" ; then + write_c_skeleton + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=3Dthread" "" ; then + have_tsan=3Dyes + fi + cat > $TMPC << EOF +#include +int main(void) { + __tsan_create_fiber(0); + return 0; +} +EOF + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=3Dthread" "" ; then + have_tsan_iface_fiber=3Dyes + fi +fi + ########################################## # check for libpmem =20 @@ -6297,6 +6327,16 @@ if test "$have_asan" =3D "yes"; then "Without code annotation, the report may be inferior." fi fi +if test "$have_tsan" =3D "yes" ; then + if test "$have_tsan_iface_fiber" =3D "yes" ; then + QEMU_CFLAGS=3D"-fsanitize=3Dthread $QEMU_CFLAGS" + QEMU_LDFLAGS=3D"-fsanitize=3Dthread $QEMU_LDFLAGS" + else + error_exit "Cannot enable TSAN due to missing fiber annotation interfa= ce." + fi +elif test "$tsan" =3D "yes" ; then + error_exit "Cannot enable TSAN due to missing sanitize thread interface." +fi if test "$have_ubsan" =3D "yes"; then QEMU_CFLAGS=3D"-fsanitize=3Dundefined $QEMU_CFLAGS" QEMU_LDFLAGS=3D"-fsanitize=3Dundefined $QEMU_LDFLAGS" @@ -6332,7 +6372,8 @@ if test "$werror" =3D "yes"; then QEMU_CFLAGS=3D"-Werror $QEMU_CFLAGS" fi =20 -if test "$solaris" =3D "no" ; then +# Exclude --warn-common with TSan to suppress warnings from the TSan libra= ries. +if test "$solaris" =3D "no" && test "$tsan" =3D "no"; then if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; = then QEMU_LDFLAGS=3D"-Wl,--warn-common $QEMU_LDFLAGS" fi @@ -7386,6 +7427,10 @@ if test "$have_asan_iface_fiber" =3D "yes" ; then echo "CONFIG_ASAN_IFACE_FIBER=3Dy" >> $config_host_mak fi =20 +if test "$have_tsan" =3D "yes" && test "$have_tsan_iface_fiber" =3D "yes" = ; then + echo "CONFIG_TSAN=3Dy" >> $config_host_mak +fi + if test "$has_environ" =3D "yes" ; then echo "CONFIG_HAS_ENVIRON=3Dy" >> $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 =20 +#ifdef CONFIG_TSAN +#include +#endif + typedef struct { Coroutine base; void *stack; size_t stack_size; sigjmp_buf env; =20 + 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]; }; =20 -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 =3D __tsan_create_fiber(0); /* flags: sync on switch= */ + co->tsan_caller_fiber =3D __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 =3D size_old; } #endif +#ifdef CONFIG_TSAN + if (fake_stack_save) { + __tsan_release(fake_stack_save); + __tsan_switch_to_fiber(fake_stack_save, 0); /* 0=3Dsynchronize */ + } +#endif } =20 -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 =3D=3D COROUTINE_TERMINATE ? NULL : fake_stack_save, + bottom, size); +#endif +#ifdef CONFIG_TSAN + void *curr_fiber =3D + __tsan_get_current_fiber(); + __tsan_acquire(curr_fiber); + + *fake_stack_save =3D curr_fiber; + __tsan_switch_to_fiber(new_fiber, 0); /* 0=3Dsynchronize */ #endif } =20 @@ -104,8 +139,12 @@ static void coroutine_trampoline(int i0, int i1) =20 /* 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); } =20 @@ -154,12 +193,16 @@ Coroutine *qemu_coroutine_new(void) =20 arg.p =3D co; =20 + on_new_fiber(co); makecontext(&uc, (void (*)(void))coroutine_trampoline, 2, arg.i[0], arg.i[1]); =20 /* 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); } =20 @@ -216,8 +259,8 @@ qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, =20 ret =3D sigsetjmp(from->env, 0); if (ret =3D=3D 0) { - start_switch_fiber(action =3D=3D COROUTINE_TERMINATE ? - NULL : &fake_stack_save, to->stack, to->stack_s= ize); + start_switch_fiber(action, &fake_stack_save, + to->stack, to->stack_size, to->tsan_co_fiber); siglongjmp(to->env, action); } =20 @@ -231,6 +274,11 @@ Coroutine *qemu_coroutine_self(void) if (!current) { current =3D &leader.base; } +#ifdef CONFIG_TSAN + if (!leader.tsan_co_fiber) { + leader.tsan_co_fiber =3D __tsan_get_current_fiber(); + } +#endif return current; } =20 --=20 2.17.1 From nobody Thu May 9 14:30:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591733587; cv=none; d=zohomail.com; s=zohoarc; b=lvjAfAJhLxCTcbMtCg7u+cguanYeOsINV+dAdMMNFmzYB81X0Xl74Zpv8iC4hgPJwVx3JLz/uukF/iQ+5KlzYc2bnwT8PhV7yBqYX+MwI22l0Nn6lPa1I5hDQrlfzlputqQWdflJQN5vNXF/qjnYdjyW1Ftr1qmfRv1hfbfNZtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591733587; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pD3JWxT76a4NROnBN3hpZMTAPaW7sxqBc70GvHSGYPw=; b=HWbJvXDXept7bgklk8VieKp4iv/xrvoqW27cxg7QR5YUzkgkpnR7k84rgSWOkQz7l0ALqCNgEfJza14b3byUKYUqAWOB1dNLm9pHmvDHLGWrmztkCcscoXuOMOS0pZ9KIZG0YB2GbNfl7AxX9BNRsJcnUd7PV62cSapxvjWnKMg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591733587800705.0939438085132; Tue, 9 Jun 2020 13:13:07 -0700 (PDT) Received: from localhost ([::1]:39014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikcM-0003WF-Df for importer@patchew.org; Tue, 09 Jun 2020 16:13:06 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 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) } =20 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 =3D=3D NULL) { - cpu->queued_work_first =3D wi; - } else { - cpu->queued_work_last->next =3D wi; - } - cpu->queued_work_last =3D wi; - wi->next =3D NULL; + QSIMPLEQ_INSERT_TAIL(&cpu->work_list, wi, node); wi->done =3D false; qemu_mutex_unlock(&cpu->work_mutex); =20 @@ -306,17 +300,14 @@ void process_queued_cpu_work(CPUState *cpu) { struct qemu_work_item *wi; =20 - if (cpu->queued_work_first =3D=3D 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 !=3D NULL) { - wi =3D cpu->queued_work_first; - cpu->queued_work_first =3D wi->next; - if (!cpu->queued_work_first) { - cpu->queued_work_last =3D NULL; - } + while (!QSIMPLEQ_EMPTY(&cpu->work_list)) { + wi =3D 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 dea= dlock: 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(); } =20 +static inline bool cpu_work_list_empty(CPUState *cpu) +{ + bool ret; + + qemu_mutex_lock(&cpu->work_mutex); + ret =3D 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 =3D first_cpu; } =20 - while (cpu && !cpu->queued_work_first && !cpu->exit_request) { + while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) { =20 atomic_mb_set(&tcg_current_rr_cpu, cpu); current_cpu =3D 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 =3D 1; =20 qemu_mutex_init(&cpu->work_mutex); + QSIMPLEQ_INIT(&cpu->work_list); QTAILQ_INIT(&cpu->breakpoints); QTAILQ_INIT(&cpu->watchpoints); =20 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 ch= anges * to @trace_dstate). * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask). @@ -376,7 +376,7 @@ struct CPUState { sigjmp_buf jmp_env; =20 QemuMutex work_mutex; - struct qemu_work_item *queued_work_first, *queued_work_last; + QSIMPLEQ_HEAD(, qemu_work_item) work_list; =20 CPUAddressSpace *cpu_ases; int num_ases; --=20 2.17.1 From nobody Thu May 9 14:30:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591733467; cv=none; d=zohomail.com; s=zohoarc; b=AIgzKqqDUl2ArMMULEJR9+g6wDHM2WuvwXZQULYQ1hFrzHBVnuoaF2zGrYKL59gResasI3XQNu518SrhquEnEM4edfhn/N+bO4oy2L1ojnwPfNWFlAjH2rZbrbkyba2ZZonDVJLN4hcPKUGuODOix3d8YH5+ntcFJ+jZnDNzGVw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591733467; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hi7LUnC/2Vxc6CG4AyW71h/9KhgELUl20yMZDhooBMo=; b=i16cUf2NkTUrBdEz3279B5mquvwzL/uJ6kV5KZRtYvIgo+RBC05e3C32+bk8AtAlXLd+6lgHqDxZftD5Gp4ZzX80rpUPq1rCZpCHYbqbHyVuCXb2Aufs22YMjF9+QgktZ7rOTrPIfepkq6iB5yRJq6klLQs/NTnr86y3x3PXx4k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591733467121992.8822140090426; Tue, 9 Jun 2020 13:11:07 -0700 (PDT) Received: from localhost ([::1]:60718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikaP-0000lF-TY for importer@patchew.org; Tue, 09 Jun 2020 16:11:05 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::643; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x643.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9e --- 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); } =20 +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))) { --=20 2.17.1 From nobody Thu May 9 14:30:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591733676; cv=none; d=zohomail.com; s=zohoarc; b=DT6u+616QkoheHlHgIUpyC47AXi+1H9z4SEfP/8rnAuHqSZ05OeeA+4yR1j0paA4e6tnp+ghXM4O8WFBuF4M5tqa28rk4I6k9QDNOhZpwo/ill+KyPzLwMLER+eiJcM9KELFieUYhM1i19GTE/BXx4ivU34PctxJNhmjnrb8xVY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591733676; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mMbQhssouUvEnYpKM8BJ1rWl4q0BOBlTa248+fa3MEA=; b=NUSeh2pfonqJvLm4MOh/cA/J3tYZRBGj2UFZT0/HNEmEd/IPHiQTYK3DrRIWMsuta0ASLIaEmV6I4ehUmFI9fbEb7NcLxZI8Mb8xD9jUvVHyj5l/ucWdIiDYmHPDErduNUhyZosmzZHX3VVf0DnREztO6sX9qPx0ehWv32QMtic= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591733676749278.6228901563742; Tue, 9 Jun 2020 13:14:36 -0700 (PDT) Received: from localhost ([::1]:44458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikdn-0005kf-Hp for importer@patchew.org; Tue, 09 Jun 2020 16:14:35 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::641; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x641.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9e --- 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) } } =20 +void tlb_destroy(CPUState *cpu) +{ + CPUArchState *env =3D cpu->env_ptr; + int i; + + qemu_spin_destroy(&env_tlb(env)->c.lock); + for (i =3D 0; i < NB_MMU_MODES; i++) { + CPUTLBDesc *desc =3D &env_tlb(env)->d[i]; + CPUTLBDescFast *fast =3D &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 =3D CPU_GET_CLASS(cpu); =20 + tlb_destroy(cpu); cpu_list_remove(cpu); =20 if (cc->vmsd !=3D 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) { } --=20 2.17.1 From nobody Thu May 9 14:30:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591733782; cv=none; d=zohomail.com; s=zohoarc; b=akf56U7z/mEZygBQ3aMjr7kSW7AJ8pGQy3CQpSlu1fkQpI5SapgK9SIzf4SNXEzaexlmk+NJVZyRNoanXYf5/z7btlDCuPeQZDvqjjJlzfYf+Mqj6rGexC6lj5g4R1Jaha1SXH1fQh0YCKwgvOfdJpSE6iBGa8e0r3KYYUM0JJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591733782; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hMythbUcqIycDnX7vBXLsyLkA4NDGTmBWD2zTKmRWuE=; b=ZtZt5ZSDNnltlDeEBrGz6NG1f833o/CvpaLrZ42I2ih9s7gmlsbJYpYwJu3uAuNZiAj2OlTZkPTIf3v6RITSMlwrvLaohtXvKVK56B4hx/Mxmi9nX8W16c00K9Nwtile0/QmqDyDaWe0+Un5r7zrv/cHbGZDKpSR2KPYUBZ1UmQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159173378293325.410159919527246; Tue, 9 Jun 2020 13:16:22 -0700 (PDT) Received: from localhost ([::1]:48880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikfV-0007f8-HE for importer@patchew.org; Tue, 09 Jun 2020 16:16:21 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Emilio G. Cota" Signed-off-by: Robert Foley Reviewed-by: Alex Benn=C3=A9e --- 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_b= ucket *head) struct qht_bucket *curr =3D head->next; struct qht_bucket *prev; =20 + qemu_spin_destroy(&head->lock); while (curr) { prev =3D curr; curr =3D curr->next; --=20 2.17.1 From nobody Thu May 9 14:30:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591733874; cv=none; d=zohomail.com; s=zohoarc; b=a98NgnQReKYv3SFhRps3LlPW/UdcX2zD41tAeTb34BpQQwD6jyhRGZi1Byz/hE6fWb4rhxHb2Oan1xI+BupXMAn8VU052y6+Xkcew2NCUbus1YplFnCMeDvOBv0asHyAhgB2DyYLEbvG02oDnWVxsHrT8ed8IgYbH954/XDyprU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591733874; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=qwuZW03UALyLreC41dDKLL3VuvvJz8e2voNJjWwlkPc=; b=Pp3CZ2+3+GHxKlYX2qA6eVQzdl5xPTrzEERy2/kRDk+vbtsjP3OnQI039ZFoemwEyHWYJ8sU8p+ppx3v/PDR5k40KrMnbRyQo9080bNEgKE8zCtwLTYl+LLiL3g+aXhKUo1aeFzaN32OkjgUM+w5V8xj1t4eOuPJrKOL9K4zS64= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591733874447968.7728617547364; Tue, 9 Jun 2020 13:17:54 -0700 (PDT) Received: from localhost ([::1]:53046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikgz-0000zg-9j for importer@patchew.org; Tue, 09 Jun 2020 16:17:53 -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) 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) 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) 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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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, Tr= anslationBlock *tb, return 0; } =20 +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 =3D true; } @@ -1886,6 +1892,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, =20 orig_aligned -=3D 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 retadd= r) tb_phys_invalidate(tb->orig_tb, -1); } tcg_tb_remove(tb); + tb_destroy(tb); } =20 /* TODO: If env->pc !=3D 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); =20 void tcg_region_init(void); +void tb_destroy(TranslationBlock *tb); void tcg_region_reset_all(void); =20 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; } =20 +static gboolean tcg_region_tree_traverse(gpointer k, gpointer v, gpointer = data) +{ + TranslationBlock *tb =3D 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 =3D 0; i < region.n; i++) { struct tcg_region_tree *rt =3D region_trees + i * tree_size; =20 + 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); --=20 2.17.1 From nobody Thu May 9 14:30:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591733588; cv=none; d=zohomail.com; s=zohoarc; b=T4udz4ttF4rFDaPwSDiWaoUrqqIx+bY++sFN+h+mkQyCeC+n0KDrRtTp5Db/Qq4x6PhNvlxZb1t8mEtLPq1ckTmcJB89NlBjYK6Vj5RQdHBDi/RATt5ZNR/fdYHE3WAVSOn/ZnetXwXI3jRwy/MJRBakeI+IS1RriiDee4krChA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591733588; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1NsThI0eMK49RH+R+oR0Ud3TTjxqLqaksL0ZDGz/oqg=; b=MYpxEad8XUsX2D2EpNSStKLoU4jfUsf4qdjm/6nXqe/GhQnKb0gcyFZ7Gh2BNUX5dElw/1ZjB9mUk31nS82GSU85XsXTXSPJAgBngSQ8ad3L30GEuzgmZsgKcBhqCQp2MhC9by4dCPfbNocP3+gXfy6+cIxM4BzT+F+2CYoO2C8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591733588550196.64041564990055; Tue, 9 Jun 2020 13:13:08 -0700 (PDT) Received: from localhost ([::1]:39116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikcN-0003Ym-8E for importer@patchew.org; Tue, 09 Jun 2020 16:13:07 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9e --- 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 =3D atomic_cmpxchg(lp, NULL, pd); if (unlikely(existing)) { +#ifndef CONFIG_USER_ONLY + { + int i; + + for (i =3D 0; i < V_L2_SIZE; i++) { + qemu_spin_destroy(&pd[i].lock); + } + } +#endif g_free(pd); pd =3D existing; } --=20 2.17.1 From nobody Thu May 9 14:30:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591733483; cv=none; d=zohomail.com; s=zohoarc; b=ZDNueiim4GYg1zhRXxQ+HoSHRKVExudzkxQyUsDQyx5U1B0/CHrpjiUy24g+CsiW29qy9VA7Rp8dGrILA3rJRr2khlYWvMYulIfC2h7Py5EO8S7JOKXyasGBH3+FS+umxUhIm/fZjWYK9/jBeXuviBpW59Z82uXZVU6gmsCAd88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591733483; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AYdOaJYxtk+d/I+Jwq+9vEcr8Iz8aXatF1CrO9YlEDI=; b=Azhx2vK6cesJQtheLu3jJD+T0wIAKUBdVF6itzFEJPPk6inAN8yNnD5Scsw88/XEDnqxoI/s+neEqZw4SS2n/tbeCww/aKpZhVE2yjpEX0u9gKEEPsdyWQEU3od0+i7KpGNmyZ258W9O1BUhoELwggjSJQEPNar6BK8Kz9D0R7g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591733483258926.3460649293663; Tue, 9 Jun 2020 13:11:23 -0700 (PDT) Received: from localhost ([::1]:33350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikag-00016V-2M for importer@patchew.org; Tue, 09 Jun 2020 16:11:22 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley Reviewed-by: Alex Benn=C3=A9e --- 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); =20 +#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 } =20 -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 +} =20 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 } =20 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 =3D __sync_lock_test_and_set(&spin->value, true); +#ifdef CONFIG_TSAN + unsigned flags =3D __tsan_mutex_try_lock; + flags |=3D busy ? __tsan_mutex_try_lock_failed : 0; + __tsan_mutex_post_lock(spin, flags, 0); +#endif + return busy; } =20 static inline bool qemu_spin_locked(QemuSpin *spin) @@ -239,7 +266,13 @@ static inline bool qemu_spin_locked(QemuSpin *spin) =20 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 } =20 struct QemuLockCnt { --=20 2.17.1 From nobody Thu May 9 14:30:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591733603; cv=none; d=zohomail.com; s=zohoarc; b=nngdWYPt7lhzM1+I8ovig4NVDjUSgyHwcRwd2uulZsorBR1ot1VxVS/dY+eug0SdzkCThO6mBDLRZ+3LKKryLm5D8mFfHwCGk6oE8iOUDh4heyZ7M1PPE6p+Ad23sNijtQLvcDN5xR/KF1PaaTDPOIvR5eO5mN2J+e37glx1Rc0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591733603; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=a1IujnwDzWygiMOVADIbNYVV1mCmC+OLrxpPE5Le/ts=; b=Lg84ueSHrL93l+c8cBHV05QrZOwN7lgKS7M6Mxdl5D7URXqDopWECyuFO+uPHrSGu6i+Y9KkmJ4ZVI/du82f4U7fnIufzuE3LAj/Hsw4fRiTAiUPtfs7ZRihljU/yHUg1y9ee278yxJsXRFZrI0EhrIeabNDK3TFolb5A/RRXiU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15917336032681014.4954191674875; Tue, 9 Jun 2020 13:13:23 -0700 (PDT) Received: from localhost ([::1]:40052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikcc-0003vx-36 for importer@patchew.org; Tue, 09 Jun 2020 16:13:22 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::643; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x643.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , robert.foley@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , cota@braap.org, peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=3D1 Also added the TSAN suppresion file to disable certain cases of TSAN warnings. Cc: Fam Zheng Cc: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Robert Foley Reviewed-by: Alex Benn=C3=A9e --- 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/dock= erfiles/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=3Dnoninteractive 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/inc= lude/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=3D"/tmp/qemu-test/build/tsan" + mkdir -p $tsan_log_dir > /dev/null || true + EXTRA_CONFIGURE_OPTS=3D"${EXTRA_CONFIGURE_OPTS} --enable-tsan \ + --cc=3Dclang-10 --cxx=3Dclang++-10 \ + --disable-werror --extra-cflags=3D-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=3D66 below. + tsan_opts=3D"suppressions=3D/tmp/qemu-test/src/tests/tsan/suppressions= .tsan\ + detect_deadlocks=3Dfalse history_size=3D7\ + halt_on_error=3D0 exitcode=3D0 verbose=3D5\ + log_path=3D$tsan_log_dir/tsan_warning" + export TSAN_OPTIONS=3D"$tsan_opts" +} + +cd "$BUILD_DIR" + +TARGET_LIST=3D${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=3D-fsanitize-blacklist=3D/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 --=20 2.17.1 From nobody Thu May 9 14:30:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591733958; cv=none; d=zohomail.com; s=zohoarc; b=lO2TTW1sZn3mv6il/k1/ik6qqG8SdeuaAPq6oAWj1p/hsHCfaYyXSQYKAvYPizhdZH5a1n/rFNzXuSZ8sPodHIH0/BfZSwOJ/8Y2ajOOfcGcjt1Ty0UlBAsZmdZG+39ii3tHdpN2+JNsFICfW5V0m85Bs6R+ZBfSPQerMdn/OR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591733958; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Z+OFj29yCFbAWNlzpwiIPBHhzK7hPpPDuoaMSZsMcbg=; b=MRLa3QDyZzwGm3siuH2uR4Q9+gTG7zc/I/kf4e5EeAE7/66o92vypXnxRJE42u/7r43dQP56azax+d+SzO99BKByltVQfQr+ZIqg7Z8Ex1NIWOOC/hhtOqFzToz8N7eGu5Fte5Trie5Zpo9cws3I8s9Jor7DOjyP9SS0PS6vZxQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159173395816755.28513990338058; Tue, 9 Jun 2020 13:19:18 -0700 (PDT) Received: from localhost ([::1]:56198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikiK-0002Fn-Vf for importer@patchew.org; Tue, 09 Jun 2020 16:19:17 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9e --- 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 late= r. + * 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 R= EADS. + * This has the effect of disabling race detection for this section of cod= e. + */ +#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 --=20 2.17.1 From nobody Thu May 9 14:30:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591734030; cv=none; d=zohomail.com; s=zohoarc; b=Dn2sA72CHmsveirMx5NLg/gK2Dk1nY2QJPRTLAqoB+CMzKRDn4Fg07Fl1KVYjSYmTRJuQ14oe6y8v9H82UftRAKndBoBGtizFaLlZd9bi+ad8unRB2TBz+AI9j4GSUsDhSUode4U/KBDz7DzwO5G2FqOdtFdPsf6uiM8Xfxgius= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591734030; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=bZmmE8g6bACENWl1LtFwmXs+x0B5ALCEi1t1qd6zEd8=; b=bSHr6BYARr+cxC1aU9RNhVRSWegfMlqOu3VFaTMPBwUyyJItzhZYEDSJU+t/bO2DQscQj1apfBysxVX0JnurhYf4UgAVd0j1Gq45JqQSp+YovUQ2NrbjvoBLa5xr93JrthJgp7jyMZd9CMeXoyjBPI5De5GsBuCSvK2AQuLROiw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591734030418859.8406603723432; Tue, 9 Jun 2020 13:20:30 -0700 (PDT) Received: from localhost ([::1]:58370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikjU-0003AZ-TX for importer@patchew.org; Tue, 09 Jun 2020 16:20:28 -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) 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) 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) 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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This allows us to see the name of the thread in tsan warning reports such as this: Thread T7 'CPU 1/TCG' (tid=3D24317, 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" =20 static bool name_threads; =20 @@ -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); --=20 2.17.1 From nobody Thu May 9 14:30:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591734104; cv=none; d=zohomail.com; s=zohoarc; b=XfcXY9JEJg8LJfDp9/uERZq8nzGnMWsLv48axfu2eNNVPTJ8qOaCGGcyMEwRx/XZMwk1ziG5bZ7VONrJQChnZ0zzvW9OPQFwgDE9gSL4XBQ3i3WfiLdyrA9rBJrUNXFzY1nlSTQAmmcSvUpZDZ+95sHp7HghJjSEPFkTHTLHGl0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591734104; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zkAx8xWtCWhcEMmU8jAnkCrKBrfEu7h9Ojxrn77WllE=; b=GC+TqRUNNjUf9WFsx1esNxrGEUvdiMr+aVDqboplWcm4sBmpAILhH6872Ps0lpalI65x/SWOwuoKm5jvUgNmz9N40lRyggJxABw/iNFis0WkcU1EEAduLSjwWt38i9axrpzEwLjv6HpobhRMEmXqFH2cwquhYyFK/6MG9XgRyco= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591734103994858.2450586535507; Tue, 9 Jun 2020 13:21:43 -0700 (PDT) Received: from localhost ([::1]:60550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jikkg-0004Dr-Gg for importer@patchew.org; Tue, 09 Jun 2020 16:21:42 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9e --- 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 frequen= tly used ones are: * ``DEBUG=3D1``: enables debug. See the previous "Debugging a Docker test failure" section. =20 +Thread Sanitizer +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Thread Sanitizer (TSan) is a tool which can detect data races. QEMU suppo= rts +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=3D1 to allow launching the test from inside the d= ocker, +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=3Dclang-10 --cxx=3Dclang++-10 \ + --disable-werror --extra-cflags=3D"-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=3Dsuppressions=3D/tests/tsan/suppressi= ons.tsan \ + detect_deadlocks=3Dfalse history_size=3D7 exitcode= =3D0 \ + log_path=3D/tsan/tsan_warning + +The above exitcode=3D0 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=3D6= 6. + +TSan Suppressions +----------------- +Keep in mind that for any data race warning, although there might be a dat= a race +detected by TSan, there might be no actual bug here. TSan provides several +different mechanisms for suppressing warnings. In general it is recommend= ed +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 ru= ntime. +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=3D-fsanitize-blacklist=3D/tests/tsan/blacklist.t= san" + +More information on the file format can be found here under "Blacklist For= mat": + +https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags + +TSan Annotations +---------------- +include/qemu/tsan.h defines annotations. See this file for more descripti= ons +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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 --=20 2.17.1 From nobody Thu May 9 14:30:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591733689; cv=none; d=zohomail.com; s=zohoarc; b=DdVzvnm04uy44q7rjCnkEFyHapwVpjJbJcEw4N0ltx8XFGl6TqKKBYITJo7yAePCf+DsuyKP0lN78/Uxjqx4rkJAQk//u1jhnPdwWltzYpp9CGPDrgVhCilz4Ng/TpuWf/t4/tRI0/JN+bnUljENzJxnmZNgZIfBDCGRbVVoVeg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591733689; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=cHjY5HzznfKw8VbLxbBOVqurhqy9xCUukR85p1gtXTQ=; b=NEO0mhedRzMTpcwvHYkvZVZYYNUGpL6p6up1FXLKwZMiv0agyyjjxB3zSaRlpCVVj9fmnlCZePlxgWldWnmDKb+NuI9Vw5Xd5cU1CB/sCcH8JdtkGtQK8yQ60mVWNuoTnB87bLxsWvdch7ixS4cVDVPilZ88GZRIg9s4MU7A6Ng= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591733689274821.5251552561489; Tue, 9 Jun 2020 13:14:49 -0700 (PDT) Received: from localhost ([::1]:45280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jike0-00064s-3c for importer@patchew.org; Tue, 09 Jun 2020 16:14:48 -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) 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) 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) 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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 :=3D $(subst -softmmu.mak,,$(notdir \ =20 check-unit-y +=3D tests/check-qdict$(EXESUF) check-unit-y +=3D tests/check-block-qdict$(EXESUF) -check-unit-$(CONFIG_SOFTMMU) +=3D tests/test-char$(EXESUF) check-unit-y +=3D tests/check-qnum$(EXESUF) check-unit-y +=3D tests/check-qstring$(EXESUF) check-unit-y +=3D tests/check-qlist$(EXESUF) @@ -108,7 +107,6 @@ check-unit-y +=3D tests/test-qht$(EXESUF) check-unit-y +=3D tests/test-qht-par$(EXESUF) check-unit-y +=3D tests/test-bitops$(EXESUF) check-unit-y +=3D tests/test-bitcnt$(EXESUF) -check-unit-$(CONFIG_SOFTMMU) +=3D tests/test-qdev-global-props$(EXESUF) check-unit-y +=3D tests/check-qom-interface$(EXESUF) check-unit-y +=3D tests/check-qom-proplist$(EXESUF) check-unit-y +=3D tests/test-qemu-opts$(EXESUF) @@ -123,9 +121,16 @@ check-speed-$(CONFIG_BLOCK) +=3D tests/benchmark-crypt= o-cipher$(EXESUF) check-unit-$(CONFIG_BLOCK) +=3D tests/test-crypto-secret$(EXESUF) check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_GNUTLS)) +=3D tests/test-c= rypto-tlscredsx509$(EXESUF) check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_GNUTLS)) +=3D tests/test-c= rypto-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) +=3D tests/test-char$(EXESUF) +check-unit-$(CONFIG_SOFTMMU) +=3D tests/test-qdev-global-props$(EXESUF) ifneq (,$(findstring qemu-ga,$(TOOLS))) check-unit-$(call land,$(CONFIG_LINUX),$(CONFIG_VIRTIO_SERIAL)) +=3D tests= /test-qga$(EXESUF) endif +endif check-unit-$(CONFIG_SOFTMMU) +=3D tests/test-timed-average$(EXESUF) check-unit-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_INOTIFY1)) +=3D tests/te= st-util-filemonitor$(EXESUF) check-unit-$(CONFIG_SOFTMMU) +=3D 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 =20 TARGETS=3D$(patsubst %-softmmu,%, $(filter %-softmmu,$(TARGET_DIRS))) +QTEST_TARGETS =3D +# 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 =3D $(TARGETS) check-qtest-y=3D$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)-y:%= =3Dtests/qtest/%$(EXESUF))) check-qtest-y +=3D $(check-qtest-generic-y:%=3Dtests/qtest/%$(EXESUF)) -else -QTEST_TARGETS =3D +endif endif =20 qtest-obj-y =3D tests/qtest/libqtest.o $(test-util-obj-y) --=20 2.17.1