Skip to content

Commit

Permalink
Merge branch 'for-3.5-fixes' of git://git.kernel.org/pub/scm/linux/ke…
Browse files Browse the repository at this point in the history
…rnel/git/tj/cgroup

Pull two cgroup fixes from Tejun Heo:
 "This containes two patches fixing a refcnt race bug during css_put().
  Decrementing and checking the value weren't atomic and two tasks could
  think that they both pushed the counter to zero."

* 'for-3.5-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup:
  cgroups: Account for CSS_DEACT_BIAS in __css_put
  cgroup: make sure that decisions in __css_put are atomic
  • Loading branch information
Linus Torvalds committed Jun 21, 2012
2 parents c4c0e9e + 8e3bbf4 commit 2ce5682
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions kernel/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,17 @@ int cgroup_lock_is_held(void)

EXPORT_SYMBOL_GPL(cgroup_lock_is_held);

static int css_unbias_refcnt(int refcnt)
{
return refcnt >= 0 ? refcnt : refcnt - CSS_DEACT_BIAS;
}

/* the current nr of refs, always >= 0 whether @css is deactivated or not */
static int css_refcnt(struct cgroup_subsys_state *css)
{
int v = atomic_read(&css->refcnt);

return v >= 0 ? v : v - CSS_DEACT_BIAS;
return css_unbias_refcnt(v);
}

/* convenient tests for these bits */
Expand Down Expand Up @@ -4982,10 +4987,12 @@ EXPORT_SYMBOL_GPL(__css_tryget);
void __css_put(struct cgroup_subsys_state *css)
{
struct cgroup *cgrp = css->cgroup;
int v;

rcu_read_lock();
atomic_dec(&css->refcnt);
switch (css_refcnt(css)) {
v = css_unbias_refcnt(atomic_dec_return(&css->refcnt));

switch (v) {
case 1:
if (notify_on_release(cgrp)) {
set_bit(CGRP_RELEASABLE, &cgrp->flags);
Expand Down

0 comments on commit 2ce5682

Please sign in to comment.