Skip to content

Commit 8c8a3b5

Browse files
pccctmarinas
authored andcommitted
arm64: add MTE supported check to thread switching and syscall entry/exit
This lets us avoid doing unnecessary work on hardware that does not support MTE, and will allow us to freely use MTE instructions in the code called by mte_thread_switch(). Since this would mean that we do a redundant check in mte_check_tfsr_el1(), remove it and add two checks now required in its callers. This also avoids an unnecessary DSB+ISB sequence on the syscall exit path for hardware not supporting MTE. Fixes: 65812c6 ("arm64: mte: Enable async tag check fault") Cc: <[email protected]> # 5.13.x Signed-off-by: Peter Collingbourne <[email protected]> Link: https://linux-review.googlesource.com/id/I02fd000d1ef2c86c7d2952a7f099b254ec227a5d Link: https://lore.kernel.org/r/[email protected] [[email protected]: adjust the commit log slightly] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 9fcb2e9 commit 8c8a3b5

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

arch/arm64/include/asm/mte.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,17 @@ void mte_check_tfsr_el1(void);
9999

100100
static inline void mte_check_tfsr_entry(void)
101101
{
102+
if (!system_supports_mte())
103+
return;
104+
102105
mte_check_tfsr_el1();
103106
}
104107

105108
static inline void mte_check_tfsr_exit(void)
106109
{
110+
if (!system_supports_mte())
111+
return;
112+
107113
/*
108114
* The asynchronous faults are sync'ed automatically with
109115
* TFSR_EL1 on kernel entry but for exit an explicit dsb()

arch/arm64/kernel/mte.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,7 @@ void mte_enable_kernel_async(void)
142142
#ifdef CONFIG_KASAN_HW_TAGS
143143
void mte_check_tfsr_el1(void)
144144
{
145-
u64 tfsr_el1;
146-
147-
if (!system_supports_mte())
148-
return;
149-
150-
tfsr_el1 = read_sysreg_s(SYS_TFSR_EL1);
145+
u64 tfsr_el1 = read_sysreg_s(SYS_TFSR_EL1);
151146

152147
if (unlikely(tfsr_el1 & SYS_TFSR_EL1_TF1)) {
153148
/*
@@ -199,6 +194,9 @@ void mte_thread_init_user(void)
199194

200195
void mte_thread_switch(struct task_struct *next)
201196
{
197+
if (!system_supports_mte())
198+
return;
199+
202200
mte_update_sctlr_user(next);
203201

204202
/*

0 commit comments

Comments
 (0)