From: Mostafa Saleh <smostafa@google.com>
To: sashiko-reviews@lists.linux.dev
Cc: Marc Zyngier <maz@kernel.org>,
kvmarm@lists.linux.dev, Oliver Upton <oupton@kernel.org>
Subject: Re: [RFC PATCH v2 2/2] KVM: arm64: Support BBM level 3
Date: Fri, 24 Jul 2026 08:17:37 +0000 [thread overview]
Message-ID: <amMfoWWEBI17jdIj@google.com> (raw)
In-Reply-To: <20260723184346.CAE8F1F000E9@smtp.kernel.org>
On Thu, Jul 23, 2026 at 06:43:45PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Missing DSB between MTE tag stores and the stage-2 PTE update.
> --
>
> --- Patch [2]: [RFC PATCH v2 2/2] KVM: arm64: Support BBM level 3 ---
> commit be481f0e17bfc16626c7f5b1b8b652be3ec92909
> Author: Mostafa Saleh <smostafa@google.com>
>
> KVM: arm64: Support BBM level 3
>
> If the system supports hardware Break-Before-Make (BBM) level 3, use it
> to replace stage-2 PTEs directly. Otherwise, fall back to the software
> BBM sequence.
>
> > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
> > index 127b7f9541b16..5e16ed7e9b909 100644
> > --- a/arch/arm64/kvm/hyp/pgtable.c
> > +++ b/arch/arm64/kvm/hyp/pgtable.c
>
> [ ... ]
>
> > @@ -873,16 +891,35 @@ static bool stage2_try_break_pte(const struct kvm_pgtable_visit_ctx *ctx,
> > return true;
> > }
> >
> > -static void stage2_make_pte(const struct kvm_pgtable_visit_ctx *ctx, kvm_pte_t new)
> > +static bool stage2_make_pte(const struct kvm_pgtable_visit_ctx *ctx, struct kvm_s2_mmu *mmu,
> > + kvm_pte_t new)
> > {
> > struct kvm_pgtable_mm_ops *mm_ops = ctx->mm_ops;
> >
> > - WARN_ON(!stage2_pte_is_locked(*ctx->ptep));
> > -
> > if (stage2_pte_is_counted(new))
> > mm_ops->get_page(ctx->ptep);
> >
> > + if (stage2_use_bbml3() && kvm_pte_valid(ctx->old)) {
> > + /*
> > + * Barrier is required because stage2_try_set_pte() uses
> > + * WRITE_ONCE for non-shared walks, lacking release semantics
> > + * used in the software BBM case.
> > + */
> > + smp_wmb();
> > + if (!stage2_try_set_pte(ctx, new)) {
> > + /* Raced with another core. */
> > + if (stage2_pte_is_counted(new))
> > + mm_ops->put_page(ctx->ptep);
> > + return false;
> > + }
> > +
> > + stage2_clean_old_pte(ctx, mmu);
> > + return true;
> > + }
> > +
> > + WARN_ON(!stage2_pte_is_locked(*ctx->ptep));
> > smp_store_release(ctx->ptep, new);
> > + return true;
> > }
>
> [Severity: High]
> This is a pre-existing issue, but does this sequence lack a required
> synchronization barrier for MTE tag stores?
>
> When KVM maps a page with MTE enabled, it clears the tags using STGM:
>
> arch/arm64/kvm/mmu.c:kvm_s2_fault_map() {
> ...
> if (!perm_fault_granule && !s2vi->map_non_cacheable && kvm_has_mte(kvm))
> sanitise_mte_tags(kvm, pfn, mapping_size);
> ...
> }
>
> The PTE is then updated here in stage2_make_pte(), which uses either
> smp_wmb() + cmpxchg() (mapping to DMB ISHST + CASAL) for BBML3, or
> smp_store_release() (mapping to STLR) for the software BBM case. Neither
> of these provides the architecturally mandated DSB semantics required
> after MTE tag stores.
>
> Without a DSB between sanitise_mte_tags() and the stage-2 PTE update, is
> it possible for the hardware page table walker to observe the new PTE
> before the explicit tag stores are globally visible? Could this result in
> the guest observing uninitialized MTE tags, leading to memory permission
> corruption or spurious tag check faults?
I do not know much about MTE, but AFAIU, STLR wouldn’t order against
page table walks. So there is a window between the STGM and the DSB at
the end of the map where another core can observe a valid PTE and not
a the new tag. My guess we need a DSB at the end of
sanitise_mte_tags()
Thanks,
Mostafa
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260723182140.4025575-1-smostafa@google.com?part=2
prev parent reply other threads:[~2026-07-24 8:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 18:21 [RFC PATCH v2 0/2] KVM: arm64: Add support for BBM level 3 Mostafa Saleh
2026-07-23 18:21 ` [RFC PATCH v2 1/2] KVM: arm64: Add stage2_clean_old_pte() Mostafa Saleh
2026-07-23 18:21 ` [RFC PATCH v2 2/2] KVM: arm64: Support BBM level 3 Mostafa Saleh
2026-07-23 18:43 ` sashiko-bot
2026-07-24 8:17 ` Mostafa Saleh [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=amMfoWWEBI17jdIj@google.com \
--to=smostafa@google.com \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.