All of lore.kernel.org
 help / color / mirror / Atom feed
* + mm-use-stack_depot_early_init-for-kmemleak.patch added to mm-hotfixes-unstable branch
@ 2023-01-18  0:19 Andrew Morton
  2023-01-19 13:02 ` Mirsad Goran Todorovac
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2023-01-18  0:19 UTC (permalink / raw)
  To: mm-commits, vbabka, peterz, nathan, mirsad.todorovac, ke.wang,
	huangzhaoyang, catalin.marinas, zhaoyang.huang, akpm


The patch titled
     Subject: mm: use stack_depot_early_init for kmemleak
has been added to the -mm mm-hotfixes-unstable branch.  Its filename is
     mm-use-stack_depot_early_init-for-kmemleak.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-use-stack_depot_early_init-for-kmemleak.patch

This patch will later appear in the mm-hotfixes-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days

------------------------------------------------------
From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
Subject: mm: use stack_depot_early_init for kmemleak
Date: Tue, 17 Jan 2023 16:11:52 +0800

Mirsad report bellow error which caused by stack_depot_init failed in
kvcalloc.  Solve this by having stackdepot use stack_depot_early_init. 
Extra Kconfig also done by moving kmemleak stuff to mm/Kconfig.debug.

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.

Link: https://lkml.kernel.org/r/1673943112-8620-1-git-send-email-zhaoyang.huang@unisoc.com
Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
Reported-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
Suggested-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: ke.wang <ke.wang@unisoc.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zhaoyang Huang <huangzhaoyang@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---


--- a/lib/Kconfig.debug~mm-use-stack_depot_early_init-for-kmemleak
+++ a/lib/Kconfig.debug
@@ -743,76 +743,6 @@ config SHRINKER_DEBUG
 	  visibility into the kernel memory shrinkers subsystem.
 	  Disable it to avoid an extra memory footprint.
 
-config HAVE_DEBUG_KMEMLEAK
-	bool
-
-config DEBUG_KMEMLEAK
-	bool "Kernel memory leak detector"
-	depends on DEBUG_KERNEL && HAVE_DEBUG_KMEMLEAK
-	select DEBUG_FS
-	select STACKTRACE if STACKTRACE_SUPPORT
-	select KALLSYMS
-	select CRC32
-	select STACKDEPOT
-	help
-	  Say Y here if you want to enable the memory leak
-	  detector. The memory allocation/freeing is traced in a way
-	  similar to the Boehm's conservative garbage collector, the
-	  difference being that the orphan objects are not freed but
-	  only shown in /sys/kernel/debug/kmemleak. Enabling this
-	  feature will introduce an overhead to memory
-	  allocations. See Documentation/dev-tools/kmemleak.rst for more
-	  details.
-
-	  Enabling DEBUG_SLAB or SLUB_DEBUG may increase the chances
-	  of finding leaks due to the slab objects poisoning.
-
-	  In order to access the kmemleak file, debugfs needs to be
-	  mounted (usually at /sys/kernel/debug).
-
-config DEBUG_KMEMLEAK_MEM_POOL_SIZE
-	int "Kmemleak memory pool size"
-	depends on DEBUG_KMEMLEAK
-	range 200 1000000
-	default 16000
-	help
-	  Kmemleak must track all the memory allocations to avoid
-	  reporting false positives. Since memory may be allocated or
-	  freed before kmemleak is fully initialised, use a static pool
-	  of metadata objects to track such callbacks. After kmemleak is
-	  fully initialised, this memory pool acts as an emergency one
-	  if slab allocations fail.
-
-config DEBUG_KMEMLEAK_TEST
-	tristate "Simple test for the kernel memory leak detector"
-	depends on DEBUG_KMEMLEAK && m
-	help
-	  This option enables a module that explicitly leaks memory.
-
-	  If unsure, say N.
-
-config DEBUG_KMEMLEAK_DEFAULT_OFF
-	bool "Default kmemleak to off"
-	depends on DEBUG_KMEMLEAK
-	help
-	  Say Y here to disable kmemleak by default. It can then be enabled
-	  on the command line via kmemleak=on.
-
-config DEBUG_KMEMLEAK_AUTO_SCAN
-	bool "Enable kmemleak auto scan thread on boot up"
-	default y
-	depends on DEBUG_KMEMLEAK
-	help
-	  Depending on the cpu, kmemleak scan may be cpu intensive and can
-	  stall user tasks at times. This option enables/disables automatic
-	  kmemleak scan at boot up.
-
-	  Say N here to disable kmemleak auto scan thread to stop automatic
-	  scanning. Disabling this option disables automatic reporting of
-	  memory leaks.
-
-	  If unsure, say Y.
-
 config DEBUG_STACK_USAGE
 	bool "Stack utilization instrumentation"
 	depends on DEBUG_KERNEL && !IA64
--- a/mm/Kconfig.debug~mm-use-stack_depot_early_init-for-kmemleak
+++ a/mm/Kconfig.debug
@@ -207,3 +207,73 @@ config PTDUMP_DEBUGFS
 	  kernel.
 
 	  If in doubt, say N.
+
+config HAVE_DEBUG_KMEMLEAK
+	bool
+
+config DEBUG_KMEMLEAK
+	bool "Kernel memory leak detector"
+	depends on DEBUG_KERNEL && HAVE_DEBUG_KMEMLEAK
+	select DEBUG_FS
+	select STACKTRACE if STACKTRACE_SUPPORT
+	select KALLSYMS
+	select CRC32
+	select STACKDEPOT
+	help
+	  Say Y here if you want to enable the memory leak
+	  detector. The memory allocation/freeing is traced in a way
+	  similar to the Boehm's conservative garbage collector, the
+	  difference being that the orphan objects are not freed but
+	  only shown in /sys/kernel/debug/kmemleak. Enabling this
+	  feature will introduce an overhead to memory
+	  allocations. See Documentation/dev-tools/kmemleak.rst for more
+	  details.
+
+	  Enabling DEBUG_SLAB or SLUB_DEBUG may increase the chances
+	  of finding leaks due to the slab objects poisoning.
+
+	  In order to access the kmemleak file, debugfs needs to be
+	  mounted (usually at /sys/kernel/debug).
+
+config DEBUG_KMEMLEAK_MEM_POOL_SIZE
+	int "Kmemleak memory pool size"
+	depends on DEBUG_KMEMLEAK
+	range 200 1000000
+	default 16000
+	help
+	  Kmemleak must track all the memory allocations to avoid
+	  reporting false positives. Since memory may be allocated or
+	  freed before kmemleak is fully initialised, use a static pool
+	  of metadata objects to track such callbacks. After kmemleak is
+	  fully initialised, this memory pool acts as an emergency one
+	  if slab allocations fail.
+
+config DEBUG_KMEMLEAK_TEST
+	tristate "Simple test for the kernel memory leak detector"
+	depends on DEBUG_KMEMLEAK && m
+	help
+	  This option enables a module that explicitly leaks memory.
+
+	  If unsure, say N.
+
+config DEBUG_KMEMLEAK_DEFAULT_OFF
+	bool "Default kmemleak to off"
+	depends on DEBUG_KMEMLEAK
+	help
+	  Say Y here to disable kmemleak by default. It can then be enabled
+	  on the command line via kmemleak=on.
+
+config DEBUG_KMEMLEAK_AUTO_SCAN
+	bool "Enable kmemleak auto scan thread on boot up"
+	default y
+	depends on DEBUG_KMEMLEAK
+	help
+	  Depending on the cpu, kmemleak scan may be cpu intensive and can
+	  stall user tasks at times. This option enables/disables automatic
+	  kmemleak scan at boot up.
+
+	  Say N here to disable kmemleak auto scan thread to stop automatic
+	  scanning. Disabling this option disables automatic reporting of
+	  memory leaks.
+
+	  If unsure, say Y.
--- a/mm/kmemleak.c~mm-use-stack_depot_early_init-for-kmemleak
+++ a/mm/kmemleak.c
@@ -2070,8 +2070,10 @@ static int __init kmemleak_boot_config(c
 		return -EINVAL;
 	if (strcmp(str, "off") == 0)
 		kmemleak_disable();
-	else if (strcmp(str, "on") == 0)
+	else if (strcmp(str, "on") == 0) {
 		kmemleak_skip_disable = 1;
+		stack_depot_want_early_init();
+	}
 	else
 		return -EINVAL;
 	return 0;
_

Patches currently in -mm which might be from zhaoyang.huang@unisoc.com are

mm-use-stack_depot_early_init-for-kmemleak.patch


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

* Re: + mm-use-stack_depot_early_init-for-kmemleak.patch added to mm-hotfixes-unstable branch
  2023-01-18  0:19 + mm-use-stack_depot_early_init-for-kmemleak.patch added to mm-hotfixes-unstable branch Andrew Morton
@ 2023-01-19 13:02 ` Mirsad Goran Todorovac
  2023-01-19 14:40   ` Catalin Marinas
  0 siblings, 1 reply; 6+ messages in thread
From: Mirsad Goran Todorovac @ 2023-01-19 13:02 UTC (permalink / raw)
  To: Andrew Morton, mm-commits, vbabka, peterz, nathan, ke.wang,
	huangzhaoyang, catalin.marinas, zhaoyang.huang

Hi,

On 18.1.2023. 1:19, Andrew Morton wrote:
> The patch titled
>       Subject: mm: use stack_depot_early_init for kmemleak
> has been added to the -mm mm-hotfixes-unstable branch.  Its filename is
>       mm-use-stack_depot_early_init-for-kmemleak.patch
> 
> This patch will shortly appear at
>       https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-use-stack_depot_early_init-for-kmemleak.patch
> 
> This patch will later appear in the mm-hotfixes-unstable branch at
>      git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> 
> Before you just go and hit "reply", please:
>     a) Consider who else should be cc'ed
>     b) Prefer to cc a suitable mailing list as well
>     c) Ideally: find the original patch on the mailing list and do a
>        reply-to-all to that, adding suitable additional cc's
> 
> *** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
> 
> The -mm tree is included into linux-next via the mm-everything
> branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> and is updated there every 2-3 working days
> 
> ------------------------------------------------------
> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> Subject: mm: use stack_depot_early_init for kmemleak
> Date: Tue, 17 Jan 2023 16:11:52 +0800
> 
> Mirsad report bellow error which caused by stack_depot_init failed in
> kvcalloc.  Solve this by having stackdepot use stack_depot_early_init.
> Extra Kconfig also done by moving kmemleak stuff to mm/Kconfig.debug.
> 
> 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.
> 
> Link: https://lkml.kernel.org/r/1673943112-8620-1-git-send-email-zhaoyang.huang@unisoc.com
> Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> Reported-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
> Suggested-by: Vlastimil Babka <vbabka@suse.cz>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: ke.wang <ke.wang@unisoc.com>
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Zhaoyang Huang <huangzhaoyang@gmail.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
> 
> 
> --- a/lib/Kconfig.debug~mm-use-stack_depot_early_init-for-kmemleak
> +++ a/lib/Kconfig.debug
> @@ -743,76 +743,6 @@ config SHRINKER_DEBUG
>   	  visibility into the kernel memory shrinkers subsystem.
>   	  Disable it to avoid an extra memory footprint.
>   
> -config HAVE_DEBUG_KMEMLEAK
> -	bool
> -
> -config DEBUG_KMEMLEAK
> -	bool "Kernel memory leak detector"
> -	depends on DEBUG_KERNEL && HAVE_DEBUG_KMEMLEAK
> -	select DEBUG_FS
> -	select STACKTRACE if STACKTRACE_SUPPORT
> -	select KALLSYMS
> -	select CRC32
> -	select STACKDEPOT
> -	help
> -	  Say Y here if you want to enable the memory leak
> -	  detector. The memory allocation/freeing is traced in a way
> -	  similar to the Boehm's conservative garbage collector, the
> -	  difference being that the orphan objects are not freed but
> -	  only shown in /sys/kernel/debug/kmemleak. Enabling this
> -	  feature will introduce an overhead to memory
> -	  allocations. See Documentation/dev-tools/kmemleak.rst for more
> -	  details.
> -
> -	  Enabling DEBUG_SLAB or SLUB_DEBUG may increase the chances
> -	  of finding leaks due to the slab objects poisoning.
> -
> -	  In order to access the kmemleak file, debugfs needs to be
> -	  mounted (usually at /sys/kernel/debug).
> -
> -config DEBUG_KMEMLEAK_MEM_POOL_SIZE
> -	int "Kmemleak memory pool size"
> -	depends on DEBUG_KMEMLEAK
> -	range 200 1000000
> -	default 16000
> -	help
> -	  Kmemleak must track all the memory allocations to avoid
> -	  reporting false positives. Since memory may be allocated or
> -	  freed before kmemleak is fully initialised, use a static pool
> -	  of metadata objects to track such callbacks. After kmemleak is
> -	  fully initialised, this memory pool acts as an emergency one
> -	  if slab allocations fail.
> -
> -config DEBUG_KMEMLEAK_TEST
> -	tristate "Simple test for the kernel memory leak detector"
> -	depends on DEBUG_KMEMLEAK && m
> -	help
> -	  This option enables a module that explicitly leaks memory.
> -
> -	  If unsure, say N.
> -
> -config DEBUG_KMEMLEAK_DEFAULT_OFF
> -	bool "Default kmemleak to off"
> -	depends on DEBUG_KMEMLEAK
> -	help
> -	  Say Y here to disable kmemleak by default. It can then be enabled
> -	  on the command line via kmemleak=on.
> -
> -config DEBUG_KMEMLEAK_AUTO_SCAN
> -	bool "Enable kmemleak auto scan thread on boot up"
> -	default y
> -	depends on DEBUG_KMEMLEAK
> -	help
> -	  Depending on the cpu, kmemleak scan may be cpu intensive and can
> -	  stall user tasks at times. This option enables/disables automatic
> -	  kmemleak scan at boot up.
> -
> -	  Say N here to disable kmemleak auto scan thread to stop automatic
> -	  scanning. Disabling this option disables automatic reporting of
> -	  memory leaks.
> -
> -	  If unsure, say Y.
> -
>   config DEBUG_STACK_USAGE
>   	bool "Stack utilization instrumentation"
>   	depends on DEBUG_KERNEL && !IA64
> --- a/mm/Kconfig.debug~mm-use-stack_depot_early_init-for-kmemleak
> +++ a/mm/Kconfig.debug
> @@ -207,3 +207,73 @@ config PTDUMP_DEBUGFS
>   	  kernel.
>   
>   	  If in doubt, say N.
> +
> +config HAVE_DEBUG_KMEMLEAK
> +	bool
> +
> +config DEBUG_KMEMLEAK
> +	bool "Kernel memory leak detector"
> +	depends on DEBUG_KERNEL && HAVE_DEBUG_KMEMLEAK
> +	select DEBUG_FS
> +	select STACKTRACE if STACKTRACE_SUPPORT
> +	select KALLSYMS
> +	select CRC32
> +	select STACKDEPOT
> +	help
> +	  Say Y here if you want to enable the memory leak
> +	  detector. The memory allocation/freeing is traced in a way
> +	  similar to the Boehm's conservative garbage collector, the
> +	  difference being that the orphan objects are not freed but
> +	  only shown in /sys/kernel/debug/kmemleak. Enabling this
> +	  feature will introduce an overhead to memory
> +	  allocations. See Documentation/dev-tools/kmemleak.rst for more
> +	  details.
> +
> +	  Enabling DEBUG_SLAB or SLUB_DEBUG may increase the chances
> +	  of finding leaks due to the slab objects poisoning.
> +
> +	  In order to access the kmemleak file, debugfs needs to be
> +	  mounted (usually at /sys/kernel/debug).
> +
> +config DEBUG_KMEMLEAK_MEM_POOL_SIZE
> +	int "Kmemleak memory pool size"
> +	depends on DEBUG_KMEMLEAK
> +	range 200 1000000
> +	default 16000
> +	help
> +	  Kmemleak must track all the memory allocations to avoid
> +	  reporting false positives. Since memory may be allocated or
> +	  freed before kmemleak is fully initialised, use a static pool
> +	  of metadata objects to track such callbacks. After kmemleak is
> +	  fully initialised, this memory pool acts as an emergency one
> +	  if slab allocations fail.
> +
> +config DEBUG_KMEMLEAK_TEST
> +	tristate "Simple test for the kernel memory leak detector"
> +	depends on DEBUG_KMEMLEAK && m
> +	help
> +	  This option enables a module that explicitly leaks memory.
> +
> +	  If unsure, say N.
> +
> +config DEBUG_KMEMLEAK_DEFAULT_OFF
> +	bool "Default kmemleak to off"
> +	depends on DEBUG_KMEMLEAK
> +	help
> +	  Say Y here to disable kmemleak by default. It can then be enabled
> +	  on the command line via kmemleak=on.
> +
> +config DEBUG_KMEMLEAK_AUTO_SCAN
> +	bool "Enable kmemleak auto scan thread on boot up"
> +	default y
> +	depends on DEBUG_KMEMLEAK
> +	help
> +	  Depending on the cpu, kmemleak scan may be cpu intensive and can
> +	  stall user tasks at times. This option enables/disables automatic
> +	  kmemleak scan at boot up.
> +
> +	  Say N here to disable kmemleak auto scan thread to stop automatic
> +	  scanning. Disabling this option disables automatic reporting of
> +	  memory leaks.
> +
> +	  If unsure, say Y.
> --- a/mm/kmemleak.c~mm-use-stack_depot_early_init-for-kmemleak
> +++ a/mm/kmemleak.c
> @@ -2070,8 +2070,10 @@ static int __init kmemleak_boot_config(c
>   		return -EINVAL;
>   	if (strcmp(str, "off") == 0)
>   		kmemleak_disable();
> -	else if (strcmp(str, "on") == 0)
> +	else if (strcmp(str, "on") == 0) {
>   		kmemleak_skip_disable = 1;
> +		stack_depot_want_early_init();
> +	}
>   	else
>   		return -EINVAL;
>   	return 0;
> _
> 
> Patches currently in -mm which might be from zhaoyang.huang@unisoc.com are
> 
> mm-use-stack_depot_early_init-for-kmemleak.patch

Dear Sir,

Please note that this patch activates stack_depot_want_early_init() only when
kernel boot param "kmemleak=on" is used.

When the following configuration is used:

CONFIG_HAVE_DEBUG_KMEMLEAK=y
CONFIG_DEBUG_KMEMLEAK=y
CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE=16000
# CONFIG_DEBUG_KMEMLEAK_TEST is not set
# CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set
CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y

... and there is no kmemleak boot param, then the stack_depot_want_early_init()
is not being called and Stack Depot tries initialisation with kvalloc() in
stack_depot_init(), which failed in the initial bug report.

So IMHO this patch defeats the purpose of having CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF
unset and gives a severed stack backtrace because Stack Depot is not allocated,
triggering a bug in vmalloc(), which from Googling might be because of requesting
8.4 MB too early, but I am not an expert on mm.

Here is the dmesg output with this patch on and kmemleak=on not set.

If I understood well, kmemleak_boot_config() is called only when kmemleak=on|off
boot param is present, and otherwise stack_depot_want_early_init() is not being
called.

Nothing else touched the __stack_depot_want_early_init variable, judging from
grep of the source:

static bool __stack_depot_want_early_init __initdata = IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT);

Dmesg output:

[    0.034444] software IO TLB: area num 8.
[    0.072098] Memory: 16152084K/16658536K available (18432K kernel code, 4118K rwdata, 7184K rodata, 4424K init, 7680K bss, 506192K 
reserved, 0K cma-reserved)
[    0.072287] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=6, Nodes=1
[    0.072290] Stack Depot allocating hash table of 1048576 entries with kvcalloc
[    0.072294] swapper: vmalloc error: size 8388608, vm_struct allocation failed, mode:0xdc0(GFP_KERNEL|__GFP_ZERO), 
nodemask=(null),cpuset=(null),mems_allowed=0-1023
[    0.072303] CPU: 0 PID: 0 Comm: swapper Not tainted 6.2.0-rc4-mglru-kmemlk-patch-zhaoyang4+ #1
[    0.072306] Hardware name: LENOVO 10TX000VCR/3140, BIOS M22KT49A 11/10/2022
[    0.072307] Call Trace:
[    0.072308]  <TASK>
[    0.072311]  dump_stack_lvl+0x49/0x63
[    0.072316]  dump_stack+0x10/0x16
[    0.072319]  warn_alloc.cold.161+0x75/0xe8
[    0.072323]  ? __get_vm_area_node+0x14d/0x160
[    0.072328]  __vmalloc_node_range+0x5e5/0x7d0
[    0.072332]  ? stack_depot_init.cold.2+0x7e/0xb3
[    0.072335]  ? __kmalloc_large_node+0xf8/0x150
[    0.072338]  ? kvmalloc_node+0x4f/0xe0
[    0.072341]  kvmalloc_node+0xb1/0xe0
[    0.072344]  ? stack_depot_init.cold.2+0x7e/0xb3
[    0.072346]  stack_depot_init.cold.2+0x7e/0xb3
[    0.072348]  kmemleak_init+0x1b/0x10a
[    0.072352]  start_kernel+0x710/0x9dc
[    0.072356]  x86_64_start_reservations+0x24/0x2a
[    0.072358]  x86_64_start_kernel+0xf2/0xfd
[    0.072360]  secondary_startup_64_no_verify+0xe5/0xeb
[    0.072366]  </TASK>
[    0.072367] Mem-Info:
[    0.072368] active_anon:0 inactive_anon:0 isolated_anon:0
                 active_file:0 inactive_file:0 isolated_file:0
                 unevictable:0 dirty:0 writeback:0
                 slab_reclaimable:0 slab_unreclaimable:26
                 mapped:0 shmem:0 pagetables:0
                 sec_pagetables:0 bounce:0
                 kernel_misc_reclaimable:0
                 free:4037995 free_pcp:0 free_cma:0
[    0.072373] Node 0 active_anon:0kB inactive_anon:0kB active_file:0kB inactive_file:0kB unevictable:0kB isolated(anon):0kB 
isolated(file):0kB mapped:0kB dirty:0kB writeback:0kB shmem:0kB shmem_thp: 0kB shmem_pmdmapped: 0kB anon_thp: 0kB writeback_tmp:0kB 
kernel_stack:0kB pagetables:0kB sec_pagetables:0kB all_unreclaimable? no
[    0.072377] Node 0 DMA free:14336kB boost:0kB min:0kB low:0kB high:0kB reserved_highatomic:0KB active_anon:0kB inactive_anon:0kB 
active_file:0kB inactive_file:0kB unevictable:0kB writepending:0kB present:15992kB managed:14336kB mlocked:0kB bounce:0kB 
free_pcp:0kB local_pcp:0kB free_cma:0kB
[    0.072381] lowmem_reserve[]: 0 0 0 0 0
[    0.072385] Node 0 DMA32 free:2085160kB boost:0kB min:0kB low:0kB high:0kB reserved_highatomic:0KB active_anon:0kB 
inactive_anon:0kB active_file:0kB inactive_file:0kB unevictable:0kB writepending:0kB present:2257392kB managed:2085160kB mlocked:0kB 
bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB
[    0.072388] lowmem_reserve[]: 0 0 0 0 0
[    0.072391] Node 0 Normal free:14052484kB boost:0kB min:0kB low:0kB high:0kB reserved_highatomic:0KB active_anon:0kB 
inactive_anon:0kB active_file:0kB inactive_file:0kB unevictable:0kB writepending:0kB present:14385152kB managed:14052848kB 
mlocked:0kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB
[    0.072395] lowmem_reserve[]: 0 0 0 0 0
[    0.072398] Node 0 DMA: 0*4kB 0*8kB 0*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB 2*1024kB (UM) 2*2048kB (M) 2*4096kB (M) = 14336kB
[    0.072409] Node 0 DMA32: 8*4kB (M) 9*8kB (M) 8*16kB (M) 8*32kB (M) 7*64kB (M) 7*128kB (M) 8*256kB (M) 7*512kB (M) 5*1024kB (M) 
6*2048kB (M) 503*4096kB (M) = 2085160kB
[    0.072423] Node 0 Normal: 9*4kB (UM) 8*8kB (M) 2*16kB (UM) 2*32kB (M) 1*64kB (M) 3*128kB (UM) 2*256kB (M) 4*512kB (UM) 2*1024kB 
(UM) 1*2048kB (U) 3429*4096kB (M) = 14052484kB
[    0.072437] 0 total pagecache pages
[    0.072437] 0 pages in swap cache
[    0.072438] Free swap  = 0kB
[    0.072439] Total swap = 0kB
[    0.072439] 4164634 pages RAM
[    0.072440] 0 pages HighMem/MovableOnly
[    0.072441] 126548 pages reserved
[    0.072441] 0 pages hwpoisoned
[    0.072443] Stack Depot hash table allocation failed, disabling
[    0.072465] Kernel/User page tables isolation: enabled

I hope you will take time to make an assessment of this notice despite me
not being an authority in the matters of the Linux kernel.

But you will easily see that this patch does not work without kmemleak=
boot param.

Kind regards,
Mirsad

-- 
Mirsad Todorovac
System engineer
Faculty of Graphic Arts | Academy of Fine Arts
University of Zagreb
Republic of Croatia, the European Union
--
Sistem inženjer
Grafički fakultet | Akademija likovnih umjetnosti
Sveučilište u Zagrebu


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

* Re: + mm-use-stack_depot_early_init-for-kmemleak.patch added to mm-hotfixes-unstable branch
  2023-01-19 13:02 ` Mirsad Goran Todorovac
