[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 01/19] configure: add --enable-tsan flag + fiber annotations
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH 01/19] configure: add --enable-tsan flag + fiber annotations for coroutine-ucontext |
Date: |
Sat, 23 May 2020 18:55:44 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 |
Hi Robert,
On 5/22/20 6:07 PM, Robert Foley wrote:
> From: Lingfeng Yang <address@hidden>
>
> We tried running QEMU under tsan in 2016, but tsan's lack of support for
> longjmp-based fibers was a blocker:
> https://groups.google.com/forum/#!topic/thread-sanitizer/se0YuzfWazw
>
> Fortunately, thread sanitizer gained fiber support in early 2019:
> https://reviews.llvm.org/D54889
>
> This patch brings tsan support upstream by importing the patch that annotated
> QEMU's coroutines as tsan fibers in Android's QEMU fork:
> https://android-review.googlesource.com/c/platform/external/qemu/+/844675
>
> Tested with '--enable-tsan --cc=clang-9 --cxx=clang++-9 --disable-werror'
> configure flags.
>
> Signed-off-by: Lingfeng Yang <address@hidden>
> Signed-off-by: Emilio G. Cota <address@hidden>
> [cota: minor modifications + configure changes]
> Signed-off-by: Robert Foley <address@hidden>
> [RF: minor changes to clean up checkpatch warnings/errors]
> ---
> configure | 39 ++++++++++++++++
> util/coroutine-ucontext.c | 97 +++++++++++++++++++++++++++++++++++----
> 2 files changed, 127 insertions(+), 9 deletions(-)
>
> diff --git a/configure b/configure
> index 26084fc53a..c95c54fb48 100755
> --- a/configure
> +++ b/configure
> @@ -395,6 +395,7 @@ gprof="no"
> debug_tcg="no"
> debug="no"
> sanitizers="no"
> +tsan="no"
> fortify_source=""
> strip_opt="yes"
> tcg_interpreter="no"
> @@ -1150,6 +1151,10 @@ for opt do
> ;;
> --disable-sanitizers) sanitizers="no"
> ;;
> + --enable-tsan) tsan="yes"
> + ;;
> + --disable-tsan) tsan="no"
> + ;;
> --enable-sparse) sparse="yes"
> ;;
> --disable-sparse) sparse="no"
> @@ -1750,6 +1755,7 @@ Advanced options (experts only):
> --with-pkgversion=VERS use specified string as sub-version of the package
> --enable-debug enable common debug build options
> --enable-sanitizers enable default sanitizers
> + --enable-tsan enable thread sanitizer
> --disable-strip disable stripping binaries
> --disable-werror disable compilation abort on warning
> --disable-stack-protector disable compiler-provided stack protection
> @@ -6176,6 +6182,27 @@ if test "$fuzzing" = "yes" ; then
> fi
> fi
>
> +# Thread sanitizer is, for now, much noisier than the other sanitizers;
> +# keep it separate until that is not the case.
> +have_tsan=no
> +have_tsan_iface_fiber=no
> +if test "$tsan" = "yes" ; then
> + write_c_skeleton
> + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
> + have_tsan=yes
> + fi
> + cat > $TMPC << EOF
> +#include <sanitizer/tsan_interface.h>
> +int main(void) {
> + __tsan_create_fiber(0);
> + return 0;
> +}
> +EOF
> + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
> + have_tsan_iface_fiber=yes
> + fi
> +fi
> +
> ##########################################
> # check for libpmem
>
> @@ -6277,6 +6304,14 @@ if test "$have_asan" = "yes"; then
> "Without code annotation, the report may be inferior."
> fi
> fi
> +if test "$have_tsan" = "yes" ; then
> + if test "$have_tsan_iface_fiber" = "yes" ; then
> + QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
> + QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
> + else
> + echo "Cannot enable TSAN due to missing fiber annotation interface."
I tried your series and there were no changes anywhere, then I looked at
how TSan work, started to debug, to finally realize my build was not
using TSan (clang8). Please use to something such:
if test "$tsan" = "yes" ; then
error_exit "Cannot enable TSAN due to missing fiber" \
"annotation interface."
fi
> + fi
> +fi
> if test "$have_ubsan" = "yes"; then
> QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
> QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
> @@ -7365,6 +7400,10 @@ if test "$have_asan_iface_fiber" = "yes" ; then
> echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
> fi
>
> +if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
> + echo "CONFIG_TSAN=y" >> $config_host_mak
> +fi
> +
> if test "$has_environ" = "yes" ; then
> echo "CONFIG_HAS_ENVIRON=y" >> $config_host_mak
> fi
[...]
- [PATCH 00/19] Add Thread Sanitizer support to QEMU, Robert Foley, 2020/05/22
- [PATCH 01/19] configure: add --enable-tsan flag + fiber annotations for coroutine-ucontext, Robert Foley, 2020/05/22
- Re: [PATCH 01/19] configure: add --enable-tsan flag + fiber annotations for coroutine-ucontext,
Philippe Mathieu-Daudé <=
- [PATCH 02/19] cpu: convert queued work to a QSIMPLEQ, Robert Foley, 2020/05/22
- [PATCH 03/19] thread: add qemu_spin_destroy, Robert Foley, 2020/05/22
- [PATCH 04/19] cputlb: destroy CPUTLB with tlb_destroy, Robert Foley, 2020/05/22
- [PATCH 06/19] tcg: call qemu_spin_destroy for tb->jmp_lock, Robert Foley, 2020/05/22
- [PATCH 07/19] translate-all: call qemu_spin_destroy for PageDesc, Robert Foley, 2020/05/22
- [PATCH 08/19] thread: add tsan annotations to QemuSpin, Robert Foley, 2020/05/22
- [PATCH 09/19] tests/docker: Added docker build support for TSan., Robert Foley, 2020/05/22