Re: [PATCH v3 2/2] arm64: kasan: mte: move GCR_EL1 switch to task switch when KASAN disabled
From: Catalin Marinas <catalin.marinas@arm.com>
Date: 2021-09-21 12:42:15
On Wed, Sep 15, 2021 at 12:03:36PM -0700, Peter Collingbourne wrote:
quoted hunk ↗ jump to hunk
-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. Maybe a better alternative would be to move the update_sctlr_el1() call in mte_update_sctlr_user() as well (and rename it more generically to mte_update_user_ctrl()) but with a new bool update_sctlr argument that's false on the thread switch path. Either way: 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