[all-commits] [llvm/llvm-project] ed7bf7: tsan: refactor fork handling

Dmitry Vyukov via All-commits all-commits at lists.llvm.org
Thu Apr 29 23:48:39 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ed7bf7d73fa253c770c0e715db5262f359268c3a
      https://github.com/llvm/llvm-project/commit/ed7bf7d73fa253c770c0e715db5262f359268c3a
  Author: Dmitry Vyukov <dvyukov at google.com>
  Date:   2021-04-30 (Fri, 30 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/Linux/fork_syscall.cpp
    M compiler-rt/test/tsan/pthread_atfork_deadlock.c
    M compiler-rt/test/tsan/pthread_atfork_deadlock2.c
    A compiler-rt/test/tsan/pthread_atfork_deadlock3.c

  Log Message:
  -----------
  tsan: refactor fork handling

Commit efd254b6362 ("tsan: fix deadlock in pthread_atfork callbacks")
fixed another deadlock related to atfork handling.
But builders with DCHECKs enabled reported failures of
pthread_atfork_deadlock2.c and pthread_atfork_deadlock3.c tests
related to the fact that we hold runtime locks on interceptor exit:
https://lab.llvm.org/buildbot/#/builders/70/builds/6727
This issue is somewhat inherent to the current approach,
we indeed execute user code (atfork callbacks) with runtime lock held.

Refactor fork handling to not run user code (atfork callbacks)
with runtime locks held. This change does this by installing
own atfork callbacks during runtime initialization.
Atfork callbacks run in LIFO order, so the expectation is that
our callbacks run last, right before the actual fork.
This way we lock runtime mutexes around fork, but not around
user callbacks.

Extend tests to also install after fork callbacks just to cover
more scenarios. Some tests also started reporting real races
that we previously suppressed.

Also extend tests to cover fork syscall support.

Reviewed By: vitalybuka

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




More information about the All-commits mailing list