Re: [PATCH 01/49] mm/sparse: fix vmemmap accounting imbalance on memory hotplug error

Muchun Song
2026-04-14T03:04:03Z

> On Apr 14, 2026, at 02:35, David Hildenbrand (Arm) <david@kernel.org> wrote:
>
> On 4/5/26 14:51, Muchun Song wrote:
>> In section_activate(), if populate_section_memmap() fails, the error
>> handling path calls section_deactivate() to roll back the state. This
>> approach introduces an accounting imbalance.
>>
>> Since the commit c3576889d87b ("mm: fix accounting of memmap pages"),
>> memmap pages are accounted for only after populate_section_memmap()
>> succeeds. However, section_deactivate() unconditionally decrements the
>> vmemmap account. Consequently, a failure in populate_section_memmap()
>> leads to a negative offset (underflow) in the system's vmemmap tracking.
>>
>> We can fix this by ensuring that the vmemmap accounting is incremented
>> immediately before checking for the success of populate_section_memmap().
>> If populate_section_memmap() fails, the subsequent call to
>> section_deactivate() will decrement the accounting, perfectly offsetting
>> the increment and maintaining balance.
>>
>> Fixes: c3576889d87b ("mm: fix accounting of memmap pages")
>> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
>> ---
>
> Can you send the revised fix separately, please?

No problem.

Muchun,
Thanks.

>
> AI review flagged that recently on one of my series that touched the
> code, thanks for taking it off my todo list :)
>
> --
> Cheers,
>
> David