Re: [PATCH V4 2/2] arm64/mm: Reject memory removal that splits a kernel leaf mapping

From: Anshuman Khandual

Date: Thu Mar 05 2026 - 21:46:39 EST




On 05/03/26 6:09 PM, David Hildenbrand (Arm) wrote:
> On 3/5/26 13:37, David Hildenbrand (Arm) wrote:
>> On 3/5/26 06:31, Anshuman Khandual wrote:
>>> Linear and vmemmap mappings that get torn down during a memory hot remove
>>> operation might contain leaf level entries on any page table level. If the
>>> requested memory range's linear or vmemmap mappings falls within such leaf
>>> entries, new mappings need to be created for the remaining memory mapped on
>>> the leaf entry earlier, following standard break before make aka BBM rules.
>>> But kernel cannot tolerate BBM and hence remapping to fine grained leaves
>>> would not be possible on systems without BBML2_NOABORT.
>>>
>>> Currently memory hot remove operation does not perform such restructuring,
>>> and so removing memory ranges that could split a kernel leaf level mapping
>>> need to be rejected.
>>>
>>> While memory_hotplug.c does appear to permit hot removing arbitrary ranges
>>> of memory, the higher layers that drive memory_hotplug (e.g. ACPI, virtio,
>>> ...) all appear to treat memory as fixed size devices. So it is impossible
>>> to hot unplug a different amount than was previously hot plugged, and hence
>>> we should never see a rejection in practice, but adding the check makes us
>>> robust against a future change.
>>>
>>> Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
>>> Cc: Will Deacon <will@xxxxxxxxxx>
>>> Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
>>> Cc: linux-kernel@xxxxxxxxxxxxxxx
>>> Link: https://lore.kernel.org/all/aWZYXhrT6D2M-7-N@willie-the-truck/
>>> Reviewed-by: Ryan Roberts <ryan.roberts@xxxxxxx>
>>> Suggested-by: Ryan Roberts <ryan.roberts@xxxxxxx>
>>> Signed-off-by: Anshuman Khandual <anshuman.khandual@xxxxxxx>
>>> ---
>>
>> [...]
>>
>>> +
>>> + /*
>>> + * PFN range's linear map edges are leaf entry aligned
>>> + */
>>
>> Nit: single-line comments are usually written as
>>
>> /* ... */
>>
>>> + start = __phys_to_virt(phys_start);
>>> + end = __phys_to_virt(phys_end);
>>> + if (addr_splits_kernel_leaf(start) || addr_splits_kernel_leaf(end)) {
>>> + pr_warn("[%lx %lx] splits a leaf entry in linear map\n",
>>> + phys_start, phys_end);
>>> + return false;
>>> + }
>>> +
>>> + /*
>>> + * PFN range's vmemmap edges are leaf entry aligned
>>> + */
>>
>> Dito.
>>
>> LGTM, thanks!
>>
>> Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>>
>
> In fact,
>
> Reviewed-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>
> :)
>

Thanks for the review. Sure, will respin with the comment fixes next week.