Skip to content

Commit 602ffd4

Browse files
committed
Merge branch 'for-next/mm' into for-next/core
* for-next/mm: arm64: mm: Test for pmd_sect() in vmemmap_check_pmd() arm64/mm: Replace open encodings with PXD_TABLE_BIT arm64/mm: Rename pte_mkpresent() as pte_mkvalid() arm64: Kconfig: force ARM64_PAN=y when enabling TTBR0 sw PAN arm64/kvm: Avoid invalid physical addresses to signal owner updates arm64/kvm: Configure HYP TCR.PS/DS based on host stage1 arm64/mm: Override PARange for !LPA2 and use it consistently arm64/mm: Reduce PA space to 48 bits when LPA2 is not enabled
2 parents 6e11733 + 9ab2601 commit 602ffd4

File tree

14 files changed

+58
-43
lines changed

14 files changed

+58
-43
lines changed

arch/arm64/Kconfig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,6 @@ config ARM64_VA_BITS_48
13791379

13801380
config ARM64_VA_BITS_52
13811381
bool "52-bit"
1382-
depends on ARM64_PAN || !ARM64_SW_TTBR0_PAN
13831382
help
13841383
Enable 52-bit virtual addressing for userspace when explicitly
13851384
requested via a hint to mmap(). The kernel will also use 52-bit
@@ -1431,7 +1430,6 @@ config ARM64_PA_BITS_48
14311430
config ARM64_PA_BITS_52
14321431
bool "52-bit"
14331432
depends on ARM64_64K_PAGES || ARM64_VA_BITS_52
1434-
depends on ARM64_PAN || !ARM64_SW_TTBR0_PAN
14351433
help
14361434
Enable support for a 52-bit physical address space, introduced as
14371435
part of the ARMv8.2-LPA extension.
@@ -1681,6 +1679,7 @@ config RODATA_FULL_DEFAULT_ENABLED
16811679
config ARM64_SW_TTBR0_PAN
16821680
bool "Emulate Privileged Access Never using TTBR0_EL1 switching"
16831681
depends on !KCSAN
1682+
select ARM64_PAN
16841683
help
16851684
Enabling this option prevents the kernel from accessing
16861685
user-space memory directly by pointing TTBR0_EL1 to a reserved
@@ -1937,7 +1936,6 @@ config ARM64_RAS_EXTN
19371936
config ARM64_CNP
19381937
bool "Enable support for Common Not Private (CNP) translations"
19391938
default y
1940-
depends on ARM64_PAN || !ARM64_SW_TTBR0_PAN
19411939
help
19421940
Common Not Private (CNP) allows translation table entries to
19431941
be shared between different PEs in the same inner shareable
@@ -2132,7 +2130,7 @@ config ARM64_MTE
21322130
depends on AS_HAS_ARMV8_5
21332131
depends on AS_HAS_LSE_ATOMICS
21342132
# Required for tag checking in the uaccess routines
2135-
depends on ARM64_PAN
2133+
select ARM64_PAN
21362134
select ARCH_HAS_SUBPAGE_FAULTS
21372135
select ARCH_USES_HIGH_VMA_FLAGS
21382136
select ARCH_USES_PG_ARCH_2

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/include/asm/pgtable-hwdef.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,6 @@
222222
*/
223223
#define S1_TABLE_AP (_AT(pmdval_t, 3) << 61)
224224

225-
/*
226-
* Highest possible physical address supported.
227-
*/
228-
#define PHYS_MASK_SHIFT (CONFIG_ARM64_PA_BITS)
229-
#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1)
230-
231225
#define TTBR_CNP_BIT (UL(1) << 0)
232226

