Skip to content

Fix a race condition in GCStress#41540

Merged
BruceForstall merged 1 commit intodotnet:masterfrom
BruceForstall:Fix36681
Aug 29, 2020
Merged

Fix a race condition in GCStress#41540
BruceForstall merged 1 commit intodotnet:masterfrom
BruceForstall:Fix36681

Conversation

@BruceForstall
Copy link
Contributor

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 #36681

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
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 28, 2020
// It is call by register
instructionIsACallThroughRegister = TRUE;
}
else
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


#endif // _TARGET_*

if (!IsGcCoverageInterruptInstruction(instrPtr))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the real fix: moving this code here from above the atCall setting code.

@BruceForstall BruceForstall merged commit c4b9dab into dotnet:master Aug 29, 2020
@BruceForstall BruceForstall deleted the Fix36681 branch August 29, 2020 17:22
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test failure: JIT\\Regression\\JitBlue\\GitHub_27924\\GitHub_27924\\GitHub_27924.cmd

3 participants