All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Ben Blum <bblum@andrew.cmu.edu>
Cc: linux-kernel@vger.kernel.org,
	containers@lists.linux-foundation.org, akpm@linux-foundation.org,
	ebiederm@xmission.com, lizf@cn.fujitsu.com, matthltc@us.ibm.com,
	menage@google.com
Subject: Re: [RFC] [PATCH 2/2] cgroups: make procs file writable
Date: Thu, 3 Jun 2010 16:43:21 +0200	[thread overview]
Message-ID: <20100603144321.GA6284@redhat.com> (raw)
In-Reply-To: <20100603045629.GC21006@ghc02.ghc.andrew.cmu.edu>

On 06/03, Ben Blum wrote:
>
> On Mon, May 31, 2010 at 07:52:42PM +0200, Oleg Nesterov wrote:
> >
> > OK, the caller has a reference to the argument, leader,
> >
> > > +	leader = leader->group_leader;
> >
> > But why it is safe to use leader->group_leader if we race with exec?
>
> This line means "let's try to find who the leader is", since
> attach_task_by_pid doesn't grab it for us. It's not "safe", and we still
> check if it's really the leader later (just before the 'commit point').

It is not safe to even dereference this memory, it can point to nowhere.
I do not remember how this patch does "check if it's really the leader later",
but in any case this is too late: iirc at least can_attach(leader) was called.

> Note that before this line 'leader' doesn't really mean the leader -

Yes,

> perhaps i should rename the variables :P
>
> But maybe I also want to grab a reference on the new task?

Of course.

Not that I really understand why this task must be ->group_leader at
this point.

> > > +	list_for_each_entry_rcu(tsk, &leader->thread_group, thread_group) {
> >
> > Even if we didn't change "leader" above, this is not safe in theory.
> > We already discussed this, list_for_each_rcu(head) is only safe when
> > we know that "head" itself is valid.
> >
> > Suppose that this leader exits, then leader->thread_group.next exits
> > too before we take rcu_read_lock().
>
> Why is that a problem? I thought leader->thread_group is supposed to
> stay sane as long as leader is the leader.

Unless we race with exec/exit. Yes, this race is very unlikely.

> This looks like it needs a check to see if 'leader' is still really the
> leader, but nothing more.

Or you can check pid_alive(). Again, you don't really need ->group_leader
to iterate over thread-group.

> > > +	oldcgrp = task_cgroup_from_root(leader, root);
> > > +	if (cgrp != oldcgrp) {
> > > +		retval = cgroup_task_migrate(cgrp, oldcgrp, leader, true);
> > > +		BUG_ON(retval != 0 && retval != -ESRCH);
> > > +	}
> > > +	/* Now iterate over each thread in the group. */
> > > +	list_for_each_entry_rcu(tsk, &leader->thread_group, thread_group) {
> > > +		BUG_ON(tsk->signal != leader->signal);
> > > +		/* leave current thread as it is if it's already there */
> > > +		oldcgrp = task_cgroup_from_root(tsk, root);
> > > +		if (cgrp == oldcgrp)
> > > +			continue;
> > > +		/* we don't care whether these threads are exiting */
> > > +		retval = cgroup_task_migrate(cgrp, oldcgrp, tsk, true);
> > > +		BUG_ON(retval != 0 && retval != -ESRCH);
> > > +	}
> >
> > This looks strange. Why do we move leader outside of the loop ?
> > Of course, list_for_each_entry() can't work to move all sub-threads,
> > but "do while_each_thread()" can.
>
> do/while_each_thread oves over all threads in the system, rather than
> just the threadgroup... this isn't supposed to be a fast operation, but
> that seems like overkill.

What are you talking about? ;)

do/while_each_thread iterates over threadgroup.

