From: Linu Cherian <linu.cherian@arm.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Ryan Roberts <ryan.roberts@arm.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: Anshuman Khandual <anshuman.khandual@arm.com>,
Kevin Brodsky <kevin.brodsky@arm.com>,
Zhenhua Huang <quic_zhenhuah@quicinc.com>,
Dev Jain <dev.jain@arm.com>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Yang Shi <yang@os.amperecomputing.com>,
Linu Cherian <linu.cherian@arm.com>
Subject: [PATCH v3 0/2] arm64/mm: prevent panic on -ENOMEM in arch_add_memory()
Date: Wed, 15 Oct 2025 16:57:56 +0530 [thread overview]
Message-ID: <20251015112758.2701604-1-linu.cherian@arm.com> (raw)
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()/panic if
pgtable_alloc() encounters failure at the time of boot, a wrapper is
created around __create_pgd_mapping() which is designed to panic() 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.
This theoretical bug was identified by Ryan Roberts<ryan.roberts@arm.com>
as a part of code review of the following series[1].
[1] https://lore.kernel.org/linux-arm-kernel/20250304222018.615808-4-yang@os.amperecomputing.com/
Changelog
v3:
* Added a Fixes tag to patch 1 and CCed to stable
* Fixed a maybe-uninitialized case in alloc_init_pud
* Update pgd_pgtable_alloc_init_mm to make use of
pgd_pgtable_alloc_init_mm_gfp
* Few other trivial cleanups
v2:
* With cleanup merged as part of, "arm64: mm: Move KPTI helpers to mmu.c"
changes in patch 2(v1) got much simplified and squashed to patch 1 itself.
* Patch 2 now does a trivial renaming for better readability
* Make use of INVALID_PHYS_ADDR for error checks instead of 0.
* Do early function return where we do not have any
common cleanup in return path
* Remove redundant variable initialization
* Changed BUG_ON to panic
* Renamed ___create_pgd_mapping to early_create_pgd_mapping
Chaitanya S Prakash (1):
arm64/mm: Allow __create_pgd_mapping() to propagate pgtable_alloc()
errors
Linu Cherian (1):
arm64/mm: Rename try_pgd_pgtable_alloc_init_mm
arch/arm64/mm/mmu.c | 216 +++++++++++++++++++++++++++-----------------
1 file changed, 135 insertions(+), 81 deletions(-)
--
2.43.0
next reply other threads:[~2025-10-15 11:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 11:27 Linu Cherian [this message]
2025-10-15 11:27 ` [PATCH v3 1/2] arm64/mm: Allow __create_pgd_mapping() to propagate pgtable_alloc() errors Linu Cherian
2025-10-15 15:02 ` Ryan Roberts
2025-10-15 16:05 ` Kevin Brodsky
2025-10-16 6:05 ` Dev Jain
2025-10-17 5:24 ` Anshuman Khandual
2025-10-17 6:59 ` Kevin Brodsky
2025-10-15 11:27 ` [PATCH v3 2/2] arm64/mm: Rename try_pgd_pgtable_alloc_init_mm Linu Cherian
2025-10-15 15:03 ` Ryan Roberts
2025-10-15 16:06 ` Kevin Brodsky
2025-10-16 6:07 ` Dev Jain
2025-10-17 5:28 ` Anshuman Khandual
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251015112758.2701604-1-linu.cherian@arm.com \
--to=linu.cherian@arm.com \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=catalin.marinas@arm.com \
--cc=dev.jain@arm.com \
--cc=kevin.brodsky@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=quic_zhenhuah@quicinc.com \
--cc=ryan.roberts@arm.com \
--cc=will@kernel.org \
--cc=yang@os.amperecomputing.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).