Fix a race condition in GCStress#41540
Merged
BruceForstall merged 1 commit intodotnet:masterfrom Aug 29, 2020
Merged
Conversation
Consider the case of a partially interruptible function where we've replaced each call site with INTERRUPT_INSTR_CALL or INTERRUPT_INSTR_CALL_32. Even though the call site itself isn't a safe point, we put a GCStress instruction there so we can capture the call target at GC stress time, then set a specific GCStress instruction for the next instruction that will indicate how to GC protect any GC refs that are returned from the call. Multiple threads can enter `DoGcStress` at the same time. They all get just past the race check `if (!IsGcCoverageInterruptInstruction(instrPtr)) return;`. One goes ahead, and reads the instruction code for the address at which we're doing a GCStress. We set `atCall` to `true` if this matches one of our known GCStress instructions for partially-interruptible call sites. Later, if `atCall` is `true`, we write the original call instruction back to the code stream, write the distinguished next instruction GCStress instruction, and continue. If the other threads then read at the instruction address, they might read the actual call opcode, not the distinguished GCStress breakpoint instruction code. Then, they will set `atCall` to `false`. This will indicate that we are in a fully-interruptible location, or that no special call-site behavior is required. We go on, force a GC, and eventually get to the assert in `EECodeManager::EnumGcRefs` that we are at a GC safe point. The solution is to simply move the `if (!IsGcCoverageInterruptInstruction(instrPtr))` check below the read of `*instrPtr` to set `atCall`. Re-enable the GitHub_27924 test. Fixes dotnet#36681
BruceForstall
commented
Aug 28, 2020
| // It is call by register | ||
| instructionIsACallThroughRegister = TRUE; | ||
| } | ||
| else |
Contributor
Author
There was a problem hiding this comment.
The only code change here is putting the instructionIsACallThroughImmediate case as an else clause, if we didn't first see a blx reg instruction. The rest is just whitespace and semicolons.
BruceForstall
commented
Aug 28, 2020
|
|
||
| #endif // _TARGET_* | ||
|
|
||
| if (!IsGcCoverageInterruptInstruction(instrPtr)) |
Contributor
Author
There was a problem hiding this comment.
This is the real fix: moving this code here from above the atCall setting code.
AndyAyersMS
approved these changes
Aug 29, 2020
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Consider the case of a partially interruptible function where we've replaced
each call site with INTERRUPT_INSTR_CALL or INTERRUPT_INSTR_CALL_32. Even
though the call site itself isn't a safe point, we put a GCStress instruction
there so we can capture the call target at GC stress time, then set a specific
GCStress instruction for the next instruction that will indicate how to GC
protect any GC refs that are returned from the call.
Multiple threads can enter
DoGcStressat the same time. They all get justpast the race check
if (!IsGcCoverageInterruptInstruction(instrPtr)) return;.One goes ahead, and reads the instruction code for the address at which we're
doing a GCStress. We set
atCalltotrueif this matches one of our knownGCStress instructions for partially-interruptible call sites. Later, if
atCallistrue, we write the original call instruction back to the codestream, write the distinguished next instruction GCStress instruction, and
continue. If the other threads then read at the instruction address, they
might read the actual call opcode, not the distinguished GCStress breakpoint
instruction code. Then, they will set
atCalltofalse. This will indicatethat we are in a fully-interruptible location, or that no special call-site
behavior is required. We go on, force a GC, and eventually get to the assert
in
EECodeManager::EnumGcRefsthat we are at a GC safe point.The solution is to simply move the
if (!IsGcCoverageInterruptInstruction(instrPtr))check below the read of
*instrPtrto setatCall.Re-enable the GitHub_27924 test.
Fixes #36681