[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aVfaraCze9es6Vd8@e129823.arm.com>
Date: Fri, 2 Jan 2026 14:48:13 +0000
From: Yeoreum Yun <yeoreum.yun@....com>
To: Ryan Roberts <ryan.roberts@....com>
Cc: catalin.marinas@....com, will@...nel.org, akpm@...ux-foundation.org,
david@...nel.org, kevin.brodsky@....com, quic_zhenhuah@...cinc.com,
dev.jain@....com, yang@...amperecomputing.com,
chaitanyas.prakash@....com, bigeasy@...utronix.de,
clrkwllms@...nel.org, rostedt@...dmis.org,
lorenzo.stoakes@...cle.com, ardb@...nel.org, jackmanb@...gle.com,
vbabka@...e.cz, mhocko@...e.com,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
linux-rt-devel@...ts.linux.dev
Subject: Re: [PATCH v3 2/2] arm64: mmu: avoid allocating pages while
installing ng-mapping for KPTI
Hi Ryan,
> On 18/12/2025 19:47, Yeoreum Yun wrote:
> > The current __kpti_install_ng_mappings() allocates a temporary PGD
> > while installing the NG mapping for KPTI under stop_machine(),
> > using GFP_ATOMIC.
> >
> > This is fine in the non-PREEMPT_RT case. However, it becomes a problem
> > under PREEMPT_RT because generic memory allocation/free APIs
> > (e.g., pgtable_alloc(), __get_free_pages(), etc.) cannot be invoked
> > in a non-preemptible context, except for the *_nolock() variants.
> > These generic allocators may sleep due to their use of spin_lock().
> >
> > In other words, calling __get_free_pages(), even with GFP_ATOMIC,
> > is not allowed in __kpti_install_ng_mappings(), which is executed by
> > the stopper thread where preemption is disabled under PREEMPT_RT.
> >
> > To address this, preallocate the page needed for the temporary PGD
> > before invoking __kpti_install_ng_mappings() via stop_machine().
> >
> > Fixes: 47546a1912fc ("arm64: mm: install KPTI nG mappings with MMU enabled")
> > Signed-off-by: Yeoreum Yun <yeoreum.yun@....com>
> > Reviewed-by: Ryan Roberts <ryan.roberts@....com>
> > ---
> > arch/arm64/mm/mmu.c | 22 +++++++++++++---------
> > 1 file changed, 13 insertions(+), 9 deletions(-)
> >
> > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> > index 96a9fa505e71..9ad9612728e6 100644
> > --- a/arch/arm64/mm/mmu.c
> > +++ b/arch/arm64/mm/mmu.c
> > @@ -1369,7 +1369,7 @@ static phys_addr_t __init kpti_ng_pgd_alloc(enum pgtable_type type)
> > return kpti_ng_temp_alloc;
> > }
> >
> > -static int __init __kpti_install_ng_mappings(void *__unused)
> > +static int __init __kpti_install_ng_mappings(void *data)
> > {
> > typedef void (kpti_remap_fn)(int, int, phys_addr_t, unsigned long);
> > extern kpti_remap_fn idmap_kpti_install_ng_mappings;
> > @@ -1377,10 +1377,9 @@ static int __init __kpti_install_ng_mappings(void *__unused)
> >
> > int cpu = smp_processor_id();
> > int levels = CONFIG_PGTABLE_LEVELS;
> > - int order = order_base_2(levels);
> > u64 kpti_ng_temp_pgd_pa = 0;
> > pgd_t *kpti_ng_temp_pgd;
> > - u64 alloc = 0;
> > + u64 alloc = *(u64 *)data;
> >
> > if (levels == 5 && !pgtable_l5_enabled())
> > levels = 4;
> > @@ -1391,8 +1390,6 @@ static int __init __kpti_install_ng_mappings(void *__unused)
> >
> > if (!cpu) {
> > int ret;
> > -
> > - alloc = __get_free_pages(GFP_ATOMIC | __GFP_ZERO, order);
> > kpti_ng_temp_pgd = (pgd_t *)(alloc + (levels - 1) * PAGE_SIZE);
> > kpti_ng_temp_alloc = kpti_ng_temp_pgd_pa = __pa(kpti_ng_temp_pgd);
> >
> > @@ -1423,16 +1420,17 @@ static int __init __kpti_install_ng_mappings(void *__unused)
> > remap_fn(cpu, num_online_cpus(), kpti_ng_temp_pgd_pa, KPTI_NG_TEMP_VA);
> > cpu_uninstall_idmap();
> >
> > - if (!cpu) {
> > - free_pages(alloc, order);
> > + if (!cpu)
> > arm64_use_ng_mappings = true;
> > - }
> >
> > return 0;
> > }
> >
> > void __init kpti_install_ng_mappings(void)
> > {
> > + int order = order_base_2(CONFIG_PGTABLE_LEVELS);
> > + u64 alloc;
> > +
>
> nit: Restore the blank line between the variable definitioins and the logic.
Okay. I'll restore that line.
Thanks!
--
Sincerely,
Yeoreum Yun
Powered by blists - more mailing lists