cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cgroup: make sure that decisions in __css_put are atomic
@ 2012-06-05 21:50 Salman Qazi
       [not found] ` <20120605215019.4722.31817.stgit-Oz2bD8w/QAX+Wsei8lUk51LMcqb5oVE02SarAXORi/o@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Salman Qazi @ 2012-06-05 21:50 UTC (permalink / raw)
  To: cgroups-u79uwXL29TY76Z2rM5mHXA, tejun-hpIqsD4AKlfQT0dZR+AlfA

__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 <sqazi-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
---
 kernel/cgroup.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 0f3527d..18dc8aa 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4973,8 +4973,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);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-06-07  1:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-05 21:50 [PATCH] cgroup: make sure that decisions in __css_put are atomic Salman Qazi
     [not found] ` <20120605215019.4722.31817.stgit-Oz2bD8w/QAX+Wsei8lUk51LMcqb5oVE02SarAXORi/o@public.gmane.org>
2012-06-06  7:31   ` Li Zefan
     [not found]     ` <4FCF0747.7050000-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2012-06-07  1:54       ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).