[all-commits] [llvm/llvm-project] efd254: tsan: fix deadlock in pthread_atfork callbacks

Dmitry Vyukov via All-commits all-commits at lists.llvm.org
Tue Apr 27 04:25:46 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: efd254b63621de9ce750eddf9e8135154099d261
      https://github.com/llvm/llvm-project/commit/efd254b63621de9ce750eddf9e8135154099d261
  Author: Dmitry Vyukov <dvyukov at google.com>
  Date:   2021-04-27 (Tue, 27 Apr 2021)

  Changed paths:
    M compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
    M compiler-rt/lib/tsan/rtl/tsan_mman.cpp
    M compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
    M compiler-rt/lib/tsan/rtl/tsan_rtl.h
    M compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cpp
    M compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
    M compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
    A compiler-rt/test/tsan/pthread_atfork_deadlock3.c

  Log Message:
  -----------
  tsan: fix deadlock in pthread_atfork callbacks

We take report/thread_registry locks around fork.
This means we cannot report any bugs in atfork handlers.
We resolved this by enabling per-thread ignores around fork.
This resolved some of the cases, but not all.
The added test triggers a race report from a signal handler
called from atfork callback, we reset per-thread ignores
around signal handlers, so we tried to report it and deadlocked.
But there are more cases: a signal handler can be called
synchronously if it's sent to itself. Or any other report
types would cause deadlocks as well: mutex misuse,
signal handler spoiling errno, etc.
Disable all reports for the duration of fork with
thr->suppress_reports and don't re-enable them around
signal handlers.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101154




More information about the All-commits mailing list