Thread (5 messages) flat view 5 messages, 2 authors, 2021-09-24

Re: [PATCH v3 2/2] arm64: kasan: mte: move GCR_EL1 switch to task switch when KASAN disabled

From: Peter Collingbourne <hidden>
Date: 2021-09-24 01:10:59

On Tue, Sep 21, 2021 at 5:40 AM Catalin Marinas [off-list ref] wrote:
On Wed, Sep 15, 2021 at 12:03:36PM -0700, Peter Collingbourne wrote:
quoted
-static void mte_update_sctlr_user(struct task_struct *task)
+static void mte_update_sctlr_user_and_gcr_excl(struct task_struct *task)
 {
      /*
       * This must be called with preemption disabled and can only be called
@@ -177,6 +177,24 @@ static void mte_update_sctlr_user(struct task_struct *task)
      else if (resolved_mte_tcf & MTE_CTRL_TCF_SYNC)
              sctlr |= SCTLR_EL1_TCF0_SYNC;
      task->thread.sctlr_user = sctlr;
+
+     /*
+      * SYS_GCR_EL1 will be set to current->thread.mte_ctrl value by
+      * mte_set_user_gcr() in kernel_exit, but only if KASAN is enabled.
+      */
+     if (!kasan_hw_tags_enabled())
+             write_sysreg_s(((mte_ctrl >> MTE_CTRL_GCR_USER_EXCL_SHIFT) &
+                             SYS_GCR_EL1_EXCL_MASK) | SYS_GCR_EL1_RRND,
+                            SYS_GCR_EL1);
+}
The only nitpick I have is that I'd like to keep the GCR_EL1 updating in
a separate function, mte_update_gcr_user() or something (it can be
static inline) that you'd explicitly call from mte_thread_switch() and
set_mte_ctrl(). The original mte_update_sctlr_user() was not writing any
system registers.
Done in v4. (I mildly prefer the way I originally wrote it as I think
it's less error prone, but I don't mind that much.) Sorry, I forgot to
add your Reviewed-by.

Peter

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help