Skip to content

Commit

Permalink
cgroup: make sure that decisions in __css_put are atomic
Browse files Browse the repository at this point in the history
__css_put is using atomic_dec on the ref count, and then
looking at the ref count to make decisions.  This is prone
to races, as someone else may decrement ref count between
our decrement and our decision.  Instead, we should base our
decisions on the value that we decremented the ref count to.

(This results in an actual race on Google's kernel which I
haven't been able to reproduce on the upstream kernel.  Having
said that, it's still incorrect by inspection).

Signed-off-by: Salman Qazi <[email protected]>
Acked-by: Li Zefan <[email protected]>
Signed-off-by: Tejun Heo <[email protected]>
Cc: [email protected]
  • Loading branch information
sqazi authored and htejun committed Jun 7, 2012
1 parent 71fae7e commit 967db0e
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions kernel/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -4984,8 +4984,7 @@ void __css_put(struct cgroup_subsys_state *css)
struct cgroup *cgrp = css->cgroup;

rcu_read_lock();
atomic_dec(&css->refcnt);
switch (css_refcnt(css)) {
switch (atomic_dec_return(&css->refcnt)) {
case 1:
if (notify_on_release(cgrp)) {
set_bit(CGRP_RELEASABLE, &cgrp->flags);
Expand Down

0 comments on commit 967db0e

Please sign in to comment.