@ 2023-01-19 14:40   ` Catalin Marinas
  2023-01-19 14:51     ` Vlastimil Babka
  2023-01-19 17:01     ` Mirsad Goran Todorovac
  0 siblings, 2 replies; 6+ messages in thread
From: Catalin Marinas @ 2023-01-19 14:40 UTC (permalink / raw)
  To: Mirsad Goran Todorovac
  Cc: Andrew Morton, mm-commits, vbabka, peterz, nathan, ke.wang,
	huangzhaoyang, zhaoyang.huang

On Thu, Jan 19, 2023 at 02:02:29PM +0100, Mirsad Goran Todorovac wrote:
> On 18.1.2023. 1:19, Andrew Morton wrote:
> > --- a/mm/kmemleak.c~mm-use-stack_depot_early_init-for-kmemleak
> > +++ a/mm/kmemleak.c
> > @@ -2070,8 +2070,10 @@ static int __init kmemleak_boot_config(c
> >   		return -EINVAL;
> >   	if (strcmp(str, "off") == 0)
> >   		kmemleak_disable();
> > -	else if (strcmp(str, "on") == 0)
> > +	else if (strcmp(str, "on") == 0) {
> >   		kmemleak_skip_disable = 1;
> > +		stack_depot_want_early_init();
> > +	}
> >   	else
> >   		return -EINVAL;
> >   	return 0;
> > _
> > 
> > Patches currently in -mm which might be from zhaoyang.huang@unisoc.com are
> > 
> > mm-use-stack_depot_early_init-for-kmemleak.patch
> 
> Please note that this patch activates stack_depot_want_early_init() only when
> kernel boot param "kmemleak=on" is used.
> 
> When the following configuration is used:
> 
> CONFIG_HAVE_DEBUG_KMEMLEAK=y
> CONFIG_DEBUG_KMEMLEAK=y
> CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE=16000
> # CONFIG_DEBUG_KMEMLEAK_TEST is not set
> # CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set
> CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y

Indeed, I commented here already:

https://lore.kernel.org/all/Y8gDdnpvkCKvVV1t@arm.com/

-- 
Catalin

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

* Re: + mm-use-stack_depot_early_init-for-kmemleak.patch added to mm-hotfixes-unstable branch
  2023-01-19 14:40   ` Catalin Marinas
