[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+i-1C2e7QNTy5u=HF7tLsLXLq4xYbMTCbNjWGAxHz4uwgR05g@mail.gmail.com>
Date: Sat, 13 Dec 2025 16:05:20 +0900
From: Brendan Jackman <jackmanb@...gle.com>
To: Yeoreum Yun <yeoreum.yun@....com>
Cc: akpm@...ux-foundation.org, david@...nel.org, lorenzo.stoakes@...cle.com,
Liam.Howlett@...cle.com, vbabka@...e.cz, rppt@...nel.org, surenb@...gle.com,
mhocko@...e.com, ast@...nel.org, daniel@...earbox.net, andrii@...nel.org,
martin.lau@...ux.dev, eddyz87@...il.com, song@...nel.org,
yonghong.song@...ux.dev, john.fastabend@...il.com, kpsingh@...nel.org,
sdf@...ichev.me, haoluo@...gle.com, jolsa@...nel.org, hannes@...xchg.org,
ziy@...dia.com, bigeasy@...utronix.de, clrkwllms@...nel.org,
rostedt@...dmis.org, catalin.marinas@....com, will@...nel.org,
ryan.roberts@....com, kevin.brodsky@....com, dev.jain@....com,
yang@...amperecomputing.com, linux-mm@...ck.org, linux-kernel@...r.kernel.org,
bpf@...r.kernel.org, linux-rt-devel@...ts.linux.dev,
linux-arm-kernel@...ts.infradead.org
Subject: Re: [PATCH 2/2] arm64: mmu: use pagetable_alloc_nolock() while stop_machine()
On Sat, 13 Dec 2025 at 01:18, Yeoreum Yun <yeoreum.yun@....com> wrote:
>
> linear_map_split_to_ptes() and __kpti_install_ng_mappings()
> are called as callback of stop_machine().
> That means these functions context are preemption disabled.
>
> Unfortunately, under PREEMPT_RT, the pagetable_alloc() or
> __get_free_pages() couldn't be called in this context
> since spin lock that becomes sleepable on RT,
> potentially causing a sleep during page allocation.
>
> To address this, pagetable_alloc_nolock().
>
> Signed-off-by: Yeoreum Yun <yeoreum.yun@....com>
> ---
> arch/arm64/mm/mmu.c | 23 ++++++++++++++++++-----
> 1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index 2ba01dc8ef82..0e98606d8c4c 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -475,10 +475,15 @@ static void __create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys,
> static phys_addr_t __pgd_pgtable_alloc(struct mm_struct *mm, gfp_t gfp,
> enum pgtable_type pgtable_type)
> {
> - /* Page is zeroed by init_clear_pgtable() so don't duplicate effort. */
> - struct ptdesc *ptdesc = pagetable_alloc(gfp & ~__GFP_ZERO, 0);
> + struct ptdesc *ptdesc;
> phys_addr_t pa;
>
> + /* Page is zeroed by init_clear_pgtable() so don't duplicate effort. */
> + if (gfpflags_allow_spinning(gfp))
> + ptdesc = pagetable_alloc(gfp & ~__GFP_ZERO, 0);
> + else
> + ptdesc = pagetable_alloc_nolock(gfp & ~__GFP_ZERO, 0);
> +
> if (!ptdesc)
> return INVALID_PHYS_ADDR;
>
> @@ -869,6 +874,7 @@ static int __init linear_map_split_to_ptes(void *__unused)
> unsigned long kstart = (unsigned long)lm_alias(_stext);
> unsigned long kend = (unsigned long)lm_alias(__init_begin);
> int ret;
> + gfp_t gfp = IS_ENABLED(CONFIG_PREEMPT_RT) ? __GFP_HIGH : GFP_ATOMIC;
>
> /*
> * Wait for all secondary CPUs to be put into the waiting area.
> @@ -881,9 +887,9 @@ static int __init linear_map_split_to_ptes(void *__unused)
> * PTE. The kernel alias remains static throughout runtime so
> * can continue to be safely mapped with large mappings.
> */
> - ret = range_split_to_ptes(lstart, kstart, GFP_ATOMIC);
> + ret = range_split_to_ptes(lstart, kstart, gfp);
> if (!ret)
> - ret = range_split_to_ptes(kend, lend, GFP_ATOMIC);
> + ret = range_split_to_ptes(kend, lend, gfp);
> if (ret)
> panic("Failed to split linear map\n");
> flush_tlb_kernel_range(lstart, lend);
> @@ -1207,7 +1213,14 @@ static int __init __kpti_install_ng_mappings(void *__unused)
> remap_fn = (void *)__pa_symbol(idmap_kpti_install_ng_mappings);
>
> if (!cpu) {
> - alloc = __get_free_pages(GFP_ATOMIC | __GFP_ZERO, order);
> + if (IS_ENABLED(CONFIG_PREEMPT_RT))
> + alloc = (u64) pagetable_alloc_nolock(__GFP_HIGH | __GFP_ZERO, order);
> + else
> + alloc = __get_free_pages(GFP_ATOMIC | __GFP_ZERO, order);
> +
> + if (!alloc)
> + panic("Failed to alloc kpti_ng_pgd\n");
> +
I don't have the context on what this code is doing so take this with
a grain of salt, but...
The point of the _nolock alloc is to give the allocator an excuse to
fail. Panicking on that failure doesn't seem like a great idea to me?
Powered by blists - more mailing lists