diff options
author | Tejun Heo <tj@kernel.org> | 2018-04-26 17:29:05 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2018-04-26 17:29:05 -0400 |
commit | 9a9e97b2f1f27ec70e3c138a790bd5627747d868 (patch) | |
tree | 3478f3d670cdde6cd9023990c8ebce2e2ecd73a3 /kernel/cgroup | |
parent | 8f53470bab04229e93ff9e4c20338cc08b42b344 (diff) |
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 <tj@kernel.org>
Diffstat (limited to 'kernel/cgroup')
-rw-r--r-- | kernel/cgroup/rstat.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index 339366e257d4..a4901e20735a 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c | |||
@@ -28,9 +28,12 @@ void cgroup_rstat_updated(struct cgroup *cgrp, int cpu) | |||
28 | unsigned long flags; | 28 | unsigned long flags; |
29 | 29 | ||
30 | /* | 30 | /* |
31 | * Speculative already-on-list test. This may race leading to | 31 | * Paired with the one in cgroup_rstat_cpu_pop_upated(). Either we |
32 | * temporary inaccuracies, which is fine. | 32 | * see NULL updated_next or they see our updated stat. |
33 | * | 33 | */ |
34 | smp_mb(); | ||
35 | |||
36 | /* | ||
34 | * Because @parent's updated_children is terminated with @parent | 37 | * Because @parent's updated_children is terminated with @parent |
35 | * instead of NULL, we can tell whether @cgrp is on the list by | 38 | * instead of NULL, we can tell whether @cgrp is on the list by |
36 | * testing the next pointer for NULL. | 39 | * testing the next pointer for NULL. |
@@ -126,6 +129,13 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos, | |||
126 | 129 | ||
127 | *nextp = rstatc->updated_next; | 130 | *nextp = rstatc->updated_next; |
128 | rstatc->updated_next = NULL; | 131 | 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(); | ||
129 | } | 139 | } |
130 | 140 | ||
131 | return pos; | 141 | return pos; |