linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] slab: Add allow_spin check to eliminate kmemleak warnings
@ 2025-09-30  6:38 ranxiaokai627
  2025-09-30  8:42 ` Harry Yoo
  2025-10-03  7:51 ` Vlastimil Babka
  0 siblings, 2 replies; 4+ messages in thread
From: ranxiaokai627 @ 2025-09-30  6:38 UTC (permalink / raw)
  To: vbabka, akpm, cl, rientjes, roman.gushchin, harry.yoo, ast
  Cc: linux-kernel, linux-mm, ran.xiaokai, ranxiaokai627

From: Ran Xiaokai <ran.xiaokai@zte.com.cn>

In slab_post_alloc_hook(), kmemleak check is skipped when
gfpflags_allow_spinning() returns false since commit 13d872ade8be
("slab: Introduce kmalloc_nolock() and kfree_nolock().").
Therefore, unconditionally calling kmemleak_not_leak() in
alloc_slab_obj_exts() would trigger the following warning:

kmemleak: Trying to color unknown object at 0xffff8881057f5000 as Grey
Call Trace:
 alloc_slab_obj_exts+0x1b5/0x370
 __alloc_tagging_slab_alloc_hook+0x9f/0x2d0
 __kmalloc_cache_noprof+0x1c4/0x5c0
 __set_page_owner+0x10d/0x1c0
 post_alloc_hook+0x84/0xf0
 get_page_from_freelist+0x73b/0x1380
 __alloc_frozen_pages_noprof+0x110/0x2c0
 alloc_pages_mpol+0x44/0x140
 alloc_slab_page+0xac/0x150
 allocate_slab+0x78/0x3a0
 ___slab_alloc+0x76b/0xed0
 __slab_alloc.constprop.0+0x5a/0xb0

Add the allow_spin check in alloc_slab_obj_exts() to
eliminate the above warning.

Fixes: 13d872ade8be ("slab: Introduce kmalloc_nolock() and kfree_nolock().")
Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
---
 mm/slub.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/slub.c b/mm/slub.c
index 09cbe580842c..a76275f4870a 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2145,7 +2145,8 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
 		return 0;
 	}
 
-	kmemleak_not_leak(vec);
+	if (allow_spin)
+		kmemleak_not_leak(vec);
 	return 0;
 }
 
-- 
2.25.1



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

* Re: [PATCH] slab: Add allow_spin check to eliminate kmemleak warnings
  2025-09-30  6:38 [PATCH] slab: Add allow_spin check to eliminate kmemleak warnings ranxiaokai627
@ 2025-09-30  8:42 ` Harry Yoo
  2025-09-30 11:04   ` Alexei Starovoitov
  2025-10-03  7:51 ` Vlastimil Babka
  1 sibling, 1 reply; 4+ messages in thread
From: Harry Yoo @ 2025-09-30  8:42 UTC (permalink / raw)
  To: ranxiaokai627
  Cc: vbabka, akpm, cl, rientjes, roman.gushchin, ast, linux-kernel,
	linux-mm, ran.xiaokai

On Tue, Sep 30, 2025 at 06:38:31AM +0000, ranxiaokai627@163.com wrote:
> From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> 
> In slab_post_alloc_hook(), kmemleak check is skipped when
> gfpflags_allow_spinning() returns false since commit 13d872ade8be
> ("slab: Introduce kmalloc_nolock() and kfree_nolock().").
> Therefore, unconditionally calling kmemleak_not_leak() in
> alloc_slab_obj_exts() would trigger the following warning:

Good catch.

> kmemleak: Trying to color unknown object at 0xffff8881057f5000 as Grey
> Call Trace:
>  alloc_slab_obj_exts+0x1b5/0x370
>  __alloc_tagging_slab_alloc_hook+0x9f/0x2d0
>  __kmalloc_cache_noprof+0x1c4/0x5c0
>  __set_page_owner+0x10d/0x1c0
>  post_alloc_hook+0x84/0xf0
>  get_page_from_freelist+0x73b/0x1380
>  __alloc_frozen_pages_noprof+0x110/0x2c0
>  alloc_pages_mpol+0x44/0x140
>  alloc_slab_page+0xac/0x150
>  allocate_slab+0x78/0x3a0
>  ___slab_alloc+0x76b/0xed0
>  __slab_alloc.constprop.0+0x5a/0xb0
> 
> Add the allow_spin check in alloc_slab_obj_exts() to
> eliminate the above warning.
> 
> Fixes: 13d872ade8be ("slab: Introduce kmalloc_nolock() and kfree_nolock().")

The commit hash in the tag and commit message will be adjusted after -rc1
when picking up this patch.

> Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> ---

Looks good to me,
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>

-- 
Cheers,
Harry / Hyeonggon

>  mm/slub.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 09cbe580842c..a76275f4870a 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2145,7 +2145,8 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
>  		return 0;
>  	}
>  
> -	kmemleak_not_leak(vec);
> +	if (allow_spin)
> +		kmemleak_not_leak(vec);
>  	return 0;
>  }
>  
> -- 
> 2.25.1


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

* Re: [PATCH] slab: Add allow_spin check to eliminate kmemleak warnings
  2025-09-30  8:42 ` Harry Yoo
