Skip to content

Commit efad60e

Browse files
Alexandru Eliseioupton
authored andcommitted
KVM: arm64: Initialize PMSCR_EL1 when in VHE
According to the pseudocode for StatisticalProfilingEnabled() from Arm DDI0487L.b, PMSCR_EL1 controls profiling at EL1 and EL0: - PMSCR_EL1.E1SPE controls profiling at EL1. - PMSCR_EL1.E0SPE controls profiling at EL0 if HCR_EL2.TGE=0. These two fields reset to UNKNOWN values. When KVM runs in VHE mode and profiling is enabled in the host, before entering a guest, KVM does not touch any of the SPE registers, leaving the buffer enabled, and it clears HCR_EL2.TGE. As a result, depending on the reset value for the E1SPE and E0SPE fields, KVM might unintentionally profile a guest. Make the behaviour consistent and predictable by clearing PMSCR_EL1 when KVM initialises the host debug configuration. Note that this is not a problem for nVHE, because KVM clears PMSCR_EL1.{E1SPE,E0SPE} before entering the guest. Signed-off-by: Alexandru Elisei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 860b21c commit efad60e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,7 @@ static inline bool kvm_system_needs_idmapped_vectors(void)
13691369
}
13701370

13711371
void kvm_init_host_debug_data(void);
1372+
void kvm_debug_init_vhe(void);
13721373
void kvm_vcpu_load_debug(struct kvm_vcpu *vcpu);
13731374
void kvm_vcpu_put_debug(struct kvm_vcpu *vcpu);
13741375
void kvm_debug_set_guest_ownership(struct kvm_vcpu *vcpu);

arch/arm64/kvm/arm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2113,8 +2113,10 @@ static void cpu_hyp_init_features(void)
21132113
{
21142114
cpu_set_hyp_vector();
21152115

2116-
if (is_kernel_in_hyp_mode())
2116+
if (is_kernel_in_hyp_mode()) {
21172117
kvm_timer_init_vhe();
2118+
kvm_debug_init_vhe();
2119+
}
21182120

21192121
if (vgic_present)
21202122
kvm_vgic_init_cpu_hardware();

arch/arm64/kvm/debug.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ void kvm_init_host_debug_data(void)
9696
}
9797
}
9898

99+
void kvm_debug_init_vhe(void)
100+
{
101+
/* Clear PMSCR_EL1.E{0,1}SPE which reset to UNKNOWN values. */
102+
if (SYS_FIELD_GET(ID_AA64DFR0_EL1, PMSVer, read_sysreg(id_aa64dfr0_el1)))
103+
write_sysreg_el1(0, SYS_PMSCR);
104+
}
105+
99106
/*
100107
* Configures the 'external' MDSCR_EL1 value for the guest, i.e. when the host
101108
* has taken over MDSCR_EL1.

0 commit comments

Comments
 (0)