From: Catalin Marinas <catalin.marinas@arm.com>
To: Chris von Recklinghausen <crecklin@redhat.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] don't record leak information on allocations done between kmemleak_init and kmemleak_late_init
Date: Tue, 2 Jan 2024 20:07:52 +0000 [thread overview]
Message-ID: <ZZRtGC9ZPVR5uCqu@arm.com> (raw)
In-Reply-To: <20240102153428.139984-1-crecklin@redhat.com>
On Tue, Jan 02, 2024 at 10:34:28AM -0500, Chris von Recklinghausen wrote:
> If an object is allocated after kmemleak_init is called but before
> kmemleak_late_init is called, calls to kmemleak_not_leak or
> kmemleak_ignore on the object don't prevent a scan from reporting the
> object as a leak.
This may be true but what is the reason for this? Can you give some
example of false positives you get?
> Avoid this situation by only registering objects in kmemleak_alloc when
> kmemleak_initialized is set.
I wouldn't do this, kmemleak needs to track all the early allocations,
otherwise it will lead to lots of false positives. However, looking at
your patch, it looks like it doesn't touch kmemleak_alloc() at all and
it does something completely different.
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index 5501363d6b31..0c8a5f456874 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -1117,7 +1117,8 @@ void __ref kmemleak_free_part(const void *ptr, size_t size)
> {
> pr_debug("%s(0x%px)\n", __func__, ptr);
>
> - if (kmemleak_enabled && ptr && !IS_ERR(ptr))
> + if (kmemleak_enabled && kmemleak_late_initialized && ptr &&
> + !IS_ERR(ptr))
> delete_object_part((unsigned long)ptr, size, false);
> }
This leaves some memory to still be tracked by kmemleak when it was
actually freed. Later when it is reallocated, you'll get some errors and
kmemleak will disable itself.
> EXPORT_SYMBOL_GPL(kmemleak_free_part);
> @@ -1135,7 +1136,8 @@ void __ref kmemleak_free_percpu(const void __percpu *ptr)
>
> pr_debug("%s(0x%px)\n", __func__, ptr);
>
> - if (kmemleak_free_enabled && ptr && !IS_ERR(ptr))
> + if (kmemleak_free_enabled && kmemleak_late_initialized && ptr &&
> + !IS_ERR(ptr))
> for_each_possible_cpu(cpu)
> delete_object_full((unsigned long)per_cpu_ptr(ptr,
> cpu));
Same here.
> @@ -1189,7 +1191,8 @@ void __ref kmemleak_not_leak(const void *ptr)
> {
> pr_debug("%s(0x%px)\n", __func__, ptr);
>
> - if (kmemleak_enabled && ptr && !IS_ERR(ptr))
> + if (kmemleak_enabled && kmamleak_late_initialized && ptr &&
^^^
I guess you haven't compiled this patch. Does it actually fix the
problem you are reporting?
> + !IS_ERR(ptr))
> make_gray_object((unsigned long)ptr);
> }
This change doesn't help at all with your problem statement.
> EXPORT_SYMBOL(kmemleak_not_leak);
> @@ -1207,7 +1210,8 @@ void __ref kmemleak_ignore(const void *ptr)
> {
> pr_debug("%s(0x%px)\n", __func__, ptr);
>
> - if (kmemleak_enabled && ptr && !IS_ERR(ptr))
> + if (kmemleak_enabled && kmamleak_late_initialized && ptr &&
> + !IS_ERR(ptr))
> make_black_object((unsigned long)ptr, false);
> }
> EXPORT_SYMBOL(kmemleak_ignore);
Neither does this.
Also if you re-post, please cc linux-mm as well. Andrew Morton tends to
pick up the kmemleak patches (once acked).
--
Catalin
next prev parent reply other threads:[~2024-01-02 20:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-02 15:34 [PATCH] don't record leak information on allocations done between kmemleak_init and kmemleak_late_init Chris von Recklinghausen
2024-01-02 20:07 ` Catalin Marinas [this message]
[not found] ` <5d979584-a168-4594-af19-93af6bc0ae5a@redhat.com>
2024-01-03 12:25 ` Catalin Marinas
2024-01-03 3:08 ` kernel test robot
2024-01-03 10:51 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZZRtGC9ZPVR5uCqu@arm.com \
--to=catalin.marinas@arm.com \
--cc=crecklin@redhat.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).