diff options
author | Tejun Heo <tj@kernel.org> | 2013-04-07 12:29:51 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-04-07 12:29:51 -0400 |
commit | 2219449a65ace0290cd9c2260ff337e326b8be8a (patch) | |
tree | ca93a1567a9e07adec09a3384d23536dca44603f | |
parent | 47cfcd0922454e49f4923b1e2d31a5bf199237c3 (diff) |
cgroup: remove cgroup_lock_is_held()
We don't want controllers to assume that the information is officially
available and do funky things with it.
The only user is task_subsys_state_check() which uses it to verify RCU
access context. We can move cgroup_lock_is_held() inside
CONFIG_PROVE_RCU but that doesn't add meaningful protection compared
to conditionally exposing cgroup_mutex.
Remove cgroup_lock_is_held(), export cgroup_mutex iff CONFIG_PROVE_RCU
and use lockdep_is_held() directly on the mutex in
task_subsys_state_check().
While at it, add parentheses around macro arguments in
task_subsys_state_check().
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
-rw-r--r-- | include/linux/cgroup.h | 13 | ||||
-rw-r--r-- | kernel/cgroup.c | 20 |
2 files changed, 15 insertions, 18 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 63deb70f3149..515927eebb37 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -30,7 +30,6 @@ struct css_id; | |||
30 | 30 | ||
31 | extern int cgroup_init_early(void); | 31 | extern int cgroup_init_early(void); |
32 | extern int cgroup_init(void); | 32 | extern int cgroup_init(void); |
33 | extern int cgroup_lock_is_held(void); | ||
34 | extern void cgroup_fork(struct task_struct *p); | 33 | extern void cgroup_fork(struct task_struct *p); |
35 | extern void cgroup_post_fork(struct task_struct *p); | 34 | extern void cgroup_post_fork(struct task_struct *p); |
36 | extern void cgroup_exit(struct task_struct *p, int run_callbacks); | 35 | extern void cgroup_exit(struct task_struct *p, int run_callbacks); |
@@ -552,10 +551,16 @@ static inline struct cgroup_subsys_state *cgroup_subsys_state( | |||
552 | * rcu_dereference_check() conditions, such as locks used during the | 551 | * rcu_dereference_check() conditions, such as locks used during the |
553 | * cgroup_subsys::attach() methods. | 552 | * cgroup_subsys::attach() methods. |
554 | */ | 553 | */ |
554 | #ifdef CONFIG_PROVE_RCU | ||
555 | extern struct mutex cgroup_mutex; | ||
555 | #define task_subsys_state_check(task, subsys_id, __c) \ | 556 | #define task_subsys_state_check(task, subsys_id, __c) \ |
556 | rcu_dereference_check(task->cgroups->subsys[subsys_id], \ | 557 | rcu_dereference_check((task)->cgroups->subsys[(subsys_id)], \ |
557 | lockdep_is_held(&task->alloc_lock) || \ | 558 | lockdep_is_held(&(task)->alloc_lock) || \ |
558 | cgroup_lock_is_held() || (__c)) | 559 | lockdep_is_held(&cgroup_mutex) || (__c)) |
560 | #else | ||
561 | #define task_subsys_state_check(task, subsys_id, __c) \ | ||
562 | rcu_dereference((task)->cgroups->subsys[(subsys_id)]) | ||
563 | #endif | ||
559 | 564 | ||
560 | static inline struct cgroup_subsys_state * | 565 | static inline struct cgroup_subsys_state * |
561 | task_subsys_state(struct task_struct *task, int subsys_id) | 566 | task_subsys_state(struct task_struct *task, int subsys_id) |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 1a65958c1a0b..ba3e24a76dae 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -83,7 +83,13 @@ | |||
83 | * B happens only through cgroup_show_options() and using cgroup_root_mutex | 83 | * B happens only through cgroup_show_options() and using cgroup_root_mutex |
84 | * breaks it. | 84 | * breaks it. |
85 | */ | 85 | */ |
86 | #ifdef CONFIG_PROVE_RCU | ||
87 | DEFINE_MUTEX(cgroup_mutex); | ||
88 | EXPORT_SYMBOL_GPL(cgroup_mutex); /* only for task_subsys_state_check() */ | ||
89 | #else | ||
86 | static DEFINE_MUTEX(cgroup_mutex); | 90 | static DEFINE_MUTEX(cgroup_mutex); |
91 | #endif | ||
92 | |||
87 | static DEFINE_MUTEX(cgroup_root_mutex); | 93 | static DEFINE_MUTEX(cgroup_root_mutex); |
88 | 94 | ||
89 | /* | 95 | /* |
@@ -251,20 +257,6 @@ static int cgroup_destroy_locked(struct cgroup *cgrp); | |||
251 | static int cgroup_addrm_files(struct cgroup *cgrp, struct cgroup_subsys *subsys, | 257 | static int cgroup_addrm_files(struct cgroup *cgrp, struct cgroup_subsys *subsys, |
252 | struct cftype cfts[], bool is_add); | 258 | struct cftype cfts[], bool is_add); |
253 | 259 | ||
254 | #ifdef CONFIG_PROVE_LOCKING | ||
255 | int cgroup_lock_is_held(void) | ||
256 | { | ||
257 | return lockdep_is_held(&cgroup_mutex); | ||
258 | } | ||
259 | #else /* #ifdef CONFIG_PROVE_LOCKING */ | ||
260 | int cgroup_lock_is_held(void) | ||
261 | { | ||
262 | return mutex_is_locked(&cgroup_mutex); | ||
263 | } | ||
264 | #endif /* #else #ifdef CONFIG_PROVE_LOCKING */ | ||
265 | |||
266 | EXPORT_SYMBOL_GPL(cgroup_lock_is_held); | ||
267 | |||
268 | static int css_unbias_refcnt(int refcnt) | 260 | static int css_unbias_refcnt(int refcnt) |
269 | { | 261 | { |
270 | return refcnt >= 0 ? refcnt : refcnt - CSS_DEACT_BIAS; | 262 | return refcnt >= 0 ? refcnt : refcnt - CSS_DEACT_BIAS; |