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

[Release/6.0] Backporting recent fixes related to AVX and suspension. #66120

Merged
merged 4 commits into from
Mar 8, 2022

Conversation

VSadov
Copy link
Member

@VSadov VSadov commented Mar 2, 2022

Port of a fix for #65292 and issues found along the way related to AVX registers and EE suspension.

Customer Impact

It is relatively easy to end up running AVX-accelerated code nowdays. Copying or comparing arrays or spans, using buffered IO are just some examples.

Issues with storing/restoring AVX context during EE suspension could result in:

  • data corruption when running in x86 WOW on Windows11 and Server2022
  • crashes when performing GC stress (x64, Win10)

Testing

Regular test passes.

Risk

Medium.

The code involved is fairly old. We keep discovering assumptions that may no longer hold. We have seen cases where fixing one bug exposes another. To our knowledge these fixes are robust, but this is a delicate area.

VSadov and others added 4 commits March 2, 2022 15:27
* Use CopyContext to restore saved context on X86

* PR feedback

* more PR feedback
…net#65825)

* Do not copy XState other than AVX

* #if defined(TARGET_X86) || defined(TARGET_AMD64)

* mask XState unconditionally

* Ensure XSTATE_MASK_AVX is set before calling EEGetThreadContext

* redundant supportsAVX, more clear comment

* PR feedback
* null-check the redirect context before using.

* tweak the comment

* do not allocate context if InitializeContext has unexpected results.
…net#65878)

* RestoreContextSimulated

* probe for RtlRestoreContext

* ntdll.dll

* restore self-trap sequence

* PR feedback

* Clarify CopyContext in RedirectedHandledJITCaseExceptionFilter

* simpler indentation.

* restore last error on the legacy path.

* Update src/coreclr/vm/threads.h

Co-authored-by: Dan Moseley <[email protected]>
@ghost ghost assigned VSadov Mar 2, 2022
@VSadov VSadov changed the title Backporting recent fixes related to AVX and suspension. [Release/6.0] Backporting recent fixes related to AVX and suspension. Mar 3, 2022
@VSadov VSadov marked this pull request as ready for review March 3, 2022 05:08
@VSadov
Copy link
Member Author

VSadov commented Mar 3, 2022

CC:@agocke

@agocke agocke requested a review from jkotas March 3, 2022 05:13
@VSadov VSadov added the Servicing-consider Issue for next servicing release review label Mar 3, 2022
Copy link
Member

@jeffschwMSFT jeffschwMSFT left a comment

Choose a reason for hiding this comment

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

Approved. We should take for consideration in 6.0.x

@jeffschwMSFT jeffschwMSFT added this to the 6.0.x milestone Mar 3, 2022
@rbhanda rbhanda added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Mar 3, 2022
@rbhanda rbhanda modified the milestones: 6.0.x, 6.0.4 Mar 3, 2022
@agocke
Copy link
Member

agocke commented Mar 3, 2022

/backport to release/5.0

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2022

Started backporting to release/5.0: https://github.com/dotnet/runtime/actions/runs/1929796872

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2022

@agocke backporting to release/5.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Use CopyContext to restore saved context on X86 (#65490)
Using index info to reconstruct a base tree...
A	src/coreclr/vm/threadsuspend.cpp
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/src/vm/threadsuspend.cpp
Applying: Do not copy XState other than AVX when redirecting for GC stress (#65825)
.git/rebase-apply/patch:53: trailing whitespace.
    // 
.git/rebase-apply/patch:55: trailing whitespace.
    // 
warning: 2 lines add whitespace errors.
Using index info to reconstruct a base tree...
A	src/coreclr/vm/threadsuspend.cpp
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/src/vm/threadsuspend.cpp
Applying: null-check the redirect context before using. (#65910)
Using index info to reconstruct a base tree...
A	src/coreclr/vm/threadsuspend.cpp
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/src/vm/threadsuspend.cpp
CONFLICT (content): Merge conflict in src/coreclr/src/vm/threadsuspend.cpp
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0003 null-check the redirect context before using. (#65910)
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@carlossanlop
Copy link
Member

@agocke your backport attempt to 5.0 failed. Just to make sure I'm understanding it correctly, this error does not affect the ability to merge this PR, correct? Can I already merge this since it is already servicing-approved and the CI is all green?

@agocke
Copy link
Member

agocke commented Mar 8, 2022

Yup, this one can be merged. I'll do the backport for 5.0 and 3.1 manually.

@carlossanlop carlossanlop merged commit 1ec6f8e into dotnet:release/6.0 Mar 8, 2022
carlossanlop pushed a commit that referenced this pull request Mar 15, 2022
* Use CopyContext to restore saved context on X86 (#65490)

* Use CopyContext to restore saved context on X86

* PR feedback

* more PR feedback

* Do not copy XState other than AVX when redirecting for GC stress (#65825)

* Do not copy XState other than AVX

* #if defined(TARGET_X86) || defined(TARGET_AMD64)

* mask XState unconditionally

* Ensure XSTATE_MASK_AVX is set before calling EEGetThreadContext

* redundant supportsAVX, more clear comment

* PR feedback

* null-check the redirect context before using. (#65910)

* null-check the redirect context before using.

* tweak the comment

* do not allocate context if InitializeContext has unexpected results.

* EE Suspension on x86 should use RtlRestoreContext when available (#65878)

* RestoreContextSimulated

* probe for RtlRestoreContext

* ntdll.dll

* restore self-trap sequence

* PR feedback

* Clarify CopyContext in RedirectedHandledJITCaseExceptionFilter

* simpler indentation.

* restore last error on the legacy path.

* Update src/coreclr/vm/threads.h

Co-authored-by: Dan Moseley <[email protected]>

Co-authored-by: Vladimir Sadov <[email protected]>
Co-authored-by: Dan Moseley <[email protected]>
@ghost ghost locked as resolved and limited conversation to collaborators Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VM-coreclr Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants