mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] arm64: mm: Fix a TLBI operand and a TTBR1 write in the KPTI nG rewrite
@ 2026-12-03 13:25 Fuad Tabba
  2026-12-03 13:25 ` [PATCH 1/2] arm64: mm: Mask the TLBI operand in kpti_map_pgtbl() Fuad Tabba
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Fuad Tabba @ 2026-12-03 13:25 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon
  Cc: Mark Rutland, Ard Biesheuvel, Ryan Roberts, Anshuman Khandual,
	Kevin Brodsky, Vladimir Murzin, Carl Worth, Linu Cherian,
	Yeoreum Yun, linux-arm-kernel, linux-kernel, Fuad Tabba

Hi folks,

This series fixes a TLBI operand and a TTBR1_EL1 write in
idmap_kpti_install_ng_mappings(). Both came up while I was working on
the ISB fix to the same code [1].

The first masks the TLBI operand in kpti_map_pgtbl(). Its upper bits
hold a wrong TTL hint on 4K and 16K kernels, which can leave kernel
mappings global. I couldn't find a CPU with FEAT_TTL that requires
KPTI, so hitting this takes kpti=on. The Falkor workaround in
tramp_map_kernel has the same unmasked operand. I left it alone, as
AFAICT the CPUs with that erratum predate FEAT_TTL.

The second converts the temporary pgd's address before writing it to
TTBR1_EL1, which changes the value only for tables above 2^48 on a
52-bit PA kernel.

Both bugs were introduced by commit 47546a1912fc4 ("arm64: mm: install
KPTI nG mappings with MMU enabled"). I left out the Fixes: tags, as I
don't think either is worth a backport.

Tested on QEMU (4K, and 64K with 52-bit PA) and on FVP, with "nokaslr
kpti=on". The second bug reproduces on QEMU with RAM placed at 2^48.
Without the patch the boot hangs, and with it the kernel boots. I
couldn't reproduce the first, as QEMU ignores the TTL hint and on FVP
the patch doesn't change which mappings end up global.

Based on Linux 7.4-rc1 (6628e7d4c6b25; also applies to arm64
for-next/fixes a7e632493acf3).

Cheers,
/fuad

[1] https://lore.kernel.org/all/20261120121638.194154-1-fuad.tabba@linux.dev/

Fuad Tabba (2):
  arm64: mm: Mask the TLBI operand in kpti_map_pgtbl()
  arm64: mm: Convert the temporary KPTI pgd address for TTBR1_EL1

 arch/arm64/mm/proc.S | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)


base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
-- 
2.47.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] arm64: mm: Mask the TLBI operand in kpti_map_pgtbl()
  2026-12-03 13:25 [PATCH 0/2] arm64: mm: Fix a TLBI operand and a TTBR1 write in the KPTI nG rewrite Fuad Tabba
@ 2026-12-03 13:25 ` Fuad Tabba
  2026-12-03 13:25 ` [PATCH 2/2] arm64: mm: Convert the temporary KPTI pgd address for TTBR1_EL1 Fuad Tabba
  2026-12-03 14:28 ` [PATCH 0/2] arm64: mm: Fix a TLBI operand and a TTBR1 write in the KPTI nG rewrite Ard Biesheuvel
  2 siblings, 0 replies; 4+ messages in thread
From: Fuad Tabba @ 2026-12-03 13:25 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon
  Cc: Mark Rutland, Ard Biesheuvel, Ryan Roberts, Anshuman Khandual,
	Kevin Brodsky, Vladimir Murzin, Carl Worth, Linu Cherian,
	Yeoreum Yun, linux-arm-kernel, linux-kernel, Fuad Tabba

