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

Fix debugger thread context validation after recent change #55839

Merged
merged 1 commit into from
Jul 17, 2021

Conversation

kouvel
Copy link
Member

@kouvel kouvel commented Jul 16, 2021

Followup fix to #55185

@kouvel kouvel added this to the 6.0.0 milestone Jul 16, 2021
@kouvel kouvel requested a review from janvorli July 16, 2021 16:14
@kouvel kouvel self-assigned this Jul 16, 2021
@kouvel
Copy link
Member Author

kouvel commented Jul 16, 2021

@noahfalk, I seem to have broken this path in a recent PR that made it into preview 7, for the currently typical case where CET is disabled. As a result, the check for Debugger::IsThreadContextInvalid would always say that the thread context is invalid when a debugger is attached, preventing the suspension from happening while the thread is in managed code. Seems like it has a potential to be problematic, do you feel that a fix should be ported back to preview 7?

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

LGTM

@noahfalk
Copy link
Member

preventing the suspension from happening while the thread is in managed code

This sounds like the debugger would frequently (never?) be able to suspend, such as when hitting breakpoints or stepping. Is that the right way to think about it or it is less severe?

do you feel that a fix should be ported back to preview 7?

If debugging is pretty badly broken (it sounds like it could be?) and this fix seems very low risk, then yeah, I think we should port it back if possible. Do you know what the process is for that or we could Manish/Jeff.

@noahfalk
Copy link
Member

fyi @dotnet/dotnet-diag

@kouvel kouvel merged commit 10f38d2 into dotnet:main Jul 17, 2021
@kouvel kouvel deleted the CetFix branch July 17, 2021 01:38
@kouvel
Copy link
Member Author

kouvel commented Jul 17, 2021

This sounds like the debugger would frequently (never?) be able to suspend, such as when hitting breakpoints or stepping. Is that the right way to think about it or it is less severe?

I think it's a bit less severe but it could be bad at times. To be more specific when a thread is trying to suspend another thread that is constantly (on every attempt to suspend) in interruptible managed code, it would fail to suspend (if it's not in an interruptible region we would use return address hijacking, which I think would succeed). Here's an example, somehow for this test it seems to hang on attach even before breaking the process:

static class Program
{
    private static void Main()
    {
        var t = new Thread(Foo);
        t.IsBackground = true;
        t.Start();
        Foo();
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void Foo()
    {
        while (true)
        {
        }
    }
}

I'll go ahead and port it back. I believe the process is the same as for servicing.

kouvel added a commit to kouvel/runtime that referenced this pull request Jul 17, 2021
@kouvel
Copy link
Member Author

kouvel commented Jul 17, 2021

Also I'm not sure where or how frequently GC polls would occur but they would also allow a thread to suspend

@noahfalk
Copy link
Member

Ah, if this is only for interruptible code I am much less concerned (and it aligns with not having seen our debugger tests blow up). If it is easy port back great, if it laborious or tactics wants to hold a higher bar I wouldn't push too hard. Thanks Kount!

@kouvel
Copy link
Member Author

kouvel commented Jul 17, 2021

It seems I was mistaken. The check for a valid thread context is done before return address hijacking also, so suspension would fail whenever the thread remains in managed code for an extended time, interruptible or not. If the thread happens to switch GC modes at some point or hits a GC poll, it would suspend at that point.

@kouvel
Copy link
Member Author

kouvel commented Jul 17, 2021

There seems to be one new failure in the diagnostics tests from the issue, I've confirmed that it's fixed after this change.

stephentoub pushed a commit that referenced this pull request Jul 18, 2021
@noahfalk
Copy link
Member

Thanks @kouvel! Appreciate it : )

@ghost ghost locked as resolved and limited conversation to collaborators Aug 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants