llvm-project/compiler-rt/lib
Dmitry Vyukov 7ec308715c tsan: prevent pathological slowdown for spurious races
Prevent the following pathological behavior:
Since memory access handling is not synchronized with DoReset,
a thread running concurrently with DoReset can leave a bogus shadow value
that will be later falsely detected as a race. For such false races
RestoreStack will return false and we will not report it.
However, consider that a thread leaves a whole lot of such bogus values
and these values are later read by a whole lot of threads.
This will cause massive amounts of ReportRace calls and lots of
serialization. In very pathological cases the resulting slowdown
can be >100x. This is very unlikely, but it was presumably observed
in practice: https://github.com/google/sanitizers/issues/1552
If this happens, previous access sid+epoch will be the same for all of
these false races b/c if the thread will try to increment epoch, it will
notice that DoReset has happened and will stop producing bogus shadow
values. So, last_spurious_race is used to remember the last sid+epoch
for which RestoreStack returned false. Then it is used to filter out
races with the same sid+epoch very early and quickly.
It is of course possible that multiple threads left multiple bogus shadow
values and all of them are read by lots of threads at the same time.
In such case last_spurious_race will only be able to deduplicate a few
races from one thread, then few from another and so on. An alternative
would be to hold an array of such sid+epoch, but we consider such scenario
as even less likely.
Note: this can lead to some rare false negatives as well:
1. When a legit access with the same sid+epoch participates in a race
as the "previous" memory access, it will be wrongly filtered out.
2. When RestoreStack returns false for a legit memory access because it
was already evicted from the thread trace, we will still remember it in
last_spurious_race. Then if there is another racing memory access from
the same thread that happened in the same epoch, but was stored in the
next thread trace part (which is still preserved in the thread trace),
we will also wrongly filter it out while RestoreStack would actually
succeed for that second memory access.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D130269
2022-07-25 10:40:11 +02:00
..
BlocksRuntime
asan [libasan] Remove 4Mb stack limit for swapcontext unpoisoning 2022-07-22 17:37:44 -07:00
builtins [compiler-rt][CMake] Enable TF intrinsics on powerpc32 Linux 2022-07-24 10:17:22 -07:00
cfi sanitizer_common: prefix thread-safety macros with SANITIZER_ 2022-01-07 15:11:00 +01:00
crt Revert "[compiler-rt] Use C_STANDARD instead of custom logic for adding -std=c11" 2022-04-27 00:20:44 +03:00
dfsan [DFSan] Remove deprecated flag from build-libc-list.py 2022-06-01 11:00:13 -07:00
fuzzer [CMake] Option to select C++ library for runtimes that use it 2022-07-08 22:10:24 +00:00
gwp_asan [compiler-rt][CMake] Set --unwindlib=none when using LLVM libunwind 2022-07-15 07:25:38 +00:00
hwasan [NFC] Clang-format D129645 2022-07-14 10:27:04 -07:00
interception [compiler-rt][CMake] Set --unwindlib=none when using LLVM libunwind 2022-07-15 07:25:38 +00:00
lsan [lsan][nfc] Add missing newline to VReport 2022-07-15 15:44:23 -04:00
memprof [NFC][memprof] Remove unused code 2022-07-20 18:50:45 -07:00
msan Add the FreeBSD AArch64 memory layout 2022-07-19 09:58:04 -04:00
orc [compiler-rt][CMake] Set --unwindlib=none when using LLVM libunwind 2022-07-15 07:25:38 +00:00
profile [Compiler-RT] Remove FlushViewOfFile call when unmapping gcda files on win32. 2022-07-05 13:24:28 +00:00
safestack [compiler-rt] Fix Mmap on FreeBSD AArch64 2022-06-08 17:22:33 -04:00
sanitizer_common [MIPS][compiler-rt] Fix stat struct's size for O32 ABI 2022-07-23 11:53:00 +02:00
scudo [compiler-rt][CMake] Set --unwindlib=none when using LLVM libunwind 2022-07-15 07:25:38 +00:00
stats [compiler-rt] separate lsan, ubsan, stats configuration from SANITIZER_COMMON_SUPPORTED_OS 2021-11-10 19:16:20 -08:00
tsan tsan: prevent pathological slowdown for spurious races 2022-07-25 10:40:11 +02:00
ubsan [Sanitizer][Darwin][NFC] Small SANITIZER_APPLE cleanup 2022-07-15 16:31:35 -07:00
ubsan_minimal [compiler-rt] separate lsan, ubsan, stats configuration from SANITIZER_COMMON_SUPPORTED_OS 2021-11-10 19:16:20 -08:00
xray [compiler-rt][CMake] Set --unwindlib=none when using LLVM libunwind 2022-07-15 07:25:38 +00:00
CMakeLists.txt Revert D120327 "compiler-rt: Add udivmodei5 to builtins and add bitint library" 2022-04-08 12:39:42 -07:00