Skip to content

Commit c10bc62

Browse files
author
Marc Zyngier
committed
arm64: Add level-hinted TLB invalidation helper
Add a level-hinted TLB invalidation helper that only gets used if ARMv8.4-TTL gets detected. Reviewed-by: Alexandru Elisei <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 6fcfdf6 commit c10bc62

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

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/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
* ================

0 commit comments

Comments
 (0)