@ 2023-01-19 14:51     ` Vlastimil Babka
  2023-01-19 15:03       ` Mirsad Goran Todorovac
  2023-01-19 17:01     ` Mirsad Goran Todorovac
  1 sibling, 1 reply; 6+ messages in thread
From: Vlastimil Babka @ 2023-01-19 14:51 UTC (permalink / raw)
  To: Catalin Marinas, Mirsad Goran Todorovac
  Cc: Andrew Morton, mm-commits, peterz, nathan, ke.wang,
	huangzhaoyang, zhaoyang.huang

On 1/19/23 15:40, Catalin Marinas wrote:
> On Thu, Jan 19, 2023 at 02:02:29PM +0100, Mirsad Goran Todorovac wrote:
>> On 18.1.2023. 1:19, Andrew Morton wrote:
>> > --- a/mm/kmemleak.c~mm-use-stack_depot_early_init-for-kmemleak
>> > +++ a/mm/kmemleak.c
>> > @@ -2070,8 +2070,10 @@ static int __init kmemleak_boot_config(c
>> >   		return -EINVAL;
>> >   	if (strcmp(str, "off") == 0)
>> >   		kmemleak_disable();
>> > -	else if (strcmp(str, "on") == 0)
>> > +	else if (strcmp(str, "on") == 0) {
>> >   		kmemleak_skip_disable = 1;
>> > +		stack_depot_want_early_init();
>> > +	}
>> >   	else
>> >   		return -EINVAL;
>> >   	return 0;
>> > _
>> > 
>> > Patches currently in -mm which might be from zhaoyang.huang@unisoc.com are
>> > 
>> > mm-use-stack_depot_early_init-for-kmemleak.patch
>> 
>> Please note that this patch activates stack_depot_want_early_init() only when
>> kernel boot param "kmemleak=on" is used.
>> 
>> When the following configuration is used:
>> 
>> CONFIG_HAVE_DEBUG_KMEMLEAK=y
>> CONFIG_DEBUG_KMEMLEAK=y
>> CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE=16000
>> # CONFIG_DEBUG_KMEMLEAK_TEST is not set
>> # CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set
>> CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y
> 
> Indeed, I commented here already:
> 
> https://lore.kernel.org/all/Y8gDdnpvkCKvVV1t@arm.com/

And v4 was submitted with that change included:

https://lore.kernel.org/all/1674091345-14799-2-git-send-email-zhaoyang.huang@unisoc.com/

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

* Re: + mm-use-stack_depot_early_init-for-kmemleak.patch added to mm-hotfixes-unstable branch
  2023-01-19 14:51     ` Vlastimil Babka
