From: Borislav Petkov <bp@alien8.de>
To: jiang.kun2@zte.com.cn
Cc: dave.hansen@linux.intel.com, luto@kernel.org,
peterz@infradead.org, tglx@kernel.org, mingo@redhat.com,
x86@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org,
xu.xin16@zte.com.cn
Subject: Re: [PATCH] x86/mm: remove freed init memory from kmemleak in free_init_pages()
Date: Wed, 22 Jul 2026 08:04:25 -0700 [thread overview]
Message-ID: <20260722150425.GAamDb-YAimMm61I9c@fat_crate.local> (raw)
In-Reply-To: <20260709204134153I0-fLVay3PJJjCDRGskzg@zte.com.cn>
On Thu, Jul 09, 2026 at 08:41:34PM +0800, jiang.kun2@zte.com.cn wrote:
> From: Jiang Kun <jiang.kun2@zte.com.cn>
>
> free_init_pages() already informs kmemleak when init memory is unmapped
> under debug_pagealloc_enabled(), but the normal free path only releases
> the pages through free_reserved_area() without removing the range from
> kmemleak.
>
> This can leave stale kmemleak objects for boot-time init memory such as
> initrd/initramfs buffers. Once the freed range is later reused, kmemleak
> may detect overlapping objects and report:
>
> kmemleak: Cannot insert ... into the object search tree (overlaps existing)
>
> followed by disabling the leak detector.
>
> Make both paths consistent by calling kmemleak_free_part() before
> freeing the range in the normal path as well.
>
> This matches the existing debug_pagealloc behavior and ensures that
> freed init memory is removed from kmemleak before being reused.
>
> Signed-off-by: Jiang Kun <jiang.kun2@zte.com.cn>
> ---
> arch/x86/mm/init.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
> index fb67217fddcd..3bed63ec1568 100644
> --- a/arch/x86/mm/init.c
> +++ b/arch/x86/mm/init.c
> @@ -933,6 +933,7 @@ void free_init_pages(const char *what, unsigned long begin, unsigned long end)
> set_memory_nx(begin, (end - begin) >> PAGE_SHIFT);
> set_memory_rw(begin, (end - begin) >> PAGE_SHIFT);
>
> + kmemleak_free_part((void *)begin, end - begin);
> free_reserved_area((void *)begin, (void *)end,
> POISON_FREE_INITMEM, what);
> }
How about you do not duplicate that call but make it unconditional, regardless
of the if-else?
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
prev parent reply other threads:[~2026-07-22 15:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 12:41 jiang.kun2
2026-07-22 15:04 ` Borislav Petkov [this message]
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=20260722150425.GAamDb-YAimMm61I9c@fat_crate.local \
--to=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jiang.kun2@zte.com.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
--cc=xu.xin16@zte.com.cn \
/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
all inboxes | Powered by JetHome®