create_kpti_ng_temp_pgd() was created as an alias for void returning
__create_pgd_mapping_locked() and relied on pgtable_alloc() to BUG_ON()
if an allocation failure occurred. But as __create_pgd_mapping_locked()
has been updated as a part of the error propagation patch to return a
non-void value, update create_kpti_ng_temp_pgd() to act as a wrapper
around __create_pgd_mapping_locked() and BUG_ON() on ret being a non
zero value.
Signed-off-by: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
---
arch/arm64/mm/mmu.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index db7f45ef16574..19cbabceb38bd 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -76,6 +76,14 @@ EXPORT_SYMBOL(empty_zero_page);
static DEFINE_SPINLOCK(swapper_pgdir_lock);
static DEFINE_MUTEX(fixmap_lock);
+#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
+void create_kpti_ng_temp_pgd(pgd_t *pgdir, phys_addr_t phys,
+ unsigned long virt, phys_addr_t size,
+ pgprot_t prot,
+ phys_addr_t (*pgtable_alloc)(enum pgtable_type),
+ int flags);
+#endif
+
void noinstr set_swapper_pgd(pgd_t *pgdp, pgd_t pgd)
{
pgd_t *fixmap_pgdp;
@@ -541,11 +549,17 @@ static void ___create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys,
}
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
-extern __alias(__create_pgd_mapping_locked)
void create_kpti_ng_temp_pgd(pgd_t *pgdir, phys_addr_t phys, unsigned long virt,
phys_addr_t size, pgprot_t prot,
phys_addr_t (*pgtable_alloc)(enum pgtable_type),
- int flags);
+ int flags)
+{
+ int ret = 0;
+
+ ret = __create_pgd_mapping_locked(pgdir, phys, virt, size, prot,
+ pgtable_alloc, flags);
+ BUG_ON(ret);
+}
#endif
static phys_addr_t __pgd_pgtable_alloc(struct mm_struct *mm,
--
2.34.1
On 13.08.25 16:56, Chaitanya S Prakash wrote: > create_kpti_ng_temp_pgd() was created as an alias for void returning > __create_pgd_mapping_locked() and relied on pgtable_alloc() to BUG_ON() > if an allocation failure occurred. But as __create_pgd_mapping_locked() > has been updated as a part of the error propagation patch to return a > non-void value, update create_kpti_ng_temp_pgd() to act as a wrapper > around __create_pgd_mapping_locked() and BUG_ON() on ret being a non > zero value. If my memory serves me right, panic() is preferred in such unexpected early-boot scenarios (BUG_ON is frowned upon), where you can actually print what is going wrong. Which raises the question: could create_kpti_ng_temp_pgd() be __init? __kpti_install_ng_mappings(), the only caller, seems to be. -- Cheers David / dhildenb
Smart! BUG_ON() ends up in the generic “kernel bug” path, which on many distros is configured to continue after printing the back-trace (e.g. panic_on_oops=0). Since a memory-allocation failure in early boot is unrecoverable , we must force a halt. On 8/19/2025 11:41 AM, David Hildenbrand wrote: > On 13.08.25 16:56, Chaitanya S Prakash wrote: >> create_kpti_ng_temp_pgd() was created as an alias for void returning >> __create_pgd_mapping_locked() and relied on pgtable_alloc() to BUG_ON() >> if an allocation failure occurred. But as __create_pgd_mapping_locked() >> has been updated as a part of the error propagation patch to return a >> non-void value, update create_kpti_ng_temp_pgd() to act as a wrapper >> around __create_pgd_mapping_locked() and BUG_ON() on ret being a non >> zero value. > > If my memory serves me right, panic() is preferred in such unexpected > early-boot scenarios (BUG_ON is frowned upon), where you can actually > print what is going wrong.
On 13/08/2025 16:56, Chaitanya S Prakash wrote: > create_kpti_ng_temp_pgd() was created as an alias for void returning > __create_pgd_mapping_locked() and relied on pgtable_alloc() to BUG_ON() > if an allocation failure occurred. But as __create_pgd_mapping_locked() > has been updated as a part of the error propagation patch to return a > non-void value, update create_kpti_ng_temp_pgd() to act as a wrapper > around __create_pgd_mapping_locked() and BUG_ON() on ret being a non > zero value. > > Signed-off-by: Chaitanya S Prakash <chaitanyas.prakash@arm.com> > --- > arch/arm64/mm/mmu.c | 18 ++++++++++++++++-- > 1 file changed, 16 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index db7f45ef16574..19cbabceb38bd 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -76,6 +76,14 @@ EXPORT_SYMBOL(empty_zero_page); > static DEFINE_SPINLOCK(swapper_pgdir_lock); > static DEFINE_MUTEX(fixmap_lock); > > +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 > +void create_kpti_ng_temp_pgd(pgd_t *pgdir, phys_addr_t phys, > + unsigned long virt, phys_addr_t size, > + pgprot_t prot, > + phys_addr_t (*pgtable_alloc)(enum pgtable_type), > + int flags); I'm not sure I understand why we'd now need this declaration? That function should really be declared in some header instead of the strange declaration in cpufeature.c, but that's unrelated to this patch. - Kevin > +#endif > + > void noinstr set_swapper_pgd(pgd_t *pgdp, pgd_t pgd) > { > pgd_t *fixmap_pgdp; > @@ -541,11 +549,17 @@ static void ___create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys, > } > > #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 > -extern __alias(__create_pgd_mapping_locked) > void create_kpti_ng_temp_pgd(pgd_t *pgdir, phys_addr_t phys, unsigned long virt, > phys_addr_t size, pgprot_t prot, > phys_addr_t (*pgtable_alloc)(enum pgtable_type), > - int flags); > + int flags) > +{ > + int ret = 0; > + > + ret = __create_pgd_mapping_locked(pgdir, phys, virt, size, prot, > + pgtable_alloc, flags); > + BUG_ON(ret); > +} > #endif > > static phys_addr_t __pgd_pgtable_alloc(struct mm_struct *mm,
© 2016 - 2025 Red Hat, Inc.