diff options
author | Tejun Heo <tj@kernel.org> | 2013-08-13 11:01:55 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-08-13 11:01:55 -0400 |
commit | 73e80ed8007fc48a6deeb295ba37159fad274bd2 (patch) | |
tree | c4f430a223725038cb85be6ee0e13578d831c929 | |
parent | 105347ba5da3e87facce2337c50cd5df93cc6bec (diff) |
cgroup: add __rcu modifier to cgroup->subsys[]
For the planned unified hierarchy, each css (cgroup_subsys_state) will
be RCU protected so that it can be created and destroyed individually
while allowing RCU accesses. Previous changes ensured that all
cgroup->subsys[] accesses use the cgroup_css() accessor. This patch
adds __rcu modifier to cgroup->subsys[], add matching RCU dereference
in cgroup_css() and convert all assignments to either
rcu_assign_pointer() or RCU_INIT_POINTER().
This change prepares for the actual RCUfication of css's and doesn't
introduce any visible behavior change. The conversion is verified
with sparse and all accesses are properly RCU annotated.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
-rw-r--r-- | include/linux/cgroup.h | 2 | ||||
-rw-r--r-- | kernel/cgroup.c | 19 |
2 files changed, 15 insertions, 6 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 8a5dc91fbaad..eb200b5794e7 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -204,7 +204,7 @@ struct cgroup { | |||
204 | struct cgroup_name __rcu *name; | 204 | struct cgroup_name __rcu *name; |
205 | 205 | ||
206 | /* Private pointers for each registered subsystem */ | 206 | /* Private pointers for each registered subsystem */ |
207 | struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT]; | 207 | struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT]; |
208 | 208 | ||
209 | struct cgroupfs_root *root; | 209 | struct cgroupfs_root *root; |
210 | 210 | ||
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index d63beffd41e1..c27101622567 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -229,11 +229,16 @@ static int cgroup_addrm_files(struct cgroup *cgrp, struct cftype cfts[], | |||
229 | * @subsys_id: the subsystem of interest | 229 | * @subsys_id: the subsystem of interest |
230 | * | 230 | * |
231 | * Return @cgrp's css (cgroup_subsys_state) associated with @subsys_id. | 231 | * Return @cgrp's css (cgroup_subsys_state) associated with @subsys_id. |
232 | * This function must be called either under cgroup_mutex or | ||
233 | * rcu_read_lock() and the caller is responsible for pinning the returned | ||
234 | * css if it wants to keep accessing it outside the said locks. This | ||
235 | * function may return %NULL if @cgrp doesn't have @subsys_id enabled. | ||
232 | */ | 236 | */ |
233 | static struct cgroup_subsys_state *cgroup_css(struct cgroup *cgrp, | 237 | static struct cgroup_subsys_state *cgroup_css(struct cgroup *cgrp, |
234 | int subsys_id) | 238 | int subsys_id) |
235 | { | 239 | { |
236 | return cgrp->subsys[subsys_id]; | 240 | return rcu_dereference_check(cgrp->subsys[subsys_id], |
241 | lockdep_is_held(&cgroup_mutex)); | ||
237 | } | 242 | } |
238 | 243 | ||
239 | /* convenient tests for these bits */ | 244 | /* convenient tests for these bits */ |
@@ -1072,8 +1077,10 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
1072 | BUG_ON(!cgroup_css(cgroup_dummy_top, i)); | 1077 | BUG_ON(!cgroup_css(cgroup_dummy_top, i)); |
1073 | BUG_ON(cgroup_css(cgroup_dummy_top, i)->cgroup != cgroup_dummy_top); | 1078 | BUG_ON(cgroup_css(cgroup_dummy_top, i)->cgroup != cgroup_dummy_top); |
1074 | 1079 | ||
1075 | cgrp->subsys[i] = cgroup_dummy_top->subsys[i]; | 1080 | rcu_assign_pointer(cgrp->subsys[i], |
1081 | cgroup_css(cgroup_dummy_top, i)); | ||
1076 | cgroup_css(cgrp, i)->cgroup = cgrp; | 1082 | cgroup_css(cgrp, i)->cgroup = cgrp; |
1083 | |||
1077 | list_move(&ss->sibling, &root->subsys_list); | 1084 | list_move(&ss->sibling, &root->subsys_list); |
1078 | ss->root = root; | 1085 | ss->root = root; |
1079 | if (ss->bind) | 1086 | if (ss->bind) |
@@ -1088,8 +1095,10 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
1088 | 1095 | ||
1089 | if (ss->bind) | 1096 | if (ss->bind) |
1090 | ss->bind(cgroup_css(cgroup_dummy_top, i)); | 1097 | ss->bind(cgroup_css(cgroup_dummy_top, i)); |
1098 | |||
1091 | cgroup_css(cgroup_dummy_top, i)->cgroup = cgroup_dummy_top; | 1099 | cgroup_css(cgroup_dummy_top, i)->cgroup = cgroup_dummy_top; |
1092 | cgrp->subsys[i] = NULL; | 1100 | RCU_INIT_POINTER(cgrp->subsys[i], NULL); |
1101 | |||
1093 | cgroup_subsys[i]->root = &cgroup_dummy_root; | 1102 | cgroup_subsys[i]->root = &cgroup_dummy_root; |
1094 | list_move(&ss->sibling, &cgroup_dummy_root.subsys_list); | 1103 | list_move(&ss->sibling, &cgroup_dummy_root.subsys_list); |
1095 | 1104 | ||
@@ -4314,7 +4323,7 @@ static void init_cgroup_css(struct cgroup_subsys_state *css, | |||
4314 | css->flags |= CSS_ROOT; | 4323 | css->flags |= CSS_ROOT; |
4315 | 4324 | ||
4316 | BUG_ON(cgroup_css(cgrp, ss->subsys_id)); | 4325 | BUG_ON(cgroup_css(cgrp, ss->subsys_id)); |
4317 | cgrp->subsys[ss->subsys_id] = css; | 4326 | rcu_assign_pointer(cgrp->subsys[ss->subsys_id], css); |
4318 | } | 4327 | } |
4319 | 4328 | ||
4320 | /* invoke ->css_online() on a new CSS and mark it online if successful */ | 4329 | /* invoke ->css_online() on a new CSS and mark it online if successful */ |
@@ -4962,7 +4971,7 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss) | |||
4962 | * also takes care of freeing the css_id. | 4971 | * also takes care of freeing the css_id. |
4963 | */ | 4972 | */ |
4964 | ss->css_free(cgroup_css(cgroup_dummy_top, ss->subsys_id)); | 4973 | ss->css_free(cgroup_css(cgroup_dummy_top, ss->subsys_id)); |
4965 | cgroup_dummy_top->subsys[ss->subsys_id] = NULL; | 4974 | RCU_INIT_POINTER(cgroup_dummy_top->subsys[ss->subsys_id], NULL); |
4966 | 4975 | ||
4967 | mutex_unlock(&cgroup_mutex); | 4976 | mutex_unlock(&cgroup_mutex); |
4968 | } | 4977 | } |