Skip to content

Commit 62cffa4

Browse files
ardbiesheuvelwilldeacon
authored andcommitted
arm64/mm: Override PARange for !LPA2 and use it consistently
When FEAT_LPA{,2} are not implemented, the ID_AA64MMFR0_EL1.PARange and TCR.IPS values corresponding with 52-bit physical addressing are reserved. Setting the TCR.IPS field to 0b110 (52-bit physical addressing) has side effects, such as how the TTBRn_ELx.BADDR fields are interpreted, and so it is important that disabling FEAT_LPA2 (by overriding the ID_AA64MMFR0.TGran fields) also presents a PARange field consistent with that. So limit the field to 48 bits unless LPA2 is enabled, and update existing references to use the override consistently. Fixes: 352b039 ("arm64: Enable 52-bit virtual addressing for 4k and 16k granule configs") Cc: stable@vger.kernel.org Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Acked-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20241212081841.2168124-10-ardb+git@google.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent bf74bb7 commit 62cffa4

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

arch/arm64/include/asm/assembler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ alternative_cb_end
343343
// Narrow PARange to fit the PS field in TCR_ELx
344344
ubfx \tmp0, \tmp0, #ID_AA64MMFR0_EL1_PARANGE_SHIFT, #3
345345
mov \tmp1, #ID_AA64MMFR0_EL1_PARANGE_MAX
346+
#ifdef CONFIG_ARM64_LPA2
347+
alternative_if_not ARM64_HAS_VA52
348+
mov \tmp1, #ID_AA64MMFR0_EL1_PARANGE_48
349+
alternative_else_nop_endif
350+
#endif
346351
cmp \tmp0, \tmp1
347352
csel \tmp0, \tmp1, \tmp0, hi
348353
bfi \tcr, \tmp0, \pos, #3

arch/arm64/kernel/cpufeature.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3478,7 +3478,7 @@ static void verify_hyp_capabilities(void)
34783478
return;
34793479

34803480
safe_mmfr1 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);
3481-
mmfr0 = read_cpuid(ID_AA64MMFR0_EL1);
3481+
mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);
34823482
mmfr1 = read_cpuid(ID_AA64MMFR1_EL1);
34833483

34843484
/* Verify VMID bits */

arch/arm64/kernel/pi/idreg-override.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ static bool __init mmfr2_varange_filter(u64 val)
8383
id_aa64mmfr0_override.val |=
8484
(ID_AA64MMFR0_EL1_TGRAN_LPA2 - 1) << ID_AA64MMFR0_EL1_TGRAN_SHIFT;
8585
id_aa64mmfr0_override.mask |= 0xfU << ID_AA64MMFR0_EL1_TGRAN_SHIFT;
86+
87+
/*
88+
* Override PARange to 48 bits - the override will just be
89+
* ignored if the actual PARange is smaller, but this is
90+
* unlikely to be the case for LPA2 capable silicon.
91+
*/
92+
id_aa64mmfr0_override.val |=
93+
ID_AA64MMFR0_EL1_PARANGE_48 << ID_AA64MMFR0_EL1_PARANGE_SHIFT;
94+
id_aa64mmfr0_override.mask |= 0xfU << ID_AA64MMFR0_EL1_PARANGE_SHIFT;
8695
}
8796
#endif
8897
return true;

arch/arm64/kernel/pi/map_kernel.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ static void noinline __section(".idmap.text") set_ttbr0_for_lpa2(u64 ttbr)
136136
{
137137
u64 sctlr = read_sysreg(sctlr_el1);
138138
u64 tcr = read_sysreg(tcr_el1) | TCR_DS;
139+
u64 mmfr0 = read_sysreg(id_aa64mmfr0_el1);
140+
u64 parange = cpuid_feature_extract_unsigned_field(mmfr0,
141+
ID_AA64MMFR0_EL1_PARANGE_SHIFT);
142+
143+
tcr &= ~TCR_IPS_MASK;
144+
tcr |= parange << TCR_IPS_SHIFT;
139145

140146
asm(" msr sctlr_el1, %0 ;"
141147
" isb ;"

arch/arm64/mm/init.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,12 @@ void __init arm64_memblock_init(void)
279279

280280
if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
281281
extern u16 memstart_offset_seed;
282-
u64 mmfr0 = read_cpuid(ID_AA64MMFR0_EL1);
282+
283+
/*
284+
* Use the sanitised version of id_aa64mmfr0_el1 so that linear
285+
* map randomization can be enabled by shrinking the IPA space.
286+
*/
287+
u64 mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);
283288
int parange = cpuid_feature_extract_unsigned_field(
284289
mmfr0, ID_AA64MMFR0_EL1_PARANGE_SHIFT);
285290
s64 range = linear_region_size -

0 commit comments

Comments
 (0)