[all-commits] [llvm/llvm-project] 2eb3e2: tsan: fix deadlock during race reporting

Dmitry Vyukov via All-commits all-commits at lists.llvm.org
Mon Dec 20 09:53:01 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2eb3e204618209a7f3bd9fa9f6e98c38984997b2
      https://github.com/llvm/llvm-project/commit/2eb3e204618209a7f3bd9fa9f6e98c38984997b2
  Author: Dmitry Vyukov <dvyukov at google.com>
  Date:   2021-12-20 (Mon, 20 Dec 2021)

  Changed paths:
    M compiler-rt/lib/tsan/rtl/tsan_defs.h
    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/tests/unit/tsan_trace_test.cpp
    M compiler-rt/test/tsan/stress.cpp

  Log Message:
  -----------
  tsan: fix deadlock during race reporting

SlotPairLocker calls SlotLock under ctx->multi_slot_mtx.
SlotLock can invoke global reset DoReset if we are out of slots/epochs.
But DoReset locks ctx->multi_slot_mtx as well, which leads to deadlock.

Resolve the deadlock by removing SlotPairLocker/multi_slot_mtx
and only lock one slot for which we will do RestoreStack.
We need to lock that slot because RestoreStack accesses the slot journal.
But it's unclear why we need to lock the current slot.
Initially I did it just to be on the safer side (but at that time
we dit not lock the second slot, so it was easy just to lock the current slot).

Reviewed By: melver

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




More information about the All-commits mailing list