Skip to content

Commit

Permalink
arm64: mte: Save/Restore TFSR_EL1 during suspend
Browse files Browse the repository at this point in the history
When MTE async mode is enabled TFSR_EL1 contains the accumulative
asynchronous tag check faults for EL1 and EL0.

During the suspend/resume operations the firmware might perform some
operations that could change the state of the register resulting in
a spurious tag check fault report.

Save/restore the state of the TFSR_EL1 register during the
suspend/resume operations to prevent this to happen.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
  • Loading branch information
fvincenzo authored and intel-lab-lkp committed Feb 9, 2021
1 parent a5297fd commit 7b4b56c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions arch/arm64/include/asm/mte.h
Expand Up @@ -43,6 +43,7 @@ void mte_sync_tags(pte_t *ptep, pte_t pte);
void mte_copy_page_tags(void *kto, const void *kfrom);
void flush_mte_state(void);
void mte_thread_switch(struct task_struct *next);
void mte_suspend_enter(void);
void mte_suspend_exit(void);
long set_mte_ctrl(struct task_struct *task, unsigned long arg);
long get_mte_ctrl(struct task_struct *task);
Expand All @@ -68,6 +69,9 @@ static inline void flush_mte_state(void)
static inline void mte_thread_switch(struct task_struct *next)
{
}
static inline void mte_suspend_enter(void)
{
}
static inline void mte_suspend_exit(void)
{
}
Expand Down
22 changes: 22 additions & 0 deletions arch/arm64/kernel/mte.c
Expand Up @@ -25,6 +25,7 @@

u64 gcr_kernel_excl __ro_after_init;

static u64 mte_suspend_tfsr_el1;
static bool report_fault_once = true;

/* Whether the MTE asynchronous mode is enabled. */
Expand Down Expand Up @@ -295,12 +296,33 @@ void mte_thread_switch(struct task_struct *next)
mte_check_tfsr_el1();
}

void mte_suspend_enter(void)
{
if (!system_supports_mte())
return;

/*
* The barriers are required to guarantee that the indirect writes
* to TFSR_EL1 are synchronized before we save the state.
*/
dsb(nsh);
isb();

/* Save SYS_TFSR_EL1 before suspend entry */
mte_suspend_tfsr_el1 = read_sysreg_s(SYS_TFSR_EL1);
}

void mte_suspend_exit(void)
{
if (!system_supports_mte())
return;

update_gcr_el1_excl(gcr_kernel_excl);

/* Resume SYS_TFSR_EL1 after suspend exit */
write_sysreg_s(mte_suspend_tfsr_el1, SYS_TFSR_EL1);

mte_check_tfsr_el1();
}

long set_mte_ctrl(struct task_struct *task, unsigned long arg)
Expand Down
3 changes: 3 additions & 0 deletions arch/arm64/kernel/suspend.c
Expand Up @@ -91,6 +91,9 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
unsigned long flags;
struct sleep_stack_data state;

/* Report any MTE async fault before going to suspend. */
mte_suspend_enter();

/*
* From this point debug exceptions are disabled to prevent
* updates to mdscr register (saved and restored along with
Expand Down

0 comments on commit 7b4b56c

Please sign in to comment.