[PATCH v2] arm64: mte: avoid clearing PSTATE.TCO on entry unless necessary

Catalin Marinas catalin.marinas at arm.com
Fri Dec 10 04:06:10 PST 2021


On Wed, Nov 10, 2021 at 02:07:35PM -0800, Peter Collingbourne wrote:
> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> index 2f69ae43941d..a78ec15f5bbc 100644
> --- a/arch/arm64/kernel/entry.S
> +++ b/arch/arm64/kernel/entry.S
> @@ -189,6 +189,27 @@ alternative_cb_end
>  #endif
>  	.endm
>  
> +	.macro mte_clear_tco, sctlr
> +	/*
> +	 * Re-enable tag checking (TCO set on exception entry). This is only
> +	 * necessary if MTE is enabled in either the kernel or the userspace
> +	 * task in synchronous mode. With MTE disabled in the kernel and
> +	 * disabled or asynchronous in userspace, tag check faults (including in
> +	 * uaccesses) are not reported, therefore there is no need to re-enable
> +	 * checking. This is beneficial on microarchitectures where re-enabling
> +	 * TCO is expensive.
> +	 */
> +#ifdef CONFIG_ARM64_MTE
> +alternative_cb	kasan_hw_tags_enable
> +	tbz	\sctlr, #SCTLR_EL1_TCF0_SHIFT, 1f
> +alternative_cb_end
> +alternative_if ARM64_MTE
> +	SET_PSTATE_TCO(0)
> +alternative_else_nop_endif
> +1:
> +#endif
> +	.endm

The patch looks fine to me but I recall in a private conversation with
Mark he proposed the idea of moving this to entry-common.c (unless it
was about something completely different). The downside is that we run
with the TCO set for slightly longer. There shouldn't be a major
drawback currently as we don't have stack tagging anyway.

-- 
Catalin



More information about the linux-arm-kernel mailing list