From nobody Tue Feb 10 10:54:38 2026 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=1591378768; cv=none; d=zohomail.com; s=zohoarc; b=JjT4Y/C6d6hN0q+S/SbNz8AoIm4RfTL+oVIsuRAqmo83pL2+iI5yMfAoh2NuARfcwU0h6nntj7kh8e9aYRIEtLRLEb9LfiAECO3ALbY38i+CemZfDuXLX3WTVR8FkSBNkDCnxrs+1nykTBEhZgGf4U14vWNaOznfSodLUk6MkCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591378768; 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=XzO4d9NfxHhnWYA5ypuQ0LUhD/s+5379iGqovYIf/8k=; b=jeaUW0S55stzaudOlAnla66jaUv40cHRbKU/WNwb+9znF67VqG3yqchGnxQrJr1kfFkTBYg9K+J2TrQHBEBQtuDNfC6FQbPCoh4T+5sxj7jBIRYxQmB+SmAwfuQkeNU+wXVIaMIxoXK2jHDTnYg0pzf3Or+R7xyQlczWhpCeKCo= 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 1591378768709374.03926576085985; Fri, 5 Jun 2020 10:39:28 -0700 (PDT) Received: from localhost ([::1]:35190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGJS-0007DV-FR for importer@patchew.org; Fri, 05 Jun 2020 13:39:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGI4-0004Im-Lw for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:38:00 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:40782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGI3-00041W-Hk for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:38:00 -0400 Received: by mail-pf1-x442.google.com with SMTP id s23so3961015pfh.7 for ; Fri, 05 Jun 2020 10:37:59 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XzO4d9NfxHhnWYA5ypuQ0LUhD/s+5379iGqovYIf/8k=; b=y52sj9Axg0xBsiHEVC44k/0Dm4IwyON9v7OpxX7YRbq8zlTRFJRXav3d11iFUrOQ38 oOBaP2GKKeHWzmUc8MtXZg+DoL5OG2sFCztWiYy/qwAl4VkgRMECZMZJjzPUjsnysh+R eWZzBcDBtWHePCEdQXowVjdKpzNJxMnO2wRSZEqsCfG4lX6SPn3HbCej/RbwJyiYCjPT n6beifZUWT5BIgt/7W0c0FjsfUiPHMYrGOZTIw58hjWgxjvT4uxGApLneL+f0O1NezGG /LV3+jeU3Sjl7UeOjqA28YslsxtA5DfvV9GOBkId5O3/V9/9/uxkMslcnsmJRE4YOAtT yjzg== 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=XzO4d9NfxHhnWYA5ypuQ0LUhD/s+5379iGqovYIf/8k=; b=MhOuAcxG0oLIHPttFrV8kX1I2yyNTDPQOD0NE4fmPOfV1185DAk5r+t8+SdFQVKeqC xByKDeSak2mLExhhcRcRno3ortlmMb28+g0yyXsiScWUJwagXf8TvZo4/dW2YKuEAbEb NpX3Vicf3T570z27FtyBq0vHJtFBrKbG+jJILuOaDkf9chViN/3yj9mlGYFQ5gBkMj29 jwoTMLWvEdQon66mkzhYU5lQsnAAyrcQog2r0D3ruWHuYlAMflAOXdeLCxEXMTQpADcC gILqOMymxR9twkePsunNUaKpdw4iAjPvR40senRG0/ZKoUwZ63IHYYw2F40WBh5fxxzs p/+A== X-Gm-Message-State: AOAM532Mn/mJQy5Ycp05T4q+6q+RXeV112K/ZkBID8RmDZQ+g2jb8Hvd M6tLLSk+q885aFFwnBcJKx+Gj99rVuGHDA== X-Google-Smtp-Source: ABdhPJyzBIKpLrkvpIklD4VG4YKxwyJLORDnH0Q13tLBs3zPCtE/gFZgaDRa3xrsvSR33dhmMVbGzQ== X-Received: by 2002:aa7:9a5a:: with SMTP id x26mr10972302pfj.307.1591378677823; Fri, 05 Jun 2020 10:37:57 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 12/13] docs: Added details on TSan to testing.rst Date: Fri, 5 Jun 2020 13:34:21 -0400 Message-Id: <20200605173422.1490-13-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-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::442; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+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" 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