Skip to content

Commit 5c40130

Browse files
christofferdall-armMarc Zyngier
authored andcommitted
KVM: arm64: Don't set HCR_EL2.TVM when S2FWB is supported
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 S2FWB 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 <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 01d035d commit 5c40130

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

arch/arm64/include/asm/kvm_arm.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
* RW: 64bit by default, can be overridden for 32bit VMs
6262
* TAC: Trap ACTLR
6363
* TSC: Trap SMC
64-
* TVM: Trap VM ops (until M+C set in SCTLR_EL1)
6564
* TSW: Trap cache operations by set/way
6665
* TWE: Trap WFE
6766
* TWI: Trap WFI
@@ -74,7 +73,7 @@
7473
* SWIO: Turn set/way invalidates into set/way clean+invalidate
7574
*/
7675
#define HCR_GUEST_FLAGS (HCR_TSC | HCR_TSW | HCR_TWE | HCR_TWI | HCR_VM | \
77-
HCR_TVM | HCR_BSU_IS | HCR_FB | HCR_TAC | \
76+
HCR_BSU_IS | HCR_FB | HCR_TAC | \
7877
HCR_AMO | HCR_SWIO | HCR_TIDCP | HCR_RW | HCR_TLOR | \
7978
HCR_FMO | HCR_IMO)
8079
#define HCR_VIRT_EXCP_MASK (HCR_VSE | HCR_VI | HCR_VF)

arch/arm64/include/asm/kvm_emulate.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,18 @@ static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
5353
/* trap error record accesses */
5454
vcpu->arch.hcr_el2 |= HCR_TERR;
5555
}
56-
if (cpus_have_const_cap(ARM64_HAS_STAGE2_FWB))
56+
57+
if (cpus_have_const_cap(ARM64_HAS_STAGE2_FWB)) {
5758
vcpu->arch.hcr_el2 |= HCR_FWB;
59+
} else {
60+
/*
61+
* For non-FWB CPUs, we trap VM ops (HCR_EL2.TVM) until M+C
62+
* get set in SCTLR_EL1 such that we can detect when the guest
63+
* MMU gets turned on and do the necessary cache maintenance
64+
* then.
65+
*/
66+
vcpu->arch.hcr_el2 |= HCR_TVM;
67+
}
5868

5969
if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features))
6070
vcpu->arch.hcr_el2 &= ~HCR_RW;

0 commit comments

Comments
 (0)