From nobody Mon May 20 22:40:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591378714; cv=none; d=zohomail.com; s=zohoarc; b=fW6vC9qbPqnSb4vVm72XSgb5oQ43qCWunj2GdO6LDmb4Cy7FxGimRF5u/BVcEIQrhH93EGKdZIbRyzNCzAi/1n9S33WG56IM0TcQAgXm7Gp301jvaogihzdNLIYNHJT3awJkMwSzI1BqQ0yW+2Y5xcesJrfTORQdn0kt4IKCvzM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591378714; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=PolYfWsjQxLFUFecxYjpFffyz0BlbK4AQIvIQhTtHFk=; b=EjydJSa99gG7tiPZfGS9+uXdg+dohGrUGlfmxR+Z28J2HXFg7c2040GBPEaz0v4C5KtOeXjQjuHjb5Qx0XHT6GQ08YeCeA89zSx2aBgWazZgwNLHYClhI9B0nqlaYFW/hiVU8UvgmxyF4uajpv578+nMV3OP5kFE/+mB7y8MftI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591378714098856.5358395134701; Fri, 5 Jun 2020 10:38:34 -0700 (PDT) Received: from localhost ([::1]:58340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGIa-0004vU-Jt for importer@patchew.org; Fri, 05 Jun 2020 13:38:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGHf-0003Gy-PE for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:35 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:33958) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGHe-0003pr-El for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:35 -0400 Received: by mail-pf1-x444.google.com with SMTP id z64so5296232pfb.1 for ; Fri, 05 Jun 2020 10:37:34 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37: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:in-reply-to:references; bh=PolYfWsjQxLFUFecxYjpFffyz0BlbK4AQIvIQhTtHFk=; b=frrsC2Elmq/htA0uFNhU4ByXtqejBBJec9CpBtisYiHUYZfniReqC1lrrUGNczcoIg zFm1C9ESCWw3o9gkEkuYArO2RP4nxXWJC4VV0HI6E86YhNOg7LvdP1uIOJvgpUpNkfyL ZHOV5UjOOHnBtR0Y1PeGdBHlD+WhJN3ivXktJ3g7EGf/PXAyuI5O0pOZLWaylsMiDGLQ oxDgANy3zH09suNVRpmLFCzC0eZEEnC9grot77r35ldUs+UI9n1qrxdVKW49UWwED1yN Bv1fi0/qDP2Iold2kaIE2Kc9ZXZ+aVNE1tuW6u2MryhrWJaIt9h7o95dqnSWGmyX9oZg jipA== 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=PolYfWsjQxLFUFecxYjpFffyz0BlbK4AQIvIQhTtHFk=; b=M37pjFFZzFhWI0sH6iH5dyFSj6i5f7t+w/nDW+0JKAPDWJ2ZdZZTMLi6tTrptMlGIn RfqxUJ+RXRbkxc3ARtue0MSoo7gLqBLXmTbsEQywOAS7SuPfdjveYv0IxBs3pbbMybGc sKG3Oa2ouuXgkuMkU1FpR4Ydj/zGkx6NUl+G713hnCcrnTBegoqPWH1qlVUENDV3hRDa omP8tsmEbewiqrx4Fz8VtWl1XpnYMqvQDstZ4nzOf14hAs/XOxh/b1cXQY02roHuCWvu Q6vAgwsrdDOvMftHmPd13+Yz7gqGPSGSOT54vpXjfr6MeJZnyajDqZ3au6hSpU2ysBNj 8ahw== X-Gm-Message-State: AOAM530dP33qTP4WxbXppQNcUdlnBZzfBGbe2mmSBkvRAICMHnGzXFJh eG1o9W4oimN8p2OG47EUMU0jgVR737iROw== X-Google-Smtp-Source: ABdhPJyd6iqN+f2lZcfB1N+jhvme4nlL2cxYXx/SzPpgifhA9THzo37JpRM6CpCTZ+mPSprF6YBHUg== X-Received: by 2002:a62:2cd7:: with SMTP id s206mr3403909pfs.305.1591378652406; Fri, 05 Jun 2020 10:37:32 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 01/13] configure: add --enable-tsan flag + fiber annotations for coroutine-ucontext Date: Fri, 5 Jun 2020 13:34:10 -0400 Message-Id: <20200605173422.1490-2-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , robert.foley@linaro.org, alex.bennee@linaro.org, cota@braap.org, Stefan Hajnoczi , Lingfeng Yang , peter.puhov@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Lingfeng Yang We tried running QEMU under tsan in 2016, but tsan's lack of support for longjmp-based fibers was a blocker: https://groups.google.com/forum/#!topic/thread-sanitizer/se0YuzfWazw Fortunately, thread sanitizer gained fiber support in early 2019: https://reviews.llvm.org/D54889 This patch brings tsan support upstream by importing the patch that annotat= ed QEMU's coroutines as tsan fibers in Android's QEMU fork: https://android-review.googlesource.com/c/platform/external/qemu/+/844675 Tested with '--enable-tsan --cc=3Dclang-9 --cxx=3Dclang++-9 --disable-werro= r' configure flags. Signed-off-by: Lingfeng Yang Signed-off-by: Emilio G. Cota [cota: minor modifications + configure changes] Signed-off-by: Robert Foley [RF: configure changes for warnings, erorr handling + minor modifications] Reviewed-by: Alex Benn=C3=A9e --- configure | 47 ++++++++++++++++++- util/coroutine-ucontext.c | 97 +++++++++++++++++++++++++++++++++++---- 2 files changed, 134 insertions(+), 10 deletions(-) diff --git a/configure b/configure index f087d2bcd1..9b50820366 100755 --- a/configure +++ b/configure @@ -395,6 +395,7 @@ gprof=3D"no" debug_tcg=3D"no" debug=3D"no" sanitizers=3D"no" +tsan=3D"no" fortify_source=3D"" strip_opt=3D"yes" tcg_interpreter=3D"no" @@ -1150,6 +1151,10 @@ for opt do ;; --disable-sanitizers) sanitizers=3D"no" ;; + --enable-tsan) tsan=3D"yes" + ;; + --disable-tsan) tsan=3D"no" + ;; --enable-sparse) sparse=3D"yes" ;; --disable-sparse) sparse=3D"no" @@ -1750,6 +1755,7 @@ Advanced options (experts only): --with-pkgversion=3DVERS use specified string as sub-version of the pa= ckage --enable-debug enable common debug build options --enable-sanitizers enable default sanitizers + --enable-tsan enable thread sanitizer --disable-strip disable stripping binaries --disable-werror disable compilation abort on warning --disable-stack-protector disable compiler-provided stack protection @@ -6192,6 +6198,30 @@ if test "$fuzzing" =3D "yes" ; then fi fi =20 +# Thread sanitizer is, for now, much noisier than the other sanitizers; +# keep it separate until that is not the case. +if test "$tsan" =3D "yes" && test "$sanitizers" =3D "yes"; then + error_exit "TSAN is not supported with other sanitiziers." +fi +have_tsan=3Dno +have_tsan_iface_fiber=3Dno +if test "$tsan" =3D "yes" ; then + write_c_skeleton + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=3Dthread" "" ; then + have_tsan=3Dyes + fi + cat > $TMPC << EOF +#include +int main(void) { + __tsan_create_fiber(0); + return 0; +} +EOF + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=3Dthread" "" ; then + have_tsan_iface_fiber=3Dyes + fi +fi + ########################################## # check for libpmem =20 @@ -6293,6 +6323,16 @@ if test "$have_asan" =3D "yes"; then "Without code annotation, the report may be inferior." fi fi +if test "$have_tsan" =3D "yes" ; then + if test "$have_tsan_iface_fiber" =3D "yes" ; then + QEMU_CFLAGS=3D"-fsanitize=3Dthread $QEMU_CFLAGS" + QEMU_LDFLAGS=3D"-fsanitize=3Dthread $QEMU_LDFLAGS" + else + error_exit "Cannot enable TSAN due to missing fiber annotation interfa= ce." + fi +elif test "$tsan" =3D "yes" ; then + error_exit "Cannot enable TSAN due to missing sanitize thread interface." +fi if test "$have_ubsan" =3D "yes"; then QEMU_CFLAGS=3D"-fsanitize=3Dundefined $QEMU_CFLAGS" QEMU_LDFLAGS=3D"-fsanitize=3Dundefined $QEMU_LDFLAGS" @@ -6328,7 +6368,8 @@ if test "$werror" =3D "yes"; then QEMU_CFLAGS=3D"-Werror $QEMU_CFLAGS" fi =20 -if test "$solaris" =3D "no" ; then +# Exclude --warn-common with TSan to suppress warnings from the TSan libra= ries. +if test "$solaris" =3D "no" && test "$tsan" =3D "no"; then if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; = then QEMU_LDFLAGS=3D"-Wl,--warn-common $QEMU_LDFLAGS" fi @@ -7382,6 +7423,10 @@ if test "$have_asan_iface_fiber" =3D "yes" ; then echo "CONFIG_ASAN_IFACE_FIBER=3Dy" >> $config_host_mak fi =20 +if test "$have_tsan" =3D "yes" && test "$have_tsan_iface_fiber" =3D "yes" = ; then + echo "CONFIG_TSAN=3Dy" >> $config_host_mak +fi + if test "$has_environ" =3D "yes" ; then echo "CONFIG_HAS_ENVIRON=3Dy" >> $config_host_mak fi diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c index bd593e61bc..a3dc78e67a 100644 --- a/util/coroutine-ucontext.c +++ b/util/coroutine-ucontext.c @@ -37,18 +37,33 @@ #endif #endif =20 +#ifdef CONFIG_TSAN +#include +#endif + typedef struct { Coroutine base; void *stack; size_t stack_size; sigjmp_buf env; =20 + void *tsan_co_fiber; + void *tsan_caller_fiber; + #ifdef CONFIG_VALGRIND_H unsigned int valgrind_stack_id; #endif =20 } CoroutineUContext; =20 +#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]; }; =20 -static void finish_switch_fiber(void *fake_stack_save) +/* QEMU_ALWAYS_INLINE only does so if __OPTIMIZE__, so we cannot use it. */ +static inline __attribute__((always_inline)) +void on_new_fiber(CoroutineUContext *co) +{ +#ifdef CONFIG_TSAN + co->tsan_co_fiber =3D __tsan_create_fiber(0); /* flags: sync on switch= */ + co->tsan_caller_fiber =3D __tsan_get_current_fiber(); + 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 =3D size_old; } #endif +#ifdef CONFIG_TSAN + if (fake_stack_save) { + __tsan_release(fake_stack_save); + __tsan_switch_to_fiber(fake_stack_save, 0); /* 0=3Dsynchronize */ + } +#endif } =20 -static void start_switch_fiber(void **fake_stack_save, - const void *bottom, size_t size) +static inline __attribute__((always_inline)) void start_switch_fiber( + CoroutineAction action, void **fake_stack_save, + const void *bottom, size_t size, void *new_fiber) { #ifdef CONFIG_ASAN - __sanitizer_start_switch_fiber(fake_stack_save, bottom, size); + if (action =3D=3D COROUTINE_TERMINATE) { + __sanitizer_start_switch_fiber( + action =3D=3D COROUTINE_TERMINATE ? NULL : fake_stack_save, + bottom, size); + } +#endif +#ifdef CONFIG_TSAN + void *curr_fiber =3D + __tsan_get_current_fiber(); + __tsan_acquire(curr_fiber); + + UC_TRACE("Current fiber: %p.", curr_fiber); + *fake_stack_save =3D curr_fiber; + UC_TRACE("Switch to fiber %p", new_fiber); + __tsan_switch_to_fiber(new_fiber, 0); /* 0=3Dsynchronize */ #endif } =20 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) =20 /* Initialize longjmp environment and switch back the caller */ if (!sigsetjmp(self->env, 0)) { - start_switch_fiber(&fake_stack_save, - leader.stack, leader.stack_size); + UC_TRACE("Current fiber: %p. Set co %p to env 0x%lx", + __tsan_get_current_fiber(), self, (unsigned long)self->en= v); + 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); } =20 + UC_TRACE("After first siglongjmp"); + finish_switch_fiber(fake_stack_save); =20 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); } } =20 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) =20 arg.p =3D co; =20 + on_new_fiber(co); makecontext(&uc, (void (*)(void))coroutine_trampoline, 2, arg.i[0], arg.i[1]); =20 /* swapcontext() in, siglongjmp() back out */ if (!sigsetjmp(old_env, 0)) { - start_switch_fiber(&fake_stack_save, co->stack, co->stack_size); + start_switch_fiber( + COROUTINE_YIELD, + &fake_stack_save, + co->stack, co->stack_size, co->tsan_co_fiber); swapcontext(&old_uc, &uc); } =20 @@ -185,6 +252,7 @@ static inline void valgrind_stack_deregister(CoroutineU= Context *co) =20 void qemu_coroutine_delete(Coroutine *co_) { + UC_TRACE("Nuking co %p from orbit", co_); CoroutineUContext *co =3D DO_UPCAST(CoroutineUContext, base, co_); =20 #ifdef CONFIG_VALGRIND_H @@ -209,6 +277,10 @@ qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, { CoroutineUContext *from =3D DO_UPCAST(CoroutineUContext, base, from_); CoroutineUContext *to =3D 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 =3D NULL; =20 @@ -216,8 +288,8 @@ qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, =20 ret =3D sigsetjmp(from->env, 0); if (ret =3D=3D 0) { - start_switch_fiber(action =3D=3D COROUTINE_TERMINATE ? - NULL : &fake_stack_save, to->stack, to->stack_s= ize); + start_switch_fiber(action, &fake_stack_save, + to->stack, to->stack_size, to->tsan_co_fiber); siglongjmp(to->env, action); } =20 @@ -231,6 +303,13 @@ Coroutine *qemu_coroutine_self(void) if (!current) { current =3D &leader.base; } +#ifdef CONFIG_TSAN + if (!leader.tsan_co_fiber) { + leader.tsan_co_fiber =3D __tsan_get_current_fiber(); + UC_TRACE("For co %p set leader co fiber to %p", + current, leader.tsan_co_fiber); + } +#endif return current; } =20 --=20 2.17.1 From nobody Mon May 20 22:40:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591378716; cv=none; d=zohomail.com; s=zohoarc; b=UHM7lVf9kGwt16Ibi8GECgggsQoNz/bj6HlnfoVNXQBBUIdEnBJb8K93yfuXDBHSL4J912/H1VO6IhucZBqNbK9x2fByfiKt/NFuTs00xyBibKdALWhf7MvfR5bgWbRGz1JBi9mAL/4sMOkO6gb1rhFRoybQamS15Wi0LQzMR6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591378716; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QonKzFLvxHetjYHv0eko5X68Tto6P2i1o+bAUOOMVq8=; b=bIFOh/ECarr218UlQDCXvgjEB6dM3RdKxU6uz4pZYNezlfPLcQNhYAljxmXX1CjDAhCFf0FW+u0WnZ7jglFINKpDII35NosnHGzn5aiH+ml7NAN3h/XZWSfJ8rTBjySfAUlIwDl9So9PkwO/GHWTZ3NpjYAZD7R8TqLIJqnnZoo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15913787160541018.94210347881; Fri, 5 Jun 2020 10:38:36 -0700 (PDT) Received: from localhost ([::1]:58616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGIc-000529-O2 for importer@patchew.org; Fri, 05 Jun 2020 13:38:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGHh-0003Jb-S4 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:37 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:34899) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGHg-0003q0-Qn for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:37 -0400 Received: by mail-pf1-x443.google.com with SMTP id h185so5290034pfg.2 for ; Fri, 05 Jun 2020 10:37:36 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37:34 -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=QonKzFLvxHetjYHv0eko5X68Tto6P2i1o+bAUOOMVq8=; b=IqfJ0B/6o/HB9WrnAdz0DzKWhSIhvU3L3BtJurcDXQWusz3uv1YGZvnKy6Rs3X+nWg 5XXLGHGguFT97AAbAjokOTflLlO8dBghVl/0KYD2FAsii+0MG5mJmbWUU1iqkkANWH6K b5Huid8G04XSqnLaybnwT7+/cqUnhzOJste3Ud3rYr+k1h0sL0mxN2juY8D7p9zzlniG /ebMO5NcoumH2H5cwQwHGKreFd4l9wrzaW8mEz1qQLUeZ9kgBm8dDZTV+jpJnfAxhfDw PIQEJ+8ILMnHve/9wjDAkQP8dkg2LGOmxki/mXRV3+eo6+tO1NUrXUWVu8oqOuGLanjL 4M+w== 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=QonKzFLvxHetjYHv0eko5X68Tto6P2i1o+bAUOOMVq8=; b=JAoG+8fpzJrNde8xQJNhgsrGHr9zSgIenUUp43UDT2aHr8sKmqBLKTpQ8kpxPihDXo gWI/1iMTUXM9Va6lzkK2ahDTuNzHF2M+00E/M7Ju0xjfPQ5U1ErwMioBzA1hEOTMri/T 8wDxlFqtcKlkpKwB3l+/KiNynlFyCtEhwfXIsQwlb+UZZiZ7WEpl67hFI2enUOa7Po10 z3mjIUgrqgXBtZOOaD8bj3TVZhjxv6AVDN0I/gzjFaw09o3qE2Xd6/AEyCa13Kt/or65 FYZa5ubSM5QDAIHkw8kQrzsxhRLAmNDFZJTDHOJlRQmga4spjU3NQsrkSHugM6NoMpCX E+0g== X-Gm-Message-State: AOAM533mlCb0T8+m1XBlvyA8zAeQR7PcLC5vE5Cnc6OFLLGFFGnxTOYH nrN1//d522eqvSD8jgVQZuypMXrPPF3J+Q== X-Google-Smtp-Source: ABdhPJw+se9W1WtXmKMZGAHlKna5uJVtR1KGit6G2Og/A2azeWskc6mjc5fG5yMhAuUsBP7/FkDPfg== X-Received: by 2002:aa7:868b:: with SMTP id d11mr10304598pfo.52.1591378655149; Fri, 05 Jun 2020 10:37:35 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 02/13] cpu: convert queued work to a QSIMPLEQ Date: Fri, 5 Jun 2020 13:34:11 -0400 Message-Id: <20200605173422.1490-3-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, Eduardo Habkost , cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Emilio G. Cota" We convert queued work to a QSIMPLEQ, instead of open-coding it. While at it, make sure that all accesses to the list are performed while holding the list's lock. Reviewed-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley --- cpus-common.c | 25 ++++++++----------------- cpus.c | 14 ++++++++++++-- hw/core/cpu.c | 1 + include/hw/core/cpu.h | 6 +++--- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/cpus-common.c b/cpus-common.c index 70a9d12981..8f5512b3d7 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -97,7 +97,7 @@ void cpu_list_remove(CPUState *cpu) } =20 struct qemu_work_item { - struct qemu_work_item *next; + QSIMPLEQ_ENTRY(qemu_work_item) node; run_on_cpu_func func; run_on_cpu_data data; bool free, exclusive, done; @@ -106,13 +106,7 @@ struct qemu_work_item { static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi) { qemu_mutex_lock(&cpu->work_mutex); - if (cpu->queued_work_first =3D=3D NULL) { - cpu->queued_work_first =3D wi; - } else { - cpu->queued_work_last->next =3D wi; - } - cpu->queued_work_last =3D wi; - wi->next =3D NULL; + QSIMPLEQ_INSERT_TAIL(&cpu->work_list, wi, node); wi->done =3D false; qemu_mutex_unlock(&cpu->work_mutex); =20 @@ -306,17 +300,14 @@ void process_queued_cpu_work(CPUState *cpu) { struct qemu_work_item *wi; =20 - if (cpu->queued_work_first =3D=3D NULL) { + qemu_mutex_lock(&cpu->work_mutex); + if (QSIMPLEQ_EMPTY(&cpu->work_list)) { + qemu_mutex_unlock(&cpu->work_mutex); return; } - - qemu_mutex_lock(&cpu->work_mutex); - while (cpu->queued_work_first !=3D NULL) { - wi =3D cpu->queued_work_first; - cpu->queued_work_first =3D wi->next; - if (!cpu->queued_work_first) { - cpu->queued_work_last =3D NULL; - } + while (!QSIMPLEQ_EMPTY(&cpu->work_list)) { + wi =3D QSIMPLEQ_FIRST(&cpu->work_list); + QSIMPLEQ_REMOVE_HEAD(&cpu->work_list, node); qemu_mutex_unlock(&cpu->work_mutex); if (wi->exclusive) { /* Running work items outside the BQL avoids the following dea= dlock: diff --git a/cpus.c b/cpus.c index 5670c96bcf..af44027549 100644 --- a/cpus.c +++ b/cpus.c @@ -97,9 +97,19 @@ bool cpu_is_stopped(CPUState *cpu) return cpu->stopped || !runstate_is_running(); } =20 +static inline bool cpu_work_list_empty(CPUState *cpu) +{ + bool ret; + + qemu_mutex_lock(&cpu->work_mutex); + ret =3D QSIMPLEQ_EMPTY(&cpu->work_list); + qemu_mutex_unlock(&cpu->work_mutex); + return ret; +} + static bool cpu_thread_is_idle(CPUState *cpu) { - if (cpu->stop || cpu->queued_work_first) { + if (cpu->stop || !cpu_work_list_empty(cpu)) { return false; } if (cpu_is_stopped(cpu)) { @@ -1498,7 +1508,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) cpu =3D first_cpu; } =20 - while (cpu && !cpu->queued_work_first && !cpu->exit_request) { + while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) { =20 atomic_mb_set(&tcg_current_rr_cpu, cpu); current_cpu =3D cpu; diff --git a/hw/core/cpu.c b/hw/core/cpu.c index 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 =3D 1; =20 qemu_mutex_init(&cpu->work_mutex); + QSIMPLEQ_INIT(&cpu->work_list); QTAILQ_INIT(&cpu->breakpoints); QTAILQ_INIT(&cpu->watchpoints); =20 diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 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 ch= anges * to @trace_dstate). * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask). @@ -376,7 +376,7 @@ struct CPUState { sigjmp_buf jmp_env; =20 QemuMutex work_mutex; - struct qemu_work_item *queued_work_first, *queued_work_last; + QSIMPLEQ_HEAD(, qemu_work_item) work_list; =20 CPUAddressSpace *cpu_ases; int num_ases; --=20 2.17.1 From nobody Mon May 20 22:40:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591378805; cv=none; d=zohomail.com; s=zohoarc; b=KVLE7k9TUDzKXgt271AgUToegQrfXv2UVCXPDKXYfHUQSvz1i8ihzYt+Pbsj/mGbuj6XnS7rMHhDQ0oe/b7Xv1SdG38gCe5iiHnQ7vt1oTLZtqmuf8EidKfssjkXGHc1rvI63vCYBYp6rwds6kQLjWxr5af7Rfcb/o5DZcqBSEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591378805; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hi7LUnC/2Vxc6CG4AyW71h/9KhgELUl20yMZDhooBMo=; b=fKkgMYwyFm41zaXBhoMHs7JvU/NQ9PkcN2ryGR47mPyCd5dbTnCctFuWASyAsck+OzItiB1W8shHPzsqYWbut2Mxs2j/L/6DVUV6oqEOfFF4RrxCVdYlcznj76eaBQJeAD9IQI9qol3ihK6o8RXYOFfikEq+xXQga95jFb5v/60= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159137880535749.683158458547155; Fri, 5 Jun 2020 10:40:05 -0700 (PDT) Received: from localhost ([::1]:38834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGK4-0000ZZ-12 for importer@patchew.org; Fri, 05 Jun 2020 13:40:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48144) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGHk-0003PX-0i for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:40 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:42956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGHj-0003q9-5m for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:39 -0400 Received: by mail-pg1-x541.google.com with SMTP id e9so5493054pgo.9 for ; Fri, 05 Jun 2020 10:37:38 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hi7LUnC/2Vxc6CG4AyW71h/9KhgELUl20yMZDhooBMo=; b=OVmbaf933xh3+YjoGnMzeKhaIMEES9/YNzfNkwU4WoU4wV4VsD72CXkV5csQ8rH96p SGNxx/1QpdRtfP/na6jfrSOPETR6s177Pkw0UB4llk/Tps/G1R/L8c/i8zvVNy8d1poT tuonWtc7WTRAqnf4JXd/6DGK989PV/wzRqN32OIJ5Sze5eE58MXE6nvxBQ00FtSC9gIv 4rMSDCIkQ3j13V7fkocxbt5BObP5bz1G44RJIerfaEjbfDD1GTSEfHAlGMlsXm12vD1o mEmx49o84FE5doG3phUctcF0FnNWq12omdU6IK4vcaS90OVik1nAzJvqhA9VHsODQJe9 771w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hi7LUnC/2Vxc6CG4AyW71h/9KhgELUl20yMZDhooBMo=; b=DfZ7TeFVfNqy6bCvsILBS9RDdqU4hm5iopQr8L1SLxwIQNg6JBdMNV6YqaIiNiNYIk mUVacYHx5SMig6kD9c8WwQetlVs4x7Eo76quld0+kDg4r1ZQhovYIwGGY+n0F49OTyNA vQp56J4/0bhr1YP5AU6dIRZkerb5VevZJyp7DkSkWlw85I0vdXX5dFeqvEnEEqnDO1Gw Fl8Xmd3li5u1PngCFRC/58smGz+OIbab6lQ8Pj8wsT//nKOWsU2jffUV+8A4ynJWXxdT nF4uZsGreYeV5ay/LCaUzVFQiUw+zaocdjuDPZnTfbM5qFK/X41ECqmuS0+Bj3NAsKpZ mybQ== X-Gm-Message-State: AOAM530oO5RcoJXCeIxUyiQvVffE4slqlfG6Qwl3x+zTTku/lmiu+z6x A7iV6aB3U/N/UZqM8EkI34E286CZSh8HOw== X-Google-Smtp-Source: ABdhPJy7FYzw8hFdsg5vb8oQ23ByADcRJvmYYPWoQ6JjCeTdFWmdyoxSvQBO9775/oGkiNO5JmcNhg== X-Received: by 2002:a65:568d:: with SMTP id v13mr10411043pgs.436.1591378657135; Fri, 05 Jun 2020 10:37:37 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 03/13] thread: add qemu_spin_destroy Date: Fri, 5 Jun 2020 13:34:12 -0400 Message-Id: <20200605173422.1490-4-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Emilio G. Cota" It will be used for TSAN annotations. Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley Reviewed-by: Alex Benn=C3=A9e --- include/qemu/thread.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/qemu/thread.h b/include/qemu/thread.h index d22848138e..e50a073889 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -215,6 +215,9 @@ static inline void qemu_spin_init(QemuSpin *spin) __sync_lock_release(&spin->value); } =20 +static inline void qemu_spin_destroy(QemuSpin *spin) +{ } + static inline void qemu_spin_lock(QemuSpin *spin) { while (unlikely(__sync_lock_test_and_set(&spin->value, true))) { --=20 2.17.1 From nobody Mon May 20 22:40:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591378742; cv=none; d=zohomail.com; s=zohoarc; b=JwIYxiAfN3ZzMbi3Xkc4q7RQkA6XeplMCRy5ZF9J2By0DaGypl5xUDBZdm9VcwEC+0dKpHtajXBVouedXvEhGSGLB900Xp8veBeefGimVA+J6wpUORfWtsdBeeUSQ5Th3GZkLIFI+kdKbJHDBBngSGVwm24S91ZfBnCCp6JXtFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591378742; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KA74qkYRKvEU3ng1kAP13z7yTrox0/WpEe+h4sJiZmM=; b=Al9D3CbQt/8BzcRzSW+LpJ+ewhG9Z7/2k/wMZlR+xix+EvTA+zvZ1/298eqKXR8TtzkE8WV+lV3F/Vht6a2W10mygO+xXQVmwaPXxv0W4I3VwumxcV1veiotinDKmxRMtP33REePtqT4S1a+77gkAq8sfIKsN8erakom2szBMIA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591378742761781.3922037365365; Fri, 5 Jun 2020 10:39:02 -0700 (PDT) Received: from localhost ([::1]:33384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGJ3-0006Qd-FP for importer@patchew.org; Fri, 05 Jun 2020 13:39:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48156) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGHm-0003WP-Ef for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:42 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:43332) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGHl-0003rQ-CT for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:42 -0400 Received: by mail-pf1-x444.google.com with SMTP id 23so4392891pfw.10 for ; Fri, 05 Jun 2020 10:37:40 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37:38 -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=KA74qkYRKvEU3ng1kAP13z7yTrox0/WpEe+h4sJiZmM=; b=lw2/Uwd8ZHKoaA5GuN/k3mU2SK9d8Uf+vZNl7PC/3t1lUu8jbQOB4SXaIsVyzWmdan GRPftAlfazcikKZGh4gBeGVRrXrDcw0v9el+qXwSJeajvb9FIm7dLDOJvpJ1oIcOYWgY 5cA+a1cW4kWnp70n1UW0TdbAgwiLFMdAE9yS707VIXCmt2/us8ldRUelEyEeUOaRTcEU H5IiqTnAS0kjIBxhrALY8oAq3EBgvo3zHARtPauxyCW9y+FVzqqjrefoATCSU/3qnDgH tSM/0q1X4P0qVv6Js/wuuDrZRj+OG4ruI6mndCoFbHIUhl/p20t6OWzyeze6QC5C37Tf RisQ== 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=KA74qkYRKvEU3ng1kAP13z7yTrox0/WpEe+h4sJiZmM=; b=JLzUZFNR4ODuhgfyb3CuAESpCsQRIpsJ9L30ASNF7tjrCrSjAH9vLdjfhytyL+aSDZ 43mmRlqA3QlpYdQqFL+vbxyk3Sm6mNDyg8hbp8nAwH95SxSOJmC8cDYzyy3Zaz6yNChy 9sF2eJk71/JX4aHqMtQ2/Bh9bSasd6OCW03c0sJgOwozsSAvb64Xbc1JgQ99Im87V73L NQluhtJRE/brsx25L1XBjYU8FLUSCohOjUiWyvVoiYPKO1r8esoRysUc7wr8kNdydpsu sIInAz7PiiLyl5CvbaD8Mf3FhLpSHoummpa4Cah3/3VZE7O+Drk4y7M3IUA8gtMxHeY7 SUXQ== X-Gm-Message-State: AOAM532ETORFXidpqNQa7AgcBbNp0gBQqwL5/m+rV5Uio/oFrZ5ZNii2 QSXpCjba0TJ6+NObZVpG4z1e36FFHX2JgA== X-Google-Smtp-Source: ABdhPJxA2O96zZ55IsBV3APgiv6CPJKSRMFbChmryneh1OAD2OWU7gaiafd8gWr/JnA4dGsHV0HObg== X-Received: by 2002:a63:fc4a:: with SMTP id r10mr10624014pgk.417.1591378659877; Fri, 05 Jun 2020 10:37:39 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 04/13] cputlb: destroy CPUTLB with tlb_destroy Date: Fri, 5 Jun 2020 13:34:13 -0400 Message-Id: <20200605173422.1490-5-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Emilio G. Cota" I was after adding qemu_spin_destroy calls, but while at it I noticed that we are leaking some memory. Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley Reviewed-by: Alex Benn=C3=A9e --- accel/tcg/cputlb.c | 15 +++++++++++++++ exec.c | 1 + include/exec/exec-all.h | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index eb2cf9de5e..1e815357c7 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -270,6 +270,21 @@ void tlb_init(CPUState *cpu) } } =20 +void tlb_destroy(CPUState *cpu) +{ + CPUArchState *env =3D cpu->env_ptr; + int i; + + qemu_spin_destroy(&env_tlb(env)->c.lock); + for (i =3D 0; i < NB_MMU_MODES; i++) { + CPUTLBDesc *desc =3D &env_tlb(env)->d[i]; + CPUTLBDescFast *fast =3D &env_tlb(env)->f[i]; + + g_free(fast->table); + g_free(desc->iotlb); + } +} + /* flush_all_helper: run fn across all cpus * * If the wait flag is set then the src cpu's helper will be queued as diff --git a/exec.c b/exec.c index 5162f0d12f..da3d60b034 100644 --- a/exec.c +++ b/exec.c @@ -892,6 +892,7 @@ void cpu_exec_unrealizefn(CPUState *cpu) { CPUClass *cc =3D CPU_GET_CLASS(cpu); =20 + tlb_destroy(cpu); cpu_list_remove(cpu); =20 if (cc->vmsd !=3D NULL) { diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 8792bea07a..3cf88272df 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -124,6 +124,11 @@ void cpu_address_space_init(CPUState *cpu, int asidx, * @cpu: CPU whose TLB should be initialized */ void tlb_init(CPUState *cpu); +/** + * tlb_destroy - destroy a CPU's TLB + * @cpu: CPU whose TLB should be destroyed + */ +void tlb_destroy(CPUState *cpu); /** * tlb_flush_page: * @cpu: CPU whose TLB should be flushed @@ -284,6 +289,9 @@ void tlb_set_page(CPUState *cpu, target_ulong vaddr, static inline void tlb_init(CPUState *cpu) { } +static inline void tlb_destroy(CPUState *cpu) +{ +} static inline void tlb_flush_page(CPUState *cpu, target_ulong addr) { } --=20 2.17.1 From nobody Mon May 20 22:40:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591378835; cv=none; d=zohomail.com; s=zohoarc; b=f2dcNqbEQJdfMiqPGtfOqXFNhpNQ9qKpB9x0ApPWMP7leY5qhas4PGcMtJs1a6Xdamty66qCCftQSnFtxAT6RIrSbaLkujEUlFpOzi5Kmo4q17DRNgI0luWSZORofpXDUHTE22cOs8mg3gWke/bn7b0r6qAX5LXh2HEV9ZXyK9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591378835; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hMythbUcqIycDnX7vBXLsyLkA4NDGTmBWD2zTKmRWuE=; b=QP3SPQ1RNBeCSrECDm5mAE/qLTMSmraibBCz7MywFI65l9l1fTsdIuzOjW4gMqX4UtJlWx8fJ+i6RnoPyPAAEVl0avUktPhdWx6L4OMXNejUOGTnZfkbqCyhJjcHzE70nOK04mNGLjwmJiBB8H8fQhwdu3Hknp5KTJ/CCpF9KoM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591378835876621.0706051511504; Fri, 5 Jun 2020 10:40:35 -0700 (PDT) Received: from localhost ([::1]:41784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGKY-0001l2-Ls for importer@patchew.org; Fri, 05 Jun 2020 13:40:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGHo-0003cX-IE for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:44 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:40810) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGHn-0003rf-NX for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:44 -0400 Received: by mail-pg1-x543.google.com with SMTP id o8so5504528pgm.7 for ; Fri, 05 Jun 2020 10:37:43 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hMythbUcqIycDnX7vBXLsyLkA4NDGTmBWD2zTKmRWuE=; b=QF39NHud8/ra/5ZqZBKv3m/n/nAeaD/9obblpGC2uR2ywu9ieUwSgeD0xj/Lhp0JPC I7f8pgYM/w/YGbzMvEKTLQUkKr7iDFWTkM9KNm9HAJI/MHZNZX6/ZOSGKRFzaG7YsfUt QLwZwUyV0zTMbnwQvHW79B1y0Unr/0NFSTQZN/+rLsn7mJ6cotfulusU8GlCuyoCD3xP oDvhsIjJmV0YK0vcU6xSfgoHra9GxGHFHDgtkAjO0FiBDvshRG5uxEmw7G4f+HgOKaaA n7Be7vyb+syOfzGphDOC39D4DK/Awfn0kfaoCk+vwhpJDZToyXymvJhDFkLZs+Tkv1/1 7dzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hMythbUcqIycDnX7vBXLsyLkA4NDGTmBWD2zTKmRWuE=; b=gZXEETRiN7GsgOGgGk8bOjkjcG4/DPDqFVITtnP+QfXRVIlooEAWsT+u9OG9QOkJKY ZD9efT/ANZ0AcSj5UBL3IbL5KPGp9QBZrNmQDnseV5FmAVZOH0Yx5Yj2qSGB8i7QxQ5Y 3wXYtHzVffwr6xy/PsCJAMXSL4lqtz1JjGmy2mcrkFHMxCaSGOI32lcWHNGcUsWRO5dh mjmxef/Kjwoq/2iLIzrhPIsob5QvPUsJfXj3TFPFfOiN0P5oZPIuzh7qw6VmOEnz4SCx qJhgi+MbXaSLlkuDYHfJyQ+GZiDVwd4VB8kQBxsGrj3b+dqUl28EfWbpLEJuiLJoaVNK ZGRw== X-Gm-Message-State: AOAM530iszJv//8eubVK9FQO4P+iimEcE5Z6EFHrhrkXK2OaIexw0KX/ WZFW8EmzoeE7Q8iz9N7944gBwBn6FGDjDw== X-Google-Smtp-Source: ABdhPJwVbfy5cn6wXa9rs1ItQJb4TkGXiG0kaK6fKn2CldolA5ZgeZWBAL66GCoA9GVOg7J11KV21w== X-Received: by 2002:a63:7d58:: with SMTP id m24mr10192861pgn.81.1591378661982; Fri, 05 Jun 2020 10:37:41 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 05/13] qht: call qemu_spin_destroy for head buckets Date: Fri, 5 Jun 2020 13:34:14 -0400 Message-Id: <20200605173422.1490-6-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::543; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x543.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Emilio G. Cota" Signed-off-by: Robert Foley Reviewed-by: Alex Benn=C3=A9e --- util/qht.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/qht.c b/util/qht.c index aa51be3c52..67e5d5b916 100644 --- a/util/qht.c +++ b/util/qht.c @@ -348,6 +348,7 @@ static inline void qht_chain_destroy(const struct qht_b= ucket *head) struct qht_bucket *curr =3D head->next; struct qht_bucket *prev; =20 + qemu_spin_destroy(&head->lock); while (curr) { prev =3D curr; curr =3D curr->next; --=20 2.17.1 From nobody Mon May 20 22:40:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591379000; cv=none; d=zohomail.com; s=zohoarc; b=dILf5PuKJp3px0rQ86hEjE55JcrkC85V9n0TttQuoGDTVCBPL+7L7Ippm2I1cVffaSfyyB2X8liJ/jcTCZCulWulP3LsX+Et+asWaIcMRkdCemKXXUr1kwaZfD5WCJPnUbCyCzwvQtWnOgLvKF2FbfH2k0LEzR7d5fks7a7KcSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591379000; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=6kzxdZqgA1tfO8ov7I9Hb8T4jfPMcEumhe/CTEZtvwg=; b=X1b3zfQyGCkPKq/c3UfhjAXObOPdV2cE7AtVSvQ703FFq9xjlflXqGU1jTtm9DxYh/IleIdCMuWIX6iFLD1cHqYWfb4buM8fgc4rV1a7zdOCw30MrUBXs/TPD4M251J2eGcWdwsAw3alJXAVykMSh1hdAemUhHv2efsmxUWNTq4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591379000582913.9414775271293; Fri, 5 Jun 2020 10:43:20 -0700 (PDT) Received: from localhost ([::1]:49756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGND-00057U-7T for importer@patchew.org; Fri, 05 Jun 2020 13:43:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGHq-0003iZ-Vx for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:47 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:33988) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGHq-0003rm-1Z for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:46 -0400 Received: by mail-pg1-x543.google.com with SMTP id m1so5553648pgk.1 for ; Fri, 05 Jun 2020 10:37:45 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37: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=6kzxdZqgA1tfO8ov7I9Hb8T4jfPMcEumhe/CTEZtvwg=; b=fAjq30UDfRMczkw9kAgAOc6e/2WHU9tQNAZohYKObI8yjhCUJDNKtU0JxMztVwR0OB /HSFNlmaBLgOvl8dy4+/Mos9gNtcdMFNkL1rAFRxP8jdxhMFYovTwmY1sIrgd1NdXPNA IijlFVKNqHfATy/OT9vnu4XWp17zi+A4Adbz2+9JragalNkcTO+qjnCY4Vh8Cl/e2IV8 p19Vr1MGmAZzfxQBVSutZYxf4JSiTAYL6AK3oRJivuHleKBFO6hFm7+OhbZn8U8v3MLq 1tgxRkRG1tqAPPbkSMbbubvNPRC5IkXt2ce+aHU3kRLUcIJHosCPnuh2Qw4lCSL/Ay8P B3BQ== 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=6kzxdZqgA1tfO8ov7I9Hb8T4jfPMcEumhe/CTEZtvwg=; b=GPZCma/BSLqO0lhLcUqyN1ZhafvN/52WzZxERXboLQYJQiE/mKPQ9tZHO2AU9XlyAE HkLyOiVXulpoqLssfZS4CK61/EoaKYNqSFYRN9d8koYXvQdrNxwh6E9t7sKzwqPOCozn xSW/HL6q0VWvsl6FE4k1D4yP1iFjnsmmnSx6daBbmQFZB/aq87bYJJ+3MElBvMUnoWXC 8SMskFOG0j8FMgRYALoWxstbhSD4ytGQ5iWYzOpJO1RjGT55+iPm/beohkI4koBtJ9dV ESoPs8SoNjIHxQuLGj8oHDXign8qlBrH7Vcw6wU5ob1LNzZFEnVZEmhpdT13ISXi1rO4 a0uQ== X-Gm-Message-State: AOAM530l/Hv/tz/auD2gm0nhEhFr7GQm883wTH9V0l0PZpA5QmicSvW5 2Dc9XKl8AdXs/ZzVwHtPjeSEBSJ7beQOBg== X-Google-Smtp-Source: ABdhPJxAtcwGZYbPj1kE2LFNRdbIoINSEUhUp5HWze31ZaPHhWk2jHYaToToMlsZlKGX5Spu1/5HYQ== X-Received: by 2002:a63:f91b:: with SMTP id h27mr10442676pgi.276.1591378664440; Fri, 05 Jun 2020 10:37:44 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 06/13] tcg: call qemu_spin_destroy for tb->jmp_lock Date: Fri, 5 Jun 2020 13:34:15 -0400 Message-Id: <20200605173422.1490-7-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::543; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x543.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley [RF: Minor changes to fix some checkpatch errors] --- accel/tcg/translate-all.c | 10 +++++++++- include/tcg/tcg.h | 3 ++- tcg/tcg.c | 19 ++++++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 42ce1dfcff..3708aab36b 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -384,6 +384,11 @@ static int cpu_restore_state_from_tb(CPUState *cpu, Tr= anslationBlock *tb, return 0; } =20 +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 =3D true; } @@ -1230,7 +1236,7 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_dat= a tb_flush_count) qht_reset_size(&tb_ctx.htable, CODE_GEN_HTABLE_SIZE); page_flush_tb(); =20 - 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, =20 orig_aligned -=3D ROUND_UP(sizeof(*tb), qemu_icache_linesize); atomic_set(&tcg_ctx->code_gen_ptr, (void *)orig_aligned); + tb_destroy(tb); return existing_tb; } tcg_tb_insert(tb); @@ -2235,6 +2242,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retadd= r) tb_phys_invalidate(tb->orig_tb, -1); } tcg_tb_remove(tb); + tb_destroy(tb); } =20 /* TODO: If env->pc !=3D tb->pc (i.e. the faulting instruction was not diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 380014ed80..c8313fdcf0 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -818,8 +818,9 @@ void *tcg_malloc_internal(TCGContext *s, int size); void tcg_pool_reset(TCGContext *s); TranslationBlock *tcg_tb_alloc(TCGContext *s); =20 +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); =20 size_t tcg_code_size(void); size_t tcg_code_capacity(void); diff --git a/tcg/tcg.c b/tcg/tcg.c index 1aa6cb47f2..7ae9dd7cf8 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -502,7 +502,16 @@ size_t tcg_nb_tbs(void) return nb_tbs; } =20 -static void tcg_region_tree_reset_all(void) +static gboolean tcg_region_tree_traverse(gpointer k, gpointer v, gpointer = data) +{ + TranslationBlock *tb =3D v; + tb_destroy_func tb_destroy =3D data; + + tb_destroy(tb); + return FALSE; +} + +static void tcg_region_tree_reset_all(tb_destroy_func tb_destroy) { size_t i; =20 @@ -510,6 +519,10 @@ static void tcg_region_tree_reset_all(void) for (i =3D 0; i < region.n; i++) { struct tcg_region_tree *rt =3D region_trees + i * tree_size; =20 + if (tb_destroy !=3D 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(TCG= Context *s) } =20 /* 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 =3D atomic_read(&n_tcg_ctxs); unsigned int i; @@ -603,7 +616,7 @@ void tcg_region_reset_all(void) } qemu_mutex_unlock(®ion.lock); =20 - tcg_region_tree_reset_all(); + tcg_region_tree_reset_all(tb_destroy); } =20 #ifdef CONFIG_USER_ONLY --=20 2.17.1 From nobody Mon May 20 22:40:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591378968; cv=none; d=zohomail.com; s=zohoarc; b=Gn8ewJWrNdujqDsMSby1nK94uqIBw8SCcaqCO4RQ98qg3+WzJV9arp27eVJtWbPczB8qkNbfzUwjgxXi0qTwQK+XOeKM7WwZDovqPhr7n4e0N1MfGVWd6JPeAwxLCf7pQIQzD0mUtfbvr6l6ISkV2sHzVi9EaYFnKi/CoG407+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591378968; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=v6Twul2TWinr3wq/OK/PDzXQA1fcuJlgD8ranJI4BbA=; b=bWXMdaUUXAG/qUKYqcLP66AygKblZGUsSqotT3rYmKa4bB+vrnsxa8o+dzZL1IRn/o1/ZwOWAMefLqc6g64Nq03vlZqa7gw12YdeLPHXizJy712wnze5XmKrMqOH2GsMN2SMUPguSXrAPqAvHmYGaHkFTOp84y3+zl9gcTunNfY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591378968468579.1372571819832; Fri, 5 Jun 2020 10:42:48 -0700 (PDT) Received: from localhost ([::1]:47480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGMh-0004Au-8e for importer@patchew.org; Fri, 05 Jun 2020 13:42:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGHt-0003np-7e for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:49 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:42921) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGHs-0003vn-DR for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:48 -0400 Received: by mail-pl1-x643.google.com with SMTP id x11so3970325plv.9 for ; Fri, 05 Jun 2020 10:37:48 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37:46 -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=EBdON3YYo2xKvrGSBkHyEwTIAXa61zRQoHX8yCulu7uFXilzRYrcVWM9Dj1XeJV2OH dZ2faymKP5rnvE1O1bvGQUH8Qq/QqL89/F/HqqqMNeQ/dO4pJAlUkUG4ovAE90P+R0TF QogqOTUVIcCacRqHeMi5U3VPZ9ym2TkIODq1pCP/CeX9OE8DMY5qc9TIlsovpH6mL4+E JjoLdTMG0ijXuMtbUPf/7ifWt47C4IA2OkPYoNgnBQHxzDLLz89qtYl40dIRxyqFz+hl 4MArs8YLqh89qlM7ouspumwDrNtiqYp6t9QWGprph2ArY/KEqGuMbqDRms579/CpnLFh gw5A== 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=fZHtlg/sZlxRe+SItfo2jV3SzOVdn3k33vIX/ShWYNc9VgZe3SdfW7KHbRlaEThBvC gpuZoEK0GGrgKcA9qlp+PZWrRph6gX+9EO0CmlzQaManr6bkHcgKf9E0MzW6WEdXVTo3 Zex1d2134nwhxQHNzuRVmfJzY/KNuttBsQ6XZ1uiYryBV90Vny9sEU1Q6qdA5/1A9LG3 CGBTQ/VJfARHvWu6sKBl1fYF2QTiL0gYnkBBshy/OScXVfrbRGqsVOVMo+BTqx9qGAjV xt/zpeIU9Tg2m6osc14LgqvySnP/10RwhCBdyH2yPdOLMKpLp6pdXL7BPklC6BQI7656 43iA== X-Gm-Message-State: AOAM5326tW9mrFXAewq2PWfMCqjKBK7Bv09PclQdfcsFdoxyTL8Wvnup SYm24c2B5SKN/29kSj8oc8RaPwDYPWbLAA== X-Google-Smtp-Source: ABdhPJzbrXcrZ3ylaYvR3CPB5ANin7X8436DGAOKCvo/u8bOMvKRRmvy+yxoiWavh4EU7k7LKFVU9w== X-Received: by 2002:a17:902:c3cb:: with SMTP id j11mr2968816plj.171.1591378666868; Fri, 05 Jun 2020 10:37:46 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 07/13] translate-all: call qemu_spin_destroy for PageDesc Date: Fri, 5 Jun 2020 13:34:16 -0400 Message-Id: <20200605173422.1490-8-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::643; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x643.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@linaro.org, cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Emilio G. Cota" The radix tree is append-only, but we can fail to insert a PageDesc if the insertion races with another thread. Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley Reviewed-by: Alex Benn=C3=A9e --- accel/tcg/translate-all.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 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 =3D atomic_cmpxchg(lp, NULL, pd); if (unlikely(existing)) { +#ifndef CONFIG_USER_ONLY + { + int i; + + for (i =3D 0; i < V_L2_SIZE; i++) { + qemu_spin_destroy(&pd[i].lock); + } + } +#endif g_free(pd); pd =3D existing; } --=20 2.17.1 From nobody Mon May 20 22:40:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591379050; cv=none; d=zohomail.com; s=zohoarc; b=JVM2Kv5KDZFc6lwRe6nft8FcS/vrkfAbN//ANs8v9EZJWYv5x7oxxIXZziYwi12chknmSAreXpT5FKj9RF+Tnuy/oRLO0xbcKzVj02jVjQBdyauvuz5l3/sB4cn/hzWXbZGQH1tWL2UADRnZNrzrQxQ7EyNoBnoaujDwDGN+dq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591379050; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AYdOaJYxtk+d/I+Jwq+9vEcr8Iz8aXatF1CrO9YlEDI=; b=UMXo/2wHwSk9S6NNrS9FjPEoPnmR+SpTeylcTyIDTIOekDHPLp1KZ7cj0dqZqfPw+MYD2tEBA9LKv54NXehOxepO99AKt+gNVjmkBzQDRPwsmRb59dXKYFfxoYsNjX8001VMPnPH8rHoi+UHUP3tgzkF2Mk/zcRQgNSJbJILr7U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591379050499691.0402568651318; Fri, 5 Jun 2020 10:44:10 -0700 (PDT) Received: from localhost ([::1]:54020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGO1-0006sy-73 for importer@patchew.org; Fri, 05 Jun 2020 13:44:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGHw-0003vX-H0 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:52 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:37817) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGHv-0003zi-MO for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:52 -0400 Received: by mail-pg1-x541.google.com with SMTP id d10so5523970pgn.4 for ; Fri, 05 Jun 2020 10:37:51 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AYdOaJYxtk+d/I+Jwq+9vEcr8Iz8aXatF1CrO9YlEDI=; b=p3+nbVsy4PvU9tSN8xRzYq1rT4aICEHfHySZZAcW5Vyvhf3hbtLejt4hciR33Iy5fq qQyPULZoVJl2I7Wt3oGr9IOZ0k0Zud5btJERRQHzTRTJ9AzONKSPYFnMThYLxdJfhcTh oa0pN7Da4zMTF0UBqv2+awE8VaCP4y6BgvNhlJ5OyMkYRVE/i+P8bEd3xB37BUoRC3+v QLoI8kekdxRvAJGs7bPvnBtXWfjxCsvje/39SKCxlevf95ZqqFLZuhq9SZm9XpMp+ICG hCo1Rh9scqCRP5YlKLoKkcHgy4G+ZY3JY0O+6eaiw+yWvsyzJLD6UvUl4s0aEFMyvHhz gFXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AYdOaJYxtk+d/I+Jwq+9vEcr8Iz8aXatF1CrO9YlEDI=; b=uKb3YNqfYbAITfLBdwD2qWYQE9h1+v4tE1FJYlJ/2oEOarw+yn9R7NdtiBaExjWj+M RgmLnEReOdS0pmc3EvvR5A5rK2E44ULfl67YJ+qw85X+YAV0fjxHbWAKnMtgXvE/m7d2 z5yBV5V5ceD58ish3rd0sY2r24GUQDZZmb+fb6UyGgiikOFDBBfykxwlAQkfOqPDn4zK LT000l3njlRgkWvSD9nH1menUD1rhNzf+bPOpPrEkdw008DyaZ1BoELTqK0jDpiaaqvu o0XQsWxKvBEuSX4UgohBSWgahEZl6rLtj0rOFb+C9k5v2cS8UT0VVZ/lknrRm9l51+NH 6ecQ== X-Gm-Message-State: AOAM531jrXBNpQtJUigP/GFm3GDaB/znqJNI0O3xTkvRCEmXXyT+x+Q9 xNCxJKvKAv9U932Y93pGHaU26uEFaKOIug== X-Google-Smtp-Source: ABdhPJz+0TqhsTfWBffMyJMplls+qRqMU+jjxrgCc29VZJBTvomQRRA3hOJ3R1q5/AqJ0CmDpFxHNA== X-Received: by 2002:a63:e60a:: with SMTP id g10mr10856361pgh.210.1591378669027; Fri, 05 Jun 2020 10:37:49 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 08/13] thread: add tsan annotations to QemuSpin Date: Fri, 5 Jun 2020 13:34:17 -0400 Message-Id: <20200605173422.1490-9-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley Reviewed-by: Alex Benn=C3=A9e --- include/qemu/thread.h | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/include/qemu/thread.h b/include/qemu/thread.h index e50a073889..43fc094b96 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -206,6 +206,10 @@ void qemu_thread_atexit_add(struct Notifier *notifier); */ void qemu_thread_atexit_remove(struct Notifier *notifier); =20 +#ifdef CONFIG_TSAN +#include +#endif + struct QemuSpin { int value; }; @@ -213,23 +217,46 @@ struct QemuSpin { static inline void qemu_spin_init(QemuSpin *spin) { __sync_lock_release(&spin->value); +#ifdef CONFIG_TSAN + __tsan_mutex_create(spin, __tsan_mutex_not_static); +#endif } =20 -static inline void qemu_spin_destroy(QemuSpin *spin) -{ } +/* const parameter because the only purpose here is the TSAN annotation */ +static inline void qemu_spin_destroy(const QemuSpin *spin) +{ +#ifdef CONFIG_TSAN + __tsan_mutex_destroy((void *)spin, __tsan_mutex_not_static); +#endif +} =20 static inline void qemu_spin_lock(QemuSpin *spin) { +#ifdef CONFIG_TSAN + __tsan_mutex_pre_lock(spin, 0); +#endif while (unlikely(__sync_lock_test_and_set(&spin->value, true))) { while (atomic_read(&spin->value)) { cpu_relax(); } } +#ifdef CONFIG_TSAN + __tsan_mutex_post_lock(spin, 0, 0); +#endif } =20 static inline bool qemu_spin_trylock(QemuSpin *spin) { - return __sync_lock_test_and_set(&spin->value, true); +#ifdef CONFIG_TSAN + __tsan_mutex_pre_lock(spin, __tsan_mutex_try_lock); +#endif + bool busy =3D __sync_lock_test_and_set(&spin->value, true); +#ifdef CONFIG_TSAN + unsigned flags =3D __tsan_mutex_try_lock; + flags |=3D busy ? __tsan_mutex_try_lock_failed : 0; + __tsan_mutex_post_lock(spin, flags, 0); +#endif + return busy; } =20 static inline bool qemu_spin_locked(QemuSpin *spin) @@ -239,7 +266,13 @@ static inline bool qemu_spin_locked(QemuSpin *spin) =20 static inline void qemu_spin_unlock(QemuSpin *spin) { +#ifdef CONFIG_TSAN + __tsan_mutex_pre_unlock(spin, 0); +#endif __sync_lock_release(&spin->value); +#ifdef CONFIG_TSAN + __tsan_mutex_post_unlock(spin, 0); +#endif } =20 struct QemuLockCnt { --=20 2.17.1 From nobody Mon May 20 22:40:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591379140; cv=none; d=zohomail.com; s=zohoarc; b=O/izFO54z4m0TvdTu165FWhnv+lyuNngDc0hW4sq8LVVYjcoYosSn0eEMX4wrs4ZXYmjQbiA3Q4RbHRxP780AQ4Uaz/RJm1Xjm7mtnAJ4Nv/8Hu9+YU6Ckb+0g6CIFqegzPE9flEa7K8yGy/P9zPvJO/IGudTr5EVb93RrEpfMg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591379140; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AXPq7Uy8g5ifp8uMXZd1qJX2wag4BCDXppVYNXcf0Dw=; b=IAxeua5eVvWUv0N77hMvcLDaoEDq4kTx0VO+o+ECsvrLXmONFqqvWQRcsnsJue0IZghAurLoOZ6KZM6AYgslk2JudYREM6kW5SgK1cu4UQ1/pCvE0MP4ngp5m7mkSsBFK1xL4dEbUG/wrWA+SyrqkJ4kiaN+tXmDIjNlShK7wus= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591379140579439.8436703974089; Fri, 5 Jun 2020 10:45:40 -0700 (PDT) Received: from localhost ([::1]:59092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGPT-0000X0-Be for importer@patchew.org; Fri, 05 Jun 2020 13:45:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGHy-00040d-B0 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:54 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:45776) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGHx-000410-37 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:53 -0400 Received: by mail-pg1-x541.google.com with SMTP id n23so5483253pgb.12 for ; Fri, 05 Jun 2020 10:37:52 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37:50 -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=AXPq7Uy8g5ifp8uMXZd1qJX2wag4BCDXppVYNXcf0Dw=; b=fUUR/juA87kUvzkHOXidkERsoZztFGGDQkhWhPKRV96NnsT1KWLuW7SB88q4l8ESuS Wshv1Dsy3x8ozU0I3fSn927FlGcc6CdgUbhY4zZrQQiglAxtJPbg+5RiASX4w2/6gbvc d0n3ErHBBHBvQUNTjoVRRsU60K8SHrnds1WR9eVY5VNT0/Q345Ra7zTEtE9dVQRzWPHG GIfKg4eRDwE3UHyDUrbrD6yk9XyG5OdTTmZJeUceP7vkJpCwd2r1XhzE5eHqUmgnJdhn nMuFtdyJQvfB83yDSJOslDY/lSXSp5sE7ZzI8Hj/8BXghikh6eux9Y9DjyduwlSLpwP7 k5FA== 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=AXPq7Uy8g5ifp8uMXZd1qJX2wag4BCDXppVYNXcf0Dw=; b=XAAWASD84R2utapT2l/g5R3EW+FsXvAOkr94HPMLfgZeW1sQJxYIcM+DAWQvnNlpLs ZBBER60f0IHDB2wW0cCdJoXtkWJo/VvMKx7QOz7TZ2u3a4vy/3N2OouLSGAR6slmjOa5 eTiLa0NhbgmWokpBGWjmg7C4She1I1upyrIwZpQ/E9PpXJyqwX/YWbCAod7H5wH2hl7w fTCvwJGI30HJzbHx8IZ/4mbf/DGKS/n7MSFr9wfCa2jW6LJdv443BD9OxNF/Z+GpYIgF XPcvrh+ole3NMbAnIcN41pe120UShL78944shjO2G2Sv6sh3vR5FpwABq8fx/1blB+9s Lf9A== X-Gm-Message-State: AOAM5330cXVjx3rQkowyQmIlRBTI8rIaYKqxjIs6x+IBziDmikq46gyU kZHxvEOur+sfhdP+ooyjXPF3CyQlLthJUw== X-Google-Smtp-Source: ABdhPJyGCuCwwNwHK978hztXGXybTaUfoyjA0JOCR9swtv/cKQ1QVZRWX9spz1l17gix52GSvGYJqQ== X-Received: by 2002:a65:568d:: with SMTP id v13mr10411924pgs.436.1591378671434; Fri, 05 Jun 2020 10:37:51 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 09/13] tests/docker: Added docker build support for TSan. Date: Fri, 5 Jun 2020 13:34:18 -0400 Message-Id: <20200605173422.1490-10-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , robert.foley@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , cota@braap.org, peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Added a new docker for ubuntu 20.04. This docker has support for Thread Sanitizer including one patch we need in one of the header files. https://github.com/llvm/llvm-project/commit/a72dc86cd This command will build with tsan enabled: make docker-test-tsan-ubuntu2004=20 Also added the TSAN suppresion file to disable certain cases of TSAN warnings. Cc: Fam Zheng Cc: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Robert Foley Reviewed-by: Alex Benn=C3=A9e --- tests/docker/dockerfiles/ubuntu2004.docker | 65 ++++++++++++++++++++++ tests/docker/test-tsan | 44 +++++++++++++++ tests/tsan/blacklist.tsan | 10 ++++ tests/tsan/suppressions.tsan | 14 +++++ 4 files changed, 133 insertions(+) create mode 100644 tests/docker/dockerfiles/ubuntu2004.docker create mode 100755 tests/docker/test-tsan create mode 100644 tests/tsan/blacklist.tsan create mode 100644 tests/tsan/suppressions.tsan diff --git a/tests/docker/dockerfiles/ubuntu2004.docker b/tests/docker/dock= erfiles/ubuntu2004.docker new file mode 100644 index 0000000000..6050ce7e8a --- /dev/null +++ b/tests/docker/dockerfiles/ubuntu2004.docker @@ -0,0 +1,65 @@ +FROM ubuntu:20.04 +ENV PACKAGES flex bison \ + ccache \ + clang-10\ + gcc \ + gettext \ + git \ + glusterfs-common \ + libaio-dev \ + libattr1-dev \ + libbrlapi-dev \ + libbz2-dev \ + libcacard-dev \ + libcap-ng-dev \ + libcurl4-gnutls-dev \ + libdrm-dev \ + libepoxy-dev \ + libfdt-dev \ + libgbm-dev \ + libgtk-3-dev \ + libibverbs-dev \ + libiscsi-dev \ + libjemalloc-dev \ + libjpeg-turbo8-dev \ + liblzo2-dev \ + libncurses5-dev \ + libncursesw5-dev \ + libnfs-dev \ + libnss3-dev \ + libnuma-dev \ + libpixman-1-dev \ + librados-dev \ + librbd-dev \ + librdmacm-dev \ + libsasl2-dev \ + libsdl2-dev \ + libseccomp-dev \ + libsnappy-dev \ + libspice-protocol-dev \ + libspice-server-dev \ + libssh-dev \ + libusb-1.0-0-dev \ + libusbredirhost-dev \ + libvdeplug-dev \ + libvte-2.91-dev \ + libxen-dev \ + libzstd-dev \ + make \ + python3-yaml \ + python3-sphinx \ + sparse \ + texinfo \ + xfslibs-dev\ + vim +RUN apt-get update && \ + DEBIAN_FRONTEND=3Dnoninteractive apt-get -y install $PACKAGES +RUN dpkg -l $PACKAGES | sort > /packages.txt +ENV FEATURES clang tsan pyyaml sdl2 + +# https://bugs.launchpad.net/qemu/+bug/1838763 +ENV QEMU_CONFIGURE_OPTS --disable-libssh + +# Apply patch https://reviews.llvm.org/D75820 +# This is required for TSan in clang-10 to compile with QEMU. +RUN sed -i 's/^const/static const/g' /usr/lib/llvm-10/lib/clang/10.0.0/inc= lude/sanitizer/tsan_interface.h diff --git a/tests/docker/test-tsan b/tests/docker/test-tsan new file mode 100755 index 0000000000..eb40ac45b7 --- /dev/null +++ b/tests/docker/test-tsan @@ -0,0 +1,44 @@ +#!/bin/bash -e +# +# This test will use TSan as part of a build and a make check. +# +# Copyright (c) 2020 Linaro +# Copyright (c) 2016 Red Hat Inc. +# +# Authors: +# Robert Foley +# Originally based on test-quick from Fam Zheng +# +# This work is licensed under the terms of the GNU GPL, version 2 +# or (at your option) any later version. See the COPYING file in +# the top-level directory. + +. common.rc + +setup_tsan() +{ + requires clang tsan + tsan_log_dir=3D"/tmp/qemu-test/build/tsan" + mkdir -p $tsan_log_dir > /dev/null || true + EXTRA_CONFIGURE_OPTS=3D"${EXTRA_CONFIGURE_OPTS} --enable-tsan \ + --cc=3Dclang-10 --cxx=3Dclang++-10 \ + --disable-werror --extra-cflags=3D-O0" + # detect deadlocks is false currently simply because + # TSan crashes immediately with deadlock detector enabled. + # We have maxed out the history size to get the best chance of finding + # warnings during testing. + # Note, to get TSan to fail on warning, use exitcode=3D66 below. + tsan_opts=3D"suppressions=3D/tmp/qemu-test/src/tests/tsan/suppressions= .tsan\ + detect_deadlocks=3Dfalse history_size=3D7\ + halt_on_error=3D0 exitcode=3D0 verbose=3D5\ + log_path=3D$tsan_log_dir/tsan_warning" + export TSAN_OPTIONS=3D"$tsan_opts" +} + +cd "$BUILD_DIR" + +TARGET_LIST=3D${TARGET_LIST:-$DEF_TARGET_LIST} \ +setup_tsan +build_qemu +check_qemu +install_qemu diff --git a/tests/tsan/blacklist.tsan b/tests/tsan/blacklist.tsan new file mode 100644 index 0000000000..75e444f5dc --- /dev/null +++ b/tests/tsan/blacklist.tsan @@ -0,0 +1,10 @@ +# This is an example blacklist. +# To enable use of the blacklist add this to configure: +# "--extra-cflags=3D-fsanitize-blacklist=3D/tests/tsan/blacklist= .tsan" +# The eventual goal would be to fix these warnings. + +# TSan is not happy about setting/getting of dirty bits, +# for example, cpu_physical_memory_set_dirty_range, +# and cpu_physical_memory_get_dirty. +src:bitops.c +src:bitmap.c diff --git a/tests/tsan/suppressions.tsan b/tests/tsan/suppressions.tsan new file mode 100644 index 0000000000..73414b9ebd --- /dev/null +++ b/tests/tsan/suppressions.tsan @@ -0,0 +1,14 @@ +# This is the set of runtime suppressions of TSan warnings. +# The goal would be to have here only items we do not +# plan to fix, and to explain why for each item. + +# TSan reports a double lock on RECURSIVE mutexes. +# Since the recursive lock is intentional, we choose to ignore it. +mutex:aio_context_acquire +mutex:pthread_mutex_lock + +# TSan reports a race betwen pthread_mutex_init() and +# pthread_mutex_lock(). Since this is outside of QEMU, +# we choose to ignore it. +race:pthread_mutex_init +race:pthread_mutex_lock --=20 2.17.1 From nobody Mon May 20 22:40:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591378805; cv=none; d=zohomail.com; s=zohoarc; b=l266ySFc+M8A3OfT31ck5+kK6JBj+Sr+A5pbWBiwoYfxVwuITvuqH3CpmTLHS/WXnn7OgoXD/3lKzic2ayuVolwFqX+TcvptGvRTqPB5EQTqlbo2r3e0jnE32FzndsCn4E0ifWIJlxpcGqJB0XTkrC3ocDF5AKQsi7xn/xT8G00= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591378805; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=AOzUAJyFNQB4L+phqsSsfzj9Z8OtZxOrajLi9NoXesk=; b=RlpZC5DVVn/q6O4yvXiYaGCeFuSNbWznAWf9xnhvP1O4q1ieUt+Wf+lPE4s0qzX0zpnMjQA5+J3jcQA0sc4Jo3RNV2qto5pbMMwwqcYy7qaVMi4iAVFwwbnET7RttMwXLHVcWsOIsXgvNfCHGu0wA9ZF8/hYL4Q88Id/M/9lUbg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591378805929985.5035561593314; Fri, 5 Jun 2020 10:40:05 -0700 (PDT) Received: from localhost ([::1]:38852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGK4-0000Zx-KZ for importer@patchew.org; Fri, 05 Jun 2020 13:40:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGI0-00046j-He for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:56 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:44918) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGHz-00041E-Gn for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:56 -0400 Received: by mail-pf1-x444.google.com with SMTP id f3so5263606pfd.11 for ; Fri, 05 Jun 2020 10:37:54 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37:52 -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=FW7YwxTbepxVhFcuU9CLDUQXHRQgNNhdh8JqqkQIeqt8MwWClu34MgBwJ4+2PjfIY5 Slxua9esPHR2CdKte+EkY7Y8+JVr3WstzJ2fv+Ths7xFB+aIumtnRJjIFnP9Y4FK7o8D 4TzTOMP0C1sOWR0W39VYJ0NsJiI5vQVdRID/ZXrKlDEfBRSrosHqWzqPj7Ya8w416WFR rpp9MPXK7YRxFKLZvZeU32myI2Jnw2MYtF9MbyTjrsFkKk9FAR0tdfCx3ss10D1cvYQa IGPaG05pC9diurhxuoyamTYWF3VeSihWekNYxAdwZdhGPZJYO4MKtz7c4yMnIvV4bwRW Q6yQ== 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=TQAxa6uESLq+LP4ktYNCInb6tN3wUcwKaLGvY7p3W0bjGQ5cLBn+Wdv8xHsHbjr8Ib 878GK53yOgjWnSBak5XXABir/ElgYNNQu9aIJbRBTwiPE3N9QYVVLKXDhRGAlQhF3vTh gagyoI/9ZXnp75bB4/zeazZSvdJXwfNvqLvnDF633rf94arocE7f42aV0J6FHfaMtVdt OfN6Kk/nkXqz1KILxEeEs5nTc8egk5GSU/LEI/QRSVLjewHatThOj0ZZdFkWBrj6VEm3 BzsDRF5XNkSnJY50DWozweBcPut5oLEZo4fX4SYaJZTt6R/AcQwMZ84vZrx2GDTGy+Pe 0KbQ== X-Gm-Message-State: AOAM531699BHk1Uysz2KIbe3CZT9EXqVpSkSYm2ylrhGAJBK3TuJr9O3 l4MKDU6T/2RYJ0YSGhwIv62SgAx+Tz72dw== X-Google-Smtp-Source: ABdhPJy5T/ARc5bVKkXU2KWFcWu4tQW877DdB0Q/siz4xIdOCz9KIrJW38ZyX5+X7C6hOw80U6KK7g== X-Received: by 2002:a63:1d02:: with SMTP id d2mr10615845pgd.206.1591378673552; Fri, 05 Jun 2020 10:37:53 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 10/13] include/qemu: Added tsan.h for annotations. Date: Fri, 5 Jun 2020 13:34:19 -0400 Message-Id: <20200605173422.1490-11-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" These annotations will allow us to give tsan additional hints. For example, we can inform tsan about reads/writes to ignore to silence certain classes of warnings. We can also annotate threads so that the proper thread naming shows up in tsan warning results. Signed-off-by: Robert Foley Reviewed-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e --- include/qemu/tsan.h | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 include/qemu/tsan.h diff --git a/include/qemu/tsan.h b/include/qemu/tsan.h new file mode 100644 index 0000000000..09cc665f91 --- /dev/null +++ b/include/qemu/tsan.h @@ -0,0 +1,71 @@ +#ifndef QEMU_TSAN_H +#define QEMU_TSAN_H +/* + * tsan.h + * + * This file defines macros used to give ThreadSanitizer + * additional information to help suppress warnings. + * This is necessary since TSan does not provide a header file + * for these annotations. The standard way to include these + * is via the below macros. + * + * Annotation examples can be found here: + * https://github.com/llvm/llvm-project/tree/master/compiler-rt/test/tsan + * annotate_happens_before.cpp or ignore_race.cpp are good places to start. + * + * The full set of annotations can be found here in tsan_interface_ann.cpp. + * https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/tsan/= rtl/ + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifdef CONFIG_TSAN +/* + * Informs TSan of a happens before/after relationship. + */ +#define QEMU_TSAN_ANNOTATE_HAPPENS_BEFORE(addr) \ + AnnotateHappensBefore(__FILE__, __LINE__, (void *)(addr)) +#define QEMU_TSAN_ANNOTATE_HAPPENS_AFTER(addr) \ + AnnotateHappensAfter(__FILE__, __LINE__, (void *)(addr)) +/* + * Gives TSan more information about thread names it can report the + * name of the thread in the warning report. + */ +#define QEMU_TSAN_ANNOTATE_THREAD_NAME(name) \ + AnnotateThreadName(__FILE__, __LINE__, (void *)(name)) +/* + * Allows defining a region of code on which TSan will not record memory R= EADS. + * This has the effect of disabling race detection for this section of cod= e. + */ +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_BEGIN() \ + AnnotateIgnoreReadsBegin(__FILE__, __LINE__) +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_END() \ + AnnotateIgnoreReadsEnd(__FILE__, __LINE__) +/* + * Allows defining a region of code on which TSan will not record memory + * WRITES. This has the effect of disabling race detection for this + * section of code. + */ +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN() \ + AnnotateIgnoreWritesBegin(__FILE__, __LINE__) +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_END() \ + AnnotateIgnoreWritesEnd(__FILE__, __LINE__) +#else +#define QEMU_TSAN_ANNOTATE_HAPPENS_BEFORE(addr) +#define QEMU_TSAN_ANNOTATE_HAPPENS_AFTER(addr) +#define QEMU_TSAN_ANNOTATE_THREAD_NAME(name) +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_BEGIN() +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_END() +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN() +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_END() +#endif + +void AnnotateHappensBefore(const char *f, int l, void *addr); +void AnnotateHappensAfter(const char *f, int l, void *addr); +void AnnotateThreadName(const char *f, int l, char *name); +void AnnotateIgnoreReadsBegin(const char *f, int l); +void AnnotateIgnoreReadsEnd(const char *f, int l); +void AnnotateIgnoreWritesBegin(const char *f, int l); +void AnnotateIgnoreWritesEnd(const char *f, int l); +#endif --=20 2.17.1 From nobody Mon May 20 22:40:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591378967; cv=none; d=zohomail.com; s=zohoarc; b=Ps1qpNPznYfGotnPQ6aCvL8OjCtXerNsHIfG44tx1HdIPbiebPldyC79qayT1dC++GwE9hEXIw2DXGtP9REIFTHkz7i74SbdY2mxWirOFib5Dfso3zzL7QLbg4jkizqH8+evzNtPTvgqD5bcE7BHN613humdApXZziymqNLV0dA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591378967; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=bZmmE8g6bACENWl1LtFwmXs+x0B5ALCEi1t1qd6zEd8=; b=BMgvs1Hpdcx9n1LqyupUkddvKIdfxBAP4PqFd1mTV9kdJKLfcN14DqToxVBIFhHO6HL+1aJJv/GdrHzi5xcxeNx7roTbuoexB1eI6noDHZ+BoqMAHZ0IsgzAutBZCvhoJcRjuZs66jhzcv3F3J+YupsywDfNP0l7+WdehJ5gBZk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591378967208620.6390540934551; Fri, 5 Jun 2020 10:42:47 -0700 (PDT) Received: from localhost ([::1]:47338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGMg-00047D-1B for importer@patchew.org; Fri, 05 Jun 2020 13:42:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGI2-0004Bk-6h for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:58 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:54198) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGI1-00041L-At for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:37:57 -0400 Received: by mail-pj1-x1042.google.com with SMTP id i12so2952457pju.3 for ; Fri, 05 Jun 2020 10:37:56 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bZmmE8g6bACENWl1LtFwmXs+x0B5ALCEi1t1qd6zEd8=; b=Pb7YG1V/Bc6/e68fO44j042QeV5pS685k3SzEN9JMM8i5rIjB47b4i0OyCCLtjp+KQ 6stzaFiwg+D7f0syW+O5RT/6ph5E6kxe5oQ6YZ6B+pwjiloLjto0rPT1L/tokSUIFc0f Egy1oplXvb+OyFUm8BeXEVY6zOVyu7lisfzTbqsM62tOsfpChEKcVpWlx5s8bmEDzjIK v2KBBuiGkwKCD7iStGTynAP0gNEHKNYppjTtEwZZmXuoj8VV3VDHJmVRCjc4OHiyvF0h YStOIO2lIXx/KD+KC2xByHvbzaU/v9BAdMeiZJlONus4vXqUCMincrxX9bFd3u4cnozN qzfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bZmmE8g6bACENWl1LtFwmXs+x0B5ALCEi1t1qd6zEd8=; b=M4ceFjfHudfbRR0smxknOxwgDzjbB7gb14ZX0Uiwxyn21sgDEpBRktS3ncdu58Sl8k tLSHL07WAqe0hUNPPUS4Jo6Ji0EnmUTYKBhb3FglI2k7qQiaAIeby1gFqqxxQv7aoVYZ kgk7wvWsTQT+MUqfU5D37RDvNt5TOd8LYNea7AEtMxwy3+7kU19d+lmYhZJ0OpZRpjPb ChQJN/RkGBp+Z9ve/8LkZVHTEBOQgyVxcNFwG7VCv7Wjv61w1Xb8lralncGlh5UZIM+r 7L6GYh1KzcCPtopMj8/GSHJGMhe6d08MTUltAW6QmGsSVGrSoHkMwLAJg9wRkOER3P03 ifpw== X-Gm-Message-State: AOAM5325dC5MZ7Bot228yOzjSRcIAS39twM63u6w+8updpIWst85cxzm GAMA8GZ1WcD8F6M+F6MpJ25kdqWj1vpsgQ== X-Google-Smtp-Source: ABdhPJx+Y/7CJ4ddPxc2IR6/oSwFA7XEzN/7/4gUy3R5JBcAHa/psL3INyDWZd64Xr1hoqe2/jGIwg== X-Received: by 2002:a17:90a:8594:: with SMTP id m20mr4199964pjn.38.1591378675749; Fri, 05 Jun 2020 10:37:55 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 11/13] util: Added tsan annotate for thread name. Date: Fri, 5 Jun 2020 13:34:20 -0400 Message-Id: <20200605173422.1490-12-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::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, Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This allows us to see the name of the thread in tsan warning reports such as this: Thread T7 'CPU 1/TCG' (tid=3D24317, running) created by main thread at: Signed-off-by: Robert Foley Reviewed-by: Emilio G. Cota --- util/qemu-thread-posix.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 838980aaa5..b4c2359272 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -15,6 +15,7 @@ #include "qemu/atomic.h" #include "qemu/notify.h" #include "qemu-thread-common.h" +#include "qemu/tsan.h" =20 static bool name_threads; =20 @@ -513,6 +514,7 @@ static void *qemu_thread_start(void *args) # endif } #endif + QEMU_TSAN_ANNOTATE_THREAD_NAME(qemu_thread_args->name); g_free(qemu_thread_args->name); g_free(qemu_thread_args); pthread_cleanup_push(qemu_thread_atexit_notify, NULL); --=20 2.17.1 From nobody Mon May 20 22:40:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591378768; cv=none; d=zohomail.com; s=zohoarc; b=JjT4Y/C6d6hN0q+S/SbNz8AoIm4RfTL+oVIsuRAqmo83pL2+iI5yMfAoh2NuARfcwU0h6nntj7kh8e9aYRIEtLRLEb9LfiAECO3ALbY38i+CemZfDuXLX3WTVR8FkSBNkDCnxrs+1nykTBEhZgGf4U14vWNaOznfSodLUk6MkCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591378768; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=XzO4d9NfxHhnWYA5ypuQ0LUhD/s+5379iGqovYIf/8k=; b=jeaUW0S55stzaudOlAnla66jaUv40cHRbKU/WNwb+9znF67VqG3yqchGnxQrJr1kfFkTBYg9K+J2TrQHBEBQtuDNfC6FQbPCoh4T+5sxj7jBIRYxQmB+SmAwfuQkeNU+wXVIaMIxoXK2jHDTnYg0pzf3Or+R7xyQlczWhpCeKCo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591378768709374.03926576085985; Fri, 5 Jun 2020 10:39:28 -0700 (PDT) Received: from localhost ([::1]:35190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGJS-0007DV-FR for importer@patchew.org; Fri, 05 Jun 2020 13:39:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGI4-0004Im-Lw for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:38:00 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:40782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGI3-00041W-Hk for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:38:00 -0400 Received: by mail-pf1-x442.google.com with SMTP id s23so3961015pfh.7 for ; Fri, 05 Jun 2020 10:37:59 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XzO4d9NfxHhnWYA5ypuQ0LUhD/s+5379iGqovYIf/8k=; b=y52sj9Axg0xBsiHEVC44k/0Dm4IwyON9v7OpxX7YRbq8zlTRFJRXav3d11iFUrOQ38 oOBaP2GKKeHWzmUc8MtXZg+DoL5OG2sFCztWiYy/qwAl4VkgRMECZMZJjzPUjsnysh+R eWZzBcDBtWHePCEdQXowVjdKpzNJxMnO2wRSZEqsCfG4lX6SPn3HbCej/RbwJyiYCjPT n6beifZUWT5BIgt/7W0c0FjsfUiPHMYrGOZTIw58hjWgxjvT4uxGApLneL+f0O1NezGG /LV3+jeU3Sjl7UeOjqA28YslsxtA5DfvV9GOBkId5O3/V9/9/uxkMslcnsmJRE4YOAtT yjzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XzO4d9NfxHhnWYA5ypuQ0LUhD/s+5379iGqovYIf/8k=; b=MhOuAcxG0oLIHPttFrV8kX1I2yyNTDPQOD0NE4fmPOfV1185DAk5r+t8+SdFQVKeqC xByKDeSak2mLExhhcRcRno3ortlmMb28+g0yyXsiScWUJwagXf8TvZo4/dW2YKuEAbEb NpX3Vicf3T570z27FtyBq0vHJtFBrKbG+jJILuOaDkf9chViN/3yj9mlGYFQ5gBkMj29 jwoTMLWvEdQon66mkzhYU5lQsnAAyrcQog2r0D3ruWHuYlAMflAOXdeLCxEXMTQpADcC gILqOMymxR9twkePsunNUaKpdw4iAjPvR40senRG0/ZKoUwZ63IHYYw2F40WBh5fxxzs p/+A== X-Gm-Message-State: AOAM532Mn/mJQy5Ycp05T4q+6q+RXeV112K/ZkBID8RmDZQ+g2jb8Hvd M6tLLSk+q885aFFwnBcJKx+Gj99rVuGHDA== X-Google-Smtp-Source: ABdhPJyzBIKpLrkvpIklD4VG4YKxwyJLORDnH0Q13tLBs3zPCtE/gFZgaDRa3xrsvSR33dhmMVbGzQ== X-Received: by 2002:aa7:9a5a:: with SMTP id x26mr10972302pfj.307.1591378677823; Fri, 05 Jun 2020 10:37:57 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 12/13] docs: Added details on TSan to testing.rst Date: Fri, 5 Jun 2020 13:34:21 -0400 Message-Id: <20200605173422.1490-13-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Adds TSan details to testing.rst. This includes background and reference details on TSan, and details on how to build and test with TSan both with and without docker. Signed-off-by: Robert Foley Reviewed-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e --- docs/devel/testing.rst | 107 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst index 770a987ea4..c1ff24370b 100644 --- a/docs/devel/testing.rst +++ b/docs/devel/testing.rst @@ -397,6 +397,113 @@ list is in the ``make docker`` help text. The frequen= tly used ones are: * ``DEBUG=3D1``: enables debug. See the previous "Debugging a Docker test failure" section. =20 +Thread Sanitizer +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Thread Sanitizer (TSan) is a tool which can detect data races. QEMU suppo= rts +building and testing with this tool. + +For more information on TSan: + +https://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual + +Thread Sanitizer in Docker +--------------------------- +TSan is currently supported in the ubuntu2004 docker. + +The test-tsan test will build using TSan and then run make check. + +.. code:: + + make docker-test-tsan@ubuntu2004 + +TSan warnings under docker are placed in files located at build/tsan/. + +We recommend using DEBUG=3D1 to allow launching the test from inside the d= ocker, +and to allow review of the warnings generated by TSan. + +Building and Testing with TSan +------------------------------ + +It is possible to build and test with TSan, with a few additional steps. +These steps are normally done automatically in the docker. + +There is a one time patch needed in clang-9 or clang-10 at this time: + +.. code:: + + sed -i 's/^const/static const/g' \ + /usr/lib/llvm-10/lib/clang/10.0.0/include/sanitizer/tsan_interface.h + +To configure the build for TSan: + +.. code:: + + ../configure --enable-tsan --cc=3Dclang-10 --cxx=3Dclang++-10 \ + --disable-werror --extra-cflags=3D"-O0" + +The runtime behavior of TSAN is controlled by the TSAN_OPTIONS environment +variable. + +More information on the TSAN_OPTIONS can be found here: + +https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags + +For example: + +.. code:: + + export TSAN_OPTIONS=3Dsuppressions=3D/tests/tsan/suppressi= ons.tsan \ + detect_deadlocks=3Dfalse history_size=3D7 exitcode= =3D0 \ + log_path=3D/tsan/tsan_warning + +The above exitcode=3D0 has TSan continue without error if any warnings are= found. +This allows for running the test and then checking the warnings afterwards. +If you want TSan to stop and exit with error on warnings, use exitcode=3D6= 6. + +TSan Suppressions +----------------- +Keep in mind that for any data race warning, although there might be a dat= a race +detected by TSan, there might be no actual bug here. TSan provides several +different mechanisms for suppressing warnings. In general it is recommend= ed +to fix the code if possible to eliminate the data race rather than suppress +the warning. + +A few important files for suppressing warnings are: + +tests/tsan/suppressions.tsan - Has TSan warnings we wish to suppress at ru= ntime. +The comment on each supression will typically indicate why we are +suppressing it. More information on the file format can be found here: + +https://github.com/google/sanitizers/wiki/ThreadSanitizerSuppressions + +tests/tsan/blacklist.tsan - Has TSan warnings we wish to disable +at compile time for test or debug. +Add flags to configure to enable: + +"--extra-cflags=3D-fsanitize-blacklist=3D/tests/tsan/blacklist.t= san" + +More information on the file format can be found here under "Blacklist For= mat": + +https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags + +TSan Annotations +---------------- +include/qemu/tsan.h defines annotations. See this file for more descripti= ons +of the annotations themselves. Annotations can be used to suppress +TSan warnings or give TSan more information so that it can detect proper +relationships between accesses of data. + +Annotation examples can be found here: + +https://github.com/llvm/llvm-project/tree/master/compiler-rt/test/tsan/ + +Good files to start with are: annotate_happens_before.cpp and ignore_race.= cpp + +The full set of annotations can be found here: + +https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/tsan/rtl/= tsan_interface_ann.cpp + VM testing =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 --=20 2.17.1 From nobody Mon May 20 22:40:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591378877; cv=none; d=zohomail.com; s=zohoarc; b=D/vgmDkPNrBUe4UVMqhFwjURgZUPcHBnueHneAY/2iB2y2hxl5n0d9v1bmy/7H7UG8ygFLBOb2Duoj5e4D6CW29DiPqNQcyP+n+YCx5/YZ6+yB75c3+kkvPIyY5XLoCTi5AYmpTezUbor920bhHf0CEbtAWMq0Cb+s+HMYS1xAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591378877; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=803eDYLxeJBOM1lm3oQCQ/DECicGijz33nVW4BPgwBQ=; b=DsCQEtHkyo1boKmavOKvr4dU1tMHBqRXl/7A+2ZQZHlozlP6KGOscM8Xx5st6t4PtfHPaIGzg0PJH+A27zANBNVLfYp3O/jvWPkXiDViglE85JshT7K1Q9lCgBBVbis+cK0TVXkzYKjPdLq1zbgvWwUty9t82QY7tLnSjLMsDW0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591378877181854.0666768708386; Fri, 5 Jun 2020 10:41:17 -0700 (PDT) Received: from localhost ([::1]:43756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhGLD-0002bl-V0 for importer@patchew.org; Fri, 05 Jun 2020 13:41:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhGI8-0004PG-11 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:38:04 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:45699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhGI6-00042q-W7 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 13:38:03 -0400 Received: by mail-pg1-x535.google.com with SMTP id n23so5483546pgb.12 for ; Fri, 05 Jun 2020 10:38:01 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net (c-73-47-162-176.hsd1.ma.comcast.net. [73.47.162.176]) by smtp.gmail.com with ESMTPSA id a19sm188307pfd.165.2020.06.05.10.37.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 10:37:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=803eDYLxeJBOM1lm3oQCQ/DECicGijz33nVW4BPgwBQ=; b=Ivveq8k5c6Bre34x7c3IBsxeBk/DMPW9wMxl+uG2Dvk0eW70QxO/XpguNZ4rrVQGnq g19ToVLqZy0pOju9y5wB6D7Po88nYsQ1oSiZfCl5Kz8IeKSI0XK5P1gU/b+NgiSIf8J/ taQ7yiqVZsCKThcJtNBBjO1Nv15TOvUEA79Aiziyd4GZHKJr5of8NrAztqTswF7/XLPz o2XE7EK2C4ktOeuLnt+zuqSIXrfxK/9ml7WgPJU6AWAQA+pYxa0jV2AxGULtcgVdf6mc 05w+CtKfIqvoopfzMqZC+k7nyVb66L/BJSUyGkXcUAHBzd3f71IFDqW7c7RWy/rigH8k YaJQ== 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=803eDYLxeJBOM1lm3oQCQ/DECicGijz33nVW4BPgwBQ=; b=g6rTyGq6TN5ASISsDpp8CLFhWu9/wm2z/0t8IpQ30N/WY6aLmLimLPuWm7skZKXMOh avbH0s7exXVD6M7pe8rGcUXfweQPbL1kjb/nmpUDFnXp6SR1zfE+yECJsRaMTKLP5ciZ eXgGsCqa+49Ko4jQZi13k6YGrWN3Ga3DCqyxaE18mluoZonOVCq1dtK5AYQhdCLHXArx GAUJwYXiddM620mHxFe7g7LAeDiQNHiFUwfcmaUEB43O0OJ1g8A/+AscqUqIRcD1W66M GuT07DpsFoTRY9E3FjObzMS75sEcOqaOKF9XQncSCClyN7zSs76DQr1o2M96wFqYQ7zG +4dA== X-Gm-Message-State: AOAM531cuwbiOtSzQFkoa+1zj8gGw9eYLXCmjQd8s1uQDYN7/HTK5sCE ViLiQxuLOQDdzPmk1+aewdkLaLZqFaoUKw== X-Google-Smtp-Source: ABdhPJyUHdTF/SV3Qo5asvOXhkjbKXIm+KSfzrQG3nkZ9fVYdg7+QSDtdgZTV0p8NM2o/3repwq3+A== X-Received: by 2002:a62:8487:: with SMTP id k129mr10934010pfd.296.1591378680322; Fri, 05 Jun 2020 10:38:00 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 13/13] tests: Disable select tests under TSan, which hit TSan issue. Date: Fri, 5 Jun 2020 13:34:22 -0400 Message-Id: <20200605173422.1490-14-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605173422.1490-1-robert.foley@linaro.org> References: <20200605173422.1490-1-robert.foley@linaro.org> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=robert.foley@linaro.org; helo=mail-pg1-x535.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , robert.foley@linaro.org, cota@braap.org, Paolo Bonzini , peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Disable a few tests under CONFIG_TSAN, which run into a known TSan issue that results in a hang. https://github.com/google/sanitizers/issues/1116 The disabled tests under TSan include all the qtests as well as the test-char, test-qga, and test-qdev-global-props. Signed-off-by: Robert Foley Reviewed-by: Emilio G. Cota --- tests/Makefile.include | 9 +++++++-- tests/qtest/Makefile.include | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 6e3d6370df..874a2990b3 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -53,7 +53,6 @@ SYSEMU_TARGET_LIST :=3D $(subst -softmmu.mak,,$(notdir \ =20 check-unit-y +=3D tests/check-qdict$(EXESUF) check-unit-y +=3D tests/check-block-qdict$(EXESUF) -check-unit-$(CONFIG_SOFTMMU) +=3D tests/test-char$(EXESUF) check-unit-y +=3D tests/check-qnum$(EXESUF) check-unit-y +=3D tests/check-qstring$(EXESUF) check-unit-y +=3D tests/check-qlist$(EXESUF) @@ -106,7 +105,6 @@ check-unit-y +=3D tests/test-qht$(EXESUF) check-unit-y +=3D tests/test-qht-par$(EXESUF) check-unit-y +=3D tests/test-bitops$(EXESUF) check-unit-y +=3D tests/test-bitcnt$(EXESUF) -check-unit-y +=3D tests/test-qdev-global-props$(EXESUF) check-unit-y +=3D tests/check-qom-interface$(EXESUF) check-unit-y +=3D tests/check-qom-proplist$(EXESUF) check-unit-y +=3D tests/test-qemu-opts$(EXESUF) @@ -121,9 +119,16 @@ check-speed-$(CONFIG_BLOCK) +=3D tests/benchmark-crypt= o-cipher$(EXESUF) check-unit-$(CONFIG_BLOCK) +=3D tests/test-crypto-secret$(EXESUF) check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_GNUTLS)) +=3D tests/test-c= rypto-tlscredsx509$(EXESUF) check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_GNUTLS)) +=3D tests/test-c= rypto-tlssession$(EXESUF) +ifndef CONFIG_TSAN +# Some tests: test-char, test-qdev-global-props, and test-qga, +# are not runnable under TSan due to a known issue. +# https://github.com/google/sanitizers/issues/1116 +check-unit-$(CONFIG_SOFTMMU) +=3D tests/test-char$(EXESUF) +check-unit-y +=3D tests/test-qdev-global-props$(EXESUF) ifneq (,$(findstring qemu-ga,$(TOOLS))) check-unit-$(call land,$(CONFIG_LINUX),$(CONFIG_VIRTIO_SERIAL)) +=3D tests= /test-qga$(EXESUF) endif +endif check-unit-y +=3D tests/test-timed-average$(EXESUF) check-unit-$(CONFIG_INOTIFY1) +=3D tests/test-util-filemonitor$(EXESUF) check-unit-y +=3D tests/test-util-sockets$(EXESUF) diff --git a/tests/qtest/Makefile.include b/tests/qtest/Makefile.include index 9e5a51d033..71fd714a2a 100644 --- a/tests/qtest/Makefile.include +++ b/tests/qtest/Makefile.include @@ -313,12 +313,15 @@ tests/qtest/tpm-tis-device-test$(EXESUF): tests/qtest= /tpm-tis-device-test.o test # QTest rules =20 TARGETS=3D$(patsubst %-softmmu,%, $(filter %-softmmu,$(TARGET_DIRS))) +QTEST_TARGETS =3D +# The qtests are not runnable (yet) under TSan due to a known issue. +# https://github.com/google/sanitizers/issues/1116 +ifndef CONFIG_TSAN ifeq ($(CONFIG_POSIX),y) QTEST_TARGETS =3D $(TARGETS) check-qtest-y=3D$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)-y:%= =3Dtests/qtest/%$(EXESUF))) check-qtest-y +=3D $(check-qtest-generic-y:%=3Dtests/qtest/%$(EXESUF)) -else -QTEST_TARGETS =3D +endif endif =20 qtest-obj-y =3D tests/qtest/libqtest.o $(test-util-obj-y) --=20 2.17.1