From: Tejun Heo <tj@kernel.org>
To: Roland McGrath <roland@redhat.com>
Cc: Oleg Nesterov <oleg@redhat.com>,
linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
akpm@linux-foundation.org, rjw@sisk.pl,
jan.kratochvil@redhat.com
Subject: Re: [PATCH 09/16] ptrace: make do_signal_stop() use ptrace_stop() if the task is being ptraced
Date: Thu, 27 Jan 2011 14:56:31 +0100 [thread overview]
Message-ID: <20110127135631.GD24925@htj.dyndns.org> (raw)
In-Reply-To: <20110117220923.EA622180996@magilla.sf.frob.com>
Hello, Roland.
On Mon, Jan 17, 2011 at 02:09:23PM -0800, Roland McGrath wrote:
> > In short: suppose that the tracee recieves a signal, reports it
> > to debugger, and the debugger does ptrace(PTRACE_CONT, pid, SIGSTOP).
> >
> > Before the patch the tracee sleeps in TASK_STOPPED, after the patch
> > it becomes TASK_TRACED.
>
> I am not immediately comfortable with this. What really matters is
> the userland-visible behavior (ptrace, wait, and signals). The
> /proc/pid/status difference of "T (stopped)" vs "T (traced)" is
> technically userland-visible, but I don't think that really matters
> to userland.
>
> > I missed this part of the changelog. "visible via fs/proc" is not
> > the only change. Another change is how the tracee reacts to SIGCONT
> > after that. With this patch it can't wake the tracee up.
>
> This seems like a problem to me, though there are caveats to that.
> My rationale has always been that there should be some way to get
> into normal job-control stop state, both meaning that group-stop
> happens normally and that SIGCONT works normally.
>
> However, it is not entirely clear how useful that is to userland
> given the rest of ptrace behavior as it stands. That is, the real
> parent can't see the job-control stop anyway because its wait
> reports are preempted by ptrace, so what is it for?
>
> It would be more clear if we had a cleaner interface available in
> which tracing did not prevent normal job-control stops from being
> reported to the real parent. I'm not really sure how much we should
> try to change this stuff before adding something like that.
I think we're getting a bit off course here. The CONT problem in this
context isn't generic at all. In principle, CONT doesn't
(immediately) work on a ptraced task. We basically just had this
window where STOPPED -> TRACED transition was delayed in which CONT
worked. It's more of a behavioral inconsistency than anything else.
If a task was RUNNING when PTRACE_ATTACH happens, when the tracer
wait(2) completes, the task is TRACED and won't immediately respond to
CONT. If a task was STOPPED, CONT can still wake up between the
completion of wait(2) and the first ptrace command on the tracee.
It's a subtle inconsistency which I don't believe anyone could have
taken advantag of.
As for the generic discussion of group stop vs. ptrace, yeah, there's
a lot to discuss and as I already wrote before I don't think there
will be a single behavior which would satisfy all the requirements. I
think it would be best to iron out the existing inconsistencies in a
way which doesn't break the current users and then gradually introduce
a few more ptrace operations which have well defined and more flexible
interaction with group stop.
> But the way the code is structured, arch_ptrace_stop can only be used
> on current, meaning it requires waking it up from TASK_STOPPED long
> enough to run the ptrace_stop logic. IMHO it would be wrong to
> introduce a new window visible to userland wherein a process
> previously in job-control stop is seen to be running before it gets
> into its ptrace stop. It might not matter if /proc/pid/status can be
> read to see "R (running)" for such a window. But certainly it should
> not have CLD_CONTINUED behavior (SIGCHLD and waitid visibility), nor
> report a CLD_TRAPPED stop via SIGCHLD or wait after it was already stopped.
As I wrote in another reply, the visibility is masked from the tracer
and only visible if the user does a pretty convoluted thing. Unless
there's such current user, I think we can clearly define what's
guaranteed regarding ptrace/wait interaction and leave cases outside
of it as undefined.
> [tj:]
> > Yes, before the change, the task would respond to SIGCONT before the
> > first ptrace request succeeds after attach. To me, this doesn't seem
> > to be anything intentional tho. It seems a lot of ptrace and group
> > stop interactions is in the grey area with only the current (quirky,
> > I'm afraid) behavior drawing almost arbitrary lines across different
> > behaviors.
>
> That is largely true. But userland programs like gdb and strace have
> gone to lots of contortions to work with the behavior as it is, and we
> should not break what works in practice for them.
Sure, I definitely agree but at the same time that doesn't mean we
shouldn't improve ptrace at all. It just means it's delicate and we
should proceed carefully, which we shall.
> > We can try to preserve all those behaviors but I don't think that will
> > be very beneficial. I think the best way to proceed would be
> > identifying the sensible and depended upon assumptions and then draw
> > clear lines from there stating what's guaranteed and what's undefined.
> > We'll have to keep some of quirkiness for sure.
>
> I agree with this overall. But we must consider whatever weirdness
> comes up in ptrace.
Yeap.
> I quite agree. The best way to fix this is with sane semantics for
> normal job-control operations when traced. But ptrace has never had
> that before and it's just not possible both to be sane and to match
> the expected behavior of the traditional ptrace semantics. Hence I
> lean towards leaving things as much as possible as they are today when
> only the ptrace operations we have today are used.
Yeap, definitely. I want to make things just clean enough so that it
doesn't hinder introduction of improvements while not breaking the
existing users, but things like silent STOPPED -> TRACED transition
are outright buggy and have to be fixed one way or the other. We
can't ignore them.
> I certainly agree that we should have some new operations or modes of
> tracing and have them behave sanely. I don't think the details you've
> described here are exactly what would make sense, however.
>
> IMHO there should be no discretion about whether a thread participates
> in a group stop. If a group stop is happening, every thread must be
> stopped ASAP and the debugger should not be able to interfere with
> that. (The time for the debugger to interfere is when it gets the
> chance to intercept the stop signal before it's delivered.) If a
> thread is stop for tracing when a group stop happens, then the right
> way to think about its state is "both stopped for tracing and stopped
> for job-control". When the tracer says it can resume, it goes to
> simply "stopped for job-control". Likewise, if before that a SIGCONT
> is generated, then it goes to simply "stopped for tracing" and does
> not prevent the normal CLD_CONTINUED notification from happening.
> That is, to the non-debugger parts of the system, it's no different
> from if the debugger stopped that thread for tracing immediately after
> SIGCONT resumed it and before it had a chance to do anything else.
> (This is exactly the model we tried to implement in utrace.)
There are two extremes. You can put ptrace under group stop or
completely the other way around. I think there are valid use cases
for both of them. I'll try to summarize it later.
> I've read over the rest of the long thread from December and will
> reply further to the later iterations of the patches shortly. I'm
> sorry if I've replied to stale issues or overlooked questions still
> needing answers. I hope we can all get caught up to discussing the
> same things this week.
Heh, I was the late one this time. I'll soon repost the refreshed
STOPPED <-> TRACED patchset. I think we're mostly in agreement
regarding that part.
Thank you.
--
tejun
next prev parent reply other threads:[~2011-01-27 13:56 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-06 16:56 [PATCHSET] ptrace,signal: sane interaction between ptrace and job control signals, take#2 Tejun Heo
2010-12-06 16:56 ` [PATCH 01/16] signal: fix SIGCONT notification code Tejun Heo
2010-12-06 16:56 ` [PATCH 02/16] signal: fix CLD_CONTINUED notification target Tejun Heo
2010-12-20 14:58 ` Oleg Nesterov
2010-12-21 16:31 ` Tejun Heo
2010-12-06 16:56 ` [PATCH 03/16] signal: remove superflous try_to_freeze() loop in do_signal_stop() Tejun Heo
2010-12-20 14:59 ` Oleg Nesterov
2010-12-06 16:56 ` [PATCH 04/16] ptrace: kill tracehook_notify_jctl() Tejun Heo
2010-12-20 14:59 ` Oleg Nesterov
2010-12-21 17:00 ` Tejun Heo
2010-12-06 16:56 ` [PATCH 05/16] ptrace: add @why to ptrace_stop() Tejun Heo
2010-12-06 16:56 ` [PATCH 06/16] signal: fix premature completion of group stop when interfered by ptrace Tejun Heo
2010-12-20 15:00 ` Oleg Nesterov
2010-12-21 17:04 ` Tejun Heo
2010-12-06 16:56 ` [PATCH 07/16] signal: use GROUP_STOP_PENDING to stop once for a single group stop Tejun Heo
2010-12-06 16:56 ` [PATCH 08/16] ptrace: participate in group stop from ptrace_stop() iff the task is trapping for " Tejun Heo
2010-12-06 16:56 ` [PATCH 09/16] ptrace: make do_signal_stop() use ptrace_stop() if the task is being ptraced Tejun Heo
2010-12-23 12:26 ` Oleg Nesterov
2010-12-23 13:53 ` Tejun Heo
2010-12-23 16:06 ` Oleg Nesterov
2010-12-23 16:33 ` Tejun Heo
2011-01-17 22:09 ` Roland McGrath
2011-01-27 13:56 ` Tejun Heo [this message]
2011-01-28 20:30 ` Roland McGrath
2011-01-31 14:39 ` Tejun Heo
2010-12-06 16:56 ` [PATCH 10/16] ptrace: clean transitions between TASK_STOPPED and TRACED Tejun Heo
2010-12-20 15:00 ` Oleg Nesterov
2010-12-21 17:31 ` Tejun Heo
2010-12-21 17:32 ` Tejun Heo
2010-12-22 10:54 ` Tejun Heo
2010-12-22 11:39 ` Oleg Nesterov
2010-12-22 15:14 ` Tejun Heo
2010-12-22 16:00 ` Oleg Nesterov
2010-12-22 16:21 ` Tejun Heo
2010-12-06 16:56 ` [PATCH 11/16] signal: prepare for CLD_* notification changes Tejun Heo
2010-12-20 16:21 ` Oleg Nesterov
2010-12-20 16:23 ` Oleg Nesterov
2010-12-21 17:35 ` Tejun Heo
2010-12-06 16:57 ` [PATCH 12/16] ptrace: make group stop notification reliable against ptrace Tejun Heo
2010-12-20 17:34 ` Oleg Nesterov
2010-12-21 17:43 ` Tejun Heo
2010-12-22 11:54 ` Oleg Nesterov
2010-12-22 15:26 ` Tejun Heo
2010-12-22 16:02 ` Oleg Nesterov
2010-12-06 16:57 ` [PATCH 13/16] ptrace: reorganize __ptrace_unlink() and ptrace_untrace() Tejun Heo
2010-12-20 18:15 ` Oleg Nesterov
2010-12-21 17:54 ` Tejun Heo
2010-12-06 16:57 ` [PATCH 14/16] ptrace: make SIGCONT notification reliable against ptrace Tejun Heo
2010-12-20 19:43 ` Oleg Nesterov
2010-12-21 17:48 ` Tejun Heo
2010-12-22 12:16 ` Oleg Nesterov
2010-12-21 17:25 ` Oleg Nesterov
2010-12-22 10:35 ` Tejun Heo
2010-12-06 16:57 ` [PATCH 15/16] ptrace: make sure SIGNAL_NOTIFY_CONT is checked after ptrace_signal() Tejun Heo
2010-12-06 16:57 ` [PATCH 16/16] ptrace: remove the extra wake_up_process() from ptrace_detach() Tejun Heo
2010-12-07 0:10 ` Roland McGrath
2010-12-07 13:43 ` Tejun Heo
2010-12-21 17:54 ` Oleg Nesterov
2010-12-22 10:36 ` Tejun Heo
2010-12-14 17:36 ` [PATCHSET] ptrace,signal: sane interaction between ptrace and job control signals, take#2 Oleg Nesterov
2010-12-14 17:46 ` Tejun Heo
2010-12-22 15:20 ` Oleg Nesterov
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=20110127135631.GD24925@htj.dyndns.org \
--to=tj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=jan.kratochvil@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=rjw@sisk.pl \
--cc=roland@redhat.com \
--cc=torvalds@linux-foundation.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
all inboxes | Powered by JetHome®