Skip to content

Commit cd931bd

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: nv: Add additional trap setup for CPTR_EL2
We need to teach KVM a couple of new tricks. CPTR_EL2 and its VHE accessor CPACR_EL1 need to be handled specially: - CPACR_EL1 is trapped on VHE so that we can track the TCPAC and TTA bits - CPTR_EL2.{TCPAC,E0POE} are propagated from L1 to L2 Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent e19d533 commit cd931bd

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

arch/arm64/kvm/hyp/vhe/switch.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,23 @@ static void __activate_cptr_traps(struct kvm_vcpu *vcpu)
8787
__activate_traps_fpsimd32(vcpu);
8888
}
8989

90+
if (!vcpu_has_nv(vcpu))
91+
goto write;
92+
93+
/*
94+
* The architecture is a bit crap (what a surprise): an EL2 guest
95+
* writing to CPTR_EL2 via CPACR_EL1 can't set any of TCPAC or TTA,
96+
* as they are RES0 in the guest's view. To work around it, trap the
97+
* sucker using the very same bit it can't set...
98+
*/
99+
if (vcpu_el2_e2h_is_set(vcpu) && is_hyp_ctxt(vcpu))
100+
val |= CPTR_EL2_TCPAC;
101+
90102
/*
91103
* Layer the guest hypervisor's trap configuration on top of our own if
92104
* we're in a nested context.
93105
*/
94-
if (!vcpu_has_nv(vcpu) || is_hyp_ctxt(vcpu))
106+
if (is_hyp_ctxt(vcpu))
95107
goto write;
96108

97109
cptr = vcpu_sanitised_cptr_el2(vcpu);
@@ -115,6 +127,11 @@ static void __activate_cptr_traps(struct kvm_vcpu *vcpu)
115127
if (!(SYS_FIELD_GET(CPACR_ELx, ZEN, cptr) & BIT(0)))
116128
val &= ~CPACR_ELx_ZEN;
117129

130+
if (kvm_has_feat(vcpu->kvm, ID_AA64MMFR3_EL1, S2POE, IMP))
131+
val |= cptr & CPACR_ELx_E0POE;
132+
133+
val |= cptr & CPTR_EL2_TCPAC;
134+
118135
write:
119136
write_sysreg(val, cpacr_el1);
120137
}

0 commit comments

Comments
 (0)