-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Do not copy XState other than AVX when redirecting for GC stress #65825
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
Changes from 4 commits
0ccc1c0
95204ea
7951248
d531d3d
c552ae2
ef7bcdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1997,15 +1997,6 @@ CONTEXT* AllocateOSContextHelper(BYTE** contextBuffer) | |
| pfnInitializeContext2(buffer, context, &pOSContext, &contextSize, xStateCompactionMask): | ||
| InitializeContext(buffer, context, &pOSContext, &contextSize); | ||
|
|
||
| // if AVX is supported set the appropriate features mask in the context | ||
| if (success && supportsAVX) | ||
| { | ||
| // This should not normally fail. | ||
| // The system silently ignores any feature specified in the FeatureMask | ||
| // which is not enabled on the processor. | ||
| success = SetXStateFeaturesMask(pOSContext, XSTATE_MASK_AVX); | ||
| } | ||
|
|
||
| if (!success) | ||
| { | ||
| delete[] buffer; | ||
|
|
@@ -2912,9 +2903,23 @@ BOOL Thread::RedirectThreadAtHandledJITCase(PFN_REDIRECTTARGET pTgt) | |
|
|
||
| ////////////////////////////////////// | ||
| // Get and save the thread's context | ||
| BOOL bRes = true; | ||
|
|
||
| // Always get complete context, pCtx->ContextFlags are set during Initialization | ||
| BOOL bRes = EEGetThreadContext(this, pCtx); | ||
|
|
||
| #if defined(TARGET_X86) || defined(TARGET_AMD64) | ||
| // Scenarios like GC stress may indirectly disable XState features in the pCtx | ||
| // depending on the state at the time of GC stress interrupt. | ||
| // | ||
| // Make sure that AVX feature mask is set, if supported. | ||
| // | ||
| // This should not normally fail. | ||
| // The system silently ignores any feature specified in the FeatureMask | ||
| // which is not enabled on the processor. | ||
| bRes &= SetXStateFeaturesMask(pCtx, XSTATE_MASK_AVX); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only have one nit - I would prefer failures / asserts on each of the failure instead of combining the results together.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Realistically only
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just found those would fail also when passed context without any XSTATE present. It seems like something that could possibly happen for the usage in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, my read on that was that Set(Get) would be a noop, but I think you are right, if no XState is set it may fail. Arguably a bug in the validation of Set not accepting 0. Yes, we should make this case work. |
||
| #endif //defined(TARGET_X86) || defined(TARGET_AMD64) | ||
|
|
||
| bRes &= EEGetThreadContext(this, pCtx); | ||
| _ASSERTE(bRes && "Failed to GetThreadContext in RedirectThreadAtHandledJITCase - aborting redirect."); | ||
|
|
||
| if (!bRes) | ||
|
|
@@ -3029,9 +3034,25 @@ BOOL Thread::RedirectCurrentThreadAtHandledJITCase(PFN_REDIRECTTARGET pTgt, CONT | |
|
|
||
| ////////////////////////////////////// | ||
| // Get and save the thread's context | ||
| BOOL success = CopyContext(pCtx, pCtx->ContextFlags, pCurrentThreadCtx); | ||
| BOOL success = true; | ||
|
|
||
| #if defined(TARGET_X86) || defined(TARGET_AMD64) | ||
| // This method is called for GC stress interrupts in managed code. | ||
| // The current context may have various XState features, depending on what is used/dirty, | ||
| // but only AVX feature may contain live data. (that could change in the future) | ||
| // Besides pCtx may not have space to store other features. | ||
| // So we will mask out everything but AVX. | ||
| DWORD64 srcFeatures = 0; | ||
| success &= GetXStateFeaturesMask(pCurrentThreadCtx, &srcFeatures); | ||
| success &= SetXStateFeaturesMask(pCurrentThreadCtx, srcFeatures & XSTATE_MASK_AVX); | ||
| #endif //defined(TARGET_X86) || defined(TARGET_AMD64) | ||
|
|
||
| success &= CopyContext(pCtx, pCtx->ContextFlags, pCurrentThreadCtx); | ||
| _ASSERTE(success); | ||
|
|
||
| if (!success) | ||
| return FALSE; | ||
|
|
||
| // Ensure that this flag is set for the next time through the normal path, | ||
| // RedirectThreadAtHandledJITCase. | ||
| pCtx->ContextFlags |= CONTEXT_EXCEPTION_REQUEST; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this removed, the code above that sets the supportAVX based on the FeatureMask can be removed too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, even before
supportAVXwas redundant, sinceSetXStateFeaturesMaskperforms the same check - to filter out what is not supported.