Skip to content

Add Thread Sanitizer support to QEMU

Robert Foley qemu-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest19 patches 30 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/19configure: add --enable-tsan flag + fiber annotations for coroutine-ucontextconfigure util/coroutine-ucontext.c+127 -95 replies
2/19cpu: convert queued work to a QSIMPLEQcpus-common.c cpus.c hw/core/cpu.c +1 more+24 -222 replies
3/19thread: add qemu_spin_destroyinclude/qemu/thread.h+3 -00 replies
4/19cputlb: destroy CPUTLB with tlb_destroyaccel/tcg/cputlb.c exec.c include/exec/exec-all.h+24 -00 replies
5/19qht: call qemu_spin_destroy for head bucketsutil/qht.c+1 -00 replies
6/19tcg: call qemu_spin_destroy for tb->jmp_lockaccel/tcg/translate-all.c include/tcg/tcg.h tcg/tcg.c+27 -50 replies
7/19translate-all: call qemu_spin_destroy for PageDescaccel/tcg/translate-all.c+9 -00 replies
8/19thread: add tsan annotations to QemuSpininclude/qemu/thread.h+36 -30 replies
9/19tests/docker: Added docker build support for TSan.tests/docker/Makefile.include tests/docker/common.rc tests/docker/dockerfiles/ubuntu2004.docker +1 more+100 -00 replies
10/19include/qemu: Added tsan.h for annotations.include/qemu/tsan.h+48 -02 replies
11/19accel/tcg: Fixed tsan warnings related to parallel_cpusaccel/tcg/cpu-exec.c cpus.c include/exec/exec-all.h +1 more+6 -61 reply
12/19configure: added tsan support for blacklist.configure tests/tsan/blacklist.tsan+7 -12 replies
13/19accel/tcg: Fixed tsan warnings.accel/tcg/tcg-all.c accel/tcg/tcg-runtime.c accel/tcg/translate-all.c +1 more+14 -53 replies
14/19util/async: Fixed tsan warningsutil/async.c+9 -24 replies
15/19qht: Fix tsan warnings.util/qht.c+3 -01 reply
16/19util: fixed tsan warnings in thread_pool.cutil/thread-pool.c+4 -11 reply
17/19util: Added tsan annotate for thread name.util/qemu-thread-posix.c+2 -01 reply
18/19target/arm: Fix tsan warning in cpu.ctarget/arm/cpu.c+1 -15 replies
19/19docs: Added details on TSan to testing.rstdocs/devel/testing.rst+72 -01 reply

Reviews trailers per patch

5 of 19 patches have a Reviewed-by or Acked-by.

PatchRichard HendersonAlex BennéeEmilio G. CotaPhilippe Mathieu-Daudé
1/19
2/19R-b R-b R-b
3/19
4/19
5/19
6/19
7/19
8/19
9/19
10/19R-b
11/19R-b
12/19
13/19
14/19
15/19
16/19
17/19R-b
18/19
19/19R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v1 thread

Cover letter [PATCH 00/19] Add Thread Sanitizer support to QEMU

This patch series continues the work done by Emilio Cota and others to add Thread Sanitizer (TSan) support to QEMU.

The starting point for this work was Emilio's branch here:
https://github.com/cota/qemu/commits/tsan
specifically this commit: 0be125fc0afd47218b34d2019abdd19b644f3199

The purpose of this patch is not to fix all the TSan warnings, but to enable the TSan support so that QEMU developers can start using the tool. We found this tool useful and even ran it on our recent changes in the cpu-locks series.
Clearly there is work to do here to clean up all the warnings. :) We have made a start to cleaning up these warnings by getting a VM to boot cleanly with no TSan warnings.
We have also made an effort to introduce enough of the TSan suppression mechanisms, so that others can continue this work.

