[PATCH 0/2] arm64/mm: prevent panic on -ENOMEM in arch_add_memory()
From: Chaitanya S Prakash
Date: Wed Aug 13 2025 - 11:04:14 EST
arch_add_memory() acts as a means to hotplug memory into a system. It
invokes __create_pgd_mapping() which further unwinds to call
pgtable_alloc(). Initially, this path was only invoked during early boot
and therefore it made sense to BUG_ON() in case pgtable_alloc() failed.
Now however, we risk running into a kernel crash if we try to hotplug
memory into a system that is already extremely tight on available
memory. This is undesirable and hence __create_pgd_mapping() and it's
helpers are reworked to be able to propagate the error from
pgtable_alloc() allowing the system to fail gracefully.
Keeping in mind that it is still essential to BUG_ON() if
pgtable_alloc() encounters failure at the time of boot, a wrapper is
created around __create_pgd_mapping() which is designed to BUG_ON() if
it encounters a non-zero return value. This wrapper is then invoked from
the init functions instead of __create_pgd_mapping(), thereby keeping the
original functionality intact.
Lastly, create_kpti_ng_temp_pgd() which originally acted as an alias for
the void returning __create_pgd_mapping_locked() has now been updated
accordingly to handle the return value and BUG_ON() if needed.
This theoretical bug was identified by Ryan Roberts<ryan.roberts@xxxxxxx>
as a part of code review of the following series[1].
[1] https://lore.kernel.org/linux-arm-kernel/20250304222018.615808-4-yang@xxxxxxxxxxxxxxxxxxxxxx/
Cc: Ryan Roberts <ryan.roberts@xxxxxxx>
Cc: Yang Shi <yang@xxxxxxxxxxxxxxxxxxxxxx>
Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
Cc: Will Deacon <will@xxxxxxxxxx>
Cc: Kevin Brodsky <kevin.brodsky@xxxxxxx>
Cc: Anshuman Khandual <anshuman.khandual@xxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Zhenhua Huang <quic_zhenhuah@xxxxxxxxxxx>
Cc: Joey Gouly <joey.gouly@xxxxxxx>
Cc: Chaitanya S Prakash <chaitanyas.prakash@xxxxxxx>
Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Chaitanya S Prakash (2):
arm64/mm: Allow __create_pgd_mapping() to propagate pgtable_alloc()
errors
arm64/mm: Update create_kpti_ng_temp_pgd() to handle pgtable_alloc
failure
arch/arm64/mm/mmu.c | 174 +++++++++++++++++++++++++++++++++-----------
1 file changed, 133 insertions(+), 41 deletions(-)
--
2.34.1