Skip to content

Commit

Permalink
arm64: add MTE supported check to thread switching and syscall entry/…
Browse files Browse the repository at this point in the history
…exit

commit 8c8a3b5 upstream.

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: <stable@vger.kernel.org> # 5.13.x
Signed-off-by: Peter Collingbourne <pcc@google.com>
Link: https://linux-review.googlesource.com/id/I02fd000d1ef2c86c7d2952a7f099b254ec227a5d
Link: https://lore.kernel.org/r/20210915190336.398390-1-pcc@google.com
[catalin.marinas@arm.com: adjust the commit log slightly]
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
pcc authored and gregkh committed Sep 30, 2021
1 parent 338db6e commit 7b389ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 6 additions & 0 deletions arch/arm64/include/asm/mte.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,17 @@ void mte_check_tfsr_el1(void);

static inline void mte_check_tfsr_entry(void)
{
if (!system_supports_mte())
return;

mte_check_tfsr_el1();
}

static inline void mte_check_tfsr_exit(void)
{
if (!system_supports_mte())
return;

/*
* The asynchronous faults are sync'ed automatically with
* TFSR_EL1 on kernel entry but for exit an explicit dsb()
Expand Down
10 changes: 4 additions & 6 deletions arch/arm64/kernel/mte.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,7 @@ bool mte_report_once(void)
#ifdef CONFIG_KASAN_HW_TAGS
void mte_check_tfsr_el1(void)
{
u64 tfsr_el1;

if (!system_supports_mte())
return;

tfsr_el1 = read_sysreg_s(SYS_TFSR_EL1);
u64 tfsr_el1 = read_sysreg_s(SYS_TFSR_EL1);

if (unlikely(tfsr_el1 & SYS_TFSR_EL1_TF1)) {
/*
Expand Down Expand Up @@ -221,6 +216,9 @@ void mte_thread_init_user(void)

void mte_thread_switch(struct task_struct *next)
{
if (!system_supports_mte())
return;

/*
* Check if an async tag exception occurred at EL1.
*
Expand Down

0 comments on commit 7b389ef

Please sign in to comment.