Merge remote-tracking branch 'kvmarm/misc-5.5' into kvmarm/next
[platform/kernel/linux-starfive.git] / arch / arm64 / include / asm / kvm_emulate.h
index a3c9679..5efe5ca 100644 (file)
@@ -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 on and do the necessary cache maintenance
+                * then.
+                */
+               vcpu->arch.hcr_el2 |= HCR_TVM;
+       }
 
        if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features))
                vcpu->arch.hcr_el2 &= ~HCR_RW;
@@ -77,14 +87,19 @@ static inline unsigned long *vcpu_hcr(struct kvm_vcpu *vcpu)
        return (unsigned long *)&vcpu->arch.hcr_el2;
 }
 
-static inline void vcpu_clear_wfe_traps(struct kvm_vcpu *vcpu)
+static inline void vcpu_clear_wfx_traps(struct kvm_vcpu *vcpu)
 {
        vcpu->arch.hcr_el2 &= ~HCR_TWE;
+       if (atomic_read(&vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vlpi_count))
+               vcpu->arch.hcr_el2 &= ~HCR_TWI;
+       else
+               vcpu->arch.hcr_el2 |= HCR_TWI;
 }
 
-static inline void vcpu_set_wfe_traps(struct kvm_vcpu *vcpu)
+static inline void vcpu_set_wfx_traps(struct kvm_vcpu *vcpu)
 {
        vcpu->arch.hcr_el2 |= HCR_TWE;
+       vcpu->arch.hcr_el2 |= HCR_TWI;
 }
 
 static inline void vcpu_ptrauth_enable(struct kvm_vcpu *vcpu)