linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] mm/kmemleak: use object_cache instead of kmemleak_initialized
@ 2023-08-15  5:13 Xiaolei Wang
  2023-08-15  5:13 ` [PATCH v2 1/2] mm/kmemleak: use object_cache instead of kmemleak_initialized to check in set_track_prepare() Xiaolei Wang
  2023-08-15  5:13 ` [PATCH v2 2/2] Rename kmemleak_initialized to kmemleak_late_initialized Xiaolei Wang
  0 siblings, 2 replies; 5+ messages in thread
From: Xiaolei Wang @ 2023-08-15  5:13 UTC (permalink / raw)
  To: catalin.marinas, akpm, vbabka, glider, andreyknvl, zhaoyang.huang
  Cc: linux-mm, linux-kernel

use object_cache instead of kmemleak_initialized to check in
set_track_prepare(), so that memory leaks after kmemleak_init()
can be recorded and Rename kmemleak_initialized to
kmemleak_late_initialized

unreferenced object 0xc674ca80 (size 64):
 comm "swapper/0", pid 1, jiffies 4294938337 (age 204.880s)
 hex dump (first 32 bytes):
  80 55 75 c6 80 54 75 c6 00 55 75 c6 80 52 75 c6 .Uu..Tu..Uu..Ru.
  00 53 75 c6 00 00 00 00 00 00 00 00 00 00 00 00 .Su..........

Change in V2:
Delete patch1 in v1 version, change patch2, use object_cache instead of
kmemleak_initialized to check in set_track_prepare(), so that memory leak
after kmemleak_init() can be recorded, and rename kmemleak_initialized to
kmemleak_late_initialized

Xiaolei Wang (2):
  mm/kmemleak: use object_cache instead of kmemleak_initialized to check
    in set_track_prepare()
  Rename kmemleak_initialized to kmemleak_late_initialized

 mm/kmemleak.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

-- 
2.25.1



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

* [PATCH v2 1/2] mm/kmemleak: use object_cache instead of kmemleak_initialized to check in set_track_prepare()
  2023-08-15  5:13 [PATCH v2 0/2] mm/kmemleak: use object_cache instead of kmemleak_initialized Xiaolei Wang
@ 2023-08-15  5:13 ` Xiaolei Wang
  2023-08-15 10:39   ` Catalin Marinas
  2023-08-15  5:13 ` [PATCH v2 2/2] Rename kmemleak_initialized to kmemleak_late_initialized Xiaolei Wang
  1 sibling, 1 reply; 5+ messages in thread
From: Xiaolei Wang @ 2023-08-15  5:13 UTC (permalink / raw)
  To: catalin.marinas, akpm, vbabka, glider, andreyknvl, zhaoyang.huang
  Cc: linux-mm, linux-kernel

kmemleak_initialized is set in kmemleak_late_init(), which
also means that there is no call trace which object's memory
leak is before kmemleak_late_init(), so use object_cache instead
of kmemleak_initialized to check in set_track_prepare() to avoid
no call trace records when there is a memory leak in the code
between kmemleak_init() and kmemleak_late_init().

unreferenced object 0xc674ca80 (size 64):
 comm "swapper/0", pid 1, jiffies 4294938337 (age 204.880s)
 hex dump (first 32 bytes):
  80 55 75 c6 80 54 75 c6 00 55 75 c6 80 52 75 c6 .Uu..Tu..Uu..Ru.
  00 53 75 c6 00 00 00 00 00 00 00 00 00 00 00 00 .Su..........

Fixes: 56a61617dd22 ("mm: use stack_depot for recording kmemleak's backtrace")
Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>
---
 mm/kmemleak.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index a2d34226e3c8..04bb4cdbb402 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -610,7 +610,8 @@ static noinline depot_stack_handle_t set_track_prepare(void)
 	unsigned long entries[MAX_TRACE];
 	unsigned int nr_entries;
 
-	if (!kmemleak_initialized)
+	/*Use object_cache to determine whether kmemleak_init() is complete*/
+	if (!object_cache)
 		return 0;
 	nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 3);
 	trace_handle = stack_depot_save(entries, nr_entries, GFP_NOWAIT);
-- 
2.25.1



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

* [PATCH v2 2/2] Rename kmemleak_initialized to kmemleak_late_initialized
  2023-08-15  5:13 [PATCH v2 0/2] mm/kmemleak: use object_cache instead of kmemleak_initialized Xiaolei Wang
  2023-08-15  5:13 ` [PATCH v2 1/2] mm/kmemleak: use object_cache instead of kmemleak_initialized to check in set_track_prepare() Xiaolei Wang
@ 2023-08-15  5:13 ` Xiaolei Wang
  2023-08-15 10:40   ` Catalin Marinas
  1 sibling, 1 reply; 5+ messages in thread
From: Xiaolei Wang @ 2023-08-15  5:13 UTC (permalink / raw)
  To: catalin.marinas, akpm, vbabka, glider, andreyknvl, zhaoyang.huang
  Cc: linux-mm, linux-kernel

kmemleak_initialized is set in kmemleak_late_init()
instead of kmemleak_init(), which may cause confusion,
so rename kmemleak_initialized to kmemleak_late_initialized.

Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>
---
 mm/kmemleak.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 04bb4cdbb402..5c8e5a24b890 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -218,7 +218,7 @@ static int kmemleak_enabled = 1;
 /* same as above but only for the kmemleak_free() callback */
 static int kmemleak_free_enabled = 1;
 /* set in the late_initcall if there were no errors */
