From patchwork Fri May 29 13:23:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11578651 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3EB5F912 for ; Fri, 29 May 2020 13:25:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 04BB220721 for ; Fri, 29 May 2020 13:25:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="VF7LL2Fu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 04BB220721 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef0o-00071g-34 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 May 2020 09:25:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeeyz-00042y-IN for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:33 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:45867) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeeyx-0003TD-Sb for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:33 -0400 Received: by mail-pl1-x634.google.com with SMTP id y11so1149886plt.12 for ; Fri, 29 May 2020 06:23:31 -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; bh=iW7IdIzsC9AFT7A/HgICb/ikiPzXalvsYjSvDjiUN+g=; b=VF7LL2Fu+vrqD6kGEFNiPgyrztTNHkQ+jCM9MrIJ+qhpaVUZJMQjXS0r/UqSqF3Mpi wufwEz/8zoO/QP22/Y8qMI0+l3HDlVwaq5BornSob7kOsgXc5pIFZUn5AKhswCUhAXLh Wvrs0gHIH1ZwVlBiGvnxaldhZn+h1K6nFRikGLXwVtcBJ8b6l662tjBQ9PDUOMHzItc7 KUzTJoMb2wLagDyxwFm2Tv6RD+matAUG52/Sl3ABTTM4SKRIHiTHUmAdmqbAWAy0wl/U 34roJzTwmGGSTgTu/SLHbUPps4JHQY05fo5gCm6zIkpXB3JYwO1vNGkVTx6kiYfGt2mn 9xQQ== 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; bh=iW7IdIzsC9AFT7A/HgICb/ikiPzXalvsYjSvDjiUN+g=; b=ue2YQkWvz6ynqtgOgJkjNi61wOM9AbnKBlyh/d7n4npGEY52VzSt+PR35tpedND89O DbVqCzFr4VK+GCeB4jzvyhY2Sley79RoAyvDEjK7ui9gqFf+m5b3r6snnXKPvHiBckfa 0bBxyjtgnOGwz7N+hR6eIrd/+76pmcdVi5nNkjQyN6Xd+7m6QUCuQmoAAvlxffYw3TWA uXupmtm0ZG8uKioXuxS7f06niRpGRw70C3khMJcnp//q9+E+bOHj6pEm2h1NBrFzdyK1 VC630aV3LPrjRdjEtRyxUNn75kXtp+L8/x5DZKT5RklYUOLu/HM/mJE6/Do4JJQQzswH e5Lg== X-Gm-Message-State: AOAM531aB/H62yDyURHyAVwnYtObKrl8LnXlz2FwMIaUYmwEcRtdnF4G a4G7OnscQctA+pnB3T5Ea2lPGdnEMCsWHg== X-Google-Smtp-Source: ABdhPJwo4xE3TvP97jbm78UJCvE8EMuxYTCPmgFic1Ddy1nkaIL5wiocuryyc+87pyUREK+kpjoEMw== X-Received: by 2002:a17:90b:4d10:: with SMTP id mw16mr9331139pjb.143.1590758609648; Fri, 29 May 2020 06:23:29 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id e13sm1998686pfd.10.2020.05.29.06.23.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:23:28 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 01/12] configure: add --enable-tsan flag + fiber annotations for coroutine-ucontext Date: Fri, 29 May 2020 09:23:31 -0400 Message-Id: <20200529132341.755-1-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x634.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, cota@braap.org, Stefan Hajnoczi , Lingfeng Yang , peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Lingfeng Yang We tried running QEMU under tsan in 2016, but tsan's lack of support for longjmp-based fibers was a blocker: https://groups.google.com/forum/#!topic/thread-sanitizer/se0YuzfWazw Fortunately, thread sanitizer gained fiber support in early 2019: https://reviews.llvm.org/D54889 This patch brings tsan support upstream by importing the patch that annotated QEMU's coroutines as tsan fibers in Android's QEMU fork: https://android-review.googlesource.com/c/platform/external/qemu/+/844675 Tested with '--enable-tsan --cc=clang-9 --cxx=clang++-9 --disable-werror' configure flags. Signed-off-by: Lingfeng Yang Signed-off-by: Emilio G. Cota [cota: minor modifications + configure changes] Signed-off-by: Robert Foley [RF: Error out in configure if tsan not available, fix checkpatch warnings] --- configure | 41 +++++++++++++++++ util/coroutine-ucontext.c | 97 +++++++++++++++++++++++++++++++++++---- 2 files changed, 129 insertions(+), 9 deletions(-) diff --git a/configure b/configure index b969dee675..c18efae65e 100755 --- a/configure +++ b/configure @@ -395,6 +395,7 @@ gprof="no" debug_tcg="no" debug="no" sanitizers="no" +tsan="no" fortify_source="" strip_opt="yes" tcg_interpreter="no" @@ -1150,6 +1151,10 @@ for opt do ;; --disable-sanitizers) sanitizers="no" ;; + --enable-tsan) tsan="yes" + ;; + --disable-tsan) tsan="no" + ;; --enable-sparse) sparse="yes" ;; --disable-sparse) sparse="no" @@ -1750,6 +1755,7 @@ Advanced options (experts only): --with-pkgversion=VERS use specified string as sub-version of the package --enable-debug enable common debug build options --enable-sanitizers enable default sanitizers + --enable-tsan enable thread sanitizer --disable-strip disable stripping binaries --disable-werror disable compilation abort on warning --disable-stack-protector disable compiler-provided stack protection @@ -6192,6 +6198,27 @@ if test "$fuzzing" = "yes" ; then fi fi +# Thread sanitizer is, for now, much noisier than the other sanitizers; +# keep it separate until that is not the case. +have_tsan=no +have_tsan_iface_fiber=no +if test "$tsan" = "yes" ; then + write_c_skeleton + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then + have_tsan=yes + fi + cat > $TMPC << EOF +#include +int main(void) { + __tsan_create_fiber(0); + return 0; +} +EOF + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then + have_tsan_iface_fiber=yes + fi +fi + ########################################## # check for libpmem @@ -6293,6 +6320,16 @@ if test "$have_asan" = "yes"; then "Without code annotation, the report may be inferior." fi fi +if test "$have_tsan" = "yes" ; then + if test "$have_tsan_iface_fiber" = "yes" ; then + QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS" + QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS" + else + error_exit "Cannot enable TSAN due to missing fiber annotation interface." + fi +elif test "$tsan" = "yes" ; then + error_exit "Cannot enable TSAN due to missing sanitize thread interface." +fi if test "$have_ubsan" = "yes"; then QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS" QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS" @@ -7382,6 +7419,10 @@ if test "$have_asan_iface_fiber" = "yes" ; then echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak fi +if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then + echo "CONFIG_TSAN=y" >> $config_host_mak +fi + if test "$has_environ" = "yes" ; then echo "CONFIG_HAS_ENVIRON=y" >> $config_host_mak fi diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c index bd593e61bc..a3dc78e67a 100644 --- a/util/coroutine-ucontext.c +++ b/util/coroutine-ucontext.c @@ -37,18 +37,33 @@ #endif #endif +#ifdef CONFIG_TSAN +#include +#endif + typedef struct { Coroutine base; void *stack; size_t stack_size; sigjmp_buf env; + void *tsan_co_fiber; + void *tsan_caller_fiber; + #ifdef CONFIG_VALGRIND_H unsigned int valgrind_stack_id; #endif } CoroutineUContext; +#define UC_DEBUG 0 +#if UC_DEBUG && defined(CONFIG_TSAN) +#define UC_TRACE(fmt, ...) fprintf(stderr, "%s:%d:%p " fmt "\n", \ + __func__, __LINE__, __tsan_get_current_fiber(), ##__VA_ARGS__); +#else +#define UC_TRACE(fmt, ...) +#endif + /** * Per-thread coroutine bookkeeping */ @@ -65,7 +80,20 @@ union cc_arg { int i[2]; }; -static void finish_switch_fiber(void *fake_stack_save) +/* QEMU_ALWAYS_INLINE only does so if __OPTIMIZE__, so we cannot use it. */ +static inline __attribute__((always_inline)) +void on_new_fiber(CoroutineUContext *co) +{ +#ifdef CONFIG_TSAN + co->tsan_co_fiber = __tsan_create_fiber(0); /* flags: sync on switch */ + co->tsan_caller_fiber = __tsan_get_current_fiber(); + UC_TRACE("Create new TSAN co fiber. co: %p co fiber: %p caller fiber: %p ", + co, co->tsan_co_fiber, co->tsan_caller_fiber); +#endif +} + +static inline __attribute__((always_inline)) +void finish_switch_fiber(void *fake_stack_save) { #ifdef CONFIG_ASAN const void *bottom_old; @@ -78,18 +106,40 @@ static void finish_switch_fiber(void *fake_stack_save) leader.stack_size = size_old; } #endif +#ifdef CONFIG_TSAN + if (fake_stack_save) { + __tsan_release(fake_stack_save); + __tsan_switch_to_fiber(fake_stack_save, 0); /* 0=synchronize */ + } +#endif } -static void start_switch_fiber(void **fake_stack_save, - const void *bottom, size_t size) +static inline __attribute__((always_inline)) void start_switch_fiber( + CoroutineAction action, void **fake_stack_save, + const void *bottom, size_t size, void *new_fiber) { #ifdef CONFIG_ASAN - __sanitizer_start_switch_fiber(fake_stack_save, bottom, size); + if (action == COROUTINE_TERMINATE) { + __sanitizer_start_switch_fiber( + action == COROUTINE_TERMINATE ? NULL : fake_stack_save, + bottom, size); + } +#endif +#ifdef CONFIG_TSAN + void *curr_fiber = + __tsan_get_current_fiber(); + __tsan_acquire(curr_fiber); + + UC_TRACE("Current fiber: %p.", curr_fiber); + *fake_stack_save = curr_fiber; + UC_TRACE("Switch to fiber %p", new_fiber); + __tsan_switch_to_fiber(new_fiber, 0); /* 0=synchronize */ #endif } static void coroutine_trampoline(int i0, int i1) { + UC_TRACE("Start trampoline"); union cc_arg arg; CoroutineUContext *self; Coroutine *co; @@ -104,21 +154,34 @@ static void coroutine_trampoline(int i0, int i1) /* Initialize longjmp environment and switch back the caller */ if (!sigsetjmp(self->env, 0)) { - start_switch_fiber(&fake_stack_save, - leader.stack, leader.stack_size); + UC_TRACE("Current fiber: %p. Set co %p to env 0x%lx", + __tsan_get_current_fiber(), self, (unsigned long)self->env); + start_switch_fiber( + COROUTINE_YIELD, + &fake_stack_save, + leader.stack, + leader.stack_size, + self->tsan_caller_fiber); + UC_TRACE("Jump to co %p caller fiber %p env 0x%lx", + co, self->tsan_caller_fiber, *(unsigned long *)co->entry_arg); siglongjmp(*(sigjmp_buf *)co->entry_arg, 1); } + UC_TRACE("After first siglongjmp"); + finish_switch_fiber(fake_stack_save); while (true) { co->entry(co->entry_arg); + UC_TRACE("switch from co %p to caller co %p fiber %p\n", + co, co->caller, self->tsan_caller_fiber); qemu_coroutine_switch(co, co->caller, COROUTINE_TERMINATE); } } Coroutine *qemu_coroutine_new(void) { + UC_TRACE("Start new coroutine"); CoroutineUContext *co; ucontext_t old_uc, uc; sigjmp_buf old_env; @@ -154,12 +217,16 @@ Coroutine *qemu_coroutine_new(void) arg.p = co; + on_new_fiber(co); makecontext(&uc, (void (*)(void))coroutine_trampoline, 2, arg.i[0], arg.i[1]); /* swapcontext() in, siglongjmp() back out */ if (!sigsetjmp(old_env, 0)) { - start_switch_fiber(&fake_stack_save, co->stack, co->stack_size); + start_switch_fiber( + COROUTINE_YIELD, + &fake_stack_save, + co->stack, co->stack_size, co->tsan_co_fiber); swapcontext(&old_uc, &uc); } @@ -185,6 +252,7 @@ static inline void valgrind_stack_deregister(CoroutineUContext *co) void qemu_coroutine_delete(Coroutine *co_) { + UC_TRACE("Nuking co %p from orbit", co_); CoroutineUContext *co = DO_UPCAST(CoroutineUContext, base, co_); #ifdef CONFIG_VALGRIND_H @@ -209,6 +277,10 @@ qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, { CoroutineUContext *from = DO_UPCAST(CoroutineUContext, base, from_); CoroutineUContext *to = DO_UPCAST(CoroutineUContext, base, to_); + UC_TRACE("from to: %p %p uc: %p %p. fibers: %p %p caller fibers: %p %p\n", + from_, to_, from, to, + from->tsan_co_fiber, to->tsan_co_fiber, + from->tsan_caller_fiber, to->tsan_caller_fiber); int ret; void *fake_stack_save = NULL; @@ -216,8 +288,8 @@ qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, ret = sigsetjmp(from->env, 0); if (ret == 0) { - start_switch_fiber(action == COROUTINE_TERMINATE ? - NULL : &fake_stack_save, to->stack, to->stack_size); + start_switch_fiber(action, &fake_stack_save, + to->stack, to->stack_size, to->tsan_co_fiber); siglongjmp(to->env, action); } @@ -231,6 +303,13 @@ Coroutine *qemu_coroutine_self(void) if (!current) { current = &leader.base; } +#ifdef CONFIG_TSAN + if (!leader.tsan_co_fiber) { + leader.tsan_co_fiber = __tsan_get_current_fiber(); + UC_TRACE("For co %p set leader co fiber to %p", + current, leader.tsan_co_fiber); + } +#endif return current; } From patchwork Fri May 29 13:23:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11578645 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BECC4912 for ; Fri, 29 May 2020 13:24:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 948B620721 for ; Fri, 29 May 2020 13:24:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pxDAMQAJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 948B620721 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:51610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeezw-0005om-Nn for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 May 2020 09:24:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeez6-0004FE-Pj for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:40 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:37868) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeez5-0003YQ-KD for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:40 -0400 Received: by mail-pg1-x542.google.com with SMTP id d10so1486457pgn.4 for ; Fri, 29 May 2020 06:23: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=RseCa26F61nDIy9E0oS7cXPax4VaGb6c+jHKYyFKj1U=; b=pxDAMQAJ5dYvpU2v+D/M4UDHrAs8jItoUXgA46fx67QwcXWqxXXzcYBrzxnfJv0Ryq AQp+O8OwVXGjre5JEjlFay6wEz0R5EUY3a3Sd11JWosxFxl2ym51mZ2s/QtiBIZRsNIn IxqriWUvfWWdkFiQAn8lmENM1yJwc3DG4EXhISovJiqT3rlKvfDd73tFYcbIelP3Uapg VJxXtADqD0Hlyoxq26NzFZvs4BSgIgnRa+l9iKlL9MBlbbS1LLwHIn7yk/SD7TCdubNd x+w6HLNOkH2tHudSYc8Njicct3CDa92nviHByBdy8+5f1TLPfk8wPD3EEbyGOZ7q3n1K yrdw== 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=RseCa26F61nDIy9E0oS7cXPax4VaGb6c+jHKYyFKj1U=; b=FI7y3BoQmbeQOC/ESuudf848KMpPYQpaMNliIfedGS2u7qRff7NIRk8y1LWx6r8n7C jh+pdiZ9OyjyzNoKeK8UYY+KwyfBaTbxHl20q5rqfDya6RxDdfe3Zf918fCH1h6S3XEI 4Yx6idLEnRqNjUqN1aV+O3iTaMHnim1o9KcijA6NtXB9kt7csmdawL7J4+1PW6ex5OW6 64OUbtg1rt+ZLLiU8TcMT/wsR4jyx1zwCBvW11AM9tXp/2MuwqbQf6ijGcl9LH1oE1Fr EKlGHO5SjbphwhVDSRQ3JK+8eL7AMNIbDZp6JAip5rk6tfc2BHlQryvtVWulB9QSy4JO CGhQ== X-Gm-Message-State: AOAM530QMFJ60ShCF+ad94DsT9bswCfWPyYB7XYuXjyKTIoEymaY7Ttu zcpcQxQME5E2N1c1DKFOwYAEcGuKm6LNew== X-Google-Smtp-Source: ABdhPJwXP5tMLW8pc0UK6wNO/w7yWh35dNhAK4CHQASMiJBFpFjA5klkuVh+NJ8DjiSEnWkz46mqog== X-Received: by 2002:aa7:9515:: with SMTP id b21mr8383189pfp.282.1590758617773; Fri, 29 May 2020 06:23:37 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id e13sm1998686pfd.10.2020.05.29.06.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:23:37 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 02/12] cpu: convert queued work to a QSIMPLEQ Date: Fri, 29 May 2020 09:23:32 -0400 Message-Id: <20200529132341.755-2-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529132341.755-1-robert.foley@linaro.org> References: <20200529132341.755-1-robert.foley@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::542; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x542.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, Eduardo Habkost , cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" We convert queued work to a QSIMPLEQ, instead of open-coding it. While at it, make sure that all accesses to the list are performed while holding the list's lock. Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée 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 55d5df8923..210fc7fc39 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -97,7 +97,7 @@ void cpu_list_remove(CPUState *cpu) } struct qemu_work_item { - struct qemu_work_item *next; + QSIMPLEQ_ENTRY(qemu_work_item) node; run_on_cpu_func func; run_on_cpu_data data; bool free, exclusive, done; @@ -106,13 +106,7 @@ struct qemu_work_item { static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi) { qemu_mutex_lock(&cpu->work_mutex); - if (cpu->queued_work_first == NULL) { - cpu->queued_work_first = wi; - } else { - cpu->queued_work_last->next = wi; - } - cpu->queued_work_last = wi; - wi->next = NULL; + QSIMPLEQ_INSERT_TAIL(&cpu->work_list, wi, node); wi->done = false; qemu_mutex_unlock(&cpu->work_mutex); @@ -306,17 +300,14 @@ void process_queued_cpu_work(CPUState *cpu) { struct qemu_work_item *wi; - if (cpu->queued_work_first == NULL) { + qemu_mutex_lock(&cpu->work_mutex); + if (QSIMPLEQ_EMPTY(&cpu->work_list)) { + qemu_mutex_unlock(&cpu->work_mutex); return; } - - qemu_mutex_lock(&cpu->work_mutex); - while (cpu->queued_work_first != NULL) { - wi = cpu->queued_work_first; - cpu->queued_work_first = wi->next; - if (!cpu->queued_work_first) { - cpu->queued_work_last = NULL; - } + while (!QSIMPLEQ_EMPTY(&cpu->work_list)) { + wi = QSIMPLEQ_FIRST(&cpu->work_list); + QSIMPLEQ_REMOVE_HEAD(&cpu->work_list, node); qemu_mutex_unlock(&cpu->work_mutex); if (wi->exclusive) { /* Running work items outside the BQL avoids the following deadlock: diff --git a/cpus.c b/cpus.c index 5670c96bcf..af44027549 100644 --- a/cpus.c +++ b/cpus.c @@ -97,9 +97,19 @@ bool cpu_is_stopped(CPUState *cpu) return cpu->stopped || !runstate_is_running(); } +static inline bool cpu_work_list_empty(CPUState *cpu) +{ + bool ret; + + qemu_mutex_lock(&cpu->work_mutex); + ret = QSIMPLEQ_EMPTY(&cpu->work_list); + qemu_mutex_unlock(&cpu->work_mutex); + return ret; +} + static bool cpu_thread_is_idle(CPUState *cpu) { - if (cpu->stop || cpu->queued_work_first) { + if (cpu->stop || !cpu_work_list_empty(cpu)) { return false; } if (cpu_is_stopped(cpu)) { @@ -1498,7 +1508,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) cpu = first_cpu; } - while (cpu && !cpu->queued_work_first && !cpu->exit_request) { + while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) { atomic_mb_set(&tcg_current_rr_cpu, cpu); current_cpu = cpu; diff --git a/hw/core/cpu.c b/hw/core/cpu.c index 5284d384fb..77703d62b7 100644 --- a/hw/core/cpu.c +++ b/hw/core/cpu.c @@ -368,6 +368,7 @@ static void cpu_common_initfn(Object *obj) cpu->nr_threads = 1; qemu_mutex_init(&cpu->work_mutex); + QSIMPLEQ_INIT(&cpu->work_list); QTAILQ_INIT(&cpu->breakpoints); QTAILQ_INIT(&cpu->watchpoints); diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 07f7698155..d78ff1d165 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -331,8 +331,8 @@ struct qemu_work_item; * @opaque: User data. * @mem_io_pc: Host Program Counter at which the memory was accessed. * @kvm_fd: vCPU file descriptor for KVM. - * @work_mutex: Lock to prevent multiple access to queued_work_*. - * @queued_work_first: First asynchronous work pending. + * @work_mutex: Lock to prevent multiple access to @work_list. + * @work_list: List of pending asynchronous work. * @trace_dstate_delayed: Delayed changes to trace_dstate (includes all changes * to @trace_dstate). * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask). @@ -376,7 +376,7 @@ struct CPUState { sigjmp_buf jmp_env; QemuMutex work_mutex; - struct qemu_work_item *queued_work_first, *queued_work_last; + QSIMPLEQ_HEAD(, qemu_work_item) work_list; CPUAddressSpace *cpu_ases; int num_ases; From patchwork Fri May 29 13:23:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11578659 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 676CC912 for ; Fri, 29 May 2020 13:27:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3E70E20721 for ; Fri, 29 May 2020 13:27:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pgjpq77t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E70E20721 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef2l-0002Hs-At for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 May 2020 09:27:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42758) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeez8-0004HM-8L for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:42 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:46975) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeez7-0003Z8-Fp for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:41 -0400 Received: by mail-pl1-x644.google.com with SMTP id i17so1146785pli.13 for ; Fri, 29 May 2020 06:23: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; bh=wgvUXG0Vlnhy8HNXWH/V4PveTdhkLExBdueTuZ9bPNI=; b=pgjpq77tuioHkGAn2W5W6tXnUhQdUcRYYceF/Doy3VPpMBY4vDnZO+aNpPkW8iaPgl DSIbGA9X84HQyIqnKowd6UShgAcCkHkZLVO1BEoC+489tP8lTCr9tX3kMQlNvaVIlql0 NDpC7kfUey8E3JhG2fQ6sUhVhp8gjCyKZ3hzV4N3XNw6lDdd6cddGKW1Fkp9Bu2Eh7/I WeSfHliOUQo1wGlMOlCm8JtoV0yF1D71K5P2Mr+KDPv06QzjPH2EUPEBpPy9+Es7jxtB YecaNz04uHvYJqqEDqo7tFopD4KWpSxjkGHfYkpBo0VgvLbS3ZlU6/8u6TrsVWkuiGGt MVlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wgvUXG0Vlnhy8HNXWH/V4PveTdhkLExBdueTuZ9bPNI=; b=M4wtjsO8tPMHoUKlQf/z7O36CzW5OFPIh2aP+c/9lMTlxC7vidycZPkwXh1cNBQDC2 yyEsBQsuudUOMFteWpPIQZjiwmfGSi9eIMnLWPPjWgY5pgYM55pBxaggbse8jgaHShph MqGynzQKoaaEIw45DsEQnBynh+60FR4a5JilzZfSLsfWFqVBUlGTznOQVACodx0+xU1J LzOdp+XzfiHv/HjnnOPewQJY7jZHyoJxdG628p/J5LwySSceKsYPn3OQW8yWY3SLfHBS nBmK7M7z+8jhps6e0Dwtn/PJxw9TavESGPH2r9cK2AosP5Hmevc4BHsF0IAHH10MASe1 ryxA== X-Gm-Message-State: AOAM530lmwYOSSCjGpT4z6krTgJYLpCMOo+cbVsK2I6fuYDlSi8+pbEc S2QA6nmdKL4IDx8IfBXrooB1EaIG7h+00g== X-Google-Smtp-Source: ABdhPJwtM2Z0wJ7Nip6sWVTLJvDCmNvz2dIQoMYVxj0ZSNEHJGCGH2/hgFrL1OKUBSXqXQFPEU6tWg== X-Received: by 2002:a17:90a:297:: with SMTP id w23mr9833565pja.140.1590758619893; Fri, 29 May 2020 06:23:39 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id e13sm1998686pfd.10.2020.05.29.06.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:23:39 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 03/12] thread: add qemu_spin_destroy Date: Fri, 29 May 2020 09:23:33 -0400 Message-Id: <20200529132341.755-3-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529132341.755-1-robert.foley@linaro.org> References: <20200529132341.755-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::644; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x644.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" It will be used for TSAN annotations. Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley Reviewed-by: Alex Bennée --- include/qemu/thread.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/qemu/thread.h b/include/qemu/thread.h index d22848138e..e50a073889 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -215,6 +215,9 @@ static inline void qemu_spin_init(QemuSpin *spin) __sync_lock_release(&spin->value); } +static inline void qemu_spin_destroy(QemuSpin *spin) +{ } + static inline void qemu_spin_lock(QemuSpin *spin) { while (unlikely(__sync_lock_test_and_set(&spin->value, true))) { From patchwork Fri May 29 13:23:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11578647 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 18B481392 for ; Fri, 29 May 2020 13:24:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E2E7E20721 for ; Fri, 29 May 2020 13:24:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Q1hyMGOh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2E7E20721 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:51990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef00-0005xq-31 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 May 2020 09:24:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeezA-0004Ln-Ng for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:44 -0400 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:52839) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeez9-0003aE-Po for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:44 -0400 Received: by mail-pj1-x1041.google.com with SMTP id k2so1336548pjs.2 for ; Fri, 29 May 2020 06:23: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; bh=aGYJ5nJt/JAH6FWXmjwSAlg0Omv/+y0t2oEMaylOlqc=; b=Q1hyMGOhYqTQVuJ+eJ7rnzgRQjCTe2sbRcVbbB0u0iPqw943v5zjYVpInmgrG/XPne CCyum2Ee7JCWynyPEbNdxUcAzGK4sm9WvjiM4sZqCmLkx6ruFgT0Gt+Z0zS+ksEIJKWP 3xAHoPyj5VJC2da/ouxL1N/tNHZsC0hkAODuqBZilASz66z9T/+O8bmpt8GX84vvQiZT HfuZmhRYu43Br9BUnBTShGeC6bJ8FaZqOl8DuoOt+1EYKrk4RMDRFXH0X4/JEqgT1OQy ca0eoseUmdQTbCKVgiv6nmNoEB9Pmq3DjGpzEdtpfgEq31xKZsSnFtlngxdUB2q8kjw2 3cZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aGYJ5nJt/JAH6FWXmjwSAlg0Omv/+y0t2oEMaylOlqc=; b=didnWF0vF98NNKcNPyNGqCJe0V/BAbwyHIaQwEJARo6BWlprnyz5U9UQB4av91fREK Jas8chaGqQEE1Qk8ZgVzcxVsRLGwCrs+CrMVf2xvhZXx/clhPaDFd0ZqJitLYKxaxhil ZB9hyfDzmbZq1Xsui7SD3g9uxN/cjiGCeRu7cPqsOc9Sxf8TxDlwadIGxFBTLvN/TXAA 9wBj8UagJGrV8NURMHfDH1Zpyupn2NgpSEqeh1Ay2r00SWsUwiJxhOqWcjWSmpp9I0cw k+7fjXV32cxGHOjf6fOuwNfmkJLgsyBV5iohGy4ryFy9A6IruMxvDs0KbQNYU2MpWQWn BAOA== X-Gm-Message-State: AOAM532qPSRPtHRGBsoZHdUwkaBAk5nNX377x9KWh91QvkvCPmrmHGJ/ nPGONy3aBQe6cDP4DgPVeIrStMFWbwkkww== X-Google-Smtp-Source: ABdhPJzMmFxNOyNIS0zK5sxLhaHm1mMavV6paPAnTh6gdbniECjcAbaZ4vSf3gy/ya5Tb7G8Cr4OZA== X-Received: by 2002:a17:90a:f283:: with SMTP id fs3mr9206135pjb.1.1590758621974; Fri, 29 May 2020 06:23:41 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id e13sm1998686pfd.10.2020.05.29.06.23.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:23:41 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 04/12] cputlb: destroy CPUTLB with tlb_destroy Date: Fri, 29 May 2020 09:23:34 -0400 Message-Id: <20200529132341.755-4-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529132341.755-1-robert.foley@linaro.org> References: <20200529132341.755-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::1041; envelope-from=robert.foley@linaro.org; helo=mail-pj1-x1041.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" I was after adding qemu_spin_destroy calls, but while at it I noticed that we are leaking some memory. Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley Reviewed-by: Alex Bennée --- accel/tcg/cputlb.c | 15 +++++++++++++++ exec.c | 1 + include/exec/exec-all.h | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index eb2cf9de5e..1e815357c7 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -270,6 +270,21 @@ void tlb_init(CPUState *cpu) } } +void tlb_destroy(CPUState *cpu) +{ + CPUArchState *env = cpu->env_ptr; + int i; + + qemu_spin_destroy(&env_tlb(env)->c.lock); + for (i = 0; i < NB_MMU_MODES; i++) { + CPUTLBDesc *desc = &env_tlb(env)->d[i]; + CPUTLBDescFast *fast = &env_tlb(env)->f[i]; + + g_free(fast->table); + g_free(desc->iotlb); + } +} + /* flush_all_helper: run fn across all cpus * * If the wait flag is set then the src cpu's helper will be queued as diff --git a/exec.c b/exec.c index 5162f0d12f..da3d60b034 100644 --- a/exec.c +++ b/exec.c @@ -892,6 +892,7 @@ void cpu_exec_unrealizefn(CPUState *cpu) { CPUClass *cc = CPU_GET_CLASS(cpu); + tlb_destroy(cpu); cpu_list_remove(cpu); if (cc->vmsd != NULL) { diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 8792bea07a..3cf88272df 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -124,6 +124,11 @@ void cpu_address_space_init(CPUState *cpu, int asidx, * @cpu: CPU whose TLB should be initialized */ void tlb_init(CPUState *cpu); +/** + * tlb_destroy - destroy a CPU's TLB + * @cpu: CPU whose TLB should be destroyed + */ +void tlb_destroy(CPUState *cpu); /** * tlb_flush_page: * @cpu: CPU whose TLB should be flushed @@ -284,6 +289,9 @@ void tlb_set_page(CPUState *cpu, target_ulong vaddr, static inline void tlb_init(CPUState *cpu) { } +static inline void tlb_destroy(CPUState *cpu) +{ +} static inline void tlb_flush_page(CPUState *cpu, target_ulong addr) { } From patchwork Fri May 29 13:23:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11578649 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BBBB61392 for ; Fri, 29 May 2020 13:24:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 923C520721 for ; Fri, 29 May 2020 13:24:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="uNCgit04" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 923C520721 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:52360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef03-00066r-LY for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 May 2020 09:24:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeezC-0004P7-Ep for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:46 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:52840) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeezB-0003bU-Li for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:46 -0400 Received: by mail-pj1-x1042.google.com with SMTP id k2so1336581pjs.2 for ; Fri, 29 May 2020 06:23: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=kxh2o1V8iXkuJj8JRvzQtcAUGmlKoLZ53V+la2Fi9CI=; b=uNCgit04YDQHmsPJ1hn7g7A32J2F8OcqB7Rbr+VquM/4XMzFKyNMa39Dr/lp9j4azi Fkr347gghRRa916B+smlsQwc/VKEnH0AJLbM0uz+MYMyX8OklDFEa0jrIpud1crr7JLV OD88Z6cbc6GMRmbu55lJ/LgXwFsaDy/P4fH4vrDtnfT+S84sVaPDDi2pkJg/kh5JhbbE iafLk65UrDREY3I6L/dSzQyb26GWH2wOiqlcBMiD8TMFzBBCU8GIXOyzTSYp0r38TLwj vqCT9rq1SYExuW4sWWT+hkVbFFcHAstsfkg1vpPHuYURrPRp2GGxYdklkmxcjj0sYWsL 7a9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kxh2o1V8iXkuJj8JRvzQtcAUGmlKoLZ53V+la2Fi9CI=; b=XS3ZY3KEwDJ88QUd+I6HFkQs3SwlICuqQF8SYLETLUlOgmjGrCzceGraIOokpyVtdf EtN/DIIDokscLH0wRRH8qtSSnxikbEBNWSKv1uauzEkazu3jJQTrEjrwyu4d2IsYLarG jy9stZ20VB8IIu0AmEXWSiJEyUCqO8a9wuE0PPqFJVnrVOm5Ne6VYSVbjwp4/rler7gp INqf3S5rS2Rls5gUH8QAatYMlJ1MH+BzPdB79V29e+b8S+z6+fPGIDjExjCN/CToa2nW wfEoiVXa7rkMD9a3Th8rL+91+WnZ/uIF/hKs50pyT/oZpU6TwbhIDVN2VnAlucyQB+Zc ft9g== X-Gm-Message-State: AOAM530+ZW2WTmxQBZpFFM8cSSnWju3k8Izoi0b7yytFBAtIKWluYRTd 1YqvfJHM7Z0lCnc1AzXm9NzqO8sDi4SvJw== X-Google-Smtp-Source: ABdhPJwKd+tqq3huXh4No03f70CMmaWJufj2EydvvgX4qvgEYOaDtuoKAmzjtudKsR8imtSFsSx2sA== X-Received: by 2002:a17:90b:d8a:: with SMTP id bg10mr9416204pjb.103.1590758624015; Fri, 29 May 2020 06:23:44 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id e13sm1998686pfd.10.2020.05.29.06.23.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:23:43 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 05/12] qht: call qemu_spin_destroy for head buckets Date: Fri, 29 May 2020 09:23:35 -0400 Message-Id: <20200529132341.755-5-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529132341.755-1-robert.foley@linaro.org> References: <20200529132341.755-1-robert.foley@linaro.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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Signed-off-by: Robert Foley Reviewed-by: Alex Bennée --- util/qht.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/qht.c b/util/qht.c index aa51be3c52..67e5d5b916 100644 --- a/util/qht.c +++ b/util/qht.c @@ -348,6 +348,7 @@ static inline void qht_chain_destroy(const struct qht_bucket *head) struct qht_bucket *curr = head->next; struct qht_bucket *prev; + qemu_spin_destroy(&head->lock); while (curr) { prev = curr; curr = curr->next; From patchwork Fri May 29 13:23:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11578655 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E0D6E912 for ; Fri, 29 May 2020 13:26:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B680F20721 for ; Fri, 29 May 2020 13:26:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="rkVNg2/p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B680F20721 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef2D-0001Fs-U7 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 May 2020 09:26:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeezE-0004Ui-Rs for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:48 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:41334) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeezD-0003d7-Rr for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:48 -0400 Received: by mail-pl1-x642.google.com with SMTP id a13so1164413pls.8 for ; Fri, 29 May 2020 06:23:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JYiXtqj6gRVqxuRODQQz1eMSRJbQ7+uu1VT7LzsetPI=; b=rkVNg2/p5xwqEhzyR0dz8A/RKbFbxailFWq6cwwZ/814WE0lrIQ/nRyM63u6E6/Mt7 vo8bNQ4cRgfOTi8+Z5eFu0Uzw8uNB1m65tA/nE9nkudtCuouXou0RlAR5Tz4p6nB0fzI xqBYbx6iOGylN4gO1F3KCBFyt2wTmhwCXUzjfI50sf9o6kHqz03GGvwi6KE+F09R/mKU HTkKLjeU9os8MdIWB/OvX7MzyGHaBLH5scmWmUcwbON+0vIdTZrEg4wRMDQ5gsmC/x6f zawPqM1F6MD9IGfGw1TJoKpPAuKSrYT5nLPL0P7rO3dFEwDye6nkLO94QhPtsPxxCtsE 1+Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JYiXtqj6gRVqxuRODQQz1eMSRJbQ7+uu1VT7LzsetPI=; b=qscd7/PXuCIGzjgsBTUt7txbZH3m/RWaugD2bVFg2gmVKUGCbP9QMsXyi+5igh20D4 3xkmRxNU0StuC0G5Ksn/CUlHlWdGuBXfLqLUso7CSIjA054GiVtUDhfmzUG7msgpS+aX tDt1OnQcMR06ckndfoLy/Jdsm0DlbnWnIBi1DjpoRXPaeW/hp4LiZlX9RCo2tQ4tA9Tt vBjmZDudW0s/pIwdi6/7SYXuGXuSVTrXrpvJ3p7ZJeDIxqVvhRCUET9hWjkqK9+i/DyY IacEJGMSnL+2HGU3duXb3Hdz20ffmQBbGdTqpDjhSsWy+vL7ReCimZyTwczAUyz0oEd7 gu6A== X-Gm-Message-State: AOAM533NOF3xl99opFPv3h6gY4JAGcubtTtOi6WoI6+xBcAvBCpCPvhO h3fUBHbfePLk3ruu3jRAcIhCF6dQd2kChA== X-Google-Smtp-Source: ABdhPJztSe7+0QS2bC8lcQlBNnzt7qdgei7tfmLkGLk3hXim/DOLxCFnVkmne04xjDm2+/PiLzgsKg== X-Received: by 2002:a17:90b:46d7:: with SMTP id jx23mr9324529pjb.36.1590758626201; Fri, 29 May 2020 06:23:46 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id e13sm1998686pfd.10.2020.05.29.06.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:23:45 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 06/12] tcg: call qemu_spin_destroy for tb->jmp_lock Date: Fri, 29 May 2020 09:23:36 -0400 Message-Id: <20200529132341.755-6-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529132341.755-1-robert.foley@linaro.org> References: <20200529132341.755-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::642; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x642.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley [RF: Minor changes to fix some checkpatch errors] --- accel/tcg/translate-all.c | 10 +++++++++- include/tcg/tcg.h | 3 ++- tcg/tcg.c | 19 ++++++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 42ce1dfcff..3708aab36b 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -384,6 +384,11 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, return 0; } +static void tb_destroy(TranslationBlock *tb) +{ + qemu_spin_destroy(&tb->jmp_lock); +} + bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit) { TranslationBlock *tb; @@ -413,6 +418,7 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit) /* one-shot translation, invalidate it immediately */ tb_phys_invalidate(tb, -1); tcg_tb_remove(tb); + tb_destroy(tb); } r = true; } @@ -1230,7 +1236,7 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) qht_reset_size(&tb_ctx.htable, CODE_GEN_HTABLE_SIZE); page_flush_tb(); - tcg_region_reset_all(); + tcg_region_reset_all(tb_destroy); /* XXX: flush processor icache at this point if cache flush is expensive */ atomic_mb_set(&tb_ctx.tb_flush_count, tb_ctx.tb_flush_count + 1); @@ -1886,6 +1892,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, orig_aligned -= ROUND_UP(sizeof(*tb), qemu_icache_linesize); atomic_set(&tcg_ctx->code_gen_ptr, (void *)orig_aligned); + tb_destroy(tb); return existing_tb; } tcg_tb_insert(tb); @@ -2235,6 +2242,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) tb_phys_invalidate(tb->orig_tb, -1); } tcg_tb_remove(tb); + tb_destroy(tb); } /* TODO: If env->pc != tb->pc (i.e. the faulting instruction was not diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index c48bd76b0a..2c5997e14e 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -815,8 +815,9 @@ void *tcg_malloc_internal(TCGContext *s, int size); void tcg_pool_reset(TCGContext *s); TranslationBlock *tcg_tb_alloc(TCGContext *s); +typedef void (*tb_destroy_func)(TranslationBlock *tb); void tcg_region_init(void); -void tcg_region_reset_all(void); +void tcg_region_reset_all(tb_destroy_func tb_destroy); size_t tcg_code_size(void); size_t tcg_code_capacity(void); diff --git a/tcg/tcg.c b/tcg/tcg.c index a2268d9db0..2680968683 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -502,7 +502,16 @@ size_t tcg_nb_tbs(void) return nb_tbs; } -static void tcg_region_tree_reset_all(void) +static gboolean tcg_region_tree_traverse(gpointer k, gpointer v, gpointer data) +{ + TranslationBlock *tb = v; + tb_destroy_func tb_destroy = data; + + tb_destroy(tb); + return FALSE; +} + +static void tcg_region_tree_reset_all(tb_destroy_func tb_destroy) { size_t i; @@ -510,6 +519,10 @@ static void tcg_region_tree_reset_all(void) for (i = 0; i < region.n; i++) { struct tcg_region_tree *rt = region_trees + i * tree_size; + if (tb_destroy != NULL) { + g_tree_foreach(rt->tree, tcg_region_tree_traverse, tb_destroy); + } + /* Increment the refcount first so that destroy acts as a reset */ g_tree_ref(rt->tree); g_tree_destroy(rt->tree); @@ -586,7 +599,7 @@ static inline bool tcg_region_initial_alloc__locked(TCGContext *s) } /* Call from a safe-work context */ -void tcg_region_reset_all(void) +void tcg_region_reset_all(tb_destroy_func tb_destroy) { unsigned int n_ctxs = atomic_read(&n_tcg_ctxs); unsigned int i; @@ -603,7 +616,7 @@ void tcg_region_reset_all(void) } qemu_mutex_unlock(®ion.lock); - tcg_region_tree_reset_all(); + tcg_region_tree_reset_all(tb_destroy); } #ifdef CONFIG_USER_ONLY From patchwork Fri May 29 13:23:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11578669 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E45AF1392 for ; Fri, 29 May 2020 13:29:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BB03320721 for ; Fri, 29 May 2020 13:29:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Qe/NoSKm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB03320721 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:41748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef4p-0005HW-U7 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 May 2020 09:29:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeezG-0004ah-Ur for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:50 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:39957) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeezG-0003e3-3s for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:50 -0400 Received: by mail-pj1-x1043.google.com with SMTP id s88so760298pjb.5 for ; Fri, 29 May 2020 06:23: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; bh=v6Twul2TWinr3wq/OK/PDzXQA1fcuJlgD8ranJI4BbA=; b=Qe/NoSKmjgsBaIKdrrGbLmSUkEDBU33O+Vl6A1JnrohhWUBfA+ZpFdJ1ZkHzvj3B5M yUojEYpKfFWaGgW7z1gkxF96Hpnru/1JNlDY7zF0Ph1PebQ4KCM2ubni+L7wTsJfyznU wl7/LtFu+FgJXS7JWLTV83bw9ePIWnPUwas7FD217JjvPze6vIASVR95woWo/ILyMe3j 6+i6HDArB8C9U9VtIBnDZ7xJMe8z0Dr1ASkNxgKcZw+4sCJIbDOJm48YGV8nDBxXQ5Oc FwqT0eGz/BF6++SrDXFRVOFydk63Jh9XYNERHThlITKjATRvtuq/hKxaKHMdTJmhrV9X M/KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v6Twul2TWinr3wq/OK/PDzXQA1fcuJlgD8ranJI4BbA=; b=Is4ZLhHsJrYzdXFd45DE6vHBNZH/ZJmYQ3eFgOKYeGh3jYUH9CTwhR9VrhSDS1i0YR Wyqc6z60ANWiHfpP2Ghf8zY5zsJPKJ2vM2w2oSmfhcVqS8C6xTBmZ7X8AGavJ5a8gGTK YNx3bF6mFgtZRduNnlfdHwXI0L4nMQ5RlgstzdxwRr7NqM2ZNPk0rK+K208clfXB6CUO 7mXC48q5jTdMPKFZ8UkkXY0qTfYR9UU2mRR5tp9kTWzzoilYxX6gdchk+P9RU4ALdcy3 SBzQzOC2bQ0BJ/7QJL9OM9T2H59GqWoQ03X+rJt1ybnznJ5L8fuaZo7d6C0+3xq105vo WDPQ== X-Gm-Message-State: AOAM533eV4CiuLFk7oo8YJ6yki7sZzPeodjfQC5Osh5aOOxBdtLNkctF IDqWNFrZMsQD/49irg7tWm/9l0TQZtXeAA== X-Google-Smtp-Source: ABdhPJxJr7WCt9SL1vpwjxoDAZ5ctP4a3Ed6bPuZp2mTbDNaV4NWPYmc7owjpltMEp9VuUy1sQ4umw== X-Received: by 2002:a17:90a:238d:: with SMTP id g13mr9494110pje.213.1590758628414; Fri, 29 May 2020 06:23:48 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id e13sm1998686pfd.10.2020.05.29.06.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:23:47 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 07/12] translate-all: call qemu_spin_destroy for PageDesc Date: Fri, 29 May 2020 09:23:37 -0400 Message-Id: <20200529132341.755-7-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529132341.755-1-robert.foley@linaro.org> References: <20200529132341.755-1-robert.foley@linaro.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, cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" The radix tree is append-only, but we can fail to insert a PageDesc if the insertion races with another thread. Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley --- accel/tcg/translate-all.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 3708aab36b..3fb71a1503 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -547,6 +547,15 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc) #endif existing = atomic_cmpxchg(lp, NULL, pd); if (unlikely(existing)) { +#ifndef CONFIG_USER_ONLY + { + int i; + + for (i = 0; i < V_L2_SIZE; i++) { + qemu_spin_destroy(&pd[i].lock); + } + } +#endif g_free(pd); pd = existing; } From patchwork Fri May 29 13:23:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11578665 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 224CF1392 for ; Fri, 29 May 2020 13:29:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EC1F220721 for ; Fri, 29 May 2020 13:29:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="KFzDwUz0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC1F220721 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:40160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef4L-0004dB-5I for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 May 2020 09:29:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeezJ-0004gu-9L for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:53 -0400 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]:53970) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeezI-0003ew-8w for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:52 -0400 Received: by mail-pj1-x1044.google.com with SMTP id ci21so1341149pjb.3 for ; Fri, 29 May 2020 06:23: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; bh=mGW6wnv9FlzkC02Bo8Bk1So4QHTwo22NecRxOgB5aoI=; b=KFzDwUz0qmHA3ULFQs62is1dlym1KjMxCz7QHytByajg9YXKw3fNmWRKR6EH5Ky7kW 4JKfsNQ+ZVDM+BPyKe7zVh+MCSCgo/kzRcpzZgYmCeNixvvg+z+QpcmNeexDJAjxYULY y9DM8HqjwGPBlFGuJ0P7XqnSMvOREJUY5ddJxT/RpvRPcJNk/OhE30txVCMqbKbbAV3s d8GEUR4Su+uTZShn1O+6YoVdCIR/gwKTFUiLIR8gtCEGLgpVV+gWu45yuJs0Bg+Zj9IR HWASs/NVP5KVvdIzORPltuHjD9niHxbA+P/pGcPXKDaf3pORipzIuG3DsntNHII0lWuN pJsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mGW6wnv9FlzkC02Bo8Bk1So4QHTwo22NecRxOgB5aoI=; b=sPbtEEIPGoHCjY5Yh/hGCfgi+594oQEaLvg6j+ocsSrG4FMajuXqRTUB8KUtEeW0PT 2VT8/31beiFJkVIiwPSPpriGYpseg06Ru+RPpUskw+aEKv4QQjkt7bzYXk5XC2cIAM7M KBcA3l7pHMvwc4hglLThaDKAZlzsScBU1BPHxuGRQGqMq8noUQkMHaCbX1tEeceAZ5FZ iA4Rwp8yFKPkabs/9r5XtBNZ8t/7rRSrubsr+bVlyee4KYQR4M9762CfI+hNQTo11ENm C1dtqY46rE3GkBVRjv7ZydGBe3eJ3ECNYGUNSSPph4ypx41lJGMhDuDyOnqfoc9ExP4t Gpsg== X-Gm-Message-State: AOAM533GthxIwUMPEx3TldNYp7csWFn/rYUbiQ+eP/hLACHEZigPi9Z/ 1umiaUV3H0+saWizdOdbA+F/HtmRK4cPbw== X-Google-Smtp-Source: ABdhPJy3LBU7U4vWZIml69K09YTeDCX4bKcknVQXRxuLDpwOo1LGjb3BaPOpIw5Cr81VoaOBcSbD5w== X-Received: by 2002:a17:90a:f292:: with SMTP id fs18mr9260316pjb.37.1590758630496; Fri, 29 May 2020 06:23:50 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id e13sm1998686pfd.10.2020.05.29.06.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:23:49 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 08/12] thread: add tsan annotations to QemuSpin Date: Fri, 29 May 2020 09:23:38 -0400 Message-Id: <20200529132341.755-8-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529132341.755-1-robert.foley@linaro.org> References: <20200529132341.755-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::1044; envelope-from=robert.foley@linaro.org; helo=mail-pj1-x1044.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley Reviewed-by: Alex Bennée --- include/qemu/thread.h | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/include/qemu/thread.h b/include/qemu/thread.h index e50a073889..43fc094b96 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -206,6 +206,10 @@ void qemu_thread_atexit_add(struct Notifier *notifier); */ void qemu_thread_atexit_remove(struct Notifier *notifier); +#ifdef CONFIG_TSAN +#include +#endif + struct QemuSpin { int value; }; @@ -213,23 +217,46 @@ struct QemuSpin { static inline void qemu_spin_init(QemuSpin *spin) { __sync_lock_release(&spin->value); +#ifdef CONFIG_TSAN + __tsan_mutex_create(spin, __tsan_mutex_not_static); +#endif } -static inline void qemu_spin_destroy(QemuSpin *spin) -{ } +/* const parameter because the only purpose here is the TSAN annotation */ +static inline void qemu_spin_destroy(const QemuSpin *spin) +{ +#ifdef CONFIG_TSAN + __tsan_mutex_destroy((void *)spin, __tsan_mutex_not_static); +#endif +} static inline void qemu_spin_lock(QemuSpin *spin) { +#ifdef CONFIG_TSAN + __tsan_mutex_pre_lock(spin, 0); +#endif while (unlikely(__sync_lock_test_and_set(&spin->value, true))) { while (atomic_read(&spin->value)) { cpu_relax(); } } +#ifdef CONFIG_TSAN + __tsan_mutex_post_lock(spin, 0, 0); +#endif } static inline bool qemu_spin_trylock(QemuSpin *spin) { - return __sync_lock_test_and_set(&spin->value, true); +#ifdef CONFIG_TSAN + __tsan_mutex_pre_lock(spin, __tsan_mutex_try_lock); +#endif + bool busy = __sync_lock_test_and_set(&spin->value, true); +#ifdef CONFIG_TSAN + unsigned flags = __tsan_mutex_try_lock; + flags |= busy ? __tsan_mutex_try_lock_failed : 0; + __tsan_mutex_post_lock(spin, flags, 0); +#endif + return busy; } static inline bool qemu_spin_locked(QemuSpin *spin) @@ -239,7 +266,13 @@ static inline bool qemu_spin_locked(QemuSpin *spin) static inline void qemu_spin_unlock(QemuSpin *spin) { +#ifdef CONFIG_TSAN + __tsan_mutex_pre_unlock(spin, 0); +#endif __sync_lock_release(&spin->value); +#ifdef CONFIG_TSAN + __tsan_mutex_post_unlock(spin, 0); +#endif } struct QemuLockCnt { From patchwork Fri May 29 13:23:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11578653 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C74EC912 for ; Fri, 29 May 2020 13:26:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 596AA20721 for ; Fri, 29 May 2020 13:26:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="BjIq0D9R" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 596AA20721 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef2B-000197-87 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 May 2020 09:26:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeezM-0004pe-KP for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:56 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:33623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeezK-0003gJ-EO for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:56 -0400 Received: by mail-pj1-x1042.google.com with SMTP id z15so3151333pjb.0 for ; Fri, 29 May 2020 06:23:54 -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=fk2ImFtCAweaJwaiXMj1+yvDhd6ngpBz4DJyDjLrY1c=; b=BjIq0D9RgGi8EXyaqDoJIONuHQ6AxKwqgf43fedHDN6Xyo/LEb6N2LCCCxb/BO65Lk rwM4MqO6xzpoS56VLlGpHH1ZG6MSkSTKelpVkBK6CHCW8lzrWizt6jxCTLAOeiJio/QN YVV48DTDqCuB7Ig/MowElLNDf8nscLNkqmZK6EraxWUvym16eph1iUZW/TZF69boVHv9 QudByrm2pWn1RX1pVjNOjGxIBfC3bE6Jfn11Bajc+RaSIuhalQ+y2KHacQrjtNta2lzZ jDnHx3iBlv5oBndM4V2tSRl/P4zT8pf0R9dgCPn7MH7Wme6q5QPVjJFiFJDMZ8T1qvoo rTUA== 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=fk2ImFtCAweaJwaiXMj1+yvDhd6ngpBz4DJyDjLrY1c=; b=COwlz5wIJJzpWJ43+4cuLMXhfadv0uciM0SeaJNlWgFXLYWrotaXWYIKlKKvqVgdVG a4thr6PoONQHtfn6oeLO4MFcYW7BjKVtr0zH6lkZ1K4/IZSXQjW3Kl/7308luOhoTP2V 1ZFAeKa5HyKMwihYLP0CGJxdC36ND4csU2lPNTRpNAD2/tkdRJ4Vo5fr+MywH+gwvQ1w ei9yCQhExoderXui9HPmQ+xz6Cix0l4Qi0dWQdfvBkHSYkiMVUFrIjlili3l+b/YhV4N ge8etxLuRKVLJThxDJvv9ZigwVKjfwuFvW0ljtXVoCR2i5WuGxXF+SUcf4MsjItOjbYN YN8w== X-Gm-Message-State: AOAM5332F+YKoaje91zYlRXNjm+f/+/P0XpjV5qAsyU8+pbxAnA6OGp3 Y0D0CsPJ7TcXXoiUq+BFh4R1hNNUhRqhCw== X-Google-Smtp-Source: ABdhPJz3R7jFx/v73A+O/bvMi4ySM8JjZ92D3ilGyqAiICkT7nBaOuG5ishy0RrpXE3jsEyX6baKVw== X-Received: by 2002:a17:90a:930b:: with SMTP id p11mr1809274pjo.230.1590758632669; Fri, 29 May 2020 06:23:52 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id e13sm1998686pfd.10.2020.05.29.06.23.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:23:52 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 09/12] tests/docker: Added docker build support for TSan. Date: Fri, 29 May 2020 09:23:39 -0400 Message-Id: <20200529132341.755-9-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529132341.755-1-robert.foley@linaro.org> References: <20200529132341.755-1-robert.foley@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1042; envelope-from=robert.foley@linaro.org; helo=mail-pj1-x1042.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , robert.foley@linaro.org, =?utf-8?q?Philippe_?= =?utf-8?q?Mathieu-Daud=C3=A9?= , cota@braap.org, peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Added a new docker for ubuntu 20.04. This docker has support for Thread Sanitizer including one patch we need in one of the header files. https://github.com/llvm/llvm-project/commit/a72dc86cd This command will build with tsan enabled: make docker-test-build-ubuntu2004 V=1 TSAN=1 Also added the TSAN suppresion file to disable certain cases of TSAN warnings. Cc: Fam Zheng Cc: Philippe Mathieu-Daudé Signed-off-by: Robert Foley --- tests/docker/Makefile.include | 2 + tests/docker/common.rc | 19 +++++++ tests/docker/dockerfiles/ubuntu2004.docker | 65 ++++++++++++++++++++++ tests/tsan/blacklist.tsan | 10 ++++ tests/tsan/suppressions.tsan | 14 +++++ 5 files changed, 110 insertions(+) create mode 100644 tests/docker/dockerfiles/ubuntu2004.docker create mode 100644 tests/tsan/blacklist.tsan create mode 100644 tests/tsan/suppressions.tsan diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include index 43a8678688..e029e54b42 100644 --- a/tests/docker/Makefile.include +++ b/tests/docker/Makefile.include @@ -202,6 +202,7 @@ endif @echo ' (default is 1)' @echo ' DEBUG=1 Stop and drop to shell in the created container' @echo ' before running the command.' + @echo ' TSAN=1 Enable use of tsan during the build/test.' @echo ' NETWORK=1 Enable virtual network interface with default backend.' @echo ' NETWORK=$$BACKEND Enable virtual network interface with $$BACKEND.' @echo ' NOUSER Define to disable adding current user to containers passwd.' @@ -239,6 +240,7 @@ docker-run: docker-qemu-src -e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \ -e V=$V -e J=$J -e DEBUG=$(DEBUG) \ -e SHOW_ENV=$(SHOW_ENV) \ + $(if $(TSAN),,-e TSAN=$(TSAN)) \ $(if $(NOUSER),, \ -e CCACHE_DIR=/var/tmp/ccache \ -v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \ diff --git a/tests/docker/common.rc b/tests/docker/common.rc index 02cd67a8c5..5df93c6326 100755 --- a/tests/docker/common.rc +++ b/tests/docker/common.rc @@ -27,6 +27,25 @@ requires() configure_qemu() { + if test -z "$TSAN"; then + requires clang tsan + echo "Including TSan Support" + tsan_log_dir="/tmp/qemu-test/build/tsan" + mkdir -p $tsan_log_dir > /dev/null || true + EXTRA_CONFIGURE_OPTS="${EXTRA_CONFIGURE_OPTS} --enable-tsan \ + --cc=clang-10 --cxx=clang++-10 \ + --disable-werror --extra-cflags=-O0" + # detect deadlocks is false currently simply because + # TSan crashes immediately with deadlock detecter enabled. + # We have maxed out the history size to get the best chance of finding + # warnings during testing. + # Note, to get tsan to fail on warning, use exitcode=66 below. + tsan_opts="suppressions=/tmp/qemu-test/src/tests/tsan/suppressions.tsan\ + detect_deadlocks=false history_size=7\ + halt_on_error=0 exitcode=0 verbose=5\ + log_path=$tsan_log_dir/tsan_warnings.txt" + export TSAN_OPTIONS="$tsan_opts" + fi config_opts="--enable-werror \ ${TARGET_LIST:+--target-list=${TARGET_LIST}} \ --prefix=$INSTALL_DIR \ diff --git a/tests/docker/dockerfiles/ubuntu2004.docker b/tests/docker/dockerfiles/ubuntu2004.docker new file mode 100644 index 0000000000..6050ce7e8a --- /dev/null +++ b/tests/docker/dockerfiles/ubuntu2004.docker @@ -0,0 +1,65 @@ +FROM ubuntu:20.04 +ENV PACKAGES flex bison \ + ccache \ + clang-10\ + gcc \ + gettext \ + git \ + glusterfs-common \ + libaio-dev \ + libattr1-dev \ + libbrlapi-dev \ + libbz2-dev \ + libcacard-dev \ + libcap-ng-dev \ + libcurl4-gnutls-dev \ + libdrm-dev \ + libepoxy-dev \ + libfdt-dev \ + libgbm-dev \ + libgtk-3-dev \ + libibverbs-dev \ + libiscsi-dev \ + libjemalloc-dev \ + libjpeg-turbo8-dev \ + liblzo2-dev \ + libncurses5-dev \ + libncursesw5-dev \ + libnfs-dev \ + libnss3-dev \ + libnuma-dev \ + libpixman-1-dev \ + librados-dev \ + librbd-dev \ + librdmacm-dev \ + libsasl2-dev \ + libsdl2-dev \ + libseccomp-dev \ + libsnappy-dev \ + libspice-protocol-dev \ + libspice-server-dev \ + libssh-dev \ + libusb-1.0-0-dev \ + libusbredirhost-dev \ + libvdeplug-dev \ + libvte-2.91-dev \ + libxen-dev \ + libzstd-dev \ + make \ + python3-yaml \ + python3-sphinx \ + sparse \ + texinfo \ + xfslibs-dev\ + vim +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get -y install $PACKAGES +RUN dpkg -l $PACKAGES | sort > /packages.txt +ENV FEATURES clang tsan pyyaml sdl2 + +# https://bugs.launchpad.net/qemu/+bug/1838763 +ENV QEMU_CONFIGURE_OPTS --disable-libssh + +# Apply patch https://reviews.llvm.org/D75820 +# This is required for TSan in clang-10 to compile with QEMU. +RUN sed -i 's/^const/static const/g' /usr/lib/llvm-10/lib/clang/10.0.0/include/sanitizer/tsan_interface.h diff --git a/tests/tsan/blacklist.tsan b/tests/tsan/blacklist.tsan new file mode 100644 index 0000000000..75e444f5dc --- /dev/null +++ b/tests/tsan/blacklist.tsan @@ -0,0 +1,10 @@ +# This is an example blacklist. +# To enable use of the blacklist add this to configure: +# "--extra-cflags=-fsanitize-blacklist=/tests/tsan/blacklist.tsan" +# The eventual goal would be to fix these warnings. + +# TSan is not happy about setting/getting of dirty bits, +# for example, cpu_physical_memory_set_dirty_range, +# and cpu_physical_memory_get_dirty. +src:bitops.c +src:bitmap.c diff --git a/tests/tsan/suppressions.tsan b/tests/tsan/suppressions.tsan new file mode 100644 index 0000000000..73414b9ebd --- /dev/null +++ b/tests/tsan/suppressions.tsan @@ -0,0 +1,14 @@ +# This is the set of runtime suppressions of TSan warnings. +# The goal would be to have here only items we do not +# plan to fix, and to explain why for each item. + +# TSan reports a double lock on RECURSIVE mutexes. +# Since the recursive lock is intentional, we choose to ignore it. +mutex:aio_context_acquire +mutex:pthread_mutex_lock + +# TSan reports a race betwen pthread_mutex_init() and +# pthread_mutex_lock(). Since this is outside of QEMU, +# we choose to ignore it. +race:pthread_mutex_init +race:pthread_mutex_lock From patchwork Fri May 29 13:23:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11578671 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B0B1B159A for ; Fri, 29 May 2020 13:30:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 880742071A for ; Fri, 29 May 2020 13:30:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xiceRRG+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 880742071A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef5t-0008FN-MY for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 May 2020 09:30:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeezO-0004tN-0r for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:58 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:36693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeezM-0003he-VZ for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:57 -0400 Received: by mail-pl1-x644.google.com with SMTP id bg4so1164660plb.3 for ; Fri, 29 May 2020 06:23:56 -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=AOzUAJyFNQB4L+phqsSsfzj9Z8OtZxOrajLi9NoXesk=; b=xiceRRG+/TTDb0OXC244QM/ffSZIlCmPHW6oo5g7ITnFGVML6PJp1sWMy9VZpiC5zP UQDKOK/z9g6uFlzNmETiAA6Pl+OtMMtHoJHayDGMwgquXZAkuHqltVnPglKItiJ3Bl/G YMDdLs6xAot9CtGYtcJy34U9X2dkQDkJAM+QPs9/S/ElSksPV+F0WnGmIRfwUnZXHCxB n82hzUuFs0DUe/9a9rqRfWSItQ+xL1CQ9Uqm9r/J0u1WxtuCiGznSzlfl7kEUtlCapdk MFQKKiLplVS+zfIl/B12L5XMzsPhsxKoEHl2v48o9dYv+ULOkPDC5mTlV6B65uIr290v Gphg== 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=AOzUAJyFNQB4L+phqsSsfzj9Z8OtZxOrajLi9NoXesk=; b=bqG7rHc+ncsBtHhwIAthTE2phr0OuayOfP9IoMimmRXdhpAy/ifcjbDTzU7dVcctap aqGFvrRkjRpSWwbJXpgnpS7l57kkp8wtpR/Zm4WkVYTOlp8AlSj5VdQm/3EjkAEsMsq/ tzPN99g6XL6XSOKgj4VyN/wvsalQ5O6uu95oXrquPC38mDntd1t3nuwf6OUaD4gwEiTe OV/n+SAklLC3W4VO6xW84AIahmYBqLYOzzU1MlaI6aSCyd8WuiFQ4oQWS2T55RyBP3v6 OOKvsisjvD/1twM7a55rw6M2OD3PrcBSQ3MEPyw9XYcuQykGh1dS/m9oG90xwfdNsL15 73iQ== X-Gm-Message-State: AOAM5327CeWQFpCPR3h295DWKSMs2EiAsoVyHgwtAUud4rEAkTCuxAnc df4nruFiqL51BnEy3Tenfbn3F/pialxXmg== X-Google-Smtp-Source: ABdhPJxLGd/aqRKTgiPPs7yCS8oFgU0orocOOG6wSoIeb8NLWF7EMSUTHzBvTYOP1tHjR3T2XbT33g== X-Received: by 2002:a17:90a:6f26:: with SMTP id d35mr9414092pjk.210.1590758634877; Fri, 29 May 2020 06:23:54 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id e13sm1998686pfd.10.2020.05.29.06.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:23:54 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 10/12] include/qemu: Added tsan.h for annotations. Date: Fri, 29 May 2020 09:23:40 -0400 Message-Id: <20200529132341.755-10-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529132341.755-1-robert.foley@linaro.org> References: <20200529132341.755-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::644; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x644.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" These annotations will allow us to give tsan additional hints. For example, we can inform tsan about reads/writes to ignore to silence certain classes of warnings. We can also annotate threads so that the proper thread naming shows up in tsan warning results. Signed-off-by: Robert Foley Reviewed-by: Emilio G. Cota --- include/qemu/tsan.h | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 include/qemu/tsan.h diff --git a/include/qemu/tsan.h b/include/qemu/tsan.h new file mode 100644 index 0000000000..09cc665f91 --- /dev/null +++ b/include/qemu/tsan.h @@ -0,0 +1,71 @@ +#ifndef QEMU_TSAN_H +#define QEMU_TSAN_H +/* + * tsan.h + * + * This file defines macros used to give ThreadSanitizer + * additional information to help suppress warnings. + * This is necessary since TSan does not provide a header file + * for these annotations. The standard way to include these + * is via the below macros. + * + * Annotation examples can be found here: + * https://github.com/llvm/llvm-project/tree/master/compiler-rt/test/tsan + * annotate_happens_before.cpp or ignore_race.cpp are good places to start. + * + * The full set of annotations can be found here in tsan_interface_ann.cpp. + * https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/tsan/rtl/ + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifdef CONFIG_TSAN +/* + * Informs TSan of a happens before/after relationship. + */ +#define QEMU_TSAN_ANNOTATE_HAPPENS_BEFORE(addr) \ + AnnotateHappensBefore(__FILE__, __LINE__, (void *)(addr)) +#define QEMU_TSAN_ANNOTATE_HAPPENS_AFTER(addr) \ + AnnotateHappensAfter(__FILE__, __LINE__, (void *)(addr)) +/* + * Gives TSan more information about thread names it can report the + * name of the thread in the warning report. + */ +#define QEMU_TSAN_ANNOTATE_THREAD_NAME(name) \ + AnnotateThreadName(__FILE__, __LINE__, (void *)(name)) +/* + * Allows defining a region of code on which TSan will not record memory READS. + * This has the effect of disabling race detection for this section of code. + */ +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_BEGIN() \ + AnnotateIgnoreReadsBegin(__FILE__, __LINE__) +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_END() \ + AnnotateIgnoreReadsEnd(__FILE__, __LINE__) +/* + * Allows defining a region of code on which TSan will not record memory + * WRITES. This has the effect of disabling race detection for this + * section of code. + */ +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN() \ + AnnotateIgnoreWritesBegin(__FILE__, __LINE__) +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_END() \ + AnnotateIgnoreWritesEnd(__FILE__, __LINE__) +#else +#define QEMU_TSAN_ANNOTATE_HAPPENS_BEFORE(addr) +#define QEMU_TSAN_ANNOTATE_HAPPENS_AFTER(addr) +#define QEMU_TSAN_ANNOTATE_THREAD_NAME(name) +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_BEGIN() +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_END() +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN() +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_END() +#endif + +void AnnotateHappensBefore(const char *f, int l, void *addr); +void AnnotateHappensAfter(const char *f, int l, void *addr); +void AnnotateThreadName(const char *f, int l, char *name); +void AnnotateIgnoreReadsBegin(const char *f, int l); +void AnnotateIgnoreReadsEnd(const char *f, int l); +void AnnotateIgnoreWritesBegin(const char *f, int l); +void AnnotateIgnoreWritesEnd(const char *f, int l); +#endif From patchwork Fri May 29 13:23:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11578673 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A6692739 for ; Fri, 29 May 2020 13:31:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7BDAC20723 for ; Fri, 29 May 2020 13:31:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SkTUCqwc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BDAC20723 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:48226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef6Z-00010L-KU for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 May 2020 09:31:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeezP-0004xz-MZ for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:59 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:33624) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeezO-0003ib-Th for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:59 -0400 Received: by mail-pj1-x1043.google.com with SMTP id z15so3151369pjb.0 for ; Fri, 29 May 2020 06:23:58 -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=yJ08HengHm5gv++XKOUrrTtG6i6MD5Dt3ZAL97dGxmk=; b=SkTUCqwccYlbbtrJkwUfKnNuedk0cp3LgopEKXPhrYTRfTU8Z/EcFaWthADE4RaV/C jiZvOxtsHoJfwOhuWmwb6L/RtU+d0AMC3SBiTkcXKbadtIkRi7P061iHZ7OX9ZZCK4kZ 4iUNL/4A7FCM5/ATw3uh7c4lX6pC2IRDYtwVAFNJ3GR4czZ85aIIowhJo5Zp4fMdjGvt VaFzczl2/dtYhVPlAlG5X609YvKd1j4IX4Ff9rpb+PoNjl79QW+/aOUpsFvj9SWtmiUR o/X8OwWwIpRkfbHMaifXVKZB6/aN5HtR8ofzMb+dR8i4bZVqu3EwToNRlbT7LysEJorG FOvA== 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=yJ08HengHm5gv++XKOUrrTtG6i6MD5Dt3ZAL97dGxmk=; b=KIWhcGyqsHh5jMEXndCTadToIRagFMusLiNEuR9fj5LiCVQaESrQl37X52tPDfjcKs KtyYDMcNvKMOoWCou7A7o8Eukyi71JFlKclTMmOrZyx3dYc2gT8WwYipUCxnR8BQ5fxk Q82KvEL2TI1ZFyUTf4MLRGqQ5doFzu2ggPsb3IkoNFNUEOhDEBoZxPuVBCq5Zck5hTAI xVptcq2ewIYzaSWNmwziNmzKcn3CTXcpK9Z/ikpeviuH3NjqAifMmjhShtjnytvToTqf J3lyTS0Ef6mDdcvYSOY3GPjYiQ4g5pUe/HVbyLF3wE8xWvIHi3Dl5D9InTuunUzzk+9h qonA== X-Gm-Message-State: AOAM531DAxVX7PmwKHLbjF+D8IbL9DERS4knA1oqzK37d48Tig5S9cCw idxme3flfnh2lovFykiqn40WDxK0PNmYdQ== X-Google-Smtp-Source: ABdhPJwntGPkCaUGoUxpwAJAIS10p9r9UmnRjYQ3MNglbjBL4bUhdgRkqcCBPEjI2DB+rSlvHqtvTA== X-Received: by 2002:a17:90a:8918:: with SMTP id u24mr9340872pjn.71.1590758637313; Fri, 29 May 2020 06:23:57 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id e13sm1998686pfd.10.2020.05.29.06.23.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:23:56 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 11/12] util: Added tsan annotate for thread name. Date: Fri, 29 May 2020 09:23:41 -0400 Message-Id: <20200529132341.755-11-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529132341.755-1-robert.foley@linaro.org> References: <20200529132341.755-1-robert.foley@linaro.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: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This allows us to see the name of the thread in tsan warning reports such as this: Thread T7 'CPU 1/TCG' (tid=24317, running) created by main thread at: Signed-off-by: Robert Foley Reviewed-by: Emilio G. Cota --- util/qemu-thread-posix.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 838980aaa5..b4c2359272 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -15,6 +15,7 @@ #include "qemu/atomic.h" #include "qemu/notify.h" #include "qemu-thread-common.h" +#include "qemu/tsan.h" static bool name_threads; @@ -513,6 +514,7 @@ static void *qemu_thread_start(void *args) # endif } #endif + QEMU_TSAN_ANNOTATE_THREAD_NAME(qemu_thread_args->name); g_free(qemu_thread_args->name); g_free(qemu_thread_args); pthread_cleanup_push(qemu_thread_atexit_notify, NULL); From patchwork Fri May 29 13:24:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 11578677 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 446561392 for ; Fri, 29 May 2020 13:32:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 16B70208B8 for ; Fri, 29 May 2020 13:32:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="blVp3do4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 16B70208B8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:52098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef80-0002Yb-Ae for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 May 2020 09:32:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43118) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jef0P-0006UG-9c for qemu-devel@nongnu.org; Fri, 29 May 2020 09:25:01 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:38833) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jef0O-000452-1n for qemu-devel@nongnu.org; Fri, 29 May 2020 09:25:00 -0400 Received: by mail-pj1-x1042.google.com with SMTP id t8so1329903pju.3 for ; Fri, 29 May 2020 06:24: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; bh=sMSUvaGVYsjE3AMoDsJ2TYvIyY2QCzLj9JPqQSj65XM=; b=blVp3do4CV99FRaoe/I2mK0lMhr/QDqw7tOHbSmwE1l49yzEd1OEjmeDPW+GiHqY4t XmVs6KUdiHm/mSNfOrKwVmGtHp5lQAPnvtwHr8PnWynmw4bcw5i0+sVSb9ZFpm/x7Wzj /+XKQPOoveaig1DkACYpkceuB9tZdnCGf43BTmZ2PKTgPWmAZ4Mch4AmhQWEGigsPu8U v5mONNo6xjr8LD0U2CG7QN+ANgtUlwFFFtRLNRx4Z+wY7d5sCqPd1lqeiCtd/BH3uLvB cDD2SzbVIFvXi7T1dna8TFRc4fZU9UAJpoJOluUzt6OzJjSKtlC5rJvHJx/mkpOe20vq wWTw== 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; bh=sMSUvaGVYsjE3AMoDsJ2TYvIyY2QCzLj9JPqQSj65XM=; b=VAHFvDCKunxW9oiCwXbTDFT32Q2T1cB2oa5mwCfaF6wCw2h57cass3gQRmuZ/1GJtB QuA3/LZllQ6mb6FjuFYOlv6rOOWzSxSZibNmwrtEqxDWJmxAGwgE2J3jsICTLaEhaMwr k0mYEQUnQOjsovvhqny6K+WMQi8mDuvpnbyFD0H/uSOLzTseKQzG0hChHS7Sf8Eb43W2 k3KQi4HTVaiBbYjgkD90MZRuQCnTTmqwhkz4YOEhuKU23D7TkA0Hr097i1Erct4UPUe0 3vNXlnyLuyQ1mPfc1IKBqjf/uzrEy2AyPpZB03XYnP+0p9/1MFFV5MwmIoO2d9HYQk7G ljyA== X-Gm-Message-State: AOAM531bs8q21RePaLLU3Ks+CRPzk2AP4P4VyfuyXM038ALnreR1bmGN UYr3t6+7RVwDZOhSIAC5XK23jIJEscz5ng== X-Google-Smtp-Source: ABdhPJwNey+wTHvYnJiz9mViYrjHMUJT9IX1tCPe7df7VpMQam7JThuUQ3qG6K8Qkf8Lu7/YZQvP8g== X-Received: by 2002:a17:90a:ad92:: with SMTP id s18mr9675955pjq.30.1590758698186; Fri, 29 May 2020 06:24:58 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id bu7sm8370538pjb.41.2020.05.29.06.24.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:24:57 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 12/12] docs: Added details on TSan to testing.rst Date: Fri, 29 May 2020 09:24:38 -0400 Message-Id: <20200529132438.837-1-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 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, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Adds TSan details to testing.rst. This includes background and reference details on TSan, and details on how to build and test with TSan both with and without docker. Signed-off-by: Robert Foley Reviewed-by: Emilio G. Cota --- docs/devel/testing.rst | 113 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst index 770a987ea4..17a07ff8c0 100644 --- a/docs/devel/testing.rst +++ b/docs/devel/testing.rst @@ -397,6 +397,119 @@ list is in the ``make docker`` help text. The frequently used ones are: * ``DEBUG=1``: enables debug. See the previous "Debugging a Docker test failure" section. +Thread Sanitizer +================ + +Thread Sanitizer (TSan) is a tool which can detect data races. QEMU supports +building and testing with this tool. + +For more information on TSan: + +https://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual + +Thread Sanitizer in Docker +--------------------------- +TSan is currently supported in the ubuntu2004 docker. + +Just add the TSAN=1 argument to use TSan + +.. code:: + + make docker-test-build@ubuntu2004 TSAN=1 + +or + +.. code:: + + make docker-test-quick@ubuntu2004 TSAN=1 + +TSan warnings under docker are placed in files located at build/tsan/. + +We recommend using DEBUG=1 to allow launching the test from inside the docker, +and to allow review of the warnings generated by TSan. + +Building and Testing with TSan +------------------------------ + +It is possible to build and test with TSan, with a few additional steps. +These steps are normally done automatically in the docker. + +There is a one time patch needed in clang-9 or clang-10 at this time: + +.. code:: + + sed -i 's/^const/static const/g' \ + /usr/lib/llvm-10/lib/clang/10.0.0/include/sanitizer/tsan_interface.h + +To configure the build for TSan: + +.. code:: + + ../configure --enable-tsan --cc=clang-10 --cxx=clang++-10 \ + --disable-werror --extra-cflags="-O0" + +The runtime behavior of TSAN is controlled by the TSAN_OPTIONS environment +variable. + +More information on the TSAN_OPTIONS can be found here: + +https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags + +For example: + +.. code:: + + export TSAN_OPTIONS=suppressions=/tests/tsan/suppressions.tsan \ + detect_deadlocks=false history_size=7 exitcode=0 \ + log_path=/tsan/tsan_warnings.txt + +The above exitcode=0 has TSan continue without error if any warnings are found. +This allows for running the test and then checking the warnings afterwards. +If you want TSan to stop and exit with error on warnings, use exitcode=66. + +TSan Suppressions +----------------- +Keep in mind that for any data race warning, although there might be a data race +detected by TSan, there might be no actual bug here. TSan provides several +different mechanisms for suppressing warnings. In general it is recommended +to fix the code if possible to eliminate the data race rather than suppress +the warning. + +A few important files for suppressing warnings are: + +tests/tsan/suppressions.tsan - Has TSan warnings we wish to suppress at runtime. +The comment on each supression will typically indicate why we are +suppressing it. More information on the file format can be found here: + +https://github.com/google/sanitizers/wiki/ThreadSanitizerSuppressions + +tests/tsan/blacklist.tsan - Has TSan warnings we wish to disable +at compile time for test or debug. +Add flags to configure to enable: + +"--extra-cflags=-fsanitize-blacklist=/tests/tsan/blacklist.tsan" + +More information on the file format can be found here under "Blacklist Format": + +https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags + +TSan Annotations +---------------- +include/qemu/tsan.h defines annotations. See this file for more descriptions +of the annotations themselves. Annotations can be used to suppress +TSan warnings or give TSan more information so that it can detect proper +relationships between accesses of data. + +Annotation examples can be found here: + +https://github.com/llvm/llvm-project/tree/master/compiler-rt/test/tsan/ + +Good files to start with are: annotate_happens_before.cpp and ignore_race.cpp + +The full set of annotations can be found here: + +https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cpp + VM testing ==========