Skip to content

Commit 2c433f7

Browse files
committed
KVM: arm64: Compute synthetic sysreg ESR for Apple PMUv3 traps
Apple M* CPUs provide an IMPDEF trap for PMUv3 sysregs, where ESR_EL2.EC is a reserved value (0x3F) and a sysreg-like ISS is reported in AFSR1_EL2. Compute a synthetic ESR for these PMUv3 traps, giving the illusion of something architectural to the rest of KVM. Tested-by: Janne Grunau <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 5629031 commit 2c433f7

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,25 @@ static bool kvm_hyp_handle_sysreg_vhe(struct kvm_vcpu *vcpu, u64 *exit_code)
527527
return kvm_hyp_handle_sysreg(vcpu, exit_code);
528528
}
529529

530+
static bool kvm_hyp_handle_impdef(struct kvm_vcpu *vcpu, u64 *exit_code)
531+
{
532+
u64 iss;
533+
534+
if (!cpus_have_final_cap(ARM64_WORKAROUND_PMUV3_IMPDEF_TRAPS))
535+
return false;
536+
537+
/*
538+
* Compute a synthetic ESR for a sysreg trap. Conveniently, AFSR1_EL2
539+
* is populated with a correct ISS for a sysreg trap. These fruity
540+
* parts are 64bit only, so unconditionally set IL.
541+
*/
542+
iss = ESR_ELx_ISS(read_sysreg_s(SYS_AFSR1_EL2));
543+
vcpu->arch.fault.esr_el2 = FIELD_PREP(ESR_ELx_EC_MASK, ESR_ELx_EC_SYS64) |
544+
FIELD_PREP(ESR_ELx_ISS_MASK, iss) |
545+
ESR_ELx_IL;
546+
return false;
547+
}
548+
530549
static const exit_handler_fn hyp_exit_handlers[] = {
531550
[0 ... ESR_ELx_EC_MAX] = NULL,
532551
[ESR_ELx_EC_CP15_32] = kvm_hyp_handle_cp15_32,
@@ -538,6 +557,9 @@ static const exit_handler_fn hyp_exit_handlers[] = {
538557
[ESR_ELx_EC_WATCHPT_LOW] = kvm_hyp_handle_watchpt_low,
539558
[ESR_ELx_EC_ERET] = kvm_hyp_handle_eret,
540559
[ESR_ELx_EC_MOPS] = kvm_hyp_handle_mops,
560+
561+
/* Apple shenanigans */
562+
[0x3F] = kvm_hyp_handle_impdef,
541563
};
542564

543565
static inline bool fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code)

arch/arm64/tools/cpucaps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ WORKAROUND_CAVIUM_TX2_219_TVM
105105
WORKAROUND_CLEAN_CACHE
106106
WORKAROUND_DEVICE_LOAD_ACQUIRE
107107
WORKAROUND_NVIDIA_CARMEL_CNP
108+
WORKAROUND_PMUV3_IMPDEF_TRAPS
108109
WORKAROUND_QCOM_FALKOR_E1003
109110
WORKAROUND_QCOM_ORYON_CNTVOFF
110111
WORKAROUND_REPEAT_TLBI

0 commit comments

Comments
 (0)