-static int kmemleak_initialized;
+static int kmemleak_late_initialized;
 /* set if a kmemleak warning was issued */
 static int kmemleak_warning;
 /* set if a fatal kmemleak error has occurred */
@@ -2053,7 +2053,7 @@ static void kmemleak_disable(void)
 	kmemleak_enabled = 0;
 
 	/* check whether it is too early for a kernel thread */
-	if (kmemleak_initialized)
+	if (kmemleak_late_initialized)
 		schedule_work(&cleanup_work);
 	else
 		kmemleak_free_enabled = 0;
@@ -2118,7 +2118,7 @@ void __init kmemleak_init(void)
  */
 static int __init kmemleak_late_init(void)
 {
-	kmemleak_initialized = 1;
+	kmemleak_late_initialized = 1;
 
 	debugfs_create_file("kmemleak", 0644, NULL, NULL, &kmemleak_fops);
 
@@ -2126,7 +2126,7 @@ static int __init kmemleak_late_init(void)
 		/*
 		 * Some error occurred and kmemleak was disabled. There is a
 		 * small chance that kmemleak_disable() was called immediately
-		 * after setting kmemleak_initialized and we may end up with
+		 * after setting kmemleak_late_initialized and we may end up with
 		 * two clean-up threads but serialized by scan_mutex.
 		 */
 		schedule_work(&cleanup_work);
-- 
2.25.1



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

* Re: [PATCH v2 1/2] mm/kmemleak: use object_cache instead of kmemleak_initialized to check in set_track_prepare()
  2023-08-15  5:13 ` [PATCH v2 1/2] mm/kmemleak: use object_cache instead of kmemleak_initialized to check in set_track_prepare() Xiaolei Wang
@ 2023-08-15 10:39   ` Catalin Marinas
  0 siblings, 0 replies; 5+ messages in thread
From: Catalin Marinas @ 2023-08-15 10:39 UTC (permalink / raw)
  To: Xiaolei Wang
  Cc: akpm, vbabka, glider, andreyknvl, zhaoyang.huang, linux-mm, linux-kernel

On Tue, Aug 15, 2023 at 01:13:57PM +0800, Xiaolei Wang wrote:
> kmemleak_initialized is set in kmemleak_late_init(), which
> also means that there is no call trace which object's memory
> leak is before kmemleak_late_init(), so use object_cache instead
> of kmemleak_initialized to check in set_track_prepare() to avoid
> no call trace records when there is a memory leak in the code
> between kmemleak_init() and kmemleak_late_init().
> 
> unreferenced object 0xc674ca80 (size 64):
>  comm "swapper/0", pid 1, jiffies 4294938337 (age 204.880s)
>  hex dump (first 32 bytes):
>   80 55 75 c6 80 54 75 c6 00 55 75 c6 80 52 75 c6 .Uu..Tu..Uu..Ru.
>   00 53 75 c6 00 00 00 00 00 00 00 00 00 00 00 00 .Su..........
> 
> Fixes: 56a61617dd22 ("mm: use stack_depot for recording kmemleak's backtrace")
> Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>
> ---
>  mm/kmemleak.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index a2d34226e3c8..04bb4cdbb402 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -610,7 +610,8 @@ static noinline depot_stack_handle_t set_track_prepare(void)
>  	unsigned long entries[MAX_TRACE];
>  	unsigned int nr_entries;
>  
> -	if (!kmemleak_initialized)
> +	/*Use object_cache to determine whether kmemleak_init() is complete*/

Nitpick: please add spaces after/before the comment delimiters. I'd also
make it clearer that it's not about kmemleak being initialised but
rather the stack depot. E.g.:

	/*
	 * Use object_cache to determine whether kmemleak_init() has
	 * been invoked. stack_depot_early_init() is called before
	 * kmemleak_init() in mm_core_init().
	 */

> +	if (!object_cache)
>  		return 0;
>  	nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 3);
>  	trace_handle = stack_depot_save(entries, nr_entries, GFP_NOWAIT);

Otherwise:

Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>


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

* Re: [PATCH v2 2/2] Rename kmemleak_initialized to kmemleak_late_initialized
  2023-08-15  5:13 ` [PATCH v2 2/2] Rename kmemleak_initialized to kmemleak_late_initialized Xiaolei Wang
@ 2023-08-15 10:40   ` Catalin Marinas
  0 siblings, 0 replies; 5+ messages in thread
From: Catalin Marinas @ 2023-08-15 10:40 UTC (permalink / raw)
  To: Xiaolei Wang
  Cc: akpm, vbabka, glider, andreyknvl, zhaoyang.huang, linux-mm, linux-kernel

On Tue, Aug 15, 2023 at 01:13:58PM +0800, Xiaolei Wang wrote:
> kmemleak_initialized is set in kmemleak_late_init()
> instead of kmemleak_init(), which may cause confusion,
> so rename kmemleak_initialized to kmemleak_late_initialized.
> 
> Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>

If it makes it clearer, fine by me.

Acked-by: Catalin Marinas <catalin.marinas@arm.com>


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

end of thread, other threads:[~2023-08-15 10:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-15  5:13 [PATCH v2 0/2] mm/kmemleak: use object_cache instead of kmemleak_initialized Xiaolei Wang
2023-08-15  5:13 ` [PATCH v2 1/2] mm/kmemleak: use object_cache instead of kmemleak_initialized to check in set_track_prepare() Xiaolei Wang
2023-08-15 10:39   ` Catalin Marinas
2023-08-15  5:13 ` [PATCH v2 2/2] Rename kmemleak_initialized to kmemleak_late_initialized Xiaolei Wang
2023-08-15 10:40   ` Catalin Marinas

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