From: Marc Zyngier <maz@kernel•org>
To: Alexandru Elisei <alexandru.elisei@arm•com>
Cc: Christoffer Dall <christoffer.dall@arm•com>,
linux-arm-kernel@lists•infradead.org,
kvmarm@lists•cs.columbia.edu
Subject: Re: [PATCH v2] KVM: arm64: Don't set HCR_EL2.TVM when S2FWB is supported
Date: Mon, 28 Oct 2019 16:19:55 +0000 [thread overview]
Message-ID: <86pnigyh90.wl-maz@kernel.org> (raw)
In-Reply-To: <0c3291a7-18dc-1ae5-e706-8b04c9ab8a9e@arm.com>
On Mon, 28 Oct 2019 15:12:39 +0000,
Alexandru Elisei <alexandru.elisei@arm•com> wrote:
>
> Hi,
>
> Resending this email, because I replied only to the kvmarm list by accident,
> instead of replying to everyone involved.
>
> On 10/28/19 1:05 PM, Christoffer Dall wrote:
> > On CPUs that support S2FWB (Armv8.4+), KVM configures the stage 2 page
> > tables to override the memory attributes of memory accesses, regardless
> > of the stage 1 page table configurations, and also when the stage 1 MMU
> > is turned off. This results in all memory accesses to RAM being
> > cacheable, including during early boot of the guest.
> >
> > On CPUs without this feature, memory accesses were non-cacheable during
> > boot until the guest turned on the stage 1 MMU, and we had to detect
> > when the guest turned on the MMU, such that we could invalidate all cache
> > entries and ensure a consistent view of memory with the MMU turned on.
> > When the guest turned on the caches, we would call stage2_flush_vm()
> > from kvm_toggle_cache().
> >
> > However, stage2_flush_vm() walks all the stage 2 tables, and calls
> > __kvm_flush-dcache_pte, which on a system with S2FWD does ... absolutely
> > nothing.
> >
> > We can avoid that whole song and dance, and simply not set TVM when
> > creating a VM on a system that has S2FWB.
> >
> > Signed-off-by: Christoffer Dall <christoffer.dall@arm•com>
> > Reviewed-by: Mark Rutland <mark.rutland@arm•com>
> > ---
> > I was only able to test this on the model with cache modeling enabled,
> > but even removing TVM from HCR_EL2 without having FWB also worked with
> > that setup, so the testing of this has been light. It seems like it
> > should obviously work, but it would be good if someone with access to
> > appropriate hardware could give this a spin.
> >
> > arch/arm64/include/asm/kvm_arm.h | 3 +--
> > arch/arm64/include/asm/kvm_emulate.h | 12 +++++++++++-
> > 2 files changed, 12 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
> > index ddf9d762ac62..6e5d839f42b5 100644
> > --- a/arch/arm64/include/asm/kvm_arm.h
> > +++ b/arch/arm64/include/asm/kvm_arm.h
> > @@ -61,7 +61,6 @@
> > * RW: 64bit by default, can be overridden for 32bit VMs
> > * TAC: Trap ACTLR
> > * TSC: Trap SMC
> > - * TVM: Trap VM ops (until M+C set in SCTLR_EL1)
> > * TSW: Trap cache operations by set/way
> > * TWE: Trap WFE
> > * TWI: Trap WFI
> > @@ -74,7 +73,7 @@
> > * SWIO: Turn set/way invalidates into set/way clean+invalidate
> > */
> > #define HCR_GUEST_FLAGS (HCR_TSC | HCR_TSW | HCR_TWE | HCR_TWI | HCR_VM | \
> > - HCR_TVM | HCR_BSU_IS | HCR_FB | HCR_TAC | \
> > + HCR_BSU_IS | HCR_FB | HCR_TAC | \
> > HCR_AMO | HCR_SWIO | HCR_TIDCP | HCR_RW | HCR_TLOR | \
> > HCR_FMO | HCR_IMO)
> > #define HCR_VIRT_EXCP_MASK (HCR_VSE | HCR_VI | HCR_VF)
> > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
> > index d69c1efc63e7..70509799a2a9 100644
> > --- a/arch/arm64/include/asm/kvm_emulate.h
> > +++ b/arch/arm64/include/asm/kvm_emulate.h
> > @@ -53,8 +53,18 @@ static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
> > /* trap error record accesses */
> > vcpu->arch.hcr_el2 |= HCR_TERR;
> > }
> > - if (cpus_have_const_cap(ARM64_HAS_STAGE2_FWB))
> > +
> > + if (cpus_have_const_cap(ARM64_HAS_STAGE2_FWB)) {
> > vcpu->arch.hcr_el2 |= HCR_FWB;
> > + } else {
> > + /*
> > + * For non-FWB CPUs, we trap VM ops (HCR_EL2.TVM) until M+C
> > + * get set in SCTLR_EL1 such that we can detect when the guest
> > + * MMU gets turned off and do the necessary cache maintenance
> > + * then.
> > + */
> > + vcpu->arch.hcr_el2 &= ~HCR_TVM;
>
> Don't we want to set the bit here, so we're consistent with the
> previous behaviour and the comment? Because with this patch, we
> never set HCR_EL2.TVM...
Of course you're right. This is how I plan to fix it:
diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index 47c774c2d18b..7b835337f78b 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -63,7 +63,7 @@ static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
* MMU gets turned on and do the necessary cache maintenance
* then.
*/
- vcpu->arch.hcr_el2 &= ~HCR_TVM;
+ vcpu->arch.hcr_el2 |= HCR_TVM;
}
if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features))
Christoffer, please shout if you disagree.
M.
--
Jazz is not dead, it just smells funny.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists•infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-10-28 16:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-28 13:05 [PATCH v2] KVM: arm64: Don't set HCR_EL2.TVM when S2FWB is supported Christoffer Dall
2019-10-28 13:28 ` Mark Rutland
2019-10-28 13:45 ` Marc Zyngier
2019-10-28 15:12 ` Alexandru Elisei
2019-10-28 16:19 ` Marc Zyngier [this message]
2019-10-28 17:09 ` Mark Rutland
2019-11-06 13:02 ` Alexandru Elisei
2019-11-06 15:20 ` Christoffer Dall
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=86pnigyh90.wl-maz@kernel.org \
--to=maz@kernel$(echo .)org \
--cc=alexandru.elisei@arm$(echo .)com \
--cc=christoffer.dall@arm$(echo .)com \
--cc=kvmarm@lists$(echo .)cs.columbia.edu \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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