This is an archive of the discontinued LLVM Phabricator instance.

tsan: refactor fork handling
ClosedPublic

Authored by dvyukov on Apr 27 2021, 11:16 AM.

Details

Summary

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.

Diff Detail

Event Timeline

dvyukov created this revision.Apr 27 2021, 11:16 AM
dvyukov requested review of this revision.Apr 27 2021, 11:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2021, 11:16 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
dvyukov updated this revision to Diff 340961.Apr 27 2021, 1:04 PM

cherry pick the previous fix as it was reverted

I've squashed this with the original fix as it was reverted. I run both release and debug tests now.

vitalybuka accepted this revision.Apr 27 2021, 1:33 PM
This revision is now accepted and ready to land.Apr 27 2021, 1:33 PM

We won't know if it breaks something before we merge :) fingers crossed

This revision was landed with ongoing or failed builds.Apr 27 2021, 1:37 PM
This revision was automatically updated to reflect the committed changes.
tpopp added a subscriber: tpopp.Apr 28 2021, 5:11 AM

I'm reverting this due to test failures and emailing you a more in depth reproducer for the failures. It seems like you expected the possibility of failures, so I hope this is okay.