Skip to content

[Arm64/Linux] b399444b fails under gcStress=0xC jitstress=1 #10800

Closed

Description

@sdmaclea

I added a few new configurations to my nightly runs.

This test is consistently failing in these configs

gcStress=0xC jitstress=1 JIT/Regression/CLR-x86-JIT/V2.0-Beta2/b399444/b399444b/b399444b.sh
gcStress=0xC jitstress=2 JIT/Regression/CLR-x86-JIT/V2.0-Beta2/b399444/b399444b/b399444b.sh

Failure looks similar to the LocalAlloc fail.

corerun b399444b.exe

Assert failure(PID 7270 [0x00001c66], Thread: 7270 [0x1c66]): 
    !"About to FailFast. set ComPlus_AssertOnFailFast=0 if this is expected"
    File: src/vm/jithelpers.cpp Line: 5157

Activity

  1. sdmaclea commented on Jul 31, 2018

    @sdmaclea
    ContributorAuthor

    @RussKeldorph
    Originally reported in #10449

  2. self-assigned this
    on Jan 18, 2019
  3. AndyAyersMS commented on Jan 18, 2019

    @AndyAyersMS
    Member

    I'll investigate.

  4. AndyAyersMS commented on Jan 22, 2019

    @AndyAyersMS
    Member

    This has failed for the past 19 weeks (via cross checked)...

    I can repro, so will start debugging.

    A couple of odd things to follow up:

    • this test (and the companion a) version seemingly should produce the same IL, but a runs just fine
    • neither seems to fix the optimization level in the csproj -- not clear why they aren't flagged by CheckProjects
    • both cause desktop ILDASM to crash. Core version seems to work though.
  5. AndyAyersMS commented on Jan 22, 2019

    @AndyAyersMS
    Member

    Ok, figured one thing out. The a variant defines _65536 and so hits a type load exception (too many instance fields); b defines _65535 and so the type should be loadable.

    Failure backtrace:

    #0  0x0000ffffb77b3334 in DBG_DebugBreak () from /home/andya/repos/coreclr/bin/tests/Linux.arm64.Checked/Tests/Core_Root/libcoreclr.so
    dotnet/coreclr#1  0x0000ffffb7728984 in DebugBreak () at /coreclr/src/pal/src/debug/debug.cpp:405
    dotnet/coreclr#2  0x0000ffffb71ec67c in DbgAssertDialog (szFile=<optimized out>, iLine=<optimized out>, szExpr=<optimized out>) at /coreclr/src/utilcode/debug.cpp:737
    dotnet/coreclr#3  0x0000ffffb738f36c in DoJITFailFast () at /coreclr/src/vm/jithelpers.cpp:5190
    dotnet/coreclr#4  0x0000ffffb72c2354 in CrawlFrame::CheckGSCookies (this=<optimized out>) at /coreclr/src/vm/stackwalk.cpp:416
    dotnet/coreclr#5  CrawlFrame::SetCurGSCookie (this=<optimized out>, pGSCookie=<optimized out>) at /coreclr/src/vm/stackwalk.cpp:433
    dotnet/coreclr#6  StackFrameIterator::PreProcessingForManagedFrames (this=0xffffffffa830) at /coreclr/src/vm/stackwalk.cpp:3154
    dotnet/coreclr#7  0x0000ffffb72bffc0 in StackFrameIterator::ProcessCurrentFrame (this=0xffffffffa830) at /coreclr/src/vm/stackwalk.cpp:2988
    

    So we're stack walking at a GC stress breakin and the stack walk thinks there's a GS failure (a corrupted stack cookie).

  6. AndyAyersMS commented on Jan 23, 2019

    @AndyAyersMS
    Member

    Assert is a failing cookie check, looks like pCurGSCookie is wrong or the stack location it points to is corrupted:

    pCurGSCookie = 0xffffffffdd08
    pFirstGSCookie = 0xffffffffbe50
    m_pCachedGSCookie = 0xffffffffdd08
    
    s_gsCookie = 0x9abcdef012345678   (process GS cookie)
    *pFirstGSCookie = 0x9abcdef012345678
    *pCurGSCookie =  0xffffb746bab4
    

    Fails here:

    https://github.com/dotnet/coreclr/blob/b9e88989458e24fa9764e045917b141e3338eae7/src/vm/stackwalk.cpp#L403-L418

    The frame being processed seems to be

    Offset 1048572 in Tests.ThousandMoreField.ctor. (0xFFFFC)
    

    possibly more than a coincidence that the offset is very close to 2^20...? Cookie location in the frame comes from GC info, so will look at that next.

  7. AndyAyersMS commented on Jan 23, 2019

    @AndyAyersMS
    Member

    Possibly related fact: unwind info for this method gets broken into two chunks. one covering from 0 to 0xFFFFC, the other from 0xFFFFC to 0x1ABFD0. So the offset at which GC is happening is right at this boundary.

  8. AndyAyersMS commented on Jan 23, 2019

    @AndyAyersMS
    Member

    Think what may be happening here is that when offset reaches 0xFFFFC the unwinder looks at the wrong unwind data segment and so doesn't properly recover the register state.

    Unwind Info:
      >> Start offset   : 0x000000 (not in unwind data)
      >>   End offset   : 0x0ffffc (not in unwind data)
      Code Words        : 1
      Epilog Count      : 0
      E bit             : 0
      X bit             : 0
      Vers              : 0
      Function Length   : 262143 (0x3ffff) Actual length = 1048572 (0x0ffffc)
      ---- Epilog scopes ----
      No epilogs
      ---- Unwind codes ----
        E1          set_fp; mov fp, sp
        85          save_fplr_x dotnet/coreclr#5 (0x05); stp fp, lr, [sp, #-48]!
        E4          end
        E4          end
    
    allocUnwindInfo(pHotCode=0x0000FFFF1C8F0078, pColdCode=0x0000000000000000, startOffset=0x0, endOffset=0xffffc, unwindSize=0x8, pUnwindBlock=0x00000000318AF926, funKind
    =0 (main function))
    Unwind Info:
      >> Start offset   : 0x0ffffc (not in unwind data)
      >>   End offset   : 0x1abfd0 (not in unwind data)
      Code Words        : 1
      Epilog Count      : 1
      E bit             : 0
      X bit             : 0
      Vers              : 0
      Function Length   : 176117 (0x2aff5) Actual length = 704468 (0x0abfd4)
      ---- Epilog scopes ----
      ---- Scope 0
      Epilog Start Offset        : 176115 (0x2aff3) Actual offset = 704460 (0x0abfcc) Offset from main function begin = 1753032 (0x1abfc8)
      Epilog Start Index         : 2 (0x02)
      ---- Unwind codes ----
        E5          end_c
        E1          set_fp; mov fp, sp
        ---- Epilog start at index 2 ----
        85          save_fplr_x dotnet/coreclr#5 (0x05); stp fp, lr, [sp, #-48]!
        E4          end
    
    unwindEmit: fragment dotnet/coreclr#2:
    allocUnwindInfo(pHotCode=0x0000FFFF1C8F0078, pColdCode=0x0000000000000000, startOffset=0xffffc, endOffset=0x1abfd0, unwindSize=0xc, pUnwindBlock=0x000000003CC29A49, fu
    nKind=0 (main function))
    
  9. AndyAyersMS commented on Jan 23, 2019

    @AndyAyersMS
    Member

    Arm64 unwind info allows 18 bits for length; each instr is 4 bytes, so total span is 2^20 bytes. So for longer functions multiple unwind records are needed. But only one will describe the prolog and hence the way to recover saved registers.

    Guessing maybe EEJitManager::LazyGetFunctionEntry needs to be aware of these "Function Fragment" unwind records, and if the control PC lies within a fragment, then instead return the root unwind record?

    Something similar should happen if there is a very large funclet. Not sure we have any cases where the funclet is so large it can't be covered by one unwind record; if not we should add one.

    cc @janvorli @BruceForstall

  10. janvorli commented on Jan 23, 2019

    @janvorli
    Member

    @AndyAyersMS let me take a look.

  11. AndyAyersMS commented on Jan 23, 2019

    @AndyAyersMS
    Member

    Here's what I'm trying: Arm64FunctionFragmentFix.

  12. BruceForstall commented on Jan 23, 2019

    @BruceForstall
    Contributor

    Note that we have the same function fragment stuff in arm32, and I remember the fragments there are smaller, so it's possible there's some code for arm32 that needs to be enabled for arm64, or perhaps the bug exists on arm32 as well.

  13. janvorli commented on Jan 23, 2019

    @janvorli
    Member

    The fix should rather be in the unwinder code. Looking at the Windows unwinder source, it seems it has been updated to support this scenario since we've ported its sources to coreclr.

    The unwind now first checks if the UnwindType = (FunctionEntry->UnwindData & 3) is 3 and in case it is, it gets the parent record. The comment says:

            // Unwind type 3 refers to a chained record. The top 30 bits of the
            // unwind data contains the RVA of the parent pdata record.
    

    The unwind code we have in coreclr just fails when the unwind type is set to 3.
    Does our JIT generate the unwind type 3 for chained records?

  14. BruceForstall commented on Jan 23, 2019

    @BruceForstall
    Contributor

    Shouldn't EEJitManager::LazyGetFunctionEntry call IJitManager::GetFuncletStartAddress to find the "host" record for the function/funclet?

    Or maybe the caller; depends on the use, I guess.

  15. AndyAyersMS commented on Jan 23, 2019

    @AndyAyersMS
    Member
  16. 4 remaining items

  17. janvorli commented on Jan 23, 2019

    @janvorli
    Member

    is the runtime handling these fragmented records properly when it gets offsets in the fragmented part?

    No, it isn't

    does the debugger handle this properly (seems to use a different unwinder)?

    It uses the same unwinder we use for Unix (where we use it for both debugger and managed code unwinding)

    If the unwind spec changed since this was implemented, and (FunctionData->UnwindData & 3) means something besides (1) zero means Exception info RVA, and (2) non-zero means Packed unwind format,

    Yes, that's what I was trying to point out. Value 3 now means chained unwind records (for both compact and full unwind). The parent record never contains 3 there.

  18. BruceForstall commented on Jan 23, 2019

    @BruceForstall
    Contributor

    @AndyAyersMS The JIT has COMPlus_JitSplitFunctionSize which you can set to some (small-ish) value to force creating more fragments. We should probably add some testing of this to the JIT stress mix.

    See UnwindInfo::Split(). It has the "helpful" comment (you're welcome):

    // ARM64 has very similar limitations, except functions can be up to 1MB. TODO-ARM64-Bug?: make sure this works!
    

    :-)

  19. AndyAyersMS commented on Jan 23, 2019

    @AndyAyersMS
    Member

    Saw that comment....

    Yes enabling some kind of split stress seems prudent to force us down these paths more often and with more variety. It is somewhat of painful to work with huge methods (the jit dump was 1.7GB).

  20. BruceForstall commented on Jan 23, 2019

    @BruceForstall
    Contributor

    @janvorli The published arm64 unwind spec doesn't seem to mention what you're describing: https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling?view=vs-2017.

    Flag is a 2-bit field that indicates how to interpret the remaining 30 bits of the second .pdata word. If Flag is 0, then the remaining bits form an Exception Information RVA (with the low two bits implicitly 0). If Flag is non-zero, then the remaining bits form a Packed Unwind Data structure.
    
  21. AndyAyersMS commented on Jan 23, 2019

    @AndyAyersMS
    Member

    I don't know if it is related but sos ClrStack crashes when you're broken in at this offset. So we should make sure that works too.

  22. janvorli commented on Jan 23, 2019

    @janvorli
    Member

    @BruceForstall the Windows unwinder is handling it that way, so I guess the doc is out of date.

  23. AndyAyersMS commented on Jan 24, 2019

    @AndyAyersMS
    Member

    FYI the provisional changes to LazyGetFunctionEntry fix this particular issue.

    $ env | grep COMP
    
    COMPlus_GCStress=0xC
    COMPlus_JitStress=1
    
    $ time ./corerun ../../JIT/Regression/CLR-x86-JIT/V2.0-Beta2/b399444/b399444b/b399444b.exe
    
    real    3m53.360s
    user    3m21.752s
    sys     0m31.924s
    

    @janvorli does it make sense for you to take this over?

    Or, I'm happy to work up a proper fix if you give me some pointers.

  24. janvorli commented on Jan 24, 2019

    @janvorli
    Member

    Thanks @AndyAyersMS for the investigation and testing. I was thinking about it and since (unless I miss something) we need this fix for Windows ARM64 too, the fix cannot be in the unwinder code that we have in coreclr (as it would then be used for Linux / debugger only). So it seems to me that your fix is actually at a proper place. The only thing I would do is to extract the loop that iterates over the fragments into a separate function and use it both in your change and in the IJitManager::GetFuncletStartAddress. The IJitManager::GetFuncletStartAddress contains extra getting of the funcletStartAddress in each iteration, but it is actually not needed and getting it after the loop would work too.
    Would you mind making this slight modification to your change and send out a PR with that?

  25. AndyAyersMS commented on Jan 25, 2019

    @AndyAyersMS
    Member

    Sure -- should have a PR ready before too long.

  26. transferred this issue fromdotnet/coreclron Jan 31, 2020
  27. added this to the 3.0 milestone on Jan 31, 2020
  28. ghost locked as resolved and limited conversation to collaborators on Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GCStressarch-arm64area-CodeGen-coreclrbug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions