From: Frederic Weisbecker <fweisbec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: Is not locking task_lock in cgroup_fork() safe?
Date: Thu, 18 Oct 2012 16:50:59 +0200 [thread overview]
Message-ID: <CAFTL4hzo_w7HTgC9ApTk113X8WdZSpV+D+VSEe=604YEJFmKsg@mail.gmail.com> (raw)
In-Reply-To: <20121016193341.GD16166-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012/10/16 Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>:
> Hey, Frederic.
>
> On Mon, Oct 08, 2012 at 02:48:58PM +0200, Frederic Weisbecker wrote:
>> Yeah I missed this one.
>> Now the whole cgroup_attach_task() is clusteracy without the
>
> Clusteracy?
>
>> threadgroup lock anyway:
>>
>> * The PF_EXITING check is racy (we are neither holding tsk->flags nor
>> threagroup lock).
>
> PF_EXITING is *always* protected by threadgroup_change_begin/end().
>
>> * The cgrp == oldcgrp is racy (exit() can change the oldcgrp anytime.
>
> So, as long as this happens after PF_EXITING check, it should be safe.
>
>> * can_attach / attach / cancel_attach can race against fork/exit (and
>> post_fork if you consider those interested in cgroup task link like
>> the freezer. But that is racy in any case already even with
>> threadgroup lock)
>
> Against exit, no. Against forking a new process, can they? If so, we
> need to fix it.
>
>> It has been designed to be called under that lock. So I suspect the
>
> Ummm.... threadgroup_lock is a recent addition so things couldn't have
> been designed to be called under that lock. threadgroup_lock protects
> the *threadgroup* - creating a new task in the same process or a task
> of the process exiting. It doesn't do anything about other processes.
> In fact, the lock itself is per-process.
>
>> best, at least for now, is to threadgroup lock from
>> cgroup_attach_task_all(). And also make cgroup_attach_task() static to
>> avoid future unsafe callers.
>
> Oh, from that call path, sure. Can someone teach me why we need that
> one at all? I think we're confusing each other here. I was talking
> about the usual migration path not protected against forking a new
> process.
Ah right I was confused. Hmm, indeed we have a race here on
cgroup_fork(). How about using css_try_get() in cgroup_fork() and
refetch the parent's css until we succeed? This requires rcu_read_lock
though, and freeing the css_set under RCU.
Don't know which is better.
Different problem but I really would like we sanitize the cgroup hooks
in fork. There is cgroup_fork(), cgroup_post_fork() which takes that
big css_set_lock, plus the big threadgroup lock... I hope we can
simplify the mess there.
>
>> There is no harm yet because the only user of it calls that with
>> current as the "task" parameter, in a place that is
>> not in the middle of a fork. So no need to worry about some stable backport.
>>
>> Also, looking at cgroup_attach_task_all(), what guarantee do we have
>> that "from" is not concurrently exiting and removing its cgrp. Which
>> is a separate problem. But we probably need to do some css_set_get()
>> before playing with it.
>
> I really don't know. Why isn't it locking the threadgroup to begin
> with?
No idea, sounds like something to fix.
next prev parent reply other threads:[~2012-10-18 14:50 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-08 2:00 Is not locking task_lock in cgroup_fork() safe? Tejun Heo
2012-10-08 2:01 ` Tejun Heo
2012-10-08 5:46 ` Li Zefan
[not found] ` <507268AA.8050509-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2012-10-08 6:57 ` Tejun Heo
2012-10-16 19:34 ` Tejun Heo
[not found] ` <20121016193428.GE16166-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-17 7:26 ` Li Zefan
2012-10-08 12:58 ` Frederic Weisbecker
2012-10-08 12:48 ` Frederic Weisbecker
[not found] ` <CAFTL4hzXWtzp7megsCAEuak5=_2SWmp9age-+wrpyQAU4BRZ0w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-16 19:33 ` Tejun Heo
[not found] ` <20121016193341.GD16166-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-18 14:50 ` Frederic Weisbecker [this message]
[not found] ` <CAFTL4hzo_w7HTgC9ApTk113X8WdZSpV+D+VSEe=604YEJFmKsg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-18 20:07 ` Tejun Heo
[not found] ` <20121018200705.GG13370-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-18 20:53 ` Frederic Weisbecker
[not found] ` <CAFTL4hy7g4e11OUOyoihrEU8hiVgZoV1=141UtUpj9a72SNs_Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-19 0:38 ` Tejun Heo
[not found] ` <20121019003835.GE13370-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-19 0:58 ` Tejun Heo
[not found] ` <20121019005801.GF13370-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-19 8:50 ` Li Zefan
2012-10-19 0:59 ` [PATCH cgroup/for-3.7-fixes 1/2] Revert "cgroup: Remove task_lock() from cgroup_post_fork()" Tejun Heo
[not found] ` <20121019005922.GG13370-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-19 8:51 ` Li Zefan
2012-10-19 13:35 ` Frederic Weisbecker
[not found] ` <CAFTL4hz82==b3ioSMhbKzh0CN1ivR7RQMKKMFFWu5PHPjg=Bfg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-19 19:38 ` Tejun Heo
[not found] ` <20121019193808.GL13370-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-19 19:44 ` Frederic Weisbecker
[not found] ` <CAFTL4hwQ6Ntn5GJwj=jiO2p3GdwhEMp0MyR8dgUj_Lx0U4kNqg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-19 21:07 ` Tejun Heo
[not found] ` <20121019210738.GA1180-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-20 18:21 ` Frederic Weisbecker
[not found] ` <CAFTL4hy+vrvJKrc1Y2FW44k=LBi72H=34337xALpbtG_3u5O7w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-20 18:23 ` Frederic Weisbecker
2012-10-20 22:37 ` Tejun Heo
[not found] ` <20121020223709.GA5626-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2012-10-22 9:30 ` Frederic Weisbecker
2012-10-19 0:59 ` [PATCH cgroup/for-3.7-fixes 2/2] Revert "cgroup: Drop task_lock(parent) on cgroup_fork()" Tejun Heo
[not found] ` <20121019005951.GH13370-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-10-19 8:51 ` Li Zefan
2012-10-19 13:45 ` Frederic Weisbecker
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='CAFTL4hzo_w7HTgC9ApTk113X8WdZSpV+D+VSEe=604YEJFmKsg@mail.gmail.com' \
--to=fweisbec-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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;
as well as URLs for NNTP newsgroup(s).