[PATCH 4/4] arm64: mte: Lock a page for MTE tag initialisation

Catalin Marinas catalin.marinas at arm.com
Thu Sep 1 05:15:02 PDT 2022


On Fri, Jul 08, 2022 at 04:11:59PM -0700, Peter Collingbourne wrote:
> On Tue, Jul 5, 2022 at 7:26 AM Catalin Marinas <catalin.marinas at arm.com> wrote:
> > @@ -60,6 +62,32 @@ static inline bool page_mte_tagged(struct page *page)
> >         return ret;
> >  }
> >
> > +/*
> > + * Lock the page for tagging and return 'true' if the page can be tagged,
> > + * 'false' if already tagged. PG_mte_tagged is never cleared and therefore the
> > + * locking only happens once for page initialisation.
> > + *
> > + * The page MTE lock state:
> > + *
> > + *   Locked:   PG_mte_lock && !PG_mte_tagged
> > + *   Unlocked: !PG_mte_lock || PG_mte_tagged
> > + *
> > + * Acquire semantics only if the page is tagged (returning 'false').
> > + */
> > +static inline bool try_page_mte_tagging(struct page *page)
> > +{
> > +       if (!test_and_set_bit(PG_mte_lock, &page->flags))
> > +               return !page_mte_tagged(page);
> 
> Since all callers of set_page_mte_tagged() are now dominated by a call
> to try_page_mte_tagging() and PG_mte_lock is never cleared I think we
> can't end up in the state where !PG_mte_lock && PG_mte_tagged. So I
> think this can be simplified to "return true;". I can still boot VMs
> with MTE enabled after making my suggested change.

Correct. Not sure why I complicated this since the "Unlocked"
description above states that try_page_mte_tagging() should return
"unlocked" if !PG_mte_lock, so no need for the PG_mte_tagged check.

> > +
> > +       /*
> > +        * The tags are being initialised, wait for the PG_mte_tagged flag to
> 
> I think at this point the tags are either being initialized or have
> already been initialized, so the comment isn't quite right.

Yeah, they may have been initialised already by the time we got here and
smp_cond_load_acquire() would just return immediately. I was too lazy to
write all the use-cases here.

-- 
Catalin



More information about the linux-arm-kernel mailing list