From: Hao Ge <hao.ge@linux.dev>
To: Suren Baghdasaryan <surenb@google.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mm/alloc_tag: clear codetag for pages allocated before page_ext initialization
Date: Fri, 27 Mar 2026 16:14:00 +0800 [thread overview]
Message-ID: <772e1ce6-6dda-4b73-9c9d-ff04a383f07e@linux.dev> (raw)
In-Reply-To: <CAJuCfpHddCffwF6uid_nW8sMAMpJcOiB62BCeGEtoiDYY6rP4g@mail.gmail.com>
Hi Suren
On 2026/3/27 09:19, Suren Baghdasaryan wrote:
> On Thu, Mar 26, 2026 at 6:11 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>> On Thu, 26 Mar 2026 22:05:54 +0800 Hao Ge <hao.ge@linux.dev> wrote:
>>
>>> Due to initialization ordering, page_ext is allocated and initialized
>>> relatively late during boot. Some pages have already been allocated
>>> and freed before page_ext becomes available, leaving their codetag
>>> uninitialized.
>>>
>>> A clear example is in init_section_page_ext(): alloc_page_ext() calls
>>> kmemleak_alloc(). If the slab cache has no free objects, it falls back
>>> to the buddy allocator to allocate memory. However, at this point page_ext
>>> is not yet fully initialized, so these newly allocated pages have no
>>> codetag set. These pages may later be reclaimed by KASAN, which causes
>>> the warning to trigger when they are freed because their codetag ref is
>>> still empty.
>>>
>>> Use a global array to track pages allocated before page_ext is fully
>>> initialized. The array size is fixed at 8192 entries, and will emit
>>> a warning if this limit is exceeded. When page_ext initialization
>>> completes, set their codetag to empty to avoid warnings when they
>>> are freed later.
>>>
>> Thanks. I'll queue this for review and test.
>>
>> But where will I queue it?
> I don't think it's extra urgent. It is visible only when debugging
> with CONFIG_MEM_ALLOC_PROFILING_DEBUG.
>
>>> Fixes: 93d5440ece3c ("alloc_tag: uninline code gated by mem_alloc_profiling_key in page allocator")
> Hmm. I'm not sure that's the right patch. Technically the problem
> exists once we introduced CONFIG_MEM_ALLOC_PROFILING_DEBUG. I'll
> double-check.
I believe this should be Fixes: dcfe378c81f72 ("lib: introduce support
for page allocation tagging").
Earlier I thought backporting this commit here would be quite involved,
but after further consideration, this is indeed the commit being fixed.
>> A year ago, so a cc:stable might be needed.
>>
>>> +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG
>> otoh, it appears that the bug only hits with
>> CONFIG_MEM_ALLOC_PROFILING_DEBUG=y? If so, I'll add that (important)
>> info to the changelog.
> Correct, it affects only CONFIG_MEM_ALLOC_PROFILING_DEBUG=y and only
> if !mem_profiling_compressed.
>
>> Do people use CONFIG_MEM_ALLOC_PROFILING_DEBUG much? Is a backport
>> really needed?
> IMO backport would be good.
>
>> Either way, it seems that this isn't a very urgent issue so I'm
>> inclined to add it to the 7.1-rc1 pile, perhaps with a cc:stable.
>>
>> Please all share your thoughts with me, thanks.
> I'm reviewing and testing the patch and there is a race and a couple
> of smaller issues. I'll post a reply later today.
Thank you so much for your kind help! I really appreciate it.
Thanks
Hao
next prev parent reply other threads:[~2026-03-27 8:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 14:05 Hao Ge
2026-03-27 1:11 ` Andrew Morton
2026-03-27 1:19 ` Suren Baghdasaryan
2026-03-27 1:34 ` Andrew Morton
2026-03-27 1:50 ` Suren Baghdasaryan
2026-03-27 8:14 ` Hao Ge [this message]
2026-03-27 4:32 ` Suren Baghdasaryan
2026-03-27 4:39 ` Suren Baghdasaryan
2026-03-27 8:33 ` Hao Ge
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=772e1ce6-6dda-4b73-9c9d-ff04a383f07e@linux.dev \
--to=hao.ge@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=kent.overstreet@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=surenb@google.com \
/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