[release/8.0-staging] Fix hardware exception context extraction on Rosetta#107199
Merged
janvorli merged 1 commit intorelease/8.0-stagingfrom Sep 9, 2024
Merged
Conversation
The recently added AVX support in hardware exception handling path on macOS x64 has introduced a problem when running under Rosetta. When we extract the floating point part of the context of the failing thread, the thread can have AVX or AVX512 active, or none of these. The code accidentally leaves CONTEXT_XSTATE set on the context even when no AVX was enabled on the thread. Rosetta doesn't support AVX, so having CONTEXT_XSTATE set in the context flags can lead to later call to RtlRestoreContext attempting to set ymm registers using instructions that Rosetta cannot emulate and the app crashes due to that. This doesn't happen in .NET 9, since we always clear the CONTEXT_XSTATE before exception handling stack unwinding. But in .NET 8, this causes stack overflow under Rosetta, since the attemt to execute the ymm instruction triggers the hardware exception handling again and again.
jeffschwMSFT
approved these changes
Aug 30, 2024
Member
jeffschwMSFT
left a comment
There was a problem hiding this comment.
lgtm. we will take for consideration in 8.0.x
jkotas
approved these changes
Aug 30, 2024
Contributor
|
Friendly reminder that Code Complete for the October Release is September 9. If we want this fix to be included in that release, please merge this PR before that date. |
Contributor
|
Code complete is today. If this is ready, please merge it to include in the October Release. |
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.
Backport of #107188 to release/8.0-staging
/cc @janvorli
Customer Impact
The recently added AVX support in hardware exception handling path on macOS x64 that was also backported to .NET 8 has introduced a problem when running under Rosetta. Hardware exception handling always crashes when running as x64 under Rosetta emulation on arm64 macOS. The reason is that we try to set YMM registers and AVX instructions are not emulated by Rosetta.
Regression
Introduced in 8.0.8 by #104818
Testing
Directed test of a testing application where the issue got revealed and also running all coreclr tests under Rosetta.
Risk
Low, the change just removes CONTEXT_XSTATE flag from the captured context of the hardware exception location when the OS returns context without AVX.