@ 2023-01-19 15:03       ` Mirsad Goran Todorovac
  0 siblings, 0 replies; 6+ messages in thread
From: Mirsad Goran Todorovac @ 2023-01-19 15:03 UTC (permalink / raw)
  To: Vlastimil Babka, Catalin Marinas
  Cc: Andrew Morton, mm-commits, peterz, nathan, ke.wang,
	huangzhaoyang, zhaoyang.huang

On 19.1.2023. 15:51, Vlastimil Babka wrote:
> On 1/19/23 15:40, Catalin Marinas wrote:
>> On Thu, Jan 19, 2023 at 02:02:29PM +0100, Mirsad Goran Todorovac wrote:
>>> On 18.1.2023. 1:19, Andrew Morton wrote:
>>>> --- a/mm/kmemleak.c~mm-use-stack_depot_early_init-for-kmemleak
>>>> +++ a/mm/kmemleak.c
>>>> @@ -2070,8 +2070,10 @@ static int __init kmemleak_boot_config(c
>>>>    		return -EINVAL;
>>>>    	if (strcmp(str, "off") == 0)
>>>>    		kmemleak_disable();
>>>> -	else if (strcmp(str, "on") == 0)
>>>> +	else if (strcmp(str, "on") == 0) {
>>>>    		kmemleak_skip_disable = 1;
>>>> +		stack_depot_want_early_init();
>>>> +	}
>>>>    	else
>>>>    		return -EINVAL;
>>>>    	return 0;
>>>> _
>>>>
>>>> Patches currently in -mm which might be from zhaoyang.huang@unisoc.com are
>>>>
>>>> mm-use-stack_depot_early_init-for-kmemleak.patch
>>>
>>> Please note that this patch activates stack_depot_want_early_init() only when
>>> kernel boot param "kmemleak=on" is used.
>>>
>>> When the following configuration is used:
>>>
>>> CONFIG_HAVE_DEBUG_KMEMLEAK=y
>>> CONFIG_DEBUG_KMEMLEAK=y
>>> CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE=16000
>>> # CONFIG_DEBUG_KMEMLEAK_TEST is not set
>>> # CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set
>>> CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y
>>
>> Indeed, I commented here already:
>>
>> https://lore.kernel.org/all/Y8gDdnpvkCKvVV1t@arm.com/
> 
> And v4 was submitted with that change included:
> 
> https://lore.kernel.org/all/1674091345-14799-2-git-send-email-zhaoyang.huang@unisoc.com/

Indeed! I was five hours off at least.

Sorry, I missed these emails because linux-kernel@vger.kernel.org was not Cc:ed.
Fixed the filter now.

I agree this patch looks like it should be the solution, and I will test it in
the initial environment that triggered the bug as soon as I finish my current build.

Apologies, again.

Regards,
Mirsad

-- 
Mirsad Todorovac
System engineer
Faculty of Graphic Arts | Academy of Fine Arts
University of Zagreb
Republic of Croatia, the European Union
--
Sistem inženjer
Grafički fakultet | Akademija likovnih umjetnosti
Sveučilište u Zagrebu


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

* Re: + mm-use-stack_depot_early_init-for-kmemleak.patch added to mm-hotfixes-unstable branch
  2023-01-19 14:40   ` Catalin Marinas
  2023-01-19 14:51     ` Vlastimil Babka
@ 2023-01-19 17:01     ` Mirsad Goran Todorovac
  1 sibling, 0 replies; 6+ messages in thread
