linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] slab: Add check for memcg_data != OBJEXTS_ALLOC_FAIL in folio_memcg_kmem
@ 2025-10-14 15:27 Hao Ge
  2025-10-14 16:12 ` Suren Baghdasaryan
  2025-10-14 21:13 ` Roman Gushchin
  0 siblings, 2 replies; 12+ messages in thread
From: Hao Ge @ 2025-10-14 15:27 UTC (permalink / raw)
  To: Vlastimil Babka, Alexei Starovoitov, Andrew Morton,
	Johannes Weiner, Shakeel Butt, Michal Hocko, Roman Gushchin,
	Muchun Song, Suren Baghdasaryan
  Cc: Harry Yoo, cgroups, linux-mm, linux-kernel, Hao Ge

From: Hao Ge <gehao@kylinos.cn>

Since OBJEXTS_ALLOC_FAIL and MEMCG_DATA_OBJEXTS currently share
the same bit position, we cannot determine whether memcg_data still
points to the slabobj_ext vector simply by checking
folio->memcg_data & MEMCG_DATA_OBJEXTS.

If obj_exts allocation failed, slab->obj_exts is set to OBJEXTS_ALLOC_FAIL,
and during the release of the associated folio, the BUG check is triggered
because it was mistakenly assumed that a valid folio->memcg_data
was not cleared before freeing the folio.

So let's check for memcg_data != OBJEXTS_ALLOC_FAIL in folio_memcg_kmem.

Fixes: 7612833192d5 ("slab: Reuse first bit for OBJEXTS_ALLOC_FAIL")
Suggested-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: Hao Ge <gehao@kylinos.cn>
---
v3: Simplify the solution, per Harry's suggestion in the v1 comments
    Add Suggested-by: Harry Yoo <harry.yoo@oracle.com>
---
 include/linux/memcontrol.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 873e510d6f8d..7ed15f858dc4 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -534,7 +534,9 @@ static inline struct mem_cgroup *get_mem_cgroup_from_objcg(struct obj_cgroup *ob
 static inline bool folio_memcg_kmem(struct folio *folio)
 {
 	VM_BUG_ON_PGFLAGS(PageTail(&folio->page), &folio->page);
-	VM_BUG_ON_FOLIO(folio->memcg_data & MEMCG_DATA_OBJEXTS, folio);
+	VM_BUG_ON_FOLIO((folio->memcg_data != OBJEXTS_ALLOC_FAIL) &&
+			(folio->memcg_data & MEMCG_DATA_OBJEXTS),
+			folio);
 	return folio->memcg_data & MEMCG_DATA_KMEM;
 }
 
-- 
2.25.1



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-10-15 11:41 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-14 15:27 [PATCH v3] slab: Add check for memcg_data != OBJEXTS_ALLOC_FAIL in folio_memcg_kmem Hao Ge
2025-10-14 16:12 ` Suren Baghdasaryan
2025-10-14 20:14   ` Shakeel Butt
2025-10-14 20:58     ` Vlastimil Babka
2025-10-14 22:40       ` Shakeel Butt
2025-10-15  9:25   ` Harry Yoo
2025-10-15  9:54     ` Vlastimil Babka
2025-10-15 10:27       ` Harry Yoo
2025-10-15 10:37         ` Vlastimil Babka
2025-10-15 11:22           ` Hao Ge
2025-10-15 11:40             ` Harry Yoo
2025-10-14 21:13 ` Roman Gushchin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox