Skip to content

Commit ae4bffb

Browse files
author
Marc Zyngier
committed
Merge branch 'kvm-arm64/ttl-for-arm64' into HEAD
Signed-off-by: Marc Zyngier <[email protected]>
2 parents f9a026e + c10bc62 commit ae4bffb

File tree

6 files changed

+70
-1
lines changed

6 files changed

+70
-1
lines changed

arch/arm64/include/asm/cpucaps.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
#define ARM64_HAS_GENERIC_AUTH 52
6363
#define ARM64_HAS_32BIT_EL1 53
6464
#define ARM64_BTI 54
65+
#define ARM64_HAS_ARMv8_4_TTL 55
6566

66-
#define ARM64_NCAPS 55
67+
#define ARM64_NCAPS 56
6768

6869
#endif /* __ASM_CPUCAPS_H */

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,12 @@
178178
#define PTE_S2_RDONLY (_AT(pteval_t, 1) << 6) /* HAP[2:1] */
179179
#define PTE_S2_RDWR (_AT(pteval_t, 3) << 6) /* HAP[2:1] */
180180
#define PTE_S2_XN (_AT(pteval_t, 2) << 53) /* XN[1:0] */
181+
#define PTE_S2_SW_RESVD (_AT(pteval_t, 15) << 55) /* Reserved for SW */
181182

182183
#define PMD_S2_RDONLY (_AT(pmdval_t, 1) << 6) /* HAP[2:1] */
183184
#define PMD_S2_RDWR (_AT(pmdval_t, 3) << 6) /* HAP[2:1] */
184185
#define PMD_S2_XN (_AT(pmdval_t, 2) << 53) /* XN[1:0] */
186+
#define PMD_S2_SW_RESVD (_AT(pmdval_t, 15) << 55) /* Reserved for SW */
185187

186188
#define PUD_S2_RDONLY (_AT(pudval_t, 1) << 6) /* HAP[2:1] */
187189
#define PUD_S2_RDWR (_AT(pudval_t, 3) << 6) /* HAP[2:1] */

arch/arm64/include/asm/stage2_pgtable.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,13 @@ stage2_pgd_addr_end(struct kvm *kvm, phys_addr_t addr, phys_addr_t end)
256256
return (boundary - 1 < end - 1) ? boundary : end;
257257
}
258258

259+
/*
260+
* Level values for the ARMv8.4-TTL extension, mapping PUD/PMD/PTE and
261+
* the architectural page-table level.
262+
*/
263+
#define S2_NO_LEVEL_HINT 0
264+
#define S2_PUD_LEVEL 1
265+
#define S2_PMD_LEVEL 2
266+
#define S2_PTE_LEVEL 3
267+
259268
#endif /* __ARM64_S2_PGTABLE_H_ */

arch/arm64/include/asm/sysreg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@
746746

747747
/* id_aa64mmfr2 */
748748
#define ID_AA64MMFR2_E0PD_SHIFT 60
749+
#define ID_AA64MMFR2_TTL_SHIFT 48
749750
#define ID_AA64MMFR2_FWB_SHIFT 40
750751
#define ID_AA64MMFR2_AT_SHIFT 32
751752
#define ID_AA64MMFR2_LVA_SHIFT 16

arch/arm64/include/asm/tlbflush.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#ifndef __ASSEMBLY__
1212

13+
#include <linux/bitfield.h>
1314
#include <linux/mm_types.h>
1415
#include <linux/sched.h>
1516
#include <asm/cputype.h>
@@ -59,6 +60,50 @@
5960
__ta; \
6061
})
6162

63+
/*
64+
* Level-based TLBI operations.
65+
*
66+
* When ARMv8.4-TTL exists, TLBI operations take an additional hint for
67+
* the level at which the invalidation must take place. If the level is
68+
* wrong, no invalidation may take place. In the case where the level
69+
* cannot be easily determined, a 0 value for the level parameter will
70+
* perform a non-hinted invalidation.
71+
*
72+
* For Stage-2 invalidation, use the level values provided to that effect
73+
* in asm/stage2_pgtable.h.
74+
*/
75+
#define TLBI_TTL_MASK GENMASK_ULL(47, 44)
76+
#define TLBI_TTL_TG_4K 1
77+
#define TLBI_TTL_TG_16K 2
78+
#define TLBI_TTL_TG_64K 3
79+
80+
#define __tlbi_level(op, addr, level) \
81+
do { \
82+
u64 arg = addr; \
83+
\
84+
if (cpus_have_const_cap(ARM64_HAS_ARMv8_4_TTL) && \
85+
level) { \
86+
u64 ttl = level & 3; \
87+
\
88+
switch (PAGE_SIZE) { \
89+
case SZ_4K: \
90+
ttl |= TLBI_TTL_TG_4K << 2; \
91+
break; \
92+
case SZ_16K: \
93+
ttl |= TLBI_TTL_TG_16K << 2; \
94+
break; \
95+
case SZ_64K: \
96+
ttl |= TLBI_TTL_TG_64K << 2; \
97+
break; \
98+
} \
99+
\
100+
arg &= ~TLBI_TTL_MASK; \
101+
arg |= FIELD_PREP(TLBI_TTL_MASK, ttl); \
102+
} \
103+
\
104+
__tlbi(op, arg); \
105+
} while(0)
106+
62107
/*
63108
* TLB Invalidation
64109
* ================

arch/arm64/kernel/cpufeature.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ static const struct arm64_ftr_bits ftr_id_aa64mmfr1[] = {
323323

324324
static const struct arm64_ftr_bits ftr_id_aa64mmfr2[] = {
325325
ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_E0PD_SHIFT, 4, 0),
326+
ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_TTL_SHIFT, 4, 0),
326327
ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_FWB_SHIFT, 4, 0),
327328
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_AT_SHIFT, 4, 0),
328329
ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_LVA_SHIFT, 4, 0),
@@ -1882,6 +1883,16 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
18821883
.matches = has_cpuid_feature,
18831884
.cpu_enable = cpu_has_fwb,
18841885
},
1886+
{
1887+
.desc = "ARMv8.4 Translation Table Level",
1888+
.type = ARM64_CPUCAP_SYSTEM_FEATURE,
1889+
.capability = ARM64_HAS_ARMv8_4_TTL,
1890+
.sys_reg = SYS_ID_AA64MMFR2_EL1,
1891+
.sign = FTR_UNSIGNED,
1892+
.field_pos = ID_AA64MMFR2_TTL_SHIFT,
1893+
.min_field_value = 1,
1894+
.matches = has_cpuid_feature,
1895+
},
18851896
#ifdef CONFIG_ARM64_HW_AFDBM
18861897
{
18871898
/*

0 commit comments

Comments
 (0)