From: Mirsad Goran Todorovac @ 2023-01-19 17:01 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Andrew Morton, mm-commits, vbabka, peterz, nathan, ke.wang,
	huangzhaoyang, zhaoyang.huang

On 19.1.2023. 15:40, Catalin Marinas wrote:
> On Thu, Jan 19, 2023 at 02:02:29PM +0100, Mirsad Goran Todorovac wrote:
>> On 18.1.2023. 1:19, Andrew Morton wrote:
>>> --- a/mm/kmemleak.c~mm-use-stack_depot_early_init-for-kmemleak
>>> +++ a/mm/kmemleak.c
>>> @@ -2070,8 +2070,10 @@ static int __init kmemleak_boot_config(c
>>>    		return -EINVAL;
>>>    	if (strcmp(str, "off") == 0)
>>>    		kmemleak_disable();
>>> -	else if (strcmp(str, "on") == 0)
>>> +	else if (strcmp(str, "on") == 0) {
>>>    		kmemleak_skip_disable = 1;
>>> +		stack_depot_want_early_init();
>>> +	}
>>>    	else
>>>    		return -EINVAL;
>>>    	return 0;
>>> _
>>>
>>> Patches currently in -mm which might be from zhaoyang.huang@unisoc.com are
>>>
>>> mm-use-stack_depot_early_init-for-kmemleak.patch
>>
>> Please note that this patch activates stack_depot_want_early_init() only when
>> kernel boot param "kmemleak=on" is used.
>>
>> When the following configuration is used:
>>
>> CONFIG_HAVE_DEBUG_KMEMLEAK=y
>> CONFIG_DEBUG_KMEMLEAK=y
>> CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE=16000
>> # CONFIG_DEBUG_KMEMLEAK_TEST is not set
>> # CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set
>> CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y
> 
> Indeed, I commented here already:
> 
> https://lore.kernel.org/all/Y8gDdnpvkCKvVV1t@arm.com/

Hi,

I can report that the test was successful w/o kmemleak boot param.
As it is evident from the command output, /sys/kernel/debug/kmemleak
backtrace is now whole again:

dmesg:
[    0.033071] Kernel command line: BOOT_IMAGE=(hd0,gpt5)/vmlinuz-6.2.0-rc4-mglru-kmemlk-patch-zhaoyang5+ 
root=/dev/mapper/almalinux_desktop--mtodorov-root ro crashkernel=auto resume=/dev/mapper/almalinux_desktop--mtodorov-swap 
rd.lvm.lv=almalinux_desktop-mtodorov/root rd.lvm.lv=almalinux_desktop-mtodorov/swap loglevel=7 i915.alpha_support=1
[    0.033221] Unknown kernel command line parameters "BOOT_IMAGE=(hd0,gpt5)/vmlinuz-6.2.0-rc4-mglru-kmemlk-patch-zhaoyang5+", will 
be passed to user space.
[    0.034024] Dentry cache hash table entries: 2097152 (order: 12, 16777216 bytes, linear)
[    0.034403] Inode-cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.034500] mem auto-init: stack:off, heap alloc:on, heap free:off
[    0.034901] stackdepot hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.034910] software IO TLB: area num 8.
[    0.072568] Memory: 16143436K/16658536K available (18432K kernel code, 4118K rwdata, 7184K rodata, 4424K init, 7680K bss, 514840K 
reserved, 0K cma-reserved)
[    0.072753] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=6, Nodes=1
[    0.072775] Kernel/User page tables isolation: enabled

