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: 187308 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp582203ilb; Fri, 29 May 2020 06:24:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAYiw9V3GVWkx8YhE9XOtlZ5pDDcEKxUh8X47k5+fr/lCxEp2WOcuhnB+1+vmTlkRr8Tu2 X-Received: by 2002:a5b:64e:: with SMTP id o14mr14335573ybq.68.1590758671762; Fri, 29 May 2020 06:24:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590758671; cv=none; d=google.com; s=arc-20160816; b=L2bMQ+/lpUW6xiFiR2dSarhmfG6fOp5QKblv2Tvq8GDGk9LO5pnM6lf/E/D3ZowBS7 zABYx0459CFiczFWNZjNprpGbvRN6TW5gvRggYaopQKFrrbB9oBQcfehFpBMf7/fzVd0 ISzM5/s+dOX7k7wIeyw0dsFME2awQUK//xnCFEw933s20Eywt2Lzu3a1OfS3o8ipb1GS F/O8YkrPDo01bZqW4RAOjjHqu9wqEJb7tmP+MjvMFQiegqGlX+qmrclMFWSvuCSDfKIe ZPugWSs3I1p6dRJ/q3f1dE5Ghv9vCPbf0YaY9ziTy6oGMEotIRPLZs2Ix4McGix/E5aO cwpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:message-id:date:subject:to:from :dkim-signature; bh=iW7IdIzsC9AFT7A/HgICb/ikiPzXalvsYjSvDjiUN+g=; b=jLcjEa2aJkL88bJKcvZg7wuh/ANIZBZdMUnGgEwXHvUy0nBTrp3KN+RGmkKGqu1VcU TreQHCE2XNQQ0j7hrkM16Sud1ufE1dFX0ziouR16vIJ363iTcRlHfjsCoNvhqmcJW2K6 MjRn2cE6I5TTB04ZoHzX7UmTLmgNbH46jv7zAb3HADrjEP5rYSlikjB/s1gL+67H00Ik SoOhm1OyfhVkz2UAVBK6lZ2o6Oxyp9IZiZkgsviGys+7k3XrHPjNggYnuD5ASLGu0/Y6 VqV5bIodHp8aaMH/uD23jsPWsT+tbmi3hX+koTRGoG2XicAxpNIywH/8lIoyliwDhLJy 1FLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VF7LL2Fu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i17si7748276ybl.425.2020.05.29.06.24.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:24:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VF7LL2Fu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeezv-0005OC-5c for patch@linaro.org; Fri, 29 May 2020 09:24:31 -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-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+patch=linaro.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(-) -- 2.17.1 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: 187305 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp581626ilb; Fri, 29 May 2020 06:23:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZXp1U2bgLPrXcRk1tScQCWdyN7D9/DjfflO2FdgA7nmvwHds3REk38Po7FU8u5zELMd2N X-Received: by 2002:a25:3203:: with SMTP id y3mr1804165yby.77.1590758631509; Fri, 29 May 2020 06:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590758631; cv=none; d=google.com; s=arc-20160816; b=Q65SWjklHptR7yCxEZupUQBzDuuoOdolDWb3tKgjLFaknIw4eTAGNYtUSf3J1uc207 4FJIS9873qmaqcOT2AifHkm60A+DKz1UYPlAv476PBwjF5Tv20Nd4O3uA8EKBsS2f0LH 8s9/7AAH6Wma/Vgxq+6PX0BLdJmbuW2LiY0HW7ZyCErx689pZyXxBLeO6UC2JBn2/IdI y2/npF/Ro+D8ez37QltmUp66IVlmMYdwqGbpbcV/vf95dls5kTpajHb/o0Pk7vNZaXrx ogJ7Jm8qomqLc2uFi9zuqdpp9t5Zq/pF2+Inr+hUFqwR/9Z2/Z3MhvlF8GLXLGeTu1aJ HjHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=RseCa26F61nDIy9E0oS7cXPax4VaGb6c+jHKYyFKj1U=; b=V1Glp59BXRRPz4wNYgLUOEM3l7k0DcvGweJcpYxO7rIQDtXCSZumM75lgmD+oWkNzZ P2dbJ/CNiEZkCSAT34sqCKzYVuk2StRoSofiTGHWTB4vYuxADCt22r9b02GoriZJnO35 +tp/rwqTCNRj3mxBbjDCXFSLSckbeROD+Jxz8godfyVpv5TK0oMpNe69bmHT0k7W5OuC FJCNEFkOMxNxqGeiROuNoOzXN3TA1yuEY31tDg8NWQ8VeznbCN2zQCHDIqP5KTznEo3q eP46Rr9Ta0VTmN5FgsWSeBf9bwenXzgLRzr7ln9WM4wjeqe+zu/UlwNboUa8IeDql4Jo oKig== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=pxDAMQAJ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w1si7952112ybp.122.2020.05.29.06.23.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:23:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=pxDAMQAJ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeezG-0004GD-T5 for patch@linaro.org; Fri, 29 May 2020 09:23:50 -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-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+patch=linaro.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(-) -- 2.17.1 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: 187311 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp584022ilb; Fri, 29 May 2020 06:26:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIjjGBNJbAxPTH0sDsx3chFQUGtbPSgKAknkB9NZn5cAkTy7anQ3fPn9zGMz6N6FG9h25U X-Received: by 2002:a25:bb47:: with SMTP id b7mr12575673ybk.200.1590758806960; Fri, 29 May 2020 06:26:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590758806; cv=none; d=google.com; s=arc-20160816; b=nGXZkEQNiflzWUFg2xjZgz3nlMpJK8KgX50Z5fhYAHF7xyv9wT/nmxpqWFxzolF9H/ dW1oFUELR9BWkICKc1Gz0gSn2FENTjP1BdPR75ksp4UuPPiahRMLDkTO6LNmNctPnzYm KBH5nQt15kthoURct7L0kNxUxlgqbYb4KqCps8hHBzPS6PpAq8bAcvwPfb/jouF+BlXk mfWl4Y8wJmu7dRyp3qPaUvW3QRCEzCtJnAiGUIEOq7k82cxOs7xb+3dpZwUO4EGYRP3A iu3Pd4+cD/5VAni58tXrBj82gQcYAIhtB6JkBNHaJ95wY8LHyZ1ReNYaAftu3n0CVOiM 7uOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=wgvUXG0Vlnhy8HNXWH/V4PveTdhkLExBdueTuZ9bPNI=; b=QeZ1JX3qyLXweuxS3cNsbLuM9Ytg08xa8wKIE2H7uujP4CUfKi2zBUK30RLPnkTOMS bBlWRXMETZQgImlUMJZV/y/eTJgtyjRYxOKZOdO2rPAqnMheC3CLdBePd5X2sM2+mlBA bJ9NHx07SXi9jIwXjZuMTLrhavIsz7VWFktU8XZ0+vkmQMpSqkjP6liuPJizJPkLufgv puGssNzG/P8DWpOIZwK3xZ8rUEYVeTTG5V0QJx0JCgCI//DvLJLzQp+u6QsypQFMdybt sDq5K/Amz92aW4c66A9JUc+CQGJ0oZZDJqAnLJ5KISbsYGNXitoYrNvjnxfyUnwjtLW9 wfhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=pgjpq77t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f133si7340284yba.445.2020.05.29.06.26.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:26:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=pgjpq77t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef26-0000aC-D6 for patch@linaro.org; Fri, 29 May 2020 09:26:46 -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-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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" It will be used for TSAN annotations. Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley --- include/qemu/thread.h | 3 +++ 1 file changed, 3 insertions(+) -- 2.17.1 Reviewed-by: Alex Bennée 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: 187306 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp581689ilb; Fri, 29 May 2020 06:23:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMZ53YbMZp49XE2wkT8SeukPk71x4nLGOQdz+cuQZTH0vuXMsnAipr000reMke7jKrtGXR X-Received: by 2002:a25:7b41:: with SMTP id w62mr12681086ybc.435.1590758636041; Fri, 29 May 2020 06:23:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590758636; cv=none; d=google.com; s=arc-20160816; b=0fQ6OrGHww0y6zi+z17AY8Ap1rgo+FTv9U8yEsk0ZrOecUte9aFCVqNzc6BwnuY+0J 04E5cnloRubyYWoYufjykAR11sKFp5R+wOmaIPk1Up6FVRGhy1DtRvQb+KZ+XQWXvtgW WQHtTx7PBNY8QdLGZ/CyMr4n5nIZV6Gw/V0H7sIpSytixzyTbybPIMawsVk/6/wIbl6x G6PBxOWO0NnVP3ubfn2/s8jdSLKbVe2jbOkHIVcvMud4g9fuyDnLARD/c17QHfrQQL2C o1le/yyJA5vxWBfJp0j3DRGR0W948CyTcj3SDNUr479jKglhaezGUY98uRWTMbSghEBR q1Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=aGYJ5nJt/JAH6FWXmjwSAlg0Omv/+y0t2oEMaylOlqc=; b=aHqCTXnSxehyIJFqXK1LruybRLPJ90JlEpXxS5RKkD3u6p8zEDAT1MldCDycf334sT VlqVzSoi1wJZ08yMtpF7kTaB26FlBeROnd9RusuIipfG6Lp/z0zXfqGSAEF5F+f+i/tr 9IPd6Y8iC+COKA6+c5iMdena3NYI6C7wuKs7m3TOL9yexn/eVOtxY2ZSTmwlUlGCyHsn vj4SKgZ8iyjREY042QyKueOvKIv9zLN3yDnqpMY2QRiStdNOV/avN/2h9f4LZpO1DDD5 kUEjXuHyFPZIeT5RMx8/hoOZ2DyKVBuZpfaaJMHWwoabkPVEwXCi0l8rDGASeSLEPxQn Dg4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Q1hyMGOh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u9si7768759ybu.360.2020.05.29.06.23.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:23:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Q1hyMGOh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeezL-0004NP-H5 for patch@linaro.org; Fri, 29 May 2020 09:23:55 -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-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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" I was after adding qemu_spin_destroy calls, but while at it I noticed that we are leaking some memory. Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley --- accel/tcg/cputlb.c | 15 +++++++++++++++ exec.c | 1 + include/exec/exec-all.h | 8 ++++++++ 3 files changed, 24 insertions(+) -- 2.17.1 Reviewed-by: Alex Bennée 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: 187307 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp581748ilb; Fri, 29 May 2020 06:23:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzqZMwP3pmsQJQ96oRH6V6aXVvpCEl0LNHPCQo7xo6jiL0GQZYFCyOKRzi7J/C3MPBqnlv X-Received: by 2002:a25:9d86:: with SMTP id v6mr13660722ybp.322.1590758639233; Fri, 29 May 2020 06:23:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590758639; cv=none; d=google.com; s=arc-20160816; b=jaLXVwQOKC+7jX/xuQkglA/jcNi+xjkSnzFH90cTLmUHcZpfjSwi6Z/B10f2S005+a YKtqPY62RN+A3GGe78JH5+t1bo1/O9GExU26agA60bv5wz0Lxhsv2UBVXV0H5IvMJ3Mm vRAO+BdjOQl1uH1ggyeDwCq5noNkKPX3ixtewl+TyG6lQVX5XF2FgLBd/Mf81kCzRDZF cpQrEVY/4j3lWVx8CVFnavGuD3UZi2efSTSR8ykSOdgzoR6dCiw0ouoY9GSYBe2wSdcF 9WPGA0lMZZmpxDO8osby6t3KT1UJK1bu/WWvx4ZaYNzC8h1US6prATwxHFTittLbCxT5 DSkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=kxh2o1V8iXkuJj8JRvzQtcAUGmlKoLZ53V+la2Fi9CI=; b=W5tAvi9o7TI0Mhk3kvFbrbEqK1Bdz2sxgQL4tC3fm+vW8ZuEpgmLnyLSBMzvS8vC/9 Z3/y/LicPaxl30wTDy00ygQjIU9XkjWhCl4RbhnSGWYCdyYeR/Y+26iSLKq3nE6NrOvY 2uxiHXQRyfBk/tZmxwOeadDiah7jUs9LU0EKo2r+6W95MWW8ZbocrsuV1wjPMwzfyhZi 7P0Y81Ows4zke02wx47jP+BaAAq3Bj0Zb/2QtBoJm3cQnXadyYmBQmrVNWE5nmye3F+Y bjeG8PF04F+OVKo1nIgeHiFDPK0RwpXuyiIZlCIbCRf6lVQjHyL1pFfGuBPIR+mjtzrs OBJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=uNCgit04; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e18si5465757ybf.348.2020.05.29.06.23.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:23:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=uNCgit04; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeezO-0004UA-MT for patch@linaro.org; Fri, 29 May 2020 09:23:58 -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-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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Signed-off-by: Robert Foley --- util/qht.c | 1 + 1 file changed, 1 insertion(+) -- 2.17.1 Reviewed-by: Alex Bennée 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: 187310 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp583622ilb; Fri, 29 May 2020 06:26:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2QdNsAIs5BBTk6x5Q8DIc1jMXceGmsASaDwoxJUFMJqejLwDnke+/SN+4/34wrOA/0edf X-Received: by 2002:a25:6ad5:: with SMTP id f204mr12388524ybc.147.1590758772019; Fri, 29 May 2020 06:26:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590758772; cv=none; d=google.com; s=arc-20160816; b=Yg2a8FqdNCT58U0rDvwsH6MJjBfzlsz1BTppGYRLZRxZaIhLlWQYbTu+/ti6y3KcLV 7MVi1Me3BFKrndgj3glME9TfZgw/76dLuCQEhmnN7pPjN/AkZT7aJy90Kt7cCLvtGDzd S3EOvZ+/UEmc/uYTnXn2Y3xylGc2WF+rjTui8GV97eTQgAf1hWBgzw1//nh35AglLtaj VsufMJDcrHejcC+qJVrgHfGIhzz+lg+F1fD0JQBLh925dX/JwSoJRfmeTIeasuCEK1+L cKBASD2AZc1oFSufFF3CZ3OOIoj1Tv0BZ+Yj8qUImIxQ91kVVk8PdQ3o19FjiJqNwmCJ rx+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=JYiXtqj6gRVqxuRODQQz1eMSRJbQ7+uu1VT7LzsetPI=; b=j4ySGiyZ7m0vS4x4++xUJhNJolD3+bUVTajNvmePboPIHVk/5yEZmEe97fDn/TgstQ xgCa7DyI+dylwapNnPDMiOiwUvb8RTKOaIoyhADVYcigJDx5+datJLuehiy5MhRIyKaO qnEL3MRm2ow14FM04dw2xHCjPiInUopsRSilwT4xP+V7KPKKGY9tCvb+NL3gMuC8uqjm Tr70LZ7Z/Uht0c8el+tJO4iHpHjkpL57nC74pbpB+rzCsM6YN06iyHeW+3ZyvADH5KG9 eGicXzHNOd7x9s73x0OSaSJSDnQCPuV74kuEDMNj09179/3G/dQVYGAPnEtoQMXVpl6E HLrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="rkVNg2/p"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g15si7680837ybq.351.2020.05.29.06.26.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:26:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="rkVNg2/p"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef1X-00083S-E6 for patch@linaro.org; Fri, 29 May 2020 09:26:11 -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-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+patch=linaro.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(-) -- 2.17.1 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: 187313 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp585533ilb; Fri, 29 May 2020 06:28:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMCIyGYkxtxba4txGXC82J04pHNHa1+HzuQIEc4QOEU1hkHbLdfi2VxaMD3tOzAZGO2XF8 X-Received: by 2002:a5b:64e:: with SMTP id o14mr14367176ybq.68.1590758932811; Fri, 29 May 2020 06:28:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590758932; cv=none; d=google.com; s=arc-20160816; b=YG61GrFW/YEOf9VX8mYcGVV2ge5cHrhA4ht1cDxNhYUfOWR/G4x7Otc8lbO1Qb//Ap g2fMlTyxQYGmhlD2drRRBS57ZfhE5UFhMyu0KlFLjj0fXXg5d6C3jerLg7sOmxKGsTEo ASTAELbXqJV4wFDBzI070R5Y/mO3HJUayC0tBOhnNnVKPmJ4E5kmVY4lsDZulZcXmhnf CleKMondM/eFjl5IkCucJVVWjiV8zcAVY1mqrmCmfF5Nt3ta1ONsurKZLjmbFJY07qOy epccCVarrmOoYpTSfkiH4NwAjM/8eSZDI4oYI18iXe3kCEwovEj3FvlnyCJzPsrR70nG 7nwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=v6Twul2TWinr3wq/OK/PDzXQA1fcuJlgD8ranJI4BbA=; b=bpsaN4znaqVfKIVD2d/S/AZRez+8D/wxpko3qN3QwGhOoChEnEVfpglBE8g+d6Z/2q bw3W5KTzB65N5IhwoUL574E3YAUS6RWKEWDnImx7tBq8elJM58QxQcSOvmLbklJ4ejAC 7h6KhUjCfYrnJReSDBnVdYx3C3h7p0O7QCyWwN0NARyqRKBfBUy1sKr7CM62fL8utPz/ msxIAsEmXtmDIq7dM7DoMMQqWkveuXvEQH5xQ4yGiohwSdc244z7F/jELU4GPQhZcVk2 3f4cTbp6e7+ESahxZ7aMCnuE+IywaxELUZXSDyEYL3Ees8u2LvbGffz90w91rkGIyURb rhTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="Qe/NoSKm"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q1si52470ybg.41.2020.05.29.06.28.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:28:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="Qe/NoSKm"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef48-00043b-Bs for patch@linaro.org; Fri, 29 May 2020 09:28:52 -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-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+patch=linaro.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(+) -- 2.17.1 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: 187312 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp585066ilb; Fri, 29 May 2020 06:28:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy92WLLaeFnGp0dVsLyoi4Bd5yYShlBKJ2gHxon8DODRw109SQ3h7XSQnZAegx7ZuIPhi9q X-Received: by 2002:a25:b94d:: with SMTP id s13mr12865656ybm.289.1590758894568; Fri, 29 May 2020 06:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590758894; cv=none; d=google.com; s=arc-20160816; b=MKi7srnu0hf0czewQ+eELusBtzOfc0egQ019oezx9M8S8Svj6Y5jV7pzUnWIsJ5uDh WXawPT8t5ygpZyD0Bag/t46Ognu7gPBqigRdWNbIyzHAenjstA7OCB6rdJ1/MR/kLHSl eKnxe7Wln9wRIBeAqiOmd54WKfHCdef8nwNLCkY99IoS3r7L5m2mWMVJYTV5in3rh2Ta 3d1Y2J4e9gHjdpp2oq/eia9EZva1yvP6KUO1oNOrTh43C7dNbaMjJ1T+d5xj6GOBabUW UzNkkElvfBnCJaRfxM/LzJNeYfH9zBhzxETLj71S9M3vI9EClkFXZKdTD7ph9q/4EH44 SyRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=mGW6wnv9FlzkC02Bo8Bk1So4QHTwo22NecRxOgB5aoI=; b=NoSYtNlmCAs4hFyp5eMel2IrHkltqPWj9T5Slud2V54tqGLM3gL+UqqjkSDDPt9upt lK6CL/Tgf7z3VLqx2b04gh3teatUtQaYNK56EzWE4VlCwtTwrHIsEm19wRlYTvMHvzvi KHzRMi9bmSk9LKAQHuJu2JVjyDm9jdOZtOzAllFA91AVzmopAOlj/XlXj97jCBmNb5PL 9MH0v7Q65xlDOdttC98mwlpgjPkIDsECB12GQJcUm+t7fweK9RMw0YKjDD+FA7m5yhvo kx7cJBHHXhbe53DUOvCN05uWmvsq6U7los6EZ1NVSDAn74emlBxa4vVqY6cukw6xFk9S PAeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KFzDwUz0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p198si2199886yba.481.2020.05.29.06.28.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:28:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KFzDwUz0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef3W-0003KG-19 for patch@linaro.org; Fri, 29 May 2020 09:28:14 -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-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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley --- include/qemu/thread.h | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) -- 2.17.1 Reviewed-by: Alex Bennée 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: 187309 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp583588ilb; Fri, 29 May 2020 06:26:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxprMYtyH/TDmD+0It0KuTi2c7YTuYCqosiD1GnpHt35RsOi0+/eJ3RditM432IEKyDMrdp X-Received: by 2002:a25:3758:: with SMTP id e85mr6673929yba.93.1590758768874; Fri, 29 May 2020 06:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590758768; cv=none; d=google.com; s=arc-20160816; b=ohkf1WZBf9I9e39v8YzDQV1+f/tn5+sWvQn6UGEWiSpRBoLcJoeruH7qPkN86j/qY3 DNWQk+/Ix4u14lKY//viJZuYOFfqJfsim8hv2g4Z3n3wQbwj+ldAX3nn9cMveuriMowL oEN0t3H5hXyv4LQSO0AnY0MIlWTM58GBM4GhFWIfDQNoQtV3EY5r6REQW0gxeI4+Q9LR SOPiy6XToUmqfU6h2tm3S9IIUY18pZV8lAbUjY7HZMaix4txOOq80hOs3JY6rbiuMN3w qJJSDP7CMIixR8WNU5IxfrSlbRzxFjNta1bMbWf7s0vUBpfGewPI5/wE/Y+xRjO+l4IE 2P3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=fk2ImFtCAweaJwaiXMj1+yvDhd6ngpBz4DJyDjLrY1c=; b=ALo9IJ79i+kejiHrl9wHrU0kbfd5gO156jCLWgEM9V5vj8/C7Q75DrCX0cbAaUrpIr 5bELgV8hRJr57dq2qHv3tX15722gHX2kzFh0jpW17O8d/mqs8ghYRTGgMSTlDaXu5vMB Cw73RJ8DHKYqTFrtoXqiBkl6NqKV8fDd/LRdKOyaC4walSYezWOLCw4dQgL3KkogeYAl /Mmt0Upez2IDF8y8iv81xIR3GJO+kKxJ1fgWYqBSFGGxoDuoyAxa8vH7vHnOXqsDocNu RQ6sryLykPL0+TLehLU/cZ6EdFnF+hvVhHKp4/MJz2Bb5zClpL98fn3ms1S76iqXQ1HZ 86hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=BjIq0D9R; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l15si10345130ybt.337.2020.05.29.06.26.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:26:08 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=BjIq0D9R; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef1U-0007u6-2t for patch@linaro.org; Fri, 29 May 2020 09:26:08 -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-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?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , cota@braap.org, peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.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 -- 2.17.1 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: 187314 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp586513ilb; Fri, 29 May 2020 06:30:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynNt24d1njgnmMDWxMfWHAHAEcDhHip0SnkvZJbhZb0C1nIH2aK4jAPU7+j1nu8roP4EFW X-Received: by 2002:a05:6214:186b:: with SMTP id eh11mr8093199qvb.35.1590759007909; Fri, 29 May 2020 06:30:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590759007; cv=none; d=google.com; s=arc-20160816; b=Z2gpKw4dxcYnRth3HI05wmRptAmbnTHHbfcmff6tiGYCJLSEu1aU2CwOsM9Rb15fL+ ns8h9a/VviqDpt8iMCdMyZNdJbLVvfohrSUgs/5Rasu2eNZs5t9DSjQdYCW6LpaLhlHl f7+AIxtvmU4iG4AgqvH6SZ1D8/QOu/K49Urwuku6B2WhD/OCbV1+HfMS0uya7sG09UuH vlErR8XznIyHM187ISRTM2HKlJHso1OBt5UxnaNHeSi/lKShp5cZaNzPUPiEUP+2/aoQ 9LIh0M1YWGZMPMngzQpDmlwREvrJ0MSTFTj27UsoeLUtROCy5kZKddVEIKH8Gi++P9Cr I/yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=AOzUAJyFNQB4L+phqsSsfzj9Z8OtZxOrajLi9NoXesk=; b=ydcgl47Pm6W+gZBnliZbqxH7FmNLx2YcsU8HDYc4sUVt7KG+6OdxsM7+SJsfto9HxZ 3WYIyj3QElvc94HHloK8SIRgn5+GsXTwVRgnWjwrumoRiF9yvmzHKpuS87a8Yd3YvpL4 Q17iaV1BaRBkSVtOuGyO1fPV4Z8pU8pSDrbsTsCxiM9gpqCW0Cak8pCWmZ7VxhdeCc1N zS4ZiPmv7KfDQR6j6fhHbIdKmiwHq3B9PZdI8GG1T8+Ac3YskZ5y4hRD6xIVAPUm1RGc PVE9mkgLI6va70Bqksf2GKdKOJn3AwR78zobipYQwKAuckJT20SzqEQlgzz/5YEjzU6f BBjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xiceRRG+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x3si2209381qvn.6.2020.05.29.06.30.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:30:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xiceRRG+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef5L-0006WM-Aw for patch@linaro.org; Fri, 29 May 2020 09:30:07 -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-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+patch=linaro.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 -- 2.17.1 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: 187315 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp586815ilb; Fri, 29 May 2020 06:30:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEwAG7tFFRGkbBtn6xBNlwFQytkgcEEaAnVxW8lXUcxgnZvVUpi0kJixInwhyzLmVbiR7n X-Received: by 2002:a25:e0c7:: with SMTP id x190mr2634448ybg.263.1590759028990; Fri, 29 May 2020 06:30:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590759028; cv=none; d=google.com; s=arc-20160816; b=XC2Tw+/S2XY0IqAprh6gs7MiIDkMKnvvPc6wjA41J6j9S/5PaqO6riI8li5/O3Bu1M RDCYd2JLIRGm0JW/S00L0JyOdzJ0y4at/RUZJ7uK1/VDHTwV8jqAEmqIJrEMOQ/8L41t XSJYZCAdyyq5/QGLlT4ZHmrT2umKE+Ud70ErtP8nWiwBD4NyHYfcbny1YyRoL2lGhRGw oYBTw7uKllnDIKNauJMHHHEX7R3NAP5Xr06Ayaz/E1eUTquGU1UZi+/9xWAe0aXLozkD OuGDg2bolbwb56xu0bFCf3VF1e3AM9gwDt9iVjBy2ThSWjrwK1tOqPX7248B9OtsFjkI fsng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=yJ08HengHm5gv++XKOUrrTtG6i6MD5Dt3ZAL97dGxmk=; b=WK9vYeTFJYzqkS5JogHu4FZ3C7iV+MY8ser/iE5Mys2vs8cPUyK6K7reRvQvglWDwM uYAIVNNNdoQkmbcMjCV5WF+8Xkx4wJr6LMuky3mTZj1494mdBcgQZYxUT6KFlChLAAEO exgmzxNttdFGhptLaRddsz0+6KjGwnq4dOF6cZlqkAQFpljgI3FTATPdx/HuSco+QdPy 95w3XvuhBanB162SPiVwcPtZzhBi8h6l5J4qaqIlcUPZ6STj9NIMfRrygZFMSSVTFQEf NhC+iL5S6iuEqbWYk96/Fyp8I6f2WdhT3Jn5kahclDD3P1K18YvSJK96Wn0t4DyWoMTG 2K2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SkTUCqwc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n136si8090724yba.479.2020.05.29.06.30.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:30:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SkTUCqwc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef5g-0007SE-GJ for patch@linaro.org; Fri, 29 May 2020 09:30:28 -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-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+patch=linaro.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 --- util/qemu-thread-posix.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.17.1 Reviewed-by: Emilio G. Cota 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: 187316 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp588548ilb; Fri, 29 May 2020 06:32:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/IlMlVnooFDbijaJ7gnZwqsXHiKqw0ybkROqXRe0R+qafD95gU0rNTYnAfcmfJn+xQo67 X-Received: by 2002:a25:338b:: with SMTP id z133mr12547266ybz.99.1590759144478; Fri, 29 May 2020 06:32:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590759144; cv=none; d=google.com; s=arc-20160816; b=Aa3iX2lrspZ9pahaOXSOGFv8tXnp76O3nSeIt+e5JbGf40nW10bJkM7GaikNUq4+bV Nu/YQzCX5eK+BzqbvXrtwNiTHOkqdo5pJt9F7aI2UeO5XYXX4vbIiOl/A/AstEIjWlcp W6HEzFrIAE30WsWxQIToniyPRpQornc2HIdEiGR05JeMoZIIk136HUN+lan4SIxsUjcc tr3xUNHMZsUb/ejkujYCkFp0yp7m0F8yNc/BucXaHY3POdYRYUQxRyd0qhnXhSuXDuET r3/MVszngNuMFLq9xg656aZD/PqfYEhLhFwJY03aZA2aM1xpR3FknDvU3btzpd98tpE5 YRQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:message-id:date:subject:to:from :dkim-signature; bh=sMSUvaGVYsjE3AMoDsJ2TYvIyY2QCzLj9JPqQSj65XM=; b=WqnGi0u0Wu52EO/b/7mEcslHBCcx9oAVdRGdaGozNxwrtWWrhjDzjcdeYZwUVbQ+zR rkQPxjhc88L1nQle88pezC3PxYye9ikdUb88c+xXh3j08l2eFAMdT5INqgEPxJvpiJvl AEf4mUCRO4+Oonjcb1uTHbjvDFU/tIX/aa5GcZhFNnDjnfWeqrgrcS3JVpoVqV8AGVO3 E2bDA4bP6sO3uHpMzBF95I5778ORB2tX+i4Cb38n1Nj/pOooHz7ILG6vi5N3m9oh1v0O IxNC5OqK8MZLnk9AuJpRKl1cinhbVFOyGwiMNBOyvnV7qbtXgc9pjLNFMXfAGOrUEeeh jgeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=blVp3do4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z8si7140138ybg.74.2020.05.29.06.32.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:32:24 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=blVp3do4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef7X-00023J-TE for patch@linaro.org; Fri, 29 May 2020 09:32:23 -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-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+patch=linaro.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(+) -- 2.17.1 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 ==========