diff options
-rw-r--r-- | Documentation/cgroups/cgroups.txt | 2 | ||||
-rw-r--r-- | include/linux/cgroup.h | 17 | ||||
-rw-r--r-- | kernel/cgroup.c | 45 |
3 files changed, 3 insertions, 61 deletions
diff --git a/Documentation/cgroups/cgroups.txt b/Documentation/cgroups/cgroups.txt index 8e74980ab385..e86faaea7d66 100644 --- a/Documentation/cgroups/cgroups.txt +++ b/Documentation/cgroups/cgroups.txt | |||
@@ -656,7 +656,7 @@ example in cpusets, no task may attach before 'cpus' and 'mems' are set | |||
656 | up. | 656 | up. |
657 | 657 | ||
658 | void bind(struct cgroup *root) | 658 | void bind(struct cgroup *root) |
659 | (cgroup_mutex and ss->hierarchy_mutex held by caller) | 659 | (cgroup_mutex held by caller) |
660 | 660 | ||
661 | Called when a cgroup subsystem is rebound to a different hierarchy | 661 | Called when a cgroup subsystem is rebound to a different hierarchy |
662 | and root cgroup. Currently this will only involve movement between | 662 | and root cgroup. Currently this will only involve movement between |
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index d3f5fba2c159..c90eaa803440 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -500,21 +500,8 @@ struct cgroup_subsys { | |||
500 | const char *name; | 500 | const char *name; |
501 | 501 | ||
502 | /* | 502 | /* |
503 | * Protects sibling/children links of cgroups in this | ||
504 | * hierarchy, plus protects which hierarchy (or none) the | ||
505 | * subsystem is a part of (i.e. root/sibling). To avoid | ||
506 | * potential deadlocks, the following operations should not be | ||
507 | * undertaken while holding any hierarchy_mutex: | ||
508 | * | ||
509 | * - allocating memory | ||
510 | * - initiating hotplug events | ||
511 | */ | ||
512 | struct mutex hierarchy_mutex; | ||
513 | struct lock_class_key subsys_key; | ||
514 | |||
515 | /* | ||
516 | * Link to parent, and list entry in parent's children. | 503 | * Link to parent, and list entry in parent's children. |
517 | * Protected by this->hierarchy_mutex and cgroup_lock() | 504 | * Protected by cgroup_lock() |
518 | */ | 505 | */ |
519 | struct cgroupfs_root *root; | 506 | struct cgroupfs_root *root; |
520 | struct list_head sibling; | 507 | struct list_head sibling; |
@@ -602,7 +589,7 @@ int cgroup_attach_task_all(struct task_struct *from, struct task_struct *); | |||
602 | * the lifetime of cgroup_subsys_state is subsys's matter. | 589 | * the lifetime of cgroup_subsys_state is subsys's matter. |
603 | * | 590 | * |
604 | * Looking up and scanning function should be called under rcu_read_lock(). | 591 | * Looking up and scanning function should be called under rcu_read_lock(). |
605 | * Taking cgroup_mutex()/hierarchy_mutex() is not necessary for following calls. | 592 | * Taking cgroup_mutex is not necessary for following calls. |
606 | * But the css returned by this routine can be "not populated yet" or "being | 593 | * But the css returned by this routine can be "not populated yet" or "being |
607 | * destroyed". The caller should check css and cgroup's status. | 594 | * destroyed". The caller should check css and cgroup's status. |
608 | */ | 595 | */ |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index ceeafe874b3f..dec62f5936ef 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -1073,28 +1073,24 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
1073 | BUG_ON(cgrp->subsys[i]); | 1073 | BUG_ON(cgrp->subsys[i]); |
1074 | BUG_ON(!dummytop->subsys[i]); | 1074 | BUG_ON(!dummytop->subsys[i]); |
1075 | BUG_ON(dummytop->subsys[i]->cgroup != dummytop); | 1075 | BUG_ON(dummytop->subsys[i]->cgroup != dummytop); |
1076 | mutex_lock(&ss->hierarchy_mutex); | ||
1077 | cgrp->subsys[i] = dummytop->subsys[i]; | 1076 | cgrp->subsys[i] = dummytop->subsys[i]; |
1078 | cgrp->subsys[i]->cgroup = cgrp; | 1077 | cgrp->subsys[i]->cgroup = cgrp; |
1079 | list_move(&ss->sibling, &root->subsys_list); | 1078 | list_move(&ss->sibling, &root->subsys_list); |
1080 | ss->root = root; | 1079 | ss->root = root; |
1081 | if (ss->bind) | 1080 | if (ss->bind) |
1082 | ss->bind(cgrp); | 1081 | ss->bind(cgrp); |
1083 | mutex_unlock(&ss->hierarchy_mutex); | ||
1084 | /* refcount was already taken, and we're keeping it */ | 1082 | /* refcount was already taken, and we're keeping it */ |
1085 | } else if (bit & removed_bits) { | 1083 | } else if (bit & removed_bits) { |
1086 | /* We're removing this subsystem */ | 1084 | /* We're removing this subsystem */ |
1087 | BUG_ON(ss == NULL); | 1085 | BUG_ON(ss == NULL); |
1088 | BUG_ON(cgrp->subsys[i] != dummytop->subsys[i]); | 1086 | BUG_ON(cgrp->subsys[i] != dummytop->subsys[i]); |
1089 | BUG_ON(cgrp->subsys[i]->cgroup != cgrp); | 1087 | BUG_ON(cgrp->subsys[i]->cgroup != cgrp); |
1090 | mutex_lock(&ss->hierarchy_mutex); | ||
1091 | if (ss->bind) | 1088 | if (ss->bind) |
1092 | ss->bind(dummytop); | 1089 | ss->bind(dummytop); |
1093 | dummytop->subsys[i]->cgroup = dummytop; | 1090 | dummytop->subsys[i]->cgroup = dummytop; |
1094 | cgrp->subsys[i] = NULL; | 1091 | cgrp->subsys[i] = NULL; |
1095 | subsys[i]->root = &rootnode; | 1092 | subsys[i]->root = &rootnode; |
1096 | list_move(&ss->sibling, &rootnode.subsys_list); | 1093 | list_move(&ss->sibling, &rootnode.subsys_list); |
1097 | mutex_unlock(&ss->hierarchy_mutex); | ||
1098 | /* subsystem is now free - drop reference on module */ | 1094 | /* subsystem is now free - drop reference on module */ |
1099 | module_put(ss->module); | 1095 | module_put(ss->module); |
1100 | } else if (bit & final_bits) { | 1096 | } else if (bit & final_bits) { |
@@ -3917,37 +3913,6 @@ static void init_cgroup_css(struct cgroup_subsys_state *css, | |||
3917 | set_bit(CSS_CLEAR_CSS_REFS, &css->flags); | 3913 | set_bit(CSS_CLEAR_CSS_REFS, &css->flags); |
3918 | } | 3914 | } |
3919 | 3915 | ||
3920 | static void cgroup_lock_hierarchy(struct cgroupfs_root *root) | ||
3921 | { | ||
3922 | /* We need to take each hierarchy_mutex in a consistent order */ | ||
3923 | int i; | ||
3924 | |||
3925 | /* | ||
3926 | * No worry about a race with rebind_subsystems that might mess up the | ||
3927 | * locking order, since both parties are under cgroup_mutex. | ||
3928 | */ | ||
3929 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | ||
3930 | struct cgroup_subsys *ss = subsys[i]; | ||
3931 | if (ss == NULL) | ||
3932 | continue; | ||
3933 | if (ss->root == root) | ||
3934 | mutex_lock(&ss->hierarchy_mutex); | ||
3935 | } | ||
3936 | } | ||
3937 | |||
3938 | static void cgroup_unlock_hierarchy(struct cgroupfs_root *root) | ||
3939 | { | ||
3940 | int i; | ||
3941 | |||
3942 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | ||
3943 | struct cgroup_subsys *ss = subsys[i]; | ||
3944 | if (ss == NULL) | ||
3945 | continue; | ||
3946 | if (ss->root == root) | ||
3947 | mutex_unlock(&ss->hierarchy_mutex); | ||
3948 | } | ||
3949 | } | ||
3950 | |||
3951 | /* | 3916 | /* |
3952 | * cgroup_create - create a cgroup | 3917 | * cgroup_create - create a cgroup |
3953 | * @parent: cgroup that will be parent of the new cgroup | 3918 | * @parent: cgroup that will be parent of the new cgroup |
@@ -4008,9 +3973,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
4008 | ss->post_clone(cgrp); | 3973 | ss->post_clone(cgrp); |
4009 | } | 3974 | } |
4010 | 3975 | ||
4011 | cgroup_lock_hierarchy(root); | ||
4012 | list_add(&cgrp->sibling, &cgrp->parent->children); | 3976 | list_add(&cgrp->sibling, &cgrp->parent->children); |
4013 | cgroup_unlock_hierarchy(root); | ||
4014 | root->number_of_cgroups++; | 3977 | root->number_of_cgroups++; |
4015 | 3978 | ||
4016 | err = cgroup_create_dir(cgrp, dentry, mode); | 3979 | err = cgroup_create_dir(cgrp, dentry, mode); |
@@ -4037,9 +4000,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
4037 | 4000 | ||
4038 | err_remove: | 4001 | err_remove: |
4039 | 4002 | ||
4040 | cgroup_lock_hierarchy(root); | ||
4041 | list_del(&cgrp->sibling); | 4003 | list_del(&cgrp->sibling); |
4042 | cgroup_unlock_hierarchy(root); | ||
4043 | root->number_of_cgroups--; | 4004 | root->number_of_cgroups--; |
4044 | 4005 | ||
4045 | err_destroy: | 4006 | err_destroy: |
@@ -4247,10 +4208,8 @@ again: | |||
4247 | list_del_init(&cgrp->release_list); | 4208 | list_del_init(&cgrp->release_list); |
4248 | raw_spin_unlock(&release_list_lock); | 4209 | raw_spin_unlock(&release_list_lock); |
4249 | 4210 | ||
4250 | cgroup_lock_hierarchy(cgrp->root); | ||
4251 | /* delete this cgroup from parent->children */ | 4211 | /* delete this cgroup from parent->children */ |
4252 | list_del_init(&cgrp->sibling); | 4212 | list_del_init(&cgrp->sibling); |
4253 | cgroup_unlock_hierarchy(cgrp->root); | ||
4254 | 4213 | ||
4255 | list_del_init(&cgrp->allcg_node); | 4214 | list_del_init(&cgrp->allcg_node); |
4256 | 4215 | ||
@@ -4324,8 +4283,6 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss) | |||
4324 | * need to invoke fork callbacks here. */ | 4283 | * need to invoke fork callbacks here. */ |
4325 | BUG_ON(!list_empty(&init_task.tasks)); | 4284 | BUG_ON(!list_empty(&init_task.tasks)); |
4326 | 4285 | ||
4327 | mutex_init(&ss->hierarchy_mutex); | ||
4328 | lockdep_set_class(&ss->hierarchy_mutex, &ss->subsys_key); | ||
4329 | ss->active = 1; | 4286 | ss->active = 1; |
4330 | 4287 | ||
4331 | /* this function shouldn't be used with modular subsystems, since they | 4288 | /* this function shouldn't be used with modular subsystems, since they |
@@ -4452,8 +4409,6 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss) | |||
4452 | } | 4409 | } |
4453 | write_unlock(&css_set_lock); | 4410 | write_unlock(&css_set_lock); |
4454 | 4411 | ||
4455 | mutex_init(&ss->hierarchy_mutex); | ||
4456 | lockdep_set_class(&ss->hierarchy_mutex, &ss->subsys_key); | ||
4457 | ss->active = 1; | 4412 | ss->active = 1; |
4458 | 4413 | ||
4459 | /* success! */ | 4414 | /* success! */ |