Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Fix profiler enter callback init reg trash logic #100637

Merged
merged 2 commits into from
Apr 4, 2024

Conversation

jakobbotsch
Copy link
Member

During prolog generation we sometimes generate code to call the profiler enter callback. This may trash the "initReg" that we expect to keep zeroed during the prolog. The logic to check if the initReg was being trashed was wrong in a couple of cases:

  • Most backends did not take into account that the logic also trashes the registers used for arguments to the enter callback
  • SysV x64 thought that the enter callback trashed the parameter registers, but it does not

This generally did not cause issues because genFnPrologCalleeRegArgs is unnecessarily conservative around whether or not it trashes initReg, and it comes after the profiler callback in the prolog. However, with the rewrite of the homing function that is not going to be the case anymore.

Fixes an issue I noticed by inspection over in #100572

During prolog generation we sometimes generate code to call the profiler
enter callback. This may trash the "initReg" that we expect to keep
zeroed during the prolog. The logic to check if the initReg was being
trashed was wrong in a couple of cases:
- Most backends did not take into account that the logic also trashes
  the registers used for arguments to the enter callback
- SysV x64 thought that the enter callback trashed the parameter
  registers, but it does not

This generally did not cause issues because `genFnPrologCalleeRegArgs`
is unnecessarily conservative around whether or not it trashes
`initReg`, and it comes after the profiler callback in the prolog.
However, with the rewrite of the homing function that is not going to be
the case anymore.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 4, 2024
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@jakobbotsch
Copy link
Member Author

/azp run runtime-coreclr jitstress, runtime-coreclr libraries-jitstress

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@jakobbotsch jakobbotsch marked this pull request as ready for review April 4, 2024 19:14
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @BruceForstall

@BruceForstall
Copy link
Member

No diffs -- so no test coverage?

@jakobbotsch
Copy link
Member Author

No diffs -- so no test coverage?

We have test coverage in stress due to STRESS_PROFILER_CALLBACKS. I hit the problem over in #100572. There it wasn't a problem in the baseline because genFnPrologCalleeRegArgs mistakenly was marking the initReg as clobbered (even though it didn't actually end up using it for anything).

@jakobbotsch jakobbotsch merged commit 96d5a66 into dotnet:main Apr 4, 2024
135 checks passed
@jakobbotsch jakobbotsch deleted the profiler-trashed branch April 4, 2024 19:33
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
During prolog generation we sometimes generate code to call the profiler
enter callback. This may trash the "initReg" that we expect to keep
zeroed during the prolog. The logic to check if the initReg was being
trashed was wrong in a couple of cases:
- Most backends did not take into account that the logic also trashes
  the registers used for arguments to the enter callback
- SysV x64 thought that the enter callback trashed the parameter
  registers, but it does not

This generally did not cause issues because `genFnPrologCalleeRegArgs`
is unnecessarily conservative around whether or not it trashes
`initReg`, and it comes after the profiler callback in the prolog.
However, with the rewrite of the homing function that is not going to be
the case anymore.
@github-actions github-actions bot locked and limited conversation to collaborators May 5, 2024
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.

2 participants