From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 513FD19A288 for ; Mon, 3 Aug 2026 06:54:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785740066; cv=none; b=pffguhE9lxYOJxG2xFv+6rQDSysTJmZECdpMVbOmnoMUbkLAuHaCAPkMiBg8pXPke09t3OKH1hEpYq+xSM5K17pvBOaJfG/L2OguF0/nlomLjIsFfUVX4IKwG9RvabNMespJoAS1cLQazCJAMsGo7NSiFv3Ez2VAXgfi42vP/rY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785740066; c=relaxed/simple; bh=E6bODKnl5T9dwC+5wW1rFS/27eYT5EhWWzMOlszPhbA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Pcls7/ZshBGo2AHPGEY2o2kucoc7QkBGkzHFakL+5rC42GWULkNjNpwpxwQhWoIpOdSeqItuOpUzKyY9Qg57ptpPHapvy9h3CeOv4FWoLonXHiO6n1jXckq3kil/CU1i5YqCeowfgAQW6CelW5GN7PuUyKUbnzmUbheCWX8u2lk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nd47rhTt; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nd47rhTt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FAC71F000E9; Mon, 3 Aug 2026 06:54:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785740065; bh=bGmx5lhbVnAxzqXa5NcpYNSJJkO7XomAJLKorNkVBLQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=nd47rhTtI+3syd5qNqlozDRPj+MZsHdtqj4UsUwriigszD5j7vQspVOF6993/8yAk tMmb/AvvSrKNr4wmz1jbEy5Dz8vekFnPcjJM8mlxZiRKFXGGgIPMqLwugUlP58GnwP 4DhEc0re1DgvbQBFJfFhlOlE0rf4kdJ887Vo0M/OCKPFcraNGyW/SYnMSxlS0Ro+s9 nHj/Ux+5IaWLEUnlHazmHs2v7X0JdxV6La2QuAcgXedBK5VOqsozxsHZLotFBeb29U Bb2++w1FF8FPOxtwbJtnAtj7H6iKp65RtL7ZKFVt4R7RyvXeiSNRzXkVsXWFu9i9at sueamA+91bxZg== Date: Mon, 3 Aug 2026 09:54:18 +0300 From: Mike Rapoport To: Ionut Nechita Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Frederic Weisbecker , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Andrew Morton , 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 Message-ID: References: <20260728134016.674388f101f141362598240f@linux-foundation.org> <20260802115623.110513-1-ionut.nechita@windriver.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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) > Signed-off-by: Ionut Nechita Acked-by: Mike Rapoport (Microsoft) 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.