This series adds support for:
- configure option for --enable-tsan.
- testing.rst has the full details on how to use TSan with docker and also outside of docker.
- Docker builds with TSan.
- We added an Ubuntu 20.04 docker that supports TSan builds.
- Something like this will build TSan
make docker-test-build@ubuntu2004 DEBUG=1 TSAN=1
- Testing with TSan is also supported with docker,
although, be forwarned that test-quick currently fails.
See "Issues" section below for the current failures.
make docker-test-quick@ubuntu2004 DEBUG=1 TSAN=1
- We recommend using the DEBUG=1 option and launching the test (like test-quick) from inside the docker so that when the test is done, you can review the warnings from inside the docker.
- testing.rst has the full details on how to use TSan with docker.
- We added a blacklist file for files/functions
TSan should ignore at compile time.
- And added a suppression file for TSan to suppress certain warnings at run time.
We found both of these mechanisms are needed when suppressing warnings.
- It is also worth mentioning that we were able to suppress/fix enough errors to allow an Ubuntu 18.04 aarch64 VM to boot with zero TSan warnings. When we started this effort, there were ~300 warnings reported by TSan during the same VM boot !

Issues:
- When running docker-test-quick under TSan there are several tests which hang
- The unit tests which seem to hang under TSan:
test-char, test-qdev-global-props, and test-qga.
- If we comment out those tests, check-unit finishes, albeit with a couple of warnings. :)

Emilio G. Cota (7):
cpu: convert queued work to a QSIMPLEQ
thread: add qemu_spin_destroy
cputlb: destroy CPUTLB with tlb_destroy
qht: call qemu_spin_destroy for head buckets
tcg: call qemu_spin_destroy for tb->jmp_lock
translate-all: call qemu_spin_destroy for PageDesc
thread: add tsan annotations to QemuSpin

Lingfeng Yang (1):
configure: add --enable-tsan flag + fiber annotations for
coroutine-ucontext

Robert Foley (11):
tests/docker: Added docker build support for TSan. include/qemu: Added tsan.h for annotations. accel/tcg: Fixed tsan warnings related to parallel_cpus
configure: added tsan support for blacklist. accel/tcg: Fixed tsan warnings.
util/async: Fixed tsan warnings
qht: Fix tsan warnings.
util: fixed tsan warnings in thread_pool.c
util: Added tsan annotate for thread name. target/arm: Fix tsan warning in cpu.c
docs: Added details on TSan to testing.rst

 accel/tcg/cpu-exec.c                       |  4 +-
 accel/tcg/cputlb.c                         | 15 ++++
 accel/tcg/tcg-all.c                        |  4 +-
 accel/tcg/tcg-runtime.c                    |  7 +-
 accel/tcg/translate-all.c                  | 25 +++++-
 configure                                  | 40 +++++++++
 cpus-common.c                              | 25 ++----
 cpus.c                                     | 16 +++-
 docs/devel/testing.rst                     | 72 ++++++++++++++++
 exec.c                                     |  1 +
 hw/core/cpu.c                              |  3 +-
 include/exec/exec-all.h                    | 10 ++-
 include/hw/core/cpu.h                      |  6 +-
 include/qemu/thread.h                      | 38 ++++++++-
 include/qemu/tsan.h                        | 48 +++++++++++
 include/tcg/tcg.h                          |  3 +-
 linux-user/syscall.c                       |  4 +-
 target/arm/cpu.c                           |  2 +-
 tcg/tcg.c                                  | 19 ++++-
 tests/docker/Makefile.include              |  2 +
 tests/docker/common.rc                     | 19 +++++
 tests/docker/dockerfiles/ubuntu2004.docker | 65 +++++++++++++++
 tests/tsan/blacklist.tsan                  |  5 ++
 tests/tsan/suppressions.tsan               | 14 ++++
 util/async.c                               | 11 ++-
 util/coroutine-ucontext.c                  | 97 ++++++++++++++++++++--
 util/qemu-thread-posix.c                   |  2 +
 util/qht.c                                 |  4 +
 util/thread-pool.c                         |  5 +-
 29 files changed, 514 insertions(+), 52 deletions(-)
 create mode 100644 include/qemu/tsan.h
 create mode 100644 tests/docker/dockerfiles/ubuntu2004.docker
 create mode 100644 tests/tsan/blacklist.tsan
 create mode 100644 tests/tsan/suppressions.tsan
Signature · 1 line
2.17.1