diff options
author | Salman Qazi <sqazi@google.com> | 2012-06-14 17:55:30 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2012-06-18 18:38:02 -0400 |
commit | 8e3bbf42c6d73881956863cc3305456afe2bc4ea (patch) | |
tree | bb3369e7444a2efe8e890ddd341e576e3cba18c1 /kernel/cgroup.c | |
parent | 967db0ea65b0bf8507a7643ac8f296c4f2c0a834 (diff) |
cgroups: Account for CSS_DEACT_BIAS in __css_put
When we fixed the race between atomic_dec and css_refcnt, we missed
the fact that css_refcnt internally subtracts CSS_DEACT_BIAS to get
the actual reference count. This can potentially cause a refcount leak
if __css_put races with cgroup_clear_css_refs.
Signed-off-by: Salman Qazi <sqazi@google.com>
Acked-by: Li Zefan <lizefan@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r-- | kernel/cgroup.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index ceeafe874b3f..2097684cf194 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -255,12 +255,17 @@ int cgroup_lock_is_held(void) | |||
255 | 255 | ||
256 | EXPORT_SYMBOL_GPL(cgroup_lock_is_held); | 256 | EXPORT_SYMBOL_GPL(cgroup_lock_is_held); |
257 | 257 | ||
258 | static int css_unbias_refcnt(int refcnt) | ||
259 | { | ||
260 | return refcnt >= 0 ? refcnt : refcnt - CSS_DEACT_BIAS; | ||
261 | } | ||
262 | |||
258 | /* the current nr of refs, always >= 0 whether @css is deactivated or not */ | 263 | /* the current nr of refs, always >= 0 whether @css is deactivated or not */ |
259 | static int css_refcnt(struct cgroup_subsys_state *css) | 264 | static int css_refcnt(struct cgroup_subsys_state *css) |
260 | { | 265 | { |
261 | int v = atomic_read(&css->refcnt); | 266 | int v = atomic_read(&css->refcnt); |
262 | 267 | ||
263 | return v >= 0 ? v : v - CSS_DEACT_BIAS; | 268 | return css_unbias_refcnt(v); |
264 | } | 269 | } |
265 | 270 | ||
266 | /* convenient tests for these bits */ | 271 | /* convenient tests for these bits */ |
@@ -4982,9 +4987,12 @@ EXPORT_SYMBOL_GPL(__css_tryget); | |||
4982 | void __css_put(struct cgroup_subsys_state *css) | 4987 | void __css_put(struct cgroup_subsys_state *css) |
4983 | { | 4988 | { |
4984 | struct cgroup *cgrp = css->cgroup; | 4989 | struct cgroup *cgrp = css->cgroup; |
4990 | int v; | ||
4985 | 4991 | ||
4986 | rcu_read_lock(); | 4992 | rcu_read_lock(); |
4987 | switch (atomic_dec_return(&css->refcnt)) { | 4993 | v = css_unbias_refcnt(atomic_dec_return(&css->refcnt)); |
4994 | |||
4995 | switch (v) { | ||
4988 | case 1: | 4996 | case 1: |
4989 | if (notify_on_release(cgrp)) { | 4997 | if (notify_on_release(cgrp)) { |
4990 | set_bit(CGRP_RELEASABLE, &cgrp->flags); | 4998 | set_bit(CGRP_RELEASABLE, &cgrp->flags); |