kpti_map_pgtbl(), added by commit 47546a1912fc4 ("arm64: mm: install
KPTI nG mappings with MMU enabled"), maps each page-table page at a
fixed address near the top of the address space, after invalidating the
address with TLBI VAAE1.

The operand is the address shifted right by 12, so its upper bits end
up in the TTL field as a hint for a 64K level 3 entry. On a 4K or 16K
kernel the hint is wrong, and a CPU with FEAT_TTL isn't required to
invalidate the old translation. idmap_kpti_install_ng_mappings() can
then read the previous table through it instead of the next one, whose
mappings stay global with KPTI enabled.

Mask the operand down to VA[55:12], matching __TLBI_VADDR().

Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
 arch/arm64/mm/proc.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index 12aacc74f7647..e122622838ff3 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -252,7 +252,7 @@ SYM_FUNC_ALIAS(__pi_idmap_cpu_replace_ttbr1, idmap_cpu_replace_ttbr1)
 	str	xzr, [temp_pte, #8 * (\level + 2)]	// break before make
 	dsb	nshst
 	add	pte, temp_pte, #PAGE_SIZE * (\level + 2)
-	lsr	pte, pte, #12
+	ubfx	pte, pte, #12, #44
 	tlbi	vaae1, pte
 	dsb	nsh
 	isb
-- 
2.47.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] arm64: mm: Convert the temporary KPTI pgd address for TTBR1_EL1
  2026-12-03 13:25 [PATCH 0/2] arm64: mm: Fix a TLBI operand and a TTBR1 write in the KPTI nG rewrite Fuad Tabba
  2026-12-03 13:25 ` [PATCH 1/2] arm64: mm: Mask the TLBI operand in kpti_map_pgtbl() Fuad Tabba
@ 2026-12-03 13:25 ` Fuad Tabba
  2026-12-03 14:28 ` [PATCH 0/2] arm64: mm: Fix a TLBI operand and a TTBR1 write in the KPTI nG rewrite Ard Biesheuvel
  2 siblings, 0 replies; 4+ messages in thread
From: Fuad Tabba @ 2026-12-03 13:25 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon
  Cc: Mark Rutland, Ard Biesheuvel, Ryan Roberts, Anshuman Khandual,
	Kevin Brodsky, Vladimir Murzin, Carl Worth, Linu Cherian,
	Yeoreum Yun, linux-arm-kernel, linux-kernel, Fuad Tabba

Since commit 47546a1912fc4 ("arm64: mm: install KPTI nG mappings with
MMU enabled"), idmap_kpti_install_ng_mappings() writes the address of
the temporary pgd to TTBR1_EL1 without the phys_to_ttbr conversion. For
a pgd above 2^48 with CONFIG_ARM64_PA_BITS_52, the CPU walks from the
wrong table and the boot hangs.

The kernel image is kept below 2^48, but this pgd comes from the page
allocator. Systems aren't known to have RAM that high.

Use load_ttbr1, which does the conversion.

Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
 arch/arm64/mm/proc.S | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index e122622838ff3..5b95489152a78 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -313,9 +313,7 @@ SYM_TYPED_FUNC_START(idmap_kpti_install_ng_mappings)
 
 	/* Switch to the temporary page tables on this CPU only */
 	__idmap_cpu_set_reserved_ttbr1 x8, x9
-	offset_ttbr1 temp_pgd_phys, x8
-	msr	ttbr1_el1, temp_pgd_phys
-	isb
+	load_ttbr1 temp_pgd_phys, x8, x9
 
 	mov	temp_pte, x5
 	mov_q	pte_flags, KPTI_NG_PTE_FLAGS
-- 
2.47.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] arm64: mm: Fix a TLBI operand and a TTBR1 write in the KPTI nG rewrite
  2026-12-03 13:25 [PATCH 0/2] arm64: mm: Fix a TLBI operand and a TTBR1 write in the KPTI nG rewrite Fuad Tabba
  2026-12-03 13:25 ` [PATCH 1/2] arm64: mm: Mask the TLBI operand in kpti_map_pgtbl() Fuad Tabba
  2026-12-03 13:25 ` [PATCH 2/2] arm64: mm: Convert the temporary KPTI pgd address for TTBR1_EL1 Fuad Tabba
@ 2026-12-03 14:28 ` Ard Biesheuvel
  2 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2026-12-03 14:28 UTC (permalink / raw)
  To: Fuad Tabba, Catalin Marinas, Will Deacon
  Cc: Mark Rutland, Ryan Roberts, Anshuman Khandual, Kevin Brodsky,
	Vladimir Murzin, Carl Worth, Linu Cherian, Yeoreum Yun,
	linux-arm-kernel, linux-kernel, Fuad Tabba



On Thu, 3 Dec 2026, at 14:25, Fuad Tabba wrote:
> Hi folks,
>
> This series fixes a TLBI operand and a TTBR1_EL1 write in
> idmap_kpti_install_ng_mappings(). Both came up while I was working on
> the ISB fix to the same code [1].
>
> The first masks the TLBI operand in kpti_map_pgtbl(). Its upper bits
> hold a wrong TTL hint on 4K and 16K kernels, which can leave kernel
> mappings global. I couldn't find a CPU with FEAT_TTL that requires
> KPTI, so hitting this takes kpti=on. The Falkor workaround in
> tramp_map_kernel has the same unmasked operand. I left it alone, as
> AFAICT the CPUs with that erratum predate FEAT_TTL.
>
> The second converts the temporary pgd's address before writing it to
> TTBR1_EL1, which changes the value only for tables above 2^48 on a
> 52-bit PA kernel.
>
> Both bugs were introduced by commit 47546a1912fc4 ("arm64: mm: install
> KPTI nG mappings with MMU enabled"). I left out the Fixes: tags, as I
> don't think either is worth a backport.
>
> Tested on QEMU (4K, and 64K with 52-bit PA) and on FVP, with "nokaslr
> kpti=on". The second bug reproduces on QEMU with RAM placed at 2^48.
> Without the patch the boot hangs, and with it the kernel boots. I
> couldn't reproduce the first, as QEMU ignores the TTL hint and on FVP
> the patch doesn't change which mappings end up global.
>
> Based on Linux 7.4-rc1 (6628e7d4c6b25; also applies to arm64
> for-next/fixes a7e632493acf3).
>
> Cheers,
> /fuad
>
> [1] https://lore.kernel.org/all/20261120121638.194154-1-fuad.tabba@linux.dev/
>
> Fuad Tabba (2):
>   arm64: mm: Mask the TLBI operand in kpti_map_pgtbl()
>   arm64: mm: Convert the temporary KPTI pgd address for TTBR1_EL1
>

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-03 14:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 13:25 [PATCH 0/2] arm64: mm: Fix a TLBI operand and a TTBR1 write in the KPTI nG rewrite Fuad Tabba
2026-12-03 13:25 ` [PATCH 1/2] arm64: mm: Mask the TLBI operand in kpti_map_pgtbl() Fuad Tabba
2026-12-03 13:25 ` [PATCH 2/2] arm64: mm: Convert the temporary KPTI pgd address for TTBR1_EL1 Fuad Tabba
2026-12-03 14:28 ` [PATCH 0/2] arm64: mm: Fix a TLBI operand and a TTBR1 write in the KPTI nG rewrite Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®