public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Pedro Alves <palves@redhat.com>
Cc: Tejun Heo <tj@kernel.org>,
	Jan Kratochvil <jan.kratochvil@redhat.com>,
	Andrey Ryabinin <aryabinin@virtuozzo.com>,
	Roland McGrath <roland@hack.frob.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: ptrace() hangs on attempt to seize/attach stopped & frozen task
Date: Thu, 19 Nov 2015 18:47:54 +0100	[thread overview]
Message-ID: <20151119174754.GA13949@redhat.com> (raw)
In-Reply-To: <564DFDAF.3000402@redhat.com>

Thanks Pedro for your email,

I'll recheck tomorrow, but at first glance:

On 11/19, Pedro Alves wrote:
>
> Both GDB and gdbserver have special processing for attaching to already-stopped
> processes.

Yes, I am starting to recall that I have looked at this code years ago ;)

>  907 linux_attach_lwp (ptid_t ptid)
>  908 {
>  909   struct lwp_info *new_lwp;
>  910   int lwpid = ptid_get_lwp (ptid);
>  911
>  912   if (ptrace (PTRACE_ATTACH, lwpid, (PTRACE_TYPE_ARG3) 0, (PTRACE_TYPE_ARG4) 0)
>  913       != 0)
>  914     return errno;
>  915
>  916   new_lwp = add_lwp (ptid);
>  917
>  918   /* We need to wait for SIGSTOP before being able to make the next
>  919      ptrace call on this LWP.  */
>  920   new_lwp->must_set_ptrace_flags = 1;
>  921
>  922   if (linux_proc_pid_is_stopped (lwpid))

This can't happen today. Starting from v3.0 at least.

> This queuing of a SIGSTOP + PTRACE_CONT was necessary because
> otherwise when gdb attaches to a job stopped process, gdb would hang in the waitpid
> after PTRACE_ATTACH, waiting for the initial SIGSTOP which would never arrive.

Yes, because its exit code could be already cleared iirc. This was fixed
even before.

> If the proposed change makes it so that a new intermediate state can be observed
> right after PTRACE_ATTACH, and so linux_proc_pid_is_stopped can return false,
> then there's potential for breakage.

See above,

> But maybe not, if we're sure that
> that when that happens, waitpid returns for the initial
> PTRACE_ATTACH-induced SIGSTOP.

Yes. Just you can't assume that watpid(WNOHANG) will succeed. Is it OK?

Oleg.


  reply	other threads:[~2015-11-19 17:47 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-09 15:12 ptrace() hangs on attempt to seize/attach stopped & frozen task Andrey Ryabinin
2015-11-09 18:55 ` Oleg Nesterov
2015-11-09 18:02   ` Tejun Heo
2015-11-10 20:20     ` Oleg Nesterov
2015-11-16 18:45       ` Tejun Heo
2015-11-17 19:34         ` Oleg Nesterov
2015-11-17 18:57           ` Tejun Heo
2015-11-19 16:49           ` Pedro Alves
2015-11-19 17:47             ` Oleg Nesterov [this message]
2015-11-19 18:08               ` Pedro Alves
2015-11-10 20:20   ` Oleg Nesterov
2015-11-19 18:47 ` [PATCH 0/2] (Was: ptrace() hangs on attempt to seize/attach stopped & frozen task) Oleg Nesterov
2015-11-19 18:47   ` [PATCH 1/2] ptrace: make wait_on_bit(JOBCTL_TRAPPING_BIT) in ptrace_attach() killable Oleg Nesterov
2015-11-23 23:05     ` Tejun Heo
2015-11-19 18:47   ` [PATCH 2/2] ptrace: task_stopped_code(ptrace => true) can't see TASK_STOPPED task Oleg Nesterov
2015-11-23 23:15     ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151119174754.GA13949@redhat.com \
    --to=oleg@redhat.com \
    --cc=aryabinin@virtuozzo.com \
    --cc=jan.kratochvil@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=palves@redhat.com \
    --cc=roland@hack.frob.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox