From: Roland McGrath <roland@redhat.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"Eric W. Biederman" <ebiederm@xmission.com>,
"Metzger, Markus T" <markus.t.metzger@intel.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] forget_original_parent: split out the un-ptrace part
Date: Thu, 19 Feb 2009 18:27:46 -0800 (PST) [thread overview]
Message-ID: <20090220022746.8852CFC2F7@magilla.sf.frob.com> (raw)
In-Reply-To: Oleg Nesterov's message of Wednesday, 11 February 2009 22:12:16 +0100 <20090211211216.GA16847@redhat.com>
> +static inline int task_detached(struct task_struct *p)
Maybe take the opportunity to make it bool?
Clearly trivial, but a bit of implicit documentation that doesn't hurt.
> @@ -911,7 +825,10 @@ static void forget_original_parent(struc
> write_unlock_irq(&tasklist_lock);
> BUG_ON(!list_empty(&father->children));
>
> - ptrace_exit_finish(father, &ptrace_dead);
> + list_for_each_entry_safe(p, n, &ptrace_dead, ptrace_entry) {
> + list_del_init(&p->ptrace_entry);
> + release_task(p);
> + }
> }
I know it's removed by the next patch anyway. But I wouldn't mind a comment
in this patch saying "kludge overload of ptrace_entry should go away soon".
> +/*
> + * Called with irqs disabled, returns true if childs should reap themselves.
s/childs/children/
Make this bool too.
> +/*
> + * Detach all tasks we were using ptrace on.
> + */
> +void exit_ptrace(struct task_struct *tracer)
> +{
> + struct task_struct *p, *n;
> + LIST_HEAD(ptrace_dead);
I think this can do a short-circuit for the common case and avoid the lock:
if (list_empty(&tracer->ptraced))
return;
It might even be worthwhile making it an inline that does the short-circuit
check before calling out to ptrace.c at all.
I see your patch 4/4 on this. In fact, I think the short-circuit
optimization of these two cases should be two separate patches. They are
for the same motivation and the same kind of optimization, but the details
of what the race issues might be are quite distinct between the two.
Moreover, the exit_ptrace optimization is removing the new lock overhead we
introduce in this patch. The real-child optimization is just a new
optimization beyond the status quo. It can really be considered wholly
after this whole series (and probably just punted because it gets so hairy).
For the ptrace case, I started out thinking it was trivially clear that no
false positives are possible here. The tracer can't do ptrace_attach() or
do_fork(), it's exiting. But ptrace_traceme() can sneak in here. (I don't
see how release_task() could be a problem at all. Going from nonempty to
empty could only cause false negatives--which are always harmless--not false
positives.)
You didn't mention ptrace_traceme() in your 4/4 message. Off hand I don't
see what keeps it safe when we go to dropping the tasklist_lock between
exit_ptrace and changing children's real_parent links. In fact, that seems
like a new hole, period--without the short-circuit optimization.
Am I overlooking something here?
That seems addressed by e.g.:
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -534,7 +534,7 @@ repeat:
* Set the ptrace bit in the process ptrace flags.
* Then link us on our parent's ptraced list.
*/
- if (!ret) {
+ if (!ret && !(current->real_parent->flags & PF_EXITING)) {
current->ptrace |= PT_PTRACED;
__ptrace_link(current, current->real_parent);
}
Thanks,
Roland
next prev parent reply other threads:[~2009-02-20 2:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-11 21:12 Oleg Nesterov
2009-02-20 2:27 ` Roland McGrath [this message]
2009-02-23 16:46 ` Oleg Nesterov
2009-02-23 18:26 ` Oleg Nesterov
2009-02-23 18:57 ` Oleg Nesterov
2009-02-25 0:34 ` Roland McGrath
2009-02-25 20:44 ` 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=20090220022746.8852CFC2F7@magilla.sf.frob.com \
--to=roland@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=markus.t.metzger@intel.com \
--cc=oleg@redhat.com \
/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
Powered by JetHome