Re: [PATCH] mm/sparse: fix preinited section_mem_map clobbering on failure path
From: Muchun Song
Date: Tue Mar 31 2026 - 22:38:58 EST
> On Apr 1, 2026, at 04:10, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Tue, 31 Mar 2026 19:37:24 +0800 Muchun Song <songmuchun@xxxxxxxxxxxxx> wrote:
>
>> sparse_init_nid() is careful to leave alone every section whose vmemmap
>> has already been set up by sparse_vmemmap_init_nid_early(); it only
>> clears section_mem_map for the rest:
>>
>> if (!preinited_vmemmap_section(ms))
>> ms->section_mem_map = 0;
>>
>> A leftover line after that conditional block
>>
>> ms->section_mem_map = 0;
>>
>> was supposed to be deleted but was missed in the failure path, causing the
>> field to be overwritten for all sections when memory allocation fails,
>> effectively destroying the pre-initialization check.
>>
>> Drop the stray assignment so that preinited sections retain their
>> already valid state.
>
> Here I go again ;) Are there userspace impacts?
Those pre-inited sections (HugeTLB pages) are not activated. However, such
failures are extremely rare, so I don't see any major issues.
>
> AI review thinks it found a different bug:
> https://sashiko.dev/#/patchset/20260331113724.2080833-1-songmuchun@xxxxxxxxxxxxx
I don't think the issue reported by AI is a real problem, because the
allocation of sparse_usagebuf has already taken these hugetlb sections
into account.
Thanks.