Oleg.


  parent reply	other threads:[~2010-06-03 14:44 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-30  1:30 [RFC] [PATCH v2 0/2] cgroups: implement moving a threadgroup's threads atomically with cgroup.procs Ben Blum
2010-05-30  1:30 ` Ben Blum
     [not found] ` <20100530013002.GA762-kwnxxEB+oiWqwBT9kiuFm8WGCVk0P7UB@public.gmane.org>
2010-05-30  1:31   ` [RFC] [PATCH 1/2] cgroups: read-write lock CLONE_THREAD forking per threadgroup Ben Blum
2010-05-30  1:31     ` Ben Blum
2010-05-30  1:33   ` [RFC] [PATCH 2/2] cgroups: make procs file writable Ben Blum
2010-05-30  1:33     ` Ben Blum
     [not found]     ` <20100530013303.GC762-kwnxxEB+oiWqwBT9kiuFm8WGCVk0P7UB@public.gmane.org>
2010-05-31 17:52       ` Oleg Nesterov
2010-05-31 17:52     ` Oleg Nesterov
2010-05-31 18:04       ` Oleg Nesterov
     [not found]         ` <20100531180446.GA16249-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-06-01 18:57           ` Paul Menage
2010-06-01 18:57         ` Paul Menage
2010-06-02 14:06           ` Oleg Nesterov
2010-06-02 19:53             ` Paul Menage
2010-06-02 20:20               ` Oleg Nesterov
2010-06-02 20:31                 ` Paul Menage
2010-06-02 20:58                   ` Oleg Nesterov
2010-06-02 21:12                     ` Paul Menage
     [not found]                       ` <AANLkTimfHlapl7mbRyAazWW5q5Wzs23n6i9wIhVtSv6r-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-06-02 21:38                         ` Oleg Nesterov
2010-06-02 21:38                       ` Oleg Nesterov
     [not found]                         ` <20100602213832.GB31949-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-06-02 22:03                           ` Paul Menage
2010-06-02 22:03                         ` Paul Menage
     [not found]                           ` <AANLkTimsusetA9B95-LvKsDdAB_PegYH7Zljyi4Doe_q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-06-03  4:44                             ` Ben Blum
2010-06-03  4:44                               ` Ben Blum
     [not found]                     ` <20100602205855.GA30039-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-06-02 21:12                       ` Paul Menage
2010-06-03  4:40                       ` Ben Blum
2010-06-03  4:40                     ` Ben Blum
2010-06-03 14:48                       ` Oleg Nesterov
     [not found]                       ` <20100603044001.GA21006-jeg9jHBoDvuqwBT9kiuFm8WGCVk0P7UB@public.gmane.org>
2010-06-03 14:48                         ` Oleg Nesterov
     [not found]                   ` <AANLkTimrJFiidM8BlUNvmzfapUAv8369R9PYnTscasEf-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-06-02 20:58                     ` Oleg Nesterov
     [not found]                 ` <20100602202048.GB28663-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-06-02 20:31                   ` Paul Menage
     [not found]               ` <AANLkTin-T6ij3xf0ceGoCamwcoayxyf0GdAKY6yXDMVl-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-06-02 20:20                 ` Oleg Nesterov
     [not found]             ` <20100602140659.GA5324-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-06-02 19:53               ` Paul Menage
     [not found]           ` <AANLkTimcrX0TjzDMNJdubR92pAO4IPATbVpyvvVt0qIV-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-06-02 14:06             ` Oleg Nesterov
2010-06-03  4:56       ` Ben Blum
     [not found]         ` <20100603045629.GC21006-jeg9jHBoDvuqwBT9kiuFm8WGCVk0P7UB@public.gmane.org>
2010-06-03 14:43           ` Oleg Nesterov
2010-06-03 14:43         ` Oleg Nesterov [this message]
     [not found]       ` <20100531175242.GA14691-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-05-31 18:04         ` Oleg Nesterov
2010-06-03  4:56         ` Ben Blum
  -- strict thread matches above, loose matches on Subject: below --
2009-08-20 21:14 + cgroups-add-functionality-to-read-write-lock-clone_thread-forking-per-threadgroup.patch added to -mm tree akpm
2009-08-21 10:26 ` + cgroups-add-functionality-to-read-write-lock-clone_thread-forking-pe r-threadgroup.patch " Oleg Nesterov
2009-08-21 10:45   ` Oleg Nesterov
2009-08-21 23:37     ` Paul Menage
2009-08-22 13:09       ` Oleg Nesterov
2010-01-03 19:06         ` Ben Blum
     [not found]           ` <20100103190613.GA13423-OM76b2Iv3yLQjUSlxSEPGw@public.gmane.org>
2010-01-03 19:09             ` [RFC] [PATCH 2/2] cgroups: make procs file writable Ben Blum
2010-01-03 19:09               ` Ben Blum

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=20100603144321.GA6284@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=bblum@andrew.cmu.edu \
    --cc=containers@lists.linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=matthltc@us.ibm.com \
    --cc=menage@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.