diff mbox series

mm: use stack_depot_early_init for kmemleak

Message ID 1673935169-30019-1-git-send-email-zhaoyang.huang@unisoc.com (mailing list archive)
State New
Headers show
Series mm: use stack_depot_early_init for kmemleak | expand

Commit Message

zhaoyang.huang Jan. 17, 2023, 5:59 a.m. UTC
From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

Mirsad report bellow error which caused by stack_depot_init failed in kvcalloc.
Solve this by having stackdepot use stack_depot_early_init.

On 1/4/23 17:08, Mirsad Goran Todorovac wrote:
I hate to bring bad news again, but there seems to be a problem with the output of /sys/kernel/debug/kmemleak:

[root@pc-mtodorov ~]# cat /sys/kernel/debug/kmemleak
unreferenced object 0xffff951c118568b0 (size 16):
comm "kworker/u12:2", pid 56, jiffies 4294893952 (age 4356.548s)
    hex dump (first 16 bytes):
      6d 65 6d 73 74 69 63 6b 30 00 00 00 00 00 00 00 memstick0.......
    backtrace:
 [root@pc-mtodorov ~]#
   Apparently, backtrace of called functions on the stack is no longer printed with the list of memory leaks.
 This appeared on Lenovo desktop 10TX000VCR, with AlmaLinux 8.7 and BIOS version M22KT49A (11/10/2022)
 and 6.2-rc1 and 6.2-rc2 builds.
 This worked on 6.1 with the same CONFIG_KMEMLEAK=y and MGLRU enabled on a vanilla mainstream kernel
 from Mr. Torvalds' tree. I don't know if this is deliberate feature for some reason or a bug.
 Please find attached the config, lshw and kmemleak output.

reported-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
 lib/Kconfig.debug | 1 +
 1 file changed, 1 insertion(+)

Comments

Vlastimil Babka Jan. 17, 2023, 7:28 a.m. UTC | #1
On 1/17/23 06:59, zhaoyang.huang wrote:
> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> 
> Mirsad report bellow error which caused by stack_depot_init failed in kvcalloc.
> Solve this by having stackdepot use stack_depot_early_init.

This is not ideal because kmemleak can be configured so that it's only
enabled on boot with kmemleak=on and not always.
Please look into stack_depot_want_early_init() as suggested:
https://lore.kernel.org/all/f53653bd-aab1-637e-c034-62761f262a03@suse.cz/

> On 1/4/23 17:08, Mirsad Goran Todorovac wrote:
> I hate to bring bad news again, but there seems to be a problem with the output of /sys/kernel/debug/kmemleak:
> 
> [root@pc-mtodorov ~]# cat /sys/kernel/debug/kmemleak
> unreferenced object 0xffff951c118568b0 (size 16):
> comm "kworker/u12:2", pid 56, jiffies 4294893952 (age 4356.548s)
>     hex dump (first 16 bytes):
>       6d 65 6d 73 74 69 63 6b 30 00 00 00 00 00 00 00 memstick0.......
>     backtrace:
>  [root@pc-mtodorov ~]#
>    Apparently, backtrace of called functions on the stack is no longer printed with the list of memory leaks.
>  This appeared on Lenovo desktop 10TX000VCR, with AlmaLinux 8.7 and BIOS version M22KT49A (11/10/2022)
>  and 6.2-rc1 and 6.2-rc2 builds.
>  This worked on 6.1 with the same CONFIG_KMEMLEAK=y and MGLRU enabled on a vanilla mainstream kernel
>  from Mr. Torvalds' tree. I don't know if this is deliberate feature for some reason or a bug.
>  Please find attached the config, lshw and kmemleak output.
> 
> reported-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
> Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> ---
>  lib/Kconfig.debug | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 401ad4b..50cc9f5 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -727,6 +727,7 @@ config DEBUG_KMEMLEAK
>  	select KALLSYMS
>  	select CRC32
>  	select STACKDEPOT
> +	select STACKDEPOT_ALWAYS_INIT
>  	help
>  	  Say Y here if you want to enable the memory leak
>  	  detector. The memory allocation/freeing is traced in a way
diff mbox series

Patch

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 401ad4b..50cc9f5 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -727,6 +727,7 @@  config DEBUG_KMEMLEAK
 	select KALLSYMS
 	select CRC32
 	select STACKDEPOT
+	select STACKDEPOT_ALWAYS_INIT
 	help
 	  Say Y here if you want to enable the memory leak
 	  detector. The memory allocation/freeing is traced in a way