From: Tejun Heo <theo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
Fengguang Wu
<fengguang.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Subject: [PATCH cgroup/for-3.11 2/3] cgroup: fix RCU accesses around task->cgroups
Date: Fri, 21 Jun 2013 15:52:04 -0700 [thread overview]
Message-ID: <20130621225204.GD3949@htj.dyndns.org> (raw)
In-Reply-To: <20130621225116.GC3949-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
There are several places in kernel/cgroup.c where task->cgroups is
accessed and modified without going through proper RCU accessors.
None is broken as they're all lock protected accesses; however, this
still triggers sparse RCU address space warnings.
* Consistently use task_css_set() for task->cgroups dereferencing.
* Use RCU_INIT_POINTER() to clear task->cgroups to &init_css_set on
exit.
* Remove unnecessary rcu_dereference_raw() from cset->subsys[]
dereference in cgroup_exit().
Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Reported-by: Fengguang Wu <fengguang.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
kernel/cgroup.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -704,7 +704,7 @@ static struct cgroup *task_cgroup_from_r
* task can't change groups, so the only thing that can happen
* is that it exits and its css is set back to init_css_set.
*/
- cset = task->cgroups;
+ cset = task_css_set(task);
if (cset == &init_css_set) {
res = &root->top_cgroup;
} else {
@@ -1948,7 +1948,7 @@ static void cgroup_task_migrate(struct c
* css_set to init_css_set and dropping the old one.
*/
WARN_ON_ONCE(tsk->flags & PF_EXITING);
- old_cset = tsk->cgroups;
+ old_cset = task_css_set(tsk);
task_lock(tsk);
rcu_assign_pointer(tsk->cgroups, new_cset);
@@ -2071,8 +2071,11 @@ static int cgroup_attach_task(struct cgr
* we use find_css_set, which allocates a new one if necessary.
*/
for (i = 0; i < group_size; i++) {
+ struct css_set *old_cset;
+
tc = flex_array_get(group, i);
- tc->cg = find_css_set(tc->task->cgroups, cgrp);
+ old_cset = task_css_set(tc->task);
+ tc->cg = find_css_set(old_cset, cgrp);
if (!tc->cg) {
retval = -ENOMEM;
goto out_put_css_set_refs;
@@ -2989,7 +2992,7 @@ static void cgroup_enable_task_cg_lists(
* entry won't be deleted though the process has exited.
*/
if (!(p->flags & PF_EXITING) && list_empty(&p->cg_list))
- list_add(&p->cg_list, &p->cgroups->tasks);
+ list_add(&p->cg_list, &task_css_set(p)->tasks);
task_unlock(p);
} while_each_thread(g, p);
read_unlock(&tasklist_lock);
@@ -5046,8 +5049,8 @@ static const struct file_operations proc
void cgroup_fork(struct task_struct *child)
{
task_lock(current);
+ get_css_set(task_css_set(current));
child->cgroups = current->cgroups;
- get_css_set(child->cgroups);
task_unlock(current);
INIT_LIST_HEAD(&child->cg_list);
}
@@ -5081,7 +5084,7 @@ void cgroup_post_fork(struct task_struct
write_lock(&css_set_lock);
task_lock(child);
if (list_empty(&child->cg_list))
- list_add(&child->cg_list, &child->cgroups->tasks);
+ list_add(&child->cg_list, &task_css_set(child)->tasks);
task_unlock(child);
write_unlock(&css_set_lock);
}
@@ -5163,8 +5166,8 @@ void cgroup_exit(struct task_struct *tsk
/* Reassign the task to the init_css_set. */
task_lock(tsk);
- cset = tsk->cgroups;
- tsk->cgroups = &init_css_set;
+ cset = task_css_set(tsk);
+ RCU_INIT_POINTER(tsk->cgroups, &init_css_set);
if (run_callbacks && need_forkexit_callback) {
/*
@@ -5175,8 +5178,7 @@ void cgroup_exit(struct task_struct *tsk
struct cgroup_subsys *ss = subsys[i];
if (ss->exit) {
- struct cgroup *old_cgrp =
- rcu_dereference_raw(cset->subsys[i])->cgroup;
+ struct cgroup *old_cgrp = cset->subsys[i]->cgroup;
struct cgroup *cgrp = task_cgroup(tsk, i);
ss->exit(cgrp, old_cgrp, tsk);
}
@@ -5546,7 +5548,7 @@ static u64 current_css_set_refcount_read
u64 count;
rcu_read_lock();
- count = atomic_read(¤t->cgroups->refcount);
+ count = atomic_read(&task_css_set(current)->refcount);
rcu_read_unlock();
return count;
}
next prev parent reply other threads:[~2013-06-21 22:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-21 22:51 [PATCH cgroup/for-3.11 1/3] cgroup: fix RCU accesses to task->cgroups Tejun Heo
[not found] ` <20130621225116.GC3949-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-06-21 22:52 ` Tejun Heo [this message]
[not found] ` <20130621225204.GD3949-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-06-21 22:52 ` [PATCH cgroup/for-3.11 3/3] cgroup: always use RCU accessors for protected accesses Tejun Heo
[not found] ` <20130621225233.GE3949-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-06-25 2:04 ` Li Zefan
2013-06-25 2:02 ` [PATCH cgroup/for-3.11 2/3] cgroup: fix RCU accesses around task->cgroups Li Zefan
[not found] ` <51C8FA3E.9020104-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-06-25 18:50 ` Tejun Heo
2013-06-26 3:29 ` Li Zefan
2013-06-25 1:55 ` [PATCH cgroup/for-3.11 1/3] cgroup: fix RCU accesses to task->cgroups Li Zefan
2013-06-25 18:48 ` [PATCH v2 " Tejun Heo
[not found] ` <20130625184832.GC20051-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2013-06-26 3:28 ` Li Zefan
2013-06-26 17:49 ` [PATCH " Tejun Heo
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=20130621225204.GD3949@htj.dyndns.org \
--to=theo-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=fengguang.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=lizefan-hv44wF8Li93QT0dZR+AlfA@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).