Repository navigation
Ensure HasPrecode flag is read before the entry point slot - #137043
Conversation
We must ensure the HasPrecode value is read before the entry point slot is read. Otherwise hardware like a Mac M4 may reorder the reads and observe a null slot. Possible cause of dotnet#136918, though I was unable to reproduce it locally. Co-authored-by: Copilot <[email protected]> Copilot-Session: a804587b-9821-47d4-8d74-7f9e3822f595
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @agocke |
|
@davidwrighton PTAL No local repro, but this seems a likely explanation for the crash. Also seems like this pattern may exist for other similar checks on the method desc. I have not looked for those. |
There was a problem hiding this comment.
🔵 Needs a closer look
The CoreCLR entry-point publication ordering change requires runtime-maintainer review because ARM64 runtime validation is missing and its connection to crash #136918 remains unconfirmed.
No open issues 🎉
What changed in this PR
This PR strengthens CoreCLR’s precode publication ordering so readers observe HasPrecode before reading the entry point slot. It addresses a possible cause of #136918, but the connection to that crash remains unconfirmed.
Changes:
- Uses
VolatileLoadto give theHasPrecodeflag read acquire semantics. - Adds a comment explaining the required read ordering.
| File | Description |
|---|---|
src/coreclr/vm/method.hpp |
Orders the HasPrecode flag read before subsequent entry point slot reads. |
Review effort: Balanced
MethodDesc::HasPrecode()is read and then followed by a read of the entry point slot (GetPrecode()->GetStableEntryPoint()). The writer publishes the slot first and then setsHasPrecodewithInterlockedUpdateFlags3, which is ordered. The reader's two loads are plain loads, so on arm64 hardware like a Mac M4 they may be reordered, which would let the reader observeHasPrecodeset together with a stale null slot. A nullPrecode*returned toCEEInfo::getFunctionEntryPointbecomes a call through cell0x4000, which matches the dump in #136918.This reads the flag with acquire semantics so it pairs with the release on the writer side. All readers that follow
HasPrecode()withGetPrecode()are covered. It compiles toldaprhon arm64 and is free on x64.This is unconfirmed as the cause of #136918. I could not reproduce the crash in the runtime (about 12 hours of targeted stress, including SDK-shaped
dotnet testruns, on an M4 Max and an M1 Max). A message-passing litmus test modeling this protocol does show the reordering on M4 with a relaxed reader (thousands of misses per tens of millions of trials) and none with an acquire reader. I did not run the runtime test suites or benchmarks for this change.Related to #136918
Note
This PR description was drafted with the assistance of GitHub Copilot (AI-generated).