@@ -319,6 +319,25 @@ static void flush_tagged_addr_state(void)
}
#ifdef CONFIG_ARM64_MTE
+static void update_sctlr_el1_tcf0(u64 tcf0)
+{
+ /* no need for ISB since this only affects EL0, implicit with ERET */
+ sysreg_clear_set(sctlr_el1, SCTLR_EL1_TCF0_MASK, tcf0);
+}
+
+static void set_sctlr_el1_tcf0(u64 tcf0)
+{
+ /*
+ * mte_thread_switch() checks current->thread.sctlr_tcf0 as an
+ * optimisation. Disable preemption so that it does not see
+ * the variable update before the SCTLR_EL1.TCF0 one.
+ */
+ preempt_disable();
+ current->thread.sctlr_tcf0 = tcf0;
+ update_sctlr_el1_tcf0(tcf0);
+ preempt_enable();
+}
+
static void flush_mte_state(void)
{
if (!system_supports_mte())
@@ -327,7 +346,7 @@ static void flush_mte_state(void)
/* clear any pending asynchronous tag fault */
clear_thread_flag(TIF_MTE_ASYNC_FAULT);
/* disable tag checking */
- current->thread.sctlr_tcf0 = 0;
+ set_sctlr_el1_tcf0(0);
}
#else
static void flush_mte_state(void)
@@ -497,12 +516,6 @@ static void ssbs_thread_switch(struct task_struct *next)
}
#ifdef CONFIG_ARM64_MTE
-static void update_sctlr_el1_tcf0(u64 tcf0)
-{
- /* no need for ISB since this only affects EL0, implicit with ERET */
- sysreg_clear_set(sctlr_el1, SCTLR_EL1_TCF0_MASK, tcf0);
-}
-
static void update_gcr_el1_excl(u64 excl)
{
/*
@@ -643,15 +656,7 @@ static long set_mte_ctrl(unsigned long arg)
return -EINVAL;
}
- /*
- * mte_thread_switch() checks current->thread.sctlr_tcf0 as an
- * optimisation. Disable preemption so that it does not see
- * the variable update before the SCTLR_EL1.TCF0 one.
- */
- preempt_disable();
- current->thread.sctlr_tcf0 = tcf0;
- update_sctlr_el1_tcf0(tcf0);
- preempt_enable();
+ set_sctlr_el1_tcf0(tcf0);
current->thread.gcr_excl = (arg & PR_MTE_EXCL_MASK) >> PR_MTE_EXCL_SHIFT;
update_gcr_el1_excl(current->thread.gcr_excl);