@ 2025-09-30 11:04   ` Alexei Starovoitov
  0 siblings, 0 replies; 4+ messages in thread
From: Alexei Starovoitov @ 2025-09-30 11:04 UTC (permalink / raw)
  To: Harry Yoo
  Cc: ranxiaokai627, Vlastimil Babka, Andrew Morton, cl,
	David Rientjes, Roman Gushchin, Alexei Starovoitov, LKML,
	linux-mm, ran.xiaokai

On Tue, Sep 30, 2025 at 10:43 AM Harry Yoo <harry.yoo@oracle.com> wrote:
>
> On Tue, Sep 30, 2025 at 06:38:31AM +0000, ranxiaokai627@163.com wrote:
> > From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> >
> > In slab_post_alloc_hook(), kmemleak check is skipped when
> > gfpflags_allow_spinning() returns false since commit 13d872ade8be
> > ("slab: Introduce kmalloc_nolock() and kfree_nolock().").
> > Therefore, unconditionally calling kmemleak_not_leak() in
> > alloc_slab_obj_exts() would trigger the following warning:
>
> Good catch.
>
> > kmemleak: Trying to color unknown object at 0xffff8881057f5000 as Grey
> > Call Trace:
> >  alloc_slab_obj_exts+0x1b5/0x370
> >  __alloc_tagging_slab_alloc_hook+0x9f/0x2d0
> >  __kmalloc_cache_noprof+0x1c4/0x5c0
> >  __set_page_owner+0x10d/0x1c0
> >  post_alloc_hook+0x84/0xf0
> >  get_page_from_freelist+0x73b/0x1380
> >  __alloc_frozen_pages_noprof+0x110/0x2c0
> >  alloc_pages_mpol+0x44/0x140
> >  alloc_slab_page+0xac/0x150
> >  allocate_slab+0x78/0x3a0
> >  ___slab_alloc+0x76b/0xed0
> >  __slab_alloc.constprop.0+0x5a/0xb0
> >
> > Add the allow_spin check in alloc_slab_obj_exts() to
> > eliminate the above warning.
> >
> > Fixes: 13d872ade8be ("slab: Introduce kmalloc_nolock() and kfree_nolock().")
>
> The commit hash in the tag and commit message will be adjusted after -rc1
> when picking up this patch.
>
> > Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> > ---
>
> Looks good to me,
> Reviewed-by: Harry Yoo <harry.yoo@oracle.com>

Makes sense to me as well:
Acked-by: Alexei Starovoitov <ast@kernel.org>


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

* Re: [PATCH] slab: Add allow_spin check to eliminate kmemleak warnings
  2025-09-30  6:38 [PATCH] slab: Add allow_spin check to eliminate kmemleak warnings ranxiaokai627
  2025-09-30  8:42 ` Harry Yoo
@ 2025-10-03  7:51 ` Vlastimil Babka
  1 sibling, 0 replies; 4+ messages in thread
From: Vlastimil Babka @ 2025-10-03  7:51 UTC (permalink / raw)
  To: ranxiaokai627, akpm, cl, rientjes, roman.gushchin, harry.yoo, ast
  Cc: linux-kernel, linux-mm, ran.xiaokai

On 9/30/25 08:38, ranxiaokai627@163.com wrote:
> From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> 
> In slab_post_alloc_hook(), kmemleak check is skipped when
> gfpflags_allow_spinning() returns false since commit 13d872ade8be
> ("slab: Introduce kmalloc_nolock() and kfree_nolock().").
> Therefore, unconditionally calling kmemleak_not_leak() in
> alloc_slab_obj_exts() would trigger the following warning:
> 
> kmemleak: Trying to color unknown object at 0xffff8881057f5000 as Grey
> Call Trace:
>  alloc_slab_obj_exts+0x1b5/0x370
>  __alloc_tagging_slab_alloc_hook+0x9f/0x2d0
>  __kmalloc_cache_noprof+0x1c4/0x5c0
>  __set_page_owner+0x10d/0x1c0
>  post_alloc_hook+0x84/0xf0
>  get_page_from_freelist+0x73b/0x1380
>  __alloc_frozen_pages_noprof+0x110/0x2c0
>  alloc_pages_mpol+0x44/0x140
>  alloc_slab_page+0xac/0x150
>  allocate_slab+0x78/0x3a0
>  ___slab_alloc+0x76b/0xed0
>  __slab_alloc.constprop.0+0x5a/0xb0
> 
> Add the allow_spin check in alloc_slab_obj_exts() to
> eliminate the above warning.
> 
> Fixes: 13d872ade8be ("slab: Introduce kmalloc_nolock() and kfree_nolock().")

Updated commit hash (also above)

> Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>

Added to slab/for-next-fixes, thanks!

> ---
>  mm/slub.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 09cbe580842c..a76275f4870a 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2145,7 +2145,8 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
>  		return 0;
>  	}
>  
> -	kmemleak_not_leak(vec);
> +	if (allow_spin)
> +		kmemleak_not_leak(vec);
>  	return 0;
>  }
>  



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

end of thread, other threads:[~2025-10-03  7:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-30  6:38 [PATCH] slab: Add allow_spin check to eliminate kmemleak warnings ranxiaokai627
2025-09-30  8:42 ` Harry Yoo
2025-09-30 11:04   ` Alexei Starovoitov
2025-10-03  7:51 ` Vlastimil Babka

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