Skip to contentSkip to conversation

fixes for slab->obj_exts allocation failure handling

PATCH In review Suren Baghdasaryan 3 participants 6 messages Sep 15, 2025 – Sep 16, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover fixes for slab->obj_exts allocation failure handling

Fixes for several issues noticed by Shakeel pertaining to slab->obj_exts allocation failure handling in [1].

Patchset is based on mm-new.

Please route it via vbabka/slab.git as it's relevant to Alexei's patches in that branch.

[1] https://lore.kernel.org/all/jftidhymri2af5u3xtcqry3cfu6aqzte3uzlznhlaylgrdztsi@5vpjnzpsemf5/

Suren Baghdasaryan (2):
slab: prevent warnings when slab obj_exts vector allocation fails
slab: mark slab->obj_exts allocation failures unconditionally

 mm/slab.h | 8 ++++++--
 mm/slub.c | 3 +--
 2 files changed, 7 insertions(+), 4 deletions(-)

base-commit: 9a9318f95d63805868bd21e1381d68c3a75d03a7

Signature · 1 line
2.51.0.384.g4c02a37b29-goog
#1 lore raw

PATCH 1/2 slab: prevent warnings when slab obj_exts vector allocation fails

When object extension vector allocation fails, we set slab->obj_exts to OBJEXTS_ALLOC_FAIL to indicate the failure. Later, once the vector is successfully allocated, we will use this flag to mark codetag references stored in that vector as empty to avoid codetag warnings.

slab_obj_exts() used to retrieve the slab->obj_exts vector pointer checks slab->obj_exts for being either NULL or a pointer with MEMCG_DATA_OBJEXTS bit set. However it does not handle the case when slab->obj_exts equals OBJEXTS_ALLOC_FAIL. Add the missing condition to avoid extra warning.

Fixes 09c46563ff6d ("codetag: debug: introduce OBJEXTS_ALLOC_FAIL to mark failed slab_ext allocations")
Cc [email protected] # v6.10+
---
 mm/slab.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/slab.h +6 -2
index c41a512dd07c..b930193fd94e 100644
@@ -526,8 +526,12 @@ static inline struct slabobj_ext *slab_obj_exts(struct slab *slab)
 	unsigned long obj_exts = READ_ONCE(slab->obj_exts);
 
 #ifdef CONFIG_MEMCG
-	VM_BUG_ON_PAGE(obj_exts && !(obj_exts & MEMCG_DATA_OBJEXTS),
-							slab_page(slab));
+	/*
+	 * obj_exts should be either NULL, a valid pointer with
+	 * MEMCG_DATA_OBJEXTS bit set or be equal to OBJEXTS_ALLOC_FAIL.
+	 */
+	VM_BUG_ON_PAGE(obj_exts && !(obj_exts & MEMCG_DATA_OBJEXTS) &&
+		       obj_exts != OBJEXTS_ALLOC_FAIL, slab_page(slab));
 	VM_BUG_ON_PAGE(obj_exts & MEMCG_DATA_KMEM, slab_page(slab));
 #endif
 	return (struct slabobj_ext *)(obj_exts & ~OBJEXTS_FLAGS_MASK);
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] slab: prevent warnings when slab obj_exts vector allocation fails

Quoted 10 lines · Suren Baghdasaryan

When object extension vector allocation fails, we set slab->obj_exts to OBJEXTS_ALLOC_FAIL to indicate the failure. Later, once the vector is successfully allocated, we will use this flag to mark codetag references stored in that vector as empty to avoid codetag warnings.

slab_obj_exts() used to retrieve the slab->obj_exts vector pointer checks slab->obj_exts for being either NULL or a pointer with MEMCG_DATA_OBJEXTS bit set. However it does not handle the case when slab->obj_exts equals OBJEXTS_ALLOC_FAIL. Add the missing condition to avoid extra warning.

Quoted 5 lines
Fixes 09c46563ff6d ("codetag: debug: introduce OBJEXTS_ALLOC_FAIL to mark failed slab_ext allocations")
Cc [email protected] # v6.10+
#3 lore raw

PATCH 2/2 slab: mark slab->obj_exts allocation failures unconditionally

In reply to Suren Baghdasaryan

alloc_slab_obj_exts() should mark failed obj_exts vector allocations independent on whether the vector is being allocated for a new or an existing slab. Current implementation skips doing this for existing slabs. Fix this by marking failed allocations unconditionally.

Fixes 09c46563ff6d ("codetag: debug: introduce OBJEXTS_ALLOC_FAIL to mark failed slab_ext allocations")
Cc [email protected] # v6.10+
---
 mm/slub.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/slub.c +1 -2
index af343ca570b5..cab4e7822393 100644
@@ -2029,8 +2029,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
 			   slab_nid(slab));
 	if (!vec) {
 		/* Mark vectors which failed to allocate */
-		if (new_slab)
-			mark_failed_objexts_alloc(slab);
+		mark_failed_objexts_alloc(slab);
 
 		return -ENOMEM;
 	}
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] slab: mark slab->obj_exts allocation failures unconditionally

Quoted 10 lines · Suren Baghdasaryan

alloc_slab_obj_exts() should mark failed obj_exts vector allocations independent on whether the vector is being allocated for a new or an existing slab. Current implementation skips doing this for existing slabs. Fix this by marking failed allocations unconditionally.

Fixes 09c46563ff6d ("codetag: debug: introduce OBJEXTS_ALLOC_FAIL to mark failed slab_ext allocations")
Cc [email protected] # v6.10+
#5 lore raw
In reply to Suren Baghdasaryan
Quoted 7 lines · Suren Baghdasaryan

Fixes for several issues noticed by Shakeel pertaining to slab->obj_exts allocation failure handling in [1].

Patchset is based on mm-new.

Please route it via vbabka/slab.git as it's relevant to Alexei's patches in that branch.

Thanks, added to slab/for-6.18/fixes

Quoted 12 lines

[1] https://lore.kernel.org/all/jftidhymri2af5u3xtcqry3cfu6aqzte3uzlznhlaylgrdztsi@5vpjnzpsemf5/

Suren Baghdasaryan (2):
slab: prevent warnings when slab obj_exts vector allocation fails
slab: mark slab->obj_exts allocation failures unconditionally

 mm/slab.h | 8 ++++++--
 mm/slub.c | 3 +--
 2 files changed, 7 insertions(+), 4 deletions(-)

base-commit: 9a9318f95d63805868bd21e1381d68c3a75d03a7