vcpu->arch.hcr_el2 = val;
}
-static void pvm_init_traps_cptr(struct kvm_vcpu *vcpu)
-{
- struct kvm *kvm = vcpu->kvm;
- u64 val = vcpu->arch.cptr_el2;
-
- if (!has_hvhe()) {
- val |= CPTR_NVHE_EL2_RES1;
- val &= ~(CPTR_NVHE_EL2_RES0);
- }
-
- if (!kvm_has_feat(kvm, ID_AA64PFR0_EL1, AMU, IMP))
- val |= CPTR_EL2_TAM;
-
- /* SVE can be disabled by userspace even if supported. */
- if (!vcpu_has_sve(vcpu)) {
- if (has_hvhe())
- val &= ~(CPACR_ELx_ZEN);
- else
- val |= CPTR_EL2_TZ;
- }
-
- /* No SME support in KVM. */
- BUG_ON(kvm_has_feat(kvm, ID_AA64PFR1_EL1, SME, IMP));
- if (has_hvhe())
- val &= ~(CPACR_ELx_SMEN);
- else
- val |= CPTR_EL2_TSM;
-
- if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, TraceVer, IMP)) {
- if (has_hvhe())
- val |= CPACR_EL1_TTA;
- else
- val |= CPTR_EL2_TTA;
- }
-
- vcpu->arch.cptr_el2 = val;
-}
-
static void pvm_init_traps_mdcr(struct kvm_vcpu *vcpu)
{
struct kvm *kvm = vcpu->kvm;
struct kvm_vcpu *vcpu = &hyp_vcpu->vcpu;
int ret;
- vcpu->arch.cptr_el2 = kvm_get_reset_cptr_el2(vcpu);
vcpu->arch.mdcr_el2 = 0;
pkvm_vcpu_reset_hcr(vcpu);
return ret;
pvm_init_traps_hcr(vcpu);
- pvm_init_traps_cptr(vcpu);
pvm_init_traps_mdcr(vcpu);
return 0;
return ret;
}
- hyp_vcpu->vcpu.arch.cptr_el2 = kvm_get_reset_cptr_el2(&hyp_vcpu->vcpu);
-
return 0;
}
extern void kvm_nvhe_prepare_backtrace(unsigned long fp, unsigned long pc);
-static void __activate_traps(struct kvm_vcpu *vcpu)
+static void __activate_cptr_traps(struct kvm_vcpu *vcpu)
{
- u64 val;
+ u64 val = CPTR_EL2_TAM; /* Same bit irrespective of E2H */
- ___activate_traps(vcpu, vcpu->arch.hcr_el2);
- __activate_traps_common(vcpu);
+ if (has_hvhe()) {
+ val |= CPACR_ELx_TTA;
- val = vcpu->arch.cptr_el2;
- val |= CPTR_EL2_TAM; /* Same bit irrespective of E2H */
- val |= has_hvhe() ? CPACR_EL1_TTA : CPTR_EL2_TTA;
- if (cpus_have_final_cap(ARM64_SME)) {
- if (has_hvhe())
- val &= ~CPACR_ELx_SMEN;
- else
- val |= CPTR_EL2_TSM;
- }
+ if (guest_owns_fp_regs()) {
+ val |= CPACR_ELx_FPEN;
+ if (vcpu_has_sve(vcpu))
+ val |= CPACR_ELx_ZEN;
+ }
+ } else {
+ val |= CPTR_EL2_TTA | CPTR_NVHE_EL2_RES1;
- if (!guest_owns_fp_regs()) {
- if (has_hvhe())
- val &= ~(CPACR_ELx_FPEN | CPACR_ELx_ZEN);
- else
- val |= CPTR_EL2_TFP | CPTR_EL2_TZ;
+ /*
+ * Always trap SME since it's not supported in KVM.
+ * TSM is RES1 if SME isn't implemented.
+ */
+ val |= CPTR_EL2_TSM;
- __activate_traps_fpsimd32(vcpu);
+ if (!vcpu_has_sve(vcpu) || !guest_owns_fp_regs())
+ val |= CPTR_EL2_TZ;
+
+ if (!guest_owns_fp_regs())
+ val |= CPTR_EL2_TFP;
}
+ if (!guest_owns_fp_regs())
+ __activate_traps_fpsimd32(vcpu);
+
kvm_write_cptr_el2(val);
+}
+
+static void __activate_traps(struct kvm_vcpu *vcpu)
+{
+ ___activate_traps(vcpu, vcpu->arch.hcr_el2);
+ __activate_traps_common(vcpu);
+ __activate_cptr_traps(vcpu);
+
write_sysreg(__this_cpu_read(kvm_hyp_vector), vbar_el2);
if (cpus_have_final_cap(ARM64_WORKAROUND_SPECULATIVE_AT)) {