Linux Container Development
 help / color / mirror / Atom feed
From: Li Zefan <lizf@cn.fujitsu.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: paulmck@linux.vnet.ibm.com, LKML <linux-kernel@vger.kernel.org>,
	"containers@lists.osdl.org" <containers@lists.osdl.org>,
	Paul Menage <menage@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Matt Helsley <matthltc@us.ibm.com>,
	Cedric Le Goater <clg@vnet.ibm.com>
Subject: Re: [PATCH 4/5] freezer cgroup: Fix an RCU warning in cgroup_freezing_or_frozen()
Date: Fri, 23 Apr 2010 09:05:37 +0800	[thread overview]
Message-ID: <4BD0F261.6080302@cn.fujitsu.com> (raw)
In-Reply-To: <1271966935.1646.4.camel@laptop>

>>>> with CONFIG_PROVE_RCU, a warning can be triggered when we
>>>> resume from suspend:
>>>>
>>>> ...
>>>> include/linux/cgroup.h:533 invoked rcu_dereference_check() without protection!
>>>> ...
>>>>
>>>> task_freezer() calls task_subsys_state(), which needs to be
>>>> protected by rcu_read_lock or cgroup_mutex.
>>>>
>>>> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
>>>> ---
>>>>  kernel/cgroup_freezer.c |    2 ++
>>>>  1 files changed, 2 insertions(+), 0 deletions(-)
>>>>
>>>> diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
>>>> index 5038f4c..ac76983 100644
>>>> --- a/kernel/cgroup_freezer.c
>>>> +++ b/kernel/cgroup_freezer.c
>>>> @@ -53,6 +53,7 @@ int cgroup_freezing_or_frozen(struct task_struct *task)
>>>>  	struct freezer *freezer;
>>>>  	enum freezer_state state;
>>>>  
>>>> +	rcu_read_lock();
>>>>  	task_lock(task);
>>>>  	freezer = task_freezer(task);
>>>>  	if (!freezer->css.cgroup->parent)
>>>> @@ -60,6 +61,7 @@ int cgroup_freezing_or_frozen(struct task_struct *task)
>>>>  	else
>>>>  		state = freezer->state;
>>>>  	task_unlock(task);
>>>> +	rcu_read_unlock();
>>>>  
>>>>  	return (state == CGROUP_FREEZING) || (state == CGROUP_FROZEN);
>>>>  }
>>> Hmm cgroup_attach_task() does hold task_lock() over setting
>>> tsk->cgroups, so doesn't that also pin the task to the cgroup and thus
>>> the cgroup itself?
>> So you are advocating for the rcu_dereference check including the
>> task lock, correct?
> 
> I think that might be correct yes, although I would prefer confirmation
> from someone who actually knows kernel/cgroup.c ;-)
> 

You are right in that taking task_lock() is sufficient (I forgot
this lock rule), but it's not true that whatever locks are held
in the ->attach method can pin a task's cgroup.

So the right fix is including task_lock in rcu_deref check in
task_subsys_state(). I'll send a new fix.

  reply	other threads:[~2010-04-23  1:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-22  9:29 [PATCH 1/5] cgroup: Fix an RCU warning in cgroup_path() Li Zefan
2010-04-22  9:30 ` [PATCH 2/5] cgroup: Fix an RCU warning in alloc_css_id() Li Zefan
2010-04-22 19:55   ` Paul E. McKenney
2010-04-22  9:30 ` [PATCH 3/5] sched: Fix an RCU warning in print_task() Li Zefan
2010-04-22 10:20   ` Peter Zijlstra
2010-04-22 21:12     ` Matt Helsley
2010-04-22 22:05       ` Paul E. McKenney
2010-04-22 19:56   ` Paul E. McKenney
2010-04-22  9:31 ` [PATCH 4/5] freezer cgroup: Fix an RCU warning in cgroup_freezing_or_frozen() Li Zefan
2010-04-22 12:27   ` Peter Zijlstra
2010-04-22 19:59     ` Paul E. McKenney
2010-04-22 20:08       ` Peter Zijlstra
2010-04-23  1:05         ` Li Zefan [this message]
2010-04-23  6:47           ` Peter Zijlstra
2010-04-22  9:32 ` [PATCH 5/5] blk-cgroup: Fix an RCU warning in blkiocg_create() Li Zefan
2010-04-22 14:31   ` Vivek Goyal
     [not found]   ` <4BD017AC.1020209-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2010-04-22 19:57     ` Paul E. McKenney
2010-05-07  6:56       ` Li Zefan
2010-05-07  6:57         ` Jens Axboe
2010-05-07 14:55           ` Paul E. McKenney
2010-04-22 19:55 ` [PATCH 1/5] cgroup: Fix an RCU warning in cgroup_path() Paul E. McKenney

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=4BD0F261.6080302@cn.fujitsu.com \
    --to=lizf@cn.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=clg@vnet.ibm.com \
    --cc=containers@lists.osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthltc@us.ibm.com \
    --cc=menage@google.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.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