From: Catalin Marinas <catalin.marinas@arm.com>
To: Peter Collingbourne <pcc@google.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>,
Will Deacon <will@kernel.org>,
Andrey Konovalov <andreyknvl@gmail.com>,
Mark Rutland <mark.rutland@arm.com>,
Evgenii Stepanov <eugenis@google.com>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v3] arm64: mte: avoid clearing PSTATE.TCO on entry unless necessary
Date: Mon, 24 Jan 2022 11:45:14 +0000 [thread overview]
Message-ID: <Ye6RSlb0LkegxSKa@arm.com> (raw)
In-Reply-To: <20220122010250.251885-1-pcc@google.com>
On Fri, Jan 21, 2022 at 05:02:50PM -0800, Peter Collingbourne wrote:
> diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h
> index 075539f5f1c8..5352db4c0f45 100644
> --- a/arch/arm64/include/asm/mte.h
> +++ b/arch/arm64/include/asm/mte.h
> @@ -11,7 +11,9 @@
> #ifndef __ASSEMBLY__
>
> #include <linux/bitfield.h>
> +#include <linux/kasan.h>
> #include <linux/page-flags.h>
> +#include <linux/sched.h>
> #include <linux/types.h>
>
> #include <asm/pgtable-types.h>
> @@ -86,6 +88,23 @@ static inline int mte_ptrace_copy_tags(struct task_struct *child,
>
> #endif /* CONFIG_ARM64_MTE */
>
> +static inline void mte_disable_tco_entry(struct task_struct *task)
> +{
> + /*
> + * 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.
> + */
I'd add a note here that the 1ULL << SCTLR_EL1_TCF0_SHIFT is meant to
check for both synchronous and asymmetric modes even if we don't have
the latter supporting the user yet. We do have the definitions already.
> + if (kasan_hw_tags_enabled() ||
> + (system_supports_mte() &&
> + (task->thread.sctlr_user & (1UL << SCTLR_EL1_TCF0_SHIFT))))
> + asm volatile(SET_PSTATE_TCO(0));
> +}
Does it make a difference in code generation if you place a:
if (!system_supports_mte())
return;
at the beginning of the function (and remove the subsequent check)? It's
probably also easier to read, though the code generation depends on the
likely/unlikely choices for the static branches involved.
> diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
> index f418ebc65f95..5345587f3384 100644
> --- a/arch/arm64/kernel/mte.c
> +++ b/arch/arm64/kernel/mte.c
> @@ -252,6 +252,7 @@ void mte_thread_switch(struct task_struct *next)
>
> mte_update_sctlr_user(next);
> mte_update_gcr_excl(next);
> + mte_disable_tco_entry(next);
Maybe a one-line comment here that TCO may not have been disabled on
exception entry for the current task.
Otherwise it looks good to me:
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-01-24 11:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-22 1:02 [PATCH v3] arm64: mte: avoid clearing PSTATE.TCO on entry unless necessary Peter Collingbourne
2022-01-24 11:45 ` Catalin Marinas [this message]
2022-01-25 0:59 ` Peter Collingbourne
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Ye6RSlb0LkegxSKa@arm.com \
--to=catalin.marinas@arm.com \
--cc=andreyknvl@gmail.com \
--cc=eugenis@google.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=pcc@google.com \
--cc=vincenzo.frascino@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).