mm: memcontrol: add sanity checks for memcg->id.ref on get/put
authorVladimir Davydov <vdavydov@virtuozzo.com>
Sat, 10 Sep 2016 10:34:03 +0000 (20:34 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Sat, 10 Sep 2016 10:34:03 +0000 (20:34 +1000)
Link: http://lkml.kernel.org/r/1c5ddb1c171dbdfc3262252769d6138a29b35b70.1470219853.git.vdavydov@virtuozzo.com
Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/memcontrol.c

index d0a34289f3a1a25ed4b2c94256a267f43d2acbdd..bdb796fd85f40962616478fdf944f0e6768b14e7 100644 (file)
@@ -4049,11 +4049,13 @@ static DEFINE_IDR(mem_cgroup_idr);
 
 static void mem_cgroup_id_get_many(struct mem_cgroup *memcg, unsigned int n)
 {
+       VM_BUG_ON(atomic_read(&memcg->id.ref) <= 0);
        atomic_add(n, &memcg->id.ref);
 }
 
 static void mem_cgroup_id_put_many(struct mem_cgroup *memcg, unsigned int n)
 {
+       VM_BUG_ON(atomic_read(&memcg->id.ref) < n);
        if (atomic_sub_and_test(n, &memcg->id.ref)) {
                idr_remove(&mem_cgroup_idr, memcg->id.id);
                memcg->id.id = 0;
@@ -4242,8 +4244,10 @@ fail:
 
 static int mem_cgroup_css_online(struct cgroup_subsys_state *css)
 {
+       struct mem_cgroup *memcg = mem_cgroup_from_css(css);
+
        /* Online state pins memcg ID, memcg ID pins CSS */
-       mem_cgroup_id_get(mem_cgroup_from_css(css));
+       atomic_set(&memcg->id.ref, 1);
        css_get(css);
        return 0;
 }
This page took 0.026524 seconds and 5 git commands to generate.