233227
/*

arch/arm64/include/asm/pgtable-prot.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ extern unsigned long prot_ns_shared;
8181
#define lpa2_is_enabled() false
8282
#define PTE_MAYBE_SHARED PTE_SHARED
8383
#define PMD_MAYBE_SHARED PMD_SECT_S
84+
#define PHYS_MASK_SHIFT (CONFIG_ARM64_PA_BITS)
8485
#else
8586
static inline bool __pure lpa2_is_enabled(void)
8687
{
@@ -89,8 +90,14 @@ static inline bool __pure lpa2_is_enabled(void)
8990

9091
#define PTE_MAYBE_SHARED (lpa2_is_enabled() ? 0 : PTE_SHARED)
9192
#define PMD_MAYBE_SHARED (lpa2_is_enabled() ? 0 : PMD_SECT_S)
93+
#define PHYS_MASK_SHIFT (lpa2_is_enabled() ? CONFIG_ARM64_PA_BITS : 48)
9294
#endif
9395

96+
/*
97+
* Highest possible physical address supported.
98+
*/
99+
#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1)
100+
94101
/*
95102
* If we have userspace only BTI we don't want to mark kernel pages
96103
* guarded even if the system does support BTI.

arch/arm64/include/asm/pgtable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static inline pte_t pte_mknoncont(pte_t pte)
273273
return clear_pte_bit(pte, __pgprot(PTE_CONT));
274274
}
275275

276-
static inline pte_t pte_mkpresent(pte_t pte)
276+
static inline pte_t pte_mkvalid(pte_t pte)
277277
{
278278
return set_pte_bit(pte, __pgprot(PTE_VALID));
279279
}

arch/arm64/include/asm/sparsemem.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
#ifndef __ASM_SPARSEMEM_H
66
#define __ASM_SPARSEMEM_H
77

8-
#define MAX_PHYSMEM_BITS CONFIG_ARM64_PA_BITS
8+
#include <asm/pgtable-prot.h>
9+
10+
#define MAX_PHYSMEM_BITS PHYS_MASK_SHIFT
11+
#define MAX_POSSIBLE_PHYSMEM_BITS (52)
912

1013
/*
1114
* Section size must be at least 512MB for 64K base

arch/arm64/kernel/cpufeature.c

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

35113511
safe_mmfr1 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);
3512-
mmfr0 = read_cpuid(ID_AA64MMFR0_EL1);
3512+
mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);
35133513
mmfr1 = read_cpuid(ID_AA64MMFR1_EL1);
35143514

35153515
/* 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/kvm/arm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,8 +1990,7 @@ static int kvm_init_vector_slots(void)
19901990
static void __init cpu_prepare_hyp_mode(int cpu, u32 hyp_va_bits)
19911991
{
19921992
struct kvm_nvhe_init_params *params = per_cpu_ptr_nvhe_sym(kvm_init_params, cpu);
1993-
u64 mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);
1994-
unsigned long tcr;
1993+
unsigned long tcr, ips;
19951994

19961995
/*
19971996
* Calculate the raw per-cpu offset without a translation from the
@@ -2005,6 +2004,7 @@ static void __init cpu_prepare_hyp_mode(int cpu, u32 hyp_va_bits)
20052004
params->mair_el2 = read_sysreg(mair_el1);
20062005

20072006
tcr = read_sysreg(tcr_el1);
2007+
ips = FIELD_GET(TCR_IPS_MASK, tcr);
20082008
if (cpus_have_final_cap(ARM64_KVM_HVHE)) {
20092009
tcr |= TCR_EPD1_MASK;
20102010
} else {
@@ -2014,8 +2014,8 @@ static void __init cpu_prepare_hyp_mode(int cpu, u32 hyp_va_bits)
20142014
tcr &= ~TCR_T0SZ_MASK;
20152015
tcr |= TCR_T0SZ(hyp_va_bits);
20162016
tcr &= ~TCR_EL2_PS_MASK;
2017-
tcr |= FIELD_PREP(TCR_EL2_PS_MASK, kvm_get_parange(mmfr0));
2018-
if (kvm_lpa2_is_enabled())
2017+
tcr |= FIELD_PREP(TCR_EL2_PS_MASK, ips);
2018+
if (lpa2_is_enabled())
20192019
tcr |= TCR_EL2_DS;
20202020
params->tcr_el2 = tcr;
20212021

0 commit comments

Comments
 (0)