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

Peter Collingbourne pcc at google.com
Thu Sep 23 18:08:13 PDT 2021


On Tue, Sep 21, 2021 at 5:40 AM Catalin Marinas <catalin.marinas at arm.com> wrote:
>
> On Wed, Sep 15, 2021 at 12:03:36PM -0700, Peter Collingbourne wrote:
> > -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



More information about the linux-arm-kernel mailing list