linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Peter Collingbourne <pcc@google.com>
Cc: Will Deacon <will@kernel.org>, Marc Zyngier <maz@kernel.org>,
	Steven Price <steven.price@arm.com>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH 4/4] arm64: mte: Lock a page for MTE tag initialisation
Date: Thu, 1 Sep 2022 13:15:02 +0100	[thread overview]
Message-ID: <YxCiRlFKTU70eKof@arm.com> (raw)
In-Reply-To: <CAMn1gO5mCNj2oLbR0vpLbgWA1ekgdmJ7c-MU0m2gmeEYPAUSJw@mail.gmail.com>

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@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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

      reply	other threads:[~2022-09-01 12:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-05 14:26 [PATCH 0/4] arm64: mte: Fix racing on MTE tag initialisation Catalin Marinas
2022-07-05 14:26 ` [PATCH 1/4] arm64: mte: Fix/clarify the PG_mte_tagged semantics Catalin Marinas
2022-07-05 14:26 ` [PATCH 2/4] KVM: arm64: Simplify the sanitise_mte_tags() logic Catalin Marinas
2022-07-08 23:00   ` Peter Collingbourne
2022-09-01 10:42     ` Catalin Marinas
2022-07-05 14:26 ` [PATCH 3/4] mm: Add PG_arch_3 page flag Catalin Marinas
2022-07-05 14:26 ` [PATCH 4/4] arm64: mte: Lock a page for MTE tag initialisation Catalin Marinas
2022-07-08 23:11   ` Peter Collingbourne
2022-09-01 12:15     ` Catalin Marinas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YxCiRlFKTU70eKof@arm.com \
    --to=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=pcc@google.com \
    --cc=steven.price@arm.com \
    --cc=vincenzo.frascino@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).