Skip to content

Commit b96c200

Browse files
ouptonjannau
authored andcommitted
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. Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 6f32be7 commit b96c200

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

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

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

421+
static bool kvm_hyp_handle_impdef(struct kvm_vcpu *vcpu, u64 *exit_code)
422+
{
423+
u64 iss;
424+
425+
if (!cpus_have_final_cap(ARM64_WORKAROUND_PMUV3_IMPDEF_TRAPS))
426+
return false;
427+
428+
/*
429+
* Compute a synthetic ESR for a sysreg trap. Conveniently, AFSR1_EL2
430+
* is populated with a correct ISS for a sysreg trap. These fruity
431+
* parts are 64bit only, so unconditionally set IL.
432+
*/
433+
iss = ESR_ELx_ISS(read_sysreg_s(SYS_AFSR1_EL2));
434+
vcpu->arch.fault.esr_el2 = FIELD_PREP(ESR_ELx_EC_MASK, ESR_ELx_EC_SYS64) |
435+
FIELD_PREP(ESR_ELx_ISS_MASK, iss) |
436+
ESR_ELx_IL;
437+
return false;
438+
}
439+
421440
static const exit_handler_fn hyp_exit_handlers[] = {
422441
[0 ... ESR_ELx_EC_MAX] = NULL,
423442
[ESR_ELx_EC_CP15_32] = kvm_hyp_handle_cp15_32,
@@ -429,6 +448,9 @@ static const exit_handler_fn hyp_exit_handlers[] = {
429448
[ESR_ELx_EC_WATCHPT_LOW] = kvm_hyp_handle_watchpt_low,
430449
[ESR_ELx_EC_ERET] = kvm_hyp_handle_eret,
431450
[ESR_ELx_EC_MOPS] = kvm_hyp_handle_mops,
451+
452+
/* Apple shenanigans */
453+
[0x3F] = kvm_hyp_handle_impdef,
432454
};
433455

434456
static const exit_handler_fn *kvm_get_exit_handler_array(struct kvm_vcpu *vcpu)

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_REPEAT_TLBI
110111
WORKAROUND_SPECULATIVE_AT

0 commit comments

Comments
 (0)