linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/memblock: skip kmemleak for kasan_init()
@ 2018-11-28 17:40 Qian Cai
  2018-11-28 18:18 ` Catalin Marinas
  0 siblings, 1 reply; 2+ messages in thread
From: Qian Cai @ 2018-11-28 17:40 UTC (permalink / raw)
  To: akpm
  Cc: catalin.marinas, mhocko, rppt, aryabinin, glider, dvyukov,
	kasan-dev, linux-mm, linux-kernel, Qian Cai

Kmemleak does not play well with KASAN (tested on both HPE Apollo 70 and
Huawei TaiShan 2280 aarch64 servers).

After calling start_kernel()->setup_arch()->kasan_init(), kmemleak early
log buffer went from something like 280 to 260000 which caused kmemleak
disabled and crash dump memory reservation failed. The multitude of
kmemleak_alloc() calls is from,

for_each_memblock(memory, reg) x \
while (pgdp++, addr = next, addr != end) x \
while (pudp++, addr = next, addr != end && pud_none(READ_ONCE(*pudp))) \
while (pmdp++, addr = next, addr != end && pmd_none(READ_ONCE(*pmdp))) \
while (ptep++, addr = next, addr != end && pte_none(READ_ONCE(*ptep)))

Signed-off-by: Qian Cai <cai@gmx.us>
---
 mm/memblock.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/memblock.c b/mm/memblock.c
index 9a2d5ae..fd78e39 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1412,6 +1412,8 @@ static void * __init memblock_alloc_internal(
 done:
 	ptr = phys_to_virt(alloc);
 
+/* Skip kmemleak for kasan_init() due to high volume. */
+#ifndef CONFIG_KASAN
 	/*
 	 * The min_count is set to 0 so that bootmem allocated blocks
 	 * are never reported as leaks. This is because many of these blocks
@@ -1419,6 +1421,7 @@ static void * __init memblock_alloc_internal(
 	 * looked up by kmemleak.
 	 */
 	kmemleak_alloc(ptr, size, 0, 0);
+#endif
 
 	return ptr;
 }
-- 
1.8.3.1


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

* Re: [PATCH] mm/memblock: skip kmemleak for kasan_init()
  2018-11-28 17:40 [PATCH] mm/memblock: skip kmemleak for kasan_init() Qian Cai
@ 2018-11-28 18:18 ` Catalin Marinas
  0 siblings, 0 replies; 2+ messages in thread
From: Catalin Marinas @ 2018-11-28 18:18 UTC (permalink / raw)
  To: Qian Cai
  Cc: akpm, mhocko, rppt, aryabinin, glider, dvyukov, kasan-dev,
	linux-mm, linux-kernel

On Wed, Nov 28, 2018 at 12:40:33PM -0500, Qian Cai wrote:
> Kmemleak does not play well with KASAN (tested on both HPE Apollo 70 and
> Huawei TaiShan 2280 aarch64 servers).
> 
> After calling start_kernel()->setup_arch()->kasan_init(), kmemleak early
> log buffer went from something like 280 to 260000 which caused kmemleak
> disabled and crash dump memory reservation failed. The multitude of
> kmemleak_alloc() calls is from,
> 
> for_each_memblock(memory, reg) x \
> while (pgdp++, addr = next, addr != end) x \
> while (pudp++, addr = next, addr != end && pud_none(READ_ONCE(*pudp))) \
> while (pmdp++, addr = next, addr != end && pmd_none(READ_ONCE(*pmdp))) \
> while (ptep++, addr = next, addr != end && pte_none(READ_ONCE(*ptep)))
> 
> Signed-off-by: Qian Cai <cai@gmx.us>

Sorry, I didn't get the chance to investigate this further. Hopefully
early next week.

> diff --git a/mm/memblock.c b/mm/memblock.c
> index 9a2d5ae..fd78e39 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -1412,6 +1412,8 @@ static void * __init memblock_alloc_internal(
>  done:
>  	ptr = phys_to_virt(alloc);
>  
> +/* Skip kmemleak for kasan_init() due to high volume. */
> +#ifndef CONFIG_KASAN
>  	/*
>  	 * The min_count is set to 0 so that bootmem allocated blocks
>  	 * are never reported as leaks. This is because many of these blocks
> @@ -1419,6 +1421,7 @@ static void * __init memblock_alloc_internal(
>  	 * looked up by kmemleak.
>  	 */
>  	kmemleak_alloc(ptr, size, 0, 0);
> +#endif

This may render kmemleak unusable since it is not aware of the memblock
allocations and it would trigger lots of false positives.

-- 
Catalin

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

end of thread, other threads:[~2018-11-28 18:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-28 17:40 [PATCH] mm/memblock: skip kmemleak for kasan_init() Qian Cai
2018-11-28 18:18 ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).