Skip to contentSkip to conversation

mm: kmemleak: slob: respect SLAB_NOLEAKTRACE flag

PATCH Applied Rustam Kovhaev 3 participants 3 messages Nov 15, 2021 – Nov 16, 2021

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

PATCH 1/1 mm: kmemleak: slob: respect SLAB_NOLEAKTRACE flag

When kmemleak is enabled for SLOB, system does not boot and does not print anything to the console. At the very early stage in the boot process we hit infinite recursion from kmemleak_init() and eventually kernel crashes.
kmemleak_init() specifies SLAB_NOLEAKTRACE for KMEM_CACHE(), but kmem_cache_create_usercopy() removes it because CACHE_CREATE_MASK is not valid for SLOB.
Let's fix CACHE_CREATE_MASK and make kmemleak work with SLOB

Fixes d8843922fba4 ("slab: Ignore internal flags in cache creation")
---
 mm/slab.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slab.h +1 -1
index 58c01a34e5b8..56ad7eea3ddf 100644
@@ -147,7 +147,7 @@ static inline slab_flags_t kmem_cache_flags(unsigned int object_size,
 #define SLAB_CACHE_FLAGS (SLAB_NOLEAKTRACE | SLAB_RECLAIM_ACCOUNT | \
 			  SLAB_TEMPORARY | SLAB_ACCOUNT)
 #else
-#define SLAB_CACHE_FLAGS (0)
+#define SLAB_CACHE_FLAGS (SLAB_NOLEAKTRACE)
 #endif
 
 /* Common flags available with current configuration */
Signature · 1 line
2.30.2
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Rustam Kovhaev

When kmemleak is enabled for SLOB, system does not boot and does not print anything to the console. At the very early stage in the boot process we hit infinite recursion from kmemleak_init() and eventually kernel crashes.
kmemleak_init() specifies SLAB_NOLEAKTRACE for KMEM_CACHE(), but kmem_cache_create_usercopy() removes it because CACHE_CREATE_MASK is not valid for SLOB.
Let's fix CACHE_CREATE_MASK and make kmemleak work with SLOB

Fixes d8843922fba4 ("slab: Ignore internal flags in cache creation")
Quoted 18 lines
---
 mm/slab.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slab.h +1 -1
index 58c01a34e5b8..56ad7eea3ddf 100644
@@ -147,7 +147,7 @@ static inline slab_flags_t kmem_cache_flags(unsigned int object_size,
 #define SLAB_CACHE_FLAGS (SLAB_NOLEAKTRACE | SLAB_RECLAIM_ACCOUNT | \
 			  SLAB_TEMPORARY | SLAB_ACCOUNT)
 #else
-#define SLAB_CACHE_FLAGS (0)
+#define SLAB_CACHE_FLAGS (SLAB_NOLEAKTRACE)
 #endif
 
 /* Common flags available with current configuration */
Reviewed-by on v1 1/1
#2 lore raw
In reply to Rustam Kovhaev
Quoted 10 lines · Rustam Kovhaev

When kmemleak is enabled for SLOB, system does not boot and does not print anything to the console. At the very early stage in the boot process we hit infinite recursion from kmemleak_init() and eventually kernel crashes.
kmemleak_init() specifies SLAB_NOLEAKTRACE for KMEM_CACHE(), but kmem_cache_create_usercopy() removes it because CACHE_CREATE_MASK is not valid for SLOB.
Let's fix CACHE_CREATE_MASK and make kmemleak work with SLOB

Quoted 2 lines
Fixes d8843922fba4 ("slab: Ignore internal flags in cache creation")

Thanks.