[release/8.0-staging] Fix missing release semantics in VolatilePtr#124118
Open
github-actions[bot] wants to merge 1 commit intorelease/8.0-stagingfrom
Open
[release/8.0-staging] Fix missing release semantics in VolatilePtr#124118github-actions[bot] wants to merge 1 commit intorelease/8.0-stagingfrom
github-actions[bot] wants to merge 1 commit intorelease/8.0-stagingfrom
Conversation
VolatilePtr inherits from Volatile<P>, which defines operator=(P val) to call VolatileStore() with release semantics (stlr on ARM64). However, VolatilePtr did not declare its own operator=, so the compiler-generated copy/move assignment operator hid the base class operator= and performed plain stores (str) instead, bypassing the memory barrier entirely. This affected all VolatilePtr assignments including DeadlockAwareLock's m_pHoldingThread and Thread's m_pBlockingLock fields, which were being written without release semantics despite being read with acquire semantics (ldapr) on the other side. Fix by adding a using declaration to bring Volatile<P>::operator= into scope, and an explicit copy assignment operator (which the using declaration cannot suppress the compiler from generating).
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.
Related issue: #124071
Main PR: 124096
Risk: Low, purely adds a barrier which is the intended semantics of the class.
Testing: manual disassembly inspection verified that affected callsite now have appropriate barriers.
Impact: Detected as a non-deterministic lock free race that resulted in crashes in the Roslyn language server for internal customers. Mostly happens with really complex solutions that have a lot of threads accessing GC Statics.
VolatilePtrinherits fromVolatile<P>, which definesoperator=to callVolatileStore()with platform scpecific release semantics. However,VolatilePtrdid not declare its ownoperator=, so the compiler-generated copy/move assignment operator hid the base classoperator=and performed plain stores instead, bypassing memory barriers entirely.Fix by adding a using declaration to bring
Volatile<P>::operator=into scope, and an explicit copy assignment operator (which the using declaration cannot suppress the compiler from generating).