[root@pc-mtodorov marvin]# cat /sys/kernel/debug/kmemleak
unreferenced object 0xffff948246489b00 (size 16):
   comm "kworker/u12:5", pid 349, jiffies 4294893879 (age 87.016s)
   hex dump (first 16 bytes):
     6d 65 6d 73 74 69 63 6b 30 00 00 00 00 00 00 00  memstick0.......
   backtrace:
     [<ffffffff899cb9f1>] slab_post_alloc_hook+0x91/0x320
     [<ffffffff899d1faf>] __kmem_cache_alloc_node+0x1bf/0x2b0
     [<ffffffff8994fbb5>] __kmalloc_node_track_caller+0x55/0x140
     [<ffffffff89940b96>] kstrdup+0x36/0x70
     [<ffffffff89940c08>] kstrdup_const+0x28/0x30
     [<ffffffff89cfc348>] kvasprintf_const+0x78/0xa0
     [<ffffffff8a48a903>] kobject_set_name_vargs+0x23/0xa0
     [<ffffffff89fba2b3>] dev_set_name+0x53/0x70
     [<ffffffffc0e4dd3f>] memstick_check+0xff/0x384 [memstick]
     [<ffffffff896f6054>] process_one_work+0x214/0x3f0
     [<ffffffff896f6274>] worker_thread+0x34/0x3d0
     [<ffffffff897003cd>] kthread+0xed/0x120
     [<ffffffff896039f9>] ret_from_fork+0x29/0x50
