public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
	"Metzger, Markus T" <markus.t.metzger@intel.com>,
	Roland McGrath <roland@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] reparent/untrace: do nothing if no childs/tracees
Date: Wed, 11 Feb 2009 22:14:52 +0100	[thread overview]
Message-ID: <20090211211452.GA16883@redhat.com> (raw)
In-Reply-To: <20090211211224.GA16860@redhat.com>

On 02/11, Oleg Nesterov wrote:
>
> However, forget_original_parent() has another problem. We can race with
> another thread which has already picked us for reparenting before we set
> PF_EXITING, so this patch also checks thread_group_empty().
>
> It is possible to be more clever, we can take tasklist for reading, or
> ensure that ->thread_group.prev is not PF_EXITING, but this is nasty.
> Perhaps even this optimization is too ugly.

Or, perhaps we can do:

	static void forget_original_parent(struct task_struct *father)
	{
		struct task_struct *p, *n, *reaper;
		LIST_HEAD(dead_childs);

		if (list_empty(&father->children))
			return;

		write_lock_irq(&tasklist_lock);
	again:
		reaper = find_new_reaper(father);

		list_for_each_entry_safe(p, n, &father->children, sibling) {
			p->real_parent = reaper;
			if (p->parent == father) {
				BUG_ON(p->ptrace);
				p->parent = p->real_parent;
			}
			reparent_thread(father, p, &dead_childs);
		}

		smp_mb(); /* do_exit() does mb() after exit_signals() */
		if (unlikely(reaper->flags & PF_EXITING)) {
			father = reaper;
			goto again;
		}
		write_unlock_irq(&tasklist_lock);

		BUG_ON(!list_empty(&father->children));

		list_for_each_entry_safe(p, n, &dead_childs, sibling) {
			list_del_init(&p->sibling);
			release_task(p);
		}
	}

but this needs a fat comment at least. I am not sure this worth the trouble.

Oleg.


      reply	other threads:[~2009-02-11 21:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-11 21:12 [PATCH 4/4] reparent/untrace: do nothing if no childs/tracees Oleg Nesterov
2009-02-11 21:14 ` Oleg Nesterov [this message]

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=20090211211452.GA16883@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markus.t.metzger@intel.com \
    --cc=roland@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