From: Mike Rapoport <rppt@kernel.org>
To: Ionut Nechita <ionut.nechita@windriver.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Frederic Weisbecker <frederic@kernel.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Andrew Morton <akpm@linux-foundation.org>,
bugzilla-daemon@kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sched/isolation: Defer freeing of the bootmem housekeeping cpumasks
Date: Mon, 3 Aug 2026 09:54:18 +0300 [thread overview]
Message-ID: <anA7GhzjZoi293Yy@kernel.org> (raw)
In-Reply-To: <20260802115623.110513-1-ionut.nechita@windriver.com>
On Sun, Aug 02, 2026 at 02:56:23PM +0300, Ionut Nechita wrote:
> housekeeping_setup() allocates the housekeeping cpumasks from memblock
> while parsing the command line, long before the page allocator exists.
> housekeeping_init() then reallocates them with kmalloc(), so that a later
> runtime update can free the old mask with kfree(), and releases the
> memblock allocations with memblock_free().
>
> That release is not safe where it currently sits. housekeeping_init() is
> called from start_kernel() after mm_core_init(), so slab_is_available()
> is already true and memblock_phys_free() takes the __free_reserved_area()
> path. But it is still called long before page_alloc_init_late(), so with
> CONFIG_DEFERRED_STRUCT_PAGE_INIT=y the deferred part of the memory map is
> not initialized yet, and __free_reserved_area() refuses to touch it:
>
> Record the bootmem masks instead and release them from a core_initcall,
> which runs after page_alloc_init_late() has initialized the deferred
> memory map. early_initcall() would still be too early: kernel_init_freeable()
> runs do_pre_smp_initcalls() before page_alloc_init_late().
>
> Masks that housekeeping_init() did not manage to replace, because
> kmalloc() failed, are never recorded and therefore stay live, preserving
> the existing error behaviour.
>
> Fixes: 27c3a5967f05 ("sched/isolation: Convert housekeeping cpumasks to rcu pointers")
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221804
> Link: https://lore.kernel.org/linux-mm/20260728134016.674388f101f141362598240f@linux-foundation.org/
> Suggested-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> Signed-off-by: Ionut Nechita <ionut.nechita@windriver.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Some nits below.
> ---
> kernel/sched/isolation.c | 24 +++++++++++++++++++++++-
> 1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
> index ef152d401fe2..5c36e33bac50 100644
> --- a/kernel/sched/isolation.c
> +++ b/kernel/sched/isolation.c
> @@ -28,6 +28,17 @@ struct housekeeping {
>
> static struct housekeeping housekeeping;
>
> +/*
> + * Bootmem cpumasks that housekeeping_init() has replaced with kmalloc()ed
Nit: s/has replaced/replaces
> + * copies. They can't be released right there: housekeeping_init() runs once
> + * the page allocator and slab are up, but before page_alloc_init_late() has
> + * initialized the deferred part of the memory map, and memblock_free() then
> + * reaches __free_reserved_area(), which refuses to touch a memory map that
> + * isn't fully initialized yet. Record them instead and release them from a
> + * core_initcall, which runs after page_alloc_init_late().
And I'd split it into 3 paragraphs :)
- the first sentence
- description why that memory can't be released in housekeeping_init()
- Record them ...
> + */
> +static struct cpumask *housekeeping_bootmem_masks[HK_TYPE_MAX] __initdata;
> +
> bool housekeeping_enabled(enum hk_type type)
> {
> return !!(READ_ONCE(housekeeping.flags) & BIT(type));
> @@ -189,10 +200,21 @@ void __init housekeeping_init(void)
> WARN_ON_ONCE(cpumask_empty(omask));
> cpumask_copy(nmask, omask);
> RCU_INIT_POINTER(housekeeping.cpumasks[type], nmask);
> - memblock_free(omask, cpumask_size());
> + housekeeping_bootmem_masks[type] = omask;
> }
> }
>
> +static int __init housekeeping_free_bootmem_masks(void)
> +{
> + enum hk_type type;
> +
> + for (type = 0; type < HK_TYPE_MAX; type++)
> + memblock_free(housekeeping_bootmem_masks[type], cpumask_size());
> +
> + return 0;
> +}
> +core_initcall(housekeeping_free_bootmem_masks);
> +
> static void __init housekeeping_setup_type(enum hk_type type,
> cpumask_var_t housekeeping_staging)
> {
>
> base-commit: 2d2338c93da79b3bfe4b6099a931d9468d539952
> --
> 2.55.0
>
--
Sincerely yours,
Mike.
prev parent reply other threads:[~2026-08-03 6:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260728134016.674388f101f141362598240f@linux-foundation.org>
2026-08-02 11:56 ` [PATCH] sched/isolation: Defer freeing of the bootmem housekeeping cpumasks Ionut Nechita
2026-08-03 6:54 ` Mike Rapoport [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=anA7GhzjZoi293Yy@kernel.org \
--to=rppt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bsegall@google.com \
--cc=bugzilla-daemon@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=frederic@kernel.org \
--cc=ionut.nechita@windriver.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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