Skip to content

Commit 8681f71

Browse files
reijiw-kvmMarc Zyngier
authored andcommitted
KVM: arm64: PMU: Restore the host's PMUSERENR_EL0
Restore the host's PMUSERENR_EL0 value instead of clearing it, before returning back to userspace, as the host's EL0 might have a direct access to PMU registers (some bits of PMUSERENR_EL0 for might not be zero for the host EL0). Fixes: 83a7a4d ("arm64: perf: Enable PMU counter userspace access for perf event") Signed-off-by: Reiji Watanabe <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 40e54ca commit 8681f71

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

arch/arm64/kvm/hyp/include/hyp/switch.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu)
8282
* EL1 instead of being trapped to EL2.
8383
*/
8484
if (kvm_arm_support_pmu_v3()) {
85+
struct kvm_cpu_context *hctxt;
86+
8587
write_sysreg(0, pmselr_el0);
88+
89+
hctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt;
90+
ctxt_sys_reg(hctxt, PMUSERENR_EL0) = read_sysreg(pmuserenr_el0);
8691
write_sysreg(ARMV8_PMU_USERENR_MASK, pmuserenr_el0);
8792
}
8893

@@ -106,8 +111,12 @@ static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu)
106111
write_sysreg(vcpu->arch.mdcr_el2_host, mdcr_el2);
107112

108113
write_sysreg(0, hstr_el2);
109-
if (kvm_arm_support_pmu_v3())
110-
write_sysreg(0, pmuserenr_el0);
114+
if (kvm_arm_support_pmu_v3()) {
115+
struct kvm_cpu_context *hctxt;
116+
117+
hctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt;
118+
write_sysreg(ctxt_sys_reg(hctxt, PMUSERENR_EL0), pmuserenr_el0);
119+
}
111120

112121
if (cpus_have_final_cap(ARM64_SME)) {
113122
sysreg_clear_set_s(SYS_HFGRTR_EL2, 0,

0 commit comments

Comments
 (0)