diff mbox series

mm: kmemleak: slob: respect SLAB_NOLEAKTRACE flag

Message ID 20211115020850.3154366-1-rkovhaev@gmail.com (mailing list archive)
State New
Headers show
Series mm: kmemleak: slob: respect SLAB_NOLEAKTRACE flag | expand

Commit Message

Rustam Kovhaev Nov. 15, 2021, 2:08 a.m. UTC
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")
Signed-off-by: Rustam Kovhaev <rkovhaev@gmail.com>
---
 mm/slab.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Vlastimil Babka Nov. 15, 2021, 11 p.m. UTC | #1
On 11/15/21 03:08, Rustam Kovhaev wrote:
> 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")
> Signed-off-by: Rustam Kovhaev <rkovhaev@gmail.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  mm/slab.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/slab.h b/mm/slab.h
> index 58c01a34e5b8..56ad7eea3ddf 100644
> --- a/mm/slab.h
> +++ b/mm/slab.h
> @@ -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 */
>
Muchun Song Nov. 16, 2021, 2:54 a.m. UTC | #2
On Mon, Nov 15, 2021 at 10:09 AM Rustam Kovhaev <rkovhaev@gmail.com> wrote:
>
> 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")
> Signed-off-by: Rustam Kovhaev <rkovhaev@gmail.com>

Reviewed-by: Muchun Song <songmuchun@bytedance.com>

Thanks.
diff mbox series

Patch

diff --git a/mm/slab.h b/mm/slab.h
index 58c01a34e5b8..56ad7eea3ddf 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -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 */