diff options
Diffstat (limited to 'kernel/cgroup.c')
| -rw-r--r-- | kernel/cgroup.c | 62 |
1 files changed, 50 insertions, 12 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index e2769e13980c..6d870f2d1228 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
| @@ -1646,7 +1646,9 @@ static inline struct cftype *__d_cft(struct dentry *dentry) | |||
| 1646 | int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen) | 1646 | int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen) |
| 1647 | { | 1647 | { |
| 1648 | char *start; | 1648 | char *start; |
| 1649 | struct dentry *dentry = rcu_dereference(cgrp->dentry); | 1649 | struct dentry *dentry = rcu_dereference_check(cgrp->dentry, |
| 1650 | rcu_read_lock_held() || | ||
| 1651 | cgroup_lock_is_held()); | ||
| 1650 | 1652 | ||
| 1651 | if (!dentry || cgrp == dummytop) { | 1653 | if (!dentry || cgrp == dummytop) { |
| 1652 | /* | 1654 | /* |
| @@ -1662,13 +1664,17 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen) | |||
| 1662 | *--start = '\0'; | 1664 | *--start = '\0'; |
| 1663 | for (;;) { | 1665 | for (;;) { |
| 1664 | int len = dentry->d_name.len; | 1666 | int len = dentry->d_name.len; |
| 1667 | |||
| 1665 | if ((start -= len) < buf) | 1668 | if ((start -= len) < buf) |
| 1666 | return -ENAMETOOLONG; | 1669 | return -ENAMETOOLONG; |
| 1667 | memcpy(start, cgrp->dentry->d_name.name, len); | 1670 | memcpy(start, dentry->d_name.name, len); |
| 1668 | cgrp = cgrp->parent; | 1671 | cgrp = cgrp->parent; |
| 1669 | if (!cgrp) | 1672 | if (!cgrp) |
| 1670 | break; | 1673 | break; |
| 1671 | dentry = rcu_dereference(cgrp->dentry); | 1674 | |
| 1675 | dentry = rcu_dereference_check(cgrp->dentry, | ||
| 1676 | rcu_read_lock_held() || | ||
| 1677 | cgroup_lock_is_held()); | ||
| 1672 | if (!cgrp->parent) | 1678 | if (!cgrp->parent) |
| 1673 | continue; | 1679 | continue; |
| 1674 | if (--start < buf) | 1680 | if (--start < buf) |
| @@ -4429,7 +4435,15 @@ __setup("cgroup_disable=", cgroup_disable); | |||
| 4429 | */ | 4435 | */ |
| 4430 | unsigned short css_id(struct cgroup_subsys_state *css) | 4436 | unsigned short css_id(struct cgroup_subsys_state *css) |
| 4431 | { | 4437 | { |
| 4432 | struct css_id *cssid = rcu_dereference(css->id); | 4438 | struct css_id *cssid; |
| 4439 | |||
| 4440 | /* | ||
| 4441 | * This css_id() can return correct value when somone has refcnt | ||
| 4442 | * on this or this is under rcu_read_lock(). Once css->id is allocated, | ||
| 4443 | * it's unchanged until freed. | ||
| 4444 | */ | ||
| 4445 | cssid = rcu_dereference_check(css->id, | ||
| 4446 | rcu_read_lock_held() || atomic_read(&css->refcnt)); | ||
| 4433 | 4447 | ||
| 4434 | if (cssid) | 4448 | if (cssid) |
| 4435 | return cssid->id; | 4449 | return cssid->id; |
| @@ -4439,7 +4453,10 @@ EXPORT_SYMBOL_GPL(css_id); | |||
| 4439 | 4453 | ||
| 4440 | unsigned short css_depth(struct cgroup_subsys_state *css) | 4454 | unsigned short css_depth(struct cgroup_subsys_state *css) |
| 4441 | { | 4455 | { |
| 4442 | struct css_id *cssid = rcu_dereference(css->id); | 4456 | struct css_id *cssid; |
| 4457 | |||
| 4458 | cssid = rcu_dereference_check(css->id, | ||
| 4459 | rcu_read_lock_held() || atomic_read(&css->refcnt)); | ||
| 4443 | 4460 | ||
| 4444 | if (cssid) | 4461 | if (cssid) |
| 4445 | return cssid->depth; | 4462 | return cssid->depth; |
| @@ -4447,15 +4464,36 @@ unsigned short css_depth(struct cgroup_subsys_state *css) | |||
| 4447 | } | 4464 | } |
| 4448 | EXPORT_SYMBOL_GPL(css_depth); | 4465 | EXPORT_SYMBOL_GPL(css_depth); |
| 4449 | 4466 | ||
| 4467 | /** | ||
| 4468 | * css_is_ancestor - test "root" css is an ancestor of "child" | ||
| 4469 | * @child: the css to be tested. | ||
| 4470 | * @root: the css supporsed to be an ancestor of the child. | ||
| 4471 | * | ||
| 4472 | * Returns true if "root" is an ancestor of "child" in its hierarchy. Because | ||
| 4473 | * this function reads css->id, this use rcu_dereference() and rcu_read_lock(). | ||
| 4474 | * But, considering usual usage, the csses should be valid objects after test. | ||
| 4475 | * Assuming that the caller will do some action to the child if this returns | ||
| 4476 | * returns true, the caller must take "child";s reference count. | ||
| 4477 | * If "child" is valid object and this returns true, "root" is valid, too. | ||
| 4478 | */ | ||
| 4479 | |||
| 4450 | bool css_is_ancestor(struct cgroup_subsys_state *child, | 4480 | bool css_is_ancestor(struct cgroup_subsys_state *child, |
| 4451 | const struct cgroup_subsys_state *root) | 4481 | const struct cgroup_subsys_state *root) |
| 4452 | { | 4482 | { |
| 4453 | struct css_id *child_id = rcu_dereference(child->id); | 4483 | struct css_id *child_id; |
| 4454 | struct css_id *root_id = rcu_dereference(root->id); | 4484 | struct css_id *root_id; |
| 4485 | bool ret = true; | ||
| 4455 | 4486 | ||
| 4456 | if (!child_id || !root_id || (child_id->depth < root_id->depth)) | 4487 | rcu_read_lock(); |
| 4457 | return false; | 4488 | child_id = rcu_dereference(child->id); |
| 4458 | return child_id->stack[root_id->depth] == root_id->id; | 4489 | root_id = rcu_dereference(root->id); |
| 4490 | if (!child_id | ||
| 4491 | || !root_id | ||
| 4492 | || (child_id->depth < root_id->depth) | ||
| 4493 | || (child_id->stack[root_id->depth] != root_id->id)) | ||
| 4494 | ret = false; | ||
| 4495 | rcu_read_unlock(); | ||
| 4496 | return ret; | ||
| 4459 | } | 4497 | } |
| 4460 | 4498 | ||
| 4461 | static void __free_css_id_cb(struct rcu_head *head) | 4499 | static void __free_css_id_cb(struct rcu_head *head) |
| @@ -4555,13 +4593,13 @@ static int alloc_css_id(struct cgroup_subsys *ss, struct cgroup *parent, | |||
| 4555 | { | 4593 | { |
| 4556 | int subsys_id, i, depth = 0; | 4594 | int subsys_id, i, depth = 0; |
| 4557 | struct cgroup_subsys_state *parent_css, *child_css; | 4595 | struct cgroup_subsys_state *parent_css, *child_css; |
| 4558 | struct css_id *child_id, *parent_id = NULL; | 4596 | struct css_id *child_id, *parent_id; |
| 4559 | 4597 | ||
| 4560 | subsys_id = ss->subsys_id; | 4598 | subsys_id = ss->subsys_id; |
| 4561 | parent_css = parent->subsys[subsys_id]; | 4599 | parent_css = parent->subsys[subsys_id]; |
| 4562 | child_css = child->subsys[subsys_id]; | 4600 | child_css = child->subsys[subsys_id]; |
| 4563 | depth = css_depth(parent_css) + 1; | ||
| 4564 | parent_id = parent_css->id; | 4601 | parent_id = parent_css->id; |
| 4602 | depth = parent_id->depth; | ||
| 4565 | 4603 | ||
| 4566 | child_id = get_new_cssid(ss, depth); | 4604 | child_id = get_new_cssid(ss, depth); |
| 4567 | if (IS_ERR(child_id)) | 4605 | if (IS_ERR(child_id)) |
