From nobody Tue Feb 10 04:03:29 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44B64342158 for ; Mon, 5 Jan 2026 20:23:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767644624; cv=none; b=Wyo5zN5wzBj+hAheB2R7qpDk9y5EHxOZl8dElHc9HXc/pZaG1JM5m/NK9DOkb5f389rVhZodfBmgQdo91y3tzys0tspNAUloDsRKSVx5QLo+RJx7UG1RdQytu8HhDakyZTZJDF9wYghL1ckn7FVvSHYIeB8lPrpK/PdY9WJkV3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767644624; c=relaxed/simple; bh=xo8pt29quTN1cNNsi33HDNe2YtAJA7SwFJkZtiBaceo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s6k1hAwkxN+ympldnflj9Irvnop8l8XoIVajQ1Ew72fdFYgSAxkZmD0HshcxZjCoSL4O09GHIQiCsNiTiMMjzpnDSz03JLq5isP4FnOvzdXoVSiibEDd95qme6BjYXRa2t8M+xfhCStJoG1sGYNt3GwoNW18NEMrOm0VIDJ6mFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EBD8C15A1; Mon, 5 Jan 2026 12:23:35 -0800 (PST) Received: from e129823.cambridge.arm.com (e129823.arm.com [10.1.197.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C59AA3F6A8; Mon, 5 Jan 2026 12:23:39 -0800 (PST) From: Yeoreum Yun To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev Cc: catalin.marinas@arm.com, will@kernel.org, ryan.roberts@arm.com, akpm@linux-oundation.org, david@kernel.org, kevin.brodsky@arm.com, quic_zhenhuah@quicinc.com, dev.jain@arm.com, yang@os.amperecomputing.com, chaitanyas.prakash@arm.com, bigeasy@linutronix.de, clrkwllms@kernel.org, rostedt@goodmis.org, lorenzo.stoakes@oracle.com, ardb@kernel.org, jackmanb@google.com, vbabka@suse.cz, mhocko@suse.com, Yeoreum Yun Subject: [PATCH v5 3/3] arm64: mmu: avoid allocating pages while installing ng-mapping for KPTI Date: Mon, 5 Jan 2026 20:23:28 +0000 Message-Id: <20260105202328.2418990-4-yeoreum.yun@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260105202328.2418990-1-yeoreum.yun@arm.com> References: <20260105202328.2418990-1-yeoreum.yun@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Ryan Roberts --- arch/arm64/mm/mmu.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 120874a2d35b..6ea5b80ab54f 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1360,7 +1360,7 @@ static phys_addr_t __init kpti_ng_pgd_alloc(enum pgta= ble_type type) return kpti_ng_temp_alloc; } =20 -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; @@ -1368,10 +1368,9 @@ static int __init __kpti_install_ng_mappings(void *_= _unused) =20 int cpu =3D smp_processor_id(); int levels =3D CONFIG_PGTABLE_LEVELS; - int order =3D order_base_2(levels); u64 kpti_ng_temp_pgd_pa =3D 0; pgd_t *kpti_ng_temp_pgd; - u64 alloc =3D 0; + u64 alloc =3D *(u64 *)data; =20 if (levels =3D=3D 5 && !pgtable_l5_enabled()) levels =3D 4; @@ -1382,8 +1381,6 @@ static int __init __kpti_install_ng_mappings(void *__= unused) =20 if (!cpu) { int ret; - - alloc =3D __get_free_pages(GFP_ATOMIC | __GFP_ZERO, order); kpti_ng_temp_pgd =3D (pgd_t *)(alloc + (levels - 1) * PAGE_SIZE); kpti_ng_temp_alloc =3D kpti_ng_temp_pgd_pa =3D __pa(kpti_ng_temp_pgd); =20 @@ -1414,16 +1411,16 @@ 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(); =20 - if (!cpu) { - free_pages(alloc, order); + if (!cpu) arm64_use_ng_mappings =3D true; - } =20 return 0; } =20 void __init kpti_install_ng_mappings(void) { + int order =3D order_base_2(CONFIG_PGTABLE_LEVELS); + u64 alloc; /* Check whether KPTI is going to be used */ if (!arm64_kernel_unmapped_at_el0()) return; @@ -1436,8 +1433,14 @@ void __init kpti_install_ng_mappings(void) if (arm64_use_ng_mappings) return; =20 + alloc =3D __get_free_pages(GFP_KERNEL | __GFP_ZERO, order); + if (!alloc) + panic("Failed to alloc page tables\n"); + init_idmap_kpti_bbml2_flag(); - stop_machine(__kpti_install_ng_mappings, NULL, cpu_online_mask); + stop_machine(__kpti_install_ng_mappings, &alloc, cpu_online_mask); + + free_pages(alloc, order); } =20 static pgprot_t __init kernel_exec_prot(void) --=20 LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}