[Devel] [PATCH RH7 7/9] mm: memcontrol: add sanity checks for memcg->id.ref on get/put
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Wed Jul 5 09:39:50 MSK 2023
From: Vladimir Davydov <vdavydov at virtuozzo.com>
Link: http://lkml.kernel.org/r/1c5ddb1c171dbdfc3262252769d6138a29b35b70.1470219853.git.vdavydov@virtuozzo.com
Signed-off-by: Vladimir Davydov <vdavydov at virtuozzo.com>
Acked-by: Johannes Weiner <hannes at cmpxchg.org>
Acked-by: Michal Hocko <mhocko at suse.com>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
https://jira.vzint.dev/browse/PSBM-147036
(cherry picked from commit 58fa2a5512d9f224775fb01433f195e639953c5f)
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
mm/memcontrol.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index af99281292e5..42ca14e637ef 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6684,6 +6684,7 @@ static void mem_cgroup_id_remove(struct mem_cgroup *memcg)
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);
}
@@ -6707,6 +6708,7 @@ static struct mem_cgroup *mem_cgroup_id_get_online(struct mem_cgroup *memcg)
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)) {
mem_cgroup_id_remove(memcg);
@@ -6965,7 +6967,7 @@ mem_cgroup_css_online(struct cgroup *cont)
memcg = mem_cgroup_from_cont(cont);
/* Online state pins memcg ID, memcg ID pins CSS */
- mem_cgroup_id_get(memcg);
+ atomic_set(&memcg->id.ref, 1);
css_get(&memcg->css);
if (!cont->parent) {
--
2.40.1
More information about the Devel
mailing list