This is an archive of the discontinued LLVM Phabricator instance.

tsan: Consider SI_TIMER signals always asynchronous
ClosedPublic

Authored by melver on Jan 19 2023, 7:41 AM.

Details

Summary

POSIX timer can be configured to send any kind of signal, however, it
fundamentally does not make sense to consider a timer a synchronous
signal. Teach TSan that timers are never synchronous.

The tricky bit here is correctly defining compiler-rt's siginfo
replacement, which is a rather complex struct. Extend it in a limited
way that is mostly cross-platform compatible and add offset tests in
sanitizer_platform_limits_posix.cpp.

Diff Detail

Event Timeline

melver created this revision.Jan 19 2023, 7:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 7:41 AM
Herald added a subscriber: Enna1. · View Herald Transcript
melver requested review of this revision.Jan 19 2023, 7:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 7:41 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
dvyukov added inline comments.Jan 19 2023, 8:14 AM
compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
2176

Should we also consider TRAP_PERF && !PERF_TYPE_BREAKPOINT as async?
I guess they can be sync as well, but maybe not in the tsan meaning (can also land inside of the tsan runtime). Esp with precise_ip>0 even these are not strictly speaking synchronous. However, with tsan signal delaying they will never land on the sampled instructions (e.g. memory accesses or calls). But delaying them is still better than corrupting memory.

melver added inline comments.Jan 20 2023, 12:54 AM
compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
2176

We could just delay all TRAP_PERF, even breakpoint. If it's the difference of corrupting and crashing TSan and at least continuing to run, then at least it won't crash. Treating breakpoints specially might just be inconsistent. (Also saves us from having to maintain siginfo_t, which is a huge pain.)

It could do a one-off VPrintf that SIGTRAP perf events are best-effort?

(For us it also won't matter since we decided to disable TSan.)

dvyukov accepted this revision.Jan 20 2023, 1:06 AM
dvyukov added inline comments.
compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
2176

OK, let's just merge you current version.

This revision is now accepted and ready to land.Jan 20 2023, 1:06 AM
This revision was landed with ongoing or failed builds.Jan 20 2023, 2:48 AM
This revision was automatically updated to reflect the committed changes.