Skip to content

Commit 9a9e97b

Browse files
committed
cgroup: Add memory barriers to plug cgroup_rstat_updated() race window
cgroup_rstat_updated() has a small race window where an updated signaling can race with flush and could be lost till the next update. This wasn't a problem for the existing usages, but we plan to use rstat to track counters which need to be accurate. This patch plugs the race window by synchronizing cgroup_rstat_updated() and flush path with memory barriers around cgroup_rstat_cpu->updated_next pointer. Signed-off-by: Tejun Heo <[email protected]>
1 parent 8f53470 commit 9a9e97b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

kernel/cgroup/rstat.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ void cgroup_rstat_updated(struct cgroup *cgrp, int cpu)
2828
unsigned long flags;
2929

3030
/*
31-
* Speculative already-on-list test. This may race leading to
32-
* temporary inaccuracies, which is fine.
33-
*
31+
* Paired with the one in cgroup_rstat_cpu_pop_upated(). Either we
32+
* see NULL updated_next or they see our updated stat.
33+
*/
34+
smp_mb();
35+
36+
/*
3437
* Because @parent's updated_children is terminated with @parent
3538
* instead of NULL, we can tell whether @cgrp is on the list by
3639
* testing the next pointer for NULL.
@@ -126,6 +129,13 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos,
126129

127130
*nextp = rstatc->updated_next;
128131
rstatc->updated_next = NULL;
132+
133+
/*
134+
* Paired with the one in cgroup_rstat_cpu_updated().
135+
* Either they see NULL updated_next or we see their
136+
* updated stat.
137+
*/
138+
smp_mb();
129139
}
130140

131141
return pos;

0 commit comments

Comments
 (0)