Skip to content

Commit 2decad9

Browse files
ctmarinaswilldeacon
authored andcommitted
arm64: mte: Ensure TIF_MTE_ASYNC_FAULT is set atomically
The entry from EL0 code checks the TFSRE0_EL1 register for any asynchronous tag check faults in user space and sets the TIF_MTE_ASYNC_FAULT flag. This is not done atomically, potentially racing with another CPU calling set_tsk_thread_flag(). Replace the non-atomic ORR+STR with an STSET instruction. While STSET requires ARMv8.1 and an assembler that understands LSE atomics, the MTE feature is part of ARMv8.5 and already requires an updated assembler. Signed-off-by: Catalin Marinas <[email protected]> Fixes: 637ec83 ("arm64: mte: Handle synchronous and asynchronous tag check faults") Cc: <[email protected]> # 5.10.x Reported-by: Will Deacon <[email protected]> Cc: Will Deacon <[email protected]> Cc: Vincenzo Frascino <[email protected]> Cc: Mark Rutland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 185f2e5 commit 2decad9

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

arch/arm64/Kconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,10 +1406,13 @@ config ARM64_PAN
14061406
config AS_HAS_LDAPR
14071407
def_bool $(as-instr,.arch_extension rcpc)
14081408

1409+
config AS_HAS_LSE_ATOMICS
1410+
def_bool $(as-instr,.arch_extension lse)
1411+
14091412
config ARM64_LSE_ATOMICS
14101413
bool
14111414
default ARM64_USE_LSE_ATOMICS
1412-
depends on $(as-instr,.arch_extension lse)
1415+
depends on AS_HAS_LSE_ATOMICS
14131416

14141417
config ARM64_USE_LSE_ATOMICS
14151418
bool "Atomic instructions"
@@ -1666,6 +1669,7 @@ config ARM64_MTE
16661669
default y
16671670
depends on ARM64_AS_HAS_MTE && ARM64_TAGGED_ADDR_ABI
16681671
depends on AS_HAS_ARMV8_5
1672+
depends on AS_HAS_LSE_ATOMICS
16691673
# Required for tag checking in the uaccess routines
16701674
depends on ARM64_PAN
16711675
select ARCH_USES_HIGH_VMA_FLAGS

arch/arm64/kernel/entry.S

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,18 @@ alternative_cb_end
148148
.endm
149149

150150
/* Check for MTE asynchronous tag check faults */
151-
.macro check_mte_async_tcf, flgs, tmp
151+
.macro check_mte_async_tcf, tmp, ti_flags
152152
#ifdef CONFIG_ARM64_MTE
153+
.arch_extension lse
153154
alternative_if_not ARM64_MTE
154155
b 1f
155156
alternative_else_nop_endif
156157
mrs_s \tmp, SYS_TFSRE0_EL1
157158
tbz \tmp, #SYS_TFSR_EL1_TF0_SHIFT, 1f
158159
/* Asynchronous TCF occurred for TTBR0 access, set the TI flag */
159-
orr \flgs, \flgs, #_TIF_MTE_ASYNC_FAULT
160-
str \flgs, [tsk, #TSK_TI_FLAGS]
160+
mov \tmp, #_TIF_MTE_ASYNC_FAULT
161+
add \ti_flags, tsk, #TSK_TI_FLAGS
162+
stset \tmp, [\ti_flags]
161163
msr_s SYS_TFSRE0_EL1, xzr
162164
1:
163165
#endif
@@ -244,7 +246,7 @@ alternative_else_nop_endif
244246
disable_step_tsk x19, x20
245247

246248
/* Check for asynchronous tag check faults in user space */
247-
check_mte_async_tcf x19, x22
249+
check_mte_async_tcf x22, x23
248250
apply_ssbd 1, x22, x23
249251

250252
ptrauth_keys_install_kernel tsk, x20, x22, x23

0 commit comments

Comments
 (0)