From: Roland McGrath <roland@redhat.com>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Oleg Nesterov <oleg@tv-sign.ru>, Andrew Morton <akpm@osdl.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fix TASK_STOPPED vs TASK_NONINTERACTIVE interaction
Date: Sat, 1 Oct 2005 18:12:01 -0700 (PDT) [thread overview]
Message-ID: <20051002011201.D40A3180E23@magilla.sf.frob.com> (raw)
In-Reply-To: Linus Torvalds's message of Friday, 30 September 2005 10:18:02 -0700 <Pine.LNX.4.64.0509301006580.3378@g5.osdl.org>
> > It looks like "WSTOPPED | WNOWAIT is illegal for TASK_TRACED child"
> > to me. Is this correct? I think no.
>
> No, I think it's correct. If you have a traced child, you can't just wait
> for it. You need to use ptrace to release it first.
That's correct. If your child is in TASK_TRACED because someone else is
ptrace'ing it, then you don't notice its state.
> > Actually, I don't understand why we are checking p->state at all, we
> > already dropped tasklist_lock, the state can change at any monent.
>
> If it's TASK_TRACED, and it's our child, then it shouldn't be changing.
Actually, it can in two cases. First is SIGKILL, which can always wake it
up suddenly. The second is when we are not the actual ptrace parent, but
another thread in the same thread group. (do_wait loops on all the threads
in the group and checks each one's children list. my_ptrace_child does not
distinguish the ptracer from other threads in its group.)
> Besides, even if it does, we had a perfectly fine race, and we'll have
> been woken up again and we'll just go through the do_wait() loop once
> more.
>
> So I think the code is mostly correct. But that ">" is definitely
> incorrect.
Indeed. I failed to notice this > test when the other just came up recently,
because I had a change to it kicking around in my tree for a long time.
I can't honestly recall and would have to reconstruct why I wrote it this way.
The simple change Linus suggested seems fine too, probably better.
Thanks,
Roland
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1199,14 +1188,15 @@ static int wait_task_stopped(task_t *p,
if (unlikely(noreap)) {
pid_t pid = p->pid;
uid_t uid = p->uid;
- int why = (p->ptrace & PT_PTRACED) ? CLD_TRAPPED : CLD_STOPPED;
+ int state = p->state;
exit_code = p->exit_code;
- if (unlikely(!exit_code) ||
- unlikely(p->state > TASK_STOPPED))
+ if (unlikely(!exit_code) || unlikely(p->state != state))
goto bail_ref;
+
+ state = (state == TASK_TRACED) ? CLD_TRAPPED : CLD_STOPPED;
return wait_noreap_copyout(p, pid, uid,
- why, (exit_code << 8) | 0x7f,
+ state, (exit_code << 8) | 0x7f,
infop, ru);
}
next prev parent reply other threads:[~2005-10-02 1:12 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-29 21:54 Roland McGrath
2005-09-29 22:15 ` Linus Torvalds
2005-09-30 16:51 ` Oleg Nesterov
2005-09-30 17:18 ` Linus Torvalds
2005-10-01 11:32 ` Oleg Nesterov
2005-10-02 1:12 ` Roland McGrath [this message]
-- strict thread matches above, loose matches on Subject: below --
2005-10-03 23:49 linux
2005-09-29 15:58 Oleg Nesterov
2005-09-29 16:02 ` Linus Torvalds
2005-09-29 16:25 ` Paulo Marques
2005-10-03 2:54 ` Coywolf Qi Hunt
2005-10-03 3:24 ` Linus Torvalds
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=20051002011201.D40A3180E23@magilla.sf.frob.com \
--to=roland@redhat.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@tv-sign.ru \
--cc=torvalds@osdl.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®