[PATCH 09/49] mm: panic on memory allocation failure in sparse_init_nid()

Muchun Song muchun.song at linux.dev
Tue Apr 28 17:02:14 AEST 2026



> On Apr 28, 2026, at 14:56, Mike Rapoport <rppt at kernel.org> wrote:
> 
> On Sun, Apr 05, 2026 at 08:52:00PM +0800, Muchun Song wrote:
>> When vmemmap pages allocation or usemap allocation fails, sparse_init_nid()
>> currently only marks the corresponding section as non-present. However,
>> subsequent code like memmap_init() iterating over PFNs does not check for
>> non-present sections, leading to invalid memory access (additional,
>> subsection_map_init() accessing the unallocated usemap as well).
>> 
>> It is complex to audit and fix all boot-time PFN iterators to handle these
>> partially initialized sections correctly. Since vmemmap and usemap allocation
>> failures are extremely rare during early boot, the more appropriate approach
>> is to expose the problem as early as possible.
>> 
>> Therefore, use BUG_ON() to panic immediately if allocation fails, instead of
>> attempting a partial recovery that leads to obscure crashes later.
>> 
>> Signed-off-by: Muchun Song <songmuchun at bytedance.com>
> 
> Acked-by: Mike Rapoport (Microsoft) <rppt at kernel.org>

Thanks.

> 
>> ---
>> mm/sparse.c | 37 ++++++++-----------------------------
>> 1 file changed, 8 insertions(+), 29 deletions(-)
>> 
>> diff --git a/mm/sparse.c b/mm/sparse.c
>> index effdac6b0ab1..5c12b979a618 100644
>> --- a/mm/sparse.c
>> +++ b/mm/sparse.c
>> @@ -354,19 +354,15 @@ static void __init sparse_init_nid(int nid, unsigned long pnum_begin,
>>    unsigned long map_count)
>> {
>> 	unsigned long pnum;
>> - 	struct page *map;
>> - 	struct mem_section *ms;
>> -
>> - 	if (sparse_usage_init(nid, map_count)) {
>> - 		pr_err("%s: node[%d] usemap allocation failed", __func__, nid);
>> - 		goto failed;
>> - 	}
>> 
>> + 	if (sparse_usage_init(nid, map_count))
>> + 		panic("The node[%d] usemap allocation failed\n", nid);
> 
> Please consider using memblock_alloc_or_panic() in sparse_usage_init(), it
> would simplify the code even more.

Hi Mike,

Yes. I have several more updates for v2. Please hold off on reviewing
the current version to avoid wasting your time; I’ll send the new one
over shortly.

Thanks.


More information about the Linuxppc-dev mailing list