From: Hao Ge <hao.ge@linux.dev>
To: Suren Baghdasaryan <surenb@google.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>,
Petr Pavlu <petr.pavlu@suse.com>,
Daniel Gomez <da.gomez@kernel.org>,
Sami Tolvanen <samitolvanen@google.com>,
Aaron Tomlin <atomlin@atomlin.com>,
Kent Overstreet <kent.overstreet@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
linux-modules@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH v10 5/6] alloc_tag: skip percpu counter allocation when profiling is disabled
Date: Fri, 18 Sep 2026 10:37:21 +0800 [thread overview]
Message-ID: <f16c55ba-3403-4721-9ff1-061d73e17fa5@linux.dev> (raw)
In-Reply-To: <CAJuCfpFKGxOy9W+ZY9KasU5YaDVG4kbGsV6AYb2NNRyW4gT0mw@mail.gmail.com>
Hi Suren
On 2026/9/18 08:53, Suren Baghdasaryan wrote:
> On Mon, Sep 14, 2026 at 11:59 PM Hao Ge <hao.ge@linux.dev> wrote:
>>
>> After shutdown_mem_profiling() clears mem_profiling_support,
>> needs_section_mem() returns false, so later modules have their codetag
>> section placed as regular data and never enter the alloc_tag maple tree.
>> codetag_load_module() still called load_module(), which allocated a percpu
>> counter for every tag; release_module_tags() could not find these modules
>> on unload, so the counters leaked.
>>
>> Return -EOPNOTSUPP from load_module() when profiling is off:
>> codetag_module_init() drops the module's cmod, no counters are allocated
>> and the module loads without its tags. codetag_unload_module() now always
>> calls free_section_mem(), since a module whose module_load() returned
>> -EOPNOTSUPP is not in the idr but may still hold a reserved section.
>>
>> Reported-by: Sashiko <sashiko-bot@kernel.org>
>> Fixes: 4835f747d3ed ("alloc_tag: support for page allocation tag compression")
>> Cc: stable@vger.kernel.org
>> Suggested-by: Suren Baghdasaryan <surenb@google.com>
>> Acked-by: Suren Baghdasaryan <surenb@google.com>
>
> Yeah, I guess I didn't think about alternatives...
>
> When mem_profiling_support=false, why can't load_module() skip
> allocating percpu counters, zero out the whole area between start_tag
> and stop_tag and return 0 as success (mem_profiling_support is not
> enabled, so we acted accordingly)?
> Module will be added into maple tree and later codetag_unload_module()
> will find the module, call release_module_tags() (which is a NOOP
> because tag->counter==NULL) and finally call free_section_mem(). This
> seems more natural than special-casing with EOPNOTSUPP. WDYT?
>
I see, but the module would then sit in the idr with NULL-counter
tags that become visible to readers which today never expect that state.
alloc_tag_top_users calls codetag_next_ct() to find the next codetag
and alloc_tag_read() would do per_cpu_ptr(NULL) for each cpu - plain
pointer arithmetic onto a wild address, an oops straight out of the
OOM report.
https://elixir.bootlin.com/linux/v7.3-rc3/source/mm/alloc_tag.c#L503
So if the codetag section within this codetag_type ends up meaningless,
is there a reason we still return success? We will still maintain cttype->count
and allocate a slot for this module inside mod_idr.
I'd rather keep the -EOPNOTSUPP version (your original suggestion),
also because the comments in load_module() and codetag_module_init()
already document this scenario.
WDYT?
Thanks
Best Regards
Hao
>> Signed-off-by: Hao Ge <hao.ge@linux.dev>
>> ---
>> lib/codetag.c | 10 ++++++++--
>> mm/alloc_tag.c | 4 ++++
>> 2 files changed, 12 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/codetag.c b/lib/codetag.c
>> index a9cda4c962a3..a0b600720afc 100644
>> --- a/lib/codetag.c
>> +++ b/lib/codetag.c
>> @@ -240,7 +240,9 @@ static int codetag_module_init(struct codetag_type *cttype, struct module *mod)
>>
>> if (err < 0) {
>> kfree(cmod);
>> - return err;
>> + /* -EOPNOTSUPP means we can load the module without its tag. */
>> + if (err != -EOPNOTSUPP)
>> + return err;
>> }
>>
>> return 0;
>> @@ -388,7 +390,11 @@ void codetag_unload_module(struct module *mod)
>> ++cttype->content_id;
>> }
>> up_write(&cttype->mod_lock);
>> - if (found && cttype->desc.free_section_mem)
>> + /*
>> + * A module whose module_load() returned -EOPNOTSUPP is not
>> + * in the idr but may still hold reserved section memory.
>> + */
>> + if (cttype->desc.free_section_mem)
>> cttype->desc.free_section_mem(mod, true);
>> }
>> mutex_unlock(&codetag_lock);
>> diff --git a/mm/alloc_tag.c b/mm/alloc_tag.c
>> index 5836803898ad..1ca0409b492b 100644
>> --- a/mm/alloc_tag.c
>> +++ b/mm/alloc_tag.c
>> @@ -988,6 +988,10 @@ static int load_module(struct module *mod, struct codetag *start, struct codetag
>> struct alloc_tag *stop_tag;
>> struct alloc_tag *tag;
>>
>> + /* Profiling disabled: load the module without its tags. */
>> + if (!mem_profiling_support)
>> + return -EOPNOTSUPP;
>> +
>> /* percpu counters for core allocations are already statically allocated */
>> if (!mod)
>> return 0;
>> --
>> 2.25.1
>>
next prev parent reply other threads:[~2026-09-18 2:36 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 6:59 [PATCH v10 0/6] alloc_tag and module codetag section fixes Hao Ge
2026-09-15 6:59 ` [PATCH v10 1/6] alloc_tag: move release_module_tags() above reserve_module_tags() Hao Ge
2026-09-15 6:59 ` [PATCH v10 2/6] alloc_tag: clean up the populate failure path Hao Ge
2026-09-15 21:09 ` Suren Baghdasaryan
2026-09-16 6:01 ` Hao Ge
2026-09-16 16:31 ` Suren Baghdasaryan
2026-09-16 19:07 ` Suren Baghdasaryan
2026-09-17 1:12 ` Hao Ge
2026-09-17 2:32 ` Hao Ge
2026-09-18 16:35 ` Lorenzo Stoakes (ARM)
2026-09-28 9:53 ` Uladzislau Rezki
2026-09-28 9:57 ` Lorenzo Stoakes (ARM)
2026-09-28 11:09 ` Uladzislau Rezki
2026-09-28 15:09 ` Uladzislau Rezki
2026-09-28 15:16 ` Suren Baghdasaryan
2026-09-28 17:47 ` Uladzislau Rezki
2026-09-28 17:54 ` Suren Baghdasaryan
2026-09-29 8:28 ` Hao Ge
2026-09-15 6:59 ` [PATCH v10 3/6] module: introduce SH_ENTSIZE_STANDALONE for separately allocated sections Hao Ge
2026-09-17 17:25 ` Suren Baghdasaryan
2026-09-18 2:51 ` Hao Ge
2026-09-15 6:59 ` [PATCH v10 4/6] module: allocate codetag sections before the regular module layout Hao Ge
2026-09-18 0:05 ` Suren Baghdasaryan
2026-09-15 7:00 ` [PATCH v10 5/6] alloc_tag: skip percpu counter allocation when profiling is disabled Hao Ge
2026-09-18 0:53 ` Suren Baghdasaryan
2026-09-18 2:37 ` Hao Ge [this message]
2026-09-23 2:46 ` Suren Baghdasaryan
2026-09-15 7:00 ` [PATCH v10 6/6] alloc_tag: Defer /proc/allocinfo removal to a workqueue Hao Ge
2026-09-15 7:10 ` sashiko-bot
2026-09-18 1:09 ` Suren Baghdasaryan
2026-09-18 1:39 ` Hao Ge
2026-09-23 2:41 ` Suren Baghdasaryan
2026-09-23 6:55 ` Hao Ge
2026-09-15 18:23 ` [PATCH v10 0/6] alloc_tag and module codetag section fixes Suren Baghdasaryan
2026-09-16 5:03 ` 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=f16c55ba-3403-4721-9ff1-061d73e17fa5@linux.dev \
--to=hao.ge@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=atomlin@atomlin.com \
--cc=da.gomez@kernel.org \
--cc=kent.overstreet@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-modules@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=samitolvanen@google.com \
--cc=sashiko-bot@kernel.org \
--cc=stable@vger.kernel.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 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.