unreferenced object 0xffff948246489c70 (size 16):
   comm "kworker/u12:5", pid 349, jiffies 4294893882 (age 87.004s)
   hex dump (first 16 bytes):
     6d 65 6d 73 74 69 63 6b 30 00 00 00 00 00 00 00  memstick0.......
   backtrace:
     [<ffffffff899cb9f1>] slab_post_alloc_hook+0x91/0x320
     [<ffffffff899d1faf>] __kmem_cache_alloc_node+0x1bf/0x2b0
     [<ffffffff8994fbb5>] __kmalloc_node_track_caller+0x55/0x140
     [<ffffffff89940b96>] kstrdup+0x36/0x70
     [<ffffffff89940c08>] kstrdup_const+0x28/0x30
     [<ffffffff89cfc348>] kvasprintf_const+0x78/0xa0
     [<ffffffff8a48a903>] kobject_set_name_vargs+0x23/0xa0
     [<ffffffff89fba2b3>] dev_set_name+0x53/0x70
     [<ffffffffc0e4dd3f>] memstick_check+0xff/0x384 [memstick]
     [<ffffffff896f6054>] process_one_work+0x214/0x3f0
     [<ffffffff896f6274>] worker_thread+0x34/0x3d0
     [<ffffffff897003cd>] kthread+0xed/0x120
     [<ffffffff896039f9>] ret_from_fork+0x29/0x50
[root@pc-mtodorov marvin]# grep KMEMLEAK /boot/config-6.2.0-rc4-mglru-kmemlk-patch-zhaoyang5+
CONFIG_HAVE_DEBUG_KMEMLEAK=y
CONFIG_DEBUG_KMEMLEAK=y
CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE=16000
# CONFIG_DEBUG_KMEMLEAK_TEST is not set
# CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set
CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y
[root@pc-mtodorov marvin]#

I have used mainline torvalds tree vanilla kernel w MGLRU and KMEMLEAK
settings as above and the diff as below:

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 881c3f84e88a..ddbfac2adf9c 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -743,76 +743,6 @@ config SHRINKER_DEBUG
           visibility into the kernel memory shrinkers subsystem.
           Disable it to avoid an extra memory footprint.

-config HAVE_DEBUG_KMEMLEAK
-       bool
-
-config DEBUG_KMEMLEAK
-       bool "Kernel memory leak detector"
-       depends on DEBUG_KERNEL && HAVE_DEBUG_KMEMLEAK
-       select DEBUG_FS
-       select STACKTRACE if STACKTRACE_SUPPORT
-       select KALLSYMS
-       select CRC32
-       select STACKDEPOT
-       help
-         Say Y here if you want to enable the memory leak
-         detector. The memory allocation/freeing is traced in a way
-         similar to the Boehm's conservative garbage collector, the
-         difference being that the orphan objects are not freed but
-         only shown in /sys/kernel/debug/kmemleak. Enabling this
-         feature will introduce an overhead to memory
-         allocations. See Documentation/dev-tools/kmemleak.rst for more
-         details.
-
-         Enabling DEBUG_SLAB or SLUB_DEBUG may increase the chances
-         of finding leaks due to the slab objects poisoning.
-
-         In order to access the kmemleak file, debugfs needs to be
-         mounted (usually at /sys/kernel/debug).
-
-config DEBUG_KMEMLEAK_MEM_POOL_SIZE
-       int "Kmemleak memory pool size"
-       depends on DEBUG_KMEMLEAK
-       range 200 1000000
-       default 16000
-       help
-         Kmemleak must track all the memory allocations to avoid
-         reporting false positives. Since memory may be allocated or
-         freed before kmemleak is fully initialised, use a static pool
-         of metadata objects to track such callbacks. After kmemleak is
-         fully initialised, this memory pool acts as an emergency one
-         if slab allocations fail.
-
-config DEBUG_KMEMLEAK_TEST
-       tristate "Simple test for the kernel memory leak detector"
-       depends on DEBUG_KMEMLEAK && m
-       help
-         This option enables a module that explicitly leaks memory.
-
-         If unsure, say N.
-
-config DEBUG_KMEMLEAK_DEFAULT_OFF
-       bool "Default kmemleak to off"
-       depends on DEBUG_KMEMLEAK
-       help
-         Say Y here to disable kmemleak by default. It can then be enabled
-         on the command line via kmemleak=on.
-
-config DEBUG_KMEMLEAK_AUTO_SCAN
-       bool "Enable kmemleak auto scan thread on boot up"
-       default y
-       depends on DEBUG_KMEMLEAK
-       help
-         Depending on the cpu, kmemleak scan may be cpu intensive and can
-         stall user tasks at times. This option enables/disables automatic
-         kmemleak scan at boot up.
-
-         Say N here to disable kmemleak auto scan thread to stop automatic
-         scanning. Disabling this option disables automatic reporting of
-         memory leaks.
-
-         If unsure, say Y.
-
  config DEBUG_STACK_USAGE
         bool "Stack utilization instrumentation"
         depends on DEBUG_KERNEL && !IA64
diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug
index fca699ad1fb0..f765f4769f39 100644
--- a/mm/Kconfig.debug
+++ b/mm/Kconfig.debug
@@ -207,3 +207,74 @@ config PTDUMP_DEBUGFS
           kernel.

           If in doubt, say N.
+
+config HAVE_DEBUG_KMEMLEAK
+       bool
+
+config DEBUG_KMEMLEAK
+       bool "Kernel memory leak detector"
+       depends on DEBUG_KERNEL && HAVE_DEBUG_KMEMLEAK
+       select DEBUG_FS
+       select STACKTRACE if STACKTRACE_SUPPORT
+       select KALLSYMS
+       select CRC32
+       select STACKDEPOT
+       select STACKDEPOT_ALWAYS_INIT if !DEBUG_KMEMLEAK_DEFAULT_OFF
+       help
+         Say Y here if you want to enable the memory leak
+         detector. The memory allocation/freeing is traced in a way
+         similar to the Boehm's conservative garbage collector, the
+         difference being that the orphan objects are not freed but
+         only shown in /sys/kernel/debug/kmemleak. Enabling this
+         feature will introduce an overhead to memory
+         allocations. See Documentation/dev-tools/kmemleak.rst for more
+         details.
+
+         Enabling DEBUG_SLAB or SLUB_DEBUG may increase the chances
+         of finding leaks due to the slab objects poisoning.
+
+         In order to access the kmemleak file, debugfs needs to be
+         mounted (usually at /sys/kernel/debug).
+
+config DEBUG_KMEMLEAK_MEM_POOL_SIZE
+       int "Kmemleak memory pool size"
+       depends on DEBUG_KMEMLEAK
+       range 200 1000000
+       default 16000
+       help
+         Kmemleak must track all the memory allocations to avoid
+         reporting false positives. Since memory may be allocated or
+         freed before kmemleak is fully initialised, use a static pool
+         of metadata objects to track such callbacks. After kmemleak is
+         fully initialised, this memory pool acts as an emergency one
+         if slab allocations fail.
+
+config DEBUG_KMEMLEAK_TEST
+       tristate "Simple test for the kernel memory leak detector"
+       depends on DEBUG_KMEMLEAK && m
+       help
+         This option enables a module that explicitly leaks memory.
+
+         If unsure, say N.
+
+config DEBUG_KMEMLEAK_DEFAULT_OFF
+       bool "Default kmemleak to off"
+       depends on DEBUG_KMEMLEAK
+       help
+         Say Y here to disable kmemleak by default. It can then be enabled
+         on the command line via kmemleak=on.
+
+config DEBUG_KMEMLEAK_AUTO_SCAN
+       bool "Enable kmemleak auto scan thread on boot up"
+       default y
+       depends on DEBUG_KMEMLEAK
+       help
+         Depending on the cpu, kmemleak scan may be cpu intensive and can
+         stall user tasks at times. This option enables/disables automatic
+         kmemleak scan at boot up.
+
+         Say N here to disable kmemleak auto scan thread to stop automatic
+         scanning. Disabling this option disables automatic reporting of
+         memory leaks.
+
+         If unsure, say Y.
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 92f670edbf51..5082e02b6c2d 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -2070,8 +2070,10 @@ static int __init kmemleak_boot_config(char *str)
                 return -EINVAL;
         if (strcmp(str, "off") == 0)
                 kmemleak_disable();
-       else if (strcmp(str, "on") == 0)
+       else if (strcmp(str, "on") == 0) {
                 kmemleak_skip_disable = 1;
+               stack_depot_want_early_init();
+       }
         else
                 return -EINVAL;
         return 0;
@@ -2093,7 +2095,6 @@ void __init kmemleak_init(void)
         if (kmemleak_error)
                 return;

-       stack_depot_init();
         jiffies_min_age = msecs_to_jiffies(MSECS_MIN_AGE);
         jiffies_scan_wait = msecs_to_jiffies(SECS_SCAN_WAIT * 1000);

Please check if the above is correct.

Hope this helps, as this is the environment that triggered the vmalloc()
but. But I would like to go into depth, we have allocated stack_init_depot
early, but I can't seem to realise why the initial kvmalloc() failed?

Could this possibly be a sign of another bug, or was it simply called too
early, before mm_init()?

I am sorry if this is a stupid question.

Regards,
Mirsad

-- 
Mirsad Todorovac
System engineer
Faculty of Graphic Arts | Academy of Fine Arts
University of Zagreb
Republic of Croatia, the European Union
--
Sistem inženjer
Grafički fakultet | Akademija likovnih umjetnosti
Sveučilište u Zagrebu


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

end of thread, other threads:[~2023-01-19 17:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-18  0:19 + mm-use-stack_depot_early_init-for-kmemleak.patch added to mm-hotfixes-unstable branch Andrew Morton
2023-01-19 13:02 ` Mirsad Goran Todorovac
2023-01-19 14:40   ` Catalin Marinas
2023-01-19 14:51     ` Vlastimil Babka
2023-01-19 15:03       ` Mirsad Goran Todorovac
2023-01-19 17:01     ` Mirsad Goran Todorovac

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.