[release/10.0] Change PerfMap CRST to use UNSAFE_ANYMODE#128430
Closed
hoyosjs wants to merge 1 commit into
Closed
Conversation
Contributor
|
Tagging subscribers to this area: @agocke |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the CoreCLR PerfMap synchronization strategy to avoid a GC-mode toggle deadlock that can permanently hang Linux .NET processes when PerfMap is enabled. It does this by making the PerfMap lock safe to acquire without forcing cooperative/preemptive GC transitions, matching other native-only locks used on the relevant execution paths.
Changes:
- Initialize
PerfMap::s_csPerfMapwithCRST_UNSAFE_ANYMODEto eliminate GC-mode toggling during lock acquisition. - Relax
PerfMap::LogJITCompiledMethodcontract fromMODE_PREEMPTIVEtoMODE_ANYto reflect the updated locking/mode behavior.
jkotas
reviewed
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #128401
main PR #128429
Description
A .NET process on Linux can permanently deadlock when PerfMap is enabled (
DOTNET_PerfMapEnabledor via Diagnostics Server IPC). The deadlock is a three-way cycle between GC suspension,CodeFragmentHeap::m_Lock(CRST_UNSAFE_ANYMODE), andPerfMap::s_csPerfMap(CRST_DEFAULT).Acuiring s_csPerfMap on a coop thread toggles a to preemptive before acquiring the mutex, then back to cooperative after. The post-acquire DisablePreemptiveGC can block indefinitely via
RareDisablePreemptiveGCwhen a GC suspension is in progress if another thread started GC suspension and a that hasn't been suspended tries to hold CodeFragmentHeap lock. That thread cannot reach a GC safe point, so we end up blocking suspension indefinitely.The fix changes s_csPerfMap to
CRST_UNSAFE_ANYMODE, eliminating the GC-mode toggle. All data accessed under this lock is native (FILE*, fd, SString), so holding it in cooperative mode introduces no new GC-safety issues — the I/O was already performed in cooperative mode with the previous default Crst (the toggle only affected the mutex-wait phase, not the work phase). The IO operations could be slow and cause gc pause times, but those are already done in coop mode right now so it's not regressing that case.Customer Impact
Any .NET application running with PerfMap enabled on Linux (directly or via diagnostic tools like dotnet-trace, dotnet-monitor, or third-party APM agents) can hang permanently under concurrent virtual-call-stub creation and GC pressure. The process becomes unresponsive with no way to recover short of killing it. The only workaround is disabling both DOTNET_PerfMapEnabled=0 and DOTNET_EnableDiagnostics_IPC=0, which disables all perf profiling and diagnostics capabilities.
Regression
Yes, from 8 to 10. Likely around perfmap granularity changes when stub creation got rewritten.
Testing
Risk
Low. The change is a single flag addition to a lock initialization call. CRST_UNSAFE_ANYMODE is well-established and widely used throughout the VM for locks that protect native-only data (e.g., CodeFragmentHeap::m_Lock, m_JumpStubCrst, m_CodeHeapLock). The behavioral change is strictly a removal of an unnecessary GC-mode toggle - the I/O under the lock was already executing in cooperative mode after the post-acquire toggle, so no new GC-latency regression is introduced.