]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
cgroup: use RCU free in create_css() failure path
authorTejun Heo <tj@kernel.org>
Sun, 4 May 2014 19:09:14 +0000 (15:09 -0400)
committerTejun Heo <tj@kernel.org>
Sun, 4 May 2014 19:09:14 +0000 (15:09 -0400)
Currently, when create_css() fails in the middle, the half-initialized
css is freed by invoking cgroup_subsys->css_free() directly.  This
patch updates the function so that it invokes RCU free path instead.
As the RCU free path puts the parent css and owning cgroup, their
references are now acquired right after a new css is successfully
allocated.

This doesn't make any visible difference now but is to enable
implementing css->id and RCU protected lookup by such IDs.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
kernel/cgroup.c

index 7cb9c0847445ecc441cb4e17e8ff84ef1d2d1ad2..0e2c401ed7b954e633a4742a0332e343cac87423 100644 (file)
@@ -4185,12 +4185,14 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss)
        if (IS_ERR(css))
                return PTR_ERR(css);
 
+       init_css(css, ss, cgrp);
+       cgroup_get(cgrp);
+       css_get(css->parent);
+
        err = percpu_ref_init(&css->refcnt, css_release);
        if (err)
                goto err_free_css;
 
-       init_css(css, ss, cgrp);
-
        err = cgroup_populate_dir(cgrp, 1 << ss->id);
        if (err)
                goto err_free_percpu_ref;
@@ -4199,9 +4201,6 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss)
        if (err)
                goto err_clear_dir;
 
-       cgroup_get(cgrp);
-       css_get(css->parent);
-
        if (ss->broken_hierarchy && !ss->warned_broken_hierarchy &&
            parent->parent) {
                pr_warn("%s (%d) created nested cgroup for controller \"%s\" which has incomplete hierarchy support. Nested cgroups may change behavior in the future.\n",
@@ -4218,7 +4217,7 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss)
 err_free_percpu_ref:
        percpu_ref_cancel_init(&css->refcnt);
 err_free_css:
-       ss->css_free(css);
+       call_rcu(&css->rcu_head, css_free_rcu_fn);
        return err;
 }