From: Oliver Upton <oliver.upton@linux.dev>
To: Zenghui Yu <yuzenghui@huawei.com>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
Marc Zyngier <maz@kernel.org>, James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>
Subject: Re: [PATCH v2 2/5] KVM: arm64: Restore the stage-2 context in VHE's __tlb_switch_to_host()
Date: Wed, 18 Oct 2023 07:05:02 +0000 [thread overview]
Message-ID: <ZS-DnsM4JFXZ7a_H@linux.dev> (raw)
In-Reply-To: <5563bffd-0b27-ac95-9e87-24f5b8c71fb7@huawei.com>
On Wed, Oct 18, 2023 at 03:00:42PM +0800, Zenghui Yu wrote:
> On 2023/10/13 4:54, Oliver Upton wrote:
> > From: Marc Zyngier <maz@kernel.org>
> >
> > An MMU notifier could cause us to clobber the stage-2 context loaded on
> > a CPU when we switch to another VM's context to invalidate. This isn't
> > an issue right now as the stage-2 context gets reloaded on every guest
> > entry, but is disastrous when moving __load_stage2() into the
> > vcpu_load() path.
> >
> > Restore the previous stage-2 context on the way out of a TLB
> > invalidation if we installed something else. Deliberately do this after
> > TGE=1 is synchronized to keep things safe in light of the speculative AT
> > errata.
> >
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
> > ---
> > arch/arm64/kvm/hyp/vhe/tlb.c | 17 ++++++++++++++---
> > 1 file changed, 14 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/arm64/kvm/hyp/vhe/tlb.c b/arch/arm64/kvm/hyp/vhe/tlb.c
> > index f3f2e142e4f4..ef21153ce5fa 100644
> > --- a/arch/arm64/kvm/hyp/vhe/tlb.c
> > +++ b/arch/arm64/kvm/hyp/vhe/tlb.c
> > @@ -11,18 +11,25 @@
> > #include <asm/tlbflush.h>
> > struct tlb_inv_context {
> > - unsigned long flags;
> > - u64 tcr;
> > - u64 sctlr;
> > + struct kvm_s2_mmu *mmu;
> > + unsigned long flags;
> > + u64 tcr;
> > + u64 sctlr;
> > };
> > static void __tlb_switch_to_guest(struct kvm_s2_mmu *mmu,
> > struct tlb_inv_context *cxt)
> > {
> > + struct kvm_vcpu *vcpu = kvm_get_running_vcpu();
> > u64 val;
> > local_irq_save(cxt->flags);
> > + if (vcpu && mmu != vcpu->arch.hw_mmu)
> > + cxt->mmu = mmu;
>
> Shouldn't this be
>
> cxt->mm = vcpu->arch.hw_mmu (the "previous" S2 context)?
It absolutely should, and Marc had it right the first time.
--
Thanks,
Oliver
next prev parent reply other threads:[~2023-10-18 7:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-12 20:54 [PATCH v2 0/5] KVM: arm64: Load stage-2 in vcpu_load() on VHE Oliver Upton
2023-10-12 20:54 ` [PATCH v2 1/5] KVM: arm64: Don't zero VTTBR in __tlb_switch_to_host() Oliver Upton
2023-10-12 20:54 ` [PATCH v2 2/5] KVM: arm64: Restore the stage-2 context in VHE's __tlb_switch_to_host() Oliver Upton
2023-10-18 7:00 ` Zenghui Yu
2023-10-18 7:05 ` Oliver Upton [this message]
2023-10-12 20:54 ` [PATCH v2 3/5] KVM: arm64: Reload stage-2 for VMID change on VHE Oliver Upton
2023-10-12 20:54 ` [PATCH v2 4/5] KVM: arm64: Rename helpers for VHE vCPU load/put Oliver Upton
2023-10-18 7:10 ` Zenghui Yu
2023-10-12 20:54 ` [PATCH v2 5/5] KVM: arm64: Load the stage-2 MMU context in kvm_vcpu_load_vhe() Oliver Upton
2023-10-18 7:17 ` Zenghui Yu
2023-10-17 7:58 ` [PATCH v2 0/5] KVM: arm64: Load stage-2 in vcpu_load() on VHE Oliver Upton
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=ZS-DnsM4JFXZ7a_H@linux.dev \
--to=oliver.upton@linux.dev \
--cc=james.morse@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=yuzenghui@huawei.com \
/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.