Repository navigation
Description
This test fails in the CI in the last 3 runs of Windows x86 GCStress=0x3:
\r\nAssert failure(PID 4216 [0x00001078], Thread: 7224 [0x1c38]): Consistency check failed: Invalid transition into managed code!\r\n\r\nWe're walking this thread's stack and we've reached a managed frame at Esp=0x00F7D758. (The method is Advapi32::EventWriteTransfer_PInvoke) The very next FS:0 record (0x00F7D760) up from this point on the stack should be one of our 'unmanaged to managed SEH handlers', but its not... its something else, and that's very bad. It indicates that someone managed to call into managed code without setting up the proper exception handling.\r\n\r\nGet a good unmanaged stack trace for this thread. All FS:0 records are on the stack, so you can see who installed the last handler. Somewhere between that function and where the thread is now is where the bad transition occurred.\r\n\r\nA little extra info: FS:0 = 0x00F7D370, pEHR->Handler = 0x72E381BD\r\nFAILED: IsUnmanagedToManagedSEHHandler(pEHR)\r\n\r\nCORECLR! CHECK::Trigger + 0x2FB (0x727675be)\r\nCORECLR! VerifyValidTransitionFromManagedCode + 0x165 (0x7283af20)\r\nCORECLR! StackFrameIterator::NextRaw + 0x887 (0x72806395)\r\nCORECLR! StackFrameIterator::Next + 0x46 (0x72805aca)\r\nCORECLR! Thread::StackWalkFramesEx + 0x180 (0x7280705c)\r\nCORECLR! Thread::StackWalkFrames + 0x159 (0x72806e5c)\r\nCORECLR! ScanStackRoots + 0x198 (0x72cbc639)\r\nCORECLR! GCToEEInterface::GcScanRoots + 0x104 (0x72cbb9b6)\r\nCORECLR! WKS::gc_heap::mark_phase + 0x1AD (0x72c71931)\r\nCORECLR! WKS::gc_heap::gc1 + 0x167 (0x72c6bb08)\r\n File: F:\workspace\_work\1\s\src\coreclr\src\vm\i386\excepx86.cpp Line: 329\r\n Image: C:\h\w\A86D08D2\p\CoreRun.exe\r\n\r\n\r\nReturn code: 1\r\nRaw output file: C:\h\w\A86D08D2\w\9D9C0906\e\tracing\eventpipe\Reports\tracing.eventpipe\providervalidation\providervalidation\providervalidation.output.txt\r\nRaw output:\r\nBEGIN EXECUTION\r\n "C:\h\w\A86D08D2\p\corerun.exe" providervalidation.dll \r\n 0.0s: ==TEST STARTING==\r\n 5.6s: Started sending sentinel events...\r\n 6.0s: Connecting to EventPipe...\r\n 10.5s: Connected to EventPipe with sessionID '0x7633a78'\r\n 10.5s: Creating EventPipeEventSource...\r\n 22.7s: EventPipeEventSource created\r\n 26.4s: Dynamic.All callback registered\r\n 26.4s: Starting stream processing...\r\n 33.4s: Saw new provider 'Microsoft-DotNETCore-SampleProfiler'\r\n 50.9s: Saw sentinel event\r\n 51.0s: Stopped sending sentinel events\r\n 51.3s: Starting event generating action...\r\n 66.5s: Fired MyEvent 0/100,000 times...\r\n 70.3s: Saw new provider 'MyEventSource'\r\n 74.1s: Fired MyEvent 10,000/100,000 times...\r\n 75.0s: Fired MyEvent 20,000/100,000 times...\r\nExpected: 100\r\nActual: -1073740286\r\nEND EXECUTION - FAILED\r\nFAILED\r\nTest Harness Exitcode is : 1\r\nTo run the test:\r\n> set CORE_ROOT=C:\h\w\A86D08D2\p\r\n> C:\h\w\A86D08D2\w\9D9C0906\e\tracing\eventpipe\providervalidation\providervalidation\providervalidation.cmd\r\nExpected: True\r\nActual: False
Activity
BruceForstall commentedon Jan 27, 2020
@josalem
josalem commentedon Jan 27, 2020
Taking a look today
josalem commentedon Jan 28, 2020
Took a look at the dump that got generated and picked out a few things. I think the linked list of exception handlers might be corrupted. I took a look at
0x00F7D760which points at the top levelFS:0entry and the address it has for a handler is0x72e381bd. This seems to point to a seemingly random spot in the middle of jitted code (PAGE_EXECUTE_WRITECOPYowned by coreclr.dll) that doesn't resolve to a symbol (the closest symbol that windbg can resolve is 155,101 bytes away). The last managed->native transition happened in what I believe is generated P_Invoke code (Advapi32::EventWriteTransfer_PInvoke). When the GC walks back down the stack and hits this native->managed step, the validation check on the handler list fails this check:runtime/src/coreclr/src/vm/i386/excepx86.cpp
Line 153 in 2cc926e
I'm trying to run this test locally so I can figure out what is setting this top
FS:0entry into the list, but I can't reproduce the failure locally. I'll keep poking away at this.@BruceForstall, any idea what might cause the exception handler list to get corrupted inside P_Invoke code? It looks like The P_Invoke code ended up in
coreclr!JIT_PInvokeEndRarePathif that matters.BruceForstall commentedon Jan 28, 2020
I don't have an easy idea for why this corruption would occur. My first suggestion would be to run with
COMPlus_GCStress=0xFand see if it reliably repros in a different location. If that occurs, and the issue is within JIT'ed code, then perhaps that indicates a JIT compiler GC reporting issue/hole. If not, it's possible that some VM stub/etc. is incorrectly preserving GC objects.@janvorli Any advice here?
josalem commentedon Jan 28, 2020
Could this be related to #2215?
janvorli commentedon Jan 28, 2020
I'll take a look.
janvorli commentedon Jan 28, 2020
@josalem I cannot find the dump - could you please tell me where to get it?
josalem commentedon Jan 28, 2020
It got uploaded as part of the Helix workitem. Here's a direct link.
The build artifacts can be downloaded from AzDO for symbols.
janvorli commentedon Jan 29, 2020
I have figured out what's going on. It is not a corruption. The check that fails is actually wrong in this state where we have just returned from a PInvoke and the stack walk was triggered from the JIT_PInvokeEndRarePath.
The problem is actually quite interesting and it has to do with the calling convention of the function that was pinvoked - namely the fact that the callee pops the arguments from stack. So here is what happens:
ret 1Ch, so that it pops the arguments from the stack.Now the question is why we were not hitting this before. I think that the likely reason could be that the JIT was not pushing the pinvoke arguments to the stack before calling the PINVOKE_BEGIN.
@BruceForstall is this possible?
cc: @jkotas
jkotas commentedon Jan 29, 2020
I do not think that this is the problem. The contract for
m_pCallSiteSPalways was that it ESP after pushing the arguments. It is documented in the doc - look for:I think the problem is https://github.com/dotnet/runtime/blob/master/src/coreclr/src/vm/i386/cgenx86.cpp#L617 in combination with dotnet/coreclr#22560 (comment) .
The ReadyToRun helper does not set the MethodDesc for the PInvoke frame. It means that the unwinder is not able to adjust the stack for popped arguments and we get this problem.
6 remaining items
fadimounir commentedon Jan 29, 2020
Can we make some changes to the JIT to make it pass the PInvoke MethodDesc to JIT_PInvokeBegin helper? The MethodDesc can be loaded by a R2R helper call
jkotas commentedon Jan 29, 2020
Yes, that may be one option. Another option is to make the JIT to pass the size of the stack-arguments to
JIT_PInvokeBeginhelper, on x86 only.fadimounir commentedon Jan 29, 2020
Is that applicable also to arm32?
jkotas commentedon Jan 29, 2020
I do not see why this would be needed for anything but Windows x86.
fadimounir commentedon Jan 29, 2020
Interesting... probably legacy code before the time of arm/arm64 then. @BruceForstall
@josalem did you try to repro this with complus_gcstress=0xf? If so, did it start to fail deterministically?
AriNuer commentedon Mar 3, 2020
Same test
tracing\\eventpipe\\providervalidation\\providervalidation\\providervalidation.cmdfailed here :runtime-coreclr crossgen2 outerloop 20200302.1Details:
https://dev.azure.com/dnceng/public/_build/results?buildId=544222&view=ms.vss-test-web.build-test-results-tab&runId=17227512&resultId=107009&paneView=debug
Error message:
\r\nAssert failure(PID 3448 [0x00000d78], Thread: 552 [0x0228]): Consistency check failed: AV in clr at this callstack:\r\n------\r\nCORECLR! memcmp + 0x12 (0x00007ffb25268c72)\r\nCORECLR! Thread::VirtualUnwindCallFrame + 0x404 (0x00007ffb24a5c908)\r\nCORECLR! EECodeManager::EnsureCallerContextIsValid + 0x1D6 (0x00007ffb24d25542)\r\nCORECLR! StackFrameIterator::CheckForSkippedFrames + 0x6D (0x00007ffb24a56d79)\r\nCORECLR! StackFrameIterator::ProcessCurrentFrame + 0x178 (0x00007ffb24a5b588)\r\nCORECLR! StackFrameIterator::Init + 0x213 (0x00007ffb24a593af)\r\nCORECLR! Thread::StackWalkFramesEx + 0x155 (0x00007ffb24a5c195)\r\nCORECLR! Thread::HandledJITCase + 0x23F (0x00007ffb24af456b)\r\nCORECLR! ThreadSuspend::SuspendRuntime + 0x444 (0x00007ffb24af9edc)\r\nCORECLR! ThreadSuspend::SuspendEE + 0x2D7 (0x00007ffb24af97bb)\r\nCORECLR! SampleProfiler::ThreadProc + 0x272 (0x00007ffb25036652)\r\nKERNEL32! BaseThreadInitThunk + 0x14 (0x00007ffb52d284d4)\r\nNTDLL! RtlUserThreadStart + 0x21 (0x00007ffb5316e8b1)\r\n-----\r\n.AV on tid=0x228 (552), cxr=00000049D5FFD040, exr=00000049D5FFD530\r\nFAILED: false\r\n\r\nCORECLR! CHECK::Trigger + 0x2CC (0x00007ffb2494c654)\r\nCORECLR! CLRVectoredExceptionHandlerPhase3 + 0x364 (0x00007ffb24ab6e80)\r\nCORECLR! CLRVectoredExceptionHandlerPhase2 + 0x69 (0x00007ffb24ab6901)\r\nCORECLR! CLRVectoredExceptionHandler + 0x1C6 (0x00007ffb24ab687a)\r\nCORECLR! CLRVectoredExceptionHandlerShim + 0x17A (0x00007ffb24ab70da)\r\nNTDLL! RtlInitializeCriticalSection + 0x190 (0x00007ffb53165ef0)\r\nNTDLL! RtlImageNtHeaderEx + 0x17B (0x00007ffb5313fa7b)\r\nNTDLL! KiUserExceptionDispatcher + 0x3A (0x00007ffb531a964a)\r\nCORECLR! memcmp + 0x12 (0x00007ffb25268c72)\r\nCORECLR! Thread::VirtualUnwindCallFrame + 0x404 (0x00007ffb24a5c908)\r\n File: F:\workspace_work\1\s\src\coreclr\src\vm\excep.cpp Line: 7558\r\n Image: C:\h\w\A9460959\p\CoreRun.exe\r\n\r\n\r\nReturn code: 1\r\nRaw output file: C:\h\w\A9460959\w\A17608F1\e\tracing\eventpipe\Reports\tracing.eventpipe\providervalidation\providervalidation\providervalidation.output.txt\r\nRaw output:\r\nBEGIN EXECUTION\r\n 1 file(s) copied.\r\n" "C:\h\w\A9460959\p\crossgen2\crossgen2" C:\h\w\A9460959\w\A17608F1\e\tracing\eventpipe\providervalidation\providervalidation\providervalidation.org -o:C:\h\w\A9460959\w\A17608F1\e\tracing\eventpipe\providervalidation\providervalidation\providervalidation.dll --targetarch:x64 -O --inputbubble -r:"C:\h\w\A9460959\p\System..dll" -r:"C:\h\w\A9460959\p\Microsoft..dll" -r:"C:\h\w\A9460959\p\mscorlib.dll" -r:C:\h\w\A9460959\w\A17608F1\e\tracing\eventpipe\providervalidation\providervalidation*.dll"\r\nEmitting R2R PE file: C:\h\w\A9460959\w\A17608F1\e\tracing\eventpipe\providervalidation\providervalidation\providervalidation.dll\r\n "C:\h\w\A9460959\p\corerun.exe" providervalidation.dll \r\n 0.0s: ==TEST STARTING==\r\n 0.6s: Started sending sentinel events...\r\n 0.6s: Connecting to EventPipe...\r\n 0.8s: Connected to EventPipe with sessionID '0x21aa213c650'\r\n 0.8s: Creating EventPipeEventSource...\r\nExpected: 100\r\nActual: -1073740286\r\nEND EXECUTION - FAILED\r\nFAILED\r\nTest Harness Exitcode is : 1\r\nTo run the test:\r\n> set CORE_ROOT=C:\h\w\A9460959\p\r\n> C:\h\w\A9460959\w\A17608F1\e\tracing\eventpipe\providervalidation\providervalidation\providervalidation.cmd\r\nExpected: True\r\nActual: False`
Stack trace:
at tracing_eventpipe._providervalidation_providervalidation_providervalidation_._providervalidation_providervalidation_providervalidation_cmd() in F:\workspace\_work\1\s\artifacts\tests\coreclr\Windows_NT.x64.Checked\TestWrappers\tracing.eventpipe\tracing.eventpipe.XUnitWrapper.cs:line 528BruceForstall commentedon Mar 7, 2020
@fadimounir Looks like #26834 fixed this? Can we close this?
The "new failure" above is crossgen2, and is unrelated.
fadimounir commentedon Mar 9, 2020
@BruceForstall The fix has been reverted due to #31809.
@jkotas and I couldn't repro the second issue, so right now I have a new PR (#33249), and running CI testing for a couple of loops to see if some tests will fail again due to the fix (so far, nothing failed)
I'll close the issue once I merge the new PR