]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
mm, memcg: prevent mem_cgroup_protected store tearing
authorChris Down <chris@chrisdown.name>
Thu, 2 Apr 2020 04:07:33 +0000 (21:07 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 2 Apr 2020 16:35:29 +0000 (09:35 -0700)
The read side of this is all protected, but we can still tear if multiple
iterations of mem_cgroup_protected are going at the same time.

There's some intentional racing in mem_cgroup_protected which is ok, but
load/store tearing should be avoided.

Signed-off-by: Chris Down <chris@chrisdown.name>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Roman Gushchin <guro@fb.com>
Cc: Tejun Heo <tj@kernel.org>
Link: http://lkml.kernel.org/r/d1e9fbc0379fe8db475d82c8b6fbe048876e12ae.1584034301.git.chris@chrisdown.name
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/memcontrol.c

index 1cd944c2a734bfef5a8b8fc77178b256cc5cd787..a96d9015ff7347eaea8f737c1424507358670f2b 100644 (file)
@@ -6396,14 +6396,14 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root,
 
        parent_usage = page_counter_read(&parent->memory);
 
-       memcg->memory.emin = effective_protection(usage, parent_usage,
+       WRITE_ONCE(memcg->memory.emin, effective_protection(usage, parent_usage,
                        READ_ONCE(memcg->memory.min),
                        READ_ONCE(parent->memory.emin),
-                       atomic_long_read(&parent->memory.children_min_usage));
+                       atomic_long_read(&parent->memory.children_min_usage)));
 
-       memcg->memory.elow = effective_protection(usage, parent_usage,
+       WRITE_ONCE(memcg->memory.elow, effective_protection(usage, parent_usage,
                        memcg->memory.low, READ_ONCE(parent->memory.elow),
-                       atomic_long_read(&parent->memory.children_low_usage));
+                       atomic_long_read(&parent->memory.children_low_usage)));
 
 out:
        if (usage <= memcg->memory.emin)